diff --git a/frontend/src/api/device/device/index.ts b/frontend/src/api/device/device/index.ts index d2040b3..53a061d 100644 --- a/frontend/src/api/device/device/index.ts +++ b/frontend/src/api/device/device/index.ts @@ -31,33 +31,33 @@ export const deletePqDev = (params: string[]) => { // //导入被检设备(比对) // export const importPqDev=(params: Device.ReqPqDevParams)=>{ -//   return http.upload(`/pqDev/import`, params) +// return http.upload(`/pqDev/import`, params) // } // //导入比对式被检设备 // export const importContrastPqDev=(params: Device.ReqPqDevParams)=>{ -//   return http.upload(`/pqDev/importContrast`, params) +// return http.upload(`/pqDev/importContrast`, params) // } - - //导出灿能二楼设备 - export const exportCNDev=(params: Device.ReqPqDevParams)=>{ -   return http.download(`/pqDev/exportCNDev`, params) - } - - // 下载灿能二楼设备导入文件模板 - export const downloadCNDevTemplate = () => { -   return http.download(`/pqDev/downloadCNDevTemplate`) - } - - //导入灿能二楼设备 - export const importCNDev=(params: Device.ReqPqDevParams)=>{ -   return http.upload(`/pqDev/importCNDev`, params) - } + +//导出灿能二楼设备 +export const exportCNDev = (params: Device.ReqPqDevParams) => { + return http.download(`/pqDev/exportCNDev`, params) +} + +// 下载灿能二楼设备导入文件模板 +export const downloadCNDevTemplate = () => { + return http.download(`/pqDev/downloadCNDevTemplate`) +} + +//导入灿能二楼设备 +export const importCNDev = (params: Device.ReqPqDevParams) => { + return http.uploadExcel(`/pqDev/importCNDev`, params) +} //根据设备类型决定(电源、icd、模板、通道数、额定电压、额定电流); export const getPqDev = () => { return http.post(`/devType/list`) } //被检设备归档 -export const documentedPqDev=(ids:string[])=>{ +export const documentedPqDev = (ids: string[]) => { return http.post(`/pqDev/documented`, ids) } diff --git a/frontend/src/api/index.ts b/frontend/src/api/index.ts index cf1c55d..7ea5370 100644 --- a/frontend/src/api/index.ts +++ b/frontend/src/api/index.ts @@ -42,7 +42,7 @@ class RequestHttp { config.loading ?? (config.loading = true) config.loading && showFullScreenLoading() if (config.headers && typeof config.headers.set === 'function') { - config.headers.set('Authorization', 'Bearer '+userStore.token) + config.headers.set('Authorization', 'Bearer ' + userStore.token) } return config }, @@ -63,7 +63,7 @@ class RequestHttp { // 登陆失效 if (data.code == ResultEnum.OVERDUE) { userStore.setToken('') - userStore.setUserInfo({name: ''}) + userStore.setUserInfo({ name: '' }) router.replace(LOGIN_URL) ElMessage.error(data.message) return Promise.reject(data) @@ -115,9 +115,24 @@ class RequestHttp { } upload(url: string, params?: object, _object = {}): Promise { - return this.service.post(url, params, { ..._object, headers: { 'Content-Type': 'multipart/form-data' } }) + return this.service.post(url, params, { + ..._object, + headers: { 'Content-Type': 'multipart/form-data' } + }) } + /** + * 针对excel的上传,默认返回的是blob类型,Excel没问题时返回json特殊处理 + */ + uploadExcel(url: string, params?: object, _object = {}): Promise { + return this.service.post(url, params, { + ..._object, + headers: { 'Content-Type': 'multipart/form-data' }, + responseType: 'blob', + }) + } + + } export default new RequestHttp(config) diff --git a/frontend/src/components/ImportExcel/index.vue b/frontend/src/components/ImportExcel/index.vue index 6199ea0..7123b20 100644 --- a/frontend/src/components/ImportExcel/index.vue +++ b/frontend/src/components/ImportExcel/index.vue @@ -1,49 +1,48 @@ - - diff --git a/frontend/src/views/machine/device/index.vue b/frontend/src/views/machine/device/index.vue index cbb2822..9c01121 100644 --- a/frontend/src/views/machine/device/index.vue +++ b/frontend/src/views/machine/device/index.vue @@ -10,8 +10,12 @@ @@ -40,28 +47,36 @@ import { type ProTableInstance, type ColumnProps } from '@/components/ProTable/i import DevicePopup from '@/views/machine/device/components/devicePopup.vue' import { CirclePlus, Delete, EditPen, Download, Upload } from '@element-plus/icons-vue' import { useDictStore } from '@/stores/modules/dict' -import {getPqDevList, deletePqDev, getPqDev, exportCNDev, downloadCNDevTemplate, importCNDev} from '@/api/device/device/index.ts' +import { + getPqDevList, + deletePqDev, + getPqDev, + exportCNDev, + downloadCNDevTemplate, + importCNDev, +} from '@/api/device/device/index.ts' import { ElMessageBox } from 'element-plus' -import { computed, onBeforeMount, onMounted, reactive, ref } from 'vue' -import { useModeStore , useAppSceneStore} from '@/stores/modules/mode'; +import { onBeforeMount, reactive, ref } from 'vue' +import { useModeStore, useAppSceneStore } from '@/stores/modules/mode' + defineOptions({ - name: 'device' - }) -const modeStore = useModeStore(); + name: 'device', +}) +const modeStore = useModeStore() const dictStore = useDictStore() const appSceneStore = useAppSceneStore() // ProTable 实例 const proTable = ref() const devicePopup = ref() -const boundPqDevList=ref([])//根据检测计划id查询出所有已绑定的设备 +const boundPqDevList = ref([])//根据检测计划id查询出所有已绑定的设备 // 存储设备类型选项 const devTypeOptions = ref([]) - + const getTableList = async (params: any) => { let newParams = JSON.parse(JSON.stringify(params)) newParams.searchEndTime = endDate.value newParams.searchBeginTime = startDate.value - const patternId = dictStore.getDictData('Pattern').find(item=>item.name=== modeStore.currentMode)?.id//获取数据字典中对应的id + const patternId = dictStore.getDictData('Pattern').find(item => item.name === modeStore.currentMode)?.id//获取数据字典中对应的id newParams.pattern = patternId return getPqDevList(newParams) } @@ -87,7 +102,7 @@ const columns = reactive[]>([ minWidth: 200, render: (scope) => { // 查找设备类型名称 - const name = devTypeOptions.value.find(option => option.id === scope.row.devType); + const name = devTypeOptions.value.find(option => option.id === scope.row.devType) return {name?.name} }, }, @@ -97,18 +112,18 @@ const columns = reactive[]>([ minWidth: 200, isShow: appSceneStore.currentScene === '0', ...(appSceneStore.currentScene === '0' ? { - search: { + search: { render: () => { - return ( -
- -
- ) + return ( +
+ +
+ ) + }, }, - }, } : {}), // search: { // span: 2, @@ -166,47 +181,46 @@ const handleDateChange = (startDateTemp: string, endDateTemp: string) => { } // 打开 drawer(新增、编辑) const openDialog = (titleType: string, row: Partial = {}) => { - devicePopup.value?.open(titleType, row,modeStore.currentMode,appSceneStore.currentScene,devTypeOptions.value) + devicePopup.value?.open(titleType, row, modeStore.currentMode, appSceneStore.currentScene, devTypeOptions.value) } - // 批量删除设备 const batchDelete = async (id: string[]) => { - const patternId = dictStore.getDictData('Pattern').find(item=>item.name=== modeStore.currentMode)?.id ?? ''//获取数据字典中对应的id - await useHandleData(deletePqDev, {'ids':id,'pattern': patternId} , '删除所选设备') + const patternId = dictStore.getDictData('Pattern').find(item => item.name === modeStore.currentMode)?.id ?? ''//获取数据字典中对应的id + await useHandleData(deletePqDev, { 'ids': id, 'pattern': patternId }, '删除所选设备') proTable.value?.clearSelection() proTable.value?.getTableList() } // 删除设备 const handleDelete = async (params: Device.ResPqDev) => { - const patternId = dictStore.getDictData('Pattern').find(item=>item.name=== modeStore.currentMode)?.id//获取数据字典中对应的id - await useHandleData(deletePqDev, {'ids': [params.id] ,'pattern': patternId}, `删除【${params.name}】设备`) + const patternId = dictStore.getDictData('Pattern').find(item => item.name === modeStore.currentMode)?.id//获取数据字典中对应的id + await useHandleData(deletePqDev, { 'ids': [params.id], 'pattern': patternId }, `删除【${params.name}】设备`) proTable.value?.getTableList() } // 导出设备 const downloadFile = async () => { - // 获取当前的搜索参数 - const searchParam = proTable.value?.searchParam || {}; + // 获取当前的搜索参数 + const searchParam = proTable.value?.searchParam || {} - // 将开始时间和结束时间添加到搜索参数中 - searchParam.searchBeginTime = startDate.value; - searchParam.searchEndTime = endDate.value; + // 将开始时间和结束时间添加到搜索参数中 + searchParam.searchBeginTime = startDate.value + searchParam.searchEndTime = endDate.value - ElMessageBox.confirm('确认导出被检设备?', '温馨提示', { type: 'warning' }).then(() =>{ - const patternId = dictStore.getDictData('Pattern').find(item=>item.name=== modeStore.currentMode)?.id//获取数据字典中对应的id - useDownload(exportCNDev,'被检设备导出数据', {...proTable.value?.searchParam,pattern:patternId}, false,'.xlsx') - }) + ElMessageBox.confirm('确认导出被检设备?', '温馨提示', { type: 'warning' }).then(() => { + const patternId = dictStore.getDictData('Pattern').find(item => item.name === modeStore.currentMode)?.id//获取数据字典中对应的id + useDownload(exportCNDev, '被检设备导出数据', { ...proTable.value?.searchParam, pattern: patternId }, false, '.xlsx') + }) } //导入设备 const deviceImportExcel = ref | null>(null) -const importFile = async (pattern:string) => { +const importFile = async (pattern: string) => { - if(pattern === '比对式'){ + if (pattern === '比对式') { // const params = { // title: '被检设备', // showCover: false, @@ -215,34 +229,32 @@ const importFile = async (pattern:string) => { // getTableList: proTable.value?.getTableList, // } // deviceImportExcel.value?.acceptParams(params) - }else{ + } else { const params = { - title: '被检设备', - showCover: false, - patternId: dictStore.getDictData('Pattern').find(item=>item.name=== modeStore.currentMode)?.id, - tempApi: downloadCNDevTemplate, - importApi: importCNDev, - // importApi: modeStore.currentMode === "比对式"? importContrastPqDev: importCNDev, - getTableList: proTable.value?.getTableList, + title: '被检设备', + showCover: false, + patternId: dictStore.getDictData('Pattern').find(item => item.name === modeStore.currentMode)?.id, + tempApi: downloadCNDevTemplate, + importApi: importCNDev, + // importApi: modeStore.currentMode === "比对式"? importContrastPqDev: importCNDev, + getTableList: proTable.value?.getTableList, } deviceImportExcel.value?.acceptParams(params) - - console.log(params) } } onBeforeMount(async () => { const response = await getPqDev() - 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 - })) + 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, + })) }) \ No newline at end of file