refactor: chat ui
This commit is contained in:
parent
845ba0707e
commit
4ba5fa324a
@ -1,4 +1,4 @@
|
|||||||
import { Result } from '@/request/Result'
|
import {Result} from '@/request/Result'
|
||||||
import {
|
import {
|
||||||
get,
|
get,
|
||||||
post,
|
post,
|
||||||
@ -9,14 +9,16 @@ import {
|
|||||||
download,
|
download,
|
||||||
exportFile,
|
exportFile,
|
||||||
} from '@/request/chat/index'
|
} from '@/request/chat/index'
|
||||||
import { type ChatProfile } from '@/api/type/chat'
|
import {type ChatProfile} from '@/api/type/chat'
|
||||||
import { type Ref } from 'vue'
|
import {type Ref} from 'vue'
|
||||||
|
|
||||||
import useStore from '@/stores'
|
import useStore from '@/stores'
|
||||||
const prefix: any = { _value: '/workspace/' }
|
import type {LoginRequest} from "@/api/type/user.ts";
|
||||||
|
|
||||||
|
const prefix: any = {_value: '/workspace/'}
|
||||||
Object.defineProperty(prefix, 'value', {
|
Object.defineProperty(prefix, 'value', {
|
||||||
get: function () {
|
get: function () {
|
||||||
const { user } = useStore()
|
const {user} = useStore()
|
||||||
return this._value + user.getWorkspaceId() + '/application'
|
return this._value + user.getWorkspaceId() + '/application'
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -29,7 +31,7 @@ Object.defineProperty(prefix, 'value', {
|
|||||||
*/
|
*/
|
||||||
const open: (loading?: Ref<boolean>) => Promise<Result<string>> = (loading) => {
|
const open: (loading?: Ref<boolean>) => Promise<Result<string>> = (loading) => {
|
||||||
return get('/open', {}, loading)
|
return get('/open', {}, loading)
|
||||||
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 对话
|
* 对话
|
||||||
@ -44,7 +46,7 @@ const chatProfile: (assessToken: string, loading?: Ref<boolean>) => Promise<Resu
|
|||||||
assessToken,
|
assessToken,
|
||||||
loading,
|
loading,
|
||||||
) => {
|
) => {
|
||||||
return get('/profile', { access_token: assessToken }, loading)
|
return get('/profile', {access_token: assessToken}, loading)
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 匿名认证
|
* 匿名认证
|
||||||
@ -56,7 +58,7 @@ const anonymousAuthentication: (
|
|||||||
assessToken: string,
|
assessToken: string,
|
||||||
loading?: Ref<boolean>,
|
loading?: Ref<boolean>,
|
||||||
) => Promise<Result<any>> = (assessToken, loading) => {
|
) => Promise<Result<any>> = (assessToken, loading) => {
|
||||||
return post('/auth/anonymous', { access_token: assessToken }, {}, loading)
|
return post('/auth/anonymous', {access_token: assessToken}, {}, loading)
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 获取应用相关信息
|
* 获取应用相关信息
|
||||||
@ -66,10 +68,97 @@ const anonymousAuthentication: (
|
|||||||
const applicationProfile: (loading?: Ref<boolean>) => Promise<Result<any>> = (loading) => {
|
const applicationProfile: (loading?: Ref<boolean>) => Promise<Result<any>> = (loading) => {
|
||||||
return get('/application/profile', {}, 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 {
|
export default {
|
||||||
open,
|
open,
|
||||||
chat,
|
chat,
|
||||||
chatProfile,
|
chatProfile,
|
||||||
anonymousAuthentication,
|
anonymousAuthentication,
|
||||||
applicationProfile,
|
applicationProfile,
|
||||||
|
login,
|
||||||
|
getCaptcha,
|
||||||
|
getAuthType,
|
||||||
|
getDingCallback,
|
||||||
|
getQrType,
|
||||||
|
getWecomCallback,
|
||||||
|
getDingOauth2Callback,
|
||||||
|
getLarkCallback,
|
||||||
|
getQrSource,
|
||||||
|
ldapLogin
|
||||||
}
|
}
|
||||||
|
|||||||
@ -143,7 +143,7 @@ import {MsgConfirm, MsgError} from '@/utils/message.ts'
|
|||||||
// import {loadScript} from '@/utils/utils'
|
// import {loadScript} from '@/utils/utils'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const {login, user, theme} = useStore()
|
const {login, user, theme, chatUser} = useStore()
|
||||||
const {locale} = useI18n({useScope: 'global'})
|
const {locale} = useI18n({useScope: 'global'})
|
||||||
const loading = ref<boolean>(false)
|
const loading = ref<boolean>(false)
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
@ -297,55 +297,33 @@ function changeMode(val: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onBeforeMount(() => {
|
onBeforeMount(() => {
|
||||||
loading.value = true
|
if (chatUser.chat_profile?.login_value) {
|
||||||
user.asyncGetProfile().then((res) => {
|
modeList.value = chatUser.chat_profile.login_value
|
||||||
if (user.isEnterprise()) {
|
loginMode.value = modeList.value[0] || 'LOCAL'
|
||||||
loginApi
|
if (modeList.value.length == 1 && ['CAS', 'OIDC', 'OAuth2'].includes(modeList.value[0])) {
|
||||||
.getAuthType(accessToken)
|
redirectAuth(modeList.value[0])
|
||||||
.then((res: any) => {
|
|
||||||
res = res.data || {}
|
|
||||||
const direct = res.needDirect
|
|
||||||
res = res.authType || []
|
|
||||||
if (direct) {
|
|
||||||
redirectAuth(res[0], false)
|
|
||||||
} else {
|
|
||||||
|
|
||||||
//如果结果包含LDAP,把LDAP放在第一个
|
|
||||||
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 !== ''))
|
|
||||||
loginMode.value = modeList.value[0] || 'LOCAL'
|
|
||||||
console.log(modeList.value)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.finally(() => (loading.value = false))
|
|
||||||
// user
|
|
||||||
// .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
|
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
// user
|
||||||
|
// .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))
|
||||||
})
|
})
|
||||||
//declare const window: any
|
//declare const window: any
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user