feat(文件管理): 存储库部分接口

This commit is contained in:
baiqi 2023-11-06 18:08:29 +08:00 committed by 刘瑞斌
parent 51ac88e681
commit 6b2e192481
11 changed files with 241 additions and 351 deletions

View File

@ -1,8 +1,10 @@
import MSR from '@/api/http/index';
import {
AddModuleUrl,
AddRepositoryUrl,
BatchDownloadFileUrl,
BatchMoveFileUrl,
ConnectRepositoryUrl,
DeleteFileUrl,
DeleteModuleUrl,
DownloadFileUrl,
@ -11,17 +13,21 @@ import {
GetFileTypesUrl,
GetModuleCountUrl,
GetModuleUrl,
GetRepositoryFileTypesUrl,
GetRepositoryFileUrl,
MoveModuleUrl,
ReuploadFileUrl,
ToggleJarFileUrl,
UpdateFileUrl,
UpdateModuleUrl,
UpdateRepositoryUrl,
UploadFileUrl,
} from '@/api/requrls/project-management/fileManagement';
import type { CommonList } from '@/models/common';
import type {
AddModuleParams,
AddRepositoryParams,
BatchFileApiParams,
FileDetail,
FileItem,
@ -29,9 +35,12 @@ import type {
ModuleCount,
ModuleTreeNode,
MoveModuleParams,
Repository,
ReuploadFileParams,
TestRepositoryConnectParams,
UpdateFileParams,
UpdateModuleParams,
UpdateRepositoryParams,
UploadFileParams,
} from '@/models/projectManagement/file';
@ -100,7 +109,7 @@ export function deleteModule(id: string) {
return MSR.get({ url: DeleteModuleUrl, params: id });
}
// 获取文件类型集合
// 获取模块文件类型集合
export function getFileTypes(id: string) {
return MSR.get<string[]>({ url: GetFileTypesUrl, params: id });
}
@ -119,3 +128,28 @@ export function toggleJarFileStatus(id: string, status: boolean) {
export function batchMoveFile(data: BatchFileApiParams) {
return MSR.post({ url: BatchMoveFileUrl, data });
}
// 查找存储库
export function getRepositories(id: string) {
return MSR.get<Repository[]>({ url: GetRepositoryFileUrl, params: id });
}
// 获取存储库文件类型集合
export function getRepositoryFileTypes(id: string) {
return MSR.get<string[]>({ url: GetRepositoryFileTypesUrl, params: id });
}
// 添加存储库
export function addRepository(data: AddRepositoryParams) {
return MSR.post({ url: AddRepositoryUrl, data });
}
// 测试存储库连接
export function connectRepository(data: TestRepositoryConnectParams) {
return MSR.post({ url: ConnectRepositoryUrl, data });
}
// 修改存储库信息
export function updateRepository(data: UpdateRepositoryParams) {
return MSR.post({ url: UpdateRepositoryUrl, data });
}

View File

@ -13,7 +13,12 @@ export const DeleteModuleUrl = '/project/file-module/delete'; // 删除模块
export const GetModuleCountUrl = '/project/file/module/count'; // 模块统计文件数量
export const OriginImgUrl = '/file/preview/original'; // 预览图片文件接口-原图
export const CompressImgUrl = '/file/preview/compressed'; // 预览图片文件接口-缩略图
export const GetFileTypesUrl = '/project/file/type'; // 获取文件类型集合
export const GetFileTypesUrl = '/project/file/type'; // 获取模块文件类型集合
export const GetFileDetailUrl = '/project/file/get'; // 查看文件详情
export const ToggleJarFileUrl = '/project/file/jar-file-status'; // jar 文件启用禁用
export const BatchMoveFileUrl = '/project/file/batch-move'; // jar 文件启用禁用
export const GetRepositoryFileUrl = '/project/file/repository/list'; // 存储库列表
export const GetRepositoryFileTypesUrl = '/project/file/repository/file-type'; // 存储库文件类型列表
export const UpdateRepositoryUrl = '/project/file/repository/update-repository'; // 修改存储库信息
export const ConnectRepositoryUrl = '/project/file/repository/connect'; // 测试存储库连接
export const AddRepositoryUrl = '/project/file/repository/add-repository'; // 添加存储库

View File

@ -37,6 +37,7 @@ export interface UploadFileParams {
request: {
projectId: string;
moduleId: string; // 模块ID
enable: boolean; // jar文件启用禁用
};
file: File;
}
@ -52,6 +53,7 @@ export interface UpdateFileParams {
export interface ReuploadFileParams {
request: {
fileId: string;
enable: boolean; // jar文件启用禁用
};
file: File;
}
@ -86,3 +88,35 @@ export interface ModuleTreeNode {
type: string;
children: ModuleTreeNode[];
}
// 存储库列表
export interface Repository {
id: string;
name: string;
type: string;
parentId: string;
children: string[];
attachInfo: Record<string, any>; // 附加信息
count: number;
}
// 存储库公共信息
export interface RepositoryCommon {
name: string;
platform: string;
token: string;
userName: string;
}
// 添加存储库信息入参
export interface AddRepositoryParams extends RepositoryCommon {
projectId: string;
url: string;
}
// 更新存储库信息入参
export interface UpdateRepositoryParams extends RepositoryCommon {
id: string;
}
// 测试存储库连接
export interface TestRepositoryConnectParams {
url: string;
token: string;
userName: string;
}

View File

@ -182,7 +182,7 @@ const useAsyncTaskStore = defineStore('asyncTask', {
try {
if (this.uploadFileTask.uploadFunc) {
await this.uploadFileTask.uploadFunc({
request: { ...this.uploadFileTask.requestParams },
request: { ...this.uploadFileTask.requestParams, enable: unref(fileItem)?.enable },
file: unref(fileItem)?.file,
});
} else {

View File

@ -359,6 +359,7 @@
await reuploadFile({
request: {
fileId: props.fileId,
enable: false,
},
file: data,
});

View File

@ -83,7 +83,7 @@
import useAppStore from '@/store/modules/app';
import { mapTree } from '@/utils';
import { FileListQueryParams, ModuleTreeNode } from '@/models/projectManagement/file';
import { ModuleTreeNode } from '@/models/projectManagement/file';
const props = defineProps<{
isExpandAll: boolean;
@ -91,6 +91,7 @@
selectedKeys?: Array<string | number>; // key
isModal?: boolean; //
modulesCount?: Record<string, number>; //
showType?: string; //
}>();
const emit = defineEmits(['update:selectedKeys', 'init', 'folderNodeSelect']);
@ -283,9 +284,17 @@
}
}
onBeforeMount(() => {
initModules();
});
watch(
() => props.showType,
(val) => {
if (val === 'Module') {
initModules();
}
},
{
immediate: true,
}
);
/**
* 初始化模块文件数量

View File

@ -298,6 +298,7 @@
downloadFile,
getFileList,
getFileTypes,
getRepositoryFileTypes,
toggleJarFileStatus,
uploadFile,
} from '@/api/modules/project-management/fileManagement';
@ -339,7 +340,7 @@
const keyword = ref('');
const loading = ref(false);
const tableFileType = ref('');
const tableFileType = ref(''); //
const tableFileTypeOptions = ref<string[]>([]);
const fileTypeLoading = ref(false);
@ -349,7 +350,12 @@
async function initFileTypes() {
try {
fileTypeLoading.value = true;
const res = await getFileTypes(appStore.currentProjectId);
let res = null;
if (fileType.value === 'storage') {
res = await getRepositoryFileTypes(appStore.currentProjectId);
} else {
res = await getFileTypes(appStore.currentProjectId);
}
tableFileTypeOptions.value = res;
} catch (error) {
// eslint-disable-next-line no-console
@ -359,6 +365,16 @@
}
}
watch(
() => props.activeFolderType,
() => {
initFileTypes();
},
{
immediate: true,
}
);
const showType = ref<'list' | 'card'>('list'); //
function getCardClass(type: 'none' | 'jar') {
@ -704,9 +720,13 @@
function setTableParams() {
if (props.activeFolder === 'my') {
combine.value.createUser = userStore.id;
} else {
combine.value.createUser = '';
}
if (fileType.value === 'storage') {
combine.value.storage = 'git';
} else {
combine.value.storage = 'module';
}
let moduleIds: string[] = [props.activeFolder, ...props.offspringIds];
if (['all', 'my'].includes(props.activeFolder)) {
@ -721,7 +741,11 @@
});
}
/**
* 更改文件展示类型模块/存储库
*/
function changeFileType() {
initFileTypes();
setTableParams();
loadList();
}
@ -960,7 +984,6 @@
type RouteQueryPosition = 'uploadDrawer' | null;
onBeforeMount(() => {
initFileTypes();
if (route.query.position) {
switch (
route.query.position as RouteQueryPosition //

View File

@ -5,41 +5,43 @@
allow-clear
class="mb-[8px]"
></a-input>
<MsList
v-model:focus-item-key="focusItemKey"
:virtual-list-props="{
height: 'calc(100vh - 310px)',
}"
:data="storageList"
:bordered="false"
:split="false"
:item-more-actions="folderMoreActions"
:empty-text="t('project.fileManagement.noStorage')"
class="mr-[-6px]"
@more-action-select="handleMoreSelect"
@more-actions-close="moreActionsClose"
>
<template #title="{ item, index }">
<div :key="index" class="storage" @click="setActiveFolder(item.key)">
<div :class="props.activeFolder === item.key ? 'storage-text storage-text--active' : 'storage-text'">
<MsIcon type="icon-icon_git" class="storage-icon" />
<div class="storage-name">{{ item.title }}</div>
<div class="storage-count">({{ item.count }})</div>
<a-spin class="h-full w-full" :loading="loading">
<MsList
v-model:focus-item-key="focusItemKey"
:virtual-list-props="{
height: 'calc(100vh - 310px)',
}"
:data="storageList"
:bordered="false"
:split="false"
:item-more-actions="folderMoreActions"
:empty-text="t('project.fileManagement.noStorage')"
class="mr-[-6px]"
@more-action-select="handleMoreSelect"
@more-actions-close="moreActionsClose"
>
<template #title="{ item, index }">
<div :key="index" class="storage" @click="setActiveFolder(item.key)">
<div :class="props.activeFolder === item.key ? 'storage-text storage-text--active' : 'storage-text'">
<MsIcon type="icon-icon_git" class="storage-icon" />
<div class="storage-name">{{ item.title }}</div>
<div class="storage-count">({{ item.count }})</div>
</div>
</div>
</div>
</template>
<template #itemAction="{ item }">
<popConfirm
mode="rename"
:parent-id="item.key"
:field-config="{ field: renameStorageTitle }"
:all-names="[]"
@close="resetFocusItemKey"
>
<span :id="`renameSpan${item.key}`" class="relative"></span>
</popConfirm>
</template>
</MsList>
</template>
<template #itemAction="{ item }">
<popConfirm
mode="rename"
:parent-id="item.key"
:field-config="{ field: renameStorageTitle }"
:all-names="[]"
@close="resetFocusItemKey"
>
<span :id="`renameSpan${item.key}`" class="relative"></span>
</popConfirm>
</template>
</MsList>
</a-spin>
<MsDrawer
v-model:visible="showDrawer"
:title="t(isEdit ? 'project.fileManagement.updateStorageTitle' : 'project.fileManagement.addStorage')"
@ -112,12 +114,12 @@
</a-form-item>
<a-form-item
:label="t('project.fileManagement.storageUsername')"
field="username"
field="userName"
asterisk-position="end"
:rules="usernameRules"
>
<a-input
v-model:model-value="activeStorageForm.username"
v-model:model-value="activeStorageForm.userName"
:max-length="250"
:placeholder="t('project.fileManagement.storageUsernamePlaceholder')"
allow-clear
@ -144,20 +146,25 @@
import MsFormItemSub from '@/components/business/ms-form-item-sub/index.vue';
import popConfirm from './popConfirm.vue';
import { addRepository, connectRepository, getRepositories } from '@/api/modules/project-management/fileManagement';
import { useI18n } from '@/hooks/useI18n';
import useModal from '@/hooks/useModal';
import useAppStore from '@/store/modules/app';
import { validateGitUrl } from '@/utils/validate';
import { Repository } from '@/models/projectManagement/file';
import { GitPlatformEnum } from '@/enums/commonEnum';
const props = defineProps<{
activeFolder: string | number;
drawerVisible: boolean;
showType: string;
}>();
const emit = defineEmits(['update:drawerVisible', 'itemClick']);
const { t } = useI18n();
const { openModal } = useModal();
const appStore = useAppStore();
const folderMoreActions: ActionsItem[] = [
{
@ -176,309 +183,49 @@
];
const storageKeyword = ref('');
const originStorageList = ref([
{
title: 'storage1',
key: '1',
count: 129,
},
{
title: 'storage2',
key: '2',
count: 129,
},
{
title: 'storage3',
key: '3',
count: 129,
},
{
title: 'storage3',
key: '3sss',
count: 129,
},
{
title: 'storage3',
key: '3asa',
count: 129,
},
{
title: 'storage3',
key: '3sda',
count: 129,
},
{
title: 'storage3',
key: '3ads',
count: 129,
},
{
title: 'storage3',
key: '3asdd',
count: 129,
},
{
title: 'storage3',
key: '3sdfsdf',
count: 129,
},
{
title: 'storage3',
key: '3dgsg',
count: 129,
},
{
title: 'storage3',
key: '3asd',
count: 129,
},
{
title: 'storage3',
key: '3fwcdw',
count: 129,
},
{
title: 'storage3',
key: '3wef',
count: 129,
},
{
title: 'storage3',
key: '3f2ed',
count: 129,
},
{
title: 'storage3',
key: '3fe2fe',
count: 129,
},
{
title: 'storage3',
key: '3fe2feg2',
count: 129,
},
{
title: 'storage3',
key: '32s22',
count: 129,
},
{
title: 'storage3',
key: '323ff22f',
count: 129,
},
{
title: 'storage3',
key: '33f3f',
count: 129,
},
{
title: 'storage1',
key: '1f2f',
count: 129,
},
{
title: 'storage2',
key: '2ef2ef',
count: 129,
},
{
title: 'storage3',
key: '3sd2fd',
count: 129,
},
{
title: 'storage3',
key: '32ef2ef',
count: 129,
},
{
title: 'storage3',
key: '3f32v',
count: 129,
},
{
title: 'storage3',
key: '323fgt2',
count: 129,
},
{
title: 'storage3',
key: '324g23r',
count: 129,
},
{
title: 'storage3',
key: '3233d2',
count: 129,
},
{
title: 'storage3',
key: '32gftr3',
count: 129,
},
{
title: 'storage3',
key: '323f2dd',
count: 129,
},
{
title: 'storage3',
key: '32fgede',
count: 129,
},
{
title: 'storage3',
key: '32efsad',
count: 129,
},
{
title: 'storage3',
key: '3fsdgsd',
count: 129,
},
{
title: 'storage3',
key: '3sdgvsdxcs',
count: 129,
},
{
title: 'storage3',
key: '3asxc',
count: 129,
},
{
title: 'storage3',
key: '3csdcdg',
count: 129,
},
{
title: 'storage3',
key: '3gsg3f3',
count: 129,
},
{
title: 'storage3',
key: '3d3dxcsd',
count: 129,
},
{
title: 'storage3',
key: '3c3wervvb',
count: 129,
},
{
title: 'storage1',
key: '13vf33',
count: 129,
},
{
title: 'storage2',
key: '234444',
count: 129,
},
{
title: 'storage3',
key: '32323d',
count: 129,
},
{
title: 'storage3',
key: '323ffef',
count: 129,
},
{
title: 'storage3',
key: 'f23f23f3',
count: 129,
},
{
title: 'storage3',
key: '3f2f2f',
count: 129,
},
{
title: 'storage3',
key: '3rf4f2',
count: 129,
},
{
title: 'storage3',
key: '3dsewd',
count: 129,
},
{
title: 'storage3',
key: '3x2ef23f',
count: 129,
},
{
title: 'storage3',
key: '3f3f43',
count: 129,
},
{
title: 'storage3',
key: '3h4hgp',
count: 129,
},
{
title: 'storage3',
key: '3yu6n',
count: 129,
},
{
title: 'storage3',
key: '3nyuk',
count: 129,
},
{
title: 'storage3',
key: '3hn6',
count: 129,
},
{
title: 'storage3',
key: '3nyguhnmm6',
count: 129,
},
{
title: 'storage3',
key: '36n6n',
count: 129,
},
{
title: 'storage3',
key: '3yukyuk',
count: 129,
},
{
title: 'storage3',
key: '3yhnn',
count: 129,
},
{
title: 'storage3',
key: '3gntnty',
count: 129,
},
]);
const originStorageList = ref<Repository[]>([]);
const storageList = ref(originStorageList.value);
const loading = ref(false);
const searchStorage = debounce(() => {
storageList.value = originStorageList.value.filter((item) => item.title.includes(storageKeyword.value));
storageList.value = originStorageList.value.filter((item) => item.name.includes(storageKeyword.value));
}, 300);
watch(
() => storageKeyword.value,
() => {
if (storageKeyword.value === '') {
storageList.value = originStorageList.value;
storageList.value = [...originStorageList.value];
}
searchStorage();
}
);
/**
* 初始化存储库列表
*/
async function initRepositories() {
try {
loading.value = true;
const res = await getRepositories(appStore.currentProjectId);
originStorageList.value = res;
} catch (error) {
// eslint-disable-next-line no-console
console.log(error);
} finally {
loading.value = false;
}
}
watch(
() => props.showType,
(val) => {
if (val === 'Storage') {
initRepositories();
}
}
);
const focusItemKey = ref('');
function setActiveFolder(id: string) {
@ -505,6 +252,7 @@
try {
Message.success(t('project.fileManagement.deleteSuccess'));
} catch (error) {
// eslint-disable-next-line no-console
console.log(error);
}
},
@ -549,7 +297,7 @@
platform: GitPlatformEnum.GITHUB,
url: '',
token: '',
username: '',
userName: '',
});
const storageFormRef = ref<FormInstance>();
const gitPlatformTypes = Object.values(GitPlatformEnum);
@ -562,9 +310,10 @@
platform: GitPlatformEnum.GITHUB,
url: 'xxxxxxx',
token: 'sxsxsx',
username: 'ddwdwdwwd',
userName: 'ddwdwdwwd',
};
} catch (error) {
// eslint-disable-next-line no-console
console.log(error);
} finally {
drawerLoading.value = false;
@ -605,7 +354,7 @@
});
function platformChange() {
storageFormRef.value?.resetFields('username');
storageFormRef.value?.resetFields('userName');
}
const exampleUrl = 'http://github.com/xxxxx/xxxxxx.git';
@ -620,7 +369,35 @@
}
}
// async function saveStorage(isContinue: boolean) {}
function handleDrawerCancel() {
showDrawer.value = false;
storageFormRef.value?.resetFields();
isEdit.value = false;
}
/**
* 保存存储库
* @param isContinue 是否继续添加
*/
async function saveStorage(isContinue: boolean) {
try {
drawerLoading.value = true;
await addRepository({
...activeStorageForm.value,
projectId: appStore.currentProjectId,
});
if (!isContinue) {
handleDrawerCancel();
}
Message.success(t('common.addSuccess'));
initRepositories();
} catch (error) {
// eslint-disable-next-line no-console
console.log(error);
} finally {
drawerLoading.value = false;
}
}
/**
* 处理抽屉确认
@ -629,25 +406,29 @@
function handleDrawerConfirm(isContinue: boolean) {
storageFormRef.value?.validate(async (errors: Record<string, ValidatedError> | undefined) => {
if (!errors) {
// saveStorage(isContinue);
saveStorage(isContinue);
}
});
}
function handleDrawerCancel() {
showDrawer.value = false;
storageFormRef.value?.resetFields();
}
const testLoading = ref(false);
function testLink() {
storageFormRef.value?.validate(async (errors: Record<string, ValidatedError> | undefined) => {
if (!errors) {
testLoading.value = true;
setTimeout(() => {
try {
testLoading.value = true;
await connectRepository({
url: activeStorageForm.value.url,
userName: activeStorageForm.value.userName,
token: activeStorageForm.value.token,
});
Message.success(t('project.fileManagement.testLinkSuccess'));
} catch (error) {
// eslint-disable-next-line no-console
console.log(error);
} finally {
testLoading.value = false;
}, 2000);
}
}
});
}

View File

@ -58,6 +58,7 @@
v-model:selected-keys="selectedKeys"
:is-expand-all="isExpandAll"
:modules-count="modulesCount"
:show-type="showType"
@init="setRootModules"
@folder-node-select="folderNodeSelect"
/>
@ -66,6 +67,7 @@
<StorageList
v-model:drawer-visible="storageDrawerVisible"
:active-folder="activeFolder"
:show-type="showType"
@item-click="storageItemSelect"
/>
</div>
@ -100,9 +102,8 @@
import { getModulesCount } from '@/api/modules/project-management/fileManagement';
import { useI18n } from '@/hooks/useI18n';
import { mapTree } from '@/utils';
import { FileListQueryParams, ModuleTreeNode } from '@/models/projectManagement/file';
import { FileListQueryParams } from '@/models/projectManagement/file';
const { t } = useI18n();

View File

@ -34,6 +34,7 @@ export default {
'project.fileManagement.edit': 'Edit',
'project.fileManagement.cancel': 'Cancel',
'project.fileManagement.testLink': 'Test connection',
'project.fileManagement.testLinkSuccess': 'Connection successful',
'project.fileManagement.storageName': 'Repository name',
'project.fileManagement.storageNamePlaceholder': 'Please enter a repository name',
'project.fileManagement.storageNameNotNull': 'Repository name cannot be empty',

View File

@ -32,6 +32,7 @@ export default {
'project.fileManagement.edit': '编辑',
'project.fileManagement.cancel': '取消',
'project.fileManagement.testLink': '测试连接',
'project.fileManagement.testLinkSuccess': '连接成功',
'project.fileManagement.storageName': '存储库名称',
'project.fileManagement.storageNamePlaceholder': '请输入存储库名称',
'project.fileManagement.storageNameNotNull': '存储库名称不能为空',