Skip to content

Commit f744e8b

Browse files
committed
feat: add platform authentication methods and improve QR code handling
1 parent 0eb1cf7 commit f744e8b

File tree

14 files changed

+231
-100
lines changed

14 files changed

+231
-100
lines changed

ui/src/api/chat-user/auth-setting.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,30 @@ const putAuthSetting: (auth_type: string, data: any, loading?: Ref<boolean>) =>
3131
return put(`${prefix}/${auth_type}/info`, data, undefined, loading)
3232
}
3333

34+
const platformPrefix = '/chat_user/auth/platform'
35+
const getPlatformInfo: (loading?: Ref<boolean>) => Promise<Result<any>> = (loading) => {
36+
return get(`${platformPrefix}/source`, undefined, loading)
37+
}
38+
39+
const updateConfig: (data: any, loading?: Ref<boolean>) => Promise<Result<any>> = (
40+
data,
41+
loading
42+
) => {
43+
return post(`${platformPrefix}/source`, data, undefined, loading)
44+
}
45+
46+
const validateConnection: (data: any, loading?: Ref<boolean>) => Promise<Result<any>> = (
47+
data,
48+
loading
49+
) => {
50+
return put(`${platformPrefix}/source`, data, undefined, loading)
51+
}
52+
3453
export default {
3554
getAuthSetting,
3655
postAuthSetting,
37-
putAuthSetting
56+
putAuthSetting,
57+
getPlatformInfo,
58+
updateConfig,
59+
validateConnection
3860
}

ui/src/api/chat/chat.ts

Lines changed: 25 additions & 23 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,17 +9,17 @@ import {
99
download,
1010
exportFile,
1111
} from '@/request/chat/index'
12-
import { type ChatProfile } from '@/api/type/chat'
13-
import { type Ref } from 'vue'
14-
import type { ResetPasswordRequest } from '@/api/type/user.ts'
12+
import {type ChatProfile} from '@/api/type/chat'
13+
import {type Ref} from 'vue'
14+
import type {ResetPasswordRequest} from '@/api/type/user.ts'
1515

1616
import useStore from '@/stores'
17-
import type { LoginRequest } from '@/api/type/user'
17+
import type {LoginRequest} from '@/api/type/user'
1818

19-
const prefix: any = { _value: '/workspace/' }
19+
const prefix: any = {_value: '/workspace/'}
2020
Object.defineProperty(prefix, 'value', {
2121
get: function () {
22-
const { user } = useStore()
22+
const {user} = useStore()
2323
return this._value + user.getWorkspaceId() + '/application'
2424
},
2525
})
@@ -51,7 +51,7 @@ const chatProfile: (assessToken: string, loading?: Ref<boolean>) => Promise<Resu
5151
assessToken,
5252
loading,
5353
) => {
54-
return get('/profile', { access_token: assessToken }, loading)
54+
return get('/profile', {access_token: assessToken}, loading)
5555
}
5656
/**
5757
* 匿名认证
@@ -63,7 +63,7 @@ const anonymousAuthentication: (
6363
assessToken: string,
6464
loading?: Ref<boolean>,
6565
) => Promise<Result<any>> = (assessToken, loading) => {
66-
return post('/auth/anonymous', { access_token: assessToken }, {}, loading)
66+
return post('/auth/anonymous', {access_token: assessToken}, {}, loading)
6767
}
6868
/**
6969
* 密码认证
@@ -77,7 +77,7 @@ const passwordAuthentication: (
7777
password: string,
7878
loading?: Ref<boolean>,
7979
) => Promise<Result<any>> = (assessToken, password, loading) => {
80-
return post('auth/password', { access_token: assessToken, password: password }, {}, loading)
80+
return post('auth/password', {access_token: assessToken, password: password}, {}, loading)
8181
}
8282
/**
8383
* 获取应用相关信息
@@ -122,38 +122,40 @@ const getCaptcha: (loading?: Ref<boolean>) => Promise<Result<any>> = (loading) =
122122
* 获取二维码类型
123123
*/
124124
const getQrType: (loading?: Ref<boolean>) => Promise<Result<any>> = (loading) => {
125-
return get('qr_type', undefined, loading)
125+
return get('auth/qr_type', undefined, loading)
126126
}
127127

128128
const getQrSource: (loading?: Ref<boolean>) => Promise<Result<any>> = (loading) => {
129-
return get('qr_type/source', undefined, loading)
129+
return get('auth/qr_type/source', undefined, loading)
130130
}
131131

132-
const getDingCallback: (code: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
132+
const getDingCallback: (code: string, accessToken: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
133133
code,
134+
accessToken,
134135
loading,
135136
) => {
136-
return get('dingtalk', { code }, loading)
137+
return get('auth/dingtalk', {code, accessToken: accessToken}, loading)
137138
}
138139

139140
const getDingOauth2Callback: (code: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
140141
code,
141142
loading,
142143
) => {
143-
return get('dingtalk/oauth2', { code }, loading)
144+
return get('auth/dingtalk/oauth2', {code}, loading)
144145
}
145146

146-
const getWecomCallback: (code: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
147+
const getWecomCallback: (code: string, accessToken: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
147148
code,
149+
accessToken,
148150
loading,
149151
) => {
150-
return get('wecom', { code }, loading)
152+
return get('auth/wecom', {code, accessToken: accessToken}, loading)
151153
}
152154
const getLarkCallback: (code: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
153155
code,
154156
loading,
155157
) => {
156-
return get('lark/oauth2', { code }, loading)
158+
return get('auth/lark/oauth2', {code}, loading)
157159
}
158160

159161
/**
@@ -274,17 +276,17 @@ const deleteChat: (chat_id: string, loading?: Ref<boolean>) => Promise<Result<an
274276
chat_id,
275277
loading,
276278
) => {
277-
return del(`historical_conversation/${chat_id}`,undefined,undefined ,loading)
279+
return del(`historical_conversation/${chat_id}`, undefined, undefined, loading)
278280
}
279281
/**
280-
*
281-
* @param loading
282-
* @returns
282+
*
283+
* @param loading
284+
* @returns
283285
*/
284286
const clearChat: (loading?: Ref<boolean>) => Promise<Result<any>> = (
285287
loading
286288
) => {
287-
return del(`historical_conversation/clear`,undefined,undefined, loading)
289+
return del(`historical_conversation/clear`, undefined, undefined, loading)
288290
}
289291
/**
290292
*

ui/src/api/system/chat-user.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ const batchSync: (sync_type: string, loading?: Ref<boolean>) => Promise<Result<a
103103
) => {
104104
return post(`${prefix}/sync/${sync_type}`, undefined, undefined, loading)
105105
}
106+
107+
/**
108+
* 获取同步类型
109+
*/
110+
const getSyncType: (loading?: Ref<boolean>) => Promise<Result<any>> = (loading) => {
111+
return get(`${prefix}/sync_types`, undefined, loading)
112+
}
113+
106114
export default {
107115
getUserManage,
108116
putUserManage,
@@ -112,5 +120,6 @@ export default {
112120
getChatUserList,
113121
batchAddGroup,
114122
batchDelete,
115-
batchSync
123+
batchSync,
124+
getSyncType
116125
}

ui/src/stores/modules/chat-user.ts

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1-
import { defineStore } from 'pinia'
1+
import {defineStore} from 'pinia'
22
import ChatAPI from '@/api/chat/chat'
3-
import type { ChatProfile, ChatUserProfile } from '@/api/type/chat'
4-
import type { LoginRequest } from '@/api/type/user'
5-
import type { Ref } from 'vue'
6-
import { getBrowserLang } from '@/locales/index'
3+
import type {ChatProfile, ChatUserProfile} from '@/api/type/chat'
4+
import type {LoginRequest} from '@/api/type/user'
5+
import type {Ref} from 'vue'
6+
import {getBrowserLang} from '@/locales/index'
7+
import LoginApi from "@/api/user/login.ts";
8+
import useUserStore from "@/stores/modules/user.ts";
79

810
interface ChatUser {
911
// 用户id
1012
id: string
1113
}
14+
1215
interface Chat {
1316
chat_profile?: ChatProfile
1417
application?: any
1518
chatUserProfile?: ChatUserProfile
1619
token?: string
1720
accessToken?: string
1821
}
22+
1923
const useChatUserStore = defineStore('chat-user', {
2024
state: (): Chat => ({
2125
chat_profile: undefined,
@@ -111,6 +115,41 @@ const useChatUserStore = defineStore('chat-user', {
111115
return true
112116
})
113117
},
118+
async dingCallback(code: string, accessToken: string) {
119+
return ChatAPI.getDingCallback(code, accessToken).then((ok) => {
120+
this.setToken(ok.data.token)
121+
return this.token
122+
})
123+
},
124+
async dingOauth2Callback(code: string) {
125+
return ChatAPI.getDingOauth2Callback(code).then((ok) => {
126+
this.setToken(ok.data.token)
127+
return this.token
128+
})
129+
},
130+
async wecomCallback(code: string, accessToken: string) {
131+
return ChatAPI.getWecomCallback(code, accessToken).then((ok) => {
132+
this.setToken(ok.data.token)
133+
return this.token
134+
})
135+
},
136+
async larkCallback(code: string) {
137+
return ChatAPI.getLarkCallback(code).then((ok) => {
138+
this.setToken(ok.data.token)
139+
return this.token
140+
})
141+
},
142+
async getQrType() {
143+
return ChatAPI.getQrType().then((ok) => {
144+
return ok.data
145+
})
146+
},
147+
async getQrSource() {
148+
return ChatAPI.getQrSource().then((ok) => {
149+
return ok.data
150+
})
151+
},
152+
114153
},
115154
})
116155

0 commit comments

Comments
 (0)