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
| <script lang="ts" setup>
| import { reactive } from 'vue';
|
| import { useMessage } from '@jnpf/hooks';
| import { BasicForm, useForm } from '@jnpf/ui/form';
| import { BasicModal, useModalInner } from '@jnpf/ui/modal';
| import { formValidate } from '@jnpf/utils';
|
| import { create, getInfo, update } from '#/api/workFlow/template';
| import { $t } from '#/locales';
| import { colorPredefine } from '#/utils/constants';
|
| interface State {
| iconBackground: string;
| dataForm: any;
| btnLoading: boolean;
| showType: number;
| type: number;
| }
|
| const emit = defineEmits(['register', 'reload', 'design']);
| const state = reactive<State>({
| iconBackground: '#008cff',
| dataForm: {},
| btnLoading: false,
| showType: 0,
| type: 0,
| });
| const { createMessage } = useMessage();
| const [registerModal, { closeModal, changeLoading, changeOkLoading }] = useModalInner(init);
| const [registerForm, { setFieldsValue, validate, updateSchema }] = useForm({
| schemas: [
| {
| 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: [{ validator: formValidate('enCode'), trigger: 'blur' }],
| },
| {
| field: 'category',
| label: '流程分类',
| component: 'Select',
| componentProps: { placeholder: '请选择', showSearch: true },
| rules: [{ required: true, trigger: 'change', message: '必填' }],
| },
| {
| field: 'icon',
| label: '流程图标',
| slot: 'icon',
| component: 'IconPicker',
| rules: [{ required: true, trigger: 'change', message: '必填' }],
| },
| {
| field: 'showType',
| label: '显示位置',
| defaultValue: 0,
| ifShow: () => state.type != 2,
| component: 'Radio',
| componentProps: {
| optionType: 'button',
| buttonStyle: 'solid',
| options: [
| { fullName: '都显示', id: 0 },
| { fullName: '仅发起流程显示', id: 1 },
| { fullName: '仅菜单显示', id: 2 },
| ],
| },
| },
| {
| field: 'sortCode',
| label: '流程排序',
| defaultValue: 0,
| component: 'InputNumber',
| componentProps: { min: 0, max: 999999 },
| },
| {
| field: 'description',
| label: '流程说明',
| component: 'Textarea',
| componentProps: { placeholder: '请输入' },
| },
| ],
| });
|
| function init(data) {
| state.type = data.type;
| state.iconBackground = '#008cff';
| updateSchema([{ field: 'category', componentProps: { options: data.categoryList || [] } }]);
| state.dataForm.id = data.id;
| if (state.dataForm.id) {
| getInfo(state.dataForm.id).then((res) => {
| state.dataForm = res.data;
| state.iconBackground = state.dataForm.iconBackground || '#008cff';
| setFieldsValue(state.dataForm);
| changeLoading(false);
| });
| } else {
| state.dataForm.type = data.type || 0;
| changeLoading(false);
| }
| }
| async function handleSubmit(type?) {
| const values = await validate();
| if (!values) return;
| changeOkLoading(true);
| state.btnLoading = true;
| const query = {
| ...values,
| iconBackground: state.iconBackground,
| id: state.dataForm.id,
| type: state.dataForm.type,
| };
| const formMethod = state.dataForm.id ? update : create;
| formMethod(query)
| .then((res) => {
| createMessage.success(res.msg);
| changeOkLoading(false);
| state.btnLoading = false;
| closeModal();
| emit('reload');
| if (type === 1) emit('design', { id: state.dataForm.id || res.data, fullName: state.dataForm.fullName });
| })
| .catch(() => {
| changeOkLoading(false);
| state.btnLoading = false;
| });
| }
| </script>
| <template>
| <BasicModal
| v-bind="$attrs"
| @register="registerModal"
| :title="state.dataForm.id ? $t('common.editText') : $t('common.addText')"
| :width="600"
| @ok="handleSubmit"
| destroy-on-close>
| <BasicForm @register="registerForm">
| <template #icon="{ model, field }">
| <div class="flex">
| <div class="mr-[10px] flex-1">
| <jnpf-icon-picker v-model:value="model[field]" placeholder="请选择" />
| </div>
| <a-form-item-rest>
| <jnpf-color-picker v-model:value="state.iconBackground" size="small" :predefine="colorPredefine" />
| </a-form-item-rest>
| </div>
| </template>
| </BasicForm>
| <template #appendFooter>
| <a-button type="primary" @click="handleSubmit(1)" :loading="state.btnLoading">确定并设计</a-button>
| </template>
| </BasicModal>
| </template>
|
|