<template>
|
<div class="p-16px" style="background-color: #ffffff">
|
<el-header>
|
{{title}}
|
</el-header>
|
<el-main>
|
<el-form
|
ref="formRef"
|
v-loading="formLoading"
|
:model="formData"
|
:rules="formRules"
|
label-width="120px"
|
>
|
<el-divider content-position="left">模型信息</el-divider>
|
<el-row :gutter="8">
|
<el-col :span="12">
|
<el-form-item label="模型类型" prop="pyType">
|
<el-radio-group v-model="formData.pyType" @change="pyTypeChange">
|
<el-radio-button :disabled="actionType == 'edit'"
|
v-for="dict in getDictOptions(DICT_TYPE.MODEL_TYPE)"
|
:key="dict.label"
|
:label="dict.value"
|
>
|
{{ dict.label }}
|
</el-radio-button>
|
</el-radio-group>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row :gutter="8">
|
<el-col :span="12">
|
<el-form-item label="模型文件" prop="pyName">
|
<el-input disabled v-model="formData.pyName" placeholder=""/>
|
</el-form-item>
|
</el-col>
|
<el-col :span="4">
|
<el-upload
|
ref="uploadRef"
|
v-model:file-list="fileList"
|
:show-file-list="false"
|
:action="importUrl"
|
:auto-upload="true"
|
:disabled="uploadLoading"
|
v-loading="uploadLoading"
|
:before-upload="beforeUpload"
|
:headers="uploadHeaders"
|
:on-error="submitFormError"
|
:on-success="submitFormSuccess"
|
accept=".py"
|
>
|
<el-tooltip content="上传.py算法文件" placement="top" effect="light">
|
<el-button type="primary">
|
<Icon icon="ep:upload"/>
|
模型上传
|
</el-button>
|
</el-tooltip>
|
</el-upload>
|
</el-col>
|
</el-row>
|
<el-row :gutter="8">
|
<el-col :span="12">
|
<el-form-item label="模型名称" prop="pyChineseName">
|
<el-input v-model="formData.pyChineseName" placeholder=""/>
|
</el-form-item>
|
</el-col>
|
|
</el-row>
|
<el-row :gutter="8">
|
<el-col :span="12">
|
<el-form-item label="包名" prop="pkgName">
|
<el-select v-model="formData.pkgName" clearable filterable placeholder="请选择包名">
|
<el-option
|
v-for="item in pkgNameList"
|
:key="item.packName"
|
:label="item.packName"
|
:value="item.packName"
|
>
|
<span style="float: left">{{ item.packName}}</span>
|
<span
|
style="
|
float: right;
|
color: var(--el-text-color-secondary);
|
font-size: 13px;">
|
{{ item.packDesc}}
|
</span>
|
</el-option>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row :gutter="8">
|
<el-col :span="12">
|
<el-form-item label="所属目录" prop="menuAndGroup">
|
<el-cascader
|
style="width: 100%;"
|
v-model="formData.menuAndGroup"
|
:options="treeData"
|
@change="handleChange"
|
/>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row :gutter="8">
|
<el-col :span="12">
|
<el-form-item label="图标" prop="icon">
|
<el-select v-model="formData.icon" clearable filterable placeholder="请选择图标">
|
<el-option
|
v-for="item in iconList"
|
:key="item.iconName"
|
:label="item.iconName"
|
:value="item.iconName"
|
>
|
<span style="float: left">{{ item.iconName}}</span>
|
<span
|
style="
|
float: right;
|
color: var(--el-text-color-secondary);
|
font-size: 13px;">
|
<img :src="staticDir + 'SimtreeUnitImage/' + item.iconName" style="height: 24px;" :alt=" item.iconDesc" />
|
</span>
|
</el-option>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row :gutter="20">
|
<el-col :span="12">
|
<el-form-item label="备注" prop="remark">
|
<el-input v-model="formData.remark" placeholder="" type="textarea"/>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-divider content-position="left">模型方法</el-divider>
|
<el-row :gutter="20">
|
<el-col :span="4">
|
<el-button type="primary" size="small" @click="addRow()" >新增</el-button>
|
</el-col>
|
</el-row>
|
<el-table :data="formData.modelMethods" border
|
@expand-change="methodExpandChange" :expand-row-keys="methodExpandedRowKeys" :row-key="row => row.id">
|
<el-table-column
|
prop=""
|
label="方法名"
|
align="center"
|
width="250">
|
<template #default="scope">
|
<el-input size="small" v-model="scope.row.methodName" placeholder=""/>
|
</template>
|
</el-table-column>
|
<el-table-column
|
prop=""
|
label="输入个数"
|
align="center">
|
<template #default="scope">
|
<el-input-number size="small" step-strictly v-model="scope.row.dataLength" :min="1"
|
:max="50"/>
|
</template>
|
</el-table-column>
|
<el-table-column
|
prop=""
|
label="是否有model"
|
align="center">
|
<template #default="scope">
|
<el-switch size="small" v-model="scope.row.model" :active-value="1"
|
:inactive-value="0"/>
|
</template>
|
</el-table-column>
|
<el-table-column
|
prop=""
|
label="结果key"
|
align="center">
|
<template #default="scope">
|
<el-input size="small" v-model="scope.row.resultKey"/>
|
</template>
|
</el-table-column>
|
<el-table-column label="方法参数" type="expand" width="100px">
|
<template #default="props">
|
<div class="m-16px">
|
<el-button type="primary" size="small" @click="addSetting(props.row.methodSettings)">新增参数</el-button>
|
<el-table :data="props.row.methodSettings" border size="small">
|
<el-table-column align="center" label="key" prop="settingKey"/>
|
<el-table-column align="center" label="参数名称" prop="name"/>
|
<el-table-column align="center" label="参数默认值" prop="value"/>
|
<el-table-column align="center" label="输入类型" prop="type">
|
<template #default="props">
|
<div class="flex file-row justify-center items-center">
|
{{props.row.type}}
|
<div class="ml-8px" v-if="props.row.type === 'select'">
|
<el-popover placement="left" :width="400">
|
<template #reference>
|
<el-button size="small" link type="primary">
|
<Icon icon="ep:more" />
|
</el-button>
|
</template>
|
<el-table width="50%" :data="props.row.settingSelects" border size="small">
|
<el-table-column align="center" label="key" prop="selectKey"/>
|
<el-table-column align="center" label="name" prop="name"/>
|
</el-table>
|
</el-popover>
|
</div>
|
</div>
|
</template>
|
</el-table-column>
|
<el-table-column align="center" label="参数类型" prop="valueType"/>
|
<el-table-column align="center" label="最大值" prop="max"/>
|
<el-table-column align="center" label="最小值" prop="min"/>
|
<el-table-column label="操作" fixed="right" header-align="center" align="center" width="100">
|
<template #default="scope">
|
<el-button
|
@click="updateSetting(scope.row)"
|
key="danger"
|
type="primary"
|
:disabled="scope.row.settingKey === 'pyFile'"
|
link
|
>修改
|
</el-button>
|
<el-button
|
@click="deleteSetting(props.row.methodSettings,scope.$index)"
|
key="danger"
|
type="danger"
|
:disabled="scope.row.settingKey === 'pyFile'"
|
link
|
>删除
|
</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
</div>
|
</template>
|
</el-table-column>
|
<el-table-column label="操作" fixed="right" header-align="center" align="center" width="100">
|
<template #default="scope">
|
<el-button
|
@click="deleteRow(scope.$index)"
|
key="danger"
|
type="danger"
|
link
|
>删除
|
</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
</el-form>
|
</el-main>
|
<el-footer>
|
<div class="flex flex-row justify-end items-center">
|
<el-button type="primary" @click="submitForm">确 定</el-button>
|
</div>
|
</el-footer>
|
</div>
|
<SettingForm ref="settingFormRef"/>
|
</template>
|
<script lang="ts" setup>
|
import {DICT_TYPE, getDictOptions, getIntDictOptions} from '@/utils/dict'
|
import * as MpkApi from '@/api/model/mpk/mpk'
|
import * as MpkIconApi from '@/api/model/mpk/icon'
|
import * as MpkPackApi from '@/api/model/mpk/pack'
|
import * as MpkMenuApi from '@/api/model/mpk/menu'
|
import {FormRules} from 'element-plus'
|
import {getAccessToken, getTenantId} from "@/utils/auth";
|
import SettingForm from './SettingForm.vue'
|
import {generateUUID} from "@/utils";
|
|
const {t} = useI18n() // 国际化
|
const message = useMessage() // 消息弹窗
|
const title = ref('') // 弹窗的标题
|
const actionType = ref('') // 操作类型
|
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
const formType = ref('') // 表单的类型:create - 新增;update - 修改
|
const route = useRoute() // 路由
|
const router = useRouter();
|
|
const staticDir = ref(import.meta.env.VITE_STATIC_DIR)
|
|
const treeData = ref([])
|
const iconList = ref([] as MpkIconApi.MpkIconVO)
|
const pkgNameList = ref([] as MpkPackApi.MpkPackVO)
|
|
/** settingForm弹窗 */
|
const settingFormRef = ref()
|
// 添加setting
|
const addSetting = (methodSettings) => {
|
settingFormRef.value.open(undefined,methodSettings)
|
}
|
|
// 修改setting
|
const updateSetting = (info) => {
|
settingFormRef.value.open(info)
|
}
|
// 删除setting
|
const deleteSetting = (methodSettings,index) => {
|
methodSettings.splice(index, 1);
|
}
|
|
const methodExpandedRowKeys = ref([])
|
const methodExpandChange = async (row: any, expandedRows: any[]) => {
|
methodExpandedRowKeys.value = expandedRows.map(e => e.id)
|
}
|
|
const formData = ref({
|
id: route.params.id,
|
pyChineseName: undefined,
|
pyName: undefined,
|
pkgName: undefined,
|
pyType: 'predict',
|
className: undefined,
|
pyModule: undefined,
|
icon: undefined,
|
menuName: undefined,
|
groupName: undefined,
|
remark: undefined,
|
modelMethods: [],
|
filePath: undefined,
|
menuAndGroup: [],
|
})
|
|
const formRules = reactive<FormRules>({
|
pyName: [
|
{required: true, message: '模型名称不能为空,请上传模型文件', trigger: 'blur'}
|
],
|
pyChineseName: [
|
{required: true, message: '模型中文名称不能为空', trigger: 'blur'}
|
],
|
pyType: [
|
{required: true, message: '模型类型不能为空', trigger: 'blur'}
|
],
|
pkgName: [
|
{required: true, message: '包名不能为空', trigger: 'blur'}
|
],
|
className: [
|
{required: true, message: '类名不能为空', trigger: 'blur'}
|
],
|
menuAndGroup: [
|
{required: true, message: '所属目录不能为空', trigger: 'blur'}
|
],
|
})
|
|
const formRef = ref() // 表单 Ref
|
|
/** 提交表单 */
|
const submitForm = async () => {
|
// 校验表单
|
if (!formRef) return
|
const valid = await formRef.value.validate()
|
if (!valid) return
|
// 模型方法校验
|
if (formData.value.modelMethods?.length <= 0) {
|
message.error('模型方法为空')
|
return
|
}
|
// 模型方法名称校验
|
if (formData.value.modelMethods.some(e => e.methodName === undefined || e.methodName === '' || e.dataLength === undefined || e.dataLength === null)) {
|
message.error('存在不合法模型方法名')
|
return
|
}
|
// 提交请求
|
formLoading.value = true
|
try {
|
const data = formData.value as unknown as MpkApi.MpkVO
|
if (formType.value === 'create') {
|
await MpkApi.createMpk(data)
|
message.success(t('common.createSuccess'))
|
} else {
|
await MpkApi.updateMpk(data)
|
message.success(t('common.updateSuccess'))
|
}
|
} finally {
|
formLoading.value = false
|
}
|
// router.push({path:'/model/mpk'})
|
router.back()
|
}
|
|
/** 重置表单 */
|
const resetForm = () => {
|
formData.value = {
|
id: undefined,
|
pyName: undefined,
|
pyChineseName: undefined,
|
pkgName: undefined,
|
pyType: 'predict',
|
className: undefined,
|
pyModule: undefined,
|
icon: undefined,
|
menuName: undefined,
|
groupName: undefined,
|
remark: undefined,
|
modelMethods: [],
|
filePath: undefined
|
}
|
formRef.value?.resetFields()
|
}
|
|
const handleChange = function () {
|
|
}
|
|
const addRow = function () {
|
formData.value.modelMethods.push({
|
id: generateUUID(),
|
methodName: undefined,
|
dataLength: 1,
|
model: 0,
|
resultKey: undefined,
|
methodSettings: []
|
})
|
}
|
const deleteRow = function (index) {
|
formData.value.modelMethods.splice(index, 1)
|
}
|
|
const fileList = ref([]) // 文件列表
|
const importUrl = import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL + '/model/mpk/file/upload'
|
const uploadLoading = ref(false) // 表单的加载中
|
const uploadHeaders = ref() // 上传 Header 头
|
const beforeUpload = function (file) {
|
// 提交请求
|
uploadHeaders.value = {
|
Authorization: 'Bearer ' + getAccessToken(),
|
'tenant-id': getTenantId()
|
}
|
uploadLoading.value = true
|
return true;
|
}
|
const submitFormError = (): void => {
|
message.error('上传失败!')
|
uploadLoading.value = false
|
}
|
const submitFormSuccess = (response: any) => {
|
if (response.code !== 0) {
|
message.error(response.msg)
|
uploadLoading.value = false
|
return
|
}
|
const data = response.data;
|
formData.value.filePath = data.filePath
|
formData.value.pyName = data.fileName
|
message.success('上传成功')
|
uploadLoading.value = false
|
}
|
|
onMounted(async () => {
|
const id = formData.value.id;
|
const type = id ? 'edit' : 'create'
|
actionType.value = type
|
title.value = t('action.' + type)
|
formType.value = type
|
resetForm()
|
pyTypeChange()
|
// 修改时,设置数据
|
if (id) {
|
formLoading.value = true
|
try {
|
debugger
|
formData.value = await MpkApi.getMpk(id)
|
debugger
|
} finally {
|
formLoading.value = false
|
}
|
}
|
|
// 加载图标列表
|
iconList.value = await MpkIconApi.getList()
|
|
pkgNameList.value = await MpkPackApi.getList()
|
|
// 加载菜单,分组
|
treeData.value = await MpkMenuApi.getTree()
|
})
|
|
const pyTypeChange = () => {
|
if (formData.value.pyType === 'predict') {
|
formData.value.modelMethods = [
|
{
|
id: generateUUID(),
|
methodName: 'train',
|
dataLength: 1,
|
model: 0,
|
resultKey: 'result',
|
methodSettings: []
|
},
|
{
|
|
id: generateUUID(),
|
methodName: 'predict',
|
dataLength: 1,
|
model: 1,
|
resultKey: undefined,
|
methodSettings: []
|
}
|
]
|
}else {
|
formData.value.modelMethods = [
|
{
|
id: generateUUID(),
|
methodName: 'schedul',
|
dataLength: 1,
|
model: 0,
|
resultKey: undefined,
|
methodSettings: []
|
}
|
]
|
}
|
}
|
</script>
|
|
<style scoped lang="scss">
|
</style>
|