From f2fb339e301b9a41e34e9d1aa6592daf669960ac Mon Sep 17 00:00:00 2001
From: M0914 <2625053283@qq.com>
Date: Wed, 24 Sep 2025 13:47:24 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E4=B8=80=E4=B8=AA=E7=AE=80?=
=?UTF-8?q?=E5=8D=95=E7=9A=84=E8=B7=AF=E7=94=B1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/resources/static/index.html | 7 +++++++
src/main/resources/static/js/app.js | 21 ++++++++++++++++++---
src/main/resources/static/js/utils.js | 19 +++++++++++++++++++
3 files changed, 44 insertions(+), 3 deletions(-)
diff --git a/src/main/resources/static/index.html b/src/main/resources/static/index.html
index b6c3c5b..9d0576e 100644
--- a/src/main/resources/static/index.html
+++ b/src/main/resources/static/index.html
@@ -20,6 +20,13 @@
+
+
+
diff --git a/src/main/resources/static/js/app.js b/src/main/resources/static/js/app.js
index 0edf258..5515212 100644
--- a/src/main/resources/static/js/app.js
+++ b/src/main/resources/static/js/app.js
@@ -5,7 +5,7 @@ const { createApp } = Vue
const App = {
data() {
return {
- currentPage: 'home',
+ currentPage: Utils.getCurrentPage(), // 从URL获取当前页面
showConfigModal: false,
showLicenseModal: false,
showResultModal: false,
@@ -68,6 +68,17 @@ const App = {
// 加载主题设置
Utils.loadTheme()
+ // 监听路由变化
+ this.handleHashChange = () => {
+ this.currentPage = Utils.getCurrentPage()
+ this.searchQuery = ''
+ // 重置过滤结果
+ this.filteredProducts = [...this.products]
+ this.filteredPlugins = [...this.plugins]
+ }
+
+ Utils.onHashChange(this.handleHashChange)
+
// 监听滚动事件
const handleScroll = () => {
const scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
@@ -82,6 +93,11 @@ const App = {
},
beforeUnmount() {
+ // 清理路由监听器
+ if (this.handleHashChange) {
+ Utils.removeHashChangeListener(this.handleHashChange)
+ }
+
// 清理滚动事件监听器
if (this._handleScroll) {
window.removeEventListener('scroll', this._handleScroll)
@@ -232,8 +248,7 @@ const App = {
// 页面跳转
navigateTo(page) {
- this.currentPage = page
- this.searchQuery = ''
+ Utils.navigateToPage(page)
},
// 返回顶部
diff --git a/src/main/resources/static/js/utils.js b/src/main/resources/static/js/utils.js
index 4110091..f78e60b 100644
--- a/src/main/resources/static/js/utils.js
+++ b/src/main/resources/static/js/utils.js
@@ -180,6 +180,25 @@ const Utils = {
// 获取当前主题
getCurrentTheme() {
return document.documentElement.classList.contains('dark') ? 'dark' : 'light'
+ },
+
+ // 路由管理
+ getCurrentPage() {
+ const hash = window.location.hash.slice(1) // 移除 # 号
+ const validPages = ['home', 'products', 'plugins', 'jrebel', 'sponsor']
+ return validPages.includes(hash) ? hash : 'home'
+ },
+
+ navigateToPage(page) {
+ window.location.hash = page
+ },
+
+ onHashChange(callback) {
+ window.addEventListener('hashchange', callback)
+ },
+
+ removeHashChangeListener(callback) {
+ window.removeEventListener('hashchange', callback)
}
}