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);
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) => {
this.axiosInstance
.request<any, AxiosResponse<Result>>({
@ -109,11 +116,6 @@ export class MSAxios {
},
})
.then((res: AxiosResponse<Result>) => {
const transform = this.getTransform();
const { requestOptions } = this.options;
const opt = { ...requestOptions };
const { transformRequestHook } = transform || {};
// 请求成功后的处理
if (transformRequestHook && isFunction(transformRequestHook)) {
try {

View File

@ -170,7 +170,7 @@ const transform: AxiosTransform = {
throw new Error(e as unknown as string);
}
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) {
emit('select', selectedKeys, data.selectedNodes);
emit('select', selectedKeys, data.selectedNodes[0]);
}
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>

View File

@ -47,7 +47,7 @@
class="w-[200px]"
/>
<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>
</template>
</a-list-item-meta>

View File

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

View File

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

View File

@ -77,12 +77,7 @@
import type { MsTreeNodeData } from '@/components/business/ms-tree/types';
import popConfirm from './popConfirm.vue';
import {
deleteModule,
getModules,
getModulesCount,
moveModule,
} from '@/api/modules/project-management/fileManagement';
import { deleteModule, getModules, moveModule } from '@/api/modules/project-management/fileManagement';
import { useI18n } from '@/hooks/useI18n';
import useModal from '@/hooks/useModal';
import useAppStore from '@/store/modules/app';
@ -92,6 +87,7 @@
const props = defineProps<{
isExpandAll: boolean;
activeFolder?: string; // 使
selectedKeys?: Array<string | number>; // key
isModal?: boolean; //
modulesCount?: Record<string, number>; //
@ -158,11 +154,14 @@
try {
loading.value = true;
const res = await getModules(appStore.currentProjectId);
folderTree.value = res.map((e) => ({
...e,
hideMoreAction: e.id === 'root',
draggable: e.id !== 'root' && !props.isModal,
}));
folderTree.value = mapTree<ModuleTreeNode>(res, (e) => {
return {
...e,
hideMoreAction: e.id === 'root',
draggable: e.id !== 'root' && !props.isModal,
disabled: e.id === props.activeFolder && props.isModal,
};
});
if (isSetDefaultKey) {
selectedKeys.value = [folderTree.value[0].id];
}
@ -217,8 +216,14 @@
/**
* 处理文件夹树节点选中事件
*/
function folderNodeSelect(_selectedKeys: (string | number)[]) {
emit('folderNodeSelect', _selectedKeys);
function folderNodeSelect(_selectedKeys: (string | number)[], node: MsTreeNodeData) {
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>
</template>
<folderTree
<FolderTree
v-if="moveModalVisible"
v-model:selected-keys="selectedModuleKeys"
:is-expand-all="true"
:active-folder="props.activeFolder"
is-modal
@folder-node-select="folderNodeSelect"
/>
</a-modal>
<fileDetailDrawerVue
<FileDetailDrawer
v-model:visible="showDetailDrawer"
:file-id="activeFileId"
:active-file-index="activeFileIndex"
@ -287,8 +288,8 @@
import MsCardList from '@/components/business/ms-card-list/index.vue';
import MsFormItemSub from '@/components/business/ms-form-item-sub/index.vue';
import MsThumbnailCard from '@/components/business/ms-thumbnail-card/index.vue';
import fileDetailDrawerVue from './fileDetailDrawer.vue';
import folderTree from './folderTree.vue';
import FileDetailDrawer from './fileDetailDrawer.vue';
import FolderTree from './folderTree.vue';
import {
batchDownloadFile,
@ -298,7 +299,6 @@
getFileList,
getFileTypes,
toggleJarFileStatus,
updateFile,
uploadFile,
} from '@/api/modules/project-management/fileManagement';
import { CompressImgUrl } from '@/api/requrls/project-management/fileManagement';
@ -320,6 +320,7 @@
const props = defineProps<{
activeFolder: string;
activeFolderType: 'folder' | 'module' | 'storage';
offspringIds: string[]; // id
}>();
const emit = defineEmits<{
(e: 'init', params: FileListQueryParams): void;
@ -466,7 +467,7 @@
];
const tableStore = useTableStore();
tableStore.initColumn(TableKeyEnum.FILE_MANAGEMENT_FILE, columns, 'drawer');
const { propsRes, propsEvent, loadList, setLoadListParams } = useTable(
const { propsRes, propsEvent, loadList, setLoadListParams, resetSelector } = useTable(
getFileList,
{
tableKey: TableKeyEnum.FILE_MANAGEMENT_FILE,
@ -543,6 +544,7 @@
moduleIds: [props.activeFolder],
});
downloadByteFile(res, 'files.zip');
resetSelector();
} catch (error) {
// eslint-disable-next-line no-console
console.log(error);
@ -608,6 +610,7 @@
cardListRef.value?.reload();
} else {
loadList();
resetSelector();
}
emitTableParams();
} catch (error) {
@ -620,7 +623,7 @@
}
const moveModalVisible = ref(false); //
const selectedModuleKeys = ref<(string | number)[]>([]); //
const selectedModuleKeys = ref<(string | number)[]>([]); //
const isBatchMove = ref(false); //
const activeFile = ref<FileItem | null>(null); //
@ -682,6 +685,7 @@
cardListRef.value?.reload();
} else {
loadList();
resetSelector();
}
emitTableParams();
} catch (error) {
@ -704,10 +708,14 @@
if (fileType.value === 'storage') {
combine.value.storage = 'git';
}
let moduleIds: string[] = [props.activeFolder, ...props.offspringIds];
if (['all', 'my'].includes(props.activeFolder)) {
moduleIds = [];
}
setLoadListParams({
keyword: keyword.value,
fileType: tableFileType.value,
moduleIds: ['all', 'my'].includes(props.activeFolder) ? [] : [props.activeFolder],
moduleIds,
projectId: appStore.currentProjectId,
comebine: combine.value,
});
@ -745,6 +753,7 @@
() => {
keyword.value = '';
searchList();
resetSelector();
},
{ immediate: true }
);

View File

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