8080 </div >
8181 </div >
8282 <div v-if =" showQrCodeTab" >
83- <QrCodeTab :tabs =" orgOptions " :default-tab =" defaultQrTab " />
83+ <QrCodeTab :tabs =" orgOptions " :default-tab =" defaultQrTab " />
8484 </div >
8585 <div class =" login-gradient-divider lighter mt-24" v-if =" modeList.length > 1" >
8686 <span >{{ $t('views.login.moreMethod') }}</span >
9999 'font-size': item === 'OAUTH2' ? '8px' : '10px',
100100 color: theme.themeInfo?.theme,
101101 }"
102- >{{ item }}</span
102+ >{{ item }}</span
103103 >
104104 </el-button >
105105 <el-button
109109 class =" login-button-circle color-secondary"
110110 @click =" changeMode('QR_CODE')"
111111 >
112- <img src =" @/assets/icon_qr_outlined.svg" width =" 25px" />
112+ <img src =" @/assets/icon_qr_outlined.svg" width =" 25px" />
113113 </el-button >
114114 <el-button
115115 v-if =" item === '' && loginMode !== ''"
126126 </login-layout >
127127</template >
128128<script setup lang="ts">
129- import {computed , onBeforeMount , onMounted , ref } from ' vue'
130- import {useRoute , useRouter } from ' vue-router'
131- import type {FormInstance , FormRules } from ' element-plus'
132- import type {LoginRequest } from ' @/api/type/login'
129+ import { computed , onBeforeMount , onMounted , ref } from ' vue'
130+ import { useRoute , useRouter } from ' vue-router'
131+ import type { FormInstance , FormRules } from ' element-plus'
132+ import type { LoginRequest } from ' @/api/type/login'
133133import LoginContainer from ' @/layout/login-layout/LoginContainer.vue'
134134import LoginLayout from ' @/layout/login-layout/LoginLayout.vue'
135135import loginApi from ' @/api/user/login'
136136import authApi from ' @/api/system-settings/auth-setting'
137- import {getBrowserLang , t } from ' @/locales'
137+ import { getBrowserLang , t } from ' @/locales'
138138import useStore from ' @/stores'
139- import {useI18n } from ' vue-i18n'
139+ import { useI18n } from ' vue-i18n'
140140import QrCodeTab from ' @/views/login/scanCompinents/QrCodeTab.vue'
141- import {MsgConfirm , MsgError } from ' @/utils/message.ts'
141+ import { MsgConfirm , MsgError } from ' @/utils/message.ts'
142142import * as dd from ' dingtalk-jsapi'
143- import {loadScript } from ' @/utils/common'
144- import JSEncrypt from ' jsencrypt' ;
143+ import { loadScript } from ' @/utils/common'
144+ import JSEncrypt from ' jsencrypt'
145145
146146const router = useRouter ()
147- const {login, user, theme} = useStore ()
148- const {locale} = useI18n ({useScope: ' global' })
147+ const { login, user, theme } = useStore ()
148+ const { locale } = useI18n ({ useScope: ' global' })
149149const loading = ref <boolean >(false )
150150const route = useRoute ()
151151const identifyCode = ref <string >(' ' )
@@ -194,25 +194,25 @@ const loginHandle = () => {
194194 .asyncLdapLogin (loginForm .value )
195195 .then (() => {
196196 locale .value = localStorage .getItem (' MaxKB-locale' ) || getBrowserLang () || ' en-US'
197- router .push ({name: ' home' })
197+ router .push ({ name: ' home' })
198198 })
199199 .catch (() => {
200200 loading .value = false
201201 })
202202 } else {
203203 // JSEncrypt 在有些打包环境可能作为 default export 或直接导出,兼容两种情况
204- const JSEncryptCtor = (JSEncrypt as any )?.default ? (JSEncrypt as any ).default : JSEncrypt ;
205- const js = new (JSEncryptCtor as any )();
206- js .setPublicKey (user .rsaKey );
207- const jsonData = JSON .stringify (loginForm .value );
208- const encryptedBase64 = js .encrypt (jsonData );
204+ const JSEncryptCtor = (JSEncrypt as any )?.default ? (JSEncrypt as any ).default : JSEncrypt
205+ const js = new (JSEncryptCtor as any )()
206+ js .setPublicKey (user .rsaKey )
207+ const jsonData = JSON .stringify (loginForm .value )
208+ const encryptedBase64 = js .encrypt (jsonData )
209209
210210 login
211- .asyncLogin ({encryptedData: encryptedBase64 , username: loginForm .value .username })
211+ .asyncLogin ({ encryptedData: encryptedBase64 , username: loginForm .value .username })
212212 .then (() => {
213213 locale .value = localStorage .getItem (' MaxKB-locale' ) || getBrowserLang () || ' en-US'
214214 localStorage .setItem (' workspace_id' , ' default' )
215- router .push ({name: ' home' })
215+ router .push ({ name: ' home' })
216216 })
217217 .catch (() => {
218218 const username = loginForm .value .username
@@ -225,26 +225,30 @@ const loginHandle = () => {
225225}
226226
227227function makeCode(username ? : string ) {
228- loginApi .getCaptcha (username ).then ((res : any ) => {
229- if (res && res .data && res .data .captcha ) {
230- identifyCode .value = res .data .captcha
231- }
232- }).catch ((error ) => {
233- console .error (' Failed to get captcha:' , error )
234- })
228+ loginApi
229+ .getCaptcha (username )
230+ .then ((res : any ) => {
231+ if (res && res .data && res .data .captcha ) {
232+ identifyCode .value = res .data .captcha
233+ }
234+ })
235+ .catch ((error ) => {
236+ console .error (' Failed to get captcha:' , error )
237+ })
235238}
236239
237240function handleUsernameBlur(username : string ) {
238241 makeCode (username )
239242}
240243
241244onBeforeMount (() => {
245+ loading .value = true
242246 user .asyncGetProfile ().then ((res ) => {
243247 // 企业版和专业版:第三方登录
244248 if (user .isPE () || user .isEE ()) {
245249 authApi .getLoginAuthSetting ().then ((res ) => {
246250 if (Object .keys (res .data ).length > 0 ) {
247- authSetting .value = res .data ;
251+ authSetting .value = res .data
248252 } else {
249253 authSetting .value = {
250254 max_attempts: 1 ,
@@ -264,7 +268,10 @@ onBeforeMount(() => {
264268 if (! modeList .value .includes (' LOCAL' ) && ! modeList .value .includes (' LDAP' )) {
265269 loginMode .value = ' '
266270 }
267- if (modeList .value .length == 1 && [' CAS' , ' OIDC' , ' OAuth2' , ' SAML2' ].includes (modeList .value [0 ])) {
271+ if (
272+ modeList .value .length == 1 &&
273+ [' CAS' , ' OIDC' , ' OAuth2' , ' SAML2' ].includes (modeList .value [0 ])
274+ ) {
268275 redirectAuth (modeList .value [0 ])
269276 }
270277 // 这里的modeList 是oauth2 cas ldap oidc 这四个 还会有 lark wecom dingtalk
@@ -273,7 +280,9 @@ onBeforeMount(() => {
273280 (item ) => ! [' CAS' , ' OIDC' , ' OAuth2' , ' LOCAL' , ' LDAP' , ' SAML2' ].includes (item ),
274281 )
275282 // modeList需要去掉lark wecom dingtalk
276- modeList .value = modeList .value .filter ((item ) => ! [' lark' , ' wecom' , ' dingtalk' ].includes (item ))
283+ modeList .value = modeList .value .filter (
284+ (item ) => ! [' lark' , ' wecom' , ' dingtalk' ].includes (item ),
285+ )
277286 if (QrList .value .length > 0 ) {
278287 QrList .value .forEach ((item ) => {
279288 orgOptions .value .push ({
@@ -307,6 +316,7 @@ onBeforeMount(() => {
307316 default_value: ' LOCAL' ,
308317 }
309318 }
319+ loading .value = false
310320 })
311321})
312322
@@ -386,8 +396,7 @@ function redirectAuth(authType: string, needMessage: boolean = true) {
386396 .then (() => {
387397 window .location .href = url
388398 })
389- .catch (() => {
390- })
399+ .catch (() => {})
391400 } else {
392401 console .log (' url' , url )
393402 window .location .href = url
@@ -465,10 +474,10 @@ onMounted(() => {
465474 const handleDingTalk = () => {
466475 const code = params .get (' corpId' )
467476 if (code ) {
468- dd .runtime .permission .requestAuthCode ({corpId: code }).then ((res ) => {
477+ dd .runtime .permission .requestAuthCode ({ corpId: code }).then ((res ) => {
469478 console .log (' DingTalk client request success:' , res )
470479 login .dingOauth2Callback (res .code ).then (() => {
471- router .push ({name: ' home' })
480+ router .push ({ name: ' home' })
472481 })
473482 })
474483 }
@@ -481,7 +490,7 @@ onMounted(() => {
481490 appId: appId ,
482491 success : (res : any ) => {
483492 login .larkCallback (res .code ).then (() => {
484- router .push ({name: ' home' })
493+ router .push ({ name: ' home' })
485494 })
486495 },
487496 fail : (error : any ) => {
@@ -501,11 +510,11 @@ onMounted(() => {
501510 scopeList: [],
502511 success : (res : any ) => {
503512 login .larkCallback (res .code ).then (() => {
504- router .push ({name: ' home' })
513+ router .push ({ name: ' home' })
505514 })
506515 },
507516 fail : (error : any ) => {
508- const {errno} = error
517+ const { errno } = error
509518 if (errno === 103 ) {
510519 callRequestAuthCode ()
511520 }
0 commit comments