UPDATE:1.完善主计划导入被检设备逻辑;2.完善新增编辑子计划逻辑。

This commit is contained in:
贾同学
2025-08-13 20:34:08 +08:00
parent 0025895696
commit b1ddf540ca
5 changed files with 781 additions and 660 deletions

View File

@@ -2,54 +2,53 @@ import type { Plan } from './interface'
import http from '@/api' import http from '@/api'
import type { ErrorSystem } from '../device/interface/error' import type { ErrorSystem } from '../device/interface/error'
import type { Device } from '../device/interface/device' import type { Device } from '../device/interface/device'
import { pa } from 'element-plus/es/locale/index.mjs'
/** /**
* @name 检测计划管理模块 * @name 检测计划管理模块
*/ */
// 获取检测计划列表 // 获取检测计划列表
export const getPlanList = (params: Plan.ReqPlanParams) => { export const getPlanList = (params: Plan.ReqPlanParams) => {
return http.post(`/adPlan/list`, params) return http.post(`/adPlan/list`, params)
} }
// 新增检测计划 // 新增检测计划
export const addPlan = (params: any) => { export const addPlan = (params: any) => {
return http.post(`/adPlan/add`, params) return http.post(`/adPlan/add`, params)
} }
// 编辑检测计划 // 编辑检测计划
export const updatePlan = (params: any) => { export const updatePlan = (params: any) => {
return http.post(`/adPlan/update`, params) return http.post(`/adPlan/update`, params)
} }
// 删除检测计划 // 删除检测计划
export const deletePlan = (params: { id: string[] ,pattern: string}) => { export const deletePlan = (params: { id: string[]; pattern: string }) => {
return http.post(`/adPlan/delete?pattern=${params.pattern}`, params.id) return http.post(`/adPlan/delete?pattern=${params.pattern}`, params.id)
} }
// 获取指定模式下所有检测源 // 获取指定模式下所有检测源
export const getTestSourceList = (params: Plan.ReqPlan) => { export const getTestSourceList = (params: Plan.ReqPlan) => {
return http.get(`/pqSource/getAll?patternId=${params.pattern}`) return http.get(`/pqSource/getAll?patternId=${params.pattern}`)
} }
// 获取指定模式下所有检测脚本 // 获取指定模式下所有检测脚本
export const getPqScriptList = (params: Plan.ReqPlan) => { export const getPqScriptList = (params: Plan.ReqPlan) => {
return http.get(`/pqScript/getAll?patternId=${params.pattern}`) return http.get(`/pqScript/getAll?patternId=${params.pattern}`)
} }
//获取所有误差体系 //获取所有误差体系
export const getPqErrSysList = () => { export const getPqErrSysList = () => {
return http.get<ErrorSystem.ErrorSystemList>(`/pqErrSys/getAll`) return http.get<ErrorSystem.ErrorSystemList>(`/pqErrSys/getAll`)
} }
//获取指定模式下所有未绑定的设备 //获取指定模式下所有未绑定的设备
export const getUnboundPqDevList = (params: Plan.ReqPlan) => { export const getUnboundPqDevList = (params: Plan.ReqPlan) => {
return http.get(`/pqDev/listUnbound?pattern=${params.pattern}`) return http.get(`/pqDev/listUnbound?pattern=${params.pattern}`)
} }
//根据检测计划id查询出所有已绑定的设备 //根据检测计划id查询出所有已绑定的设备
export const getBoundPqDevList = (params: any) => { export const getBoundPqDevList = (params: any) => {
return http.post(`/adPlan/listByPlanId`, params) return http.post(`/adPlan/listByPlanId`, params)
} }
//检测计划绑定设备 //检测计划绑定设备
@@ -59,63 +58,68 @@ export const getBoundPqDevList = (params: any) => {
// 按照模式查询检测计划(用于首页展示) // 按照模式查询检测计划(用于首页展示)
export const getPlanListByPattern = (params: Plan.ReqPlan) => { export const getPlanListByPattern = (params: Plan.ReqPlan) => {
return http.get(`/adPlan/listByPattern?pattern=${params.pattern}`) return http.get(`/adPlan/listByPattern?pattern=${params.pattern}`)
} }
// 导出检测计划 // 导出检测计划
export const exportPlan = (params: Device.ReqPqDevParams) => { export const exportPlan = (params: Device.ReqPqDevParams) => {
return http.download(`/adPlan/export`, params) return http.download(`/adPlan/export`, params)
} }
// 下载模板 // 下载模板
export const downloadTemplate = (params: { patternId: string }) => { export const downloadTemplate = (params: { patternId: string }) => {
return http.download(`/adPlan/downloadTemplate`, params) return http.download(`/adPlan/downloadTemplate`, params)
} }
// 导入检测计划 // 导入检测计划
export const importPlan = (params: Device.ReqPqDevParams) => { export const importPlan = (params: Device.ReqPqDevParams) => {
return http.uploadExcel(`/adPlan/import`, params) return http.uploadExcel(`/adPlan/import`, params)
} }
// 装置检测报告生成 // 装置检测报告生成
export const generateDevReport = (params: Device.ReqDevReportParams) => { export const generateDevReport = (params: Device.ReqDevReportParams) => {
return http.post(`/report/generateReport`, params) return http.post(`/report/generateReport`, params)
} }
// 装置检测报告下载 // 装置检测报告下载
export const downloadDevData = (params: Device.ReqDevReportParams) => { export const downloadDevData = (params: Device.ReqDevReportParams) => {
return http.download(`/report/downloadReport`, params) return http.download(`/report/downloadReport`, params)
} }
export const staticsAnalyse = (params: { id: string[] }) => { export const staticsAnalyse = (params: { id: string[] }) => {
return http.download('/adPlan/analyse', params) return http.download('/adPlan/analyse', params)
} }
//根据计划id分页查询被检设 //根据计划id分页查询被检设
export const getDevListByPlanId = (params:any) => { export const getDevListByPlanId = (params: any) => {
return http.post(`/adPlan/listDevByPlanId`, params) return http.post(`/adPlan/listDevByPlanId`, params)
} }
//修改子计划名称 //修改子计划名称
export const updateSubPlanName = (params:Plan.ReqPlan) => { export const updateSubPlanName = (params: Plan.ReqPlan) => {
return http.get(`/adPlan/updateSubPlanName?planId=${params.id}&name=${params.name}`) return http.get(`/adPlan/updateSubPlanName?planId=${params.id}&name=${params.name}`)
} }
//子计划绑定/解绑标准设备 //子计划绑定/解绑标准设备
export const subPlanBindStandardDevList = (params:Plan.ReqPlan) => { export const subPlanBindStandardDevList = (params: Plan.ReqPlan) => {
return http.post(`/adPlan/updateBindStandardDev`, params) return http.post(`/adPlan/updateBindStandardDev`, params)
} }
//子计划绑定/解绑被检设备 //子计划绑定/解绑被检设备
export const subPlanBindDev = (params:Plan.ReqPlan) => { export const subPlanBindDev = (params: Plan.ReqPlan) => {
return http.post(`/adPlan/updateBindDev`, params) return http.post(`/adPlan/updateBindDev`, params)
} }
//根据父计划ID获取未被子计划绑定的标准设备 //根据父计划ID获取未被子计划绑定的标准设备
export const getUnboundStandardDevList = (params:Plan.ResPlan) => { export const getUnboundStandardDevList = (params: Plan.ResPlan) => {
return http.get(`/adPlan/getUnBoundStandardDev?fatherPlanId=${params.fatherPlanId}`) return http.get(`/adPlan/getUnBoundStandardDev?fatherPlanId=${params.fatherPlanId}`)
} }
//根据计划ID获取已绑定的标准设备 //根据计划ID获取已绑定的标准设备
export const getBoundStandardDevList = (params:Plan.ResPlan) => { export const getBoundStandardDevList = (params: Plan.ResPlan) => {
return http.get(`/adPlan/getBoundStandardDev?planId=${params.id}`) return http.get(`/adPlan/getBoundStandardDev?planId=${params.id}`)
}
//根据计划ID获取已绑定的所有标准设备
export const getBoundStandardDevAllList = (params: Plan.ResPlan) => {
return http.get(`/adPlan/getBoundStandardDev?planId=${params.id}&all=1`)
} }

View File

@@ -1,59 +1,69 @@
<template> <template>
<el-dialog v-model='dialogVisible' :title='`批量添加${parameter.title}`' :destroy-on-close='true' width='580px' <el-dialog
draggable> v-model="dialogVisible"
<el-form class='drawer-multiColumn-form' label-width='100px'> :title="`批量添加${parameter.title}`"
<el-form-item label='模板下载 :'> :destroy-on-close="true"
<el-button type='primary' :icon='Download' @click='downloadTemp'> 点击下载</el-button> width="580px"
</el-form-item> draggable
<el-form-item label='文件上传 :'> >
<el-upload <el-form class="drawer-multiColumn-form" label-width="100px">
action='#' <el-form-item label="模板下载 :">
class='upload' <el-button type="primary" :icon="Download" @click="downloadTemp">点击下载</el-button>
:drag='true' </el-form-item>
:limit='excelLimit' <el-form-item label="文件上传 :">
:multiple='true' <el-upload
:show-file-list='true' action="#"
:http-request='uploadExcel' class="upload"
:before-upload='beforeExcelUpload' :drag="true"
:on-exceed='handleExceed' :limit="excelLimit"
:accept="parameter.fileType!.join(',')" :multiple="true"
> :show-file-list="true"
<slot name='empty'> :http-request="uploadExcel"
<el-icon class='el-icon--upload'> :before-upload="beforeExcelUpload"
<upload-filled /> :on-exceed="handleExceed"
</el-icon> :accept="parameter.fileType!.join(',')"
<div class='el-upload__text'>将文件拖到此处<em>点击上传</em></div> >
</slot> <slot name="empty">
<template #tip> <el-icon class="el-icon--upload">
<slot name='tip'> <upload-filled />
<div class='el-upload__tip'>请上传 .xls , .xlsx 标准格式文件文件最大为 {{ parameter.fileSize }}M</div> </el-icon>
</slot> <div class="el-upload__text">
</template> 将文件拖到此处
</el-upload> <em>点击上传</em>
</el-form-item> </div>
<el-form-item v-if='parameter.showCover' label='数据覆盖 :'> </slot>
<el-switch v-model='isCover' /> <template #tip>
</el-form-item> <slot name="tip">
</el-form> <div class="el-upload__tip">
</el-dialog> 请上传 .xls , .xlsx 标准格式文件文件最大为 {{ parameter.fileSize }}M
</div>
</slot>
</template>
</el-upload>
</el-form-item>
<el-form-item v-if="parameter.showCover" label="数据覆盖 :">
<el-switch v-model="isCover" />
</el-form-item>
</el-form>
</el-dialog>
</template> </template>
<script setup lang='ts' name='ImportExcel'> <script setup lang="ts" name="ImportExcel">
import { ref } from 'vue' import { ref } from 'vue'
import { useDownload } from '@/hooks/useDownload' import { useDownload } from '@/hooks/useDownload'
import { Download } from '@element-plus/icons-vue' import { Download } from '@element-plus/icons-vue'
import { ElNotification, UploadRequestOptions, UploadRawFile, ElMessage } from 'element-plus' import { ElMessage, ElNotification, UploadRawFile, UploadRequestOptions } from 'element-plus'
export interface ExcelParameterProps { export interface ExcelParameterProps {
title: string; // 标题 title: string // 标题
showCover?: boolean; // 是否显示”数据覆盖“选项 showCover?: boolean // 是否显示”数据覆盖“选项
patternId?: string; // 模式ID patternId?: string // 模式ID
planId?: string | null ;//计划ID planId?: string | null //计划ID
fileSize?: number; // 上传文件的大小 fileSize?: number // 上传文件的大小
fileType?: File.ExcelMimeType[]; // 上传文件的类型 fileType?: File.ExcelMimeType[] // 上传文件的类型
tempApi?: (params: any) => Promise<any>; // 下载模板的Api tempApi?: (params: any) => Promise<any> // 下载模板的Api
importApi?: (params: any) => Promise<any>; // 批量导入的Api importApi?: (params: any) => Promise<any> // 批量导入的Api
getTableList?: () => void; // 获取表格数据的Api getTableList?: () => void // 获取表格数据的Api
} }
// 是否覆盖数据 // 是否覆盖数据
@@ -64,71 +74,73 @@ const excelLimit = ref(1)
const dialogVisible = ref(false) const dialogVisible = ref(false)
// 父组件传过来的参数 // 父组件传过来的参数
const parameter = ref<ExcelParameterProps>({ const parameter = ref<ExcelParameterProps>({
title: '', title: '',
fileSize: 5, fileSize: 5,
fileType: ['application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'], fileType: ['application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']
}) })
const emit = defineEmits<{
(e: 'result', data: boolean): void
}>()
// 接收父组件参数 // 接收父组件参数
const acceptParams = (params: ExcelParameterProps) => { const acceptParams = (params: ExcelParameterProps) => {
parameter.value = { ...parameter.value, ...params } parameter.value = { ...parameter.value, ...params }
dialogVisible.value = true dialogVisible.value = true
} }
// Excel 导入模板下载 // Excel 导入模板下载
const downloadTemp = () => { const downloadTemp = () => {
if (!parameter.value.tempApi) return if (!parameter.value.tempApi) return
useDownload(parameter.value.tempApi, `${parameter.value.title}模板`, {'pattern':parameter.value.patternId}, false) useDownload(parameter.value.tempApi, `${parameter.value.title}模板`, { pattern: parameter.value.patternId }, false)
} }
// 文件上传 // 文件上传
const uploadExcel = async (param: UploadRequestOptions) => { const uploadExcel = async (param: UploadRequestOptions) => {
let excelFormData = new FormData() let excelFormData = new FormData()
excelFormData.append('file', param.file) excelFormData.append('file', param.file)
if (parameter.value.patternId) { if (parameter.value.patternId) {
excelFormData.append('patternId', parameter.value.patternId) excelFormData.append('patternId', parameter.value.patternId)
} }
excelFormData.append('planId', parameter.value.planId) excelFormData.append('planId', parameter.value.planId)
isCover.value && excelFormData.append('isCover', isCover.value as unknown as Blob) isCover.value && excelFormData.append('isCover', isCover.value as unknown as Blob)
//await parameter.value.importApi!(excelFormData); //await parameter.value.importApi!(excelFormData);
await parameter.value.importApi!(excelFormData) await parameter.value.importApi!(excelFormData).then(res => handleImportResponse(res))
.then(res => handleImportResponse(res)) parameter.value.getTableList && parameter.value.getTableList()
parameter.value.getTableList && parameter.value.getTableList() dialogVisible.value = false
dialogVisible.value = false
} }
async function handleImportResponse(res: any) { async function handleImportResponse(res: any) {
console.log(res) console.log(res)
if (res.type === 'application/json') { if (res.type === 'application/json') {
const fileReader = new FileReader() const fileReader = new FileReader()
fileReader.onloadend = () => { fileReader.onloadend = () => {
try { try {
const jsonData = JSON.parse(fileReader.result) const jsonData = JSON.parse(fileReader.result)
if (jsonData.code === 'A0000') { if (jsonData.code === 'A0000') {
ElMessage.success('导入成功') ElMessage.success('导入成功')
} else { } else {
ElMessage.error(jsonData.message) ElMessage.error(jsonData.message)
}
emit('result', jsonData.data)
} catch (err) {
console.log(err)
}
} }
} catch (err) { fileReader.readAsText(res)
console.log(err) } else {
} emit('result', false)
ElMessage.error('导入失败,请查看下载附件!')
let blob = new Blob([res], { type: 'application/vnd.ms-excel' })
const url = window.URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = url
link.download = '导入失败数据'
document.body.appendChild(link)
link.click()
link.remove()
} }
fileReader.readAsText(res)
} else {
ElMessage.error('导入失败,请查看下载附件!')
let blob = new Blob([res], { type: 'application/vnd.ms-excel' })
const url = window.URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = url
link.download = '导入失败数据'
document.body.appendChild(link)
link.click()
link.remove()
}
} }
/** /**
@@ -136,32 +148,32 @@ async function handleImportResponse(res: any) {
* @param file 上传的文件 * @param file 上传的文件
* */ * */
const beforeExcelUpload = (file: UploadRawFile) => { const beforeExcelUpload = (file: UploadRawFile) => {
const isExcel = parameter.value.fileType!.includes(file.type as File.ExcelMimeType) const isExcel = parameter.value.fileType!.includes(file.type as File.ExcelMimeType)
const fileSize = file.size / 1024 / 1024 < parameter.value.fileSize! const fileSize = file.size / 1024 / 1024 < parameter.value.fileSize!
if (!isExcel) if (!isExcel)
ElNotification({ ElNotification({
title: '温馨提示', title: '温馨提示',
message: '上传文件只能是 xls / xlsx 格式!', message: '上传文件只能是 xls / xlsx 格式!',
type: 'warning', type: 'warning'
}) })
if (!fileSize) if (!fileSize)
setTimeout(() => { setTimeout(() => {
ElNotification({ ElNotification({
title: '温馨提示', title: '温馨提示',
message: `上传文件大小不能超过 ${parameter.value.fileSize}MB`, message: `上传文件大小不能超过 ${parameter.value.fileSize}MB`,
type: 'warning', type: 'warning'
}) })
}, 0) }, 0)
return isExcel && fileSize return isExcel && fileSize
} }
// 文件数超出提示 // 文件数超出提示
const handleExceed = () => { const handleExceed = () => {
ElNotification({ ElNotification({
title: '温馨提示', title: '温馨提示',
message: '最多只能上传一个文件!', message: '最多只能上传一个文件!',
type: 'warning', type: 'warning'
}) })
} }
// 上传错误提示 // 上传错误提示
@@ -183,9 +195,9 @@ const handleExceed = () => {
// } // }
defineExpose({ defineExpose({
acceptParams, acceptParams
}) })
</script> </script>
<style lang='scss' scoped> <style lang="scss" scoped>
@import "./index.scss"; @use './index.scss';
</style> </style>

View File

@@ -1,122 +1,154 @@
<!--单列--> <!--单列-->
<template> <template>
<el-dialog <el-dialog
class="table-box" class="table-box"
v-model="dialogVisible" v-model="dialogVisible"
top="114px" top="114px"
:style="{ height: height + 'px', maxHeight: height + 'px', overflow: 'hidden' }" :style="{ height: height + 'px', maxHeight: height + 'px', overflow: 'hidden' }"
:title="title" :title="title"
:width="width" :width="width"
:modal="false" :modal="false"
@close="handleClose" @close="handleClose"
>
<div
class="table-box"
:style="{ height: height - 64 + 'px', maxHeight: height - 64 + 'px', overflow: 'hidden' }"
> >
<el-tabs <div
v-model="editableTabsValue" class="table-box"
type="card" :style="{ height: height - 64 + 'px', maxHeight: height - 64 + 'px', overflow: 'hidden' }"
@tab-remove="removeTab"
@tab-click="handleTabClick"
> >
<el-tab-pane <el-tabs v-model="editableTabsValue" type="card" @tab-remove="removeTab" @tab-click="handleTabClick">
v-for="item in editableTabs" <el-tab-pane
:key="item.name" v-for="item in editableTabs"
:label="item.title" :key="item.name"
:name="item.name" :label="item.title"
:closable="item.closable" :name="item.name"
> :closable="item.closable"
</el-tab-pane> ></el-tab-pane>
</el-tabs> </el-tabs>
<ProTable <ProTable ref="proTable" :columns="columns" :request-api="getTableList" type="selection">
ref="proTable" <!-- 表格 header 按钮 -->
:columns="columns" <template #tableHeader="scope">
:request-api="getTableList" <el-button type="primary" :icon="CirclePlus" @click="addTab('add')" v-if="!isTabPlanFather">
type="selection" 新增子计划
> </el-button>
<!-- 表格 header 按钮 --> <el-button type="primary" :icon="CirclePlus" @click="addTab('edit')" v-if="isTabPlanFather">
<template #tableHeader="scope"> 编辑子计划
<el-button type="primary" :icon="CirclePlus" @click="addTab('add')" v-if="!isTabPlanFather"> </el-button>
新增子计划 <!-- <el-button type="primary" :icon="Upload" >
</el-button>
<el-button type="primary" :icon="CirclePlus" @click="addTab('edit')" v-if="isTabPlanFather">
编辑子计划
</el-button>
<!-- <el-button type="primary" :icon="Upload" >
导出检测方案 导出检测方案
</el-button> </el-button>
<el-button type="primary" :icon="Download" > <el-button type="primary" :icon="Download" >
导入检测结果 导入检测结果
</el-button> --> </el-button> -->
<el-button type="danger" :icon="Delete" plain :disabled="!scope.isSelected" v-if="isTabPlanFather" @click="subBatchRemove(scope.selectedListIds)"> <el-button
批量移除 type="danger"
</el-button> :icon="Delete"
<el-dropdown trigger="hover" placement="right-start" :disabled="!scope.isSelected"> plain
<el-button type="primary" :icon="ScaleToOriginal" style="margin-left: 10px;" v-if="!isTabPlanFather" :disabled="!scope.isSelected"> :disabled="!scope.isSelected"
分配被检设备 v-if="isTabPlanFather"
</el-button> @click="subBatchRemove(scope.selectedListIds)"
<template #dropdown >
<el-dropdown-menu>
<el-dropdown-item
v-for="child in planFormContent?.children"
:key="child.id"
@click="distribute(child,scope)"
> >
{{ child.name }} 批量移除
</el-dropdown-item> </el-button>
</el-dropdown-menu> <el-dropdown
</template> v-if="planFormContent && planFormContent?.children.length > 0"
</el-dropdown> trigger="hover"
<el-dropdown trigger="hover" placement="right-start"> placement="right-start"
<el-button type="primary" :icon="ScaleToOriginal" style="margin-left: 10px;" v-if="!isTabPlanFather"> :disabled="!scope.isSelected"
标准设备管理
</el-button>
<template #dropdown >
<el-dropdown-menu>
<el-dropdown-item
v-for="child in planFormContent?.children"
:key="child.id"
@click="allotStandardDev(child)"
> >
{{ child.name }} <el-button
</el-dropdown-item> type="primary"
</el-dropdown-menu> :icon="ScaleToOriginal"
style="margin-left: 10px"
v-if="!isTabPlanFather"
:disabled="!scope.isSelected"
>
分配被检设备
</el-button>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item
v-for="child in planFormContent?.children"
:key="child.id"
@click="distribute(child, scope)"
>
{{ child.name }}
</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
<el-dropdown
v-if="planFormContent && planFormContent?.children.length > 0"
trigger="hover"
placement="right-start"
>
<el-button
type="primary"
:icon="ScaleToOriginal"
style="margin-left: 10px"
v-if="!isTabPlanFather"
>
标准设备管理
</el-button>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item
v-for="child in planFormContent?.children"
:key="child.id"
@click="allotStandardDev(child)"
>
{{ child.name }}
</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</template> </template>
</el-dropdown> <!-- 表格操作 -->
</template> <template #operation="scope">
<!-- 表格操作 --> <el-button
<template #operation="scope"> type="primary"
<el-button type="primary" link :icon="Delete" v-if="!isTabPlanFather" :disabled="scope.row.checkState != 0" @click="handleRemove(scope.row)">删除</el-button> link
<el-button type="primary" link :icon="Delete" v-if="isTabPlanFather" @click="subHandleRemove(scope.row)">移除</el-button> :icon="Delete"
</template> v-if="!isTabPlanFather"
</ProTable> :disabled="scope.row.checkState != 0"
</div> @click="handleRemove(scope.row)"
</el-dialog> >
<!-- 向计划导入/导出设备对话框 --> 删除
<PlanPopup :refresh-table='proTable?.getTableList' ref='planPopup' @update:tab="addNewChildTab"/> </el-button>
<DevTransfer ref='devTransfer' @update:table="addNewChildTab"/> <el-button
type="primary"
link
:icon="Delete"
v-if="isTabPlanFather"
@click="subHandleRemove(scope.row)"
>
移除
</el-button>
</template>
</ProTable>
</div>
</el-dialog>
<!-- 向计划导入/导出设备对话框 -->
<PlanPopup :refresh-table="proTable?.getTableList" ref="planPopup" @update:tab="addNewChildTab" />
<DevTransfer ref="devTransfer" @update:table="addNewChildTab" />
</template> </template>
<script setup lang="tsx"> <script setup lang="tsx">
import { ElMessage, ElMessageBox, TabPaneName } from 'element-plus' import { ElMessage, ElMessageBox, TabPaneName } from 'element-plus'
import { ref, computed, watch, reactive } from 'vue' import { computed, reactive, ref } from 'vue'
import { ScaleToOriginal, CirclePlus, Delete, Upload, Download } from '@element-plus/icons-vue' import { CirclePlus, Delete, ScaleToOriginal } from '@element-plus/icons-vue'
import PlanPopup from '@/views/plan/planList/components/planPopup.vue' // 导入子组件 import PlanPopup from '@/views/plan/planList/components/planPopup.vue' // 导入子组件
import { Plan } from '@/api/plan/interface' import { Plan } from '@/api/plan/interface'
import {useModeStore } from '@/stores/modules/mode'; // 引入模式 store import { useModeStore } from '@/stores/modules/mode' // 引入模式 store
import { ColumnProps, ProTableInstance, SearchRenderScope } from '@/components/ProTable/interface' import { ColumnProps, ProTableInstance, SearchRenderScope } from '@/components/ProTable/interface'
import {getDevListByPlanId ,subPlanBindDev,deletePlan} from '@/api/plan/plan' import { deletePlan, getDevListByPlanId, subPlanBindDev } from '@/api/plan/plan'
import { Device } from '@/api/device/interface/device' import { Device } from '@/api/device/interface/device'
import { useDictStore } from '@/stores/modules/dict' import { useDictStore } from '@/stores/modules/dict'
import DevTransfer from '@/views/plan/planList/components/devTransfer.vue' import DevTransfer from '@/views/plan/planList/components/devTransfer.vue'
import { useHandleData } from '@/hooks/useHandleData' import { useHandleData } from '@/hooks/useHandleData'
import router from '@/routers' import router from '@/routers'
const dictStore = useDictStore() const dictStore = useDictStore()
const planFormContent = ref<Plan.ReqPlan>() const planFormContent = ref<Plan.ReqPlan>()
const proTable = ref<ProTableInstance>() const proTable = ref<ProTableInstance>()
const modeStore = useModeStore(); const modeStore = useModeStore()
const planPopup = ref() const planPopup = ref()
const devTransfer = ref() const devTransfer = ref()
@@ -133,230 +165,228 @@ const patternId = ref('')
const getTableList = async (params: any) => { const getTableList = async (params: any) => {
if (!planFormContent.value) { if (!planFormContent.value) {
return Promise.resolve({ data: [], total: 0 }); return Promise.resolve({ data: [], total: 0 })
} }
let newParams = JSON.parse(JSON.stringify(params)); let newParams = JSON.parse(JSON.stringify(params))
newParams.pattern = patternId.value newParams.pattern = patternId.value
if(!isTabPlanFather.value) if (!isTabPlanFather.value) newParams.planId = planFormContent.value.id
newParams.planId = planFormContent.value.id else newParams.planId = planId.value
else newParams.planIdList = [newParams.planId]
newParams.planId = planId.value
newParams.planIdList = [newParams.planId];
proTable.value?.clearSelection() proTable.value?.clearSelection()
planTabDevList.value = await getDevListByPlanId(newParams); planTabDevList.value = await getDevListByPlanId(newParams)
return planTabDevList.value; return planTabDevList.value
} }
const columns = reactive<ColumnProps<Device.ResPqDev>[]>([ const columns = reactive<ColumnProps<Device.ResPqDev>[]>([
{ type: 'selection', fixed: 'left', width: 70,selectable: (row) => row.checkState == 0 }, { type: 'selection', fixed: 'left', width: 70, selectable: row => row.checkState == 0 },
{ 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: 180, minWidth: 180
}, },
{ {
prop: 'devType', prop: 'devType',
label: '设备类型', label: '设备类型',
minWidth: 150, minWidth: 150
}, },
{ {
prop: 'createDate', prop: 'createDate',
label: '出厂日期', label: '出厂日期',
minWidth: 150, minWidth: 150
}, },
{ {
prop: 'devChns', prop: 'devChns',
label: '通道数', label: '通道数',
minWidth: 100, minWidth: 100
}, },
{ {
prop: 'devVolt', prop: 'devVolt',
label: '额定电压V', label: '额定电压V',
minWidth: 150, minWidth: 150
}, },
{ {
prop: 'devCurr', prop: 'devCurr',
label: '额定电流A', label: '额定电流A',
minWidth: 150, minWidth: 150
}, },
{ {
prop: 'manufacturer', prop: 'manufacturer',
label: '设备厂家', label: '设备厂家',
enum: dictStore.getDictData('Dev_Manufacturers'), enum: dictStore.getDictData('Dev_Manufacturers'),
search: {el: 'select', props: {filterable: true}, order: 1}, search: { el: 'select', props: { filterable: true }, order: 1 },
fieldNames: {label: 'name', value: 'id'}, fieldNames: { label: 'name', value: 'id' },
minWidth: 200, minWidth: 200
}, },
{ {
prop: 'cityName', prop: 'cityName',
label: '地市', label: '地市',
minWidth: 150, minWidth: 150
},
}, {
{
prop: 'region', prop: 'region',
label: '地市', label: '地市',
minWidth: 150, minWidth: 150,
isShow:false, isShow: false,
search: { search: {
el: 'input', el: 'input',
label :'关键词', label: '关键词',
render: (scope: SearchRenderScope) => { render: (scope: SearchRenderScope) => {
return ( return <el-input v-model={scope.searchParam.region} placeholder="请输入关键词" clearable />
<el-input }
v-model={scope.searchParam.region}
placeholder="请输入关键词"
clearable
/>
);
}
} }
}, },
{ {
prop: 'gdName', prop: 'gdName',
label: '供电公司', label: '供电公司',
minWidth: 150, minWidth: 150
}, },
{ {
prop: 'subName', prop: 'subName',
label: '变电站', label: '变电站',
minWidth: 150, minWidth: 150
}, },
{ {
prop: 'boundPlanName', prop: 'boundPlanName',
label: '子计划', label: '子计划',
minWidth: 150, minWidth: 150,
render: (scope) => { render: scope => {
console.log('boundPlanName', isTabPlanFather.value) console.log('boundPlanName', isTabPlanFather.value)
const value = scope.row.boundPlanName; const value = scope.row.boundPlanName
if (!value) { if (!value) {
return '/'; // 空值直接返回空字符串 return '/' // 空值直接返回空字符串
} }
return ( return (
<el-link type='primary' link onClick={() => unbindDevice(scope.row)}> <el-link type="primary" link onClick={() => unbindDevice(scope.row)}>
{value} {value}
</el-link> </el-link>
); )
}, }
}, },
{ {
prop: 'checkState', prop: 'checkState',
label: '检测状态', label: '检测状态',
minWidth: 150, minWidth: 150,
render: (scope: { row: { checkState: number } }) => { render: (scope: { row: { checkState: number } }) => {
return ( return scope.row.checkState === 0 ? (
scope.row.checkState === 0 ? <el-tag type='warning' effect="dark">未检</el-tag> : <el-tag type="warning" effect="dark">
scope.row.checkState === 1 ? <el-tag type='danger' effect="dark">检测中</el-tag> : 未检
<el-tag type='success' effect="dark">检测完成</el-tag> </el-tag>
) ) : scope.row.checkState === 1 ? (
}, <el-tag type="danger" effect="dark">
}, 检测中
{ prop: 'operation', label: '操作', fixed: 'right', width: 100}, </el-tag>
]) ) : (
<el-tag type="success" effect="dark">
检测完成
</el-tag>
)
}
},
{ prop: 'operation', label: '操作', fixed: 'right', width: 100 }
])
const editableTabs = computed(() => { const editableTabs = computed(() => {
console.log('editableTabs',planFormContent.value) console.log('editableTabs', planFormContent.value)
const tabs = [] const tabs = []
// 主计划 tab // 主计划 tab
if (planFormContent.value) { if (planFormContent.value) {
tabs.push({ tabs.push({
title: planFormContent.value.name, title: planFormContent.value.name,
name: planFormContent.value.id, name: planFormContent.value.id,
closable: false closable: false
}) })
} }
// 子计划 tabs // 子计划 tabs
if (planFormContent.value?.children?.length > 0) { if (planFormContent.value?.children?.length > 0) {
planFormContent.value.children.forEach((child, index) => { planFormContent.value.children.forEach((child, index) => {
tabs.push({ tabs.push({
title: child.name, title: child.name,
name: child.id, name: child.id,
closable: true closable: true
}) })
}) })
} }
return tabs return tabs
}) })
//解绑被检设备 //解绑被检设备
const unbindDevice = (row: any) => { const unbindDevice = (row: any) => {
if(row.state == '/') if (row.state == '/') return
return
ElMessageBox.confirm(`确定将设备 ${row.name} 从子计划中解绑吗?`, '提示', { ElMessageBox.confirm(`确定将设备 ${row.name} 从子计划中解绑吗?`, '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}).then(async () => { })
if(row.checkState != 0){ .then(async () => {
ElMessage.warning(`当前设备已检,无法解除绑定!`); if (row.checkState != 0) {
return ElMessage.warning(`当前设备已检,无法解除绑定!`)
} return
await subPlanBindDev({'planId': row.planId, 'devIds': [row.id] ,'bindFlag': 0}) //解绑 0 绑定 1 }
// 👇 更新数据(例如清空 state 字段) await subPlanBindDev({ planId: row.planId, devIds: [row.id], bindFlag: 0 }) //解绑 0 绑定 1
row.state = '/' // 👇 更新数据(例如清空 state 字段)
proTable.value?.getTableList() row.state = '/'
// 可选:刷新表格或提交接口 proTable.value?.getTableList()
ElMessage.success('解绑成功') // 可选:刷新表格或提交接口
}).catch(() => { ElMessage.success('解绑成功')
// 用户取消操作 })
}) .catch(() => {
// 用户取消操作
})
} }
// 新增 tab 方法 // 新增 tab 方法
const addTab = (type: string) => { const addTab = (type: string) => {
if(type === "add"){ if (type === 'add') {
planPopup.value?.open("edit", planFormContent.value,modeStore.currentMode,1) planPopup.value?.open('edit', planFormContent.value, modeStore.currentMode, 1)
}else { } else {
const subPlanFormContent = ref<Plan.ReqPlan>() const subPlanFormContent = ref<Plan.ReqPlan>()
// 从 planFormContent.value?.children 中找到 id 与 item.name 匹配的子计划 // 从 planFormContent.value?.children 中找到 id 与 item.name 匹配的子计划
subPlanFormContent.value = planFormContent.value?.children?.find( subPlanFormContent.value = planFormContent.value?.children?.find(
(child: Plan.ReqPlan) => child.id === planId.value (child: Plan.ReqPlan) => child.id === planId.value
) )
console.log('0000---',subPlanFormContent.value) console.log('0000---', subPlanFormContent.value)
planPopup.value?.open("edit", subPlanFormContent.value,modeStore.currentMode,2) planPopup.value?.open('edit', subPlanFormContent.value, modeStore.currentMode, 2)
} }
} }
//收到子组件回复后新增子计划tab //收到子组件回复后新增子计划tab
const addNewChildTab = async () => { const addNewChildTab = async () => {
await props.refreshTable!()//刷新检测计划列表 await props.refreshTable!() //刷新检测计划列表
} }
//分配被检设备 //分配被检设备
const distribute = (childPlan: Plan.ResPlan, scope: any) => { const distribute = (childPlan: Plan.ResPlan, scope: any) => {
// 获取当前选中的设备对象
// 获取当前选中的设备对象 const selectedDevices = planTabDevList.value.data.records.filter((dev: { id: any }) =>
const selectedDevices = planTabDevList.value.data.records.filter((dev: { id: any }) => scope.selectedListIds.includes(dev.id)
scope.selectedListIds.includes(dev.id) )
); // 找出不符合条件的设备
// 找出不符合条件的设备 const invalidDevices = selectedDevices.filter(
const invalidDevices = selectedDevices.filter( (dev: { checkState: number; assign: number }) => dev.checkState !== 0 || dev.assign === 1
(dev: { checkState: number; assign: number }) => dev.checkState !== 0 || dev.assign === 1 )
); if (invalidDevices.length > 0) {
if (invalidDevices.length > 0) { const names = invalidDevices.map((dev: { name: any }) => dev.name).join('、')
const names = invalidDevices.map((dev: { name: any }) => dev.name).join('、'); ElMessage.warning(`以下设备不可分配:${names}`)
ElMessage.warning(`以下设备不可分配:${names}`); proTable.value?.clearSelection()
proTable.value?.clearSelection() return
return; }
} ElMessageBox.confirm(`确定将以下被检设备分配给 ${childPlan.name} 吗?`, '提示', {
ElMessageBox.confirm(`确定将以下被检设备分配给 ${childPlan.name} 吗?`, '提示', { confirmButtonText: '确定',
confirmButtonText: '确定', cancelButtonText: '取消',
cancelButtonText: '取消', type: 'warning'
type: 'warning', })
}).then(async () => { .then(async () => {
await subPlanBindDev({'planId': childPlan.id, 'devIds': scope.selectedListIds ,'bindFlag': 1}) //解绑 0 绑定 1 await subPlanBindDev({ planId: childPlan.id, devIds: scope.selectedListIds, bindFlag: 1 }) //解绑 0 绑定 1
proTable.value?.getTableList() proTable.value?.getTableList()
ElMessage.success('分配成功') ElMessage.success('分配成功')
}).catch(() => { })
// 用户取消操作 .catch(() => {
}) // 用户取消操作
})
} }
const allotStandardDev = (childPlan: Plan.ResPlan) => { const allotStandardDev = (childPlan: Plan.ResPlan) => {
@@ -365,177 +395,176 @@ const allotStandardDev = (childPlan: Plan.ResPlan) => {
// 删除 tab 方法 // 删除 tab 方法
const removeTab = async (targetName: TabPaneName) => { const removeTab = async (targetName: TabPaneName) => {
// 找到匹配的 tab // 找到匹配的 tab
const tab = editableTabs.value.find(item => item.name === targetName); const tab = editableTabs.value.find(item => item.name === targetName)
const tabTitle = tab?.title || '未知计划'; // 获取 tab 的标题,若不存在则默认为 '未知计划' const tabTitle = tab?.title || '未知计划' // 获取 tab 的标题,若不存在则默认为 '未知计划'
await useHandleData(deletePlan, { id: [targetName], pattern: patternId.value }, `删除【${tabTitle}】检测计划`); await useHandleData(deletePlan, { id: [targetName], pattern: patternId.value }, `删除【${tabTitle}】检测计划`)
await props.refreshTable!()//刷新检测计划列表 await props.refreshTable!() //刷新检测计划列表
} }
// 弹窗打开方法 // 弹窗打开方法
const open = async (textTitle: string,data: Plan.ReqPlan,pattern: string) => { const open = async (textTitle: string, data: Plan.ReqPlan, pattern: string) => {
console.log('open',data) console.log('open', data)
dialogVisible.value = true dialogVisible.value = true
title.value = textTitle title.value = textTitle
planTitle.value = data.name planTitle.value = data.name
planId.value = data.id planId.value = data.id
planFormContent.value = data planFormContent.value = data
editableTabsValue.value = planFormContent.value.id//默认tab第一个 editableTabsValue.value = planFormContent.value.id //默认tab第一个
proTable.value?.getTableList() proTable.value?.getTableList()
isTabPlanFather.value = false//子计划页面按钮默认展示主计划的 isTabPlanFather.value = false //子计划页面按钮默认展示主计划的
patternId.value = pattern patternId.value = pattern
columns.forEach(item => {//刚进去子计划页面隐藏主计划的操作列 columns.forEach(item => {
if (item.prop === 'operation') { //刚进去子计划页面隐藏主计划的操作列
item.isShow = false; if (item.prop === 'operation') {
} item.isShow = false
}); }
})
} }
const handleTabClick = (tab:any) => { const handleTabClick = (tab: any) => {
if(tab.props.closable){ if (tab.props.closable) {
columns.forEach(item => {//隐藏子计划名称 columns.forEach(item => {
if (item.prop === 'boundPlanName') { //隐藏子计划名称
item.isShow = false; if (item.prop === 'boundPlanName') {
} item.isShow = false
if (item.prop === 'operation') { }
item.isShow = true; if (item.prop === 'operation') {
} item.isShow = true
}); }
isTabPlanFather.value = true })
}else{ isTabPlanFather.value = true
columns.forEach(item => { } else {
if (item.prop === 'boundPlanName') { columns.forEach(item => {
item.isShow = true; if (item.prop === 'boundPlanName') {
} item.isShow = true
if (item.prop === 'operation') { }
item.isShow = false; if (item.prop === 'operation') {
} item.isShow = false
}); }
isTabPlanFather.value = false })
} isTabPlanFather.value = false
planId.value = tab.props.name }
proTable.value?.getTableList() planId.value = tab.props.name
proTable.value?.getTableList()
} }
const handleTableDataUpdate = async (newData: any[]) => { const handleTableDataUpdate = async (newData: any[]) => {
// 👇 处理新数据,例如更新 planFormContent // 👇 处理新数据,例如更新 planFormContent
console.log('handleTableDataUpdate', newData) console.log('handleTableDataUpdate', newData)
const matchedItem = findItemById(newData, planId.value); const matchedItem = findItemById(newData, planId.value)
if (matchedItem) { if (matchedItem) {
planFormContent.value = matchedItem planFormContent.value = matchedItem
console.log('递归匹配成功:', planFormContent.value) console.log('递归匹配成功:', planFormContent.value)
} else { } else {
console.warn('未找到匹配的 planId:', planId.value) console.warn('未找到匹配的 planId:', planId.value)
} }
} }
const findItemById = (data: any[], id: string): any => { const findItemById = (data: any[], id: string): any => {
for (const item of data) { for (const item of data) {
if (item.id === id) { if (item.id === id) {
return item; // 找到匹配项,返回它 return item // 找到匹配项,返回它
}
if (item.children && item.children.length > 0) {
const result = findItemById(item.children, id) // 递归查找子项
if (result) {
return item // 如果子项中找到,返回结果
}
}
} }
if (item.children && item.children.length > 0) { return null // 未找到匹配项
const result = findItemById(item.children, id); // 递归查找子项 }
if (result) {
return item; // 如果子项中找到,返回结果
}
}
}
return null; // 未找到匹配项
};
//主计划下移除被检设备 //主计划下移除被检设备
const handleRemove = async (row: any) => { const handleRemove = async (row: any) => {
ElMessageBox.confirm(`确定要移除计划【${row.name}】吗?`, '提示', { ElMessageBox.confirm(`确定要移除计划【${row.name}】吗?`, '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}).then(async () => { })
if(row.assign != 0){ .then(async () => {
ElMessage.warning(`当前设备已被子计划绑定,无法删除!`); if (row.assign != 0) {
return ElMessage.warning(`当前设备已被子计划绑定,无法删除!`)
} return
console.log('shcn',planFormContent.value) }
proTable.value?.getTableList(); // 刷新当前表格 console.log('shcn', planFormContent.value)
}).catch(() => { proTable.value?.getTableList() // 刷新当前表格
// 用户取消操作 })
}); .catch(() => {
// 用户取消操作
})
} }
//子计划下移除被检设备 //子计划下移除被检设备
const subHandleRemove = async (row: any) => { const subHandleRemove = async (row: any) => {
ElMessageBox.confirm(`确定要移除计划【${row.name}】吗?`, '提示', { ElMessageBox.confirm(`确定要移除计划【${row.name}】吗?`, '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}).then(async () => { })
if(row.checkState != 0){ .then(async () => {
ElMessage.warning(`当前设备已检,无法移除!`); if (row.checkState != 0) {
return ElMessage.warning(`当前设备已检,无法移除!`)
} return
await subPlanBindDev({'planId': row.planId, 'devIds': [row.id] ,'bindFlag': 0}) //解绑 0 绑定 1 }
ElMessage.success('移除成功'); await subPlanBindDev({ planId: row.planId, devIds: [row.id], bindFlag: 0 }) //解绑 0 绑定 1
proTable.value?.getTableList(); // 刷新当前表格 ElMessage.success('移除成功')
}).catch(() => { proTable.value?.getTableList() // 刷新当前表格
// 用户取消操作 })
}); .catch(() => {
// 用户取消操作
})
} }
// 子计划下批量移除被检设备 // 子计划下批量移除被检设备
const subBatchRemove = async (selectedListIds: string[]) => { const subBatchRemove = async (selectedListIds: string[]) => {
const selectedDevices = planTabDevList.value.data.records.filter((dev: { id: any }) =>
selectedListIds.includes(dev.id)
)
const invalidDevices = selectedDevices.filter((dev: { checkState: number }) => dev.checkState !== 0)
const selectedDevices = planTabDevList.value.data.records.filter((dev: { id: any }) => if (invalidDevices.length > 0) {
selectedListIds.includes(dev.id) const names = invalidDevices.map((dev: { name: any }) => dev.name).join('、')
); ElMessage.warning(`以下设备不可移除(已检):${names}`)
proTable.value?.clearSelection()
return
}
const invalidDevices = selectedDevices.filter( try {
(dev: { checkState: number }) => dev.checkState !== 0 await ElMessageBox.confirm(`确定要批量移除选中的 ${selectedListIds.length} 个设备吗?`, '提示', {
); confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
})
if (invalidDevices.length > 0) { await subPlanBindDev({ planId: planId.value, devIds: selectedListIds, bindFlag: 0 })
const names = invalidDevices.map((dev: { name: any }) => dev.name).join('、'); ElMessage.success('批量移除成功')
ElMessage.warning(`以下设备不可移除(已检):${names}`); proTable.value?.getTableList() // 刷新表格
proTable.value?.clearSelection(); } catch (error) {
return; // 用户取消或接口异常
} console.error('批量移除失败:', error)
}
try {
await ElMessageBox.confirm(`确定要批量移除选中的 ${selectedListIds.length} 个设备吗?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
});
await subPlanBindDev({ planId: planId.value, devIds: selectedListIds, bindFlag: 0 });
ElMessage.success('批量移除成功');
proTable.value?.getTableList(); // 刷新表格
} catch (error) {
// 用户取消或接口异常
console.error('批量移除失败:', error);
}
};
const handleClose = () => {
dialogVisible.value = false
router.push('/plan/planList')
} }
defineExpose({ open,handleTableDataUpdate }) const handleClose = () => {
dialogVisible.value = false
router.push('/plan/planList')
}
defineExpose({ open, handleTableDataUpdate })
interface ChildrenPlanProps { interface ChildrenPlanProps {
refreshTable?: () => Promise<void> refreshTable?: () => Promise<void>
width?: number width?: number
height?: number height?: number
} }
const props = withDefaults(defineProps<ChildrenPlanProps>(), { const props = withDefaults(defineProps<ChildrenPlanProps>(), {
width: 800, width: 800,
height: 744 height: 744
}) })
// const props = defineProps<{ // const props = defineProps<{
// refreshTable: (() => Promise<void>) | undefined; // refreshTable: (() => Promise<void>) | undefined;

View File

@@ -1,99 +1,134 @@
<template> <template>
<!-- 权限信息弹出框 --> <!-- 权限信息弹出框 -->
<el-dialog title="标准设备绑定" v-model='dialogVisible' @close="close" v-bind="dialogBig" width="600" draggable> <el-dialog title="标准设备绑定" v-model="dialogVisible" @close="close" v-bind="dialogBig" width="700" draggable>
<div> <div>
<el-transfer v-model="value" <el-transfer
filterable v-model="value"
:filter-method="filterMethod" filterable
filter-placeholder="请输入内容搜索" :filter-method="filterMethod"
:data="allData" filter-placeholder="请输入内容搜索"
:titles="['未绑定标准设备', '已绑定标准设备']"> :data="allData"
<template #default="{ option }"> :titles="['未绑定标准设备', '已绑定标准设备']"
<el-tooltip :content="option.tips" placement="top" :show-after=1000> >
<span>{{ option.label }}</span> <template #default="{ option }">
</el-tooltip> <div style="display: flex; align-items: center; justify-content: space-between">
</template> <span>{{ JSON.parse(option.label).manufacturer }} - {{ JSON.parse(option.label).name }}</span>
</el-transfer> <!-- <el-tooltip placement="top" effect="light">
<template #content>
<el-descriptions size="small" title="标准设备详情" border>
<el-descriptions-item label="设备名称">
{{ JSON.parse(option.label).name }}
</el-descriptions-item>
<el-descriptions-item label="设备厂家">
{{ JSON.parse(option.label).manufacturer }}
</el-descriptions-item>
</el-descriptions>
</template>
<el-icon><Warning /></el-icon>
</el-tooltip>-->
</div>
</template>
</el-transfer>
</div>
<template #footer>
<div class="dialog-footer">
<el-button @click="close()">取消</el-button>
<el-button type="primary" @click="save()">保存</el-button>
</div>
</template>
</el-dialog>
</template>
</div> <script lang="ts" setup>
<template #footer> import { computed, ref } from 'vue'
<div class="dialog-footer"> import type { StandardDevice } from '@/api/device/interface/standardDevice'
<el-button @click="close()">取消</el-button> import { dialogBig } from '@/utils/elementBind'
<el-button type="primary" @click="save()"> import { getBoundStandardDevList, getUnboundStandardDevList, subPlanBindStandardDevList } from '@/api/plan/plan.ts'
保存 import { type Plan } from '@/api/plan/interface'
</el-button> import { ElMessage } from 'element-plus'
</div> import { useDictStore } from '@/stores/modules/dict'
</template>
</el-dialog>
</template>
<script lang="ts" setup> const unboundStandardDevList = ref<StandardDevice.ResPqStandardDevice[]>([]) //指定模式下所有未绑定的标准设备
import { computed, ref } from 'vue' const boundStandardDevList = ref<StandardDevice.ResPqStandardDevice[]>([]) //根据检测计划id查询出所有已绑定的标准设备
import type { StandardDevice } from '@/api/device/interface/standardDevice' const dialogVisible = ref(false)
import { dialogBig } from '@/utils/elementBind' const planData = ref<Plan.ReqPlan | null>(null) // 新增状态管理
import { getBoundStandardDevList,getUnboundStandardDevList,subPlanBindStandardDevList } from '@/api/plan/plan.ts'
import { type Plan } from '@/api/plan/interface'
import { ElMessage } from 'element-plus'
const unboundStandardDevList=ref<StandardDevice.ResPqStandardDevice[]>([])//指定模式下所有未绑定的标准设备
const boundStandardDevList=ref<StandardDevice.ResPqStandardDevice[]>([])//根据检测计划id查询出所有已绑定的标准设备
const dialogVisible = ref(false)
const planData = ref<Plan.ReqPlan | null>(null) // 新增状态管理
const value = ref<string[]>([]) const value = ref<string[]>([])
const generateData = () => { const dictStore = useDictStore()
const unboundData = unboundStandardDevList.value.map((i: StandardDevice.ResPqStandardDevice) => ({ const generateData = () => {
key: i.id, const manufacturerDict = dictStore.getDictData('Dev_Manufacturers')
label: i.name, unboundStandardDevList.value.forEach(i => {
})) // 确保字段不为空且字典存在再进行查找
const boundData = boundStandardDevList.value.map((i: StandardDevice.ResPqStandardDevice) => ({ if (i.manufacturer && manufacturerDict) {
key: i.id, const manufacturer = manufacturerDict.find(item => item.id === i.manufacturer)
label: i.name, if (manufacturer) {
})) i.manufacturer = manufacturer.name
}
return [...unboundData, ...boundData] }
})
const unboundData = unboundStandardDevList.value.map((i: StandardDevice.ResPqStandardDevice) => ({
key: i.id,
label: JSON.stringify(i)
}))
boundStandardDevList.value.forEach(i => {
// 确保字段不为空且字典存在再进行查找
if (i.manufacturer && manufacturerDict) {
const manufacturer = manufacturerDict.find(item => item.id === i.manufacturer)
if (manufacturer) {
i.manufacturer = manufacturer.name
}
}
})
const boundData = boundStandardDevList.value.map((i: StandardDevice.ResPqStandardDevice) => ({
key: i.id,
label: JSON.stringify(i)
}))
return [...unboundData, ...boundData]
} }
const allData = computed(() => generateData()) const allData = computed(() => generateData())
const filterMethod = (query: string, item: { label?: string }) => { const filterMethod = (query: string, item: { label?: string }) => {
return item.label?.toLowerCase().includes(query.toLowerCase()) ?? false return item.label?.toLowerCase().includes(query.toLowerCase()) ?? false
} }
// 打开弹窗,可能是新增,也可能是编辑 // 打开弹窗,可能是新增,也可能是编辑
const open = async (data: Plan.ReqPlan) => { const open = async (data: Plan.ReqPlan) => {
dialogVisible.value = true dialogVisible.value = true
planData.value = data planData.value = data
console.log('planData.value',planData.value) console.log('planData.value', planData.value)
const standardDevList_Result1 = await getUnboundStandardDevList(data); const standardDevList_Result1 = await getUnboundStandardDevList(data)
unboundStandardDevList.value = standardDevList_Result1.data as StandardDevice.ResPqStandardDevice[]; unboundStandardDevList.value = standardDevList_Result1.data as StandardDevice.ResPqStandardDevice[]
const standardDevList_Result2 = await getBoundStandardDevList(data); const standardDevList_Result2 = await getBoundStandardDevList(data)
boundStandardDevList.value = standardDevList_Result2.data as StandardDevice.ResPqStandardDevice[]; boundStandardDevList.value = standardDevList_Result2.data as StandardDevice.ResPqStandardDevice[]
value.value = boundStandardDevList.value.map((i: { id: { toString: () => any } }) => i.id.toString());
value.value = boundStandardDevList.value.map((i: { id: { toString: () => any } }) => i.id.toString())
} }
const close = () => { const close = () => {
dialogVisible.value = false dialogVisible.value = false
} }
const emit = defineEmits(['update:table'])
const emit = defineEmits(['update:table']) const save = async () => {
const save = async () => {
if (planData.value) { if (planData.value) {
planData.value.planId = planData.value.id planData.value.planId = planData.value.id
planData.value.devIds = value.value planData.value.devIds = value.value
await subPlanBindStandardDevList(planData.value) await subPlanBindStandardDevList(planData.value)
emit('update:table') emit('update:table')
ElMessage.success({ message: `标准设备绑定保存成功!` }) ElMessage.success({ message: `标准设备绑定保存成功!` })
} }
dialogVisible.value = false dialogVisible.value = false
} }
// 对外映射 // 对外映射
defineExpose({ open }) defineExpose({ open })
</script>
</script> <style scoped lang="scss">
:deep(.el-transfer) {
--el-transfer-panel-width: 250px;
--el-transfer-panel-body-height: 315px;
}
</style>

View File

@@ -9,7 +9,7 @@
align-center align-center
> >
<el-row :gutter="24"> <el-row :gutter="24">
<el-col :span="planType == 0 ? 10 : 24"> <el-col :span="10">
<el-form :model="formContent" ref="dialogFormRef" :rules="rules"> <el-form :model="formContent" ref="dialogFormRef" :rules="rules">
<el-form-item label="名称" prop="name" :label-width="110"> <el-form-item label="名称" prop="name" :label-width="110">
<el-input <el-input
@@ -20,18 +20,13 @@
show-word-limit show-word-limit
/> />
</el-form-item> </el-form-item>
<el-form-item <el-form-item label="标准设备" prop="standardDevIds" :label-width="110">
label="标准设备"
prop="standardDevIds"
:label-width="110"
v-if="selectByMode && planType == 0"
>
<el-select <el-select
v-model="formContent.standardDevIds" v-model="formContent.standardDevIds"
multiple multiple
filterable
collapse-tags collapse-tags
:max-collapse-tags="2" :max-collapse-tags="2"
:disabled="planType != 0"
placeholder="请选择标准设备" placeholder="请选择标准设备"
clearable clearable
> >
@@ -46,6 +41,7 @@
</el-form-item> </el-form-item>
<el-form-item label="测试项" prop="testItems" :label-width="110" v-if="selectByMode"> <el-form-item label="测试项" prop="testItems" :label-width="110" v-if="selectByMode">
<el-select <el-select
filterable
v-model="formContent.testItems" v-model="formContent.testItems"
multiple multiple
collapse-tags collapse-tags
@@ -64,6 +60,7 @@
</el-form-item> </el-form-item>
<el-form-item label="检测源" prop="sourceIds" :label-width="110" v-if="!selectByMode"> <el-form-item label="检测源" prop="sourceIds" :label-width="110" v-if="!selectByMode">
<el-select <el-select
filterable
v-model="formContent.sourceIds" v-model="formContent.sourceIds"
:multiple="selectByMode" :multiple="selectByMode"
collapse-tags collapse-tags
@@ -80,6 +77,7 @@
</el-form-item> </el-form-item>
<el-form-item label="数据源" prop="datasourceIds" :label-width="110"> <el-form-item label="数据源" prop="datasourceIds" :label-width="110">
<el-select <el-select
filterable
v-model="formContent.datasourceIds" v-model="formContent.datasourceIds"
:multiple="selectByMode" :multiple="selectByMode"
:max-collapse-tags="2" :max-collapse-tags="2"
@@ -116,6 +114,7 @@
</el-form-item> </el-form-item>
<el-form-item label="误差体系" prop="errorSysId" :label-width="110"> <el-form-item label="误差体系" prop="errorSysId" :label-width="110">
<el-select <el-select
filterable
v-model="formContent.errorSysId" v-model="formContent.errorSysId"
placeholder="请选择误差体系" placeholder="请选择误差体系"
autocomplete="off" autocomplete="off"
@@ -180,7 +179,7 @@
</el-form-item> </el-form-item>
</el-form> </el-form>
</el-col> </el-col>
<el-col :span="14" v-if="planType == 0"> <el-col :span="14">
<el-transfer <el-transfer
v-model="value" v-model="value"
filterable filterable
@@ -190,7 +189,7 @@
:titles="['未绑定被检设备', '已绑定被检设备']" :titles="['未绑定被检设备', '已绑定被检设备']"
> >
<template #default="{ option }"> <template #default="{ option }">
<div style="display: flex; align-items: center; justify-content:space-between"> <div style="display: flex; align-items: center; justify-content: space-between">
<span> <span>
{{ JSON.parse(option.label).manufacturer }} - {{ JSON.parse(option.label).name }} {{ JSON.parse(option.label).manufacturer }} - {{ JSON.parse(option.label).name }}
</span> </span>
@@ -219,7 +218,7 @@
</div> </div>
</template> </template>
<template #left-footer> <template #left-footer v-if="planType === 0">
<el-button <el-button
class="transfer-footer" class="transfer-footer"
v-if="modeStore.currentMode !== '比对式'" v-if="modeStore.currentMode !== '比对式'"
@@ -243,7 +242,7 @@
导入被检设备 导入被检设备
</el-button> </el-button>
</template> </template>
<template #right-footer> <template #right-footer v-if="planType === 0">
<el-text></el-text> <el-text></el-text>
</template> </template>
<template #left-empty> <template #left-empty>
@@ -261,7 +260,7 @@
<el-button type="primary" @click="save()"> </el-button> <el-button type="primary" @click="save()"> </el-button>
</div> </div>
</template> </template>
<ImportExcel ref="deviceImportExcel" /> <ImportExcel ref="deviceImportExcel" @result="importResult" />
</el-dialog> </el-dialog>
</template> </template>
@@ -273,12 +272,12 @@ import { type Plan } from '@/api/plan/interface'
import { import {
addPlan, addPlan,
getBoundPqDevList, getBoundPqDevList,
getBoundStandardDevAllList,
getPqErrSysList, getPqErrSysList,
getPqScriptList, getPqScriptList,
getTestSourceList, getTestSourceList,
getUnboundPqDevList, getUnboundPqDevList,
updatePlan, updatePlan
updateSubPlanName
} from '@/api/plan/plan.ts' } from '@/api/plan/plan.ts'
import { useDictStore } from '@/stores/modules/dict' import { useDictStore } from '@/stores/modules/dict'
import { type TestSource } from '@/api/device/interface/testSource' import { type TestSource } from '@/api/device/interface/testSource'
@@ -322,7 +321,7 @@ const userArray = ref<{ label: string; value: string }[]>([])
const unboundPqDevList = ref<Device.ResPqDev[]>([]) //指定模式下所有未绑定的设备 const unboundPqDevList = ref<Device.ResPqDev[]>([]) //指定模式下所有未绑定的设备
const boundPqDevList = ref<Device.ResPqDev[]>([]) //根据检测计划id查询出所有已绑定的设备 const boundPqDevList = ref<Device.ResPqDev[]>([]) //根据检测计划id查询出所有已绑定的设备
const value = ref<string[]>([]) const value = ref<string[]>([])
const allData = computed(() => generateData()) const allData = ref<[any[], any[]]>([])
const isSelectDisabled = ref(false) const isSelectDisabled = ref(false)
const planType = ref<number>(0) const planType = ref<number>(0)
const subPlanBindStandardDev = ref<any>([]) //哪些标准设备已经被子计划绑定 const subPlanBindStandardDev = ref<any>([]) //哪些标准设备已经被子计划绑定
@@ -359,7 +358,7 @@ const generateData = () => {
//tips: i.description //tips: i.description
disabled: i.checkState != 0 || i.assign == 1 disabled: i.checkState != 0 || i.assign == 1
})) }))
return [...unboundData, ...boundData] allData.value = [...unboundData, ...boundData]
} }
const filterMethod = (query: string, item: { label?: string }) => { const filterMethod = (query: string, item: { label?: string }) => {
@@ -504,7 +503,6 @@ const save = () => {
dialogFormRef.value?.validate(async (valid: boolean) => { dialogFormRef.value?.validate(async (valid: boolean) => {
if (valid) { if (valid) {
formContent.devIds = value.value formContent.devIds = value.value
if (formContent.id) { if (formContent.id) {
// 把数据处理原则转成字典ID // 把数据处理原则转成字典ID
const patternItem = dictStore const patternItem = dictStore
@@ -514,16 +512,18 @@ const save = () => {
formContent.dataRule = patternItem.id formContent.dataRule = patternItem.id
} }
if (mode.value === '比对式') { if (mode.value === '比对式') {
// 新增子计划
if (planType.value == 1) { if (planType.value == 1) {
formContent.fatherPlanId = formContent.id formContent.fatherPlanId = formContent.id
formContent.id = '' formContent.id = ''
formContent.devIds = [] //formContent.devIds = []
formContent.standardDevIds = [] //formContent.standardDevIds = []
formContent.standardDevMap = new Map<string, number>() // formContent.standardDevMap = new Map<string, number>()
await addPlan(formContent) await addPlan(formContent)
emit('update:tab') emit('update:tab')
// 编辑子计划
} else if (planType.value == 2) { } else if (planType.value == 2) {
await updateSubPlanName(formContent) await updatePlan(formContent)
emit('update:tab') emit('update:tab')
console.log('更新子计划', formContent) console.log('更新子计划', formContent)
} else { } else {
@@ -565,9 +565,7 @@ const save = () => {
} }
close() close()
// 刷新表格 // 刷新表格
if (planType.value == 0) { await props.refreshTable!()
await props.refreshTable!()
}
} }
}) })
} catch (err) { } catch (err) {
@@ -759,8 +757,20 @@ const open = async (sign: string, data: Plan.ReqPlan, currentMode: string, plan:
Object.assign(formContent, { ...data }) Object.assign(formContent, { ...data })
//设备绑定显示 //设备绑定显示
unboundPqDevList.value = unboundData as Device.ResPqDev[] if (planType.value === 0) {
boundPqDevList.value = boundData as Device.ResPqDev[] unboundPqDevList.value = unboundData as Device.ResPqDev[]
boundPqDevList.value = boundData as Device.ResPqDev[]
} else if (planType.value === 1) {
unboundPqDevList.value = boundData.filter(i => !i.boundPlanName) as Device.ResPqDev[]
} else if (planType.value === 2) {
const fatherBoundData_Result = await getBoundPqDevList({ planIdList: [data.fatherPlanId] })
const fatherBoundData = Array.isArray(fatherBoundData_Result.data) ? fatherBoundData_Result.data : []
// 从 fatherBoundData 中排除 boundData 中已存在的数据(根据 id 进行比较)
unboundPqDevList.value = fatherBoundData.filter(
fatherItem => !boundData.some(boundItem => boundItem.id === fatherItem.id)
) as Device.ResPqDev[]
boundPqDevList.value = boundData as Device.ResPqDev[]
}
} }
pqToArray() //将对象转为数组 pqToArray() //将对象转为数组
@@ -796,6 +806,7 @@ const open = async (sign: string, data: Plan.ReqPlan, currentMode: string, plan:
value: item.id value: item.id
})) }))
} }
generateData()
// 所有数据加载完成后显示对话框 // 所有数据加载完成后显示对话框
dialogVisible.value = true dialogVisible.value = true
} }
@@ -837,10 +848,30 @@ function pqToArray() {
})) }))
const sourceArray5 = Array.isArray(pqStandardDevList.value) ? pqStandardDevList.value : [] const sourceArray5 = Array.isArray(pqStandardDevList.value) ? pqStandardDevList.value : []
pqStandardDevArray.value = sourceArray5.map(item => ({ if (planType.value === 0) {
label: item.name, pqStandardDevArray.value = sourceArray5.map(item => ({
value: item.id label: item.name,
})) value: item.id
}))
} else if (planType.value === 1) {
pqStandardDevArray.value = sourceArray5
.filter(item => formContent.standardDevIds.includes(item.id))
.map(item => ({
label: item.name,
value: item.id
}))
formContent.standardDevIds = []
formContent.standardDevMap = new Map<string, number>()
} else if (planType.value === 2) {
const params = { id: formContent.id }
getBoundStandardDevAllList(params).then(result => {
const boundStandardDevAllList = Array.isArray(result.data) ? result.data : []
pqStandardDevArray.value = boundStandardDevAllList.map(item => ({
label: item.name,
value: item.id
}))
})
}
} }
const dataSourceType = computed(() => { const dataSourceType = computed(() => {
@@ -899,7 +930,17 @@ const importFile = async (pattern: string) => {
} }
deviceImportExcel.value?.acceptParams(params) deviceImportExcel.value?.acceptParams(params)
} }
const importResult = async (success: boolean | undefined) => {
if (success) {
const patternId = dictStore.getDictData('Pattern').find(item => item.name === mode.value)?.id ?? ''
const data = { pattern: patternId }
// 刷新未绑定的
const unboundPqDevList_Result = await getUnboundPqDevList(data)
const unboundData = Array.isArray(unboundPqDevList_Result.data) ? unboundPqDevList_Result.data : []
unboundPqDevList.value = unboundData
generateData()
}
}
// 对外映射 // 对外映射
defineExpose({ open }) defineExpose({ open })
const props = defineProps<{ const props = defineProps<{