|
36 | 36 | </div> |
37 | 37 | </el-form> |
38 | 38 |
|
39 | | - <el-button size="large" type="primary" class="w-full" @click="login">{{ |
40 | | - $t('views.login.buttons.login') |
41 | | - }}</el-button> |
| 39 | + <el-button size="large" type="primary" class="w-full" @click="login" |
| 40 | + >{{ $t('views.login.buttons.login') }} |
| 41 | + </el-button> |
42 | 42 | <div class="operate-container flex-between mt-12"> |
43 | 43 | <!-- <el-button class="register" @click="router.push('/register')" link type="primary"> |
44 | 44 | 注册 |
|
103 | 103 | <script setup lang="ts"> |
104 | 104 | import { onMounted, ref, onBeforeMount } from 'vue' |
105 | 105 | import type { LoginRequest } from '@/api/type/user' |
106 | | -import { useRouter } from 'vue-router' |
| 106 | +import { useRoute, useRouter } from 'vue-router' |
107 | 107 | import type { FormInstance, FormRules } from 'element-plus' |
108 | 108 | import useStore from '@/stores' |
109 | 109 | import authApi from '@/api/auth-setting' |
110 | | -import { MsgConfirm, MsgSuccess } from '@/utils/message' |
| 110 | +import { MsgConfirm, MsgError, MsgSuccess } from '@/utils/message' |
111 | 111 |
|
112 | 112 | import { t, getBrowserLang } from '@/locales' |
113 | 113 | import QrCodeTab from '@/views/login/components/QrCodeTab.vue' |
114 | 114 | import { useI18n } from 'vue-i18n' |
| 115 | +import * as dd from 'dingtalk-jsapi' |
| 116 | +import { loadScript } from '@/utils/utils' |
115 | 117 | const { locale } = useI18n({ useScope: 'global' }) |
116 | 118 | const loading = ref<boolean>(false) |
117 | 119 | const { user } = useStore() |
@@ -143,11 +145,14 @@ const modeList = ref<string[]>(['']) |
143 | 145 | const QrList = ref<any[]>(['']) |
144 | 146 | const loginMode = ref('') |
145 | 147 | const showQrCodeTab = ref(false) |
| 148 | +
|
146 | 149 | interface qrOption { |
147 | 150 | key: string |
148 | 151 | value: string |
149 | 152 | } |
| 153 | +
|
150 | 154 | const orgOptions = ref<qrOption[]>([]) |
| 155 | +
|
151 | 156 | function redirectAuth(authType: string) { |
152 | 157 | if (authType === 'LDAP' || authType === '') { |
153 | 158 | return |
@@ -266,6 +271,83 @@ onBeforeMount(() => { |
266 | 271 | } |
267 | 272 | }) |
268 | 273 | }) |
| 274 | +declare const window: any |
| 275 | +
|
| 276 | +onMounted(() => { |
| 277 | + const route = useRoute() |
| 278 | + const currentUrl = ref(route.fullPath) |
| 279 | + const params = new URLSearchParams(currentUrl.value.split('?')[1]) |
| 280 | + const client = params.get('client') |
| 281 | +
|
| 282 | + const handleDingTalk = () => { |
| 283 | + const code = params.get('corpId') |
| 284 | + if (code) { |
| 285 | + dd.runtime.permission.requestAuthCode({ corpId: code }).then((res) => { |
| 286 | + console.log('DingTalk client request success:', res) |
| 287 | + user.dingOauth2Callback(res.code).then(() => { |
| 288 | + router.push({ name: 'home' }) |
| 289 | + }) |
| 290 | + }) |
| 291 | + } |
| 292 | + } |
| 293 | +
|
| 294 | + const handleLark = () => { |
| 295 | + const appId = params.get('appId') |
| 296 | + const callRequestAuthCode = () => { |
| 297 | + window.tt?.requestAuthCode({ |
| 298 | + appId: appId, |
| 299 | + success: (res: any) => { |
| 300 | + user.larkCallback(res.code).then(() => { |
| 301 | + router.push({ name: 'home' }) |
| 302 | + }) |
| 303 | + }, |
| 304 | + fail: (error: any) => { |
| 305 | + MsgError(error) |
| 306 | + } |
| 307 | + }) |
| 308 | + } |
| 309 | +
|
| 310 | + loadScript('https://lf-scm-cn.feishucdn.com/lark/op/h5-js-sdk-1.5.35.js', { |
| 311 | + jsId: 'lark-sdk', |
| 312 | + forceReload: true |
| 313 | + }) |
| 314 | + .then(() => { |
| 315 | + if (window.tt) { |
| 316 | + window.tt.requestAccess({ |
| 317 | + appID: appId, |
| 318 | + scopeList: [], |
| 319 | + success: (res: any) => { |
| 320 | + user.larkCallback(res.code).then(() => { |
| 321 | + router.push({ name: 'home' }) |
| 322 | + }) |
| 323 | + }, |
| 324 | + fail: (error: any) => { |
| 325 | + const { errno } = error |
| 326 | + if (errno === 103) { |
| 327 | + callRequestAuthCode() |
| 328 | + } |
| 329 | + } |
| 330 | + }) |
| 331 | + } else { |
| 332 | + callRequestAuthCode() |
| 333 | + } |
| 334 | + }) |
| 335 | + .catch((error) => { |
| 336 | + console.error('SDK 加载失败:', error) |
| 337 | + }) |
| 338 | + } |
| 339 | +
|
| 340 | + switch (client) { |
| 341 | + case 'dingtalk': |
| 342 | + handleDingTalk() |
| 343 | + break |
| 344 | + case 'lark': |
| 345 | + handleLark() |
| 346 | + break |
| 347 | + default: |
| 348 | + break |
| 349 | + } |
| 350 | +}) |
269 | 351 | </script> |
270 | 352 | <style lang="scss" scope> |
271 | 353 | .login-gradient-divider { |
|
0 commit comments