feat(文件管理): 文件管理部分接口&部分组件调整&无权限登录无限重定向问题解决

This commit is contained in:
baiqi 2023-11-02 10:13:03 +08:00 committed by rubylliu
parent 1514ab80db
commit eb9e4253e7
8 changed files with 120 additions and 52 deletions

View File

@ -129,11 +129,11 @@
// 01
const activeDetailIsFirst = computed(() => activeDetailIndex.value === 0 && props.pagination?.current === 1);
const activeDetailIsLast = computed(
// *+
// (-1)*+
() =>
activeDetailIndex.value === props.tableData.length - 1 &&
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
props.pagination!.current * props.pagination!.pageSize + activeDetailIndex.value >=
(props.pagination!.current - 1) * props.pagination!.pageSize + (activeDetailIndex.value + 1) >=
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
props.pagination!.total
);
@ -158,6 +158,7 @@
activeDetailId.value = props.tableData[activeDetailIndex.value - 1].id;
activeDetailIndex.value -= 1;
}
initDetail();
}
}
@ -181,13 +182,16 @@
activeDetailId.value = props.tableData[activeDetailIndex.value + 1].id;
activeDetailIndex.value += 1;
}
initDetail();
}
}
watch(
() => activeDetailId.value,
() => {
initDetail();
() => innerVisible.value,
(val) => {
if (val) {
initDetail();
}
}
);

View File

@ -1,11 +1,12 @@
<template>
<div
:class="`ms-button ms-button-${props.type} ms-button--${props.status} ${
props.disabled ? 'ms-button--disabled' : ''
props.disabled || props.loading ? 'ms-button--disabled' : ''
}`"
@click="clickHandler"
>
<slot></slot>
<icon-loading v-if="props.loading" />
</div>
</template>
@ -15,6 +16,7 @@
type?: 'text' | 'icon' | 'button';
status?: 'primary' | 'danger' | 'secondary';
disabled?: boolean;
loading?: boolean;
}>(),
{
type: 'text',

View File

@ -22,11 +22,13 @@
<slot name="item-value" :item="item">
<template v-if="item.isTag">
<MsTag
v-for="tag of item.value"
v-for="tag of Array.isArray(item.value) ? item.value : [item.value]"
:key="`${tag}`"
theme="outline"
color="var(--color-text-n8)"
class="mb-[8px] mr-[8px] font-normal !text-[var(--color-text-1)]"
:closable="item.closable"
@close="emit('tagClose', tag, item)"
>
{{ tag }}
</MsTag>
@ -106,6 +108,7 @@
value: (string | number) | (string | number)[];
key?: string;
isTag?: boolean; //
closable?: boolean; //
showTagAdd?: boolean; //
isButton?: boolean;
showCopy?: boolean;
@ -120,7 +123,7 @@
column?: number;
descriptions: Description[];
labelWidth?: string;
addTagFunc?: (val: string) => Promise<void>;
addTagFunc?: (val: string, item: Description) => Promise<void>;
}>(),
{
column: 1,
@ -128,6 +131,7 @@
);
const emit = defineEmits<{
(e: 'addTag', val: string): void;
(e: 'tagClose', tag: string | number, item: Description): void;
}>();
const { t } = useI18n();
@ -163,6 +167,10 @@
* @param item 当前标签项
*/
async function handleAddTag(item: Description) {
if (addTagInput.value.trim() === '') {
showTagInput.value = false;
return;
}
if (Array.isArray(item.value) && item.value.includes(addTagInput.value)) {
tagInputError.value = t('ms.description.addTagRepeat');
return;
@ -171,7 +179,7 @@
try {
tagInputLoading.value = true;
if (props.addTagFunc && typeof props.addTagFunc === 'function') {
await props.addTagFunc(addTagInput.value);
await props.addTagFunc(addTagInput.value, item);
if (Array.isArray(item.value)) {
item.value.push(addTagInput.value);
} else {
@ -180,6 +188,7 @@
} else {
emit('addTag', addTagInput.value);
}
addTagInput.value = '';
showTagInput.value = false;
} catch (error) {
// eslint-disable-next-line no-console

View File

@ -3,17 +3,18 @@
v-bind="attrs"
:type="props.type"
defer
:size="props.size"
:style="{
...typeStyle,
'margin-right': tagMargin,
'min-width': props.width && `${props.width}ch`,
'max-width: 144px': !props.width,
'max-width': '144px',
}"
:size="props.size"
class="inline-block"
>
<slot name="icon"></slot>
<slot></slot>
<div class="one-line-text">
<slot></slot>
</div>
</a-tag>
</template>

View File

@ -28,6 +28,7 @@ export interface FileDetail extends FileItem {
projectId: string;
moduleName: string; // 所属模块名
moduleId: string;
storage?: string; // 存储方式
createUser: string;
createTime: number;
}
@ -43,7 +44,7 @@ export interface UploadFileParams {
export interface UpdateFileParams {
id: string;
name?: string;
tags?: string[];
tags?: (string | number)[];
description?: string;
moduleId?: string;
}

View File

@ -28,7 +28,7 @@ function setupPageGuard(router: Router) {
}
switch (getRouteLevelByKey(to.name as PathMapRoute)) {
case MENU_LEVEL[1]: // 组织级别的页面,需要给页面携带上组织 ID
if (!urlOrgId) {
if (urlOrgId === undefined) {
to.query = {
...to.query,
organizationId: appStore.currentOrgId,
@ -38,7 +38,7 @@ function setupPageGuard(router: Router) {
}
break;
case MENU_LEVEL[2]: // 项目级别的页面,需要给页面携带上组织 ID和项目 ID
if (!urlOrgId && !urlProjectId) {
if (urlOrgId === undefined && urlProjectId === undefined) {
to.query = {
...to.query,
organizationId: appStore.currentOrgId,

View File

@ -16,7 +16,7 @@
<template #titleRight="{ loading, detail }">
<a-switch
v-if="fileType === 'jar'"
:default-checked="detail?.enable"
v-model:model-value="detail.enable"
:before-change="handleEnableIntercept"
:disabled="loading"
size="small"
@ -27,7 +27,8 @@
status="secondary"
class="!rounded-[var(--border-radius-small)] !text-[var(--color-text-1)]"
:disabled="loading"
@click="handleDownload"
:loading="downLoading"
@click="handleDownload(detail)"
>
<MsIcon type="icon-icon_bottom-align_outlined" class="mr-[4px]" />
{{ t('project.fileManagement.download') }}
@ -71,6 +72,7 @@
:descriptions="fileDescriptions"
:label-width="currentLocale === 'zh-CN' ? '80px' : '100px'"
:add-tag-func="addFileTag"
@tag-close="handleFileTagClose"
>
<template #value="{ item }">
<div class="flex flex-wrap items-center">
@ -197,13 +199,20 @@
import MsThumbnailCard from '@/components/business/ms-thumbnail-card/index.vue';
import popConfirm from './popConfirm.vue';
import { getFileDetail, reuploadFile, updateFile } from '@/api/modules/project-management/fileManagement';
import {
downloadFile,
getFileDetail,
reuploadFile,
toggleJarFileStatus,
updateFile,
} from '@/api/modules/project-management/fileManagement';
import { CompressImgUrl, OriginImgUrl } from '@/api/requrls/project-management/fileManagement';
import { useI18n } from '@/hooks/useI18n';
import useLocale from '@/locale/useLocale';
import useUserStore from '@/store/modules/user';
import { downloadUrlFile, formatFileSize } from '@/utils';
import { downloadByteFile, downloadUrlFile, formatFileSize } from '@/utils';
import { FileDetail } from '@/models/projectManagement/file';
import { TableKeyEnum } from '@/enums/tableEnum';
const props = defineProps<{
@ -241,22 +250,38 @@
);
async function handleEnableIntercept(newValue: string | number | boolean) {
await new Promise((resolve) => {
setTimeout(() => {
resolve(true);
}, 1000);
});
return true;
try {
await toggleJarFileStatus(props.fileId, newValue as boolean);
return true;
} catch (error) {
// eslint-disable-next-line no-console
console.log(error);
return false;
}
}
function handleDownload(detail: any) {
downloadUrlFile(detail.url, detail.name);
const downLoading = ref(false);
/**
* 下载单个文件
* @param record 表格数据项
*/
async function handleDownload(detail: FileDetail) {
try {
downLoading.value = true;
const res = await downloadFile(detail.id);
downloadByteFile(res, `${detail.name}.${detail.fileType}`);
} catch (error) {
// eslint-disable-next-line no-console
console.log(error);
} finally {
downLoading.value = false;
}
}
const fileType = ref('unknown');
const renameTitle = ref(''); //
function loadedFile(detail: any) {
function loadedFile(detail: FileDetail) {
if (detail.fileType) {
fileType.value = getFileEnum(`/${detail.fileType.toLowerCase()}`);
}
@ -269,7 +294,7 @@
},
{
label: t('project.fileManagement.desc'),
value: detail.desc,
value: detail.description,
key: 'desc',
},
{
@ -291,9 +316,10 @@
},
{
label: t('project.fileManagement.tag'),
value: detail.tag,
value: detail.tags,
isTag: true,
showTagAdd: true,
closable: true,
key: 'tag',
},
{
@ -306,18 +332,18 @@
3,
0,
...[
{
label: t('project.fileManagement.gitBranch'),
value: detail.gitBranch,
},
{
label: t('project.fileManagement.gitPath'),
value: detail.gitPath,
},
{
label: t('project.fileManagement.gitVersion'),
value: detail.gitVersion,
},
// {
// label: t('project.fileManagement.gitBranch'),
// value: detail.gitBranch,
// },
// {
// label: t('project.fileManagement.gitPath'),
// value: detail.gitPath,
// },
// {
// label: t('project.fileManagement.gitVersion'),
// value: detail.gitVersion,
// },
]
);
}
@ -359,10 +385,17 @@
const previewVisible = ref(false);
async function addFileTag(val: string) {
async function addFileTag(val: string, item: Description) {
await updateFile({
id: props.fileId,
tags: [val],
tags: Array.isArray(item.value) ? [...item.value, val] : [item.value, val],
});
}
async function handleFileTagClose(tag: string | number, item: Description) {
await updateFile({
id: props.fileId,
tags: Array.isArray(item.value) ? item.value.filter((e) => e !== tag) : [],
});
}

View File

@ -466,12 +466,21 @@
];
const tableStore = useTableStore();
tableStore.initColumn(TableKeyEnum.FILE_MANAGEMENT_FILE, columns, 'drawer');
const { propsRes, propsEvent, loadList, setLoadListParams } = useTable(getFileList, {
tableKey: TableKeyEnum.FILE_MANAGEMENT_FILE,
showSetting: true,
selectable: true,
showSelectAll: true,
});
const { propsRes, propsEvent, loadList, setLoadListParams } = useTable(
getFileList,
{
tableKey: TableKeyEnum.FILE_MANAGEMENT_FILE,
showSetting: true,
selectable: true,
showSelectAll: true,
},
(item) => {
return {
...item,
tags: item.tags?.map((e: string) => ({ id: e, name: e })) || [],
};
}
);
const moduleFileBatchActions = {
baseAction: [
{
@ -653,7 +662,7 @@
try {
batchMoveFileLoading.value = true;
await batchMoveFile({
selectIds: batchParams.value?.selectedIds || [activeFile.value?.id || ''],
selectIds: isBatchMove.value ? batchParams.value?.selectedIds || [] : [activeFile.value?.id || ''],
selectAll: !!batchParams.value?.selectAll,
excludeIds: batchParams.value?.excludeIds || [],
condition: { keyword: keyword.value, comebine: combine.value },
@ -834,6 +843,15 @@
activeFileIndex.value = index;
}
watch(
() => showDetailDrawer.value,
(val) => {
if (!val) {
loadList();
}
}
);
const uploadDrawerVisible = ref(false); // -
const fileList = ref<MsFileItem[]>(asyncTaskStore.uploadFileTask.fileList);
//