From 5defc890ed25d828b344140adc9df95157a18248 Mon Sep 17 00:00:00 2001 From: chenkainan Date: Tue, 2 Sep 2025 17:10:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/layout/HeaderNav.vue | 1 - src/components/layout/HomeLayout.vue | 8 +++++-- src/libs/utils.js | 3 --- src/main.js | 32 +++++++++++++++++++++++++ src/router/index.js | 36 ++++++++++++++-------------- 5 files changed, 56 insertions(+), 24 deletions(-) diff --git a/src/components/layout/HeaderNav.vue b/src/components/layout/HeaderNav.vue index 334a53e..640d510 100644 --- a/src/components/layout/HeaderNav.vue +++ b/src/components/layout/HeaderNav.vue @@ -22,7 +22,6 @@ > 我的订单 - 商户后台 退出 diff --git a/src/components/layout/HomeLayout.vue b/src/components/layout/HomeLayout.vue index 08781c8..6525f96 100644 --- a/src/components/layout/HomeLayout.vue +++ b/src/components/layout/HomeLayout.vue @@ -30,8 +30,12 @@
- 登录 - 注册 + 登录 + 注册 客服
diff --git a/src/libs/utils.js b/src/libs/utils.js index ae7fa39..19c5a2c 100644 --- a/src/libs/utils.js +++ b/src/libs/utils.js @@ -62,9 +62,6 @@ export default { } else { return 'https://static.ticket.sz-trip.com' + img; } - }, - gotoPath(path) { - this.$router.push(path) } } } diff --git a/src/main.js b/src/main.js index d47293a..0fa1ee4 100644 --- a/src/main.js +++ b/src/main.js @@ -33,7 +33,39 @@ Vue.use(VueLazyload, { } }) +// 全局挂载公共路由跳转方法 +Vue.prototype.gotoPath = function(path, options = {}) { + // 1. 避免重复跳转同一页面 + const currentPath = this.$router.currentRoute.fullPath + if (path === currentPath) { + return + } + try { + // 2. 支持两种跳转方式:路径字符串或配置对象 + if (typeof path === 'string') { + // 字符串路径,可附带query参数 + this.$router.push({ + path, + query: options.query || {} + }) + } else if (typeof path === 'object') { + // 直接传入路由配置对象(如命名路由) + this.$router.push(path) + } + + // 3. 可选的跳转成功回调 + if (typeof options.success === 'function') { + options.success() + } + } catch (error) { + // 4. 错误处理 + console.error('路由跳转失败:', error) + if (typeof options.fail === 'function') { + options.fail(error) + } + } +} /* eslint-disable no-new */ new Vue({ diff --git a/src/router/index.js b/src/router/index.js index a4a977d..7241b3b 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -16,6 +16,24 @@ const router = new Router({ }, component: () => import('@/views/Index.vue') }, + { + path: '/Login', + name: 'Login', + meta: { + title: '登录 - 精品商城', + keepAlive: false + }, + component: () => import('@/views/Login.vue') + }, + { + path: '/Register', + name: 'Register', + meta: { + title: '注册 - 精品商城', + keepAlive: false + }, + component: () => import('@/views/Register.vue') + }, { path: '/Home', name: 'Home', @@ -209,24 +227,6 @@ const router = new Router({ // }, // component: () => import('@/views/OrderDetail.vue') // }, - { - path: '/Login', - name: 'Login', - meta: { - title: '登录 - 精品商城', - keepAlive: false - }, - component: () => import('@/views/Login.vue') - }, - { - path: '/Register', - name: 'Register', - meta: { - title: '注册 - 精品商城', - keepAlive: false - }, - component: () => import('@/views/Register.vue') - }, // { // path: '*', // name: 'NotFound',