mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 01:33:05 +00:00
feat: streamline WeCom QR code login success handling with direct callback integration
This commit is contained in:
parent
fd170cdbc0
commit
5ddd1db32d
|
|
@ -3,10 +3,11 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { nextTick, defineProps, onBeforeUnmount } from 'vue'
|
import {nextTick, defineProps, onBeforeUnmount} from 'vue'
|
||||||
import { useRoute, useRouter } from 'vue-router'
|
import {useRoute, useRouter} from 'vue-router'
|
||||||
import { getBrowserLang } from '@/locales'
|
import {getBrowserLang} from '@/locales'
|
||||||
import useStore from '@/stores'
|
import useStore from '@/stores'
|
||||||
|
|
||||||
const WE_COM_ORIGIN = 'https://login.work.weixin.qq.com'
|
const WE_COM_ORIGIN = 'https://login.work.weixin.qq.com'
|
||||||
const LOGIN_STATE = 'fit2cloud-wecom-qr'
|
const LOGIN_STATE = 'fit2cloud-wecom-qr'
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
|
|
@ -21,10 +22,10 @@ const props = defineProps<{
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const { chatUser } = useStore()
|
const {chatUser} = useStore()
|
||||||
|
|
||||||
const {
|
const {
|
||||||
params: { accessToken },
|
params: {accessToken},
|
||||||
} = route as any
|
} = route as any
|
||||||
|
|
||||||
let iframe: HTMLIFrameElement | null = null
|
let iframe: HTMLIFrameElement | null = null
|
||||||
|
|
@ -52,16 +53,6 @@ function getLang() {
|
||||||
return lang === 'en-US' ? 'en' : 'zh'
|
return lang === 'en-US' ? 'en' : 'zh'
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleLoginSuccess(code: string) {
|
|
||||||
await chatUser.wecomCallback(code, accessToken)
|
|
||||||
|
|
||||||
router.push({
|
|
||||||
name: 'chat',
|
|
||||||
params: { accessToken },
|
|
||||||
query: route.query,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function cleanup() {
|
function cleanup() {
|
||||||
iframe?.remove()
|
iframe?.remove()
|
||||||
iframe = null
|
iframe = null
|
||||||
|
|
@ -86,13 +77,20 @@ const init = async () => {
|
||||||
`&panel_size=small` +
|
`&panel_size=small` +
|
||||||
`&redirect_type=self`
|
`&redirect_type=self`
|
||||||
iframe.addEventListener('load', (e) => {
|
iframe.addEventListener('load', (e) => {
|
||||||
|
console.log('load', iframe)
|
||||||
if (iframe?.contentWindow) {
|
if (iframe?.contentWindow) {
|
||||||
iframe?.contentWindow?.stop()
|
iframe.contentWindow.stop()
|
||||||
const searchParams = new URLSearchParams(iframe.contentWindow.location.search)
|
const searchParams = new URLSearchParams(iframe.contentWindow.location.search)
|
||||||
const code = searchParams.get('code')
|
const code = searchParams.get('code')
|
||||||
if (code) {
|
if (code) {
|
||||||
handleLoginSuccess(code)
|
chatUser.wecomCallback(code, accessToken).then((ok) => {
|
||||||
cleanup()
|
router.push({
|
||||||
|
name: 'chat',
|
||||||
|
params: {accessToken},
|
||||||
|
query: route.query,
|
||||||
|
})
|
||||||
|
cleanup()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue