|
|
@@ -26,12 +26,23 @@ defineOptions({ name: 'QrCodeForm' })
|
|
|
const { t } = useI18n()
|
|
|
const { handleBackLogin, getLoginState } = useLoginState()
|
|
|
const getShow = computed(() => unref(getLoginState) === LoginStateEnum.QR_CODE)
|
|
|
+const hasInitDingLogin = ref(false)
|
|
|
+const messageHandler = ref<((event: MessageEvent) => void) | null>(null)
|
|
|
|
|
|
const appId = 'dingmr9ez0ecgbmscfeb'
|
|
|
const dingRedirectUrl = import.meta.env.VITE_BASE_URL + '/login?loginType=dingding&type=20'
|
|
|
|
|
|
-onMounted(() => {
|
|
|
- initDingLogin()
|
|
|
+watch(getShow, (show) => {
|
|
|
+ if (show && !hasInitDingLogin.value) {
|
|
|
+ initDingLogin()
|
|
|
+ hasInitDingLogin.value = true
|
|
|
+ }
|
|
|
+})
|
|
|
+
|
|
|
+onBeforeUnmount(() => {
|
|
|
+ if (messageHandler.value) {
|
|
|
+ window.removeEventListener('message', messageHandler.value, false)
|
|
|
+ }
|
|
|
})
|
|
|
const _getRandomString = (len) => {
|
|
|
len = len || 10
|
|
|
@@ -102,6 +113,7 @@ const initDingLogin = () => {
|
|
|
} else if (typeof window.attachEvent != 'undefined') {
|
|
|
window.attachEvent('onmessage', handleMessage)
|
|
|
}
|
|
|
+ messageHandler.value = handleMessage
|
|
|
// }
|
|
|
}
|
|
|
</script>
|