From 6ae0472109f30eb9c9e8a5723c08a5f231bcceb6 Mon Sep 17 00:00:00 2001 From: zhangyichen <5277314+zacty@user.noreply.gitee.com> Date: Tue, 19 Apr 2022 15:21:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9bug=2052615=20=E5=BE=81?= =?UTF-8?q?=E6=B1=82=E6=84=8F=E8=A7=81=EF=BC=9A=E6=B7=BB=E5=8A=A0=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=AE=8C=E6=88=90=E5=90=8E=20=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E8=87=AA=E5=8A=A8=E5=88=B7=E6=96=B0=20?= =?UTF-8?q?=E7=8E=B0=E5=9C=A8=E6=98=AF=E6=89=8B=E5=8A=A8=E5=88=B7=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.js | 3 ++- .../pags/consultationDetails.vue | 24 ++++++++++++++++++- src/utils/tool.js | 13 ++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 src/utils/tool.js diff --git a/src/main.js b/src/main.js index a2c5adf76..803cf9d99 100644 --- a/src/main.js +++ b/src/main.js @@ -46,7 +46,8 @@ import 'vant/lib/index.css'; //vant import animate from 'animate.css' - +import tool from './utils/tool' +Vue.use(tool) // 引入路由器 import router from './router' // 路由解析器 diff --git a/src/pages/regulatoryRepository/standardForComments/pags/consultationDetails.vue b/src/pages/regulatoryRepository/standardForComments/pags/consultationDetails.vue index 89cb9de04..c1c1e7514 100644 --- a/src/pages/regulatoryRepository/standardForComments/pags/consultationDetails.vue +++ b/src/pages/regulatoryRepository/standardForComments/pags/consultationDetails.vue @@ -388,6 +388,7 @@ export default { console.log(res.data.records); this.total = res.data.total this.spinShow = false + localStorage.setItem('refreshFlag', false) }, e => { }) }, @@ -557,6 +558,13 @@ export default { }, handleQueryPdf(file){ window.open('/static/pdf/web/viewer.html?file=' + encodeURIComponent('/api/att/attFile/getFileInfo?fileId=' + file.attId)) + }, + isVisible(e) { + if (e.target.visibilityState === "visible") { + this.getList() + } else if (e.target.visibilityState === "hidden") { + this.getList() + } } }, watch: { @@ -572,6 +580,17 @@ export default { ...mapGetters(['refreshFlag']) }, mounted() { + const that = this; + //监听缓存中指定key的值变化 + window.addEventListener("setItemEvent",function(e){ + //e.key : 是值发生变化的key + //例如 e.key==="token"; + //e.newValue : 是可以对应的新值 + if(e.key === "refreshFlag" && e.newValue === true){ + this.getList() + } + }) + document.addEventListener('visibilitychange', that.isVisible) if (this.lawsStand) { this.form = { ideaId: this.lawsStand.id, @@ -613,7 +632,10 @@ export default { this.getList() this.getIdeaKey() this.getFileInfo() - } + }, + destroyed() { + document.removeEventListener('visibilitychange', this.isVisible) + }, } diff --git a/src/utils/tool.js b/src/utils/tool.js new file mode 100644 index 000000000..2efd74a93 --- /dev/null +++ b/src/utils/tool.js @@ -0,0 +1,13 @@ +function dispatchEventStroage() { + const signSetItem = localStorage.setItem + localStorage.setItem = function(key, val) { + let setEvent = new Event('setItemEvent') + setEvent.key = key + setEvent.newValue = val + window.dispatchEvent(setEvent) + signSetItem.apply(this, arguments) + } +} + +export default dispatchEventStroage +