Browse Source

feat: 编辑活动页面增加每30秒自动暂存功能

Developer 5 ngày trước cách đây
mục cha
commit
3a4b764d38
1 tập tin đã thay đổi với 25 bổ sung0 xóa
  1. 25 0
      src/views/modules/activity/add.vue

+ 25 - 0
src/views/modules/activity/add.vue

@@ -275,6 +275,7 @@ export default {
   mixins: [mixinRegionModule],
   data () {
     return {
+      autoSaveTimer: null,
       currentFile: '',
       cropperIndex: null,
       showCropper: false,
@@ -366,6 +367,17 @@ export default {
         this.getDetail(this.$route.query.id)
       }
     })
+
+    // 自动暂存:每30秒保存一次(仅编辑模式)
+    this.autoSaveTimer = setInterval(() => {
+      this.autoSave()
+    }, 30000)
+  },
+  beforeDestroy () {
+    if (this.autoSaveTimer) {
+      clearInterval(this.autoSaveTimer)
+      this.autoSaveTimer = null
+    }
   },
   methods: {
     recruitmentChange (e) {
@@ -601,6 +613,19 @@ export default {
         }, 500)
       })
     },
+    autoSave () {
+      // 只在编辑模式(有id)时自动保存
+      if (!this.basicForm.id) return
+      let { signupStartEnd, activityStartEnd, ...newBasic } = JSON.parse(JSON.stringify(this.basicForm))
+      let { recruitmentFlag, userAgeFlag, userLevelFlag, ...newMore } = JSON.parse(JSON.stringify(this.moreForm))
+      let dto = { ...newBasic, ...newMore }
+      dto.state = dto.state ? 1 : 0
+      this.$http.put('/core/activity', dto).then(res => {
+        if (res.data.code === 0) {
+          this.$message({ message: '已自动暂存', type: 'success', duration: 1500 })
+        }
+      }).catch(() => {})
+    },
     handleSave () {
       this.$refs.moreRef.validate(valid => {
         if (valid) {