|
@@ -0,0 +1,39 @@
|
|
|
+import {useEventListener} from '@vueuse/core'
|
|
|
+import {onUnmounted} from "vue";
|
|
|
+import {CyMessageBox} from "@/components/cy/message-box";
|
|
|
+
|
|
|
+
|
|
|
+export enum documentVisibilityEnum {
|
|
|
+ hidden = 'hidden',
|
|
|
+ visible = 'visible'
|
|
|
+}
|
|
|
+
|
|
|
+function useChangeToken() {
|
|
|
+ const token = localStorage.token
|
|
|
+
|
|
|
+ function isChange() {
|
|
|
+ if (document.visibilityState === documentVisibilityEnum.hidden)
|
|
|
+ return
|
|
|
+ if (token !== localStorage.token)
|
|
|
+ CyMessageBox.alert({
|
|
|
+ message: '监测到账号不一致',
|
|
|
+ confirmButtonText: '刷新页面'
|
|
|
+ }).finally(() => {
|
|
|
+ window.location.reload()
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ const listener = useEventListener(document, "visibilitychange", () => {
|
|
|
+ isChange()
|
|
|
+ });
|
|
|
+
|
|
|
+ onMounted(() => {
|
|
|
+ isChange()
|
|
|
+ })
|
|
|
+
|
|
|
+ onUnmounted(() => {
|
|
|
+ listener()
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+export default useChangeToken
|