| | |
| | | }, |
| | | |
| | | }) |
| | | //定义模拟计算弹窗默认隐藏 |
| | | const optimizecompute = ref(false) |
| | | const Mange = ref(true) |
| | | //右键菜单点击事件 |
| | | // 定义操作配置对象数组,集中管理不同操作选项对应的参数 |
| | | const operationConfigs = [ |
| | | { |
| | | code: 'compute', // 打开模拟计算操作 |
| | | initialState: ['1', '2'], // |
| | | targetState: null, |
| | | successMsg: '模拟计算已启动!', |
| | | checkMessage: '当前工程状态不符合模拟计算条件,请确认工程状态后再操作!', |
| | | requiresRow: true, |
| | | actionFunction: () => { |
| | | optimizeCompute.value = true; |
| | | Mange.value = false; |
| | | } |
| | | }, |
| | | { |
| | | code: 'undocompute', |
| | | initialState: '10', |
| | | targetState: 2, |
| | | successMsg: '撤销模拟计算成功,数据已更新!', |
| | | checkMessage: '当前工程状态不符合撤销模拟计算条件,请确认工程状态后再操作!', |
| | | requiresRow: true, |
| | | }, |
| | | { |
| | | code: 'undooptimize', |
| | | initialState: '20', |
| | | targetState: 10, |
| | | successMsg: '撤销优化成功,数据已更新!', |
| | | checkMessage: '当前工程状态不符合撤销优化条件,请确认工程状态后再操作!', |
| | | requiresRow: true, |
| | | }, |
| | | { |
| | | code: 'production', |
| | | initialState: '20', |
| | | targetState: 100, |
| | | successMsg: '设置成功,允许生产!', |
| | | checkMessage: '当前工程状态不符合允许生产条件,请确认工程状态后再操作!', |
| | | requiresRow: true, |
| | | }, |
| | | { |
| | | code: 'novisible', |
| | | initialState: '100', |
| | | targetState: 20, |
| | | successMsg: '设置成功,生产不可见!', |
| | | checkMessage: '当前工程状态不符合生产不可见条件,请确认工程状态后再操作!', |
| | | requiresRow: true, |
| | | }, |
| | | { |
| | | code: 'Initializeproject', |
| | | initialState: ['2', '10', '20'], |
| | | targetState: 1, |
| | | successMsg: '初始化工程成功!', |
| | | checkMessage: '当前工程状态不符合初始化条件,请确认工程状态后再操作!', |
| | | requiresRow: true, |
| | | }, |
| | | { |
| | | code: 'delproject', |
| | | initialState: ['1', '2', '10', '20', '100'], // 假设这些状态下的工程都允许删除,你可根据实际业务调整 |
| | | targetState: null, |
| | | successMsg: '工程删除成功!', |
| | | failureMsg: '工程删除失败,请联系管理员!', |
| | | checkMessage: '当前工程状态不符合删除条件,请确认工程状态后再操作!', |
| | | }, |
| | | { |
| | | code: 'Export', // 导出文件操作的配置 |
| | | initialState: [], |
| | | targetState: null, |
| | | successMsg: '文件导出成功!', |
| | | gridRef: xGrid, // 将xGrid的引用传递进来,用于调用exportData方法 |
| | | requiresRow: false, |
| | | } |
| | | ]; |
| | | function getOriginalState(targetState) { |
| | | // 根据工程状态返回对应的原始状态 |
| | | const stateMapping = { |
| | | 2: '10', |
| | | 10: '20', |
| | | 100: '200', |
| | | 200: '100', |
| | | 1:['2', '10', '20'], |
| | | }; |
| | | return stateMapping[targetState] || targetState; |
| | | } |
| | | // 右键菜单点击事件 |
| | | const gridEvents = { |
| | | menuClick({menu, row, column}) { |
| | | const $grid = xGrid.value |
| | | menuClick({ menu, row }) { |
| | | const $grid = xGrid.value; |
| | | if ($grid) { |
| | | switch (menu.code) { |
| | | case 'copy': |
| | | if (row && column) { |
| | | if (VxeUI.clipboard.copy(row[column.field])) { |
| | | VxeUI.modal.message({content: '已复制到剪贴板!', status: 'success'}) |
| | | } |
| | | const config = operationConfigs.find(c => c.code === menu.code); |
| | | if (config) { |
| | | if (config.requiresRow &&!row) { |
| | | ElMessage.warning('未选中工程,请选中工程后再进行当前操作!'); |
| | | return; |
| | | } |
| | | if (config.code === 'compute') { |
| | | config.actionFunction(); |
| | | } else if (config.code === 'Export') { |
| | | config.gridRef.value.exportData(); |
| | | ElMessage.success(config.successMsg); |
| | | } else if (config.code === 'delproject') { |
| | | deleteProject(row.projectNumber, config); // 调用删除工程的函数,传入工程编号和配置信息 |
| | | } else |
| | | if (config.requiresRow && config.initialState.includes(String(row.state))) { |
| | | row.state = config.targetState; |
| | | const index = produceList.value.findIndex(item => item === row); |
| | | if (index!== -1) { |
| | | produceList.value.splice(index, 1, {...row }); |
| | | xGrid.value.reloadData(produceList.value); |
| | | } |
| | | break |
| | | case 'compute': |
| | | optimizecompute.value = true; |
| | | Mange.value = false; |
| | | break |
| | | case 'Export': |
| | | $grid.exportData() |
| | | break |
| | | case 'undocompute': |
| | | if (!row) { |
| | | ElMessage.warning('未选中工程,请选中工程后再进行当前操作!'); |
| | | return; |
| | | } |
| | | if (String(row.state) === '10') { |
| | | row.state = '2'; |
| | | const index = produceList.value.findIndex(item => item === row); |
| | | if (index!== -1) { |
| | | produceList.value.splice(index, 1, {...row }); |
| | | xGrid.value.reloadData(produceList.value); |
| | | } |
| | | const projectNumber = row.projectNumber; |
| | | const state = 2; // 明确定义要更新的状态值为2 |
| | | const updateParams = { |
| | | projectNumber: projectNumber, |
| | | stateToUpdate: state |
| | | }; |
| | | request.post(`/glassOptimize/updateProjectState/${projectNumber}/${state}`, updateParams, { |
| | | headers: { |
| | | 'Content-Type': 'application/json' |
| | | } |
| | | }).then((res) => { |
| | | if (res.code === 200 && res.data && res.data.success) { // 假设后端返回的data里有success字段表示操作是否成功,根据后端实际返回结构调整 |
| | | ElMessage.success('撤销模拟计算成功,数据已更新!'); |
| | | } else { |
| | | console.log('撤销模拟计算失败,后端返回的详细信息:', res); |
| | | const errorMsg = res.data? res.data.errorMessage : '撤销模拟计算失败,未获取到具体原因,请联系管理员'; // 尝试获取后端返回的详细错误消息,如果没有则显示通用提示 |
| | | ElMessage.error(`撤销模拟计算失败,原因: ${errorMsg}`); |
| | | row.state = '10'; |
| | | const rollbackIndex = produceList.value.findIndex(item => item === row); |
| | | if (rollbackIndex!== -1) { |
| | | produceList.value.splice(rollbackIndex, 1, {...row }); |
| | | xGrid.value.reloadData(produceList.value); |
| | | } |
| | | } |
| | | }).catch((error) => { |
| | | console.error('请求出错,撤销模拟计算未完成,详细错误信息:', error); |
| | | const errorMsg = error.message || '请求出错,未获取到具体原因,请联系管理员'; |
| | | ElMessage.error(`请求出错,撤销模拟计算未完成,原因: ${errorMsg}`); |
| | | row.state = '10'; |
| | | const rollbackIndex = produceList.value.findIndex(item => item === row); |
| | | if (rollbackIndex!== -1) { |
| | | produceList.value.splice(rollbackIndex, 1, {...row }); |
| | | xGrid.value.reloadData(produceList.value); |
| | | } |
| | | }); |
| | | } else { |
| | | ElMessage.warning('当前工程状态不符合撤销模拟计算条件,请确认工程状态后再操作!'); |
| | | } |
| | | break; |
| | | updateProjectStateAndHandleResponse(row, row.projectNumber, config.targetState, config.successMsg); |
| | | } else { |
| | | ElMessage.warning(config.checkMessage); |
| | | } |
| | | } else { |
| | | console.error(`未找到操作选项 ${menu.code} 对应的配置,请检查配置项`); |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | |
| | | // 封装发送右键菜单请求、处理响应以及错误回滚等逻辑的函数 |
| | | function rollbackStateAndReloadGrid(row, targetState) { |
| | | row.state = getOriginalState(targetState); |
| | | const rollbackIndex = produceList.value.findIndex(item => item === row); |
| | | if (rollbackIndex!== -1) { |
| | | produceList.value.splice(rollbackIndex, 1, {...row}); |
| | | xGrid.value.reloadData(produceList.value); |
| | | } |
| | | } |
| | | function updateProjectStateAndHandleResponse(row, projectNumber, targetState, successMsg) { |
| | | const updateParams = { |
| | | projectNumber: projectNumber, |
| | | stateToUpdate: targetState |
| | | }; |
| | | request.post(`/glassOptimize/updateProjectState/${projectNumber}/${targetState}`, updateParams, { |
| | | headers: { |
| | | 'Content-Type': 'application/json' |
| | | } |
| | | }).then((res) => { |
| | | if (Number(res.code) === 200 && (res.msg === "" || res.msg === null)) { |
| | | ElMessage.success(successMsg); |
| | | } else { |
| | | console.log('res.code 的值:', res.code, ', 类型:', typeof res.code); |
| | | console.log('res.msg 的值:', res.msg, ', 类型:', typeof res.msg); |
| | | const errorMsg = res.data? res.data.errorMessage : '操作失败,未获取到具体原因,请联系管理员'; |
| | | ElMessage.error(`操作失败,原因: ${errorMsg}`); |
| | | rollbackStateAndReloadGrid(row, targetState); // 调用回滚函数 |
| | | } |
| | | }).catch((error) => { |
| | | console.error('请求出错,操作未完成,详细错误信息:', error); |
| | | const errorMsg = (res.data && res.data.errorMessage)? res.data.errorMessage : '操作失败,未获取到具体原因,请联系管理员'; |
| | | ElMessage.error(`请求出错,操作未完成,原因: ${errorMsg}`); |
| | | rollbackStateAndReloadGrid(row, targetState); // 调用回滚函数 |
| | | }); |
| | | } |
| | | |
| | | //删除工程 |
| | | function deleteProject(projectNumber, config) { |
| | | request.post(`/glassOptimize/deleteProject/${projectNumber}`, { |
| | | headers: { |
| | | 'Content-Type': 'application/json' |
| | | } |
| | | }).then((res) => { |
| | | if (Number(res.code) === 200 && (res.msg === "" || res.msg === null)) { |
| | | ElMessage.success(config.successMsg); |
| | | // 从列表中移除已删除的工程数据 |
| | | const index = produceList.value.findIndex(item => item.projectNumber === projectNumber); |
| | | if (index!== -1) { |
| | | produceList.value.splice(index, 1); |
| | | xGrid.value.reloadData(produceList.value); |
| | | } |
| | | } else { |
| | | console.log('res.code 的值:', res.code, ', 类型:', typeof res.code); |
| | | console.log('res.msg 的值:', res.msg, ', 类型:', typeof res.msg); |
| | | const errorMsg = res.data? res.data.errorMessage : config.failureMsg; |
| | | ElMessage.error(`操作失败,原因: ${errorMsg}`); |
| | | } |
| | | }).catch((error) => { |
| | | console.error('请求出错,工程删除未完成,详细错误信息:', error); |
| | | const errorMsg = (res.data && res.data.errorMessage)? res.data.errorMessage : config.failureMsg; |
| | | ElMessage.error(`请求出错,工程删除未完成,原因: ${errorMsg}`); |
| | | }); |
| | | } |
| | | |
| | | //定义模拟计算弹窗默认隐藏 |
| | | const optimizeCompute = ref(false) |
| | | const Mange = ref(true) |
| | | |
| | | //定义工程状态 |
| | | const optionVal = ref('all') |
| | | const options = [ |
| | |
| | | |
| | | <template> |
| | | <div id="mange"> |
| | | <glass-computed v-if="optimizecompute"/> |
| | | <glass-computed v-if="optimizeCompute"/> |
| | | <div style="height: 100%; width: 100%" v-if="Mange"> |
| | | <div id="select"> |
| | | <span>优化日期</span> |