File size: 4,332 Bytes
97d4387 f422a06 fad2ec7 97d4387 eb8254e 97d4387 88e5a61 362ec6c fad2ec7 97d4387 f422a06 fad2ec7 f3dd131 04aba1b e4e6a45 97d4387 fad2ec7 362ec6c fad2ec7 f3dd131 04aba1b e4e6a45 97d4387 fad2ec7 362ec6c eb8254e 97d4387 eb8254e 97d4387 362ec6c fad2ec7 97d4387 fad2ec7 97d4387 04aba1b fad2ec7 eb8254e 97d4387 88e5a61 97d4387 362ec6c fad2ec7 362ec6c eb8254e 362ec6c fad2ec7 362ec6c eb8254e fad2ec7 04aba1b fad2ec7 362ec6c fad2ec7 eb8254e 04aba1b fad2ec7 04aba1b fad2ec7 eb8254e fad2ec7 eb8254e fad2ec7 eb8254e fad2ec7 362ec6c |
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 |
import { BaseState } from '@/interfaces/common';
import { IChunk, IKnowledgeFile } from '@/interfaces/database/knowledge';
import kbService from '@/services/kbService';
import { message } from 'antd';
import { pick } from 'lodash';
// import { delay } from '@/utils/storeUtil';
import i18n from '@/locales/config';
import { DvaModel } from 'umi';
export interface ChunkModelState extends BaseState {
data: IChunk[];
total: number;
isShowCreateModal: boolean;
chunk_id: string;
doc_id: string;
chunkInfo: any;
documentInfo: IKnowledgeFile;
available?: number;
}
const model: DvaModel<ChunkModelState> = {
namespace: 'chunkModel',
state: {
data: [],
total: 0,
isShowCreateModal: false,
chunk_id: '',
doc_id: '',
chunkInfo: {},
documentInfo: {} as IKnowledgeFile,
pagination: {
current: 1,
pageSize: 10,
},
searchString: '',
available: undefined, // set to undefined to select all
},
reducers: {
updateState(state, { payload }) {
return {
...state,
...payload,
};
},
setIsShowCreateModal(state, { payload }) {
return {
...state,
isShowCreateModal:
typeof payload === 'boolean' ? payload : !state.isShowCreateModal,
};
},
setAvailable(state, { payload }) {
return { ...state, available: payload };
},
setSearchString(state, { payload }) {
return { ...state, searchString: payload };
},
setPagination(state, { payload }) {
return { ...state, pagination: { ...state.pagination, ...payload } };
},
resetFilter(state, {}) {
return {
...state,
pagination: {
current: 1,
pageSize: 10,
},
searchString: '',
available: undefined,
};
},
},
effects: {
*chunk_list({ payload = {} }, { call, put, select }) {
const { available, searchString, pagination }: ChunkModelState =
yield select((state: any) => state.chunkModel);
const { data } = yield call(kbService.chunk_list, {
...payload,
available_int: available,
keywords: searchString,
page: pagination.current,
size: pagination.pageSize,
});
const { retcode, data: res } = data;
if (retcode === 0) {
yield put({
type: 'updateState',
payload: {
data: res.chunks,
total: res.total,
documentInfo: res.doc,
},
});
}
},
throttledGetChunkList: [
function* ({ payload }, { put }) {
yield put({ type: 'chunk_list', payload: { doc_id: payload } });
},
{ type: 'throttle', ms: 1000 }, // TODO: Provide type support for this effect
],
*switch_chunk({ payload = {} }, { call }) {
const { data } = yield call(kbService.switch_chunk, payload);
const { retcode } = data;
if (retcode === 0) {
message.success(i18n.t('message.modified'));
}
return retcode;
},
*rm_chunk({ payload = {} }, { call, put }) {
const { data } = yield call(kbService.rm_chunk, payload);
const { retcode } = data;
if (retcode === 0) {
yield put({
type: 'setIsShowCreateModal',
payload: false,
});
yield put({ type: 'setPagination', payload: { current: 1 } });
yield put({ type: 'chunk_list', payload: pick(payload, ['doc_id']) });
}
return retcode;
},
*get_chunk({ payload = {} }, { call, put }) {
const { data } = yield call(kbService.get_chunk, payload);
const { retcode, data: res } = data;
if (retcode === 0) {
yield put({
type: 'updateState',
payload: {
chunkInfo: res,
},
});
}
return data;
},
*create_chunk({ payload = {} }, { call, put }) {
let service = kbService.create_chunk;
if (payload.chunk_id) {
service = kbService.set_chunk;
}
const { data } = yield call(service, payload);
const { retcode } = data;
if (retcode === 0) {
yield put({
type: 'setIsShowCreateModal',
payload: false,
});
yield put({ type: 'chunk_list', payload: pick(payload, ['doc_id']) });
}
},
},
};
export default model;
|