Files
pqs-9100_client/frontend/src/views/machine/testScript/components/testScriptPopup.vue

244 lines
8.0 KiB
Vue
Raw Normal View History

2024-11-21 14:42:26 +08:00
<template>
2025-02-17 09:00:27 +08:00
<div>
<el-card style="margin-bottom: 10px" class="cardTop">
2025-02-17 16:44:02 +08:00
<el-form
:model="formContent"
:inline="true"
label-width="auto"
ref="dialogFormRef"
:rules="rules"
class="form-five"
>
2025-02-17 09:00:27 +08:00
<el-form-item label="脚本名称" prop="name">
<el-input v-model.trim="formContent.name" placeholder="请输入脚本名称" clearable />
</el-form-item>
<el-form-item label="参照标准名称" prop="standardName">
<el-input v-model.trim="formContent.standardName" placeholder="请输入参照标准名称" clearable />
</el-form-item>
<el-form-item label="标准推行年份" prop="standardTime">
2025-02-17 16:44:02 +08:00
<el-date-picker
v-model="formContent.standardTime"
style="width: 100%"
type="year"
format="YYYY"
value-format="YYYY"
placeholder="请选择标准推行年份"
/>
2025-02-17 09:00:27 +08:00
</el-form-item>
2025-02-17 16:44:02 +08:00
<el-form-item label="模版类型" prop="type">
<el-select v-model="formContent.type" filterable clearable placeholder="请选择模版类型">
<el-option v-for="item in stencil" :key="item.value" :label="item.name" :value="item.value" />
</el-select>
</el-form-item>
<el-form-item label="检测脚本值类型" prop="valueType">
2025-02-18 16:36:54 +08:00
<el-select
v-model="formContent.valueType"
:disabled="titleType == '编辑检测脚本'"
filterable
clearable
placeholder="请选择值类型"
>
2025-02-17 09:00:27 +08:00
<el-option
v-for="item in dictStore.getDictData('Script_Value_Type')"
:key="item.id"
:label="item.name"
:value="item.id"
2025-02-13 16:15:26 +08:00
/>
2025-02-17 09:00:27 +08:00
</el-select>
</el-form-item>
<el-form-item>
<div class="formBut">
<el-button type="primary" :icon="Select" @click="save">保存</el-button>
<el-button :icon="Close" @click="close">返回</el-button>
</div>
</el-form-item>
</el-form>
</el-card>
2025-02-17 16:44:02 +08:00
<el-card v-if="show">
2025-02-18 16:36:54 +08:00
<TestScriptDetail :options="secondLevelOptions" :formContent="formContent" />
2025-02-17 09:00:27 +08:00
</el-card>
</div>
2024-11-21 14:42:26 +08:00
</template>
2025-02-13 16:15:26 +08:00
<script setup lang="ts">
2025-02-17 16:44:02 +08:00
import { ref, nextTick } from 'vue'
2024-12-24 20:22:36 +08:00
import { useDictStore } from '@/stores/modules/dict'
2025-02-13 16:15:26 +08:00
import TestScriptDetail from '@/views/machine/testScript/components/testScriptDetail.vue'
import { type TestScript } from '@/api/device/interface/testScript'
import type { Dict } from '@/api/system/dictionary/interface'
2025-02-14 16:22:45 +08:00
import { getDictTreeByCode } from '@/api/system/dictionary/dictTree'
2025-02-13 16:15:26 +08:00
import type { CascaderOption } from 'element-plus'
2025-02-17 09:00:27 +08:00
import { Select, Close } from '@element-plus/icons-vue'
2025-02-17 16:44:02 +08:00
import { pqScriptAdd, pqScriptUpdate } from '@/api/device/testScript'
2025-02-17 09:00:27 +08:00
import { useRouter } from 'vue-router'
2024-12-24 20:22:36 +08:00
const modeId = ref()
2025-02-17 09:00:27 +08:00
const show = ref(false)
const router = useRouter()
2025-02-18 16:36:54 +08:00
2025-02-13 16:15:26 +08:00
const secondLevelOptions: any[] = []
2024-11-21 14:42:26 +08:00
// 定义弹出组件元信息
const dialogFormRef = ref()
2024-12-24 20:22:36 +08:00
const dictStore = useDictStore()
2025-02-13 16:15:26 +08:00
function useMetaInfo() {
2024-12-24 20:22:36 +08:00
const titleType = ref('add')
const formContent = ref<TestScript.ResTestScript>({
2025-02-13 16:15:26 +08:00
name: '',
2024-12-24 20:22:36 +08:00
type: '',
2025-02-13 16:15:26 +08:00
valueType: '',
2024-12-24 20:22:36 +08:00
pattern: modeId.value,
standardName: '',
standardTime: '',
2025-02-18 16:36:54 +08:00
state: 1
2024-12-24 20:22:36 +08:00
})
2025-02-17 09:00:27 +08:00
return { titleType, formContent }
2025-02-13 16:15:26 +08:00
}
2025-02-17 16:44:02 +08:00
const stencil = [
{ name: '脚本', value: 0 },
{ name: '模版', value: 1 }
]
const rules = {
name: [{ required: true, message: '请输入脚本名称', trigger: 'blur' }],
standardName: [{ required: true, message: '请输入参照标准名称', trigger: 'blur' }],
standardTime: [{ required: true, message: '请选择标准推行年份', trigger: 'change' }],
type: [{ required: true, message: '请选择模版类型', trigger: 'change' }],
valueType: [{ required: true, message: '请选择检测脚本值类型', trigger: 'change' }]
}
2025-02-13 16:15:26 +08:00
2025-02-17 09:00:27 +08:00
const { titleType, formContent } = useMetaInfo()
2025-02-13 16:15:26 +08:00
// 清空formContent
const resetFormContent = () => {
2024-11-21 14:42:26 +08:00
formContent.value = {
2025-02-13 16:15:26 +08:00
name: '',
2024-12-24 20:22:36 +08:00
type: '',
2025-02-13 16:15:26 +08:00
valueType: '',
2025-02-17 16:44:02 +08:00
pattern: '',
2024-12-24 20:22:36 +08:00
standardName: '',
standardTime: '',
2025-02-13 16:15:26 +08:00
state: 1
2024-11-21 14:42:26 +08:00
}
2025-02-17 09:00:27 +08:00
router.go(-1)
2025-02-13 16:15:26 +08:00
}
// 关闭弹窗
const close = () => {
2024-11-21 14:42:26 +08:00
// 清空dialogForm中的值
resetFormContent()
// 重置表单
dialogFormRef.value?.resetFields()
2025-02-13 16:15:26 +08:00
}
// 关闭信息弹框
2025-02-17 09:00:27 +08:00
const closeInformation = () => {}
2024-11-21 14:42:26 +08:00
2025-02-13 16:15:26 +08:00
// 保存数据
2025-02-17 16:44:02 +08:00
const save = () => {
// dialogFormRef
2025-02-18 16:36:54 +08:00
dialogFormRef.value.validate((valid: boolean) => {
2025-02-17 16:44:02 +08:00
if (valid) {
if (titleType.value == '新增检测脚本') {
formContent.value.pattern = modeId.value
pqScriptAdd(formContent.value).then(res => {
if (res.code === 'A0000') {
ElMessage.success({ message: res.message })
2025-02-19 16:54:54 +08:00
formContent.value.id = JSON.stringify(res.data)
titleType.value == '编辑检测脚本'
2025-02-17 16:44:02 +08:00
show.value = true
}
})
} else {
pqScriptUpdate(formContent.value).then(res => {
if (res.code === 'A0000') {
ElMessage.success({ message: res.message })
}
})
}
}
})
}
2024-11-21 14:42:26 +08:00
// 打开弹窗,可能是新增,也可能是编辑
2025-02-17 16:44:02 +08:00
const open = async (title: string, row: any) => {
titleType.value = title
if (title == '新增检测脚本') {
show.value = false
} else {
let list = JSON.parse(row)
formContent.value = list
show.value = true
}
2025-02-13 16:15:26 +08:00
2025-02-17 16:44:02 +08:00
// 重置表单
dialogFormRef.value?.resetFields()
}
// 获取树字典
const treeInfo = async (currentMode: string) => {
2025-02-18 16:36:54 +08:00
const data: Dict.ResDictTree = {
2025-02-19 16:54:54 +08:00
name: '',
id: '',
pid: '',
pids: '',
code: 'Script_Indicator_Items',
sort: 0
}
2025-02-18 16:36:54 +08:00
const result = await getDictTreeByCode(data)
2025-02-17 09:00:27 +08:00
const allOptions = convertToOptions(result.data as Dict.ResDictTree[])
2025-02-13 16:15:26 +08:00
secondLevelOptions.push(...(allOptions[0]?.children || []))
modeId.value = dictStore.getDictData('Pattern').find(item => item.name === currentMode)?.id
2024-11-21 14:42:26 +08:00
}
2025-02-17 16:44:02 +08:00
2025-02-17 09:00:27 +08:00
onMounted(() => {
let data: any = router.options.history.state
2025-02-17 16:44:02 +08:00
console.log('🚀 ~ onMounted ~ data:', data)
if (data.title == null) return
nextTick(async () => {
await treeInfo(data.mode)
await open(data.title, data.row)
})
2025-02-17 09:00:27 +08:00
})
2024-12-26 09:28:19 +08:00
2025-02-13 16:15:26 +08:00
// 转换函数
const convertToOptions = (dictTree: Dict.ResDictTree[]): CascaderOption[] => {
2024-12-26 09:28:19 +08:00
return dictTree.map(item => ({
value: item.id,
2025-02-19 16:54:54 +08:00
code: item.code.split('-')[1] || item.code.split('-')[0],
2024-12-26 09:28:19 +08:00
label: item.name,
children: item.children ? convertToOptions(item.children) : undefined
2025-02-13 16:15:26 +08:00
}))
}
2024-11-21 14:42:26 +08:00
// 对外映射
defineExpose({ open })
2024-12-24 20:22:36 +08:00
</script>
2025-02-17 09:00:27 +08:00
<style lang="scss" scoped>
2024-12-24 20:22:36 +08:00
/* .dialog-content {
padding: 10px;
} */
2025-02-17 09:00:27 +08:00
:deep(.cardTop) {
.el-card__body {
padding: 20px 0 0 20px;
}
}
.formBut {
width: 100%;
display: flex;
justify-content: end;
}
.form-five {
display: flex;
flex-wrap: wrap;
// justify-content: space-between;
.el-form-item {
display: flex;
2025-02-17 16:44:02 +08:00
width: 15.8%;
2025-02-17 09:00:27 +08:00
.el-form-item__content {
flex: 1;
.el-select,
.el-cascader,
.el-input__inner,
.el-date-editor {
width: 100%;
}
}
}
}
2025-02-13 16:15:26 +08:00
</style>