فهرست منبع

排班编辑时增加批量操作的回退功能

(cherry picked from commit 49fc482c92cc1794b73d42599855e4edcbe7b822)
zhonghuizhen 1 سال پیش
والد
کامیت
54a2a004eb
1فایلهای تغییر یافته به همراه38 افزوده شده و 5 حذف شده
  1. 38 5
      src/views/business/​scheduleManage/edit.vue

+ 38 - 5
src/views/business/​scheduleManage/edit.vue

@@ -25,7 +25,7 @@
                         :size="btn.size || 'mini'"
                         @click="handleAction(btn.key)"
                     >
-                        {{ btn.label }}
+                        {{ btn.key ==='undo'? undoButtonLabel : btn.label }}
                     </el-button>
                 </template>
             </div>
@@ -432,6 +432,7 @@ export default {
             configList: [],
             configOptions: [],
             maxHeight: '250px',
+            undoButtonLabel: '撤销批量修改(0)',
             toolbars: [
                 { key: 'prev', icon: 'el-icon-d-arrow-left', label: '上一步', type: 'primary', steps: '2,3', show: true },
                 { key: 'next', icon: 'el-icon-d-arrow-right', label: '下一步', type: 'primary', steps: '1,2', show: true },
@@ -443,7 +444,8 @@ export default {
                 // { key: 'edit', icon: 'el-icon-edit', label: '编辑', type: 'primary', steps: '2,3' },
                 { key: 'save', icon: 'ibps-icon-save', label: '保存', type: 'primary', show: (!this.readonly) },
                 { key: 'submit', icon: 'ibps-icon-send', label: '提交', type: 'success', steps: '3', show: (!this.readonly) },
-                { key: 'cancel', icon: 'el-icon-close', label: '关闭', type: 'danger', show: true }
+                { key: 'cancel', icon: 'el-icon-close', label: '关闭', type: 'danger', show: true },
+                { key: 'undo', icon: 'el-icon-refresh-left', label: '撤销批量修改', type: 'info', steps: '2', show: (!this.readonly) }
             ],
             viewType: 'users',
             scheduleData: {},
@@ -469,6 +471,8 @@ export default {
                 operateType: 'copy',
                 pasteType: 'all'
             },
+            historyStack: [], // 新增历史记录栈
+            maxHistorySteps: 10, // 最大历史记录步数
             pickerOptions: {
                 disabledDate: (time) => {
                     const { dateRange } = this.formData
@@ -508,9 +512,6 @@ export default {
                 }))
             }
         }
-        // scheduleData () {
-        //     return mapValues(keyBy(this.ordinateList, 'value'), () => Array.from({ length: this.dateList.length }, () => []))
-        // }
     },
     watch: {
         'formData.dateRange': {
@@ -521,6 +522,13 @@ export default {
                 }
             },
             immediate: false // 不需要在组件初始化时执行,仅在日期真正改变时执行
+        },
+        historyStack: {
+            handler (newVal) {
+                this.undoButtonLabel = `撤销批量修改(${newVal.length})` // 更新标签
+            },
+            immediate: true, // 初始化时立即执行
+            deep: true // 深度监听
         }
     },
     created () {
@@ -896,6 +904,9 @@ export default {
                 case 'cancel':
                     this.closeDialog()
                     break
+                case 'undo':
+                    this.handleUndo()
+                    break
                 default:
                     break
             }
@@ -1266,6 +1277,8 @@ export default {
             return Math.ceil((new Date(end) - new Date(start)) / (1000 * 60 * 60 * 24))
         },
         handleShiftSetting (type) {
+            // 保存当前状态到历史记录
+            this.pushHistory()
             const { cycle, dates, operateType, current } = this.shiftForm || {}
             if ((operateType === 'copy' && this.$utils.isEmpty(dates)) || (operateType === 'cycle' && this.$utils.isEmpty(cycle))) {
                 return this.$message.warning('请补充必填信息!')
@@ -1303,6 +1316,26 @@ export default {
             }
             this.resetShiftSetting()
         },
+        pushHistory () {
+            // 保留最多maxHistorySteps步历史记录
+            if (this.historyStack.length >= this.maxHistorySteps) {
+                this.historyStack.shift()
+            }
+            // 深拷贝当前排班数据
+            this.historyStack.push(JSON.parse(JSON.stringify(this.scheduleData)))
+        },
+        handleUndo () {
+            if (this.historyStack.length === 0) {
+                this.$message.warning('已无更多可撤销操作')
+                return
+            }
+            // 取出最近的历史记录
+            const history = this.historyStack.pop()
+            // 恢复排班数据
+            this.scheduleData = history
+            this.$message.success('撤销成功')
+            this.$forceUpdate() // 强制更新视图
+        },
         /** 获取排班变化描述 */
         getOverViews (responseData, newData) {
             const oldData = responseData.staffScheduleDetailPoList