Skip to content

Commit 08cdfc6

Browse files
committed
feat: integrate WeCom SDK for QR code login functionality
1 parent e1da951 commit 08cdfc6

File tree

2 files changed

+54
-20
lines changed

2 files changed

+54
-20
lines changed

ui/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"@logicflow/extension": "^1.2.27",
2525
"@vavt/cm-extension": "^1.9.1",
2626
"@vueuse/core": "^13.3.0",
27+
"@wecom/jssdk": "^2.3.3",
2728
"axios": "^1.8.4",
2829
"cropperjs": "^1.6.2",
2930
"dingtalk-jsapi": "^3.1.0",

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

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,79 @@
11
<template>
2-
<iframe :src="iframeUrl" width="100%" height="380px" frameborder="0"
3-
style="margin-top: -30px"></iframe>
2+
<div id="wecom-qr" class="wecom-qr flex"></div>
43
</template>
54

65
<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'
714
import {ref, nextTick, defineProps} from 'vue'
15+
import {MsgError} from '@/utils/message'
16+
import useStore from '@/stores'
817
import {getBrowserLang} from '@/locales'
9-
import {useRoute} from "vue-router";
1018
19+
const router = useRouter()
1120
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+
1228
const props = defineProps<{
1329
config: {
30+
callback_url: string;
1431
app_secret: string
1532
app_key: string
1633
corp_id?: string
1734
agent_id?: string
18-
callback_url: string
1935
}
2036
}>()
2137
22-
const {
23-
params: {accessToken},
24-
} = route as any
25-
26-
const iframeUrl = ref('')
2738
const init = async () => {
2839
await nextTick() // 确保DOM已更新
2940
const data = {
3041
corpId: props.config.corp_id,
31-
agentId: props.config.agent_id,
32-
redirectUri: props.config.callback_url,
42+
agentId: props.config.agent_id
3343
}
34-
let lang = localStorage.getItem('MaxKB-locale') || getBrowserLang() || 'en-US'
35-
if (lang === 'en-US') {
36-
lang = 'en'
37-
} else {
38-
lang = 'zh'
44+
const lang = localStorage.getItem('MaxKB-locale') || getBrowserLang() || 'en-US'
45+
const redirectUri = props.config.callback_url
46+
try {
47+
wwLogin.value = ww.createWWLoginPanel({
48+
el: '#wecom-qr',
49+
params: {
50+
login_type: WWLoginType.corpApp,
51+
appid: data.corpId || '',
52+
agentid: data.agentId,
53+
redirect_uri: redirectUri,
54+
state: 'fit2cloud-wecom-qr',
55+
lang: lang === 'zh-CN' || lang === 'zh-Hant' ? WWLoginLangType.zh : WWLoginLangType.en,
56+
redirect_type: WWLoginRedirectType.callback,
57+
panel_size: WWLoginPanelSizeType.small
58+
},
59+
onCheckWeComLogin: obj.value,
60+
async onLoginSuccess({code}: any) {
61+
chatUser.wecomCallback(code, accessToken).then(() => {
62+
setTimeout(() => {
63+
router.push({
64+
name: 'chat',
65+
params: {accessToken: accessToken},
66+
query: route.query,
67+
})
68+
})
69+
})
70+
},
71+
onLoginFail(err) {
72+
MsgError(`${err.errMsg}`)
73+
}
74+
})
75+
} catch (error) {
3976
}
40-
const redirectUri = encodeURIComponent(data.redirectUri)
41-
console.log('redirectUri', data.redirectUri)
42-
// 手动构建生成二维码的url
43-
iframeUrl.value = `https://login.work.weixin.qq.com/wwlogin/sso/login?login_type=CorpApp&appid=${data.corpId}&agentid=${data.agentId}&redirect_uri=${redirectUri}&state=${accessToken}&lang=${lang}&lang=${lang}&panel_size=small`
4477
}
4578
4679
init()

0 commit comments

Comments
 (0)