|
@@ -1,12 +1,14 @@
|
|
|
import { makeAutoObservable } from 'mobx';
|
|
import { makeAutoObservable } from 'mobx';
|
|
|
|
|
+import { message } from 'antd';
|
|
|
import { apis } from '@/apis';
|
|
import { apis } from '@/apis';
|
|
|
|
|
+import { downloadFile } from '@/utils';
|
|
|
import { State, ReadonlyState, StateAction, DataExportStore } from './types';
|
|
import { State, ReadonlyState, StateAction, DataExportStore } from './types';
|
|
|
|
|
|
|
|
// 定义状态
|
|
// 定义状态
|
|
|
const stateGenerator = (): ReadonlyState => ({
|
|
const stateGenerator = (): ReadonlyState => ({
|
|
|
- pageLoading: false,
|
|
|
|
|
|
|
+ query: undefined,
|
|
|
|
|
+ listLoading: false,
|
|
|
list: [],
|
|
list: [],
|
|
|
- appId: '',
|
|
|
|
|
page: {
|
|
page: {
|
|
|
pageNumber: 1,
|
|
pageNumber: 1,
|
|
|
pageSize: 10,
|
|
pageSize: 10,
|
|
@@ -17,19 +19,18 @@ const stateGenerator = (): ReadonlyState => ({
|
|
|
// 修改状态
|
|
// 修改状态
|
|
|
const stateActionsGenerator = (state: State): StateAction => {
|
|
const stateActionsGenerator = (state: State): StateAction => {
|
|
|
return {
|
|
return {
|
|
|
- setPageLoading: (loading) => {
|
|
|
|
|
- state.pageLoading = loading;
|
|
|
|
|
|
|
+ setQuery: (query) => {
|
|
|
|
|
+ state.query = query;
|
|
|
|
|
+ },
|
|
|
|
|
+ setListLoading: (loading) => {
|
|
|
|
|
+ state.listLoading = loading;
|
|
|
},
|
|
},
|
|
|
setList: (list) => {
|
|
setList: (list) => {
|
|
|
state.list = list;
|
|
state.list = list;
|
|
|
},
|
|
},
|
|
|
- setAppId: (appId) => {
|
|
|
|
|
- state.appId = appId;
|
|
|
|
|
- },
|
|
|
|
|
setPage: (page) => {
|
|
setPage: (page) => {
|
|
|
state.page = page;
|
|
state.page = page;
|
|
|
},
|
|
},
|
|
|
-
|
|
|
|
|
};
|
|
};
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -39,50 +40,63 @@ const useDataExportStore = (): DataExportStore => {
|
|
|
const actions = stateActionsGenerator(state);
|
|
const actions = stateActionsGenerator(state);
|
|
|
|
|
|
|
|
const api = {
|
|
const api = {
|
|
|
- // 获取应用聊天列表
|
|
|
|
|
- fetchDocumentLibList: async () => {
|
|
|
|
|
- actions.setPageLoading(true);
|
|
|
|
|
|
|
+ // 获取聊天记录列表
|
|
|
|
|
+ fetchChatHistoryList: async () => {
|
|
|
|
|
+ actions.setListLoading(true);
|
|
|
try {
|
|
try {
|
|
|
const data = {
|
|
const data = {
|
|
|
|
|
+ ...state.query,
|
|
|
pageNumber: state.page.pageNumber,
|
|
pageNumber: state.page.pageNumber,
|
|
|
pageSize: state.page.pageSize,
|
|
pageSize: state.page.pageSize,
|
|
|
};
|
|
};
|
|
|
- const res = await apis.fetchDialogListLibApi(state.appId, data);
|
|
|
|
|
|
|
+ const res = await apis.fetchChatHistoryList(data);
|
|
|
actions.setList(res.rows);
|
|
actions.setList(res.rows);
|
|
|
actions.setPage({
|
|
actions.setPage({
|
|
|
...state.page,
|
|
...state.page,
|
|
|
total: res.total,
|
|
total: res.total,
|
|
|
});
|
|
});
|
|
|
-
|
|
|
|
|
} catch (error: any) {
|
|
} catch (error: any) {
|
|
|
console.error(error);
|
|
console.error(error);
|
|
|
} finally {
|
|
} finally {
|
|
|
- actions.setPageLoading(false);
|
|
|
|
|
|
|
+ actions.setListLoading(false);
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
-
|
|
|
|
|
- // 获取所有聊天列表
|
|
|
|
|
- fetchDocumentLibAllList: async () => {
|
|
|
|
|
- actions.setPageLoading(true);
|
|
|
|
|
|
|
+ // 导出聊天记录
|
|
|
|
|
+ exportChatHistory: async (id: string, fileName: string) => {
|
|
|
try {
|
|
try {
|
|
|
- const data = {
|
|
|
|
|
- pageNumber: state.page.pageNumber,
|
|
|
|
|
- pageSize: state.page.pageSize,
|
|
|
|
|
- };
|
|
|
|
|
- const res = await apis.fetchDialogAllListLibApi(data);
|
|
|
|
|
- actions.setList(res.rows);
|
|
|
|
|
- actions.setPage({
|
|
|
|
|
- ...state.page,
|
|
|
|
|
- total: res.total,
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ const blob = await apis.exportChatHistory(id);
|
|
|
|
|
+ fileName = `${fileName}.xlsx`;
|
|
|
|
|
+ downloadFile(blob, fileName);
|
|
|
|
|
+ message.success('导出成功');
|
|
|
} catch (error: any) {
|
|
} catch (error: any) {
|
|
|
- console.error(error);
|
|
|
|
|
- } finally {
|
|
|
|
|
- actions.setPageLoading(false);
|
|
|
|
|
|
|
+ message.error(error.msg);
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 点击查询
|
|
|
|
|
+ const onClickSearch: DataExportStore['onClickSearch'] = async (query) => {
|
|
|
|
|
+ const initialPageNumber = stateGenerator().page.pageNumber;
|
|
|
|
|
+
|
|
|
|
|
+ actions.setQuery(query);
|
|
|
|
|
+ actions.setPage({
|
|
|
|
|
+ ...state.page,
|
|
|
|
|
+ pageNumber: initialPageNumber,
|
|
|
|
|
+ });
|
|
|
|
|
+ // 获取聊天记录列表
|
|
|
|
|
+ await api.fetchChatHistoryList();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 点击重置
|
|
|
|
|
+ const onClickReset: DataExportStore['onClickReset'] = async (query) => {
|
|
|
|
|
+ const initialPage = stateGenerator().page;
|
|
|
|
|
+
|
|
|
|
|
+ actions.setQuery(query);
|
|
|
|
|
+ actions.setPage(initialPage);
|
|
|
|
|
+ // 获取聊天记录列表
|
|
|
|
|
+ await api.fetchChatHistoryList();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 更改分页
|
|
// 更改分页
|
|
|
const onChangePagination: DataExportStore['onChangePagination'] = async (pageNumber, pageSize) => {
|
|
const onChangePagination: DataExportStore['onChangePagination'] = async (pageNumber, pageSize) => {
|
|
|
actions.setPage({
|
|
actions.setPage({
|
|
@@ -90,36 +104,42 @@ const useDataExportStore = (): DataExportStore => {
|
|
|
pageNumber: pageNumber,
|
|
pageNumber: pageNumber,
|
|
|
pageSize: pageSize,
|
|
pageSize: pageSize,
|
|
|
});
|
|
});
|
|
|
- // 获取知识库列表
|
|
|
|
|
- init();
|
|
|
|
|
|
|
+ // 获取聊天记录列表
|
|
|
|
|
+ await api.fetchChatHistoryList();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 点击导出
|
|
|
|
|
+ const onClickDownload: DataExportStore['onClickDownload'] = async (id, name) => {
|
|
|
|
|
+ // 导出聊天记录
|
|
|
|
|
+ await api.exportChatHistory(id, name);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 初始渲染
|
|
// 初始渲染
|
|
|
- const init: DataExportStore['init'] = (appId) => {
|
|
|
|
|
- // 获取知识列表
|
|
|
|
|
- if(appId){
|
|
|
|
|
- actions.setAppId(appId);
|
|
|
|
|
- api.fetchDocumentLibList();
|
|
|
|
|
- }else{
|
|
|
|
|
- api.fetchDocumentLibAllList();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ const init: DataExportStore['init'] = async () => {
|
|
|
|
|
+ // 获取聊天记录列表
|
|
|
|
|
+ await api.fetchChatHistoryList();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 状态重置
|
|
// 状态重置
|
|
|
- const reset = () => {
|
|
|
|
|
- const initialPageLoading = stateGenerator().pageLoading;
|
|
|
|
|
|
|
+ const reset: DataExportStore['reset'] = () => {
|
|
|
|
|
+ const initialQuery = stateGenerator().query;
|
|
|
|
|
+ const initialListLoading = stateGenerator().listLoading;
|
|
|
|
|
+ const initialList = stateGenerator().list;
|
|
|
const initialPage = stateGenerator().page;
|
|
const initialPage = stateGenerator().page;
|
|
|
|
|
|
|
|
- actions.setPageLoading(initialPageLoading);
|
|
|
|
|
- actions.setList([]);
|
|
|
|
|
- actions.setAppId('');
|
|
|
|
|
|
|
+ actions.setQuery(initialQuery);
|
|
|
|
|
+ actions.setListLoading(initialListLoading);
|
|
|
|
|
+ actions.setList(initialList);
|
|
|
actions.setPage(initialPage);
|
|
actions.setPage(initialPage);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
|
state,
|
|
state,
|
|
|
- init,
|
|
|
|
|
|
|
+ onClickSearch,
|
|
|
|
|
+ onClickReset,
|
|
|
onChangePagination,
|
|
onChangePagination,
|
|
|
|
|
+ onClickDownload,
|
|
|
|
|
+ init,
|
|
|
reset
|
|
reset
|
|
|
};
|
|
};
|
|
|
};
|
|
};
|