//此js文件是用来自定义扩展业务代码,可以扩展一些自定义页面或者重新配置生成的代码 import gridHeader from './extend/relocationTask.vue' let extension = { components: { //查询界面扩展组件 gridHeader: gridHeader, gridBody: '', gridFooter: '', //新建、编辑弹出框扩展组件 modelHeader: '', modelBody: '', modelFooter: '' }, tableAction: '', //指定某张表的权限(这里填写表名,默认不用填写) buttons: { view: [], box: [], detail: [] }, //扩展的按钮 methods: { //下面这些方法可以保留也可以删除 onInit() { let TaskHandCancelBtn = this.buttons.find(x => x.value == 'TaskHandCancel'); if (TaskHandCancelBtn) { TaskHandCancelBtn.onClick = function () { let rows = this.$refs.table.getSelected(); if (rows.length == 0) return this.$error("请选择数据!"); if (rows.length > 1) return this.$error("请选择一条数据!"); var param = rows[0].taskNum; this.http .post("api/Task/TaskCancel?taskNum=" + param, "数据处理中...") .then((x) => { if (x.status) { this.$Message.success('任务取消成功.'); this.refresh(); } else { return this.$error(x.message); } }); } } let TaskHandCompletedBtn = this.buttons.find(x => x.value == 'TaskHandCompleted'); if (TaskHandCompletedBtn) { TaskHandCompletedBtn.onClick = function () { this.$confirm("是否确认完成任务", "手动任务完成警告", { confirmButtonText: "确定", cancelButtonText: "取消", type: "warning", center: true, }).then(() => { let rows = this.$refs.table.getSelected(); if (rows.length == 0) return this.$error("请选择数据!"); if (rows.length > 1) return this.$error("请选择一条数据!"); var param = rows[0].taskNum; this.http .post("api/Task/TaskCompleted?taskNum=" + param, "") .then((x) => { if (x.status) { this.$Message.success('任务手动完成'); this.refresh(); } else { return this.$error(x.message); } }); }); } } let ResendTaskBtn = this.buttons.find(x => x.value == 'ResendTask'); if (ResendTaskBtn) { ResendTaskBtn.onClick = function () { this.$confirm("是否确认重新下发任务", "重新下发任务警告", { confirmButtonText: "确定", cancelButtonText: "取消", type: "warning", center: true, }).then(() => { let rows = this.$refs.table.getSelected(); if (rows.length == 0) return this.$error("请选择数据!"); if (rows.length > 1) return this.$error("请选择一条数据!"); var param = rows[0].taskNum; this.http .post("api/Task/ResendTask?taskNum=" + param, "") .then((x) => { if (x.status) { this.$Message.success('任务重新下发'); this.refresh(); } else { return this.$error(x.message); } }); }); } } let relocationBtn = this.buttons.find(x => x.value == 'Relocation'); if (relocationBtn) { relocationBtn.onClick = function () { this.$refs.gridHeader.open(); } } // 初始化任务状态检查定时器 this.taskStatusMap = {}; // 存储任务状态开始时间 this.taskTimeoutMinutes = 10; // 任务超时时间,单位为分钟 this.checkTaskStatusTimer = setInterval(() => { this.checkTaskStatus(); }, 1000); // 每1秒检查一次,提高检查精度,减少延迟 }, // 检查任务状态 checkTaskStatus() { // 获取当前所有任务数据 const taskData = this.$refs.table?.rowData || this.$refs.table?.tableData || []; const now = new Date(); // 获取全局对象和store const globalObj = this.$global || window.$global || {}; const store = this.$store || window.$store; // 处理消息删除逻辑,重置对应任务的定时器 const deletedMessages = globalObj.messageDeleted || []; if (deletedMessages.length > 0) { const storeMessageList = store?.state?.messageList || []; // 遍历被删除的消息ID,重置对应任务的定时器 deletedMessages.forEach(deletedId => { const deletedMessage = storeMessageList.find(msg => msg.id === deletedId); if (deletedMessage?.businessType === 'task_timeout' && deletedMessage.taskNum && this.taskStatusMap[deletedMessage.taskNum]) { this.taskStatusMap[deletedMessage.taskNum] = now; } }); // 清空已处理的删除消息列表 globalObj.messageDeleted = []; } // 获取当前所有任务号和状态 const currentTaskStatuses = {}; taskData.forEach(task => { currentTaskStatuses[task.taskNum] = task.taskStatus; }); // 检查任务状态 taskData.forEach(task => { if (task.taskStatus === 210) { // 堆垛机执行中状态 if (!this.taskStatusMap[task.taskNum]) { this.taskStatusMap[task.taskNum] = now; } else { // 计算持续时间(分钟) const duration = (now - this.taskStatusMap[task.taskNum]) / 60000; if (duration >= this.taskTimeoutMinutes) { this.sendTaskWarningMessage(task, duration); delete this.taskStatusMap[task.taskNum]; } } } else { // 任务状态已改变,清除记录 delete this.taskStatusMap[task.taskNum]; } }); // 清除已解决的任务超时消息 this.clearResolvedTaskMessages(currentTaskStatuses); }, // 清除已解决的任务超时消息 clearResolvedTaskMessages(currentTaskStatuses) { // 获取全局对象和store const globalObj = this.$global || window.$global || {}; const store = this.$store || window.$store; // 获取所有消息列表 const globalMessageList = globalObj.messageList || []; const storeMessageList = store?.state?.messageList || []; // 合并所有消息,找出需要清除的任务超时消息 const allMessages = [...globalMessageList, ...storeMessageList]; const taskTimeoutMessages = allMessages.filter(msg => msg.businessType === 'task_timeout'); // 遍历所有任务超时消息 taskTimeoutMessages.forEach(msg => { const taskNum = msg.taskNum; // 检查条件: // 1. 任务不在当前任务列表中(已完成或被移除) // 2. 任务在当前任务列表中,但状态已不再是堆垛机执行中 if (!currentTaskStatuses[taskNum] || currentTaskStatuses[taskNum] !== 210) { // 任务已完成或状态已改变,清除该消息 this.handleDeleteTaskMessage(msg); } }); }, // 处理删除单个任务消息 handleDeleteTaskMessage(message) { // 获取全局对象和store const globalObj = this.$global || window.$global || {}; const store = this.$store || window.$store; // 从全局消息列表中删除该消息 if (globalObj.messageList) { const index = globalObj.messageList.findIndex(msg => msg.id === message.id); if (index !== -1) { globalObj.messageList.splice(index, 1); } } // 从store中删除该消息 if (store) { store.commit('removeMessage', message.id); } }, // 发送任务警告消息 sendTaskWarningMessage(task, duration) { // 创建警告消息 const warningMessage = { id: Date.now(), title: '任务异常警告', message: `任务号 ${task.taskNum} 已在堆垛机执行中状态超过${Math.round(duration)}分钟,请及时处理!`, type: 'warning', businessType: 'task_timeout', taskNum: task.taskNum, createTime: new Date().toLocaleString() }; // 获取全局对象和store,检查是否存在相同的警告消息 const globalObj = this.$global || window.$global || {}; const store = this.$store || window.$store; const globalMessageList = globalObj.messageList || []; const storeMessageList = store?.state?.messageList || []; // 检查是否已经存在相同的任务超时警告 const hasExistingWarning = [...globalMessageList, ...storeMessageList].some(msg => msg.businessType === 'task_timeout' && msg.taskNum === task.taskNum ); if (hasExistingWarning) return; // 发送消息到消息列表 try { // 添加消息到store const $store = this.$store || window.$store; if ($store) { $store.commit('addMessage', warningMessage); } // 添加消息到全局消息列表 if (globalObj.messageList) { globalObj.messageList.push(warningMessage); } // 显示警告对话框,优先使用$alert // const $global = this.$global || window.$global; // const alertOptions = { // confirmButtonText: '确定', // type: warningMessage.type, // closeOnClickModal: false, // closeOnPressEscape: false, // showCancelButton: false // }; // if (this.$alert || window.$alert) { // const $alert = this.$alert || window.$alert; // $alert(warningMessage.message, warningMessage.title, alertOptions); // } else if (this.$confirm || window.$confirm) { // const $confirm = this.$confirm || window.$confirm; // $confirm(warningMessage.message, warningMessage.title, alertOptions); // } else { // // 使用浏览器原生alert作为备选 // alert(`${warningMessage.title}: ${warningMessage.message}`); // } } catch (error) { // 出错时使用浏览器原生alert作为最终备选 try { alert(`任务异常警告: 任务号 ${task.taskNum} 已在堆垛机执行中状态超过${Math.round(duration)}分钟,请及时处理!`); } catch (e) { // 忽略所有错误 } } }, onInited() { //框架初始化配置后 //如果要配置明细表,在此方法操作 //this.detailOptions.columns.forEach(column=>{ }); }, searchBefore(param) { //界面查询前,可以给param.wheres添加查询参数 //返回false,则不会执行查询 return true; }, searchAfter(result) { // 查询后,result返回的查询数据,可以在显示到表格前处理表格的值 // 处理任务列表刷新后的任务超时消息清理 // 提取当前任务状态 const currentTaskStatuses = {}; if (result && Array.isArray(result)) { result.forEach(task => { currentTaskStatuses[task.taskNum] = task.taskStatus; }); } else if (result && result.result && Array.isArray(result.result)) { // 处理分页返回的数据格式 result.result.forEach(task => { currentTaskStatuses[task.taskNum] = task.taskStatus; }); } // 清除已解决的任务超时消息 this.clearResolvedTaskMessages(currentTaskStatuses); return true; }, addBefore(formData) { //新建保存前formData为对象,包括明细表,可以给给表单设置值,自己输出看formData的值 return true; }, updateBefore(formData) { //编辑保存前formData为对象,包括明细表、删除行的Id return true; }, rowClick({ row, column, event }) { //查询界面点击行事件 this.$refs.table.$refs.table.toggleRowSelection(row); //单击行时选中当前行; }, modelOpenAfter(row) { //点击编辑、新建按钮弹出框后,可以在此处写逻辑,如,从后台获取数据 //(1)判断是编辑还是新建操作: this.currentAction=='Add'; //(2)给弹出框设置默认值 //(3)this.editFormFields.字段='xxx'; //如果需要给下拉框设置默认值,请遍历this.editFormOptions找到字段配置对应data属性的key值 //看不懂就把输出看:console.log(this.editFormOptions) } } }; export default extension;