refactor: chat ui

This commit is contained in:
wxg0103 2025-06-17 16:18:41 +08:00
parent 845ba0707e
commit 4ba5fa324a
2 changed files with 124 additions and 57 deletions

View File

@ -13,6 +13,8 @@ import { type ChatProfile } from '@/api/type/chat'
import {type Ref} from 'vue'
import useStore from '@/stores'
import type {LoginRequest} from "@/api/type/user.ts";
const prefix: any = {_value: '/workspace/'}
Object.defineProperty(prefix, 'value', {
get: function () {
@ -66,10 +68,97 @@ const anonymousAuthentication: (
const applicationProfile: (loading?: Ref<boolean>) => Promise<Result<any>> = (loading) => {
return get('/application/profile', {}, loading)
}
/**
*
* @param request
* @param loading
* @returns
*/
const login: (accessToken: string, request: LoginRequest, loading?: Ref<boolean>) => Promise<Result<any>> = (
accessToken: string,
request,
loading,
) => {
return post('/auth/login/' + accessToken, request, undefined, loading)
}
const ldapLogin: (accessToken: string, request: LoginRequest, loading?: Ref<boolean>) => Promise<Result<any>> = (
accessToken: string,
request,
loading,
) => {
return post('/auth/ldap/login/' + accessToken, request, undefined, loading)
}
/**
*
* @param loading
*/
const getCaptcha: (loading?: Ref<boolean>) => Promise<Result<any>> = (loading) => {
return get('/user/captcha', undefined, loading)
}
/**
*
*/
const getAuthType: (accessToken: string, loading?: Ref<boolean>) => Promise<Result<any>> = (accessToken, loading) => {
return get('auth/auth/types/' + accessToken, undefined, loading)
}
/**
*
*/
const getQrType: (loading?: Ref<boolean>) => Promise<Result<any>> = (loading) => {
return get('qr_type', undefined, loading)
}
const getQrSource: (loading?: Ref<boolean>) => Promise<Result<any>> = (loading) => {
return get('qr_type/source', undefined, loading)
}
const getDingCallback: (code: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
code,
loading
) => {
return get('dingtalk', {code}, loading)
}
const getDingOauth2Callback: (code: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
code,
loading
) => {
return get('dingtalk/oauth2', {code}, loading)
}
const getWecomCallback: (code: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
code,
loading
) => {
return get('wecom', {code}, loading)
}
const getLarkCallback: (code: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
code,
loading
) => {
return get('lark/oauth2', {code}, loading)
}
export default {
open,
chat,
chatProfile,
anonymousAuthentication,
applicationProfile,
login,
getCaptcha,
getAuthType,
getDingCallback,
getQrType,
getWecomCallback,
getDingOauth2Callback,
getLarkCallback,
getQrSource,
ldapLogin
}

View File

@ -143,7 +143,7 @@ import {MsgConfirm, MsgError} from '@/utils/message.ts'
// import {loadScript} from '@/utils/utils'
const router = useRouter()
const {login, user, theme} = useStore()
const {login, user, theme, chatUser} = useStore()
const {locale} = useI18n({useScope: 'global'})
const loading = ref<boolean>(false)
const route = useRoute()
@ -297,31 +297,13 @@ function changeMode(val: string) {
}
onBeforeMount(() => {
loading.value = true
user.asyncGetProfile().then((res) => {
if (user.isEnterprise()) {
loginApi
.getAuthType(accessToken)
.then((res: any) => {
res = res.data || {}
const direct = res.needDirect
res = res.authType || []
if (direct) {
redirectAuth(res[0], false)
} else {
//LDAPLDAP
const ldapIndex = res.indexOf('LDAP')
if (ldapIndex !== -1) {
const [ldap] = res.splice(ldapIndex, 1)
res.unshift(ldap)
}
modeList.value = [...modeList.value, ...res].filter((item => item !== ''))
if (chatUser.chat_profile?.login_value) {
modeList.value = chatUser.chat_profile.login_value
loginMode.value = modeList.value[0] || 'LOCAL'
console.log(modeList.value)
if (modeList.value.length == 1 && ['CAS', 'OIDC', 'OAuth2'].includes(modeList.value[0])) {
redirectAuth(modeList.value[0])
}
}
})
.finally(() => (loading.value = false))
// user
// .getQrType()
// .then((res) => {
@ -342,10 +324,6 @@ onBeforeMount(() => {
// }
// })
// .finally(() => (loading.value = false))
} else {
loading.value = false
}
})
})
//declare const window: any