feat: add file icon to table of FileManager #345 (#543)

### What problem does this PR solve?

feat: add file icon to table of FileManager #345
fix: modify datasetDescription

### Type of change

- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2024-04-25 19:06:24 +08:00
committed by GitHub
parent 26003b5076
commit 1dcd439c58
19 changed files with 317 additions and 154 deletions

View File

@ -1,16 +1,22 @@
import { paginationModel } from '@/base';
import { BaseState } from '@/interfaces/common';
import { IFile, IFolder } from '@/interfaces/database/file-manager';
import fileManagerService from '@/services/fileManagerService';
import omit from 'lodash/omit';
import { DvaModel } from 'umi';
export interface FileManagerModelState {
export interface FileManagerModelState extends BaseState {
fileList: IFile[];
parentFolderList: IFolder[];
}
const model: DvaModel<FileManagerModelState> = {
namespace: 'fileManager',
state: { fileList: [], parentFolderList: [] },
state: {
fileList: [],
parentFolderList: [],
...(paginationModel.state as BaseState),
},
reducers: {
setFileList(state, { payload }) {
return { ...state, fileList: payload };
@ -18,6 +24,7 @@ const model: DvaModel<FileManagerModelState> = {
setParentFolderList(state, { payload }) {
return { ...state, parentFolderList: payload };
},
...paginationModel.reducers,
},
effects: {
*removeFile({ payload = {} }, { call, put }) {
@ -31,16 +38,29 @@ const model: DvaModel<FileManagerModelState> = {
payload: { parentId: payload.parentId },
});
}
return retcode;
},
*listFile({ payload = {} }, { call, put }) {
const { data } = yield call(fileManagerService.listFile, payload);
*listFile({ payload = {} }, { call, put, select }) {
const { searchString, pagination } = yield select(
(state: any) => state.fileManager,
);
const { current, pageSize } = pagination;
const { data } = yield call(fileManagerService.listFile, {
...payload,
keywords: searchString.trim(),
page: current,
pageSize,
});
const { retcode, data: res } = data;
if (retcode === 0 && Array.isArray(res.files)) {
yield put({
type: 'setFileList',
payload: res.files,
});
yield put({
type: 'setPagination',
payload: { total: res.total },
});
}
},
*renameFile({ payload = {} }, { call, put }) {
@ -57,10 +77,16 @@ const model: DvaModel<FileManagerModelState> = {
return data.retcode;
},
*uploadFile({ payload = {} }, { call, put }) {
const fileList = payload.file;
const pathList = payload.path;
const formData = new FormData();
formData.append('parent_id', payload.parentId);
formData.append('file', payload.file);
formData.append('path', payload.path);
// formData.append('file', payload.file);
// formData.append('path', payload.path);
fileList.forEach((file: any, index: number) => {
formData.append('file', file);
formData.append('path', pathList[index]);
});
const { data } = yield call(fileManagerService.uploadFile, formData);
if (data.retcode === 0) {
yield put({
@ -108,4 +134,12 @@ const model: DvaModel<FileManagerModelState> = {
},
},
};
// const finalModel = modelExtend<DvaModel<FileManagerModelState & BaseState>>(
// paginationModel,
// model,
// );
// console.info(finalModel);
export default model;