ny
昨天 282fbc6488f4e8ceb5fda759f963ee88fbf7b999
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
<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 } from '#/api/system/kit';
import { useBaseStore } from '#/store';
 
interface State {
  dataForm: any;
}
 
const emit = defineEmits(['register', 'reload']);
const state = reactive<State>({
  dataForm: {},
});
const [registerForm, { setFieldsValue, resetFields, validate, updateSchema }] = useForm({
  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: 'icon',
      label: '模板图标',
      component: 'IconPicker',
      rules: [{ required: true, trigger: 'change', message: '必填' }],
    },
    {
      field: 'sortCode',
      label: '模板排序',
      defaultValue: 0,
      component: 'InputNumber',
      componentProps: { min: 0, max: 999999 },
    },
    {
      field: 'enabledMark',
      label: '模板状态',
      component: 'Switch',
      defaultValue: 1,
    },
    {
      field: 'description',
      label: '模板说明',
      component: 'Textarea',
      componentProps: { placeholder: '请输入' },
    },
  ],
});
const [registerModal, { closeModal, changeOkLoading }] = useModalInner(init);
const { createMessage } = useMessage();
const baseStore = useBaseStore();
 
function init(data = {}) {
  getOptions();
  resetFields();
  state.dataForm = data;
  setFieldsValue(data);
}
async function getOptions() {
  const typeRes = await baseStore.getDictionaryData('businessType');
  updateSchema({ field: 'category', componentProps: { options: typeRes } });
}
async function handleSubmit() {
  const values = await validate();
  if (!values) return;
  changeOkLoading(true);
  const query = { ...state.dataForm, ...values };
  create(query)
    .then((res) => {
      createMessage.success(res.msg);
      changeOkLoading(false);
      closeModal();
      emit('reload');
    })
    .catch(() => {
      changeOkLoading(false);
    });
}
</script>
<template>
  <BasicModal v-bind="$attrs" @register="registerModal" title="另存为模板" @ok="handleSubmit">
    <BasicForm @register="registerForm" />
  </BasicModal>
</template>