feat(文件管理): 文件管理部分接口&部分组件调整&文件上传接口返回接口错误信息

This commit is contained in:
baiqi 2023-11-02 16:42:42 +08:00 committed by 刘瑞斌
parent d1ec8d00bc
commit 03109b9bff
9 changed files with 69 additions and 31 deletions

View File

@ -96,6 +96,13 @@ export class MSAxios {
const requestData = JSON.stringify(params.request); const requestData = JSON.stringify(params.request);
formData.append('request', new Blob([requestData], { type: ContentTypeEnum.JSON })); formData.append('request', new Blob([requestData], { type: ContentTypeEnum.JSON }));
} }
const transform = this.getTransform();
const { requestOptions } = this.options;
const opt = { ...requestOptions, isTransformResponse: false };
const { transformRequestHook } = transform || {};
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.axiosInstance this.axiosInstance
.request<any, AxiosResponse<Result>>({ .request<any, AxiosResponse<Result>>({
@ -109,11 +116,6 @@ export class MSAxios {
}, },
}) })
.then((res: AxiosResponse<Result>) => { .then((res: AxiosResponse<Result>) => {
const transform = this.getTransform();
const { requestOptions } = this.options;
const opt = { ...requestOptions };
const { transformRequestHook } = transform || {};
// 请求成功后的处理 // 请求成功后的处理
if (transformRequestHook && isFunction(transformRequestHook)) { if (transformRequestHook && isFunction(transformRequestHook)) {
try { try {

View File

@ -170,7 +170,7 @@ const transform: AxiosTransform = {
throw new Error(e as unknown as string); throw new Error(e as unknown as string);
} }
checkStatus(error?.response?.status, msg, errorMessageMode); checkStatus(error?.response?.status, msg, errorMessageMode);
return Promise.reject(error); return Promise.reject(error?.response?.data?.message);
}, },
}; };

View File

@ -295,7 +295,7 @@
* 处理树节点选中非复选框 * 处理树节点选中非复选框
*/ */
function select(selectedKeys: Array<string | number>, data: MsTreeSelectedData) { function select(selectedKeys: Array<string | number>, data: MsTreeSelectedData) {
emit('select', selectedKeys, data.selectedNodes); emit('select', selectedKeys, data.selectedNodes[0]);
} }
function checked(checkedKeys: Array<string | number>) { function checked(checkedKeys: Array<string | number>) {
@ -472,6 +472,19 @@
} }
} }
} }
.arco-tree-node-disabled {
&:hover {
background-color: transparent;
}
* {
color: var(--color-text-4) !important;
}
.arco-tree-node-title {
&:hover {
background-color: transparent;
}
}
}
} }
} }
</style> </style>

View File

@ -47,7 +47,7 @@
class="w-[200px]" class="w-[200px]"
/> />
<div v-else-if="item.status === UploadStatus.error" class="text-[rgb(var(--danger-6))]"> <div v-else-if="item.status === UploadStatus.error" class="text-[rgb(var(--danger-6))]">
{{ t('ms.upload.uploadFail') }} {{ item.errMsg || t('ms.upload.uploadFail') }}
</div> </div>
</template> </template>
</a-list-item-meta> </a-list-item-meta>

View File

@ -10,4 +10,5 @@ export type MsFileItem = FileItem & {
status?: keyof typeof UploadStatus; status?: keyof typeof UploadStatus;
enable?: boolean; // jar类型文件是否可用 enable?: boolean; // jar类型文件是否可用
uploadedTime?: string | number; // 上传完成时间 uploadedTime?: string | number; // 上传完成时间
errMsg?: string; // 上传失败的错误信息
}; };

View File

@ -197,6 +197,7 @@ const useAsyncTaskStore = defineStore('asyncTask', {
console.log(error); console.log(error);
if (fileItem) { if (fileItem) {
fileItem.status = UploadStatus.error; fileItem.status = UploadStatus.error;
fileItem.errMsg = error as string;
} }
} finally { } finally {
// 上传完成/失败,重置进度和定时器 // 上传完成/失败,重置进度和定时器

View File

@ -77,12 +77,7 @@
import type { MsTreeNodeData } from '@/components/business/ms-tree/types'; import type { MsTreeNodeData } from '@/components/business/ms-tree/types';
import popConfirm from './popConfirm.vue'; import popConfirm from './popConfirm.vue';
import { import { deleteModule, getModules, moveModule } from '@/api/modules/project-management/fileManagement';
deleteModule,
getModules,
getModulesCount,
moveModule,
} from '@/api/modules/project-management/fileManagement';
import { useI18n } from '@/hooks/useI18n'; import { useI18n } from '@/hooks/useI18n';
import useModal from '@/hooks/useModal'; import useModal from '@/hooks/useModal';
import useAppStore from '@/store/modules/app'; import useAppStore from '@/store/modules/app';
@ -92,6 +87,7 @@
const props = defineProps<{ const props = defineProps<{
isExpandAll: boolean; isExpandAll: boolean;
activeFolder?: string; // 使
selectedKeys?: Array<string | number>; // key selectedKeys?: Array<string | number>; // key
isModal?: boolean; // isModal?: boolean; //
modulesCount?: Record<string, number>; // modulesCount?: Record<string, number>; //
@ -158,11 +154,14 @@
try { try {
loading.value = true; loading.value = true;
const res = await getModules(appStore.currentProjectId); const res = await getModules(appStore.currentProjectId);
folderTree.value = res.map((e) => ({ folderTree.value = mapTree<ModuleTreeNode>(res, (e) => {
return {
...e, ...e,
hideMoreAction: e.id === 'root', hideMoreAction: e.id === 'root',
draggable: e.id !== 'root' && !props.isModal, draggable: e.id !== 'root' && !props.isModal,
})); disabled: e.id === props.activeFolder && props.isModal,
};
});
if (isSetDefaultKey) { if (isSetDefaultKey) {
selectedKeys.value = [folderTree.value[0].id]; selectedKeys.value = [folderTree.value[0].id];
} }
@ -217,8 +216,14 @@
/** /**
* 处理文件夹树节点选中事件 * 处理文件夹树节点选中事件
*/ */
function folderNodeSelect(_selectedKeys: (string | number)[]) { function folderNodeSelect(_selectedKeys: (string | number)[], node: MsTreeNodeData) {
emit('folderNodeSelect', _selectedKeys); const offspringIds: string[] = [];
mapTree(node.children || [], (e) => {
offspringIds.push(e.id);
return e;
});
emit('folderNodeSelect', _selectedKeys, offspringIds);
} }
/** /**

View File

@ -249,15 +249,16 @@
</div> </div>
</div> </div>
</template> </template>
<folderTree <FolderTree
v-if="moveModalVisible" v-if="moveModalVisible"
v-model:selected-keys="selectedModuleKeys" v-model:selected-keys="selectedModuleKeys"
:is-expand-all="true" :is-expand-all="true"
:active-folder="props.activeFolder"
is-modal is-modal
@folder-node-select="folderNodeSelect" @folder-node-select="folderNodeSelect"
/> />
</a-modal> </a-modal>
<fileDetailDrawerVue <FileDetailDrawer
v-model:visible="showDetailDrawer" v-model:visible="showDetailDrawer"
:file-id="activeFileId" :file-id="activeFileId"
:active-file-index="activeFileIndex" :active-file-index="activeFileIndex"
@ -287,8 +288,8 @@
import MsCardList from '@/components/business/ms-card-list/index.vue'; import MsCardList from '@/components/business/ms-card-list/index.vue';
import MsFormItemSub from '@/components/business/ms-form-item-sub/index.vue'; import MsFormItemSub from '@/components/business/ms-form-item-sub/index.vue';
import MsThumbnailCard from '@/components/business/ms-thumbnail-card/index.vue'; import MsThumbnailCard from '@/components/business/ms-thumbnail-card/index.vue';
import fileDetailDrawerVue from './fileDetailDrawer.vue'; import FileDetailDrawer from './fileDetailDrawer.vue';
import folderTree from './folderTree.vue'; import FolderTree from './folderTree.vue';
import { import {
batchDownloadFile, batchDownloadFile,
@ -298,7 +299,6 @@
getFileList, getFileList,
getFileTypes, getFileTypes,
toggleJarFileStatus, toggleJarFileStatus,
updateFile,
uploadFile, uploadFile,
} from '@/api/modules/project-management/fileManagement'; } from '@/api/modules/project-management/fileManagement';
import { CompressImgUrl } from '@/api/requrls/project-management/fileManagement'; import { CompressImgUrl } from '@/api/requrls/project-management/fileManagement';
@ -320,6 +320,7 @@
const props = defineProps<{ const props = defineProps<{
activeFolder: string; activeFolder: string;
activeFolderType: 'folder' | 'module' | 'storage'; activeFolderType: 'folder' | 'module' | 'storage';
offspringIds: string[]; // id
}>(); }>();
const emit = defineEmits<{ const emit = defineEmits<{
(e: 'init', params: FileListQueryParams): void; (e: 'init', params: FileListQueryParams): void;
@ -466,7 +467,7 @@
]; ];
const tableStore = useTableStore(); const tableStore = useTableStore();
tableStore.initColumn(TableKeyEnum.FILE_MANAGEMENT_FILE, columns, 'drawer'); tableStore.initColumn(TableKeyEnum.FILE_MANAGEMENT_FILE, columns, 'drawer');
const { propsRes, propsEvent, loadList, setLoadListParams } = useTable( const { propsRes, propsEvent, loadList, setLoadListParams, resetSelector } = useTable(
getFileList, getFileList,
{ {
tableKey: TableKeyEnum.FILE_MANAGEMENT_FILE, tableKey: TableKeyEnum.FILE_MANAGEMENT_FILE,
@ -543,6 +544,7 @@
moduleIds: [props.activeFolder], moduleIds: [props.activeFolder],
}); });
downloadByteFile(res, 'files.zip'); downloadByteFile(res, 'files.zip');
resetSelector();
} catch (error) { } catch (error) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log(error); console.log(error);
@ -608,6 +610,7 @@
cardListRef.value?.reload(); cardListRef.value?.reload();
} else { } else {
loadList(); loadList();
resetSelector();
} }
emitTableParams(); emitTableParams();
} catch (error) { } catch (error) {
@ -620,7 +623,7 @@
} }
const moveModalVisible = ref(false); // const moveModalVisible = ref(false); //
const selectedModuleKeys = ref<(string | number)[]>([]); // const selectedModuleKeys = ref<(string | number)[]>([]); //
const isBatchMove = ref(false); // const isBatchMove = ref(false); //
const activeFile = ref<FileItem | null>(null); // const activeFile = ref<FileItem | null>(null); //
@ -682,6 +685,7 @@
cardListRef.value?.reload(); cardListRef.value?.reload();
} else { } else {
loadList(); loadList();
resetSelector();
} }
emitTableParams(); emitTableParams();
} catch (error) { } catch (error) {
@ -704,10 +708,14 @@
if (fileType.value === 'storage') { if (fileType.value === 'storage') {
combine.value.storage = 'git'; combine.value.storage = 'git';
} }
let moduleIds: string[] = [props.activeFolder, ...props.offspringIds];
if (['all', 'my'].includes(props.activeFolder)) {
moduleIds = [];
}
setLoadListParams({ setLoadListParams({
keyword: keyword.value, keyword: keyword.value,
fileType: tableFileType.value, fileType: tableFileType.value,
moduleIds: ['all', 'my'].includes(props.activeFolder) ? [] : [props.activeFolder], moduleIds,
projectId: appStore.currentProjectId, projectId: appStore.currentProjectId,
comebine: combine.value, comebine: combine.value,
}); });
@ -745,6 +753,7 @@
() => { () => {
keyword.value = ''; keyword.value = '';
searchList(); searchList();
resetSelector();
}, },
{ immediate: true } { immediate: true }
); );

View File

@ -72,7 +72,12 @@
</div> </div>
</template> </template>
<template #right> <template #right>
<rightBox :active-folder="activeFolder" :active-folder-type="activeFolderType" @init="handleModuleTableInit" /> <rightBox
:active-folder="activeFolder"
:active-folder-type="activeFolderType"
:offspring-ids="offspringIds"
@init="handleModuleTableInit"
/>
</template> </template>
</MsSplitBox> </MsSplitBox>
</div> </div>
@ -127,6 +132,7 @@
get: () => [activeFolder.value], get: () => [activeFolder.value],
set: (val) => val, set: (val) => val,
}); });
const offspringIds = ref<string[]>([]);
function setActiveFolder(id: string) { function setActiveFolder(id: string) {
activeFolder.value = id; activeFolder.value = id;
@ -151,9 +157,10 @@
/** /**
* 处理文件夹树节点选中事件 * 处理文件夹树节点选中事件
*/ */
function folderNodeSelect(keys: string[]) { function folderNodeSelect(keys: string[], _offspringIds: string[]) {
[activeFolder.value] = keys; [activeFolder.value] = keys;
activeFolderType.value = 'module'; activeFolderType.value = 'module';
offspringIds.value = [..._offspringIds];
} }
/** /**