Skip to content

Commit 4e3a843

Browse files
feat(X-Pack): Support Lark embedded
1 parent 3184b66 commit 4e3a843

File tree

6 files changed

+132
-33
lines changed

6 files changed

+132
-33
lines changed

frontend/src/views/login/xpack/Handler.vue

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,40 @@ const wecomLogin = () => {
449449
}, 1500)
450450
})
451451
}
452+
const larkLogin = () => {
453+
const urlParams = getUrlParams()
454+
urlParams['redirect_uri'] = encodeURIComponent(window.location.origin + window.location.pathname)
455+
request
456+
.post('/system/platform/sso/8', urlParams)
457+
.then((res: any) => {
458+
const token = res.access_token
459+
// const platform_info = res.platform_info
460+
if (token && isPlatformClient()) {
461+
wsCache.set('sqlbot-platform-client', true)
462+
}
463+
userStore.setToken(token)
464+
userStore.setExp(res.exp)
465+
userStore.setTime(Date.now())
466+
userStore.setPlatformInfo({
467+
flag: 'lark',
468+
// data: platform_info ? JSON.stringify(platform_info) : '',
469+
origin: 8,
470+
})
471+
const queryRedirectPath = getCurLocation()
472+
router.push({ path: queryRedirectPath })
473+
})
474+
.catch((e: any) => {
475+
userStore.setToken('')
476+
setTimeout(() => {
477+
// logoutHandler(true, true)
478+
platformLoginMsg.value = e?.message || e
479+
setTimeout(() => {
480+
window.location.href =
481+
window.location.origin + window.location.pathname + window.location.hash
482+
}, 2000)
483+
}, 1500)
484+
})
485+
}
452486
const dingtalkLogin = () => {
453487
const urlParams = getUrlParams()
454488
request
@@ -661,6 +695,8 @@ onMounted(() => {
661695
wecomLogin()
662696
} else if (state?.includes('dingtalk')) {
663697
dingtalkLogin()
698+
} else if (state?.includes('lark')) {
699+
larkLogin()
664700
} else {
665701
auto2Platform()
666702
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<template>
2+
<div id="de2-lark-qr" :class="{ 'de2-lark-qr': !isBind }" />
3+
</template>
4+
5+
<script lang="ts" setup>
6+
import { loadScript } from '@/utils/RemoteJs'
7+
import { propTypes } from '@/utils/propTypes'
8+
import { queryClientInfo } from './platformUtils'
9+
import { getSQLBotAddr } from '@/utils/utils'
10+
import { ref } from 'vue'
11+
interface LarkQrInfo {
12+
client_id?: string
13+
state?: string
14+
redirect_uri?: string
15+
}
16+
17+
const props = defineProps({
18+
isBind: propTypes.bool.def(false),
19+
})
20+
const origin = ref(8)
21+
const remoteJsUrl =
22+
'https://lf-package-cn.feishucdn.com/obj/feishu-static/lark/passport/qrcode/LarkSSOSDKWebQRCode-1.0.3.js'
23+
const jsId = 'de-lark-qr-id'
24+
const init = () => {
25+
loadScript(remoteJsUrl, jsId).then(() => {
26+
queryClientInfo(origin.value).then((res: any) => {
27+
const data = formatQrResult(res) as any
28+
loadQr(data.client_id, data.state, data.redirect_uri)
29+
})
30+
})
31+
}
32+
33+
const formatQrResult = (data: any): LarkQrInfo => {
34+
const result = { client_id: null, state: null, redirect_uri: null } as unknown as LarkQrInfo
35+
result.client_id = data.client_id
36+
result.state = 'fit2cloud-lark-qr'
37+
result.redirect_uri = data.redirect_uri || getSQLBotAddr()
38+
if (props.isBind) {
39+
result.state += '_de_bind'
40+
}
41+
return result
42+
}
43+
44+
const loadQr = (CLIENT_ID: string, STATE: string, REDIRECT_URI: string) => {
45+
let url = `https://passport.feishu.cn/suite/passport/oauth/authorize?client_id=${CLIENT_ID}&response_type=code&state=${STATE}&redirect_uri=${REDIRECT_URI}`
46+
// eslint-disable-next-line
47+
// @ts-ignore
48+
const QRLoginObj = window['QRLogin']({
49+
id: 'de2-lark-qr',
50+
goto: url,
51+
style: 'border:none;background-color:#FFFFFF;width: 266px;height: 266px;',
52+
})
53+
const handleMessage = function (event: any) {
54+
const origin = event.origin
55+
if (QRLoginObj.matchOrigin(origin)) {
56+
const loginTmpCode = event.data
57+
url += '&tmp_code=' + loginTmpCode.tmp_code
58+
window.location.href = url
59+
}
60+
}
61+
if (typeof window.addEventListener != 'undefined') {
62+
window.addEventListener('message', handleMessage, false)
63+
// eslint-disable-next-line
64+
// @ts-ignore
65+
} else if (typeof window['attachEvent'] != 'undefined') {
66+
// eslint-disable-next-line
67+
// @ts-ignore
68+
window['attachEvent']('onmessage', handleMessage)
69+
}
70+
}
71+
init()
72+
</script>
73+
<style lang="less" scoped>
74+
.de2-lark-qr {
75+
margin-top: -15px;
76+
}
77+
</style>

frontend/src/views/login/xpack/PlatformClient.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,14 @@ const larkClientRequest = async () => {
101101
return
102102
}
103103
const res = await queryClientInfo(8)
104-
if (!res?.appId) {
105-
ElMessage.error('get appId error')
104+
if (!res?.client_id) {
105+
ElMessage.error('get client_id error')
106106
return
107107
}
108-
const appId = res.data.appId
108+
const clientId = res.client_id
109109
const callRequestAuthCode = () => {
110110
window['tt'].requestAuthCode({
111-
appId: appId,
111+
appId: clientId,
112112
success: (res: any) => {
113113
const { code } = res
114114
const state = `fit2cloud-lark-client`
@@ -122,7 +122,7 @@ const larkClientRequest = async () => {
122122
}
123123
if (window['tt'].requestAccess) {
124124
window['tt'].requestAccess({
125-
appID: appId,
125+
appID: clientId,
126126
scopeList: [],
127127
success: (res: any) => {
128128
const { code } = res
@@ -149,15 +149,15 @@ const larksuiteClientRequest = async () => {
149149
return
150150
}
151151
const res = await queryClientInfo(9)
152-
if (!res?.data?.appId) {
153-
ElMessage.error('get appId error')
152+
if (!res?.client_id) {
153+
ElMessage.error('get client_id error')
154154
return
155155
}
156-
const appId = res.data.appId
156+
const clientId = res.client_id
157157

158158
window['h5sdk'].ready(() => {
159159
window['tt'].requestAuthCode({
160-
appId: appId,
160+
appId: clientId,
161161
success(res: any) {
162162
const code = res?.code || res
163163
const state = `fit2cloud-larksuite-client`

frontend/src/views/login/xpack/QrTab.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<el-icon>
3737
<Icon name="logo_lark"><logo_lark class="svg-icon" /></Icon>
3838
</el-icon>
39-
{{ t('threshold.lark') }}
39+
{{ t('user.lark') }}
4040
</div>
4141
<div class="qrcode">
4242
<lark-qr v-if="activeName === 'lark'" />
@@ -60,8 +60,8 @@ import logo_wechatWork from '@/assets/svg/logo_wechat-work.svg'
6060
import logo_dingtalk from '@/assets/svg/logo_dingtalk.svg'
6161
import logo_lark from '@/assets/svg/logo_lark.svg'
6262
import { ref } from 'vue'
63-
/* import LarkQr from './LarkQr.vue'
64-
import LarksuiteQr from './LarksuiteQr.vue' */
63+
import LarkQr from './LarkQr.vue'
64+
/* import LarksuiteQr from './LarksuiteQr.vue' */
6565
import DingtalkQr from './DingtalkQr.vue'
6666
import WecomQr from './WecomQr.vue'
6767
import { propTypes } from '@/utils/propTypes'

frontend/src/views/system/platform/common/SettingTemplate.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -70,49 +70,35 @@ export const settingMapping = {
7070
},
7171
],
7272
8: [
73-
{
74-
realKey: 'corpid',
75-
pkey: 'CorpId',
76-
pval: '',
77-
type: 'text',
78-
sort: 1,
79-
},
8073
{
8174
realKey: 'client_id',
8275
pkey: 'APP Key',
8376
pval: '',
8477
type: 'text',
85-
sort: 2,
78+
sort: 1,
8679
},
8780
{
8881
realKey: 'client_secret',
8982
pkey: 'APP Secret',
9083
pval: '',
9184
type: 'pwd',
92-
sort: 3,
85+
sort: 2,
9386
},
9487
],
9588
9: [
96-
{
97-
realKey: 'corpid',
98-
pkey: 'CorpId',
99-
pval: '',
100-
type: 'text',
101-
sort: 1,
102-
},
10389
{
10490
realKey: 'client_id',
10591
pkey: 'APP Key',
10692
pval: '',
10793
type: 'text',
108-
sort: 2,
94+
sort: 1,
10995
},
11096
{
11197
realKey: 'client_secret',
11298
pkey: 'APP Secret',
11399
pval: '',
114100
type: 'pwd',
115-
sort: 3,
101+
sort: 2,
116102
},
117103
],
118104
} as any
@@ -134,13 +120,13 @@ export const cardMapping = {
134120
title: 'user.lark',
135121
icon: logo_lark,
136122
settingList: settingMapping[8],
137-
copyField: ['CorpId', 'APP Secret'],
123+
copyField: ['APP Key', 'APP Secret'],
138124
},
139125
9: {
140126
title: 'user.larksuite',
141127
icon: logo_lark,
142128
settingList: settingMapping[9],
143-
copyField: ['CorpId', 'APP Secret'],
129+
copyField: ['APP Key', 'APP Secret'],
144130
},
145131
} as any
146132

frontend/src/views/system/platform/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const loadData = () => {
2929
item.config = JSON.parse(item.config)
3030
return item
3131
})
32-
.filter((card: any) => card.type < 8)
32+
.filter((card: any) => card.type < 9)
3333
})
3434
}
3535
onMounted(() => {

0 commit comments

Comments
 (0)