Skip to content

Commit c744375

Browse files
committed
fix: update WeCom QR code handling to use iframe and include callback URL
1 parent eb867da commit c744375

File tree

2 files changed

+30
-101
lines changed

2 files changed

+30
-101
lines changed

ui/src/views/chat/user-login/scanCompinents/wecomQrCode.vue

Lines changed: 14 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,39 @@
11
<template>
2-
<div id="wecom-qr" class="wecom-qr flex"></div>
2+
<iframe :src="iframeUrl" width="100%" height="380px" frameborder="0"></iframe>
33
</template>
44

55
<script lang="ts" setup>
6-
import {useRoute, useRouter} from 'vue-router'
7-
import * as ww from '@wecom/jssdk'
8-
import {
9-
WWLoginLangType,
10-
WWLoginPanelSizeType,
11-
WWLoginRedirectType,
12-
WWLoginType
13-
} from '@wecom/jssdk'
146
import {ref, nextTick, defineProps} from 'vue'
15-
import {MsgError} from '@/utils/message'
16-
import useStore from '@/stores'
177
import {getBrowserLang} from '@/locales'
188
19-
const router = useRouter()
20-
const route = useRoute()
21-
const {
22-
params: {accessToken},
23-
} = route as any
24-
const wwLogin = ref({})
25-
const obj = ref<any>({isWeComLogin: false})
26-
const {chatUser} = useStore()
27-
289
const props = defineProps<{
2910
config: {
3011
app_secret: string
3112
app_key: string
3213
corp_id?: string
3314
agent_id?: string
15+
callback_url: string
3416
}
3517
}>()
3618
19+
const iframeUrl = ref('')
3720
const init = async () => {
3821
await nextTick() // 确保DOM已更新
3922
const data = {
4023
corpId: props.config.corp_id,
41-
agentId: props.config.agent_id
24+
agentId: props.config.agent_id,
25+
redirectUri: props.config.callback_url,
4226
}
43-
const lang = localStorage.getItem('MaxKB-locale') || getBrowserLang() || 'en-US'
44-
const redirectUri = window.location.origin
45-
try {
46-
wwLogin.value = ww.createWWLoginPanel({
47-
el: '#wecom-qr',
48-
params: {
49-
login_type: WWLoginType.corpApp,
50-
appid: data.corpId || '',
51-
agentid: data.agentId,
52-
redirect_uri: redirectUri,
53-
state: 'fit2cloud-wecom-qr',
54-
lang: lang === 'zh-CN' || lang === 'zh-Hant' ? WWLoginLangType.zh : WWLoginLangType.en,
55-
redirect_type: WWLoginRedirectType.callback,
56-
panel_size: WWLoginPanelSizeType.small
57-
},
58-
onCheckWeComLogin: obj.value,
59-
async onLoginSuccess({code}: any) {
60-
chatUser.wecomCallback(code, accessToken).then(() => {
61-
setTimeout(() => {
62-
router.push({
63-
name: 'chat',
64-
params: {accessToken: accessToken},
65-
query: route.query,
66-
})
67-
})
68-
})
69-
},
70-
onLoginFail(err) {
71-
MsgError(`${err.errMsg}`)
72-
}
73-
})
74-
} catch (error) {
27+
let lang = localStorage.getItem('MaxKB-locale') || getBrowserLang() || 'en-US'
28+
if (lang === 'en-US') {
29+
lang = 'en'
30+
} else {
31+
lang = 'zh'
7532
}
33+
const redirectUri = encodeURIComponent(data.redirectUri)
34+
console.log('redirectUri', data.redirectUri)
35+
// 手动构建生成二维码的url
36+
iframeUrl.value = `https://login.work.weixin.qq.com/wwlogin/sso/login?login_type=CorpApp&appid=${data.corpId}&agentid=${data.agentId}&redirect_uri=${redirectUri}&state=fit2cloud-wecom-qr&lang=${lang}&lang=${lang}&panel_size=small`
7637
}
7738
7839
init()

ui/src/views/login/scanCompinents/wecomQrCode.vue

Lines changed: 16 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,39 @@
11
<template>
2-
<div id="wecom-qr" class="wecom-qr flex"></div>
2+
<iframe :src="iframeUrl" width="100%" height="380px" frameborder="0"></iframe>
33
</template>
44

55
<script lang="ts" setup>
6-
import { useRouter } from 'vue-router'
7-
import * as ww from '@wecom/jssdk'
8-
import {
9-
WWLoginLangType,
10-
WWLoginPanelSizeType,
11-
WWLoginRedirectType,
12-
WWLoginType
13-
} from '@wecom/jssdk'
14-
import { ref, nextTick, defineProps } from 'vue'
15-
import { MsgError } from '@/utils/message'
16-
import useStore from '@/stores'
17-
import { getBrowserLang } from '@/locales'
18-
const router = useRouter()
19-
const { login } = useStore()
20-
const wwLogin = ref({})
21-
const obj = ref<any>({ isWeComLogin: false })
22-
6+
import {ref, nextTick, defineProps} from 'vue'
7+
import {getBrowserLang} from '@/locales'
238
249
const props = defineProps<{
2510
config: {
2611
app_secret: string
2712
app_key: string
2813
corp_id?: string
2914
agent_id?: string
15+
callback_url: string
3016
}
3117
}>()
3218
19+
const iframeUrl = ref('')
3320
const init = async () => {
3421
await nextTick() // 确保DOM已更新
3522
const data = {
3623
corpId: props.config.corp_id,
37-
agentId: props.config.agent_id
24+
agentId: props.config.agent_id,
25+
redirectUri: props.config.callback_url,
3826
}
39-
const lang = localStorage.getItem('MaxKB-locale') || getBrowserLang() || 'en-US'
40-
const redirectUri = window.location.origin
41-
console.log('redirectUri', redirectUri)
42-
try {
43-
wwLogin.value = ww.createWWLoginPanel({
44-
el: '#wecom-qr',
45-
params: {
46-
login_type: WWLoginType.corpApp,
47-
appid: data.corpId || '',
48-
agentid: data.agentId,
49-
redirect_uri: redirectUri,
50-
state: 'fit2cloud-wecom-qr',
51-
lang: lang === 'zh-CN' || lang === 'zh-Hant' ? WWLoginLangType.zh : WWLoginLangType.en,
52-
redirect_type: WWLoginRedirectType.callback,
53-
panel_size: WWLoginPanelSizeType.small
54-
},
55-
onCheckWeComLogin: obj.value,
56-
async onLoginSuccess({ code }: any) {
57-
login.wecomCallback(code).then(() => {
58-
setTimeout(() => {
59-
router.push({ name: 'home' })
60-
})
61-
})
62-
},
63-
onLoginFail(err) {
64-
MsgError(`${err.errMsg}`)
65-
}
66-
})
67-
} catch (error) {
27+
let lang = localStorage.getItem('MaxKB-locale') || getBrowserLang() || 'en-US'
28+
if (lang === 'en-US') {
29+
lang = 'en'
30+
} else {
31+
lang = 'zh'
6832
}
33+
const redirectUri = encodeURIComponent(data.redirectUri)
34+
console.log('redirectUri', data.redirectUri)
35+
// 手动构建生成二维码的url
36+
iframeUrl.value = `https://login.work.weixin.qq.com/wwlogin/sso/login?login_type=CorpApp&appid=${data.corpId}&agentid=${data.agentId}&redirect_uri=${redirectUri}&state=fit2cloud-wecom-qr&lang=${lang}&panel_size=small`
6937
}
7038
7139
init()

0 commit comments

Comments
 (0)