File size: 4,636 Bytes
bd39551 8c06509 7c6cf75 dd4cbfc 7c6cf75 4056097 8c06509 bd39551 8c06509 bd39551 8c06509 bd39551 8c06509 4056097 8c06509 7c6cf75 8c06509 4056097 8c06509 bd39551 8c06509 bd39551 8c06509 bd39551 8c06509 4056097 7c6cf75 4056097 40a88fa bd39551 40a88fa bd39551 40a88fa 7c6cf75 40a88fa 4056097 8c06509 7c6cf75 4056097 8c06509 40a88fa 7c6cf75 40a88fa dd4cbfc 8c06509 bd39551 8c06509 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
import { paginationModel } from '@/base';
import { BaseState } from '@/interfaces/common';
import { IFile, IFolder } from '@/interfaces/database/file-manager';
import i18n from '@/locales/config';
import fileManagerService, {
getDocumentFile,
} from '@/services/fileManagerService';
import { message } from 'antd';
import omit from 'lodash/omit';
import { DvaModel } from 'umi';
export interface FileManagerModelState extends BaseState {
fileList: IFile[];
parentFolderList: IFolder[];
}
const model: DvaModel<FileManagerModelState> = {
namespace: 'fileManager',
state: {
fileList: [],
parentFolderList: [],
...(paginationModel.state as BaseState),
},
reducers: {
setFileList(state, { payload }) {
return { ...state, fileList: payload };
},
setParentFolderList(state, { payload }) {
return { ...state, parentFolderList: payload };
},
...paginationModel.reducers,
},
effects: {
*removeFile({ payload = {} }, { call, put }) {
const { data } = yield call(fileManagerService.removeFile, {
fileIds: payload.fileIds,
});
const { retcode } = data;
if (retcode === 0) {
message.success(i18n.t('message.deleted'));
yield put({
type: 'listFile',
payload: { parentId: payload.parentId },
});
}
return retcode;
},
*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 }) {
const { data } = yield call(
fileManagerService.renameFile,
omit(payload, ['parentId']),
);
if (data.retcode === 0) {
message.success(i18n.t('message.renamed'));
yield put({
type: 'listFile',
payload: { parentId: payload.parentId },
});
}
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);
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) {
message.success(i18n.t('message.uploaded'));
yield put({
type: 'listFile',
payload: { parentId: payload.parentId },
});
}
return data.retcode;
},
*createFolder({ payload = {} }, { call, put }) {
const { data } = yield call(fileManagerService.createFolder, payload);
if (data.retcode === 0) {
message.success(i18n.t('message.created'));
yield put({
type: 'listFile',
payload: { parentId: payload.parentId },
});
}
return data.retcode;
},
*getAllParentFolder({ payload = {} }, { call, put }) {
const { data } = yield call(
fileManagerService.getAllParentFolder,
payload,
);
if (data.retcode === 0) {
yield put({
type: 'setParentFolderList',
payload: data.data?.parent_folders ?? [],
});
}
return data.retcode;
},
*connectFileToKnowledge({ payload = {} }, { call, put }) {
const { data } = yield call(
fileManagerService.connectFileToKnowledge,
omit(payload, 'parentId'),
);
if (data.retcode === 0) {
message.success(i18n.t('message.operated'));
yield put({
type: 'listFile',
payload: { parentId: payload.parentId },
});
}
return data.retcode;
},
*getDocumentFile({ payload = {} }, { call }) {
const ret = yield call(getDocumentFile, payload);
return ret;
},
},
};
// const finalModel = modelExtend<DvaModel<FileManagerModelState & BaseState>>(
// paginationModel,
// model,
// );
// console.info(finalModel);
export default model;
|