diff --git a/src/utils/Array.ts b/src/utils/Array.ts new file mode 100644 index 0000000..74d9300 --- /dev/null +++ b/src/utils/Array.ts @@ -0,0 +1,43 @@ +// 常见数组操作 + +// 两个数组求交集 +export const intersectionArray = (list1: any[], list2: any[]) => { + return list1.filter(v => list2.includes(v)) +} +// 差集 -- 常用于 表格中多选删除 +export const differenceArray = (list1: any[], list2: any[]) => { + return list1.filter(v => !list2.includes(v)) +} +// 补集 +export const complementaryArray = (list1: any[], list2: any[]) => { + return list1.filter((v) => { return !(list2.includes(v)) }) + .concat(list2.filter((v) => { return !(list1.includes(v)) })) +} +// 并集 +export const unionArray = (list1: any[], list2: any[]) => { + return list1.concat(list2.filter((v) => { return !(list1.includes(v)) })) +} +// 一维数组去重 +export const uniqueArray = (list: any) => { + return [...new Set(list)] +} +// 二维数组根据 某一属性 去重 +export const uniqueMultiArray = (list: any, attribute: string) => { + const data = list.value.map((item: any) => item[attribute]) + return list.filter((item: any) => !data.includes(item[attribute])) +} +// 一维数组或对象拷贝 +export const cloneArray = (data: any) => { + return JSON.parse(JSON.stringify(data)) +} +// 数组操作-下拉框操作(已经选择的数据不能再选) +/** + * @param list 下拉框初始数据(所有) + * @param list1 已经选择的数据 + * @param current 当前数据 可为空 + * @param attribute 属性(即绑定在 list1哪个属性上) + */ +export const setSelectList = (list: any[], list1: any[], current: string, attribute: string) => { + const select = [...new Set(list1.map((item: any) => item[attribute]))].filter((item: string) => item !== current) + return list.filter((item) => { return !select.includes(item.value) }) +} diff --git a/src/utils/Array.ts b/src/utils/Array.ts new file mode 100644 index 0000000..74d9300 --- /dev/null +++ b/src/utils/Array.ts @@ -0,0 +1,43 @@ +// 常见数组操作 + +// 两个数组求交集 +export const intersectionArray = (list1: any[], list2: any[]) => { + return list1.filter(v => list2.includes(v)) +} +// 差集 -- 常用于 表格中多选删除 +export const differenceArray = (list1: any[], list2: any[]) => { + return list1.filter(v => !list2.includes(v)) +} +// 补集 +export const complementaryArray = (list1: any[], list2: any[]) => { + return list1.filter((v) => { return !(list2.includes(v)) }) + .concat(list2.filter((v) => { return !(list1.includes(v)) })) +} +// 并集 +export const unionArray = (list1: any[], list2: any[]) => { + return list1.concat(list2.filter((v) => { return !(list1.includes(v)) })) +} +// 一维数组去重 +export const uniqueArray = (list: any) => { + return [...new Set(list)] +} +// 二维数组根据 某一属性 去重 +export const uniqueMultiArray = (list: any, attribute: string) => { + const data = list.value.map((item: any) => item[attribute]) + return list.filter((item: any) => !data.includes(item[attribute])) +} +// 一维数组或对象拷贝 +export const cloneArray = (data: any) => { + return JSON.parse(JSON.stringify(data)) +} +// 数组操作-下拉框操作(已经选择的数据不能再选) +/** + * @param list 下拉框初始数据(所有) + * @param list1 已经选择的数据 + * @param current 当前数据 可为空 + * @param attribute 属性(即绑定在 list1哪个属性上) + */ +export const setSelectList = (list: any[], list1: any[], current: string, attribute: string) => { + const select = [...new Set(list1.map((item: any) => item[attribute]))].filter((item: string) => item !== current) + return list.filter((item) => { return !select.includes(item.value) }) +} diff --git a/src/views/business/measure/item/components/second/templateDetail.vue b/src/views/business/measure/item/components/second/templateDetail.vue index bc3656a..1dd1254 100644 --- a/src/views/business/measure/item/components/second/templateDetail.vue +++ b/src/views/business/measure/item/components/second/templateDetail.vue @@ -9,6 +9,7 @@ import { useCheckList } from '@/commonMethods/useCheckList' import { calculate, recalculate } from '@/api/business/measure/caculate' import type { TableColumn } from '@/components/NormalTable/table_interface' +import { differenceArray, setSelectList } from '@/utils/Array' const props = defineProps({ pageType: { type: String, @@ -50,10 +51,6 @@ }) watch(() => props.form, (newVal) => { form.value = newVal - // form.value.voltageRepresentationValueErrorType = '1' - // form.value.ammeterDirectType = '1' - // form.value.ammeterIndirectType = '1' - // form.value.technicalIndexSymbol = '≤' }) const pageEditFlag = ref(false) const tableLoading = ref(false) @@ -66,8 +63,10 @@ const rippleVoltageList = ref([]) // 纹波电压 const outputVoltageStabilityList = ref([]) // 输出电压短期稳定性 // 表格数据对应 list 字典 -const listDict = ref<{ [key: string]: any }>( - { +const listDict = ref<{ [key: string]: any }>() +// 监听所有表格数据 +watch(() => [lineVoltageRegulationList.value, loadRegulationList.value, voltageRepresentationValueErrorList.value, ammeterDirectList.value, ammeterIndirectList.value, rippleVoltageList.value, outputVoltageStabilityList.value], () => { + listDict.value = { '1-电源电压调整率': lineVoltageRegulationList.value, // 1 '2-负载调整率': loadRegulationList.value, // 2 '3-电压表示值误差': voltageRepresentationValueErrorList.value, // 3 @@ -75,19 +74,14 @@ '5-电流表示值误差(间接测量)': ammeterIndirectList.value, // 5 '6-纹波电压': rippleVoltageList.value, // 6 '7-输出电压短期稳定性': outputVoltageStabilityList.value, // 7 - }, -) -watch(() => listDict.value, (newVal) => { - if (newVal) { - list.value = [] - for (const i in newVal) { - list.value = [...list.value, ...newVal[i]] - } + } + list.value = [] + for (const i in listDict.value) { + list.value = [...list.value, ...listDict.value[i]] } }, { deep: true, }) -// const mainPage = useMainPage() // 清空所有数据 function clearAllList() { list.value = [] @@ -101,11 +95,11 @@ for (const i in listDict.value) { listDict.value[i] = [] } - // mainPage.reload() } // 页面 pageType 发生变化清空所有数据 watch(() => props.pageType, () => { clearAllList() + setLoadSituation('', []) }) const lineVoltageRegulationCheckoutList = ref([]) // 电源电压调整率多选 const loadRegulationCheckoutList = ref([]) // 负载调整率多选 @@ -133,7 +127,7 @@ const columns_voltage_representation_value_error_number = ref([ { text: '检定项目', value: 'params', align: 'center', required: true, type: 'text' }, { text: '输出通道', value: 'outputChannel', align: 'center', required: true, type: 'select' }, - { text: '单位', value: 'unit', align: 'center', required: true, type: 'select' }, + { text: '测量单位', value: 'unit', align: 'center', required: true, type: 'select' }, { text: '被检表示值', value: 'measureIndicationValue', align: 'center', required: true, type: 'input' }, { text: '误差参数a', value: 'errorParamA', align: 'center', required: true, type: 'input' }, { text: '误差参数b', value: 'errorParamB', align: 'center', required: true, type: 'input' }, @@ -148,7 +142,7 @@ const columns_voltage_representation_value_error_pointer = ref([ { text: '检定项目', value: 'params', align: 'center', required: true, type: 'text' }, { text: '输出通道', value: 'outputChannel', align: 'center', required: true, type: 'select' }, - { text: '单位', value: 'unit', align: 'center', required: true, type: 'select' }, + { text: '测量单位', value: 'unit', align: 'center', required: true, type: 'select' }, { text: '被检表示值', value: 'measureIndicationValue', align: 'center', required: true, type: 'input' }, { text: '准确度a', value: 'accuracyA', align: 'center', required: true, type: 'input' }, { text: '指针式仪表满量程值', value: 'fullScaleValue', align: 'center', required: true, type: 'input' }, @@ -234,17 +228,8 @@ '7-输出电压短期稳定性': columns_output_voltage_stability.value, // 7 }, ) - -// 表格对应的 cheked -let chekedDict = { - // '1-电源电压调整率': form.value.voltageRegulation, // 1 - // '2-负载调整率': form.value.loadRegulation, // 2 - // '3-电压表示值误差': form.value.voltageRepresentError, // 3 - // '4-电流表示值误差(直接测量)': form.value.currentRepresentErrorDirect, // 4 - // '5-电流表示值误差(间接测量)': form.value.currentRepresentErrorIndirect, // 5 - // '6-纹波电压': form.value.rippleVoltage, // 6 - // '7-输出电压短期稳定性': form.value.voltageOutputStability, -} as { [key: string]: any } +// 表格对应的 选择状态 +let chekedDict = {} as { [key: string]: any } watch(() => form.value, () => { chekedDict = { '1-电源电压调整率': form.value.voltageRegulation, // 1 @@ -265,9 +250,10 @@ */ const addRow = (list: IList[], title: string, index: string) => { if (checkList(list, columnsDict.value[`${index}-${title}`], `${title}表格`)) { + let data = {} switch (title) { case '电源电压调整率': // 电源电压调整率 - lineVoltageRegulationList.value.push({ + data = { params: '电源电压调整率', dataType: '1', technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号 @@ -276,14 +262,16 @@ unit: '', // 单位 voltageRegulatorOutputValue: '', // 调压器输出值 editable: true, - }) + } + console.log(data, 'data') + lineVoltageRegulationList.value.push(data) break case '负载调整率': // 负载调整率 if (loadRegulationList.value.length === 8) { ElMessage.warning('最多添加四项') return } - loadRegulationList.value.push({ + data = { params: '负载调整率', dataType: '2', technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号 @@ -291,135 +279,112 @@ outputChannel: '', // 输出通道 unit: '', // 单位 editable: true, - loadSituation: '1', // 负载情况 1 空载 2 满载 - }, - { - params: '负载调整率', - dataType: '2', - technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号 - technicalIndex: '', // 技术指标 - outputChannel: '', // 输出通道 - unit: '', // 单位 - editable: true, - loadSituation: '2', // 负载情况 1 空载 2 满载 - }) + } + for (let i = 1; i < 3; i++) { + loadRegulationList.value.push({ ...data, loadSituation: i.toString() }) + } break case '电压表示值误差': // 电压表示值误差 - // voltageRepresentationValueErrorList 1数字式、2指针式 + // 1数字式、2指针式 + data = { + params: '电压表示值误差', + dataType: '3', + outputChannel: '', // 输出通道 + technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号 + unit: '', // 单位 + measureIndicationValue: '', // 被检表示值 + resolution: '0.0001', // 分辨力 + editable: true, + maximumError: '', // 最大允许误差 + } if (form.value.ammeterDirectType === '1') { // 数字式 voltageRepresentationValueErrorList.value.push({ - params: '电压表示值误差', - dataType: '3', + ...data, dataTypeType: '1', - outputChannel: '', // 输出通道 - technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号 - unit: '', // 单位 - measureIndicationValue: '', // 被检表示值 errorParamA: '', // 误差参数a errorParamB: '', // 误差参数b - maximumError: '', // 最大允许误差 - resolution: '0.0001', // 分辨力 - editable: true, }) } else { // 指针式 voltageRepresentationValueErrorList.value.push({ - params: '电压表示值误差', - dataType: '3', + ...data, dataTypeType: '2', - outputChannel: '', // 输出通道 - technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号 - unit: '', // 单位 - measureIndicationValue: '', // 被检表示值 accuracyA: '', // 准确度a fullScaleValue: '', // 指针式仪表满量程值 - maximumError: '1', // 最大允许误差 - resolution: '0.0001', // 分辨力 - editable: true, }) } break case '电流表示值误差(直接测量)': // 电流表示值误差(直接测量) + data = { + params: '电流表示值误差(直接测量)', + dataType: '4', + outputChannel: '', // 输出通道 + technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号 + unit: '', // 单位 + measureIndicationValue: '', // 被检表示值 + maximumError: '1', // 最大允许误差 + resolution: '0.0001', // 分辨力 + editable: true, + } // 1数字式、2指针式 if (form.value.ammeterDirectType === '1') { // 数字式 ammeterDirectList.value.push({ - params: '电流表示值误差(直接测量)', - dataType: '4', + ...data, dataTypeType: '1', - outputChannel: '', // 输出通道 - technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号 - unit: '', // 单位 - measureIndicationValue: '', // 被检表示值 errorParamA: '', // 误差参数a errorParamB: '', // 误差参数b - maximumError: '', // 最大允许误差 - resolution: '0.0001', // 分辨力 - editable: true, }) } else { // 指针式 ammeterDirectList.value.push({ - params: '电流表示值误差(直接测量)', - dataType: '4', + ...data, dataTypeType: '2', - outputChannel: '', // 输出通道 - technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号 - unit: '', // 单位 - measureIndicationValue: '', // 被检表示值 accuracyA: '', // 准确度a fullScaleValue: '', // 指针式仪表满量程值 - maximumError: '1', // 最大允许误差 - resolution: '0.0001', // 分辨力 - editable: true, }) } break case '电流表示值误差(间接测量)': // 电流表示值误差(间接测量) + data = { + params: '电流表示值误差(间接测量)', + dataType: '5', + outputChannel: '', // 输出通道 + technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号 + standardResistanceValue: '', // 标准电阻值 + standardResistanceValueUnit: '', // 标准电阻值单位 + editable: true, + unit: '', // 单位 + measureIndicationValue: '', // 被检表示值 + maximumError: '', // 最大允许误差 + } // 1数字式、2指针式 if (form.value.ammeterIndirectType === '1') { // 数字式 ammeterIndirectList.value.push({ - params: '电流表示值误差(间接测量)', - dataType: '5', + ...data, dataTypeType: '1', - outputChannel: '', // 输出通道 - technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号 - unit: '', // 单位 - measureIndicationValue: '', // 被检表示值 errorParamA: '', // 误差参数a errorParamB: '', // 误差参数b maximumError: '', // 最大允许误差 resolution: '0.0001', // 分辨力 - standardResistanceValue: '', // 标准电阻值 - standardResistanceValueUnit: '', // 标准电阻值单位 - editable: true, }) } else { // 指针式 ammeterIndirectList.value.push({ - params: '电流表示值误差(间接测量)', - dataType: '5', + ...data, dataTypeType: '2', - outputChannel: '', // 输出通道 - technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号 - unit: '', // 单位 - measureIndicationValue: '', // 被检表示值 - accuracyA: '', // 准确度a **目前缺少该参数 - fullScaleValue: '', // 指针式仪表满量程值 **目前缺少该参数 - maximumError: '1', // 最大允许误差 - standardResistanceValue: '', // 标准电阻值 - standardResistanceValueUnit: '', // 标准电阻值单位 - editable: true, + accuracyA: '', // 准确度a + fullScaleValue: '', // 指针式仪表满量程值 }) } break case '纹波电压': // 纹波电压 - rippleVoltageList.value.push({ + data = { params: '纹波电压', dataType: '6', technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号 @@ -427,10 +392,11 @@ outputChannel: '', // 输出通道 unit: '', // 单位 editable: true, - }) + } + rippleVoltageList.value.push(data) break case '输出电压短期稳定性': // 输出电压短期稳定性 - outputVoltageStabilityList.value.push({ + data = { params: '输出电压短期稳定性', dataType: '7', technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号 @@ -438,7 +404,8 @@ outputChannel: '', // 输出通道 unit: '', // 单位 editable: true, - }) + } + outputVoltageStabilityList.value.push(data) break } } @@ -454,40 +421,31 @@ } else { let data = [] as any[] - data = list.filter((item: any) => { - return !checkoutList.includes(item) - }) + data = differenceArray(list, checkoutList) switch (title) { case '电源电压调整率': // 电源电压调整率 lineVoltageRegulationList.value = data - listDict.value['1-电源电压调整率'] = lineVoltageRegulationList.value break case '负载调整率': // 负载调整率 loadRegulationList.value = loadRegulationList.value.filter((item: any) => { const needDelte = [...new Set(checkoutList.map(item => item.outputChannel))] return !needDelte.includes(item.outputChannel) }) - listDict.value['2-负载调整率'] = loadRegulationList.value break case '电压表示值误差': // 电压表示值误差 voltageRepresentationValueErrorList.value = data - listDict.value['3-电压表示值误差'] = voltageRepresentationValueErrorList.value break case '电流表示值误差(直接测量)': // 电流表示值误差(直接测量) ammeterDirectList.value = data - listDict.value['4-电流表示值误差(直接测量)'] = ammeterDirectList.value break case '电流表示值误差(间接测量)': // 电流表示值误差(间接测量) ammeterIndirectList.value = data - listDict.value['5-电流表示值误差(间接测量)'] = ammeterIndirectList.value break case '纹波电压': // 纹波电压 rippleVoltageList.value = data - listDict.value['6-纹波电压'] = rippleVoltageList.value break case '输出电压短期稳定性': // 输出电压短期稳定性 outputVoltageStabilityList.value = data - listDict.value['7-输出电压短期稳定性'] = outputVoltageStabilityList.value break } } @@ -508,21 +466,8 @@ break } } - // return reultArr.map((item: boolean) => item) return result } -// ------------------------------------------------------------------------------------------------ -const calculateResult = (title: string) => { - -} -// 点击计算结果--上方表格计算 -const calculateDataTop = () => { - -} -// 点击生成辅助接地电阻--下面表格计算 -const calculateDataBottom = () => { - -} // ----------------------------------------------------------------------------------------------------- // 设置默认值 const setType = (list: Ilist[]) => { @@ -569,37 +514,30 @@ case '1': // 电源电压调整率 lineVoltageRegulationList.value.push({ ...item, params: '电源电压调整率' }) - listDict.value['1-电源电压调整率'].push({ ...item, params: '电源电压调整率' }) break case '2': // 负载调整率 loadRegulationList.value.push({ ...item, params: '负载调整率' }) - listDict.value['2-负载调整率'].push({ ...item, params: '负载调整率' }) break case '3': // 电压表示值误差 voltageRepresentationValueErrorList.value.push({ ...item, params: '电压表示值误差' }) - listDict.value['3-电压表示值误差'].push({ ...item, params: '电压表示值误差' }) break case '4': // 电流表示值误差(直接测量) ammeterDirectList.value.push({ ...item, params: '电流表示值误差(直接测量)' }) - listDict.value['4-电流表示值误差(直接测量)'].push({ ...item, params: '电流表示值误差(直接测量)' }) break case '5': // 电流表示值误差(间接测量) ammeterIndirectList.value.push({ ...item, params: '电流表示值误差(间接测量)' }) - listDict.value['5-电流表示值误差(间接测量)'].push({ ...item, params: '电流表示值误差(间接测量)' }) break case '6': // 纹波电压 rippleVoltageList.value.push({ ...item, params: '纹波电压' }) - listDict.value['6-纹波电压'].push({ ...item, params: '纹波电压' }) break case '7': // 输出电压短期稳定性 outputVoltageStabilityList.value.push({ ...item, params: '输出电压短期稳定性' }) - listDict.value['7-输出电压短期稳定性'].push({ ...item, params: '输出电压短期稳定性' }) break } }) @@ -616,7 +554,6 @@ columnsDict.value['3-电压表示值误差'] = columns_voltage_representation.value if (!pageEditFlag.value) { return } voltageRepresentationValueErrorList.value = [] - listDict.value['3-电压表示值误差'] = voltageRepresentationValueErrorList.value }) watch(() => form.value.ammeterDirectType, (newValue) => { if (newValue === '2') { @@ -628,7 +565,6 @@ columnsDict.value['4-电流表示值误差(直接测量)'] = columns_ammeter_direct.value if (!pageEditFlag.value) { return } ammeterDirectList.value = [] - listDict.value['4-电流表示值误差(直接测量)'] = ammeterDirectList.value }) // 监听电流表示值误差(间接测量) watch(() => form.value.ammeterIndirectType, (newValue) => { @@ -641,7 +577,6 @@ columnsDict.value['5-电流表示值误差(间接测量)'] = columns_ammeter_indirect.value if (!pageEditFlag.value) { return } ammeterIndirectList.value = [] - listDict.value['5-电流表示值误差(间接测量)'] = ammeterIndirectList.value }) // 监听 输出通道 修改下拉框内容 @@ -659,6 +594,15 @@ // 2.限制下拉框内容 setLoadSituation(typeof value === 'string' ? value : list[index].outputChannel as string, list) } +// 表格下拉框等内容是否禁用 +const disabled = ({ scope, column }, fun) => { + // 禁用的话 调用fun函数并传递参数 + if (column.text === '负载情况') { + fun(true) + return + } + fun(props.pageType === 'detail') +} // ---------------------------------------------获取字典--------------------------------------------------- const TechnicalIndexSymbolList = ref<{ value: string;name: string;id: string }[]>([]) // 技术指标前符号 const OutputChannelList = ref<{ value: string;name: string;id: string }[]>([]) // 输出通道 @@ -692,10 +636,12 @@ const tableDict = ref<{ [key: string]: { value: string;name: string;id: string }[] }>({}) // 修改输出通道 function setLoadSituation(current: string, list: IList[]) { - // 1. 已经选择的输出通道 - const selectLoadSituation = [...new Set(list.map((item: any) => item.outputChannel))].filter((item: string) => item !== current) - // 2. 修改下拉框内容 - tableDict.value['输出通道'] = OutputChannelAllList.value.filter((item) => { return !selectLoadSituation.includes(item.value) }) + if (props.pageType === 'detail') { + tableDict.value['输出通道'] = OutputChannelAllList.value + } + else { + tableDict.value['输出通道'] = setSelectList(OutputChannelAllList.value, list, current, 'outputChannel') + } } const fecthDict = async () => { @@ -729,16 +675,10 @@ 负载情况: loadSituationList.value, 最大允许误差: standardMaximumError.value, 标准电阻值单位: standardResistance.value, + 测量单位: unitList1.value, } } fecthDict() -// 获取任意下拉框 -const getAnySelect = (text: string, title: string) => { - if (text === '单位' && title.includes('测量')) { - return unitList1.value - } - return tableDict.value[text] -} defineExpose({ list, checkAllList, form }) @@ -763,506 +703,211 @@ - -
+ + + + + + + + - -
+ + + + + + + - -
+ + + + + + + + - -
+ + + + - -
+ + + + - -
+ + + + + - -
+ + + + + + + diff --git a/src/utils/Array.ts b/src/utils/Array.ts new file mode 100644 index 0000000..74d9300 --- /dev/null +++ b/src/utils/Array.ts @@ -0,0 +1,43 @@ +// 常见数组操作 + +// 两个数组求交集 +export const intersectionArray = (list1: any[], list2: any[]) => { + return list1.filter(v => list2.includes(v)) +} +// 差集 -- 常用于 表格中多选删除 +export const differenceArray = (list1: any[], list2: any[]) => { + return list1.filter(v => !list2.includes(v)) +} +// 补集 +export const complementaryArray = (list1: any[], list2: any[]) => { + return list1.filter((v) => { return !(list2.includes(v)) }) + .concat(list2.filter((v) => { return !(list1.includes(v)) })) +} +// 并集 +export const unionArray = (list1: any[], list2: any[]) => { + return list1.concat(list2.filter((v) => { return !(list1.includes(v)) })) +} +// 一维数组去重 +export const uniqueArray = (list: any) => { + return [...new Set(list)] +} +// 二维数组根据 某一属性 去重 +export const uniqueMultiArray = (list: any, attribute: string) => { + const data = list.value.map((item: any) => item[attribute]) + return list.filter((item: any) => !data.includes(item[attribute])) +} +// 一维数组或对象拷贝 +export const cloneArray = (data: any) => { + return JSON.parse(JSON.stringify(data)) +} +// 数组操作-下拉框操作(已经选择的数据不能再选) +/** + * @param list 下拉框初始数据(所有) + * @param list1 已经选择的数据 + * @param current 当前数据 可为空 + * @param attribute 属性(即绑定在 list1哪个属性上) + */ +export const setSelectList = (list: any[], list1: any[], current: string, attribute: string) => { + const select = [...new Set(list1.map((item: any) => item[attribute]))].filter((item: string) => item !== current) + return list.filter((item) => { return !select.includes(item.value) }) +} diff --git a/src/views/business/measure/item/components/second/templateDetail.vue b/src/views/business/measure/item/components/second/templateDetail.vue index bc3656a..1dd1254 100644 --- a/src/views/business/measure/item/components/second/templateDetail.vue +++ b/src/views/business/measure/item/components/second/templateDetail.vue @@ -9,6 +9,7 @@ import { useCheckList } from '@/commonMethods/useCheckList' import { calculate, recalculate } from '@/api/business/measure/caculate' import type { TableColumn } from '@/components/NormalTable/table_interface' +import { differenceArray, setSelectList } from '@/utils/Array' const props = defineProps({ pageType: { type: String, @@ -50,10 +51,6 @@ }) watch(() => props.form, (newVal) => { form.value = newVal - // form.value.voltageRepresentationValueErrorType = '1' - // form.value.ammeterDirectType = '1' - // form.value.ammeterIndirectType = '1' - // form.value.technicalIndexSymbol = '≤' }) const pageEditFlag = ref(false) const tableLoading = ref(false) @@ -66,8 +63,10 @@ const rippleVoltageList = ref([]) // 纹波电压 const outputVoltageStabilityList = ref([]) // 输出电压短期稳定性 // 表格数据对应 list 字典 -const listDict = ref<{ [key: string]: any }>( - { +const listDict = ref<{ [key: string]: any }>() +// 监听所有表格数据 +watch(() => [lineVoltageRegulationList.value, loadRegulationList.value, voltageRepresentationValueErrorList.value, ammeterDirectList.value, ammeterIndirectList.value, rippleVoltageList.value, outputVoltageStabilityList.value], () => { + listDict.value = { '1-电源电压调整率': lineVoltageRegulationList.value, // 1 '2-负载调整率': loadRegulationList.value, // 2 '3-电压表示值误差': voltageRepresentationValueErrorList.value, // 3 @@ -75,19 +74,14 @@ '5-电流表示值误差(间接测量)': ammeterIndirectList.value, // 5 '6-纹波电压': rippleVoltageList.value, // 6 '7-输出电压短期稳定性': outputVoltageStabilityList.value, // 7 - }, -) -watch(() => listDict.value, (newVal) => { - if (newVal) { - list.value = [] - for (const i in newVal) { - list.value = [...list.value, ...newVal[i]] - } + } + list.value = [] + for (const i in listDict.value) { + list.value = [...list.value, ...listDict.value[i]] } }, { deep: true, }) -// const mainPage = useMainPage() // 清空所有数据 function clearAllList() { list.value = [] @@ -101,11 +95,11 @@ for (const i in listDict.value) { listDict.value[i] = [] } - // mainPage.reload() } // 页面 pageType 发生变化清空所有数据 watch(() => props.pageType, () => { clearAllList() + setLoadSituation('', []) }) const lineVoltageRegulationCheckoutList = ref([]) // 电源电压调整率多选 const loadRegulationCheckoutList = ref([]) // 负载调整率多选 @@ -133,7 +127,7 @@ const columns_voltage_representation_value_error_number = ref([ { text: '检定项目', value: 'params', align: 'center', required: true, type: 'text' }, { text: '输出通道', value: 'outputChannel', align: 'center', required: true, type: 'select' }, - { text: '单位', value: 'unit', align: 'center', required: true, type: 'select' }, + { text: '测量单位', value: 'unit', align: 'center', required: true, type: 'select' }, { text: '被检表示值', value: 'measureIndicationValue', align: 'center', required: true, type: 'input' }, { text: '误差参数a', value: 'errorParamA', align: 'center', required: true, type: 'input' }, { text: '误差参数b', value: 'errorParamB', align: 'center', required: true, type: 'input' }, @@ -148,7 +142,7 @@ const columns_voltage_representation_value_error_pointer = ref([ { text: '检定项目', value: 'params', align: 'center', required: true, type: 'text' }, { text: '输出通道', value: 'outputChannel', align: 'center', required: true, type: 'select' }, - { text: '单位', value: 'unit', align: 'center', required: true, type: 'select' }, + { text: '测量单位', value: 'unit', align: 'center', required: true, type: 'select' }, { text: '被检表示值', value: 'measureIndicationValue', align: 'center', required: true, type: 'input' }, { text: '准确度a', value: 'accuracyA', align: 'center', required: true, type: 'input' }, { text: '指针式仪表满量程值', value: 'fullScaleValue', align: 'center', required: true, type: 'input' }, @@ -234,17 +228,8 @@ '7-输出电压短期稳定性': columns_output_voltage_stability.value, // 7 }, ) - -// 表格对应的 cheked -let chekedDict = { - // '1-电源电压调整率': form.value.voltageRegulation, // 1 - // '2-负载调整率': form.value.loadRegulation, // 2 - // '3-电压表示值误差': form.value.voltageRepresentError, // 3 - // '4-电流表示值误差(直接测量)': form.value.currentRepresentErrorDirect, // 4 - // '5-电流表示值误差(间接测量)': form.value.currentRepresentErrorIndirect, // 5 - // '6-纹波电压': form.value.rippleVoltage, // 6 - // '7-输出电压短期稳定性': form.value.voltageOutputStability, -} as { [key: string]: any } +// 表格对应的 选择状态 +let chekedDict = {} as { [key: string]: any } watch(() => form.value, () => { chekedDict = { '1-电源电压调整率': form.value.voltageRegulation, // 1 @@ -265,9 +250,10 @@ */ const addRow = (list: IList[], title: string, index: string) => { if (checkList(list, columnsDict.value[`${index}-${title}`], `${title}表格`)) { + let data = {} switch (title) { case '电源电压调整率': // 电源电压调整率 - lineVoltageRegulationList.value.push({ + data = { params: '电源电压调整率', dataType: '1', technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号 @@ -276,14 +262,16 @@ unit: '', // 单位 voltageRegulatorOutputValue: '', // 调压器输出值 editable: true, - }) + } + console.log(data, 'data') + lineVoltageRegulationList.value.push(data) break case '负载调整率': // 负载调整率 if (loadRegulationList.value.length === 8) { ElMessage.warning('最多添加四项') return } - loadRegulationList.value.push({ + data = { params: '负载调整率', dataType: '2', technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号 @@ -291,135 +279,112 @@ outputChannel: '', // 输出通道 unit: '', // 单位 editable: true, - loadSituation: '1', // 负载情况 1 空载 2 满载 - }, - { - params: '负载调整率', - dataType: '2', - technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号 - technicalIndex: '', // 技术指标 - outputChannel: '', // 输出通道 - unit: '', // 单位 - editable: true, - loadSituation: '2', // 负载情况 1 空载 2 满载 - }) + } + for (let i = 1; i < 3; i++) { + loadRegulationList.value.push({ ...data, loadSituation: i.toString() }) + } break case '电压表示值误差': // 电压表示值误差 - // voltageRepresentationValueErrorList 1数字式、2指针式 + // 1数字式、2指针式 + data = { + params: '电压表示值误差', + dataType: '3', + outputChannel: '', // 输出通道 + technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号 + unit: '', // 单位 + measureIndicationValue: '', // 被检表示值 + resolution: '0.0001', // 分辨力 + editable: true, + maximumError: '', // 最大允许误差 + } if (form.value.ammeterDirectType === '1') { // 数字式 voltageRepresentationValueErrorList.value.push({ - params: '电压表示值误差', - dataType: '3', + ...data, dataTypeType: '1', - outputChannel: '', // 输出通道 - technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号 - unit: '', // 单位 - measureIndicationValue: '', // 被检表示值 errorParamA: '', // 误差参数a errorParamB: '', // 误差参数b - maximumError: '', // 最大允许误差 - resolution: '0.0001', // 分辨力 - editable: true, }) } else { // 指针式 voltageRepresentationValueErrorList.value.push({ - params: '电压表示值误差', - dataType: '3', + ...data, dataTypeType: '2', - outputChannel: '', // 输出通道 - technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号 - unit: '', // 单位 - measureIndicationValue: '', // 被检表示值 accuracyA: '', // 准确度a fullScaleValue: '', // 指针式仪表满量程值 - maximumError: '1', // 最大允许误差 - resolution: '0.0001', // 分辨力 - editable: true, }) } break case '电流表示值误差(直接测量)': // 电流表示值误差(直接测量) + data = { + params: '电流表示值误差(直接测量)', + dataType: '4', + outputChannel: '', // 输出通道 + technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号 + unit: '', // 单位 + measureIndicationValue: '', // 被检表示值 + maximumError: '1', // 最大允许误差 + resolution: '0.0001', // 分辨力 + editable: true, + } // 1数字式、2指针式 if (form.value.ammeterDirectType === '1') { // 数字式 ammeterDirectList.value.push({ - params: '电流表示值误差(直接测量)', - dataType: '4', + ...data, dataTypeType: '1', - outputChannel: '', // 输出通道 - technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号 - unit: '', // 单位 - measureIndicationValue: '', // 被检表示值 errorParamA: '', // 误差参数a errorParamB: '', // 误差参数b - maximumError: '', // 最大允许误差 - resolution: '0.0001', // 分辨力 - editable: true, }) } else { // 指针式 ammeterDirectList.value.push({ - params: '电流表示值误差(直接测量)', - dataType: '4', + ...data, dataTypeType: '2', - outputChannel: '', // 输出通道 - technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号 - unit: '', // 单位 - measureIndicationValue: '', // 被检表示值 accuracyA: '', // 准确度a fullScaleValue: '', // 指针式仪表满量程值 - maximumError: '1', // 最大允许误差 - resolution: '0.0001', // 分辨力 - editable: true, }) } break case '电流表示值误差(间接测量)': // 电流表示值误差(间接测量) + data = { + params: '电流表示值误差(间接测量)', + dataType: '5', + outputChannel: '', // 输出通道 + technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号 + standardResistanceValue: '', // 标准电阻值 + standardResistanceValueUnit: '', // 标准电阻值单位 + editable: true, + unit: '', // 单位 + measureIndicationValue: '', // 被检表示值 + maximumError: '', // 最大允许误差 + } // 1数字式、2指针式 if (form.value.ammeterIndirectType === '1') { // 数字式 ammeterIndirectList.value.push({ - params: '电流表示值误差(间接测量)', - dataType: '5', + ...data, dataTypeType: '1', - outputChannel: '', // 输出通道 - technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号 - unit: '', // 单位 - measureIndicationValue: '', // 被检表示值 errorParamA: '', // 误差参数a errorParamB: '', // 误差参数b maximumError: '', // 最大允许误差 resolution: '0.0001', // 分辨力 - standardResistanceValue: '', // 标准电阻值 - standardResistanceValueUnit: '', // 标准电阻值单位 - editable: true, }) } else { // 指针式 ammeterIndirectList.value.push({ - params: '电流表示值误差(间接测量)', - dataType: '5', + ...data, dataTypeType: '2', - outputChannel: '', // 输出通道 - technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号 - unit: '', // 单位 - measureIndicationValue: '', // 被检表示值 - accuracyA: '', // 准确度a **目前缺少该参数 - fullScaleValue: '', // 指针式仪表满量程值 **目前缺少该参数 - maximumError: '1', // 最大允许误差 - standardResistanceValue: '', // 标准电阻值 - standardResistanceValueUnit: '', // 标准电阻值单位 - editable: true, + accuracyA: '', // 准确度a + fullScaleValue: '', // 指针式仪表满量程值 }) } break case '纹波电压': // 纹波电压 - rippleVoltageList.value.push({ + data = { params: '纹波电压', dataType: '6', technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号 @@ -427,10 +392,11 @@ outputChannel: '', // 输出通道 unit: '', // 单位 editable: true, - }) + } + rippleVoltageList.value.push(data) break case '输出电压短期稳定性': // 输出电压短期稳定性 - outputVoltageStabilityList.value.push({ + data = { params: '输出电压短期稳定性', dataType: '7', technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号 @@ -438,7 +404,8 @@ outputChannel: '', // 输出通道 unit: '', // 单位 editable: true, - }) + } + outputVoltageStabilityList.value.push(data) break } } @@ -454,40 +421,31 @@ } else { let data = [] as any[] - data = list.filter((item: any) => { - return !checkoutList.includes(item) - }) + data = differenceArray(list, checkoutList) switch (title) { case '电源电压调整率': // 电源电压调整率 lineVoltageRegulationList.value = data - listDict.value['1-电源电压调整率'] = lineVoltageRegulationList.value break case '负载调整率': // 负载调整率 loadRegulationList.value = loadRegulationList.value.filter((item: any) => { const needDelte = [...new Set(checkoutList.map(item => item.outputChannel))] return !needDelte.includes(item.outputChannel) }) - listDict.value['2-负载调整率'] = loadRegulationList.value break case '电压表示值误差': // 电压表示值误差 voltageRepresentationValueErrorList.value = data - listDict.value['3-电压表示值误差'] = voltageRepresentationValueErrorList.value break case '电流表示值误差(直接测量)': // 电流表示值误差(直接测量) ammeterDirectList.value = data - listDict.value['4-电流表示值误差(直接测量)'] = ammeterDirectList.value break case '电流表示值误差(间接测量)': // 电流表示值误差(间接测量) ammeterIndirectList.value = data - listDict.value['5-电流表示值误差(间接测量)'] = ammeterIndirectList.value break case '纹波电压': // 纹波电压 rippleVoltageList.value = data - listDict.value['6-纹波电压'] = rippleVoltageList.value break case '输出电压短期稳定性': // 输出电压短期稳定性 outputVoltageStabilityList.value = data - listDict.value['7-输出电压短期稳定性'] = outputVoltageStabilityList.value break } } @@ -508,21 +466,8 @@ break } } - // return reultArr.map((item: boolean) => item) return result } -// ------------------------------------------------------------------------------------------------ -const calculateResult = (title: string) => { - -} -// 点击计算结果--上方表格计算 -const calculateDataTop = () => { - -} -// 点击生成辅助接地电阻--下面表格计算 -const calculateDataBottom = () => { - -} // ----------------------------------------------------------------------------------------------------- // 设置默认值 const setType = (list: Ilist[]) => { @@ -569,37 +514,30 @@ case '1': // 电源电压调整率 lineVoltageRegulationList.value.push({ ...item, params: '电源电压调整率' }) - listDict.value['1-电源电压调整率'].push({ ...item, params: '电源电压调整率' }) break case '2': // 负载调整率 loadRegulationList.value.push({ ...item, params: '负载调整率' }) - listDict.value['2-负载调整率'].push({ ...item, params: '负载调整率' }) break case '3': // 电压表示值误差 voltageRepresentationValueErrorList.value.push({ ...item, params: '电压表示值误差' }) - listDict.value['3-电压表示值误差'].push({ ...item, params: '电压表示值误差' }) break case '4': // 电流表示值误差(直接测量) ammeterDirectList.value.push({ ...item, params: '电流表示值误差(直接测量)' }) - listDict.value['4-电流表示值误差(直接测量)'].push({ ...item, params: '电流表示值误差(直接测量)' }) break case '5': // 电流表示值误差(间接测量) ammeterIndirectList.value.push({ ...item, params: '电流表示值误差(间接测量)' }) - listDict.value['5-电流表示值误差(间接测量)'].push({ ...item, params: '电流表示值误差(间接测量)' }) break case '6': // 纹波电压 rippleVoltageList.value.push({ ...item, params: '纹波电压' }) - listDict.value['6-纹波电压'].push({ ...item, params: '纹波电压' }) break case '7': // 输出电压短期稳定性 outputVoltageStabilityList.value.push({ ...item, params: '输出电压短期稳定性' }) - listDict.value['7-输出电压短期稳定性'].push({ ...item, params: '输出电压短期稳定性' }) break } }) @@ -616,7 +554,6 @@ columnsDict.value['3-电压表示值误差'] = columns_voltage_representation.value if (!pageEditFlag.value) { return } voltageRepresentationValueErrorList.value = [] - listDict.value['3-电压表示值误差'] = voltageRepresentationValueErrorList.value }) watch(() => form.value.ammeterDirectType, (newValue) => { if (newValue === '2') { @@ -628,7 +565,6 @@ columnsDict.value['4-电流表示值误差(直接测量)'] = columns_ammeter_direct.value if (!pageEditFlag.value) { return } ammeterDirectList.value = [] - listDict.value['4-电流表示值误差(直接测量)'] = ammeterDirectList.value }) // 监听电流表示值误差(间接测量) watch(() => form.value.ammeterIndirectType, (newValue) => { @@ -641,7 +577,6 @@ columnsDict.value['5-电流表示值误差(间接测量)'] = columns_ammeter_indirect.value if (!pageEditFlag.value) { return } ammeterIndirectList.value = [] - listDict.value['5-电流表示值误差(间接测量)'] = ammeterIndirectList.value }) // 监听 输出通道 修改下拉框内容 @@ -659,6 +594,15 @@ // 2.限制下拉框内容 setLoadSituation(typeof value === 'string' ? value : list[index].outputChannel as string, list) } +// 表格下拉框等内容是否禁用 +const disabled = ({ scope, column }, fun) => { + // 禁用的话 调用fun函数并传递参数 + if (column.text === '负载情况') { + fun(true) + return + } + fun(props.pageType === 'detail') +} // ---------------------------------------------获取字典--------------------------------------------------- const TechnicalIndexSymbolList = ref<{ value: string;name: string;id: string }[]>([]) // 技术指标前符号 const OutputChannelList = ref<{ value: string;name: string;id: string }[]>([]) // 输出通道 @@ -692,10 +636,12 @@ const tableDict = ref<{ [key: string]: { value: string;name: string;id: string }[] }>({}) // 修改输出通道 function setLoadSituation(current: string, list: IList[]) { - // 1. 已经选择的输出通道 - const selectLoadSituation = [...new Set(list.map((item: any) => item.outputChannel))].filter((item: string) => item !== current) - // 2. 修改下拉框内容 - tableDict.value['输出通道'] = OutputChannelAllList.value.filter((item) => { return !selectLoadSituation.includes(item.value) }) + if (props.pageType === 'detail') { + tableDict.value['输出通道'] = OutputChannelAllList.value + } + else { + tableDict.value['输出通道'] = setSelectList(OutputChannelAllList.value, list, current, 'outputChannel') + } } const fecthDict = async () => { @@ -729,16 +675,10 @@ 负载情况: loadSituationList.value, 最大允许误差: standardMaximumError.value, 标准电阻值单位: standardResistance.value, + 测量单位: unitList1.value, } } fecthDict() -// 获取任意下拉框 -const getAnySelect = (text: string, title: string) => { - if (text === '单位' && title.includes('测量')) { - return unitList1.value - } - return tableDict.value[text] -} defineExpose({ list, checkAllList, form }) @@ -763,506 +703,211 @@
- -
+ + + + + + + + - -
+ + + + + + + - -
+ + + + + + + + - -
+ + + + - -
+ + + + - -
+ + + + + - -
+ + + + + + + diff --git a/src/views/business/measure/item/components/second/templateTable.vue b/src/views/business/measure/item/components/second/templateTable.vue index ccc3ed2..677a6ff 100644 --- a/src/views/business/measure/item/components/second/templateTable.vue +++ b/src/views/business/measure/item/components/second/templateTable.vue @@ -38,22 +38,39 @@ type: String, default: 'default', }, // 表格大小,默认,small,mini等,与el-table条件相同 + // 标题 + title: { + type: String, + default: '', + }, + // 排序 + index: { + type: String, + default: '', + }, + // 按钮展示 + showBtn: { + type: Boolean, + default: false, + }, + // 计算机结果按钮 + calcBtn: { + type: Boolean, + default: false, + }, + // 自定义内容 + customContent: { + type: Boolean, + default: false, + }, + // 下拉框内容 + selectAllList: { + type: Object, + default: () => ({}), + }, }) -const emit = defineEmits(['change', 'selectionChange', 'rowClick', 'rowDbClick', 'multiSelect', 'filterChange']) +const emit = defineEmits(['change', 'selectionChange', 'rowClick', 'rowDbClick', 'multiSelect', 'filterChange', 'addRow', 'delRow', 'changeLoadSituationa', 'calculateResult', 'disabled']) // ------------------------------------------字典---------------------------------------------- -const paramsList = ref([]) // 参数 - -/** - * 获取字典 - */ -function getDict() { - // 参数 - getDictByCode('bizFirstStandardParams').then((response) => { - paramsList.value = response.data - }) -} - -// getDict() // -------定义数据-------------- interface columnsCheckInfo { text: string @@ -103,8 +120,11 @@ initColumnsState() changeColumns() }) +// 多选选中 +const selectList = ref([]) // 多选 const handleSelectionChange = (val: any) => { + selectList.value = val emit('selectionChange', val) } // 清除多选选中 @@ -113,6 +133,34 @@ table.value!.clearSelection() singleChecked.value = '' } +// 删除行 +const delRow = (selectList: any[], list: any[], title: string) => { + emit('delRow', selectList, list, title) +} +// 添加行 +const addRow = (list: any[], title: string, index: string) => { + emit('addRow', list, title, index) +} +// 下拉框 +const getAnySelect = (text: string, title: string) => { + return props.selectAllList[text] +} +// 下拉框禁用情况 +const disabled = (scope: any, column: any) => { + let result = false + emit('disabled', { scope, column }, (value: boolean) => { + result = value + }) + return result +} +// 下拉框获取焦点 或者 下拉框的值发生变化 +const changeLoadSituationa = (value: any, index: number, text: string, type: string, list: any[], title: string) => { + emit('changeLoadSituationa', value, index, text, type, list, title) +} +// 计算结果 +const calculateResult = (title) => { + emit('calculateResult', title) +} defineExpose({ clearMulti, initColumnsState, }) @@ -123,35 +171,100 @@