<template>
|
<Dialog v-model="dialogVisible" :title="dialogTitle">
|
<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 :loading="loading" @click="generatorCode()" type="primary">生成</el-button>
|
</div>
|
</Dialog>
|
</template>
|
<script lang="ts" setup>
|
import * as MpkApi from '@/api/model/mpk/mpk'
|
import download from "@/utils/download";
|
import {formatToDateString} from "@/utils/dateUtil";
|
|
|
const { t } = useI18n() // 国际化
|
const message = useMessage() // 消息弹窗
|
|
const dialogVisible = ref(false) // 弹窗的是否展示
|
const dialogTitle = 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
|
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 () => {
|
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 resetForm = () => {
|
formData.value = {
|
id: undefined,
|
zipFileName: '',
|
remark: ''
|
}
|
formRef.value?.resetFields()
|
}
|
</script>
|