Skip to content

Commit

Permalink
refactor(iframe): 优化 iframe 在tab页关闭和刷新时重新加载iframe页面。
Browse files Browse the repository at this point in the history
  • Loading branch information
kanyxmo committed Nov 27, 2024
1 parent f368ec1 commit 936abb0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions web/src/layouts/components/iframe/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default defineComponent({
const route = useRoute()
const routers = useRouter().getRoutes()
const iframeStore = useIframeKeepAliveStore()
const list = computed(() => iframeStore.iframeList ?? [])
onMounted(() => {
const iframeArea = document.querySelector('.mine-iframe-area') as HTMLDivElement
iframeArea.classList.add('overflow-hidden')
Expand Down
18 changes: 18 additions & 0 deletions web/src/store/modules/useTabStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const useTabStore = defineStore(
const router = useRouter()
const settingStore = useSettingStore()
const keepAliveStore = useKeepAliveStore()
const iframeKeepLiveStore = useIframeKeepAliveStore()
const welcomePage = settingStore.getSettings('welcomePage') as SystemSettings.welcomePage
const tabList = ref<MineTabbar[]>([])
const { isLoading } = useNProgress()
Expand Down Expand Up @@ -103,8 +104,12 @@ const useTabStore = defineStore(
keepAliveStore.hidden()
await new Promise(resolve => resolve(setTimeout(() => {
}, 200)))
if (tab.path.indexOf('MineIframe') > 0) {
iframeKeepLiveStore.remove(tab.name)
}
keepAliveStore.remove(tab.name)
await nextTick(async () => {
iframeKeepLiveStore.add(tab.name)
keepAliveStore.add(tab.name)
keepAliveStore.display()
await go(tab)
Expand All @@ -126,6 +131,9 @@ const useTabStore = defineStore(
await router.push(tabList.value[idx - 1].fullPath)
}
}
if (tab.path.indexOf('MineIframe') > 0) {
iframeKeepLiveStore.remove(tab.name)
}
tabList.value.splice(idx, 1)
keepAliveStore.remove(item.name)
}
Expand All @@ -138,6 +146,9 @@ const useTabStore = defineStore(
return true
}
else {
if (item.path.indexOf('MineIframe') > 0) {
iframeKeepLiveStore.remove(item.name)
}
keepAliveStore.remove(item.name)
return false
}
Expand All @@ -158,6 +169,9 @@ const useTabStore = defineStore(
return true
}
else {
if (item.path.indexOf('MineIframe') > 0) {
iframeKeepLiveStore.remove(item.name)
}
keepAliveStore.remove(item.name)
return false
}
Expand All @@ -179,6 +193,9 @@ const useTabStore = defineStore(
return true
}
else {
if (item.path.indexOf('MineIframe') > 0) {
iframeKeepLiveStore.remove(item.name)
}
keepAliveStore.remove(item.name)
return false
}
Expand Down Expand Up @@ -206,6 +223,7 @@ const useTabStore = defineStore(
function clearTab() {
tabList.value = [defaultTab.value]
keepAliveStore.clean()
iframeKeepLiveStore.clean()
}

function storage() {
Expand Down

0 comments on commit 936abb0

Please sign in to comment.