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