fix: 增加sessionStorage 监听
parent
39b92124af
commit
1d79aa9a9b
|
@ -8,6 +8,20 @@
|
|||
|
||||
<script>
|
||||
import { getSysconfQueryByCode, getDictChildren } from '@/services'
|
||||
const addStorageEvent = (key, data) => {
|
||||
// 创建一个StorageEvent事件
|
||||
var newStorageEvent = document.createEvent('StorageEvent')
|
||||
const storage = {
|
||||
setItem: function (k, val) {
|
||||
sessionStorage.setItem(k, val)
|
||||
// 初始化创建的事件
|
||||
newStorageEvent.initStorageEvent('setItem', false, false, k, null, val, null, null)
|
||||
// 派发对象
|
||||
window.dispatchEvent(newStorageEvent)
|
||||
}
|
||||
}
|
||||
return storage.setItem(key, data)
|
||||
}
|
||||
export default {
|
||||
setup() {
|
||||
// 是否为主阵地
|
||||
|
@ -17,13 +31,14 @@ export default {
|
|||
// 已选择
|
||||
const selectPostion = ref('')
|
||||
const SET_SELECTED_POSITION = () => {
|
||||
sessionStorage.setItem('selectPostion', selectPostion.value)
|
||||
addStorageEvent('selectPostion', selectPostion.value)
|
||||
}
|
||||
|
||||
async function init() {
|
||||
const res = await getSysconfQueryByCode({ code: 'isLeaderPosition' })
|
||||
if (!res.success) return
|
||||
isLeaderPosition.value = res.data.value
|
||||
addStorageEvent('isLeaderPosition', res.data.value)
|
||||
if (isLeaderPosition.value) {
|
||||
const res = await getDictChildren({ value: 'POSITION_DATA' })
|
||||
if (!res.success) return
|
||||
|
@ -38,7 +53,8 @@ export default {
|
|||
}
|
||||
init()
|
||||
onUnmounted(() => {
|
||||
sessionStorage.removeItem('selectPostion')
|
||||
addStorageEvent('isLeaderPosition', '')
|
||||
addStorageEvent('selectPostion', '')
|
||||
})
|
||||
return {
|
||||
isLeaderPosition,
|
||||
|
|
Loading…
Reference in New Issue