From 5c475d3ac8ee98713e0f0962dd9464daccfb9eb1 Mon Sep 17 00:00:00 2001 From: dengzedong <dengzedong@email> Date: 星期四, 28 十一月 2024 18:16:07 +0800 Subject: [PATCH] 模型参数改为output --- src/views/model/mpk/file/MpkGenerator.vue | 69 +++++++++++++++++++++++++--------- 1 files changed, 50 insertions(+), 19 deletions(-) diff --git a/src/views/model/mpk/file/MpkGenerator.vue b/src/views/model/mpk/file/MpkGenerator.vue index 5a86965..47a72ae 100644 --- a/src/views/model/mpk/file/MpkGenerator.vue +++ b/src/views/model/mpk/file/MpkGenerator.vue @@ -1,12 +1,24 @@ <template> <Dialog v-model="dialogVisible" :title="dialogTitle"> - <el-input - type="textarea" - :rows="4" - placeholder="备注" - v-model="remark"/> + <el-form + ref="formRef" + :model="formData" + :rules="formRules" + label-width="0px" + > + <el-form-item prop="pyName"> + <el-input v-model="formData.pyName" readonly /> + </el-form-item> + <el-form-item prop="remark"> + <el-input + type="textarea" + :rows="4" + placeholder="备注" + v-model="formData.remark"/> + </el-form-item> + </el-form> <div style="width: 100%;display: flex;flex-direction: row;justify-content: end;margin-top: 16px"> - <el-button @click="generatorCode()" type="primary">生成</el-button> + <el-button :loading="loading" @click="generatorCode()" type="primary">生成</el-button> </div> </Dialog> </template> @@ -22,28 +34,47 @@ const dialogVisible = ref(false) // 弹窗的是否展示 const dialogTitle = ref('生成代码') // 弹窗的标题 - const remark = ref('') - const id = ref() - const zipFileName = ref() + const formData = ref({ + id: undefined, + pyName: '', + zipFileName: '', + remark: '' + }) + const formRules = reactive({ + }) + const formRef = ref() /** 打开弹窗 */ const open = async (modelId: string,pyName: string) => { dialogVisible.value = true - id.value = modelId; - zipFileName.value = pyName + '_' + formatToDateString(new Date()) + '.zip'; - remark.value = ""; + resetForm() + formData.value.id = modelId + formData.value.pyName = pyName + formData.value.zipFileName = pyName + '_' + formatToDateString(new Date()) + '.zip'; } defineExpose({ open }) // 提供 open 方法,用于打开弹窗 + // 代码生成loading + const loading = ref(false) /** 提交表单 */ const generatorCode = async () => { - const param = { - 'id': id.value, - 'remark': remark.value, - 'zipFileName': zipFileName.value + try { + loading.value = true + const data = await MpkApi.generatorCode(formData.value) + download.zip(data, formData.value.zipFileName) + }finally { + loading.value = false + dialogVisible.value = false } - const data = await MpkApi.generatorCode(param) - download.zip(data, zipFileName.value) - dialogVisible.value = false + + } + /** 重置表单 */ + const resetForm = () => { + formData.value = { + id: undefined, + zipFileName: '', + remark: '' + } + formRef.value?.resetFields() } </script> -- Gitblit v1.9.3