refactor: clean up code formatting and improve readability in index.vue
parent
680502f366
commit
52f420df58
|
|
@ -317,224 +317,225 @@ onBeforeMount(() => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|
||||||
const modeList = ref<string[]>([''])
|
const modeList = ref<string[]>([''])
|
||||||
const QrList = ref<any[]>([''])
|
const QrList = ref<any[]>([''])
|
||||||
const loginMode = ref('')
|
const loginMode = ref('')
|
||||||
const showQrCodeTab = ref(false)
|
const showQrCodeTab = ref(false)
|
||||||
|
|
||||||
interface qrOption {
|
interface qrOption {
|
||||||
key: string
|
key: string
|
||||||
value: string
|
value: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const orgOptions = ref<qrOption[]>([])
|
const orgOptions = ref<qrOption[]>([])
|
||||||
|
|
||||||
function uuidv4() {
|
function uuidv4() {
|
||||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
||||||
const r = (Math.random() * 16) | 0
|
const r = (Math.random() * 16) | 0
|
||||||
const v = c === 'x' ? r : (r & 0x3) | 0x8
|
const v = c === 'x' ? r : (r & 0x3) | 0x8
|
||||||
return v.toString(16)
|
return v.toString(16)
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const newDefaultSlogan = computed(() => {
|
|
||||||
const default_login = '强大易用的企业级智能体平台'
|
|
||||||
if (!theme.themeInfo?.slogan || default_login == theme.themeInfo?.slogan) {
|
|
||||||
return t('theme.defaultSlogan')
|
|
||||||
} else {
|
|
||||||
return theme.themeInfo?.slogan
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function redirectAuth(authType: string, needMessage: boolean = true) {
|
const newDefaultSlogan = computed(() => {
|
||||||
if (authType === 'LDAP' || authType === '') {
|
const default_login = '强大易用的企业级智能体平台'
|
||||||
|
if (!theme.themeInfo?.slogan || default_login == theme.themeInfo?.slogan) {
|
||||||
|
return t('theme.defaultSlogan')
|
||||||
|
} else {
|
||||||
|
return theme.themeInfo?.slogan
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
function redirectAuth(authType: string, needMessage: boolean = true) {
|
||||||
|
if (authType === 'LDAP' || authType === '') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
authApi.getLoginViewAuthSetting(authType, loading).then((res: any) => {
|
||||||
|
if (!res.data || !res.data.config) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
authApi.getLoginViewAuthSetting(authType, loading).then((res: any) => {
|
|
||||||
if (!res.data || !res.data.config) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const config = res.data.config
|
const config = res.data.config
|
||||||
// 构造带查询参数的redirectUrl
|
// 构造带查询参数的redirectUrl
|
||||||
const redirectUrl = `${config.redirectUrl}`
|
const redirectUrl = `${config.redirectUrl}`
|
||||||
let url
|
let url
|
||||||
if (authType === 'CAS') {
|
if (authType === 'CAS') {
|
||||||
url = config.ldpUri
|
url = config.ldpUri
|
||||||
url +=
|
url +=
|
||||||
url.indexOf('?') !== -1
|
url.indexOf('?') !== -1
|
||||||
? `&service=${encodeURIComponent(redirectUrl)}`
|
? `&service=${encodeURIComponent(redirectUrl)}`
|
||||||
: `?service=${encodeURIComponent(redirectUrl)}`
|
: `?service=${encodeURIComponent(redirectUrl)}`
|
||||||
} else if (authType === 'OIDC') {
|
} else if (authType === 'OIDC') {
|
||||||
const scope = config.scope || 'openid+profile+email'
|
const scope = config.scope || 'openid+profile+email'
|
||||||
url = `${config.authEndpoint}?client_id=${config.clientId}&redirect_uri=${redirectUrl}&response_type=code&scope=${scope}`
|
url = `${config.authEndpoint}?client_id=${config.clientId}&redirect_uri=${redirectUrl}&response_type=code&scope=${scope}`
|
||||||
if (config.state) {
|
if (config.state) {
|
||||||
url += `&state=${config.state}`
|
url += `&state=${config.state}`
|
||||||
}
|
|
||||||
} else if (authType === 'OAuth2') {
|
|
||||||
url = `${config.authEndpoint}?client_id=${config.clientId}&response_type=code&redirect_uri=${redirectUrl}&state=${uuidv4()}`
|
|
||||||
if (config.scope) {
|
|
||||||
url += `&scope=${config.scope}`
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!url) {
|
} else if (authType === 'OAuth2') {
|
||||||
return
|
url = `${config.authEndpoint}?client_id=${config.clientId}&response_type=code&redirect_uri=${redirectUrl}&state=${uuidv4()}`
|
||||||
|
if (config.scope) {
|
||||||
|
url += `&scope=${config.scope}`
|
||||||
}
|
}
|
||||||
if (needMessage) {
|
}
|
||||||
MsgConfirm(t('views.login.jump_tip'), '', {
|
if (!url) {
|
||||||
confirmButtonText: t('views.login.jump'),
|
|
||||||
cancelButtonText: t('common.cancel'),
|
|
||||||
confirmButtonClass: '',
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
window.location.href = url
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
console.log('url', url)
|
|
||||||
window.location.href = url
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function changeMode(val: string, needMessage: boolean = true) {
|
|
||||||
loginMode.value = val === 'LDAP' ? val : ''
|
|
||||||
if (val === 'QR_CODE') {
|
|
||||||
loginMode.value = val
|
|
||||||
showQrCodeTab.value = true
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
showQrCodeTab.value = false
|
if (needMessage) {
|
||||||
loginForm.value = {
|
MsgConfirm(t('views.login.jump_tip'), '', {
|
||||||
username: '',
|
confirmButtonText: t('views.login.jump'),
|
||||||
password: '',
|
cancelButtonText: t('common.cancel'),
|
||||||
captcha: '',
|
confirmButtonClass: '',
|
||||||
}
|
|
||||||
redirectAuth(val, needMessage)
|
|
||||||
loginFormRef.value?.clearValidate()
|
|
||||||
}
|
|
||||||
|
|
||||||
onBeforeMount(() => {
|
|
||||||
loading.value = true
|
|
||||||
user.asyncGetProfile().then((res) => {
|
|
||||||
// 企业版和专业版:第三方登录
|
|
||||||
if (user.isPE() || user.isEE()) {
|
|
||||||
login
|
|
||||||
.getAuthType()
|
|
||||||
.then((res) => {
|
|
||||||
//如果结果包含LDAP,把LDAP放在第一个
|
|
||||||
const ldapIndex = res.indexOf('LDAP')
|
|
||||||
if (ldapIndex !== -1) {
|
|
||||||
const [ldap] = res.splice(ldapIndex, 1)
|
|
||||||
res.unshift(ldap)
|
|
||||||
}
|
|
||||||
modeList.value = [...modeList.value, ...res]
|
|
||||||
})
|
|
||||||
.finally(() => (loading.value = false))
|
|
||||||
login
|
|
||||||
.getQrType()
|
|
||||||
.then((res) => {
|
|
||||||
if (res.length > 0) {
|
|
||||||
modeList.value = ['QR_CODE', ...modeList.value]
|
|
||||||
QrList.value = res
|
|
||||||
QrList.value.forEach((item) => {
|
|
||||||
orgOptions.value.push({
|
|
||||||
key: item,
|
|
||||||
value:
|
|
||||||
item === 'wecom'
|
|
||||||
? t('views.system.authentication.scanTheQRCode.wecom')
|
|
||||||
: item === 'dingtalk'
|
|
||||||
? t('views.system.authentication.scanTheQRCode.dingtalk')
|
|
||||||
: t('views.system.authentication.scanTheQRCode.lark'),
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.finally(() => (loading.value = false))
|
|
||||||
} else {
|
|
||||||
loading.value = false
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
declare const window: any
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
const route = useRoute()
|
|
||||||
const currentUrl = ref(route.fullPath)
|
|
||||||
const params = new URLSearchParams(currentUrl.value.split('?')[1])
|
|
||||||
const client = params.get('client')
|
|
||||||
|
|
||||||
const handleDingTalk = () => {
|
|
||||||
const code = params.get('corpId')
|
|
||||||
if (code) {
|
|
||||||
dd.runtime.permission.requestAuthCode({corpId: code}).then((res) => {
|
|
||||||
console.log('DingTalk client request success:', res)
|
|
||||||
login.dingOauth2Callback(res.code).then(() => {
|
|
||||||
router.push({name: 'home'})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleLark = () => {
|
|
||||||
const appId = params.get('appId')
|
|
||||||
const callRequestAuthCode = () => {
|
|
||||||
window.tt?.requestAuthCode({
|
|
||||||
appId: appId,
|
|
||||||
success: (res: any) => {
|
|
||||||
login.larkCallback(res.code).then(() => {
|
|
||||||
router.push({name: 'home'})
|
|
||||||
})
|
|
||||||
},
|
|
||||||
fail: (error: any) => {
|
|
||||||
MsgError(error)
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
loadScript('https://lf-scm-cn.feishucdn.com/lark/op/h5-js-sdk-1.5.35.js', {
|
|
||||||
jsId: 'lark-sdk',
|
|
||||||
forceReload: true,
|
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (window.tt) {
|
window.location.href = url
|
||||||
window.tt.requestAccess({
|
|
||||||
appID: appId,
|
|
||||||
scopeList: [],
|
|
||||||
success: (res: any) => {
|
|
||||||
login.larkCallback(res.code).then(() => {
|
|
||||||
router.push({name: 'home'})
|
|
||||||
})
|
|
||||||
},
|
|
||||||
fail: (error: any) => {
|
|
||||||
const {errno} = error
|
|
||||||
if (errno === 103) {
|
|
||||||
callRequestAuthCode()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
callRequestAuthCode()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch(() => {
|
||||||
console.error('SDK 加载失败:', error)
|
|
||||||
})
|
})
|
||||||
}
|
} else {
|
||||||
|
console.log('url', url)
|
||||||
switch (client) {
|
window.location.href = url
|
||||||
case 'dingtalk':
|
|
||||||
handleDingTalk()
|
|
||||||
break
|
|
||||||
case 'lark':
|
|
||||||
handleLark()
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function changeMode(val: string, needMessage: boolean = true) {
|
||||||
|
loginMode.value = val === 'LDAP' ? val : ''
|
||||||
|
if (val === 'QR_CODE') {
|
||||||
|
loginMode.value = val
|
||||||
|
showQrCodeTab.value = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
showQrCodeTab.value = false
|
||||||
|
loginForm.value = {
|
||||||
|
username: '',
|
||||||
|
password: '',
|
||||||
|
captcha: '',
|
||||||
|
}
|
||||||
|
redirectAuth(val, needMessage)
|
||||||
|
loginFormRef.value?.clearValidate()
|
||||||
|
}
|
||||||
|
|
||||||
|
onBeforeMount(() => {
|
||||||
|
loading.value = true
|
||||||
|
user.asyncGetProfile().then((res) => {
|
||||||
|
// 企业版和专业版:第三方登录
|
||||||
|
if (user.isPE() || user.isEE()) {
|
||||||
|
login
|
||||||
|
.getAuthType()
|
||||||
|
.then((res) => {
|
||||||
|
//如果结果包含LDAP,把LDAP放在第一个
|
||||||
|
const ldapIndex = res.indexOf('LDAP')
|
||||||
|
if (ldapIndex !== -1) {
|
||||||
|
const [ldap] = res.splice(ldapIndex, 1)
|
||||||
|
res.unshift(ldap)
|
||||||
|
}
|
||||||
|
modeList.value = [...modeList.value, ...res]
|
||||||
|
})
|
||||||
|
.finally(() => (loading.value = false))
|
||||||
|
login
|
||||||
|
.getQrType()
|
||||||
|
.then((res) => {
|
||||||
|
if (res.length > 0) {
|
||||||
|
modeList.value = ['QR_CODE', ...modeList.value]
|
||||||
|
QrList.value = res
|
||||||
|
QrList.value.forEach((item) => {
|
||||||
|
orgOptions.value.push({
|
||||||
|
key: item,
|
||||||
|
value:
|
||||||
|
item === 'wecom'
|
||||||
|
? t('views.system.authentication.scanTheQRCode.wecom')
|
||||||
|
: item === 'dingtalk'
|
||||||
|
? t('views.system.authentication.scanTheQRCode.dingtalk')
|
||||||
|
: t('views.system.authentication.scanTheQRCode.lark'),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.finally(() => (loading.value = false))
|
||||||
|
} else {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
declare const window: any
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
const route = useRoute()
|
||||||
|
const currentUrl = ref(route.fullPath)
|
||||||
|
const params = new URLSearchParams(currentUrl.value.split('?')[1])
|
||||||
|
const client = params.get('client')
|
||||||
|
|
||||||
|
const handleDingTalk = () => {
|
||||||
|
const code = params.get('corpId')
|
||||||
|
if (code) {
|
||||||
|
dd.runtime.permission.requestAuthCode({corpId: code}).then((res) => {
|
||||||
|
console.log('DingTalk client request success:', res)
|
||||||
|
login.dingOauth2Callback(res.code).then(() => {
|
||||||
|
router.push({name: 'home'})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleLark = () => {
|
||||||
|
const appId = params.get('appId')
|
||||||
|
const callRequestAuthCode = () => {
|
||||||
|
window.tt?.requestAuthCode({
|
||||||
|
appId: appId,
|
||||||
|
success: (res: any) => {
|
||||||
|
login.larkCallback(res.code).then(() => {
|
||||||
|
router.push({name: 'home'})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
fail: (error: any) => {
|
||||||
|
MsgError(error)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
loadScript('https://lf-scm-cn.feishucdn.com/lark/op/h5-js-sdk-1.5.35.js', {
|
||||||
|
jsId: 'lark-sdk',
|
||||||
|
forceReload: true,
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
if (window.tt) {
|
||||||
|
window.tt.requestAccess({
|
||||||
|
appID: appId,
|
||||||
|
scopeList: [],
|
||||||
|
success: (res: any) => {
|
||||||
|
login.larkCallback(res.code).then(() => {
|
||||||
|
router.push({name: 'home'})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
fail: (error: any) => {
|
||||||
|
const {errno} = error
|
||||||
|
if (errno === 103) {
|
||||||
|
callRequestAuthCode()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
callRequestAuthCode()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error('SDK 加载失败:', error)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (client) {
|
||||||
|
case 'dingtalk':
|
||||||
|
handleDingTalk()
|
||||||
|
break
|
||||||
|
case 'lark':
|
||||||
|
handleLark()
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.login-gradient-divider {
|
.login-gradient-divider {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue