Skip to content

Commit 60f90fd

Browse files
ice201508jiuling
andauthored
fix history frontend back correct (#1250)
* Draft MR * Main fix history frontend back correct * fix history frontend back correct --------- Co-authored-by: jiuling <[email protected]>
1 parent 3264ef3 commit 60f90fd

File tree

17 files changed

+1152
-344
lines changed

17 files changed

+1152
-344
lines changed

frontend/src/components/__tests__/finetune/FinetuneDetail.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ vi.mock('vue-router', () => ({
99
query: { tab: 'page' }
1010
}),
1111
useRouter: () => ({
12-
replace: vi.fn()
12+
replace: vi.fn(),
13+
push: vi.fn() // 添加这一行
1314
})
1415
}));
1516

frontend/src/components/collections/CollectionsDetail.vue

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
</div>
100100
</template>
101101
<script setup>
102-
import { ref, onBeforeMount, computed, provide } from 'vue'
102+
import { ref, onBeforeMount, computed, provide, watch } from 'vue'
103103
import RepoHeader from '../shared/RepoHeader.vue'
104104
import CollectionsRepoList from './CollectionsRepoList.vue'
105105
import CollectionsSettings from './CollectionsSettings.vue'
@@ -109,6 +109,7 @@
109109
import useFetchApi from '../../packs/useFetchApi'
110110
import { storeToRefs } from 'pinia'
111111
import { useRoute, useRouter } from 'vue-router'
112+
import { validateTab } from '../../packs/utils'
112113
113114
const repoDetailStore = useRepoDetailStore()
114115
const { isInitialized } = storeToRefs(repoDetailStore)
@@ -150,20 +151,34 @@
150151
return validTabs.value.includes(tab)
151152
}
152153
154+
// 监听路由变化,当用户使用浏览器前进/后退按钮时更新tab
155+
watch(() => route.query.tab, (newTab) => {
156+
const validatedTab = validateTab(newTab)
157+
if (validatedTab && isValidTab(validatedTab) && validatedTab !== activeName.value) {
158+
activeName.value = validatedTab
159+
setRepoTab({
160+
tab: validatedTab,
161+
actionName: 'files',
162+
lastPath: ''
163+
})
164+
tabChange({ paneName: validatedTab })
165+
}
166+
})
167+
153168
const tabChange = (tab) => {
154-
let tabName = tab.paneName
169+
let tabName = validateTab(tab.paneName)
155170
156171
if (!isValidTab(tabName)) {
157172
tabName = getDefaultTab()
158-
router.replace({
173+
router.push({
159174
path: `/collections/${props.collectionsId}`,
160175
query: { tab: tabName }
161176
})
162177
}
163178
164179
activeName.value = tabName
165180
166-
router.replace({
181+
router.push({
167182
path: `/collections/${props.collectionsId}`,
168183
query: {
169184
tab: tabName
@@ -191,7 +206,7 @@
191206
192207
// 处理URL query参数中的tab
193208
const params = new URLSearchParams(window.location.search)
194-
const urlTab = params.get('tab')
209+
const urlTab = validateTab(params.get('tab'))
195210
if (urlTab && isValidTab(urlTab)) {
196211
tabChange({ paneName: urlTab })
197212
} else {

0 commit comments

Comments
 (0)