Просмотр исходного кода

成本添加30分钟无操作自动保存并退出登录。

yuanrf 1 год назад
Родитель
Сommit
81200bbe87
1 измененных файлов с 50 добавлено и 30 удалено
  1. 50 30
      src/components/Finance/Cost.vue

+ 50 - 30
src/components/Finance/Cost.vue

@@ -29,8 +29,9 @@
                         <el-button size="small" type="primary" @click="GetClientWord">导出客户报表</el-button>
                         <el-button size="small" type="primary" @click="GetGroupCostExcel">导出成本</el-button>
                         <!-- <el-button type="primary">一键复制</el-button> -->
-                        <el-button v-if="isShare==1" size="small" type="info" @click="GroupIsShare">取消成本通知</el-button>
-                        <el-button v-if="isShare==0" size="small" type="primary" @click="GroupIsShare">成本通知</el-button>
+                        <el-button v-if="isShare == 1" size="small" type="info" @click="GroupIsShare">取消成本通知</el-button>
+                        <el-button v-if="isShare == 0" size="small" type="primary"
+                            @click="GroupIsShare">成本通知</el-button>
                         <el-button size="small" type="primary" @click="save">保存设置</el-button>
                     </div>
                 </div>
@@ -2649,14 +2650,14 @@ export default {
                 }
             ],
             autoSave: null,
-            acconarr:[],
-            acconarrs:[],
-            isShare:0,
+            acconarr: [],
+            acconarrs: [],
+            isShare: 0,
             blackCodeIsTrue: false,
             //监听变量
-            count:0,
-            x:0,
-            y:0,
+            //count: 0,
+            x: 0,
+            y: 0,
         };
     },
     watch: {
@@ -3169,7 +3170,7 @@ export default {
                         var acostvalue = resp.data.data.groupCostParameter.filter(x => x.costType == 'A')[0];
                         if (acostvalue != undefined) {
                             that.AGroupCostParameter = acostvalue;
-                            that.isShare=that.AGroupCostParameter.isShare;//是否通知
+                            that.isShare = that.AGroupCostParameter.isShare;//是否通知
                             console.log(that.AGroupCostParameter)
                             var result = Number(that.AGroupCostParameter.currency);
                             if (isNaN(result)) {
@@ -4553,7 +4554,7 @@ export default {
             }).then(resp => {
                 ////console.log(resp.data.data, '------------------------------------');
                 if (resp.data.code == 200) {
-                    this.isShare=resp.data.data.isShare;
+                    this.isShare = resp.data.data.isShare;
                     this.$message({
                         message: '操作成功!' + resp.data.msg,
                         type: 'success'
@@ -5516,39 +5517,58 @@ export default {
 
         },
         //监听鼠标
-        MonitorMouse(){
+        MonitorMouse() {
             document.onmousemove = (event) => {
                 let x1 = event.clientX
                 let y1 = event.clientY
                 if (this.x !== x1 || this.y !== y1) {
-                    this.count = 0
+                    this.setTimer();
                 }
                 this.x = x1
                 this.y = y1
             }
         },
         //监听键盘
-        MonitorKeyboard(){
+        MonitorKeyboard() {
             document.onkeydown = () => {
-                this.count = 0;
+                this.setTimer();
             }
         },
         //取消定时器
-        clearTimer () {
-            clearInterval(window.myTimer)
+        clearTimer() {
+            clearTimeout(window.myTimer)
             window.myTimer = null
+            //取消监听
+            document.onmousemove = null;
+            document.onkeydown = null;
         },
         //定时调用函数
-        setTimer () {
+        setTimer() {
             this.count = 0
-            if (!window.myTimer) {
-                window.myTimer = window.setInterval(this.cookieTimeout, 1000)
+            const mm = 1000 * 60;
+            if (window.myTimer) {
+                try {
+                    clearTimeout(window.myTimer);
+                } catch (e) {
+                    console.log("setTimerMessage", e.message);
+                }
             }
+            window.myTimer = setInterval(this.SaveAndLogOut, mm * 30);
         },
-        //执行函数
-        cookieTimeout(){
-            this.count++;
-            console.log(this.count);
+        SaveAndLogOut() {
+            this.save().then(() => {
+                this.$router.push({ name: 'Login' })
+                localStorage.removeItem("userinif");
+                this.$message({
+                    type: 'success',
+                    message: '已退出!'
+                });
+                console.log("保存成功,已退出!");
+            }).catch(e => {
+                console.log(e);
+                console.log("保存失败,仅停止自动保存!");
+                clearInterval(this.autoSave);
+            })
         }
 
     },
@@ -5570,10 +5590,14 @@ export default {
                 setTimeout(() => {
                     this.save();
                 }, 100);
-            }, mm * 3);
+            }, mm * 10);
+
+            this.MonitorMouse();
+            this.MonitorKeyboard();
+            this.setTimer();
         }
 
-        document.querySelectorAll('.el-table__footer')[0].style.display = "none"
+        document.querySelectorAll('.el-table__footer')[0].style.display = "none";
         if (costLoadData) {
             var JSONP = JSON.parse(costLoadData);
             var diidP = Number(JSONP.diid);
@@ -5583,12 +5607,8 @@ export default {
         }
 
         window.Vue = this;
-        
-        this.MonitorMouse();
-        this.MonitorKeyboard();
-        this.setTimer();
     },
-    beforeDestroy(){
+    beforeDestroy() {
         this.clearTimer()
     },
     computed: {