提交 | 用户 | 时间
|
9ec4bd
|
1 |
<template> |
潘 |
2 |
<Dialog v-model="dialogVisible" :title="dialogTitle"> |
b8017e
|
3 |
<el-form |
潘 |
4 |
ref="formRef" |
|
5 |
:model="formData" |
|
6 |
:rules="formRules" |
|
7 |
label-width="0px" |
|
8 |
> |
|
9 |
<el-form-item prop="pyName"> |
|
10 |
<el-input v-model="formData.pyName" readonly /> |
|
11 |
</el-form-item> |
|
12 |
<el-form-item prop="remark"> |
|
13 |
<el-input |
|
14 |
type="textarea" |
|
15 |
:rows="4" |
|
16 |
placeholder="备注" |
|
17 |
v-model="formData.remark"/> |
|
18 |
</el-form-item> |
|
19 |
</el-form> |
9ec4bd
|
20 |
<div style="width: 100%;display: flex;flex-direction: row;justify-content: end;margin-top: 16px"> |
31bb5f
|
21 |
<el-button :loading="loading" @click="generatorCode()" type="primary">生成</el-button> |
9ec4bd
|
22 |
</div> |
潘 |
23 |
</Dialog> |
|
24 |
</template> |
|
25 |
<script lang="ts" setup> |
aff5c9
|
26 |
import * as MpkApi from '@/api/model/mpk/mpk' |
9ec4bd
|
27 |
import download from "@/utils/download"; |
潘 |
28 |
import {formatToDateString} from "@/utils/dateUtil"; |
|
29 |
|
|
30 |
|
|
31 |
const { t } = useI18n() // 国际化 |
|
32 |
const message = useMessage() // 消息弹窗 |
|
33 |
|
|
34 |
const dialogVisible = ref(false) // 弹窗的是否展示 |
|
35 |
const dialogTitle = ref('生成代码') // 弹窗的标题 |
|
36 |
|
b8017e
|
37 |
const formData = ref({ |
潘 |
38 |
id: undefined, |
|
39 |
pyName: '', |
|
40 |
zipFileName: '', |
|
41 |
remark: '' |
|
42 |
}) |
|
43 |
const formRules = reactive({ |
|
44 |
}) |
|
45 |
const formRef = ref() |
9ec4bd
|
46 |
|
潘 |
47 |
/** 打开弹窗 */ |
|
48 |
const open = async (modelId: string,pyName: string) => { |
|
49 |
dialogVisible.value = true |
b8017e
|
50 |
resetForm() |
潘 |
51 |
formData.value.id = modelId |
|
52 |
formData.value.pyName = pyName |
|
53 |
formData.value.zipFileName = pyName + '_' + formatToDateString(new Date()) + '.zip'; |
9ec4bd
|
54 |
} |
潘 |
55 |
defineExpose({ open }) // 提供 open 方法,用于打开弹窗 |
|
56 |
|
31bb5f
|
57 |
// 代码生成loading |
D |
58 |
const loading = ref(false) |
9ec4bd
|
59 |
/** 提交表单 */ |
潘 |
60 |
const generatorCode = async () => { |
31bb5f
|
61 |
try { |
D |
62 |
loading.value = true |
|
63 |
const data = await MpkApi.generatorCode(formData.value) |
|
64 |
download.zip(data, formData.value.zipFileName) |
|
65 |
}finally { |
de019e
|
66 |
loading.value = false |
31bb5f
|
67 |
dialogVisible.value = false |
D |
68 |
} |
|
69 |
|
9ec4bd
|
70 |
} |
b8017e
|
71 |
/** 重置表单 */ |
潘 |
72 |
const resetForm = () => { |
|
73 |
formData.value = { |
|
74 |
id: undefined, |
|
75 |
zipFileName: '', |
|
76 |
remark: '' |
|
77 |
} |
|
78 |
formRef.value?.resetFields() |
|
79 |
} |
9ec4bd
|
80 |
</script> |