比对检测计划
This commit is contained in:
@@ -3,15 +3,17 @@
|
||||
<ProTable
|
||||
ref='proTable'
|
||||
:columns='columns'
|
||||
:request-api='getTableList'
|
||||
:data="currentPageData"
|
||||
:request-api='getTableList'
|
||||
:pagination="false"
|
||||
>
|
||||
<!-- 表格 header 按钮 -->
|
||||
<template #tableHeader='scope'>
|
||||
<el-button type='primary' v-auth.plan="'import'" :icon='Download' @click='importClick' v-if="modeStore.currentMode != '比对式'">导入</el-button>
|
||||
<el-button type='primary' v-auth.plan="'export'" :icon='Upload' @click='exportClick' v-if="modeStore.currentMode != '比对式'">导出</el-button>
|
||||
<el-button type='primary' v-auth.plan="'combine'" :icon='ScaleToOriginal' :disabled='!(scope.selectedList.length > 1)' @click='combineClick'>
|
||||
<!-- <el-button type='primary' v-auth.plan="'combine'" :icon='ScaleToOriginal' :disabled='!(scope.selectedList.length > 1)' @click='combineClick'>
|
||||
合并
|
||||
</el-button>
|
||||
</el-button> -->
|
||||
<el-button type='primary' v-auth.plan="'add'" :icon='CirclePlus' @click="openDialog('add')">新增</el-button>
|
||||
<el-button type='primary' v-auth.plan="'analysis'" :icon='List' :disabled='!scope.isSelected' @click='statisticalAnalysisMore(scope.selectedListIds,scope.selectedList)'>统计分析</el-button>
|
||||
<el-button type='danger' v-auth.plan="'delete'" :icon='Delete' plain :disabled='!scope.isSelected' @click='batchDelete(scope.selectedListIds)'>
|
||||
@@ -23,37 +25,50 @@
|
||||
<template #operation='scope'>
|
||||
<el-button type='primary' v-auth.plan="'edit'" link :icon='EditPen' @click="openDialog('edit',scope.row)">编辑</el-button>
|
||||
<el-button type='primary' v-auth.plan="'delete'" link :icon='Delete' @click='handleDelete(scope.row)'>删除</el-button>
|
||||
<el-button type='primary' link :icon='List' @click="openTestSource(scope.row)">子计划</el-button>
|
||||
<el-button type='primary' link :icon='List' @click="openChildrenPlan(scope.row)" v-if="modeStore.currentMode == '比对式' && scope.row.fatherPlanId == 0">子计划</el-button>
|
||||
<!-- <el-button type='primary' link :icon='List' @click='showDeviceOpen(scope.row)'>设备绑定</el-button> -->
|
||||
<el-button type='primary' v-auth.plan="'analysis'" link :icon='List' v-if="scope.row.testState == '2'" @click='statisticalAnalysis(scope.row)'>统计分析</el-button>
|
||||
</template>
|
||||
|
||||
<!-- 在此处新增 footer 插槽 -->
|
||||
<template #pagination ='scope'>
|
||||
<el-pagination
|
||||
:background="true"
|
||||
:current-page="currentPage"
|
||||
:page-size="pageSize"
|
||||
:page-sizes="[10, 25, 50, 100]"
|
||||
:total="pageTotal"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
@size-change="handleSizeChange"
|
||||
@current-change="handleCurrentChange"
|
||||
/>
|
||||
</template>
|
||||
</ProTable>
|
||||
</div>
|
||||
|
||||
<!-- 向计划导入/导出设备对话框 -->
|
||||
<PlanPopup :refresh-table='proTable?.getTableList' ref='planPopup'/>
|
||||
<PlanPopup :refresh-table='refreshTable' ref='planPopup'/>
|
||||
<!-- 查看误差体系详细信息 -->
|
||||
<ErrorStandardPopup :refresh-table='proTable?.getTableList' ref="errorStandardPopup"/>
|
||||
<!-- 查看检测源 -->
|
||||
<TestSourcePopup :refresh-table='proTable?.getTableList' ref="testSourcePopup"/>
|
||||
<!-- 查看设备绑定
|
||||
<DevTransfer :refresh-table='proTable?.getTableList' ref='devTransferPopup'/> -->
|
||||
|
||||
<ImportExcel ref='planImportExcel' />
|
||||
<SourceOpen :refresh-table='proTable?.getTableList' ref='openSourceView' :width='viewWidth' :height='viewHeight'></SourceOpen>
|
||||
|
||||
<ChildrenPlan :refresh-table='refreshTable' ref='childrenPlanView' :width='viewWidth' :height='viewHeight'></ChildrenPlan>
|
||||
|
||||
</template>
|
||||
|
||||
<script setup lang='tsx' name='useProTable'>
|
||||
import ProTable from '@/components/ProTable/index.vue'
|
||||
import type { ProTableInstance, ColumnProps } from '@/components/ProTable/interface'
|
||||
import type { ProTableInstance, ColumnProps, RenderScope } from '@/components/ProTable/interface'
|
||||
import { ScaleToOriginal, CirclePlus, Delete, EditPen, View, Upload, Download, List, Tools } from '@element-plus/icons-vue'
|
||||
import {getPlanList,deletePlan,exportPlan,downloadTemplate,importPlan } from '@/api/plan/plan.ts'
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import type { Plan } from '@/api/plan/interface'
|
||||
import PlanPopup from '@/views/plan/planList/components/planPopup.vue' // 导入子组件
|
||||
import DeviceOpen from '@/views/plan/planList/components/devPopup.vue'
|
||||
import SourceOpen from '@/views/plan/planList/components/chidrenPlan.vue'
|
||||
import DevTransfer from './components/devTransfer.vue'
|
||||
import ChildrenPlan from '@/views/plan/planList/components/childrenPlan.vue'
|
||||
import { useViewSize } from '@/hooks/useViewSize'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useDictStore } from '@/stores/modules/dict'
|
||||
@@ -72,41 +87,135 @@ import {useDownload} from "@/hooks/useDownload";
|
||||
import {getTestConfig } from '@/api/system/base/index'
|
||||
import {type Base } from '@/api/system/base/interface'
|
||||
import { getBoundPqDevList ,staticsAnalyse} from '@/api/plan/plan.ts'
|
||||
import { kMaxLength } from 'buffer'
|
||||
|
||||
// defineOptions({
|
||||
// name: 'planList'
|
||||
// })
|
||||
const dictStore = useDictStore()
|
||||
const openDeviceView = ref()
|
||||
const openSourceView = ref()
|
||||
const devTransferVisible = ref(false)
|
||||
const sourceTransferVisible = ref(false)
|
||||
const childrenPlanView = ref()
|
||||
// ProTable 实例
|
||||
const proTable = ref<ProTableInstance>()
|
||||
const errorStandardPopup = ref()
|
||||
const testSourcePopup = ref()
|
||||
const planPopup = ref()
|
||||
const devTransferPopup = ref()
|
||||
|
||||
const modeStore = useModeStore();
|
||||
|
||||
const tableData = ref<any[]>([])
|
||||
const planImportExcel = ref<InstanceType<typeof ImportExcel> | null>(null)
|
||||
const planList = ref<Plan.ResPlan[]>([]);
|
||||
const getTableList = async(params: any) => {
|
||||
let newParams = JSON.parse(JSON.stringify(params))
|
||||
const patternId = dictStore.getDictData('Pattern').find(item=>item.name=== modeStore.currentMode)?.id//获取数据字典中对应的id
|
||||
newParams.patternId = patternId
|
||||
|
||||
const { popupBaseView, viewWidth, viewHeight } = useViewSize()
|
||||
const pageTotal = ref(0)
|
||||
const currentPage = ref(1)
|
||||
const pageSize = ref(10)
|
||||
const currentPageData = ref<any[]>([])//当前页的数据
|
||||
const patternId = ref('')
|
||||
onMounted(async () => {
|
||||
refreshTable()
|
||||
|
||||
})
|
||||
//假分页后用data刷新
|
||||
const refreshTable = async () => {
|
||||
try {
|
||||
const result = await getPlanList(newParams);
|
||||
planList.value = result.data as Plan.ResPlan[];
|
||||
return result;
|
||||
console.log("表格刷新")
|
||||
patternId.value = dictStore.getDictData('Pattern').find(item => item.name === modeStore.currentMode)?.id;
|
||||
const result = await getPlanList({'patternId' : patternId.value});
|
||||
tableData.value = buildTree(result.data as any[]);
|
||||
pageTotal.value = tableData.value.length;
|
||||
updateCurrentPageData(tableData.value)
|
||||
console.log("表格刷新成功")
|
||||
} catch (error) {
|
||||
return { data: [] }; // 返回空数据或处理错误
|
||||
tableData.value = [];
|
||||
ElMessage.error('获取计划列表失败');
|
||||
}
|
||||
}
|
||||
|
||||
const { popupBaseView, viewWidth, viewHeight } = useViewSize()
|
||||
// 监听 tableData 变化
|
||||
watch(() => tableData.value, (newVal) => {
|
||||
if (childrenPlanView.value && newVal) {
|
||||
console.log('监听 tableData 变化', newVal)
|
||||
childrenPlanView.value.handleTableDataUpdate?.(newVal)
|
||||
updateCurrentPageData(newVal)
|
||||
}
|
||||
}, { deep: true, immediate: true })
|
||||
|
||||
//模糊查询计划列表
|
||||
const getTableList = async(params: any) => {
|
||||
let newParams = JSON.parse(JSON.stringify(params))
|
||||
// 从 newParams 中提取筛选条件
|
||||
const name = newParams.name
|
||||
const reportState = newParams.reportState
|
||||
const result = newParams.result
|
||||
const testState = newParams.testState
|
||||
|
||||
// 对 tableData.value 进行筛选
|
||||
const filteredData = tableData.value.filter(item => {
|
||||
let match = true
|
||||
|
||||
if (name) {
|
||||
match = item.name?.includes(name)
|
||||
}
|
||||
|
||||
if (reportState !== undefined && reportState !== null && reportState !== '') {
|
||||
match = item.reportState == (reportState)
|
||||
}
|
||||
|
||||
if (result !== undefined && result !== null && result !== '') {
|
||||
match = item.result == (result)
|
||||
}
|
||||
|
||||
if (testState !== undefined && testState !== null && testState !== '') {
|
||||
match = item.testState == (testState)
|
||||
}
|
||||
|
||||
return match
|
||||
})
|
||||
|
||||
|
||||
// 更新分页总数
|
||||
pageTotal.value = filteredData.length
|
||||
|
||||
// 更新当前页数据
|
||||
currentPage.value = 1
|
||||
updateCurrentPageData(filteredData)
|
||||
}
|
||||
|
||||
function buildTree(flatList: any[]): any[] {
|
||||
const map = new Map();
|
||||
const tree: any[] = [];
|
||||
|
||||
// First, create a map of all items by id for fast lookup
|
||||
flatList.forEach(item => {
|
||||
map.set(item.id, { ...item, children: [] });
|
||||
});
|
||||
|
||||
// Then, assign each item to its parent's children array
|
||||
flatList.forEach(item => {
|
||||
if (item.fatherPlanId && map.has(item.fatherPlanId)) {
|
||||
map.get(item.fatherPlanId).children.push(map.get(item.id));
|
||||
} else if (item.fatherPlanId === '0') {
|
||||
// Items with fatherPlanId '0' are root nodes
|
||||
tree.push(map.get(item.id));
|
||||
}
|
||||
});
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
const handleSizeChange = (size: number) => {
|
||||
pageSize.value = size
|
||||
updateCurrentPageData()
|
||||
}
|
||||
|
||||
const handleCurrentChange = (page: number) => {
|
||||
currentPage.value = page
|
||||
updateCurrentPageData()
|
||||
}
|
||||
|
||||
const updateCurrentPageData = (data = tableData.value) => {
|
||||
const start = (currentPage.value - 1) * pageSize.value
|
||||
const end = start + pageSize.value
|
||||
currentPageData.value = data.slice(start, end)
|
||||
console.log('currentPageData', currentPageData.value)
|
||||
}
|
||||
|
||||
const dataSourceType = computed(() => {
|
||||
// switch (modeStore.currentMode) {
|
||||
@@ -120,21 +229,20 @@ const dataSourceType = computed(() => {
|
||||
return 'Datasource'
|
||||
})
|
||||
|
||||
|
||||
// 表格配置项
|
||||
const columns = reactive<ColumnProps<Plan.ReqPlan>[]>([
|
||||
{ type: 'selection', fixed: 'left', minWidth: 70 },
|
||||
{ type: 'index', fixed: 'left', minWidth: 70, label: '序号' },
|
||||
{ type: 'index', fixed: 'left', minWidth: 70, label: '序号'},
|
||||
{
|
||||
prop: 'name',
|
||||
label: '名称',
|
||||
minWidth: 220,
|
||||
minWidth: 200,
|
||||
search: { el: 'input' },
|
||||
},
|
||||
{
|
||||
prop: 'testState',
|
||||
label: '检测状态',
|
||||
minWidth: 120,
|
||||
minWidth: 100,
|
||||
enum:dictTestState,
|
||||
search: { el:'select',props: { filterable: true }},
|
||||
fieldNames: { label: 'label', value: 'id' },
|
||||
@@ -149,14 +257,13 @@ const columns = reactive<ColumnProps<Plan.ReqPlan>[]>([
|
||||
{
|
||||
prop: 'progress',
|
||||
label: '检测进度',
|
||||
minWidth: 180,
|
||||
minWidth: 150,
|
||||
render: (scope) => {
|
||||
const randomPercentage = Math.floor(Math.random() * 101); // 生成 0 到 100 的随机整数
|
||||
return (
|
||||
<el-progress
|
||||
text-inside={true}
|
||||
stroke-width={20}
|
||||
percentage={randomPercentage}
|
||||
percentage={(scope.row.progress ?? 0) * 100}
|
||||
status='success'
|
||||
/>
|
||||
);
|
||||
@@ -178,12 +285,11 @@ const columns = reactive<ColumnProps<Plan.ReqPlan>[]>([
|
||||
{
|
||||
prop: 'result',
|
||||
label: '检测结果',
|
||||
minWidth: 120,
|
||||
minWidth: 100,
|
||||
enum:dictResult,
|
||||
search: { el: 'select', props: { filterable: true } },
|
||||
fieldNames: { label: 'label', value: 'id' },
|
||||
render: scope => {
|
||||
console.log('检测结果',scope.row.result)
|
||||
return (
|
||||
scope.row.result === 0 ? '不符合' : scope.row.result === 1 ? '符合' : '/'
|
||||
)
|
||||
@@ -192,7 +298,7 @@ const columns = reactive<ColumnProps<Plan.ReqPlan>[]>([
|
||||
{
|
||||
prop: 'createTime',
|
||||
label: '创建时间',
|
||||
minWidth: 200,
|
||||
minWidth: 180,
|
||||
render: scope => {
|
||||
if (scope.row.createTime) {
|
||||
const date = new Date(scope.row.createTime);
|
||||
@@ -210,7 +316,8 @@ const columns = reactive<ColumnProps<Plan.ReqPlan>[]>([
|
||||
{
|
||||
prop: 'sourceName',
|
||||
label: '检测源',
|
||||
minWidth: 400,
|
||||
minWidth: 300,
|
||||
isShow: modeStore.currentMode != "比对式",
|
||||
render: scope => {
|
||||
const sourceNames = Array.isArray(scope.row.sourceName) ? scope.row.sourceName : [];
|
||||
const sourceIds = Array.isArray(scope.row.sourceIds) ? scope.row.sourceIds : [];
|
||||
@@ -238,17 +345,30 @@ const columns = reactive<ColumnProps<Plan.ReqPlan>[]>([
|
||||
{
|
||||
prop: 'scriptId',
|
||||
label: '检测脚本',
|
||||
minWidth: 360,
|
||||
minWidth: 300,
|
||||
isShow: modeStore.currentMode != "比对式",
|
||||
render: scope => {
|
||||
return (
|
||||
<span>{scope.row.scriptName}</span>
|
||||
)
|
||||
},
|
||||
},
|
||||
{
|
||||
prop: 'standardDevNameStr',
|
||||
label: '标准设备',
|
||||
minWidth: 250,
|
||||
isShow: modeStore.currentMode == "比对式",
|
||||
|
||||
},
|
||||
{
|
||||
prop: 'testItemNameStr',
|
||||
label: '测试项',
|
||||
minWidth: 300,
|
||||
isShow: modeStore.currentMode == "比对式",
|
||||
},
|
||||
{
|
||||
prop: 'errorSysId',
|
||||
label: '误差体系',
|
||||
minWidth: 240,
|
||||
label: '误差体系', minWidth:300,
|
||||
render: scope => {
|
||||
return (
|
||||
<el-link type='primary' link onClick={() => showData(scope.row)}>
|
||||
@@ -257,12 +377,18 @@ const columns = reactive<ColumnProps<Plan.ReqPlan>[]>([
|
||||
)
|
||||
},
|
||||
},
|
||||
{
|
||||
prop: 'origin',//null 表示主计划 1表示子计划
|
||||
label: '来源',
|
||||
minWidth:200,
|
||||
isShow: modeStore.currentMode == "比对式",
|
||||
},
|
||||
{
|
||||
prop: 'datasourceIds',
|
||||
label: '数据源',
|
||||
enum: dictStore.getDictData(dataSourceType.value),
|
||||
fieldNames: { label: 'name', value: 'value' },
|
||||
minWidth: 250,
|
||||
minWidth: 230,
|
||||
render: (scope) => {
|
||||
const codes = scope.row.datasourceIds // 获取当前行的 datasourceIds 字段
|
||||
if (!codes) {
|
||||
@@ -295,7 +421,7 @@ const columns = reactive<ColumnProps<Plan.ReqPlan>[]>([
|
||||
minWidth: 120,
|
||||
},
|
||||
|
||||
{ prop: 'operation', label: '操作', fixed: 'right', minWidth: 300 },
|
||||
{ prop: 'operation', label: '操作', fixed: 'right', minWidth: 250 },
|
||||
])
|
||||
|
||||
|
||||
@@ -332,44 +458,6 @@ async function showTestSource(row:string) {
|
||||
|
||||
}
|
||||
|
||||
function showTestScript(row: string) {
|
||||
|
||||
}
|
||||
|
||||
function handleFiles(event: Event) {
|
||||
const target = event.target as HTMLInputElement
|
||||
const files = target.files
|
||||
if (files && files.length > 0) {
|
||||
// 处理文件
|
||||
// console.log(files)
|
||||
ElMessageBox.confirm(
|
||||
'导入的数据与当前数据有冲突,请选择以哪个数据为主进行覆盖',
|
||||
'数据冲突',
|
||||
{
|
||||
distinguishCancelAndClose: true,
|
||||
confirmButtonText: '以导入数据为主覆盖',
|
||||
cancelButtonText: '以当前数据为主覆盖',
|
||||
type: 'warning',
|
||||
},
|
||||
)
|
||||
.then(() => {
|
||||
ElMessage({
|
||||
type: 'info',
|
||||
message: '以导入数据为主完成数据覆盖',
|
||||
})
|
||||
})
|
||||
.catch((action: Action) => {
|
||||
ElMessage({
|
||||
type: 'info',
|
||||
message:
|
||||
action === 'cancel'
|
||||
? '以当前数据为主完成数据覆盖'
|
||||
: '取消本次导入操作',
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 点击导入按钮
|
||||
const importClick = () => {
|
||||
const params = {
|
||||
@@ -378,7 +466,7 @@ const importClick = () => {
|
||||
patternId: dictStore.getDictData('Pattern').find(item=>item.name=== modeStore.currentMode)?.id ?? '',
|
||||
tempApi: downloadTemplate,
|
||||
importApi: importPlan,
|
||||
getTableList: proTable.value?.getTableList,
|
||||
getTableList: refreshTable(),
|
||||
}
|
||||
planImportExcel.value?.acceptParams(params)
|
||||
}
|
||||
@@ -391,51 +479,30 @@ const exportClick = () => {
|
||||
})
|
||||
}
|
||||
|
||||
// 点击合并按钮
|
||||
const combineClick = () => {
|
||||
ElMessageBox.prompt(
|
||||
'请输入合并后的计划名称',
|
||||
'检测计划合并',
|
||||
{
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
},
|
||||
)
|
||||
.then(({ value }) => {
|
||||
// console.log(`合并后的计划名为:`, value)
|
||||
proTable.value?.clearSelection()
|
||||
proTable.value?.getTableList()
|
||||
})
|
||||
}
|
||||
|
||||
// 打开 drawer(新增、编辑)
|
||||
const openDialog = (titleType: string, row: Partial<Plan.ReqPlan> = {}) => {
|
||||
planPopup.value?.open(titleType, row,modeStore.currentMode)
|
||||
planPopup.value?.open(titleType, row,modeStore.currentMode,0)//0主计划 1子计划 2修改子计划
|
||||
}
|
||||
|
||||
|
||||
// 批量删除设备
|
||||
const batchDelete = async (id: string[]) => {
|
||||
await useHandleData(deletePlan, id, '删除所选检测计划')
|
||||
await useHandleData(deletePlan, {'id':id, 'pattern':patternId.value},'删除所选检测计划')
|
||||
proTable.value?.clearSelection()
|
||||
proTable.value?.getTableList()
|
||||
await refreshTable()
|
||||
}
|
||||
|
||||
// 删除检测计划
|
||||
const handleDelete = async (params: Plan.ReqPlanParams) => {
|
||||
await useHandleData(deletePlan, [params.id], `删除【${params.name}】检测计划`)
|
||||
proTable.value?.getTableList()
|
||||
await useHandleData(deletePlan, {id: [params.id], 'pattern': patternId.value}, `删除【${params.name}】检测计划`)
|
||||
proTable.value?.clearSelection()
|
||||
await refreshTable()
|
||||
}
|
||||
|
||||
const openTestSource = (row: Partial<Plan.ReqPlan> = {}) => {
|
||||
openSourceView.value.open("检测计划详情",row.name)
|
||||
const openChildrenPlan = (row: Partial<Plan.ReqPlan> = {}) => {
|
||||
childrenPlanView.value.open("检测计划详情",row)
|
||||
}
|
||||
|
||||
const showDeviceOpen = (row: Partial<Plan.ReqPlan> = {}) => {
|
||||
devTransferPopup.value.open(row)
|
||||
}
|
||||
|
||||
const myDict = new Map<string, any[]>();
|
||||
|
||||
const statisticalAnalysisMore = async (ids: string[], rows: Plan.ReqPlan[]) => {
|
||||
const hasInvalidState = rows.some(row => row.testState != 2);
|
||||
@@ -452,39 +519,10 @@ const statisticalAnalysisMore = async (ids: string[], rows: Plan.ReqPlan[]) => {
|
||||
|
||||
const statisticalAnalysis = async (row: Partial<Plan.ReqPlan> = {}) => {
|
||||
useDownload(staticsAnalyse,'分析结果', [row.id], false,'.xlsx')
|
||||
|
||||
// const response = await getTestConfig() as unknown as Base.ResTestConfig
|
||||
// const maxTime= response.data.maxTime//检测最大次数
|
||||
// const dev = await getBoundPqDevList({ 'planId': row.id })
|
||||
// for (let i = 0; i <= maxTime; i++) {
|
||||
// dev.data.forEach((item: any) => {
|
||||
// if(item.reCheckNum === i){
|
||||
// // 向已有的数组中添加元素
|
||||
// if (myDict.has(i.toString())) {
|
||||
// myDict.get(i.toString())?.push(item.name);
|
||||
// }else{
|
||||
// myDict.set(i.toString(), [item.name]);
|
||||
// }
|
||||
// }
|
||||
|
||||
// })
|
||||
// }
|
||||
|
||||
// for (let i = 0; i <= maxTime; i++) {
|
||||
// if (myDict.has(i.toString())) {
|
||||
// const array = myDict.get(i.toString());
|
||||
// if (array) {
|
||||
// for (const value of array) {
|
||||
// console.log(i + '---'+value);
|
||||
// }
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
Reference in New Issue
Block a user