fix: 增加sessionStorage 监听

develop
时启龙 2024-08-28 10:09:14 +08:00
parent 39b92124af
commit 1d79aa9a9b
1 changed files with 18 additions and 2 deletions

View File

@ -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,