import Utils from "~/utils" const INTERVAL_SAVE_TIME = 10000 export default{ methods: { intervalSaveModel(){ let ownKey = this.combineKey(); if(!ownKey){ return } window.localStorage.setItem(ownKey,JSON.stringify(this.model)) }, combineKey(){ let url = this.$route.fullPath let userid = window.sessionStorage.userId let org = JSON.parse(window.sessionStorage.currentOrg).id let role =JSON.parse(window.sessionStorage.curRole).id let ownKey = url+"-"+userid+"-"+org+"-"+role if(ownKey.indexOf("null") > -1 || ownKey.indexOf("undefined")> -1){ return "" } return ownKey; }, recoverPendingRecord(){ let ownKey = this.combineKey() let modelStr = localStorage.getItem(ownKey) if(!ownKey || !modelStr){ return Promise.resolve(false) } let oldModel = JSON.parse(modelStr) if(oldModel != null){ return new Promise(async (resolve)=>this.$confirm('该笔交易存在异常退出的数据,是否恢复?', '提示', { confirmButtonText: '恢复', cancelButtonText: '删除', type: 'warning' }).then(async() => { Utils.copyValueFromVoData(this.model,oldModel) // this.handleIsImportRules() this.beginInterval() resolve(true) }).catch(() => { localStorage.removeItem(ownKey) resolve(false) })) } return Promise().resolve(false) }, initDefaultData(){ return this.initDefault() }, beginInterval(){ this.$timer = setInterval(() => { this.intervalSaveModel(); }, INTERVAL_SAVE_TIME); } } }