1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
| <script lang="ts" setup>
| import { reactive, toRefs } from 'vue';
|
| import { useMessage } from '@jnpf/hooks';
| import { BasicForm, useForm } from '@jnpf/ui/form';
| import { BasicModal, useModalInner } from '@jnpf/ui/modal';
| import { formValidate, isUrl } from '@jnpf/utils';
|
| import { createPortal, getInfo, updatePortal } from '#/api/onlineDev/portal';
| import { $t } from '#/locales';
|
| const emit = defineEmits(['register', 'reload', 'design']);
|
| interface State {
| dataForm: any;
| btnLoading: boolean;
| }
|
| const state = reactive<State>({
| dataForm: {
| type: 0,
| },
| btnLoading: false,
| });
| const { dataForm, btnLoading } = toRefs(state);
| const { createMessage } = useMessage();
| const [registerModal, { closeModal, changeLoading, changeOkLoading }] = useModalInner(init);
| const [registerForm, { setFieldsValue, getFieldsValue, resetFields, validate, clearValidate, updateSchema }] = useForm({
| labelWidth: 100,
| schemas: [
| {
| field: 'fullName',
| label: '名称',
| component: 'Input',
| componentProps: { placeholder: '请输入', maxlength: 100 },
| rules: [{ required: true, trigger: 'blur', message: '必填' }],
| },
| {
| field: 'enCode',
| label: '编码',
| component: 'Input',
| componentProps: { placeholder: '请输入', maxlength: 50 },
| rules: [{ validator: formValidate('enCode'), trigger: 'blur' }],
| },
| {
| field: 'category',
| label: '分类',
| component: 'Select',
| componentProps: { placeholder: '请选择', showSearch: true },
| rules: [{ required: true, trigger: 'change', message: '必填' }],
| },
| {
| field: 'type',
| label: '类型',
| defaultValue: 0,
| component: 'Radio',
| componentProps: {
| options: [
| { id: 0, fullName: '门户设计' },
| { id: 1, fullName: '配置路径' },
| ],
| optionType: 'button',
| buttonStyle: 'solid',
| onChange: onTypeChange,
| },
| rules: [{ required: true, trigger: 'change', message: '必填', type: 'number' }],
| },
| {
| ifShow: ({ values }) => values.type === 1,
| field: 'linkType',
| label: '链接类型',
| defaultValue: 0,
| component: 'Radio',
| componentProps: {
| options: [
| { id: 0, fullName: '页面' },
| { id: 1, fullName: '外链' },
| ],
| optionType: 'button',
| buttonStyle: 'solid',
| onChange: onLinkTypeChange,
| },
| rules: [{ required: true, trigger: 'change', message: '必填', type: 'number' }],
| },
| {
| ifShow: ({ values }) => values.type === 1,
| field: 'customUrl',
| label: '链接地址',
| component: 'Input',
| componentProps: { placeholder: '请输入' },
| helpMessage: '链接类型选择页面,只支持PC显示,不支持APP显示。',
| rules: [
| { required: true, trigger: 'blur', message: '必填' },
| {
| validator: (_rule, value) => {
| if (value && getFieldsValue()?.linkType == 1 && !isUrl(value)) return Promise.reject(new Error('请输入正确的链接地址'));
| return Promise.resolve();
| },
| trigger: 'blur',
| },
| ],
| },
| {
| ifShow: ({ values }) => values.type === 0,
| field: 'enabledLock',
| label: '锁定',
| component: 'Switch',
| defaultValue: 1,
| helpMessage: '启用:不允许拖拽移动控件;禁用:允许用户在PC门户上拖拽大小及移动控件。',
| },
| {
| field: 'sortCode',
| label: '排序',
| defaultValue: 0,
| component: 'InputNumber',
| componentProps: { min: 0, max: 999999 },
| },
| {
| field: 'description',
| label: '说明 ',
| component: 'Textarea',
| componentProps: { placeholder: '请输入' },
| },
| ],
| });
|
| function init(data) {
| resetFields();
| state.dataForm.id = data.id || '';
| updateSchema([{ field: 'category', componentProps: { options: data.categoryList || [] } }]);
| state.dataForm.type = 0;
| if (state.dataForm.id) {
| changeLoading(true);
| getInfo(state.dataForm.id)
| .then((res) => {
| state.dataForm = res.data;
| onLinkTypeChange(state.dataForm.linkType);
| setFieldsValue(state.dataForm);
| changeLoading(false);
| })
| .catch(() => {
| changeLoading(false);
| });
| }
| }
| function onLinkTypeChange(val) {
| updateSchema([
| { field: 'customUrl', componentProps: { addonBefore: val === 0 ? '@/views/' : '' }, helpMessage: val === 1 ? '地址以http://或https://为开头' : '' },
| ]);
| setFieldsValue({ customUrl: '' });
| clearValidate('customUrl');
| }
| function onTypeChange(val) {
| state.dataForm.type = val;
| onLinkTypeChange(getFieldsValue()?.linkType);
| }
| async function handleSubmit(type?) {
| const values = await validate();
| if (!values) return;
| type === 1 ? (state.btnLoading = true) : changeOkLoading(true);
| const query = {
| ...values,
| id: state.dataForm.id,
| };
| const formMethod = state.dataForm.id ? updatePortal : createPortal;
| formMethod(query)
| .then((res) => {
| createMessage.success(res.msg);
| changeOkLoading(false);
| state.btnLoading = false;
| closeModal();
| emit('reload');
| if (!state.dataForm.id) state.dataForm.id = res.data;
| if (type == 1) emit('design', { ...values, id: state.dataForm.id });
| })
| .catch(() => {
| changeOkLoading(false);
| state.btnLoading = false;
| });
| }
| </script>
| <template>
| <BasicModal v-bind="$attrs" @register="registerModal" :title="state.dataForm.id ? $t('common.editText') : $t('common.addText')" @ok="handleSubmit">
| <BasicForm @register="registerForm" />
| <template #appendFooter>
| <a-button type="primary" :loading="btnLoading" @click="handleSubmit(1)" v-if="dataForm.type === 0">确定并设计</a-button>
| </template>
| </BasicModal>
| </template>
|
|