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
| <script lang="ts" setup>
| import { computed, ref, unref } from 'vue';
|
| import { useMessage } from '@jnpf/hooks';
| import { BasicForm, useForm } from '@jnpf/ui/form';
| import { BasicModal, useModalInner } from '@jnpf/ui/modal';
|
| import {
| createDictionaryData as create,
| getDictionaryDataTypeSelector,
| getDictionaryDataInfo as getInfo,
| updateDictionaryData as update,
| } from '#/api/systemData/dictionary';
| import { $t } from '#/locales';
| import { useBaseStore } from '#/store';
|
| const emit = defineEmits(['register', 'reload']);
| const [registerForm, { setFieldsValue, resetFields, validate, updateSchema }] = useForm({
| schemas: [
| {
| field: 'parentId',
| label: '项目上级',
| defaultValue: '0',
| component: 'TreeSelect',
| componentProps: { placeholder: '请选择', showSearch: true },
| rules: [{ required: true, trigger: 'blur', message: '必填' }],
| },
| {
| field: 'fullName',
| label: '字典名称',
| component: 'Input',
| componentProps: { placeholder: '请输入', maxlength: 50 },
| rules: [{ required: true, trigger: 'blur', message: '必填' }],
| },
| {
| field: 'enCode',
| label: '字典编码',
| component: 'Input',
| componentProps: { placeholder: '请输入', maxlength: 50 },
| rules: [{ required: true, trigger: 'blur', message: '必填' }],
| },
| {
| field: 'sortCode',
| label: '排序',
| defaultValue: 0,
| component: 'InputNumber',
| componentProps: { min: 0, max: 999999 },
| },
| {
| field: 'enabledMark',
| label: '状态',
| defaultValue: 1,
| component: 'Switch',
| },
| {
| field: 'description',
| label: '说明',
| component: 'Textarea',
| componentProps: { placeholder: '请输入', rows: 3 },
| },
| ],
| });
| const [registerModal, { closeModal, changeLoading, changeOkLoading }] = useModalInner(init);
| const id = ref('');
| const isTree = ref(0);
| const typeId = ref('');
| const treeData = ref([]);
| const { createMessage } = useMessage();
| const baseStore = useBaseStore();
|
| const getTitle = computed(() => (unref(id) ? $t('common.editText') : $t('common.addText')));
|
| function init(data) {
| changeLoading(true);
| resetFields();
| id.value = data.id;
| isTree.value = data.isTree;
| typeId.value = data.typeId;
| updateSchema({ field: 'parentId', componentProps: { disabled: !unref(isTree) } });
| getDictionaryDataTypeSelector(data.typeId, data.isTree, data.id).then((res) => {
| treeData.value = res.data.list;
| updateSchema([
| {
| field: 'parentId',
| componentProps: { options: treeData.value },
| },
| ]);
| if (id.value) {
| getInfo(id.value).then((res) => {
| setFieldsValue(res.data);
| typeId.value = res.data.dictionaryTypeId;
| changeLoading(false);
| });
| } else {
| setFieldsValue({ parentId: res.data.list[0].id });
| changeLoading(false);
| }
| });
| }
|
| async function handleSubmit() {
| const values = await validate();
| if (!values) return;
| changeOkLoading(true);
| const query = {
| ...values,
| id: id.value,
| dictionaryTypeId: typeId.value,
| };
| const formMethod = id.value ? update : create;
| formMethod(query)
| .then((res) => {
| createMessage.success(res.msg);
| changeOkLoading(false);
| baseStore.setDictionaryList();
| closeModal();
| emit('reload');
| })
| .catch(() => {
| changeOkLoading(false);
| });
| }
| </script>
| <template>
| <BasicModal v-bind="$attrs" @register="registerModal" :title="getTitle" @ok="handleSubmit">
| <BasicForm @register="registerForm" />
| </BasicModal>
| </template>
|
|