11<template >
22 <div class =" flex flex-col gap-[16px] min-h-[300px] py-[32px] md:px-5" >
3- <div class =" test -[14px]" ><p >{{ repoName + repoTab.lastPath }}/</p ></div >
3+ <div class =" text -[14px]" ><p >{{ repoName + ( repoTab.lastPath ? '/' + repoTab.lastPath : '') }}/</p ></div >
44 <div class =" border border-gray-200 rounded-xs bg-gray-100" >
55 <div class =" flex text-sm text-brand-500 leading-[22px]" >
66 <div class =" px-[20px] py-[9px] border-r bg-white w-[140px]" >
5959<script setup>
6060import CommunityMDTextarea from ' ../community/CommunityMDTextarea.vue'
6161import { ref } from ' vue'
62+ import { useRouter } from ' vue-router'
6263import {ElMessage } from " element-plus"
6364import { useI18n } from ' vue-i18n'
6465import useFetchApi from ' ../../packs/useFetchApi'
@@ -71,6 +72,7 @@ const props = defineProps({
7172})
7273
7374const { repoTab , setRepoTab } = useRepoTabStore ()
75+ const router = useRouter ()
7476
7577const { t } = useI18n ();
7678const uploadRef = ref ();
@@ -117,10 +119,26 @@ const handleRemove = (file, fileList) => {
117119
118120const cancel = () => {
119121 // window.location.href = `/${prefixPath}/${props.namespacePath}/files/${props.currentBranch}`
120- const toPath = repoTab .lastPath && repoTab .lastPath .startsWith (' /' ) ? repoTab .lastPath .slice (1 ) : repoTab .lastPath || ' '
122+ const normalizedPath = repoTab .lastPath || ' '
123+
124+ const query = {
125+ tab: ' files' ,
126+ actionName: ' files' ,
127+ branch: router .currentRoute .value .query .branch || props .currentBranch
128+ }
129+
130+ // 只有当路径不为空时才添加到 query
131+ if (normalizedPath) {
132+ query .path = normalizedPath
133+ }
134+
121135 setRepoTab ({
122136 actionName: ' files' ,
123- lastPath: toPath
137+ lastPath: normalizedPath
138+ })
139+
140+ router .push ({
141+ query
124142 })
125143}
126144
@@ -134,7 +152,8 @@ const buildCommitMessage = () => {
134152const appendFilesToFormData = (formData , files ) => {
135153 files .forEach ((file ) => {
136154 formData .append (' file' , file .raw )
137- formData .append (' file_path' , (repoTab .lastPath || ' ' ) + ' /' + file .name )
155+ const filePath = repoTab .lastPath ? ` ${ repoTab .lastPath } /${ file .name } ` : file .name
156+ formData .append (' file_path' , filePath)
138157 })
139158}
140159
@@ -159,10 +178,26 @@ const syncUploadFile = async () => {
159178 } else {
160179 filesList .value = []
161180 // window.location.href = `/${prefixPath}/${props.namespacePath}/files/${props.currentBranch}`
162- const toPath = repoTab .lastPath && repoTab .lastPath .startsWith (' /' ) ? repoTab .lastPath .slice (1 ) : repoTab .lastPath || ' '
181+ const normalizedPath = repoTab .lastPath || ' '
182+
183+ const query = {
184+ tab: ' files' ,
185+ actionName: ' files' ,
186+ branch: router .currentRoute .value .query .branch || props .currentBranch
187+ }
188+
189+ // 只有当路径不为空时才添加到 query
190+ if (normalizedPath) {
191+ query .path = normalizedPath
192+ }
193+
163194 setRepoTab ({
164195 actionName: ' files' ,
165- lastPath: toPath
196+ lastPath: normalizedPath
197+ })
198+
199+ router .push ({
200+ query
166201 })
167202 }
168203 } catch (error) {
0 commit comments