From 545203f9995415cb93229b0f8249bc50b2efca91 Mon Sep 17 00:00:00 2001 From: niuran Date: Wed, 29 Jan 2025 09:45:01 +0800 Subject: [PATCH] fix file list bug --- frontend/src/components/shared/FileList.vue | 42 ++++++++++++++++++++- frontend/src/locales/en_js/all.js | 3 +- frontend/src/locales/zh_js/all.js | 3 +- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/shared/FileList.vue b/frontend/src/components/shared/FileList.vue index 5dad9b361..b4a6593a6 100644 --- a/frontend/src/components/shared/FileList.vue +++ b/frontend/src/components/shared/FileList.vue @@ -128,6 +128,7 @@ +

{{ $t('all.loadMore') }}

@@ -157,6 +158,9 @@ const lastCommit = ref() const lastCommitAvatar = ref('https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png') const prefixPath = document.location.pathname.split('/')[1] + const filePageCursor = ref('') + const commitList = ref([]) + const tempCommit = ref([]) const emit = defineEmits(['changeBranch']) @@ -255,14 +259,48 @@ } } + const fetchCommits = async () => { + const url = `/${prefixPath}/${props.namespacePath}/refs/${props.currentBranch}/logs_tree/${props.currentPath}?offset=${commitList.value.length}&limit=50` + try { + const { response, data, error } = await useFetchApi(url).json() + + if (data.value) { + tempCommit.value = data.value.data?.Commits + commitList.value = [...commitList.value, ...tempCommit.value] + + tempCommit.value.forEach(commit => { + const file = files.value.find(f => f.name === commit.name); + if (file) { + file.commit = commit; + } + }); + + if (commitList.value.length < files.value.length) { + fetchCommits(); + } + } else if (response.value.status === 403) { + ToUnauthorizedPage() + } else if (response.value.status === 404) { + ToNotFoundPage() + } else { + ElMessage.warning(error.value ? error.value.msg : 'Failed to fetch commit list') + } + } catch (error) { + console.log(error) + } finally { + loading.value = false + } + } const fetchFileListData = async () => { - const url = `/${prefixPath}/${props.namespacePath}/tree?path=${props.currentPath}&ref=${props.currentBranch}` + const url = `/${prefixPath}/${props.namespacePath}/refs/${props.currentBranch}/tree/${props.currentPath}?cursor=${filePageCursor.value}&limit=500` try { const { response, data, error } = await useFetchApi(url).json() if (data.value) { - files.value = data.value.data + files.value = [...files.value, ...data.value.data?.Files] + filePageCursor.value = data.value.data?.Cursor + fetchCommits() } else if (response.value.status === 403) { ToUnauthorizedPage() } else if (response.value.status === 404) { diff --git a/frontend/src/locales/en_js/all.js b/frontend/src/locales/en_js/all.js index e5f980492..c4ba5490b 100644 --- a/frontend/src/locales/en_js/all.js +++ b/frontend/src/locales/en_js/all.js @@ -83,5 +83,6 @@ export const all = { more:"More", sdkTips: "Please register first and then obtain the Token from OpenCSG's account page", public: "Public", - private: "Private" + private: "Private", + loadMore: "Load more", } \ No newline at end of file diff --git a/frontend/src/locales/zh_js/all.js b/frontend/src/locales/zh_js/all.js index b20e84def..f9b175e2e 100644 --- a/frontend/src/locales/zh_js/all.js +++ b/frontend/src/locales/zh_js/all.js @@ -83,5 +83,6 @@ export const all = { more:"更多", sdkTips: "请先注册,然后从 OpenCSG 的账号页面获取 Token", public: "公开", - private: "私有" + private: "私有", + loadMore:"加载更多" } \ No newline at end of file