| | |
| | | <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> |
| | |
| | | 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> |