修改bug 52615 征求意见:添加数据完成后 页面需要自动刷新 现在是手动刷新

This commit is contained in:
zhangyichen
2022-04-19 15:21:39 +08:00
parent d24b00baee
commit 6ae0472109
3 changed files with 38 additions and 2 deletions
+2 -1
View File
@@ -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'
// 路由解析器
@@ -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)
},
}
</script>
+13
View File
@@ -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