Skip to content

Commit 4ba5fa3

Browse files
committed
refactor: chat ui
1 parent 845ba07 commit 4ba5fa3

File tree

2 files changed

+124
-57
lines changed

2 files changed

+124
-57
lines changed

ui/src/api/chat/chat.ts

Lines changed: 97 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Result } from '@/request/Result'
1+
import {Result} from '@/request/Result'
22
import {
33
get,
44
post,
@@ -9,14 +9,16 @@ import {
99
download,
1010
exportFile,
1111
} from '@/request/chat/index'
12-
import { type ChatProfile } from '@/api/type/chat'
13-
import { type Ref } from 'vue'
12+
import {type ChatProfile} from '@/api/type/chat'
13+
import {type Ref} from 'vue'
1414

1515
import useStore from '@/stores'
16-
const prefix: any = { _value: '/workspace/' }
16+
import type {LoginRequest} from "@/api/type/user.ts";
17+
18+
const prefix: any = {_value: '/workspace/'}
1719
Object.defineProperty(prefix, 'value', {
1820
get: function () {
19-
const { user } = useStore()
21+
const {user} = useStore()
2022
return this._value + user.getWorkspaceId() + '/application'
2123
},
2224
})
@@ -29,7 +31,7 @@ Object.defineProperty(prefix, 'value', {
2931
*/
3032
const open: (loading?: Ref<boolean>) => Promise<Result<string>> = (loading) => {
3133
return get('/open', {}, loading)
32-
34+
3335
}
3436
/**
3537
* 对话
@@ -44,7 +46,7 @@ const chatProfile: (assessToken: string, loading?: Ref<boolean>) => Promise<Resu
4446
assessToken,
4547
loading,
4648
) => {
47-
return get('/profile', { access_token: assessToken }, loading)
49+
return get('/profile', {access_token: assessToken}, loading)
4850
}
4951
/**
5052
* 匿名认证
@@ -56,7 +58,7 @@ const anonymousAuthentication: (
5658
assessToken: string,
5759
loading?: Ref<boolean>,
5860
) => Promise<Result<any>> = (assessToken, loading) => {
59-
return post('/auth/anonymous', { access_token: assessToken }, {}, loading)
61+
return post('/auth/anonymous', {access_token: assessToken}, {}, loading)
6062
}
6163
/**
6264
* 获取应用相关信息
@@ -66,10 +68,97 @@ const anonymousAuthentication: (
6668
const applicationProfile: (loading?: Ref<boolean>) => Promise<Result<any>> = (loading) => {
6769
return get('/application/profile', {}, loading)
6870
}
71+
72+
73+
/**
74+
* 登录
75+
* @param request 登录接口请求表单
76+
* @param loading 接口加载器
77+
* @returns 认证数据
78+
*/
79+
const login: (accessToken: string, request: LoginRequest, loading?: Ref<boolean>) => Promise<Result<any>> = (
80+
accessToken: string,
81+
request,
82+
loading,
83+
) => {
84+
return post('/auth/login/' + accessToken, request, undefined, loading)
85+
}
86+
87+
const ldapLogin: (accessToken: string, request: LoginRequest, loading?: Ref<boolean>) => Promise<Result<any>> = (
88+
accessToken: string,
89+
request,
90+
loading,
91+
) => {
92+
return post('/auth/ldap/login/' + accessToken, request, undefined, loading)
93+
}
94+
95+
96+
/**
97+
* 获取验证码
98+
* @param loading 接口加载器
99+
*/
100+
const getCaptcha: (loading?: Ref<boolean>) => Promise<Result<any>> = (loading) => {
101+
return get('/user/captcha', undefined, loading)
102+
}
103+
104+
/**
105+
* 获取登录方式
106+
*/
107+
const getAuthType: (accessToken: string, loading?: Ref<boolean>) => Promise<Result<any>> = (accessToken, loading) => {
108+
return get('auth/auth/types/' + accessToken, undefined, loading)
109+
}
110+
111+
/**
112+
* 获取二维码类型
113+
*/
114+
const getQrType: (loading?: Ref<boolean>) => Promise<Result<any>> = (loading) => {
115+
return get('qr_type', undefined, loading)
116+
}
117+
118+
const getQrSource: (loading?: Ref<boolean>) => Promise<Result<any>> = (loading) => {
119+
return get('qr_type/source', undefined, loading)
120+
}
121+
122+
const getDingCallback: (code: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
123+
code,
124+
loading
125+
) => {
126+
return get('dingtalk', {code}, loading)
127+
}
128+
129+
const getDingOauth2Callback: (code: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
130+
code,
131+
loading
132+
) => {
133+
return get('dingtalk/oauth2', {code}, loading)
134+
}
135+
136+
const getWecomCallback: (code: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
137+
code,
138+
loading
139+
) => {
140+
return get('wecom', {code}, loading)
141+
}
142+
const getLarkCallback: (code: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
143+
code,
144+
loading
145+
) => {
146+
return get('lark/oauth2', {code}, loading)
147+
}
69148
export default {
70149
open,
71150
chat,
72151
chatProfile,
73152
anonymousAuthentication,
74153
applicationProfile,
154+
login,
155+
getCaptcha,
156+
getAuthType,
157+
getDingCallback,
158+
getQrType,
159+
getWecomCallback,
160+
getDingOauth2Callback,
161+
getLarkCallback,
162+
getQrSource,
163+
ldapLogin
75164
}

ui/src/views/chat/user-login/index.vue

Lines changed: 27 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ import {MsgConfirm, MsgError} from '@/utils/message.ts'
143143
// import {loadScript} from '@/utils/utils'
144144
145145
const router = useRouter()
146-
const {login, user, theme} = useStore()
146+
const {login, user, theme, chatUser} = useStore()
147147
const {locale} = useI18n({useScope: 'global'})
148148
const loading = ref<boolean>(false)
149149
const route = useRoute()
@@ -297,55 +297,33 @@ function changeMode(val: string) {
297297
}
298298
299299
onBeforeMount(() => {
300-
loading.value = true
301-
user.asyncGetProfile().then((res) => {
302-
if (user.isEnterprise()) {
303-
loginApi
304-
.getAuthType(accessToken)
305-
.then((res: any) => {
306-
res = res.data || {}
307-
const direct = res.needDirect
308-
res = res.authType || []
309-
if (direct) {
310-
redirectAuth(res[0], false)
311-
} else {
312-
313-
//如果结果包含LDAP,把LDAP放在第一个
314-
const ldapIndex = res.indexOf('LDAP')
315-
if (ldapIndex !== -1) {
316-
const [ldap] = res.splice(ldapIndex, 1)
317-
res.unshift(ldap)
318-
}
319-
modeList.value = [...modeList.value, ...res].filter((item => item !== ''))
320-
loginMode.value = modeList.value[0] || 'LOCAL'
321-
console.log(modeList.value)
322-
}
323-
})
324-
.finally(() => (loading.value = false))
325-
// user
326-
// .getQrType()
327-
// .then((res) => {
328-
// if (res.length > 0) {
329-
// modeList.value = ['QR_CODE', ...modeList.value]
330-
// QrList.value = res
331-
// QrList.value.forEach((item) => {
332-
// orgOptions.value.push({
333-
// key: item,
334-
// value:
335-
// item === 'wecom'
336-
// ? t('views.system.authentication.scanTheQRCode.wecom')
337-
// : item === 'dingtalk'
338-
// ? t('views.system.authentication.scanTheQRCode.dingtalk')
339-
// : t('views.system.authentication.scanTheQRCode.lark'),
340-
// })
341-
// })
342-
// }
343-
// })
344-
// .finally(() => (loading.value = false))
345-
} else {
346-
loading.value = false
300+
if (chatUser.chat_profile?.login_value) {
301+
modeList.value = chatUser.chat_profile.login_value
302+
loginMode.value = modeList.value[0] || 'LOCAL'
303+
if (modeList.value.length == 1 && ['CAS', 'OIDC', 'OAuth2'].includes(modeList.value[0])) {
304+
redirectAuth(modeList.value[0])
347305
}
348-
})
306+
}
307+
// user
308+
// .getQrType()
309+
// .then((res) => {
310+
// if (res.length > 0) {
311+
// modeList.value = ['QR_CODE', ...modeList.value]
312+
// QrList.value = res
313+
// QrList.value.forEach((item) => {
314+
// orgOptions.value.push({
315+
// key: item,
316+
// value:
317+
// item === 'wecom'
318+
// ? t('views.system.authentication.scanTheQRCode.wecom')
319+
// : item === 'dingtalk'
320+
// ? t('views.system.authentication.scanTheQRCode.dingtalk')
321+
// : t('views.system.authentication.scanTheQRCode.lark'),
322+
// })
323+
// })
324+
// }
325+
// })
326+
// .finally(() => (loading.value = false))
349327
})
350328
//declare const window: any
351329

0 commit comments

Comments
 (0)