1、文档选择添加公共库
This commit is contained in:
@@ -492,6 +492,7 @@
|
||||
ref="fileModal"
|
||||
:current-company-id="currentCompanyId"
|
||||
:selection-key="currentFileSelectionKey"
|
||||
:selection-state="getTableFileSelection(currentFileSelectionKey)"
|
||||
@confirm="handleFileSelectConfirm"
|
||||
/>
|
||||
<HistoryModal
|
||||
@@ -556,6 +557,75 @@
|
||||
hasContent
|
||||
} from './data/funcs';
|
||||
|
||||
type SelectionKey = string | number;
|
||||
type DocSourceType = 'company' | 'public';
|
||||
type DirFileSelectionMap = Record<string, SelectionKey[]>;
|
||||
type SourceSelectionState = {
|
||||
dirKeys: SelectionKey[];
|
||||
fileKeys: SelectionKey[];
|
||||
currentDirKey?: SelectionKey;
|
||||
dirFileSelections: DirFileSelectionMap;
|
||||
};
|
||||
type TableFileSelectionState = {
|
||||
activeSource: DocSourceType;
|
||||
company: SourceSelectionState;
|
||||
public: SourceSelectionState;
|
||||
dirKeys: SelectionKey[];
|
||||
fileKeys: SelectionKey[];
|
||||
};
|
||||
|
||||
const dedupeSelectionKeys = (keys: SelectionKey[] = []) => {
|
||||
return Array.from(
|
||||
new Set(keys.filter((key) => key !== undefined && key !== null))
|
||||
);
|
||||
};
|
||||
|
||||
const cloneDirFileSelections = (
|
||||
dirFileSelections?: DirFileSelectionMap
|
||||
): DirFileSelectionMap => {
|
||||
return Object.fromEntries(
|
||||
Object.entries(dirFileSelections || {}).map(([key, value]) => [
|
||||
key,
|
||||
[...value]
|
||||
])
|
||||
);
|
||||
};
|
||||
|
||||
const cloneSourceSelectionState = (
|
||||
state?: Partial<SourceSelectionState>
|
||||
): SourceSelectionState => {
|
||||
return {
|
||||
dirKeys: dedupeSelectionKeys([...(state?.dirKeys || [])]),
|
||||
fileKeys: dedupeSelectionKeys([...(state?.fileKeys || [])]),
|
||||
currentDirKey: state?.currentDirKey,
|
||||
dirFileSelections: cloneDirFileSelections(state?.dirFileSelections)
|
||||
};
|
||||
};
|
||||
|
||||
const normalizeTableFileSelection = (
|
||||
selection?: Partial<TableFileSelectionState>
|
||||
): TableFileSelectionState => {
|
||||
const hasSourceState = !!(selection?.company || selection?.public);
|
||||
const company = cloneSourceSelectionState(selection?.company);
|
||||
const publicState = cloneSourceSelectionState(selection?.public);
|
||||
|
||||
if (!hasSourceState) {
|
||||
company.dirKeys = dedupeSelectionKeys([...(selection?.dirKeys || [])]);
|
||||
company.fileKeys = dedupeSelectionKeys([...(selection?.fileKeys || [])]);
|
||||
}
|
||||
|
||||
return {
|
||||
activeSource: selection?.activeSource === 'public' ? 'public' : 'company',
|
||||
company,
|
||||
public: publicState,
|
||||
dirKeys: dedupeSelectionKeys([...company.dirKeys, ...publicState.dirKeys]),
|
||||
fileKeys: dedupeSelectionKeys([
|
||||
...company.fileKeys,
|
||||
...publicState.fileKeys
|
||||
])
|
||||
};
|
||||
};
|
||||
|
||||
const useForm = Form.useForm;
|
||||
|
||||
const props = defineProps<{
|
||||
@@ -602,16 +672,10 @@
|
||||
const currentFileSelectionKey = ref('');
|
||||
const selectedDocList = ref<string[]>([]);
|
||||
const selectedFileList = ref<string[]>([]);
|
||||
const selectedFileKeys = ref<(string | number)[]>([]);
|
||||
const checkedDirKeys = ref<(string | number)[]>([]);
|
||||
const selectedFileKeys = ref<SelectionKey[]>([]);
|
||||
const checkedDirKeys = ref<SelectionKey[]>([]);
|
||||
const tableFileSelectionMap = reactive<
|
||||
Record<
|
||||
string,
|
||||
{
|
||||
dirKeys: (string | number)[];
|
||||
fileKeys: (string | number)[];
|
||||
}
|
||||
>
|
||||
Record<string, TableFileSelectionState>
|
||||
>({});
|
||||
|
||||
// ========== 取证单相关 ==========
|
||||
@@ -704,12 +768,7 @@
|
||||
};
|
||||
|
||||
const getTableFileSelection = (tableKey: string) => {
|
||||
return (
|
||||
tableFileSelectionMap[tableKey] || {
|
||||
dirKeys: [],
|
||||
fileKeys: []
|
||||
}
|
||||
);
|
||||
return normalizeTableFileSelection(tableFileSelectionMap[tableKey]);
|
||||
};
|
||||
|
||||
const applyTableFileSelection = (tableKey: string) => {
|
||||
@@ -722,13 +781,9 @@
|
||||
|
||||
const saveTableFileSelection = (
|
||||
tableKey: string,
|
||||
dirKeys: (string | number)[] = [],
|
||||
fileKeys: (string | number)[] = []
|
||||
selection?: Partial<TableFileSelectionState>
|
||||
) => {
|
||||
tableFileSelectionMap[tableKey] = {
|
||||
dirKeys: [...dirKeys],
|
||||
fileKeys: [...fileKeys]
|
||||
};
|
||||
tableFileSelectionMap[tableKey] = normalizeTableFileSelection(selection);
|
||||
};
|
||||
|
||||
// ========== 通用方法 ==========
|
||||
@@ -777,13 +832,9 @@
|
||||
};
|
||||
|
||||
/* 处理文件选择确认 */
|
||||
const handleFileSelectConfirm = (data: { dirKeys: (string | number)[], fileKeys: (string | number)[] }) => {
|
||||
const handleFileSelectConfirm = (data: TableFileSelectionState) => {
|
||||
if (currentFileSelectionKey.value) {
|
||||
saveTableFileSelection(
|
||||
currentFileSelectionKey.value,
|
||||
data.dirKeys,
|
||||
data.fileKeys
|
||||
);
|
||||
saveTableFileSelection(currentFileSelectionKey.value, data);
|
||||
}
|
||||
|
||||
checkedDirKeys.value = data.dirKeys;
|
||||
@@ -1438,8 +1489,12 @@
|
||||
saveTableGenerationData(tableKey, requestData, responseData, interfaceName);
|
||||
saveTableFileSelection(
|
||||
tableKey,
|
||||
Array.isArray(requestData?.docList) ? requestData.docList : [],
|
||||
Array.isArray(requestData?.fileList) ? requestData.fileList : []
|
||||
requestData?.fileSelectionState || {
|
||||
dirKeys: Array.isArray(requestData?.docList) ? requestData.docList : [],
|
||||
fileKeys: Array.isArray(requestData?.fileList)
|
||||
? requestData.fileList
|
||||
: []
|
||||
}
|
||||
);
|
||||
|
||||
// 使用数据映射函数
|
||||
@@ -1877,7 +1932,8 @@
|
||||
const normalizedRequestData = {
|
||||
...(generationData.requestData || {}),
|
||||
docList: [...currentSelection.dirKeys],
|
||||
fileList: [...currentSelection.fileKeys]
|
||||
fileList: [...currentSelection.fileKeys],
|
||||
fileSelectionState: normalizeTableFileSelection(currentSelection)
|
||||
};
|
||||
|
||||
const aiHistory = {
|
||||
|
||||
Reference in New Issue
Block a user