2024-11-28 14:30:49 +08:00
|
|
|
<template>
|
2024-12-02 08:50:21 +08:00
|
|
|
<el-dialog v-model="dialogVisible" :title="dialogTitle"
|
|
|
|
|
v-bind="dialogSmall" @close="close">
|
2024-11-28 14:30:49 +08:00
|
|
|
<div>
|
2024-12-02 08:50:21 +08:00
|
|
|
<el-form :model="formContent" ref="dialogFormRef" :rules="rules">
|
|
|
|
|
<el-form-item label="参数所属" prop="pId" :label-width="100">
|
|
|
|
|
<el-tree-select
|
|
|
|
|
v-model="displayPid"
|
|
|
|
|
:data="tableData"
|
|
|
|
|
check-strictly
|
|
|
|
|
:render-after-expand="false"
|
|
|
|
|
show-checkbox
|
|
|
|
|
check-on-click-node
|
|
|
|
|
node-key="id"
|
|
|
|
|
:props="defaultProps"
|
|
|
|
|
/>
|
|
|
|
|
</el-form-item>
|
2024-12-13 16:35:27 +08:00
|
|
|
<el-form-item label="源参数描述" :label-width="100" prop="desc">
|
|
|
|
|
<el-input v-model="formContent.desc" autocomplete="off"/>
|
2024-12-02 08:50:21 +08:00
|
|
|
</el-form-item>
|
2024-12-13 16:35:27 +08:00
|
|
|
<el-form-item label="源参数类型" :label-width="100" prop="type">
|
|
|
|
|
<el-input v-model="formContent.type" autocomplete="off"/>
|
2024-12-02 08:50:21 +08:00
|
|
|
</el-form-item>
|
2024-12-03 09:50:15 +08:00
|
|
|
<el-form-item label="源参数值" :label-width="100"
|
2024-12-13 16:35:27 +08:00
|
|
|
prop="value">
|
|
|
|
|
<el-input v-model="formContent.value" autocomplete="off"/>
|
2024-12-02 08:50:21 +08:00
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="排序" :label-width="100">
|
|
|
|
|
<el-input-number v-model="formContent.sort" :min='1' :max='999'/>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
2024-11-28 14:30:49 +08:00
|
|
|
</div>
|
2024-12-02 08:50:21 +08:00
|
|
|
<template #footer>
|
|
|
|
|
<div class="dialog-footer">
|
|
|
|
|
<el-button @click="close()">取消</el-button>
|
|
|
|
|
<el-button type="primary" @click="save()">
|
|
|
|
|
保存
|
|
|
|
|
</el-button>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
</el-dialog>
|
2024-11-28 14:30:49 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2024-12-03 09:50:15 +08:00
|
|
|
import {computed, defineEmits, reactive, watch} from 'vue'
|
2024-12-02 08:50:21 +08:00
|
|
|
import {dialogSmall} from "@/utils/elementBind"
|
|
|
|
|
import {TestSource} from "@/api/device/interface/testSource"
|
|
|
|
|
import {ElMessage, FormItemRule} from "element-plus"
|
|
|
|
|
|
|
|
|
|
defineProps<{
|
|
|
|
|
tableData: TestSource.ParameterType[]
|
|
|
|
|
}>()
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits(['get-parameter'])
|
|
|
|
|
|
|
|
|
|
// 计算属性,用于控制显示的 pid
|
|
|
|
|
const displayPid = computed({
|
|
|
|
|
get: () => {
|
2024-12-03 09:50:15 +08:00
|
|
|
|
2024-12-02 08:50:21 +08:00
|
|
|
return formContent.pId === '0' ? '' : formContent.pId;
|
|
|
|
|
},
|
|
|
|
|
set: (value) => {
|
2024-12-03 09:50:15 +08:00
|
|
|
|
2024-12-02 08:50:21 +08:00
|
|
|
formContent.pId = value;
|
|
|
|
|
}
|
2024-12-03 09:50:15 +08:00
|
|
|
|
2024-12-02 08:50:21 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 树形节点配置
|
|
|
|
|
const defaultProps = {
|
|
|
|
|
children: 'children',
|
2024-12-13 16:35:27 +08:00
|
|
|
label: 'desc',
|
2024-12-02 08:50:21 +08:00
|
|
|
value: 'id'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const dialogFormRef = ref()
|
|
|
|
|
const {dialogVisible, titleType, formContent} = useMetaInfo()
|
|
|
|
|
|
|
|
|
|
function useMetaInfo() {
|
|
|
|
|
const dialogVisible = ref(false)
|
|
|
|
|
const titleType = ref('add')
|
|
|
|
|
|
|
|
|
|
const formContent = reactive<TestSource.ParameterType>({
|
|
|
|
|
id: "",
|
2024-12-13 16:35:27 +08:00
|
|
|
type: "",
|
2024-12-16 11:34:12 +08:00
|
|
|
value: null,
|
2024-12-13 16:35:27 +08:00
|
|
|
desc: "",
|
2024-12-02 08:50:21 +08:00
|
|
|
sort: 100,
|
|
|
|
|
pId: "0",
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return {dialogVisible, titleType, formContent}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const rules: reactive<Record<string, Array<FormItemRule>>> = reactive({
|
2024-12-13 16:35:27 +08:00
|
|
|
desc: [{required: true, message: '源参数描述必填!', trigger: 'blur'}],
|
|
|
|
|
type: [{required: true, message: '源参数类型必填!', trigger: 'blur'}],
|
2024-12-02 08:50:21 +08:00
|
|
|
sort: [{required: true, message: '排序必填!', trigger: 'blur'}]
|
|
|
|
|
})
|
|
|
|
|
|
2024-12-03 09:50:15 +08:00
|
|
|
// watch(() => formContent.pId, (newVal, oldVal) => {
|
|
|
|
|
|
|
|
|
|
// if (newVal !== '0') {
|
|
|
|
|
// rules.sourceParamValue = [{required: true, message: '源参数值必填!', trigger: 'blur'}]
|
|
|
|
|
// } else {
|
|
|
|
|
// rules.sourceParamValue = []
|
|
|
|
|
// }
|
|
|
|
|
// })
|
2024-12-02 08:50:21 +08:00
|
|
|
|
|
|
|
|
let dialogTitle = computed(() => {
|
|
|
|
|
return titleType.value === 'add' ? '新增源参数' : '编辑源参数'
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const resetFormContent = () => {
|
|
|
|
|
Object.assign(formContent, {
|
|
|
|
|
id: "",
|
2024-12-13 16:35:27 +08:00
|
|
|
type: "",
|
2024-12-16 11:34:12 +08:00
|
|
|
value: null,
|
2024-12-13 16:35:27 +08:00
|
|
|
desc: "",
|
2024-12-02 08:50:21 +08:00
|
|
|
sort: 100,
|
|
|
|
|
pId: "0",
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
const open = (sign: string, data: TestSource.ParameterType) => {
|
|
|
|
|
// 重置表单
|
|
|
|
|
dialogFormRef.value?.resetFields()
|
|
|
|
|
resetFormContent()
|
|
|
|
|
|
|
|
|
|
titleType.value = sign
|
|
|
|
|
dialogVisible.value = true
|
|
|
|
|
if (data.id) {
|
|
|
|
|
Object.assign(formContent, data)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const save = () => {
|
|
|
|
|
try {
|
|
|
|
|
dialogFormRef.value?.validate(async (valid: boolean) => {
|
|
|
|
|
if (valid) {
|
|
|
|
|
let newUpdateParameter = toRaw({...formContent})
|
|
|
|
|
delete newUpdateParameter.children
|
|
|
|
|
emit('get-parameter', newUpdateParameter)
|
|
|
|
|
close()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error('验证过程中出现错误', err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const close = () => {
|
|
|
|
|
dialogVisible.value = false
|
|
|
|
|
resetFormContent()
|
|
|
|
|
dialogFormRef.value?.resetFields()
|
|
|
|
|
}
|
2024-11-28 14:30:49 +08:00
|
|
|
|
2024-12-02 08:50:21 +08:00
|
|
|
defineExpose({open})
|
2024-11-28 14:30:49 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
|
|
|
|
</style>
|