diff --git a/ui/dasadmin/src/views/backend/realData/index.vue b/ui/dasadmin/src/views/backend/realData/index.vue index 1b0f7d00..f62b064d 100644 --- a/ui/dasadmin/src/views/backend/realData/index.vue +++ b/ui/dasadmin/src/views/backend/realData/index.vue @@ -7,7 +7,7 @@
可添加的测点 - + 模拟量 状态量 @@ -16,8 +16,9 @@ - + @selectionChange="selectTable" + :row-key="getRowKey"> + @@ -111,14 +112,8 @@ import {Crop,Download,Top,Bottom} from '@element-plus/icons-vue' import {onMounted, onUnmounted, reactive, ref, watch,computed} from 'vue' import {ElMessage} from 'element-plus' import {equipList,getModelAttributeList,getsnapshotData} from "/@/api/backend/realData/request.ts"; -import * as console from "console"; const tableData = ref() -/*const tableItem0: any = { - label: '风机列表', - prop: 'code', - align: 'center', -}*/ const tableItem0: any = [ { label: '风机列表', @@ -190,7 +185,7 @@ const tableColumn=ref( const deviceList = ref() const tableList=ref() -var modalTbleData=ref([]) +const modalTbleData=ref([]) const devicelistData = reactive({ objectType: 10002, }) @@ -210,12 +205,10 @@ const deviceQuery = (data: any) => { snapshotParms.push({...objparms}) }) getsnapshotData(snapshotParms).then((res) => { - debugger if (res.code == 200) { const tsnapshotVoObject: any = res.data; const tsnapshotVoMap = new Map(Object.entries(tsnapshotVoObject)); const updatedTableData = tableColumn.value.reduce((acc, item1) => { - debugger acc.forEach((item, i) => { const itemKey = item.id; if (tsnapshotVoMap.has(itemKey)) { @@ -265,7 +258,7 @@ const modelAttributeList=(data: any) =>{ }) } -const Statistic=ref(0) + interface TableType { attributeCode:string @@ -282,12 +275,26 @@ interface TableType { visible:number | null } + +const tableRef=ref() const multipleSelection = ref([]) -const selectTable = (selected: TableType[]) => { - Statistic.value=selected.length - multipleSelection.value =selected - selectpageTotal.value=selected.length +const Statistic = computed(() => multipleSelection.value.length) +const selectTable = (selected: TableType[] | null) => { + if (!selected) { + console.error('Selected is null or undefined') + return + } + multipleSelection.value = selected } +const getRowKey = (row) => row.id; +const visible = ref(false) +const openMeasure=() =>{ + visible.value=true + queryListData.iotModelId=iotModelId.value + queryListData.attributeType=radioActiveName.value + modelAttributeList(queryListData) +} + const moveUp = (index:number) => { if (index > 0) { const temp = multipleSelection.value[index]; @@ -308,12 +315,13 @@ const moveDown = (index:number) => { const clearList=() => { Statistic.value=0 multipleSelection.value = []; + tableRef.value.clearSelection() queryListData.iotModelId=iotModelId.value queryListData.attributeType=radioActiveName.value modelAttributeList(queryListData) } - const handleradioClose=() => { - multipleSelection.value = []; + const handleradioChange=() => { + //multipleSelection.value = []; queryListData.iotModelId=iotModelId.value queryListData.attributeType=radioActiveName.value modelAttributeList(queryListData) @@ -366,13 +374,7 @@ const selecthandleCurrentChange = (val: number) => { modelAttributeList(queryListData)*/ } -const visible = ref(false) -const openMeasure=() =>{ - visible.value=true - queryListData.iotModelId=iotModelId.value - queryListData.attributeType=radioActiveName.value - modelAttributeList(queryListData) -} + const handleClose = (done: () => void) => { visible.value = false @@ -388,26 +390,38 @@ const objparms = reactive({ const getTableData = () => { const deviceId=deviceList.value.map((item) => item.id); const tableColumnEnds = ref([]); + const tableColumnup = ref([]); const tableColumnMap = new Map(); tableColumn.value.forEach(item1 => { if (item1.prop) { tableColumnMap.set(item1.prop, item1); + tableColumnup.value.push({ + label: item1.label, + prop: item1.prop, + align: 'center', + }); } }); - multipleSelection.value.forEach(item => { - if (item.attributeCode) { - const attributeCodeLower = item.attributeCode.toLowerCase(); - if (!tableColumnMap.has(attributeCodeLower)) { - tableColumnEnds.value.push({ - label: item.attributeName, - prop: attributeCodeLower, - align: 'center', - }); + if(multipleSelection.value.length === 0){ + tableColumn.value = [...tableItem0, ...tableColumnEnds.value]; + }else{ + multipleSelection.value.forEach(item => { + if (item.attributeCode) { + const attributeCodeLower = item.attributeCode.toLowerCase(); + if (!tableColumnMap.has(attributeCodeLower)) { + tableColumnEnds.value.push({ + label: item.attributeName+'\n'+item.unit, + prop: attributeCodeLower, + align: 'center', + }); + } } - } - }); + }); + tableColumn.value = [...tableColumnup.value, ...tableColumnEnds.value]; + } - tableColumn.value = [...tableItem0, ...tableColumnEnds.value]; + + //tableColumn.value = [...tableItem0, ...tableColumnEnds.value]; deviceId.forEach((item,index) => { objparms.deviceId=item objparms.attributes=multipleSelection.value.map((item) => item.attributeCode) @@ -416,36 +430,8 @@ const getTableData = () => { getsnapshotData(snapshotParms).then((res) => { if (res.code == 200) { const tsnapshotVoObject: any = res.data; - /* const validatedSelections = multipleSelection.value.filter(item => typeof item === 'object' && item !== null); - const validatedTableItems = tableData.value.filter(item => typeof item === 'object' && item !== null); - - const attributeCodeMap = new Map(); - validatedSelections.forEach(selectionItem => { - if (selectionItem.attributeCode) { - attributeCodeMap.set(selectionItem.id, selectionItem.attributeCode.toLowerCase()); - } - }); - - validatedTableItems.forEach((tableItem: any, index: number, tableArray: any) => { - try { - debugger - for (const key in tsnapshotVoObject) { - if (tableItem.id === key) { - const attributeCodeLower = attributeCodeMap.get(key); - if (attributeCodeLower) { - const value = tsnapshotVoObject[key]?.[attributeCodeLower]; - const formattedValue = value ? (value % 1 === 0 ? value : value.toFixed(3)) : '-'; - tableArray[index] = { ...tableItem, [attributeCodeLower]: formattedValue }; - } - } - } - } catch (error) { - console.error('Error processing data:', error); - } - });*/ multipleSelection.value.map((item1: any) => { tableData.value.forEach((item: any, i: number, arr: any) => { - debugger for (const itemKey in tsnapshotVoObject) { if (item.id === itemKey) { const attributeCodeLower = item1.attributeCode?.toLowerCase(); @@ -483,9 +469,11 @@ const downFun=(tableColumn,tableData)=>{ let str = ``; for(let i = 0; i < tableDatadown.length; i++) { for(let item in tableDatadown[i]) { - // 2.5.1 注意要将本身就有换行或者英文逗号的内容进行变换 否则表格内容会错乱 - //tableDatadown[i][item] = tableDatadown[i][item].replace(/\n/g, ' ') - //tableDatadown[i][item] = tableDatadown[i][item].replace(/,/g, ',') // 英文替换为中文 + if (typeof tableDatadown[i][item] === 'string') { + tableDatadown[i][item] = tableDatadown[i][item].replace(/[\n,]/g, match => match === '\n' ? ' ' : ','); + } else { + console.warn(`tableDatadown[${i}][${item}] is not a string`); + } str += `${tableDatadown[i][item] + '\t'},`; } str += '\n';