<template>
|
<Dialog v-model="dialogVisible" :title="dialogTitle" width="60%">
|
<el-form
|
ref="formRef"
|
v-loading="formLoading"
|
:model="formData"
|
:rules="formRules"
|
label-width="120px"
|
>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="模型编号" prop="modelCode">
|
<el-input v-model="formData.modelCode" placeholder="请输入模型编号" />
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="模型名称" prop="modelName">
|
<el-input v-model="formData.modelName" placeholder="请输入模型名称" />
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="模型类型" prop="modelType">
|
<el-select v-model="formData.modelType" placeholder="请选择">
|
<el-option
|
v-for="dict in getStrDictOptions(DICT_TYPE.SCHE_MODEL_TYPE)"
|
:key="dict.value"
|
:label="dict.label"
|
:value="dict.value"
|
/>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="调用方式" prop="invocation">
|
<el-select v-model="formData.invocation" placeholder="请选择">
|
<el-option
|
v-for="dict in getStrDictOptions(DICT_TYPE.SCHE_MODEL_INVOCATION)"
|
:key="dict.value"
|
:label="dict.label"
|
:value="dict.value"
|
/>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="24">
|
<el-form-item label="类名" prop="className">
|
<el-input v-model="formData.className" placeholder="请输入类名 " />
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="方法名" prop="methodName">
|
<el-input v-model="formData.methodName" placeholder="请输入方法名 " />
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="参数数量" prop="portLength">
|
<el-input-number v-model="formData.portLength" :min="0" controls-position="right" />
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="24">
|
<el-form-item label="参数构造" prop="paramStructure">
|
<el-input v-model="formData.paramStructure" placeholder="请输入参数构造 " />
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="24">
|
<el-form-item label="模型路径" prop="modelPath">
|
<el-input v-model="formData.modelPath" placeholder="模型路径" />
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-divider content-position="left">输入参数</el-divider>
|
<el-table
|
:data="formData.paramList"
|
border
|
style="width: 100%; margin-top: 5px;">
|
<el-table-column
|
prop=""
|
label="端口"
|
width="100"
|
align="center">
|
<template #default="scope">
|
<el-input size="mini" v-model="scope.row.modelparamportorder" maxlength="5" clearable
|
style="width:100%; hight:100%"/>
|
</template>
|
</el-table-column>
|
<el-table-column
|
prop=""
|
label="序号"
|
width="100"
|
align="center">
|
<template #default="scope">
|
<el-input size="mini" v-model="scope.row.modelparamorder" maxlength="5" clearable
|
style="width:100%;hight:100%"/>
|
</template>
|
</el-table-column>
|
<el-table-column
|
prop=""
|
label="类型"
|
width="150"
|
align="center">
|
<template #default="scope">
|
<el-select v-model="scope.row.modelparamtype" placeholder="请选择">
|
<el-option
|
v-for="dict in getStrDictOptions(DICT_TYPE.MODEL_PARAM_TYPE)"
|
:key="dict.value"
|
:label="dict.label"
|
:value="dict.value"
|
/>
|
</el-select>
|
</template>
|
</el-table-column>
|
<el-table-column
|
prop=""
|
label="参数名称"
|
align="center">
|
<template #default="scope">
|
<el-select
|
size="mini"
|
v-model="scope.row.modelparamid"
|
filterable
|
placeholder="请选择">
|
<el-option
|
v-for="(item, index) in modelparamListMap[scope.row.modelparamtype]"
|
:key="index"
|
:label="item.name"
|
:value="item.id"/>
|
</el-select>
|
</template>
|
</el-table-column>
|
<el-table-column
|
prop=""
|
label="参数长度"
|
width="160"
|
align="center">
|
<template #default="scope">
|
<el-input-number v-model="scope.row.datalength" :min="0" clearable controls-position="right"
|
style="width:100%;hight:100%"/>
|
</template>
|
</el-table-column>
|
<el-table-column
|
prop=""
|
label="操作"
|
width="100"
|
align="center">
|
<template #default="scope">
|
<el-button
|
link
|
@click.prevent="addRow(scope.$index, formData.paramList)"
|
type="primary"
|
size="small">
|
添加
|
</el-button>
|
<el-button
|
link
|
@click.prevent="deleteRow(scope.$index, formData.paramList)"
|
type="primary"
|
size="small">
|
删除
|
</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
|
<el-divider content-position="left">设置参数</el-divider>
|
<el-table
|
:data="formData.settingList"
|
border
|
style="width: 100%; margin-top: 5px;">
|
<el-table-column
|
prop=""
|
label="键"
|
align="center">
|
<template #default="scope">
|
<el-input size="mini" v-model="scope.row.key" maxlength="20" clearable
|
style="width:100%;hight:100%"/>
|
</template>
|
</el-table-column>
|
<el-table-column
|
prop=""
|
label="名称"
|
align="center">
|
<template #default="scope">
|
<el-input size="mini" v-model="scope.row.name" maxlength="20" clearable
|
style="width:100%;hight:100%"/>
|
</template>
|
</el-table-column>
|
<el-table-column
|
prop=""
|
label="类型"
|
align="center">
|
<template #default="scope">
|
<el-select v-model="scope.row.valuetype" placeholder="请选择">
|
<el-option
|
v-for="dict in getStrDictOptions(DICT_TYPE.MODEL_METHOD_SETTING_VALUE_TYPE)"
|
:key="dict.value"
|
:label="dict.label"
|
:value="dict.value"
|
/>
|
</el-select>
|
</template>
|
</el-table-column>
|
<el-table-column
|
prop=""
|
label="值"
|
align="center">
|
<template #default="scope">
|
<el-input size="mini" v-model="scope.row.value" maxlength="256" clearable
|
style="width:100%;hight:100%"/>
|
</template>
|
</el-table-column>
|
<el-table-column
|
prop=""
|
label="操作"
|
width="100"
|
align="center">
|
<template #default="scope">
|
<el-button
|
@click.prevent="addRow(scope.$index, formData.settingList)"
|
link
|
type="primary"
|
size="small">
|
添加
|
</el-button>
|
<el-button
|
@click.prevent="deleteRow(scope.$index, formData.settingList)"
|
link
|
type="primary"
|
size="small">
|
删除
|
</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
</el-form>
|
<template #footer>
|
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button>
|
<el-button @click="dialogVisible = false">取 消</el-button>
|
</template>
|
</Dialog>
|
</template>
|
<script lang="ts" setup>
|
import { DICT_TYPE, getStrDictOptions } from '@/utils/dict'
|
import * as ScheduleModelApi from '@/api/model/sche/model'
|
import { CommonStatusEnum } from '@/utils/constants'
|
|
defineOptions({ name: 'ScheduleModelForm' })
|
|
const { t } = useI18n() // 国际化
|
const message = useMessage() // 消息弹窗
|
const dialogVisible = ref(false) // 弹窗的是否展示
|
const dialogTitle = ref('') // 弹窗的标题
|
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
const formType = ref('') // 表单的类型:create - 新增;update - 修改
|
const formData = ref({
|
id: undefined,
|
modelCode: undefined,
|
modelName: undefined,
|
modelType: undefined,
|
className: undefined,
|
methodName: undefined,
|
portLength: undefined,
|
paramStructure: undefined,
|
modelPath: undefined,
|
resultStrId: undefined,
|
invocation: undefined,
|
status: CommonStatusEnum.ENABLE,
|
paramList: [{
|
modelparamportorder: '1',
|
modelparamorder: '1',
|
modelparamtype: '',
|
modelparamid: '',
|
datalength: ''
|
}],
|
settingList: [{
|
key: '',
|
value: '',
|
valuetype: '',
|
name: ''
|
}]
|
})
|
const formRules = reactive({
|
modelCode: [{ required: true, message: '模型编号不能为空', trigger: 'blur' }],
|
modelName: [{ required: true, message: '模型名称不能为空', trigger: 'blur' }],
|
modelType: [{ required: true, message: '模型类型不能为空', trigger: 'blur' }]
|
})
|
const formRef = ref() // 表单 Ref
|
const modelparamListMap = ref({})
|
|
const addRow = function (index, rows) {
|
let row = JSON.parse(JSON.stringify(rows[index]))
|
rows.splice(index, 0, row)
|
this.orderRow(rows)
|
}
|
|
const deleteRow = function (index, rows) {
|
if (!rows || rows.length === 1) {
|
message.error('不能全部删除!')
|
return
|
}
|
rows.splice(index, 1)
|
this.orderRow(rows)
|
}
|
|
const orderRow = function (rows) {
|
let modelparamorder = 0
|
let modelparamportorder = 0
|
rows.forEach(function (value) {
|
if (value.modelparamportorder !== modelparamportorder) {
|
modelparamportorder = value.modelparamportorder
|
modelparamorder = 1
|
}
|
value.modelparamorder = modelparamorder
|
modelparamorder++
|
})
|
}
|
|
/** 打开弹窗 */
|
const open = async (type: string, id?: number) => {
|
dialogVisible.value = true
|
dialogTitle.value = t('action.' + type)
|
formType.value = type
|
resetForm()
|
// 修改时,设置数据
|
if (id) {
|
formLoading.value = true
|
try {
|
formData.value = await ScheduleModelApi.getScheduleModel(id)
|
} finally {
|
formLoading.value = false
|
}
|
}
|
// 加载参数列表
|
modelparamListMap.value = await ScheduleModelApi.getModelParamList()
|
}
|
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
|
|
/** 提交表单 */
|
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
|
const submitForm = async () => {
|
// 校验表单
|
if (!formRef) return
|
const valid = await formRef.value.validate()
|
if (!valid) return
|
// 提交请求
|
formLoading.value = true
|
try {
|
const data = formData.value as unknown as ScheduleModelApi.ScheduleModelVO
|
if (formType.value === 'create') {
|
await ScheduleModelApi.createScheduleModel(data)
|
message.success(t('common.createSuccess'))
|
} else {
|
await ScheduleModelApi.updateScheduleModel(data)
|
message.success(t('common.updateSuccess'))
|
}
|
dialogVisible.value = false
|
// 发送操作成功的事件
|
emit('success')
|
} finally {
|
formLoading.value = false
|
}
|
}
|
|
/** 重置表单 */
|
const resetForm = () => {
|
formData.value = {
|
id: undefined,
|
modelCode: undefined,
|
modelName: undefined,
|
modelType: undefined,
|
className: undefined,
|
methodName: undefined,
|
portLength: undefined,
|
paramStructure: undefined,
|
modelPath: undefined,
|
resultStrId: undefined,
|
invocation: undefined,
|
status: CommonStatusEnum.ENABLE,
|
paramList: [{
|
modelparamportorder: '1',
|
modelparamorder: '1',
|
modelparamtype: '',
|
modelparamid: '',
|
datalength: ''
|
}],
|
settingList: [{
|
key: '',
|
value: '',
|
valuetype: '',
|
name: ''
|
}]
|
}
|
formRef.value?.resetFields()
|
}
|
</script>
|