common.ts 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. import type { Fetcher } from 'swr'
  2. import { del, download, get, patch, post, put, upload } from './base'
  3. import type {
  4. AccountIntegrate,
  5. ApiBasedExtension,
  6. CodeBasedExtension,
  7. CommonResponse,
  8. DataSourceNotion,
  9. FileUploadConfigResponse,
  10. ICurrentWorkspace,
  11. IWorkspace,
  12. InitValidateStatusResponse,
  13. InvitationResponse,
  14. LangGeniusVersionResponse,
  15. Member,
  16. ModerateResponse,
  17. OauthResponse,
  18. PluginProvider,
  19. Provider,
  20. ProviderAnthropicToken,
  21. ProviderAzureToken,
  22. SetupStatusResponse,
  23. UserProfileOriginResponse,
  24. } from '@/models/common'
  25. import type {
  26. UpdateOpenAIKeyResponse,
  27. ValidateOpenAIKeyResponse,
  28. } from '@/models/app'
  29. import type {
  30. DefaultModelResponse,
  31. Model,
  32. ModelItem,
  33. ModelLoadBalancingConfig,
  34. ModelParameterRule,
  35. ModelProvider,
  36. ModelTypeEnum,
  37. } from '@/app/components/header/account-setting/model-provider-page/declarations'
  38. import type { RETRIEVE_METHOD } from '@/types/app'
  39. import type { SystemFeatures } from '@/types/feature'
  40. type LoginSuccess = {
  41. result: 'success'
  42. data: { access_token: string; refresh_token: string }
  43. }
  44. type LoginFail = {
  45. result: 'fail'
  46. data: string
  47. code: string
  48. message: string
  49. }
  50. type LoginResponse = LoginSuccess | LoginFail
  51. export const login: Fetcher<LoginResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  52. return post(url, { body }) as Promise<LoginResponse>
  53. }
  54. export const fetchNewToken: Fetcher<CommonResponse & { data: { access_token: string; refresh_token: string } }, { body: Record<string, any> }> = ({ body }) => {
  55. return post('/refresh-token', { body }) as Promise<CommonResponse & { data: { access_token: string; refresh_token: string } }>
  56. }
  57. export const setup: Fetcher<CommonResponse, { body: Record<string, any> }> = ({ body }) => {
  58. return post<CommonResponse>('/setup', { body })
  59. }
  60. export const initValidate: Fetcher<CommonResponse, { body: Record<string, any> }> = ({ body }) => {
  61. return post<CommonResponse>('/init', { body })
  62. }
  63. export const fetchInitValidateStatus = () => {
  64. return get<InitValidateStatusResponse>('/init')
  65. }
  66. export const fetchSetupStatus = () => {
  67. return get<SetupStatusResponse>('/setup')
  68. }
  69. export const fetchUserProfile: Fetcher<UserProfileOriginResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  70. return get<UserProfileOriginResponse>(url, params, { needAllResponseContent: true })
  71. }
  72. export const updateUserProfile: Fetcher<CommonResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  73. return post<CommonResponse>(url, { body })
  74. }
  75. export const logout: Fetcher<CommonResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  76. return get<CommonResponse>(url, params)
  77. }
  78. export const fetchLanggeniusVersion: Fetcher<LangGeniusVersionResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  79. return get<LangGeniusVersionResponse>(url, { params })
  80. }
  81. export const oauth: Fetcher<OauthResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  82. return get<OauthResponse>(url, { params })
  83. }
  84. export const oneMoreStep: Fetcher<CommonResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  85. return post<CommonResponse>(url, { body })
  86. }
  87. export const fetchMembers: Fetcher<{ accounts: Member[] | null }, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  88. return get<{ accounts: Member[] | null }>(url, { params })
  89. }
  90. export const fetchTypes = ({ url, params }: any) => {
  91. console.log('查询类型列表')
  92. return get(url, { params })
  93. // return new Promise((resolve) => {
  94. // setTimeout(() => {
  95. // const arr: any = []
  96. // for (let i = 1; i < 10; i++) {
  97. // arr.push({
  98. // id: i,
  99. // name: `类型${i}`,
  100. // relation: i % 2,
  101. // })
  102. // }
  103. // resolve({
  104. // data: arr,
  105. // })
  106. // }, 1000)
  107. // })
  108. }
  109. export const fetchKnowledges = ({ url, params }: any) => {
  110. console.log('查询知识服务', params, url)
  111. return get(url, { params })
  112. // return new Promise((resolve) => {
  113. // setTimeout(() => {
  114. // const arr: any = []
  115. // for (let i = 1; i < 10; i++) {
  116. // arr.push({
  117. // id: i,
  118. // serviceType: i % 3 + 1,
  119. // serviceName: `深圳口岸服务网${i}`,
  120. // url: '74.10.28.118',
  121. // status: i % 2,
  122. // time: '2021-09-22 14:22:22',
  123. // })
  124. // }
  125. // resolve({
  126. // data: arr,
  127. // })
  128. // }, 1000)
  129. // })
  130. }
  131. export const fetchMoulds = ({ url, params }: any) => {
  132. console.log('查询知识库模板', params, url)
  133. return get<{ accounts: Member[] | null }>(url, { params })
  134. // return new Promise((resolve) => {
  135. // setTimeout(() => {
  136. // const arr: any = []
  137. // for (let i = 1; i < 2; i++) {
  138. // // /files/7be8a2ca-a633-473c-8bcf-b73ee9fd7738/file-preview?timestamp=1744947616&nonce=a4107f3e163bbb0da255914e2ccabaf3&sign=H82Wk2VbWjXXEyzRUhGyNQlR-PG8NEGy5ijCEF0IKgo=
  139. // arr.push({
  140. // id: '7be8a2ca-a633-473c-8bcf-b73ee9fd7738',
  141. // fileName: `文件${i}.doc`,
  142. // })
  143. // }
  144. // resolve({
  145. // data: arr,
  146. // })
  147. // }, 1000)
  148. // })
  149. }
  150. export const fetchProviders: Fetcher<Provider[] | null, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  151. return get<Provider[] | null>(url, { params })
  152. }
  153. export const validateProviderKey: Fetcher<ValidateOpenAIKeyResponse, { url: string; body: { token: string } }> = ({ url, body }) => {
  154. return post<ValidateOpenAIKeyResponse>(url, { body })
  155. }
  156. export const updateProviderAIKey: Fetcher<UpdateOpenAIKeyResponse, { url: string; body: { token: string | ProviderAzureToken | ProviderAnthropicToken } }> = ({ url, body }) => {
  157. return post<UpdateOpenAIKeyResponse>(url, { body })
  158. }
  159. export const fetchAccountIntegrates: Fetcher<{ data: AccountIntegrate[] | null }, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  160. return get<{ data: AccountIntegrate[] | null }>(url, { params })
  161. }
  162. export const inviteMember: Fetcher<InvitationResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  163. return post<InvitationResponse>(url, { body })
  164. }
  165. export const updateMemberRole: Fetcher<CommonResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  166. return put<CommonResponse>(url, { body })
  167. }
  168. export const deleteMemberOrCancelInvitation: Fetcher<CommonResponse, { url: string }> = ({ url }) => {
  169. return del<CommonResponse>(url)
  170. }
  171. export const addType = ({ url, body }: any) => {
  172. console.log('新增类型', url, body)
  173. return post(url, { body })
  174. }
  175. export const editType = ({ url, body }: any) => {
  176. console.log('编辑类型', url, body)
  177. return patch(url, { body })
  178. }
  179. export const delType = ({ url, body }: any) => {
  180. console.log('删除类型', url, body)
  181. return del(url, { body })
  182. }
  183. export const addKnowledge = ({ url, body }: any) => {
  184. console.log('新增知识', body, url)
  185. return post(url, { body })
  186. }
  187. export const editKnowledge = ({ url, body }: any) => {
  188. console.log('编辑知识', body, url)
  189. return patch(url, { body })
  190. }
  191. export const delKnowledge = ({ url, body }: any) => {
  192. console.log('删除知识', url, body)
  193. return del(url, { body })
  194. }
  195. export const addMouldFile = ({ url, body }: any) => {
  196. console.log('新增模板文件', body, url)
  197. return upload({
  198. xhr: new XMLHttpRequest(),
  199. data: body,
  200. }, false, url)
  201. }
  202. export const delMouldFile = ({ url, body }: any) => {
  203. console.log('删除模板文件', url)
  204. return del(url)
  205. }
  206. export const downloadMouldFile = ({ url, fileName }: any) => {
  207. console.log('下载模板文件', url, fileName)
  208. return download(url, {}, { fileName })
  209. }
  210. export const handleExamine = ({ url, body }: any) => {
  211. // return post<InvitationResponse>(url, { body })
  212. console.log('处理上下线审核', body)
  213. return new Promise((resolve) => {
  214. setTimeout(() => {
  215. resolve({
  216. result: 'success',
  217. })
  218. }, 1000)
  219. })
  220. }
  221. export const applyExamine = ({ url, body }: any) => {
  222. // return post<InvitationResponse>(url, { body })
  223. console.log('提交上下线审核', body)
  224. return new Promise((resolve) => {
  225. setTimeout(() => {
  226. resolve({
  227. result: 'success',
  228. })
  229. }, 1000)
  230. })
  231. }
  232. export const fetchFilePreview: Fetcher<{ content: string }, { fileID: string }> = ({ fileID }) => {
  233. return get<{ content: string }>(`/files/${fileID}/preview`)
  234. }
  235. export const fetchCurrentWorkspace: Fetcher<ICurrentWorkspace, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  236. return get<ICurrentWorkspace>(url, { params })
  237. }
  238. export const updateCurrentWorkspace: Fetcher<ICurrentWorkspace, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  239. return post<ICurrentWorkspace>(url, { body })
  240. }
  241. export const fetchWorkspaces: Fetcher<{ workspaces: IWorkspace[] }, { url: string; params: Record<string, any> }> = ({ url, params }) => {
  242. return get<{ workspaces: IWorkspace[] }>(url, { params })
  243. }
  244. export const switchWorkspace: Fetcher<CommonResponse & { new_tenant: IWorkspace }, { url: string; body: Record<string, any> }> = ({ url, body }) => {
  245. return post<CommonResponse & { new_tenant: IWorkspace }>(url, { body })
  246. }
  247. export const fetchDataSource: Fetcher<{ data: DataSourceNotion[] }, { url: string }> = ({ url }) => {
  248. return get<{ data: DataSourceNotion[] }>(url)
  249. }
  250. export const syncDataSourceNotion: Fetcher<CommonResponse, { url: string }> = ({ url }) => {
  251. return get<CommonResponse>(url)
  252. }
  253. export const updateDataSourceNotionAction: Fetcher<CommonResponse, { url: string }> = ({ url }) => {
  254. return patch<CommonResponse>(url)
  255. }
  256. export const fetchPluginProviders: Fetcher<PluginProvider[] | null, string> = (url) => {
  257. return get<PluginProvider[] | null>(url)
  258. }
  259. export const validatePluginProviderKey: Fetcher<ValidateOpenAIKeyResponse, { url: string; body: { credentials: any } }> = ({ url, body }) => {
  260. return post<ValidateOpenAIKeyResponse>(url, { body })
  261. }
  262. export const updatePluginProviderAIKey: Fetcher<UpdateOpenAIKeyResponse, { url: string; body: { credentials: any } }> = ({ url, body }) => {
  263. return post<UpdateOpenAIKeyResponse>(url, { body })
  264. }
  265. export const invitationCheck: Fetcher<CommonResponse & { is_valid: boolean; data: { workspace_name: string; email: string; workspace_id: string } }, { url: string; params: { workspace_id?: string; email?: string; token: string } }> = ({ url, params }) => {
  266. return get<CommonResponse & { is_valid: boolean; data: { workspace_name: string; email: string; workspace_id: string } }>(url, { params })
  267. }
  268. export const activateMember: Fetcher<LoginResponse, { url: string; body: any }> = ({ url, body }) => {
  269. return post<LoginResponse>(url, { body })
  270. }
  271. export const fetchModelProviders: Fetcher<{ data: ModelProvider[] }, string> = (url) => {
  272. return get<{ data: ModelProvider[] }>(url)
  273. }
  274. export type ModelProviderCredentials = {
  275. credentials?: Record<string, string | undefined | boolean>
  276. load_balancing: ModelLoadBalancingConfig
  277. }
  278. export const fetchModelProviderCredentials: Fetcher<ModelProviderCredentials, string> = (url) => {
  279. return get<ModelProviderCredentials>(url)
  280. }
  281. export const fetchModelLoadBalancingConfig: Fetcher<{
  282. credentials?: Record<string, string | undefined | boolean>
  283. load_balancing: ModelLoadBalancingConfig
  284. }, string> = (url) => {
  285. return get<{
  286. credentials?: Record<string, string | undefined | boolean>
  287. load_balancing: ModelLoadBalancingConfig
  288. }>(url)
  289. }
  290. export const fetchModelProviderModelList: Fetcher<{ data: ModelItem[] }, string> = (url) => {
  291. return get<{ data: ModelItem[] }>(url)
  292. }
  293. export const fetchModelList: Fetcher<{ data: Model[] }, string> = (url) => {
  294. return get<{ data: Model[] }>(url)
  295. }
  296. export const validateModelProvider: Fetcher<ValidateOpenAIKeyResponse, { url: string; body: any }> = ({ url, body }) => {
  297. return post<ValidateOpenAIKeyResponse>(url, { body })
  298. }
  299. export const validateModelLoadBalancingCredentials: Fetcher<ValidateOpenAIKeyResponse, { url: string; body: any }> = ({ url, body }) => {
  300. return post<ValidateOpenAIKeyResponse>(url, { body })
  301. }
  302. export const setModelProvider: Fetcher<CommonResponse, { url: string; body: any }> = ({ url, body }) => {
  303. return post<CommonResponse>(url, { body })
  304. }
  305. export const deleteModelProvider: Fetcher<CommonResponse, { url: string; body?: any }> = ({ url, body }) => {
  306. return del<CommonResponse>(url, { body })
  307. }
  308. export const changeModelProviderPriority: Fetcher<CommonResponse, { url: string; body: any }> = ({ url, body }) => {
  309. return post<CommonResponse>(url, { body })
  310. }
  311. export const setModelProviderModel: Fetcher<CommonResponse, { url: string; body: any }> = ({ url, body }) => {
  312. return post<CommonResponse>(url, { body })
  313. }
  314. export const deleteModelProviderModel: Fetcher<CommonResponse, { url: string }> = ({ url }) => {
  315. return del<CommonResponse>(url)
  316. }
  317. export const getPayUrl: Fetcher<{ url: string }, string> = (url) => {
  318. return get<{ url: string }>(url)
  319. }
  320. export const fetchDefaultModal: Fetcher<{ data: DefaultModelResponse }, string> = (url) => {
  321. return get<{ data: DefaultModelResponse }>(url)
  322. }
  323. export const updateDefaultModel: Fetcher<CommonResponse, { url: string; body: any }> = ({ url, body }) => {
  324. return post<CommonResponse>(url, { body })
  325. }
  326. export const fetchModelParameterRules: Fetcher<{ data: ModelParameterRule[] }, string> = (url) => {
  327. return get<{ data: ModelParameterRule[] }>(url)
  328. }
  329. export const fetchFileUploadConfig: Fetcher<FileUploadConfigResponse, { url: string }> = ({ url }) => {
  330. return get<FileUploadConfigResponse>(url)
  331. }
  332. export const fetchNotionConnection: Fetcher<{ data: string }, string> = (url) => {
  333. return get(url) as Promise<{ data: string }>
  334. }
  335. export const fetchDataSourceNotionBinding: Fetcher<{ result: string }, string> = (url) => {
  336. return get(url) as Promise<{ result: string }>
  337. }
  338. export const fetchApiBasedExtensionList: Fetcher<ApiBasedExtension[], string> = (url) => {
  339. return get(url) as Promise<ApiBasedExtension[]>
  340. }
  341. export const fetchApiBasedExtensionDetail: Fetcher<ApiBasedExtension, string> = (url) => {
  342. return get(url) as Promise<ApiBasedExtension>
  343. }
  344. export const addApiBasedExtension: Fetcher<ApiBasedExtension, { url: string; body: ApiBasedExtension }> = ({ url, body }) => {
  345. return post(url, { body }) as Promise<ApiBasedExtension>
  346. }
  347. export const updateApiBasedExtension: Fetcher<ApiBasedExtension, { url: string; body: ApiBasedExtension }> = ({ url, body }) => {
  348. return post(url, { body }) as Promise<ApiBasedExtension>
  349. }
  350. export const deleteApiBasedExtension: Fetcher<{ result: string }, string> = (url) => {
  351. return del(url) as Promise<{ result: string }>
  352. }
  353. export const fetchCodeBasedExtensionList: Fetcher<CodeBasedExtension, string> = (url) => {
  354. return get(url) as Promise<CodeBasedExtension>
  355. }
  356. export const moderate = (url: string, body: { app_id: string; text: string }) => {
  357. return post(url, { body }) as Promise<ModerateResponse>
  358. }
  359. type RetrievalMethodsRes = {
  360. retrieval_method: RETRIEVE_METHOD[]
  361. }
  362. export const fetchSupportRetrievalMethods: Fetcher<RetrievalMethodsRes, string> = (url) => {
  363. return get<RetrievalMethodsRes>(url)
  364. }
  365. export const getSystemFeatures = () => {
  366. return get<SystemFeatures>('/system-features')
  367. }
  368. export const enableModel = (url: string, body: { model: string; model_type: ModelTypeEnum }) =>
  369. patch<CommonResponse>(url, { body })
  370. export const disableModel = (url: string, body: { model: string; model_type: ModelTypeEnum }) =>
  371. patch<CommonResponse>(url, { body })
  372. export const sendForgotPasswordEmail: Fetcher<CommonResponse & { data: string }, { url: string; body: { email: string } }> = ({ url, body }) =>
  373. post<CommonResponse & { data: string }>(url, { body })
  374. export const verifyForgotPasswordToken: Fetcher<CommonResponse & { is_valid: boolean; email: string }, { url: string; body: { token: string } }> = ({ url, body }) => {
  375. return post(url, { body }) as Promise<CommonResponse & { is_valid: boolean; email: string }>
  376. }
  377. export const changePasswordWithToken: Fetcher<CommonResponse, { url: string; body: { token: string; new_password: string; password_confirm: string } }> = ({ url, body }) =>
  378. post<CommonResponse>(url, { body })
  379. export const uploadRemoteFileInfo = (url: string, isPublic?: boolean) => {
  380. return post<{ id: string; name: string; size: number; mime_type: string; url: string }>('/remote-files/upload', { body: { url } }, { isPublicAPI: isPublic })
  381. }
  382. export const sendEMailLoginCode = (email: string, language = 'en-US') =>
  383. post<CommonResponse & { data: string }>('/email-code-login', { body: { email, language } })
  384. export const emailLoginWithCode = (data: { email: string; code: string; token: string }) =>
  385. post<LoginResponse>('/email-code-login/validity', { body: data })
  386. export const sendResetPasswordCode = (email: string, language = 'en-US') =>
  387. post<CommonResponse & { data: string; message?: string; code?: string }>('/forgot-password', { body: { email, language } })
  388. export const verifyResetPasswordCode = (body: { email: string; code: string; token: string }) =>
  389. post<CommonResponse & { is_valid: boolean }>('/forgot-password/validity', { body })
  390. export const sendDeleteAccountCode = () =>
  391. get<CommonResponse & { data: string }>('/account/delete/verify')
  392. export const verifyDeleteAccountCode = (body: { code: string; token: string }) =>
  393. post<CommonResponse & { is_valid: boolean }>('/account/delete', { body })
  394. export const submitDeleteAccountFeedback = (body: { feedback: string; email: string }) =>
  395. post<CommonResponse>('/account/delete/feedback', { body })
  396. export const getDocDownloadUrl = (doc_name: string) =>
  397. get<{ url: string }>('/compliance/download', { params: { doc_name } }, { silent: true })
  398. export const fetchStatistic = ({ url, params }: any) => {
  399. console.log('查询知识总览', url, params)
  400. return get(url, { params })
  401. }
  402. export const fetchLog = ({ url, params }: any) => {
  403. console.log('查询训练日志列表', url, params)
  404. // return get(url, { params })
  405. return new Promise((resolve) => {
  406. setTimeout(() => {
  407. const arr: any = []
  408. for (let i = 1; i < 10; i++) {
  409. arr.push({
  410. id: i,
  411. version: `${i}.${i}.${i}`,
  412. time: '2022-02-02 02:21:23',
  413. })
  414. }
  415. resolve({
  416. data: arr,
  417. has_more: false,
  418. limit: 10,
  419. total: 100,
  420. page: 1,
  421. })
  422. }, 1000)
  423. })
  424. }
  425. export const fetchIntentType = ({ url, params }: any) => {
  426. console.log('查询意图类型', url, params)
  427. // return get(url, { params })
  428. return new Promise((resolve) => {
  429. setTimeout(() => {
  430. const arr: any = []
  431. for (let i = 1; i < 10; i++) {
  432. arr.push({
  433. id: i,
  434. name: `意图类型_${i}`,
  435. binding_count: i,
  436. })
  437. }
  438. resolve({
  439. data: arr,
  440. has_more: false,
  441. limit: 10,
  442. total: 100,
  443. page: 1,
  444. })
  445. }, 1000)
  446. })
  447. }
  448. export const fetchIntentName = ({ url, params }: any) => {
  449. console.log('查询意图名称', url, params)
  450. // return get(url, { params })
  451. return new Promise((resolve) => {
  452. setTimeout(() => {
  453. const arr: any = []
  454. for (let i = 1; i < 10; i++) {
  455. arr.push({
  456. id: i,
  457. name: `意图名称_${i}`,
  458. })
  459. }
  460. resolve({
  461. data: arr,
  462. has_more: false,
  463. limit: 10,
  464. total: 100,
  465. page: 1,
  466. })
  467. }, 1000)
  468. })
  469. }
  470. export const fetchCorpus = ({ url, params }: any) => {
  471. console.log('查询训练语料列表', url, params)
  472. // return get(url, { params })
  473. return new Promise((resolve) => {
  474. setTimeout(() => {
  475. const arr: any = []
  476. for (let i = 1; i < 10; i++) {
  477. arr.push({
  478. id: i,
  479. name: `语料_${i}`,
  480. relation: i % 2,
  481. })
  482. }
  483. resolve({
  484. data: arr,
  485. has_more: false,
  486. limit: 10,
  487. total: 100,
  488. page: 1,
  489. })
  490. }, 1000)
  491. })
  492. }
  493. export const addCorpus = ({ url, body }: any) => {
  494. console.log('新增训练语料', url, body)
  495. return post(url, { body })
  496. }
  497. export const editCorpus = ({ url, body }: any) => {
  498. console.log('编辑训练语料', url, body)
  499. return patch(url, { body })
  500. }
  501. export const delCorpus = ({ url, body }: any) => {
  502. console.log('删除训练语料', url, body)
  503. return del(url, { body })
  504. }
  505. export const addCorpusQuestion = ({ url, body }: any) => {
  506. console.log('新增训练语料-相似问题', url, body)
  507. return post(url, { body })
  508. }
  509. export const editCorpusQuestion = ({ url, body }: any) => {
  510. console.log('编辑训练语料-相似问题', url, body)
  511. return patch(url, { body })
  512. }
  513. export const delCorpusQuestion = ({ url, body }: any) => {
  514. console.log('删除训练语料-相似问题', url, body)
  515. return del(url, { body })
  516. }
  517. export const fetchDepts = ({ url, params }: any) => {
  518. console.log('查询部门列表', params, url)
  519. // return get(url, { params })
  520. return new Promise((resolve) => {
  521. setTimeout(() => {
  522. const arr: any = []
  523. for (let i = 1; i < 3; i++) {
  524. const dept1: any = {
  525. id: `${i}`,
  526. name: `部门_${i}`,
  527. children: [],
  528. }
  529. for (let j = 1; j < 4; j++) {
  530. const dept2: any = {
  531. id: `${i}_${j}`,
  532. name: `部门_${i}-${j}`,
  533. children: [],
  534. }
  535. for (let k = 1; k < 5; k++) {
  536. const dept3: any = {
  537. id: `${i}_${j}_${k}`,
  538. name: `部门_${i}-${j}-${k}`,
  539. relation: k % 2,
  540. }
  541. dept2.children.push(dept3)
  542. }
  543. dept1.children.push(dept2)
  544. }
  545. arr.push(dept1)
  546. }
  547. resolve({
  548. data: arr,
  549. })
  550. }, 1000)
  551. })
  552. }
  553. export const fetchDeptUsers = ({ url, params }: any) => {
  554. console.log('查询部门用户列表', params, url)
  555. // return get(url, { params })
  556. return new Promise((resolve) => {
  557. setTimeout(() => {
  558. const arr: any = []
  559. for (let i = 1; i < 3; i++) {
  560. const dept1: any = {
  561. id: `${i}`,
  562. name: `部门_${i}`,
  563. children: [],
  564. }
  565. for (let j = 1; j < 4; j++) {
  566. const dept2: any = {
  567. id: `${i}_${j}`,
  568. name: `部门_${i}-${j}`,
  569. children: [],
  570. }
  571. for (let k = 1; k < 5; k++) {
  572. const dept3: any = {
  573. id: `${i}_${j}_${k}`,
  574. name: `用户_${i}-${j}-${k}`,
  575. relation: k % 2,
  576. }
  577. dept2.children.push(dept3)
  578. }
  579. dept1.children.push(dept2)
  580. }
  581. arr.push(dept1)
  582. }
  583. resolve({
  584. data: arr,
  585. })
  586. }, 1000)
  587. })
  588. }