<template>
|
<Dialog v-model="dialogVisible" :title="dialogTitle">
|
<el-form
|
ref="formRef"
|
v-loading="formLoading"
|
:model="formData"
|
:rules="formRules"
|
label-width="80px"
|
>
|
<el-row :gutter="8">
|
<el-col :span="12">
|
<el-form-item label="key" prop="settingKey">
|
<el-input v-model="formData.settingKey" placeholder=""/>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="参数名称" prop="name">
|
<el-input v-model="formData.name" placeholder=""/>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row :gutter="8">
|
<el-col :span="12">
|
<el-form-item label="输入类型" prop="type">
|
<el-select v-model="formData.type" @change="typeChange">
|
<el-option
|
v-for="item in getDictOptions(DICT_TYPE.MODEL_METHOD_SETTING_TYPE)"
|
:key="item.value"
|
:label="item.label"
|
:value="item.value"
|
/>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="参数类型" prop="valueType">
|
<el-select v-model="formData.valueType">
|
<el-option
|
v-for="item in getDictOptions(DICT_TYPE.MODEL_METHOD_SETTING_VALUE_TYPE)"
|
:key="item.value"
|
:label="item.label"
|
:value="item.value"
|
:disabled="valueTypeSelectDisabled(item.value)"
|
/>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<div v-if="formData.type === 'input'">
|
<el-row :gutter="8">
|
<el-col :span="8">
|
<el-form-item label="默认值" prop="value">
|
<el-input v-model="formData.value" placeholder=""/>
|
</el-form-item>
|
</el-col>
|
<el-col :span="8">
|
<el-form-item label="最大值" prop="max">
|
<el-input-number v-model="formData.max" placeholder=""/>
|
</el-form-item>
|
</el-col>
|
<el-col :span="8">
|
<el-form-item label="最小值" prop="min">
|
<el-input-number v-model="formData.min" placeholder=""/>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
</div>
|
<div v-if="formData.type === 'select'">
|
<el-divider content-position="left">选项信息</el-divider>
|
<el-row :gutter="8">
|
<el-col :span="4">
|
<el-button type="primary" size="small" @click="addRow()">新增</el-button>
|
</el-col>
|
</el-row>
|
<el-table :data="formData.settingSelects" border>
|
<el-table-column
|
prop=""
|
label="key"
|
align="center">
|
<template #default="scope">
|
<el-input size="small" v-model="scope.row.selectKey" maxlength="50" clearable />
|
</template>
|
</el-table-column>
|
<el-table-column
|
prop=""
|
label="name"
|
align="center">
|
<template #default="scope">
|
<el-input size="small" v-model="scope.row.name" maxlength="50" clearable />
|
</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>
|
</div>
|
</el-form>
|
<template #footer>
|
<el-button type="primary" @click="submitForm">确 定</el-button>
|
<el-button @click="dialogVisible = false">取 消</el-button>
|
</template>
|
</Dialog>
|
</template>
|
<script lang="ts" setup>
|
import {DICT_TYPE,getDictOptions} from '@/utils/dict';
|
import * as ProjectApi from '@/api/mpk/project'
|
import * as MpkApi from '@/api/mpk/mpk'
|
import {FormRules} from 'element-plus'
|
import {generateUUID} from "@/utils";
|
import {func} from "vue-types";
|
|
|
const {t} = useI18n() // 国际化
|
const message = useMessage() // 消息弹窗
|
|
const dialogVisible = ref(false) // 弹窗的是否展示
|
const dialogTitle = ref('参数设置') // 弹窗的标题
|
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
const formData = ref({
|
settingKey: undefined,
|
name: undefined,
|
type: undefined,
|
valueType: undefined,
|
value: undefined,
|
max: undefined,
|
min: undefined,
|
settingSelects: []
|
})
|
|
|
const formRules = reactive<FormRules>({
|
settingKey: [
|
{required: true, message: 'key不能为空', trigger: 'blur'},
|
],
|
name: [
|
{required: true, message: '参数名称不能为空', trigger: 'blur'},
|
],
|
type: [
|
{required: true, message: '输入类型不能为空', trigger: 'blur'},
|
],
|
valueType: [
|
{required: true, message: '参数类型不能为空', trigger: 'blur'},
|
]
|
})
|
|
const formRef = ref() // 表单 Ref
|
|
let methodSettingsRef = undefined
|
let infoRef = undefined
|
/** 打开弹窗 */
|
const open = async (info,methodSettings) => {
|
dialogVisible.value = true
|
resetForm()
|
// 修改时,设置数据
|
if (info) {
|
infoRef = info
|
formLoading.value = true
|
try {
|
formData.value = {...info}
|
} finally {
|
formLoading.value = false
|
}
|
}else {
|
methodSettingsRef = methodSettings
|
}
|
}
|
defineExpose({open}) // 提供 open 方法,用于打开弹窗
|
|
|
// 数据回调
|
const emit = defineEmits(['addSettingCallback'])
|
/** 提交表单 */
|
const submitForm = async () => {
|
// 校验表单
|
if (!formRef) return
|
const valid = await formRef.value.validate()
|
if (!valid) return
|
|
//校验select
|
if (formData.value.type === 'select') {
|
if (formData.value.settingSelects?.length === 0) {
|
message.error('选项为空');
|
return
|
}
|
}
|
|
// 提交请求
|
formLoading.value = true
|
try {
|
if (infoRef) {
|
// 修改
|
for (let key in formData.value) {
|
infoRef[key] = formData.value[key];
|
}
|
}else {
|
// 新增
|
methodSettingsRef.push({...formData.value})
|
}
|
dialogVisible.value = false
|
} finally {
|
formLoading.value = false
|
}
|
}
|
|
/** 重置表单 */
|
const resetForm = () => {
|
formData.value = {
|
settingKey: undefined,
|
name: undefined,
|
type: undefined,
|
valueType: undefined,
|
value: undefined,
|
max: undefined,
|
min: undefined,
|
settingSelects: []
|
}
|
formRef.value?.resetFields()
|
}
|
|
const valueTypeSelectDisabled = (value) => {
|
const type = formData.value.type;
|
switch (type) {
|
case "input":
|
if (['int','decimal','decimalArray','string'].includes(value)) {
|
return false
|
}else {
|
return true
|
}
|
case "file":
|
if (['file'].includes(value)) {
|
return false
|
}else {
|
return true
|
}
|
case "select":
|
if (['int','string'].includes(value)) {
|
return false
|
}else {
|
return true
|
}
|
default :
|
return true
|
}
|
}
|
|
const typeChange = () => {
|
formData.value.valueType = undefined
|
formData.value.value = undefined
|
formData.value.max = undefined
|
formData.value.min = undefined
|
formData.value.settingSelects = []
|
}
|
|
const addRow = function () {
|
formData.value.settingSelects.push({
|
selectKey: '',
|
name: ''
|
})
|
}
|
const deleteRow = function (index) {
|
formData.value.settingSelects.splice(index, 1)
|
}
|
</script>
|