ExportExcelModal.vue
2.24 KB
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
<template>
<BasicModal
v-bind="$attrs"
:title="t('component.excel.exportModalTitle')"
@ok="handleOk"
@register="registerModal"
>
<BasicForm
:labelWidth="100"
:schemas="schemas"
:showActionButtonGroup="false"
@register="registerForm"
/>
</BasicModal>
</template>
<script lang="ts">
import type { ExportModalResult } from './typing';
import { defineComponent, nextTick } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
import { useI18n } from '/@/hooks/web/useI18n';
const { t } = useI18n();
const schemas: FormSchema[] = [
{
field: 'filename',
component: 'Input',
label: t('component.excel.fileName'),
rules: [{ required: true }],
},
{
field: 'bookType',
component: 'Select',
label: t('component.excel.fileType'),
defaultValue: 'xlsx',
rules: [{ required: true }],
componentProps: {
options: [
{
label: 'xlsx',
value: 'xlsx',
key: 'xlsx',
},
{
label: 'html',
value: 'html',
key: 'html',
},
{
label: 'csv',
value: 'csv',
key: 'csv',
},
{
label: 'txt',
value: 'txt',
key: 'txt',
},
],
},
},
];
export default defineComponent({
components: { BasicModal, BasicForm },
emits: ['success', 'register'],
setup(_, { emit }) {
const [registerForm, { validateFields, resetFields }] = useForm();
const [registerModal, { closeModal }] = useModalInner();
async function handleOk() {
const res = (await validateFields()) as ExportModalResult;
const { filename, bookType } = res;
emit('success', {
filename: `${filename.split('.').shift()}.${bookType}`,
bookType,
});
closeModal();
}
const clearFieldFunc = () => nextTick(() => resetFields());
return {
schemas,
handleOk,
registerForm,
registerModal,
t,
clearFieldFunc,
};
},
});
</script>