This commit is contained in:
caozehui
2026-06-01 09:26:01 +08:00
parent c05d329614
commit cf3141198b
4 changed files with 215 additions and 153 deletions

View File

@@ -2,43 +2,44 @@ import type { ReqPage, ResPage } from '@/api/interface'
// 检测源模块 // 检测源模块
export namespace TestSource { export namespace TestSource {
/**
/** * 检测源表格分页查询参数
* 检测脚本表格分页查询参数 */
*/ export interface ReqTestSourceParams extends ReqPage {
export interface ReqTestSourceParams extends ReqPage{ id: string
id: string; // 装置序号id 必填 name: string
name: string; pattern: string
pattern: string; }
}
// 检测源接口 // 检测源接口
export interface ResTestSource { export interface ResTestSource {
id: string; //检测源ID id: string
name?: string; //检测源名称(检测源类型 + 设备类型 + 数字自动生成) name?: string
pattern: string;//检测源模式(字典表Code字段数字、模拟、比对) pattern: string
type: string; //检测源类型(字典表Code字段标准源、高精度设备) type: string
devType: string;//检测源设备类型(字典表Code字段) devType: string
parameter?: string;//源参数JSON字符串 maxVoltage?: number
state:number;// maxCurrent?: number
createBy?: string; parameter?: string
createTime?: string; state: number
updateBy?: string; createBy?: string
updateTime?: string; createTime?: string
updateBy?: string
updateTime?: string
} }
/* 检测脚本查询分页返回的对象; /*
*/ * 检测源查询分页返回的对象
export interface ResTestSourcePage extends ResPage<ResTestSource> { */
export interface ResTestSourcePage extends ResPage<ResTestSource> {}
} export interface ParameterType {
export interface ParameterType{ id: string
id:string; type: string
type:string; desc: string
desc:string; value: string | null
value:string|null; sort: number
sort:number; pId: string
pId:string; children?: ParameterType[]
children?:ParameterType[];
} }
} }

View File

@@ -206,6 +206,20 @@ function handleWarningError(stepRef: any, logRef: any, message: string) {
watch(webMsgSend, function (newValue, oldValue) { watch(webMsgSend, function (newValue, oldValue) {
if (testStatus.value !== 'waiting') { if (testStatus.value !== 'waiting') {
switch (newValue.requestId) { switch (newValue.requestId) {
case 'overloadTest':
if (newValue.code === 1) {
handleFatalError(step1, step1InitLog, '电压过载!')
}
if (newValue.code === 2) {
handleFatalError(step1, step1InitLog, '电流过载!')
}
if (newValue.code === 3) {
handleFatalError(step1, step1InitLog, '电压和电流过载!')
}
if (newValue.code === 4) {
handleFatalError(step1, step1InitLog, '过载检测成功!')
}
break;
case 'yjc_ytxjy': case 'yjc_ytxjy':
switch (newValue.operateCode) { switch (newValue.operateCode) {
case 'INIT_GATHER': case 'INIT_GATHER':

View File

@@ -10,7 +10,7 @@
class="form-three" class="form-three"
> >
<el-form-item label="设备类型" prop="devType"> <el-form-item label="设备类型" prop="devType">
<el-select v-model="formContent.devType" placeholder="请选择源型"> <el-select v-model="formContent.devType" placeholder="请选择源设备类型">
<el-option <el-option
v-for="item in dictStore.getDictData(dictTypeCode)" v-for="item in dictStore.getDictData(dictTypeCode)"
:key="item.id" :key="item.id"
@@ -29,6 +29,24 @@
/> />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="最大电压" prop="maxVoltage">
<el-input-number
v-model="formContent.maxVoltage"
:min="0"
:precision="2"
:step="0.1"
style="width: 100%"
/>
</el-form-item>
<el-form-item label="最大电流" prop="maxCurrent">
<el-input-number
v-model="formContent.maxCurrent"
:min="0"
:precision="2"
:step="0.1"
style="width: 100%"
/>
</el-form-item>
</el-form> </el-form>
</div> </div>
@@ -40,7 +58,7 @@
/> />
<template #footer> <template #footer>
<div> <div>
<el-button :disabled="tableIsDisable" @click="close()"> </el-button> <el-button :disabled="tableIsDisable" @click="close()">取消</el-button>
<el-button :disabled="tableIsDisable" type="primary" @click="save()">保存</el-button> <el-button :disabled="tableIsDisable" type="primary" @click="save()">保存</el-button>
</div> </div>
</template> </template>
@@ -49,12 +67,12 @@
<script lang="ts" setup name="ErrorSystemDialog"> <script lang="ts" setup name="ErrorSystemDialog">
import { ElMessage, type FormItemRule } from 'element-plus' import { ElMessage, type FormItemRule } from 'element-plus'
import { computed, Ref, ref } from 'vue' import { computed, ref, type Ref } from 'vue'
import { dialogBig } from '@/utils/elementBind' import { dialogBig } from '@/utils/elementBind'
import { addTestSource, getTestSourceById, updateTestSource } from '@/api/device/testSource/index' import { addTestSource, getTestSourceById, updateTestSource } from '@/api/device/testSource/index'
import { useDictStore } from '@/stores/modules/dict'
import { type TestSource } from '@/api/device/interface/testSource' import { type TestSource } from '@/api/device/interface/testSource'
// 定义弹出组件元信息 import { useDictStore } from '@/stores/modules/dict'
const dialogFormRef = ref() const dialogFormRef = ref()
const dictStore = useDictStore() const dictStore = useDictStore()
const mode = ref() const mode = ref()
@@ -71,13 +89,15 @@ function useMetaInfo() {
parameter: '', parameter: '',
type: '', type: '',
devType: '', devType: '',
maxVoltage: undefined,
maxCurrent: undefined,
state: 1 state: 1
}) })
return { dialogVisible, titleType, formContent } return { dialogVisible, titleType, formContent }
} }
const { dialogVisible, titleType, formContent } = useMetaInfo() const { dialogVisible, titleType, formContent } = useMetaInfo()
// 清空formContent
const resetFormContent = () => { const resetFormContent = () => {
formContent.value = { formContent.value = {
id: '', id: '',
@@ -85,11 +105,13 @@ const resetFormContent = () => {
parameter: '', parameter: '',
type: '', type: '',
devType: '', devType: '',
maxVoltage: undefined,
maxCurrent: undefined,
state: 1 state: 1
} }
} }
let dialogTitle = computed(() => { const dialogTitle = computed(() => {
switch (titleType.value) { switch (titleType.value) {
case 'add': case 'add':
tableIsDisable.value = false tableIsDisable.value = false
@@ -101,45 +123,52 @@ let dialogTitle = computed(() => {
tableIsDisable.value = true tableIsDisable.value = true
return '查看检测源' return '查看检测源'
default: default:
return '' // 默认情况,可选 return ''
} }
}) })
let dictTypeCode = computed(() => { const dictTypeCode = computed(() => {
return 'S_Dev_Type_' + dictStore.getDictData('Pattern').find(item => item.id === modeId.value)?.code return 'S_Dev_Type_' + dictStore.getDictData('Pattern').find(item => item.id === modeId.value)?.code
}) })
// 定义规则
const validateNonNegative = (label: string) => {
return (_rule: FormItemRule, value: number | undefined, callback: (error?: Error) => void) => {
if (value != null && value < 0) {
callback(new Error(`${label} cannot be negative`))
return
}
callback()
}
}
const rules: Ref<Record<string, Array<FormItemRule>>> = ref({ const rules: Ref<Record<string, Array<FormItemRule>>> = ref({
name: [{ required: true, message: '检测源名称必填', trigger: 'blur' }], name: [{ required: true, message: '检测源名称必填', trigger: 'blur' }],
devType: [{ required: true, message: '请选择一项设备类型', trigger: 'change' }], devType: [{ required: true, message: '请选择一项设备类型', trigger: 'change' }],
type: [{ required: true, message: '请选择一项检测源类型', trigger: 'change ' }] type: [{ required: true, message: '请选择一项检测源类型', trigger: 'change' }],
maxVoltage: [{ validator: validateNonNegative('最大电压'), trigger: 'change' }],
maxCurrent: [{ validator: validateNonNegative('最大电流'), trigger: 'change' }]
}) })
// 关闭弹窗
const close = () => { const close = () => {
dialogVisible.value = false dialogVisible.value = false
// 清空dialogForm中的值
resetFormContent() resetFormContent()
// 重置表单
dialogFormRef.value?.resetFields() dialogFormRef.value?.resetFields()
parameterTable.value?.clearData() parameterTable.value?.clearData()
} }
// 保存数据
const save = () => { const save = () => {
try { try {
dialogFormRef.value?.validate(async (valid: boolean) => { dialogFormRef.value?.validate(async (valid: boolean) => {
if (valid) { if (valid) {
if (formContent.value.id) { if (formContent.value.id) {
await updateTestSource(formContent.value) await updateTestSource(formContent.value)
ElMessage.success({ message: `${dialogTitle.value}成功` }) ElMessage.success({ message: `${dialogTitle.value}成功` })
} else { } else {
await addTestSource(formContent.value) await addTestSource(formContent.value)
ElMessage.success({ message: `${dialogTitle.value}成功` }) ElMessage.success({ message: `${dialogTitle.value}成功` })
} }
close() close()
// 刷新表格 await props.refreshTable?.()
await props.refreshTable!()
} }
}) })
} catch (err) { } catch (err) {
@@ -147,7 +176,6 @@ const save = () => {
} }
} }
// 打开弹窗,可能是新增,也可能是编辑
const open = async (sign: string, data: TestSource.ResTestSource, currentMode: string) => { const open = async (sign: string, data: TestSource.ResTestSource, currentMode: string) => {
titleType.value = sign titleType.value = sign
dialogVisible.value = true dialogVisible.value = true
@@ -155,13 +183,25 @@ const open = async (sign: string, data: TestSource.ResTestSource, currentMode: s
modeId.value = dictStore.getDictData('Pattern').find(item => item.name === currentMode)?.id modeId.value = dictStore.getDictData('Pattern').find(item => item.name === currentMode)?.id
if (data.id) { if (data.id) {
const result = await getTestSourceById(data) const result = await getTestSourceById(data)
if (result && result.data) { const sourceData = (result?.data ?? {}) as Partial<TestSource.ResTestSource>
formContent.value = result.data as TestSource.ResTestSource formContent.value = {
id: sourceData.id ?? data.id,
pattern: sourceData.pattern ?? modeId.value,
parameter: sourceData.parameter ?? '',
type: sourceData.type ?? '',
devType: sourceData.devType ?? '',
maxVoltage: sourceData.maxVoltage ?? undefined,
maxCurrent: sourceData.maxCurrent ?? undefined,
state: sourceData.state ?? 1,
name: sourceData.name,
createBy: sourceData.createBy,
createTime: sourceData.createTime,
updateBy: sourceData.updateBy,
updateTime: sourceData.updateTime
} }
} else { } else {
resetFormContent() resetFormContent()
} }
// 重置表单
dialogFormRef.value?.resetFields() dialogFormRef.value?.resetFields()
} }
@@ -169,7 +209,6 @@ const changeParameter = (parameterArr: any) => {
formContent.value.parameter = JSON.stringify(parameterArr) formContent.value.parameter = JSON.stringify(parameterArr)
} }
// 对外映射
defineExpose({ open }) defineExpose({ open })
const props = defineProps<{ const props = defineProps<{
refreshTable: (() => Promise<void>) | undefined refreshTable: (() => Promise<void>) | undefined

View File

@@ -1,115 +1,123 @@
<template> <template>
<div class='table-box'> <div class="table-box">
<ProTable <ProTable ref="proTable" :columns="columns" :request-api="getTableList">
ref='proTable' <template #tableHeader="scope">
:columns='columns' <el-button v-auth.testSource="'add'" type="primary" :icon="CirclePlus" @click="openDialog('add')">
:request-api="getTableList" 新增
> </el-button>
<!-- :data='testSourceData' 如果要显示静态数据就切换该配置--> <el-button
<!-- 表格 header 按钮 --> v-auth.testSource="'delete'"
<template #tableHeader='scope'> type="danger"
<el-button v-auth.testSource="'add'" type='primary' :icon='CirclePlus' @click="openDialog('add')">新增</el-button> :icon="Delete"
<el-button v-auth.testSource="'delete'" type='danger' :icon='Delete' plain
plain :disabled='!scope.isSelected' @click='batchDelete(scope.selectedListIds)'> :disabled="!scope.isSelected"
删除 @click="batchDelete(scope.selectedListIds)"
</el-button> >
</template> 删除
<!-- 表格操作 --> </el-button>
<template #operation='scope'> </template>
<el-button v-auth.testSource="'view'" type='primary' link :icon='View' @click="openDialog('view', scope.row)">查看</el-button> <template #operation="scope">
<el-button v-auth.testSource="'edit'" type='primary' link :icon='EditPen' @click="openDialog('edit', scope.row)">编辑</el-button> <el-button v-auth.testSource="'view'" type="primary" link :icon="View" @click="openDialog('view', scope.row)">
<el-button v-auth.testSource="'delete'" type='primary' link :icon='Delete' @click='handleDelete(scope.row)'>删除</el-button> 查看
</template> </el-button>
<el-button v-auth.testSource="'edit'" type="primary" link :icon="EditPen" @click="openDialog('edit', scope.row)">
</ProTable> 编辑
</el-button>
<el-button
v-auth.testSource="'delete'"
type="primary"
link
:icon="Delete"
@click="handleDelete(scope.row)"
>
删除
</el-button>
</template>
</ProTable>
</div> </div>
<TestSourcePopup :refresh-table='proTable?.getTableList' ref='testSourcePopup' /> <TestSourcePopup :refresh-table="proTable?.getTableList" ref="testSourcePopup" />
</template>
</template> <script setup lang="tsx" name="useRole">
import { type TestSource } from '@/api/device/interface/testSource'
import { useHandleData } from '@/hooks/useHandleData'
import ProTable from '@/components/ProTable/index.vue'
import type { ProTableInstance, ColumnProps } from '@/components/ProTable/interface'
import { CirclePlus, Delete, EditPen, View } from '@element-plus/icons-vue'
import { useDictStore } from '@/stores/modules/dict'
import TestSourcePopup from './components/testSourcePopup.vue'
import { getTestSourceList, deleteTestSource } from '@/api/device/testSource/index'
import { reactive, ref } from 'vue'
import { useModeStore } from '@/stores/modules/mode'
<script setup lang='tsx' name='useRole'> defineOptions({
import { type TestSource } from '@/api/device/interface/testSource' name: 'testSource'
import { useHandleData } from '@/hooks/useHandleData' })
import { useDownload } from '@/hooks/useDownload'
import { useAuthButtons } from '@/hooks/useAuthButtons'
import ProTable from '@/components/ProTable/index.vue'
import ImportExcel from '@/components/ImportExcel/index.vue'
import type{ ProTableInstance, ColumnProps } from '@/components/ProTable/interface'
import { CirclePlus, Delete, EditPen, Share, Download, Upload, View, Refresh } from '@element-plus/icons-vue'
import { useDictStore } from '@/stores/modules/dict'
import TestSourcePopup from './components/testSourcePopup.vue'
import {
getTestSourceList,deleteTestSource,
} from '@/api/device/testSource/index'
import { reactive, ref } from 'vue'
import { useModeStore } from '@/stores/modules/mode'; // 引入模式 store
defineOptions({
name: 'testSource'
})
const testSourcePopup = ref()
const dictStore = useDictStore()
const modeStore = useModeStore();
// ProTable 实例
const proTable = ref<ProTableInstance>()
const getTableList = (params: any) => { const testSourcePopup = ref()
const dictStore = useDictStore()
const modeStore = useModeStore()
const proTable = ref<ProTableInstance>()
let newParams = JSON.parse(JSON.stringify(params)) const getTableList = (params: any) => {
const patternId = dictStore.getDictData('Pattern').find(item=>item.name=== modeStore.currentMode)?.id//获取数据字典中对应的id const newParams = JSON.parse(JSON.stringify(params))
newParams.pattern = patternId const patternId = dictStore.getDictData('Pattern').find(item => item.name === modeStore.currentMode)?.id
return getTestSourceList(newParams) newParams.pattern = patternId
return getTestSourceList(newParams)
} }
// 表格配置项 const columns = reactive<ColumnProps<TestSource.ResTestSource>[]>([
const columns = reactive<ColumnProps<TestSource.ResTestSource>[]>([ { type: 'selection', fixed: 'left', width: 70 },
{ type: 'selection', fixed: 'left', width: 70 ,
},
{ type: 'index', fixed: 'left', width: 70, label: '序号' }, { type: 'index', fixed: 'left', width: 70, label: '序号' },
{ {
prop: 'name', prop: 'name',
label: '名称', label: '名称',
search: { el: 'input' }, search: { el: 'input' },
minWidth: 300, minWidth: 300
}, },
{ {
prop: 'devType', prop: 'devType',
label: '设备类型', label: '设备类型',
enum: dictStore.getDictData('S_Dev_Type_'+dictStore.getDictData('Pattern').find(item=>item.name=== modeStore.currentMode)?.code), enum: dictStore.getDictData(
fieldNames: { label: 'name', value: 'id' }, 'S_Dev_Type_' + dictStore.getDictData('Pattern').find(item => item.name === modeStore.currentMode)?.code
search: { el: 'select' }, ),
minWidth: 250, fieldNames: { label: 'name', value: 'id' },
search: { el: 'select' },
minWidth: 250
}, },
{ {
prop: 'type', prop: 'type',
label: '检测源类型', label: '检测源类型',
enum: dictStore.getDictData('Pq_Source_Type'), enum: dictStore.getDictData('Pq_Source_Type'),
fieldNames: { label: 'name', value: 'id' }, fieldNames: { label: 'name', value: 'id' },
search: { el: 'select' }, search: { el: 'select' },
minWidth: 150, minWidth: 150
}, },
{ prop: 'operation', label: '操作', fixed: 'right', width: 250 }, {
]) prop: 'maxVoltage',
label: '最大电压(V)',
minWidth: 140
},
{
prop: 'maxCurrent',
label: '最大电流(A)',
minWidth: 140
},
{ prop: 'operation', label: '操作', fixed: 'right', width: 250 }
])
// 打开 drawer(新增、编辑)
const openDialog = (titleType: string, row: Partial<TestSource.ResTestSource> = {}) => { const openDialog = (titleType: string, row: Partial<TestSource.ResTestSource> = {}) => {
testSourcePopup.value?.open(titleType, row, modeStore.currentMode)
testSourcePopup.value?.open(titleType, row,modeStore.currentMode)
} }
// 批量删除设备
const batchDelete = async (id: string[]) => { const batchDelete = async (id: string[]) => {
await useHandleData(deleteTestSource, id, '删除所选检测源') await useHandleData(deleteTestSource, id, '删除所选检测源')
proTable.value?.clearSelection() proTable.value?.clearSelection()
proTable.value?.getTableList() proTable.value?.getTableList()
} }
// 删除设备
const handleDelete = async (params: TestSource.ResTestSource) => { const handleDelete = async (params: TestSource.ResTestSource) => {
await useHandleData(deleteTestSource, [params.id], `删除【${params.name}】检测源`) await useHandleData(deleteTestSource, [params.id], `删除【${params.name}】检测源`)
proTable.value?.getTableList() proTable.value?.getTableList()
} }
</script>
</script>