Files
pqs-9100_client/frontend/src/views/machine/device/index.vue

274 lines
9.2 KiB
Vue
Raw Normal View History

<template>
2024-11-06 21:15:49 +08:00
<div class='table-box' ref='popupBaseView'>
<ProTable
2025-03-14 11:23:49 +08:00
ref='proTable'
:columns='columns'
:request-api='getTableList'
2024-11-06 21:15:49 +08:00
>
<!-- :requestApi="getRoleList" -->
<!-- 表格 header 按钮 -->
<template #tableHeader='scope'>
2024-11-21 10:05:44 +08:00
<el-button v-auth.device="'add'" type='primary' :icon='CirclePlus' @click="openDialog('add')">新增</el-button>
<el-button v-auth.device="'export'" type='primary' :icon='Upload' plain @click='downloadFile()'>导出</el-button>
2025-01-16 19:45:48 +08:00
<el-button v-auth.device="'import'" type='primary' :icon='Download' plain @click="importFile('')"
v-if='modeStore.currentMode != "比对式"'>导入
</el-button>
<el-button v-auth.device="'import'" type='primary' :icon='Download' plain @click="importFile('比对式')"
v-if='modeStore.currentMode === "比对式"'>导入
</el-button>
2024-11-21 10:05:44 +08:00
<el-button v-auth.device="'delete'" type='danger' :icon='Delete' plain :disabled='!scope.isSelected'
2024-11-06 21:15:49 +08:00
@click='batchDelete(scope.selectedListIds)'>
2024-12-04 20:00:04 +08:00
删除
2024-11-06 21:15:49 +08:00
</el-button>
</template>
<!-- 表格操作 -->
<template #operation='scope'>
2025-01-16 19:45:48 +08:00
<el-button v-auth.device="'edit'" type='primary' link :icon='EditPen' :model-value='false'
@click="openDialog('edit', scope.row)">编辑
</el-button>
<el-button v-auth.device="'delete'" type='primary' link :icon='Delete' @click='handleDelete(scope.row)'>删除
</el-button>
</template>
2024-11-06 21:07:44 +08:00
2024-11-06 21:15:49 +08:00
</ProTable>
</div>
2025-03-14 11:23:49 +08:00
<DevicePopup :refresh-table='proTable?.getTableList' ref='devicePopup'/>
<ImportExcel ref='deviceImportExcel'/>
2024-11-06 21:15:49 +08:00
</template>
<script setup lang='tsx' name='useRole'>
import TimeControl from '@/components/TimeControl/index.vue'
2025-03-14 11:23:49 +08:00
import {type Device} from '@/api/device/interface/device.ts'
import {useHandleData} from '@/hooks/useHandleData'
import {useDownload} from '@/hooks/useDownload'
2024-11-06 21:15:49 +08:00
import ProTable from '@/components/ProTable/index.vue'
import ImportExcel from '@/components/ImportExcel/index.vue'
2025-03-14 11:23:49 +08:00
import {type ColumnProps, type ProTableInstance} from '@/components/ProTable/interface'
2024-11-06 21:15:49 +08:00
import DevicePopup from '@/views/machine/device/components/devicePopup.vue'
2025-03-14 11:23:49 +08:00
import {CirclePlus, Delete, Download, EditPen, Upload} from '@element-plus/icons-vue'
import {useDictStore} from '@/stores/modules/dict'
import {deletePqDev, downloadTemplate, exportPqDev, getPqDev, getPqDevList, importPqDev} from '@/api/device/device/index.ts'
import {ElMessageBox} from 'element-plus'
import {onBeforeMount, reactive, ref} from 'vue'
import {useAppSceneStore, useModeStore} from '@/stores/modules/mode'
2025-01-16 19:45:48 +08:00
2025-02-11 10:59:41 +08:00
// defineOptions({
// name: 'device',
// })
2025-01-16 19:45:48 +08:00
const modeStore = useModeStore()
2024-11-06 21:15:49 +08:00
const dictStore = useDictStore()
2025-01-13 18:12:36 +08:00
const appSceneStore = useAppSceneStore()
2024-11-06 21:15:49 +08:00
// ProTable 实例
const proTable = ref<ProTableInstance>()
const devicePopup = ref()
2025-01-16 19:45:48 +08:00
const boundPqDevList = ref<Device.ReqPqDevParams[]>([])//根据检测计划id查询出所有已绑定的设备
2025-01-13 19:28:51 +08:00
// 存储设备类型选项
2025-01-13 21:06:24 +08:00
const devTypeOptions = ref<Device.ResDev[]>([])
2025-01-16 19:45:48 +08:00
2025-03-14 11:23:49 +08:00
2024-12-13 16:35:27 +08:00
const getTableList = async (params: any) => {
2024-11-06 21:15:49 +08:00
let newParams = JSON.parse(JSON.stringify(params))
2024-11-07 10:24:33 +08:00
newParams.searchEndTime = endDate.value
newParams.searchBeginTime = startDate.value
2025-01-16 19:45:48 +08:00
const patternId = dictStore.getDictData('Pattern').find(item => item.name === modeStore.currentMode)?.id//获取数据字典中对应的id
2024-11-21 14:42:26 +08:00
newParams.pattern = patternId
2024-11-06 21:15:49 +08:00
return getPqDevList(newParams)
}
2024-11-12 18:56:33 +08:00
2024-11-06 21:15:49 +08:00
// 表格配置项
const columns = reactive<ColumnProps<Device.ResPqDev>[]>([
2025-03-14 11:23:49 +08:00
{type: 'selection', fixed: 'left', width: 70},
{type: 'index', fixed: 'left', width: 70, label: '序号'},
2024-11-06 21:15:49 +08:00
{
prop: 'name',
2024-12-05 13:43:05 +08:00
label: '名称',
2025-03-14 11:23:49 +08:00
search: {el: 'input'},
2025-01-14 10:03:44 +08:00
// isShow: appSceneStore.currentScene != '1',
// ...(appSceneStore.currentScene != '1' ? {
// search: { el: 'input' },
// } : {}),
2024-12-05 09:55:35 +08:00
minWidth: 200,
2024-11-06 21:15:49 +08:00
},
{
prop: 'devType',
2024-11-15 16:31:48 +08:00
label: '设备类型',
2024-12-05 09:55:35 +08:00
minWidth: 200,
2025-01-13 19:28:51 +08:00
render: (scope) => {
// 查找设备类型名称
2025-01-16 19:45:48 +08:00
const name = devTypeOptions.value.find(option => option.id === scope.row.devType)
2025-01-13 19:28:51 +08:00
return <span>{name?.name}</span>
},
2024-11-06 21:15:49 +08:00
},
2024-11-14 18:26:34 +08:00
{
prop: 'createDate',
2024-12-05 14:37:50 +08:00
label: '出厂日期',
2024-12-05 09:55:35 +08:00
minWidth: 200,
2025-01-14 15:14:37 +08:00
isShow: appSceneStore.currentScene === '0',
...(appSceneStore.currentScene === '0' ? {
2025-01-16 19:45:48 +08:00
search: {
2025-01-14 15:14:37 +08:00
render: () => {
2025-01-16 19:45:48 +08:00
return (
2025-03-14 11:23:49 +08:00
<div class='flx-flex-start'>
<TimeControl
default={'月'}
onUpdate-dates={handleDateChange}
/>
</div>
2025-01-16 19:45:48 +08:00
)
},
2024-11-14 18:26:34 +08:00
},
2025-01-14 15:14:37 +08:00
} : {}),
// search: {
// span: 2,
// render: () => {
// return (
// <div class='flx-flex-start'>
// <TimeControl
// default={'月'}
// onUpdate-dates={handleDateChange}
// />
// </div>
// )
// },
// },
2024-11-14 18:26:34 +08:00
},
2024-11-06 21:15:49 +08:00
{
prop: 'devChns',
2024-12-05 20:06:59 +08:00
label: '通道数',
2024-11-06 21:15:49 +08:00
minWidth: 110,
2024-11-14 19:33:33 +08:00
2024-11-06 21:15:49 +08:00
},
{
prop: 'devVolt',
label: '额定电压V',
minWidth: 130,
2024-11-14 19:33:33 +08:00
2024-11-06 21:15:49 +08:00
},
{
prop: 'devCurr',
label: '额定电流A',
minWidth: 130,
2024-11-14 19:33:33 +08:00
2024-11-06 21:15:49 +08:00
},
{
prop: 'manufacturer',
2024-12-05 14:37:50 +08:00
label: '设备厂家',
2024-11-11 15:40:49 +08:00
enum: dictStore.getDictData('Dev_Manufacturers'),
2025-01-13 18:12:36 +08:00
isShow: appSceneStore.currentScene != '1',
...(appSceneStore.currentScene != '1' ? {
2025-03-14 11:23:49 +08:00
search: {el: 'select', props: {filterable: true}, order: 1},
fieldNames: {label: 'name', value: 'id'},
2025-01-13 18:12:36 +08:00
} : {}),
2024-12-05 09:55:35 +08:00
minWidth: 200,
2024-11-06 21:15:49 +08:00
},
2025-01-17 14:57:17 +08:00
{
prop: 'createTime',
label: '创建时间',
width: 200,
2025-01-22 12:09:32 +08:00
render: scope => {
if (scope.row.createTime) {
2025-03-14 11:23:49 +08:00
const date = new Date(scope.row.createTime);
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
const seconds = String(date.getSeconds()).padStart(2, '0');
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}
return '';
2025-01-22 12:09:32 +08:00
}
2025-01-17 14:57:17 +08:00
},
2025-03-14 11:23:49 +08:00
{prop: 'operation', label: '操作', fixed: 'right', width: 200},
2024-11-06 21:15:49 +08:00
])
2024-11-06 21:07:44 +08:00
2024-11-06 21:15:49 +08:00
// 处理日期变化的回调函数
const startDate = ref('')
const endDate = ref('')
const handleDateChange = (startDateTemp: string, endDateTemp: string) => {
startDate.value = startDateTemp
endDate.value = endDateTemp
}
// 打开 drawer(新增、编辑)
const openDialog = (titleType: string, row: Partial<Device.ResPqDev> = {}) => {
2025-01-16 19:45:48 +08:00
devicePopup.value?.open(titleType, row, modeStore.currentMode, appSceneStore.currentScene, devTypeOptions.value)
2024-11-06 21:07:44 +08:00
}
2024-11-06 21:15:49 +08:00
2024-11-18 16:02:19 +08:00
2024-11-07 15:13:53 +08:00
// 批量删除设备
2024-11-06 21:15:49 +08:00
const batchDelete = async (id: string[]) => {
2025-01-16 19:45:48 +08:00
const patternId = dictStore.getDictData('Pattern').find(item => item.name === modeStore.currentMode)?.id ?? ''//获取数据字典中对应的id
2025-03-14 11:23:49 +08:00
await useHandleData(deletePqDev, {'ids': id, 'pattern': patternId}, '删除所选设备')
2025-01-22 12:09:32 +08:00
proTable.value?.clearSelection()
proTable.value?.getTableList()
2024-11-06 21:15:49 +08:00
}
2024-11-07 15:13:53 +08:00
// 删除设备
2024-11-06 21:15:49 +08:00
const handleDelete = async (params: Device.ResPqDev) => {
2025-01-16 19:45:48 +08:00
const patternId = dictStore.getDictData('Pattern').find(item => item.name === modeStore.currentMode)?.id//获取数据字典中对应的id
2025-03-14 11:23:49 +08:00
await useHandleData(deletePqDev, {'ids': [params.id], 'pattern': patternId}, `删除【${params.name}】设备`)
2024-11-06 21:15:49 +08:00
proTable.value?.getTableList()
2025-03-14 11:23:49 +08:00
2024-11-06 21:15:49 +08:00
}
2024-11-07 15:13:53 +08:00
// 导出设备
2024-11-14 19:24:36 +08:00
const downloadFile = async () => {
2025-01-16 19:45:48 +08:00
// 获取当前的搜索参数
const searchParam = proTable.value?.searchParam || {}
2024-11-14 18:26:34 +08:00
2025-01-16 19:45:48 +08:00
// 将开始时间和结束时间添加到搜索参数中
searchParam.searchBeginTime = startDate.value
searchParam.searchEndTime = endDate.value
2024-11-14 18:26:34 +08:00
2025-03-14 11:23:49 +08:00
ElMessageBox.confirm('确认导出被检设备?', '温馨提示', {type: 'warning'}).then(() => {
2025-01-16 19:45:48 +08:00
const patternId = dictStore.getDictData('Pattern').find(item => item.name === modeStore.currentMode)?.id//获取数据字典中对应的id
2025-03-14 11:23:49 +08:00
useDownload(exportPqDev, '被检设备导出数据', {...proTable.value?.searchParam, pattern: patternId}, false, '.xlsx')
2025-01-16 19:45:48 +08:00
})
2024-11-07 15:13:53 +08:00
}
//导入设备
2024-11-07 16:17:33 +08:00
const deviceImportExcel = ref<InstanceType<typeof ImportExcel> | null>(null)
2024-11-07 15:12:44 +08:00
2025-01-16 19:45:48 +08:00
const importFile = async (pattern: string) => {
2025-01-15 20:23:05 +08:00
2025-01-16 19:45:48 +08:00
if (pattern === '比对式') {
2025-01-15 20:37:58 +08:00
// const params = {
// title: '被检设备',
// showCover: false,
// tempApi: downloadTemplate,
// importApi: importPqDev,
// getTableList: proTable.value?.getTableList,
// }
// deviceImportExcel.value?.acceptParams(params)
2025-01-16 19:45:48 +08:00
} else {
2025-01-15 20:23:05 +08:00
const params = {
2025-01-16 19:45:48 +08:00
title: '被检设备',
showCover: false,
patternId: dictStore.getDictData('Pattern').find(item => item.name === modeStore.currentMode)?.id,
2025-03-14 11:23:49 +08:00
tempApi: downloadTemplate,
importApi: importPqDev,
2025-01-16 19:45:48 +08:00
// importApi: modeStore.currentMode === "比对式"? importContrastPqDev: importCNDev,
getTableList: proTable.value?.getTableList,
2025-01-15 20:23:05 +08:00
}
deviceImportExcel.value?.acceptParams(params)
2024-11-07 15:12:44 +08:00
}
2025-01-15 20:23:05 +08:00
2024-11-07 15:13:53 +08:00
}
2024-11-14 11:34:25 +08:00
2025-01-13 19:28:51 +08:00
onBeforeMount(async () => {
const response = await getPqDev()
2025-01-16 19:45:48 +08:00
devTypeOptions.value = (response.data as Device.ResDev[]).map(item => ({
id: item.id,
name: item.name,
icd: item.icd,
power: item.power,
devVolt: item.devVolt,
devCurr: item.devCurr,
devChns: item.devChns,
}))
2025-01-13 19:28:51 +08:00
})
2024-11-06 21:15:49 +08:00
</script>