fix: 增加sessionStorage 监听
parent
39b92124af
commit
1d79aa9a9b
|
@ -8,6 +8,20 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { getSysconfQueryByCode, getDictChildren } from '@/services'
|
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 {
|
export default {
|
||||||
setup() {
|
setup() {
|
||||||
// 是否为主阵地
|
// 是否为主阵地
|
||||||
|
@ -17,13 +31,14 @@ export default {
|
||||||
// 已选择
|
// 已选择
|
||||||
const selectPostion = ref('')
|
const selectPostion = ref('')
|
||||||
const SET_SELECTED_POSITION = () => {
|
const SET_SELECTED_POSITION = () => {
|
||||||
sessionStorage.setItem('selectPostion', selectPostion.value)
|
addStorageEvent('selectPostion', selectPostion.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
const res = await getSysconfQueryByCode({ code: 'isLeaderPosition' })
|
const res = await getSysconfQueryByCode({ code: 'isLeaderPosition' })
|
||||||
if (!res.success) return
|
if (!res.success) return
|
||||||
isLeaderPosition.value = res.data.value
|
isLeaderPosition.value = res.data.value
|
||||||
|
addStorageEvent('isLeaderPosition', res.data.value)
|
||||||
if (isLeaderPosition.value) {
|
if (isLeaderPosition.value) {
|
||||||
const res = await getDictChildren({ value: 'POSITION_DATA' })
|
const res = await getDictChildren({ value: 'POSITION_DATA' })
|
||||||
if (!res.success) return
|
if (!res.success) return
|
||||||
|
@ -38,7 +53,8 @@ export default {
|
||||||
}
|
}
|
||||||
init()
|
init()
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
sessionStorage.removeItem('selectPostion')
|
addStorageEvent('isLeaderPosition', '')
|
||||||
|
addStorageEvent('selectPostion', '')
|
||||||
})
|
})
|
||||||
return {
|
return {
|
||||||
isLeaderPosition,
|
isLeaderPosition,
|
||||||
|
|
Loading…
Reference in New Issue