Skip to content

Commit 9e24e8c

Browse files
authored
feat: workspace to store (#3261)
1 parent cbcad3c commit 9e24e8c

File tree

8 files changed

+491
-25
lines changed

8 files changed

+491
-25
lines changed

ui/src/api/application/application-key.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import { Result } from '@/request/Result'
22
import { get, post, del, put } from '@/request/index'
3-
3+
import useStore from '@/stores'
44
import { type Ref } from 'vue'
55

6-
const prefix = '/workspace/' + localStorage.getItem('workspace_id') + '/application'
7-
6+
const prefix: any = { _value: '/workspace/' }
7+
Object.defineProperty(prefix, 'value', {
8+
get: function () {
9+
const { user } = useStore()
10+
return this._value + user.getWorkspaceId() + '/application'
11+
},
12+
})
813
/**
914
* API_KEY列表
1015
* @param 参数 application_id
@@ -13,7 +18,7 @@ const getAPIKey: (application_id: string, loading?: Ref<boolean>) => Promise<Res
1318
application_id,
1419
loading,
1520
) => {
16-
return get(`${prefix}/${application_id}/application`, undefined, loading)
21+
return get(`${prefix.value}/${application_id}/application`, undefined, loading)
1722
}
1823

1924
/**
@@ -24,7 +29,7 @@ const postAPIKey: (application_id: string, loading?: Ref<boolean>) => Promise<Re
2429
application_id,
2530
loading,
2631
) => {
27-
return post(`${prefix}/${application_id}/application`, {}, undefined, loading)
32+
return post(`${prefix.value}/${application_id}/application`, {}, undefined, loading)
2833
}
2934

3035
/**
@@ -36,7 +41,12 @@ const delAPIKey: (
3641
api_key_id: string,
3742
loading?: Ref<boolean>,
3843
) => Promise<Result<boolean>> = (application_id, api_key_id, loading) => {
39-
return del(`${prefix}/${application_id}/application/${api_key_id}`, undefined, undefined, loading)
44+
return del(
45+
`${prefix.value}/${application_id}/application/${api_key_id}`,
46+
undefined,
47+
undefined,
48+
loading,
49+
)
4050
}
4151

4252
/**
@@ -52,7 +62,12 @@ const putAPIKey: (
5262
data: any,
5363
loading?: Ref<boolean>,
5464
) => Promise<Result<any>> = (application_id, api_key_id, data, loading) => {
55-
return put(`${prefix}/${application_id}/application/${api_key_id}`, data, undefined, loading)
65+
return put(
66+
`${prefix.value}/${application_id}/application/${api_key_id}`,
67+
data,
68+
undefined,
69+
loading,
70+
)
5671
}
5772

5873
export default {

ui/src/api/application/application.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@ import { get, post, postStream, del, put, request, download, exportFile } from '
33
import type { pageRequest } from '@/api/type/common'
44
import type { ApplicationFormType } from '@/api/type/application'
55
import { type Ref } from 'vue'
6+
import useStore from '@/stores'
67

7-
const prefix = '/workspace/' + localStorage.getItem('workspace_id') + '/application'
8-
8+
const prefix: any = { _value: '/workspace/' }
9+
Object.defineProperty(prefix, 'value', {
10+
get: function () {
11+
const { user } = useStore()
12+
return this._value + user.getWorkspaceId() + '/application'
13+
},
14+
})
915
/**
1016
* 获取全部应用
1117
* @param 参数
@@ -14,7 +20,7 @@ const getAllApplication: (param?: any, loading?: Ref<boolean>) => Promise<Result
1420
param,
1521
loading,
1622
) => {
17-
return get(`${prefix}`, param, loading)
23+
return get(`${prefix.value}`, param, loading)
1824
}
1925

2026
/**
@@ -28,7 +34,7 @@ const getApplication: (
2834
param: any,
2935
loading?: Ref<boolean>,
3036
) => Promise<Result<any>> = (page, param, loading) => {
31-
return get(`${prefix}/${page.current_page}/${page.page_size}`, param, loading)
37+
return get(`${prefix.value}/${page.current_page}/${page.page_size}`, param, loading)
3238
}
3339

3440
/**
@@ -39,7 +45,7 @@ const postApplication: (
3945
data: ApplicationFormType,
4046
loading?: Ref<boolean>,
4147
) => Promise<Result<any>> = (data, loading) => {
42-
return post(`${prefix}`, data, undefined, loading)
48+
return post(`${prefix.value}`, data, undefined, loading)
4349
}
4450

4551
/**
@@ -51,7 +57,7 @@ const putApplication: (
5157
data: ApplicationFormType,
5258
loading?: Ref<boolean>,
5359
) => Promise<Result<any>> = (application_id, data, loading) => {
54-
return put(`${prefix}/${application_id}`, data, undefined, loading)
60+
return put(`${prefix.value}/${application_id}`, data, undefined, loading)
5561
}
5662

5763
/**
@@ -62,7 +68,7 @@ const delApplication: (
6268
application_id: string,
6369
loading?: Ref<boolean>,
6470
) => Promise<Result<boolean>> = (application_id, loading) => {
65-
return del(`${prefix}/${application_id}`, undefined, {}, loading)
71+
return del(`${prefix.value}/${application_id}`, undefined, {}, loading)
6672
}
6773

6874
/**
@@ -73,7 +79,7 @@ const getApplicationDetail: (
7379
application_id: string,
7480
loading?: Ref<boolean>,
7581
) => Promise<Result<any>> = (application_id, loading) => {
76-
return get(`${prefix}/${application_id}`, undefined, loading)
82+
return get(`${prefix.value}/${application_id}`, undefined, loading)
7783
}
7884

7985
/**
@@ -84,7 +90,7 @@ const getAccessToken: (application_id: string, loading?: Ref<boolean>) => Promis
8490
application_id,
8591
loading,
8692
) => {
87-
return get(`${prefix}/${application_id}/access_token`, undefined, loading)
93+
return get(`${prefix.value}/${application_id}/access_token`, undefined, loading)
8894
}
8995

9096
/**
@@ -99,7 +105,7 @@ const putAccessToken: (
99105
data: any,
100106
loading?: Ref<boolean>,
101107
) => Promise<Result<any>> = (application_id, data, loading) => {
102-
return put(`${prefix}/${application_id}/access_token`, data, undefined, loading)
108+
return put(`${prefix.value}/${application_id}/access_token`, data, undefined, loading)
103109
}
104110

105111
/**
@@ -113,7 +119,7 @@ const exportApplication = (
113119
) => {
114120
return exportFile(
115121
application_name + '.mk',
116-
`${prefix}/${application_id}/export`,
122+
`${prefix.value}/${application_id}/export`,
117123
undefined,
118124
loading,
119125
)
@@ -126,7 +132,7 @@ const importApplication: (data: any, loading?: Ref<boolean>) => Promise<Result<a
126132
data,
127133
loading,
128134
) => {
129-
return post(`${prefix}/import`, data, undefined, loading)
135+
return post(`${prefix.value}/import`, data, undefined, loading)
130136
}
131137

132138
/**
@@ -138,7 +144,7 @@ const getStatistics: (
138144
data: any,
139145
loading?: Ref<boolean>,
140146
) => Promise<Result<any>> = (application_id, data, loading) => {
141-
return get(`${prefix}/${application_id}/application_stats`, data, loading)
147+
return get(`${prefix.value}/${application_id}/application_stats`, data, loading)
142148
}
143149
/**
144150
* 打开调试对话id
@@ -150,7 +156,7 @@ const open: (application_id: string, loading?: Ref<boolean>) => Promise<Result<s
150156
application_id,
151157
loading,
152158
) => {
153-
return get(`${prefix}/${application_id}/open`, {}, loading)
159+
return get(`${prefix.value}/${application_id}/open`, {}, loading)
154160
}
155161
/**
156162
* 对话

ui/src/api/chat/chat.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { Result } from '@/request/Result'
2+
import {
3+
get,
4+
post,
5+
postStream,
6+
del,
7+
put,
8+
request,
9+
download,
10+
exportFile,
11+
} from '@/request/chat/index'
12+
13+
import { type Ref } from 'vue'
14+
15+
const prefix = '/workspace/' + localStorage.getItem('workspace_id') + '/application'
16+
17+
/**
18+
* 打开调试对话id
19+
* @param application_id 应用id
20+
* @param loading 加载器
21+
* @returns
22+
*/
23+
const open: (application_id: string, loading?: Ref<boolean>) => Promise<Result<string>> = (
24+
application_id,
25+
loading,
26+
) => {
27+
return get(`${prefix}/${application_id}/open`, {}, loading)
28+
}
29+
/**
30+
* 对话
31+
* @param 参数
32+
* chat_id: string
33+
* data
34+
*/
35+
const chat: (chat_id: string, data: any) => Promise<any> = (chat_id, data) => {
36+
return postStream(`/api/chat_message/${chat_id}`, data)
37+
}
38+
const chatProfile: (assessToken: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
39+
assessToken,
40+
loading,
41+
) => {
42+
return get('/auth/profile', { access_token: assessToken }, loading)
43+
}
44+
const applicationProfile: (assessToken: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
45+
assessToken,
46+
loading,
47+
) => {
48+
return get('/chat/api/profile')
49+
}
50+
export default {
51+
open,
52+
chat,
53+
chatProfile,
54+
}

ui/src/request/chat/Result.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export class Result<T> {
2+
message: string
3+
code: number
4+
data: T
5+
constructor(message: string, code: number, data: T) {
6+
this.message = message
7+
this.code = code
8+
this.data = data
9+
}
10+
11+
static success(data: any) {
12+
return new Result('请求成功', 200, data)
13+
}
14+
static error(message: string, code: number) {
15+
return new Result(message, code, null)
16+
}
17+
}
18+
19+
export default Result

0 commit comments

Comments
 (0)