|
@@ -38,7 +38,7 @@
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|
|
|
import { ref, onMounted, onBeforeUnmount, computed, watch } from "vue";
|
|
import { ref, onMounted, onBeforeUnmount, computed, watch } from "vue";
|
|
|
-import { useRoute } from "vue-router";
|
|
|
|
|
|
|
+import { useRoute, useRouter } from "vue-router";
|
|
|
import Header from "@/components/layout/Header.vue";
|
|
import Header from "@/components/layout/Header.vue";
|
|
|
import Footer from "@/components/layout/Footer.vue";
|
|
import Footer from "@/components/layout/Footer.vue";
|
|
|
import LoginDialog from "@/components/LoginDialog.vue";
|
|
import LoginDialog from "@/components/LoginDialog.vue";
|
|
@@ -47,6 +47,7 @@ import { useUserStore } from "@/store/user";
|
|
|
type TabKey = "home" | "purchased" | "account" | "favorite";
|
|
type TabKey = "home" | "purchased" | "account" | "favorite";
|
|
|
|
|
|
|
|
const route = useRoute();
|
|
const route = useRoute();
|
|
|
|
|
+const router = useRouter();
|
|
|
const active = ref<TabKey>("home");
|
|
const active = ref<TabKey>("home");
|
|
|
const showScrollTop = ref(false);
|
|
const showScrollTop = ref(false);
|
|
|
const showLoginDialog = ref(false);
|
|
const showLoginDialog = ref(false);
|
|
@@ -82,7 +83,19 @@ function switchTab(key: TabKey) {
|
|
|
showLoginDialog.value = true;
|
|
showLoginDialog.value = true;
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- // 这里不再需要手动设置active,因为路由变化会自动更新
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 根据tab跳转到对应路由
|
|
|
|
|
+ const routeMap: Record<TabKey, string> = {
|
|
|
|
|
+ home: "/",
|
|
|
|
|
+ purchased: "/purchased",
|
|
|
|
|
+ account: "/account",
|
|
|
|
|
+ favorite: "/favorite",
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const targetRoute = routeMap[key];
|
|
|
|
|
+ if (targetRoute && route.path !== targetRoute) {
|
|
|
|
|
+ router.push(targetRoute);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function handleLoginSuccess() {
|
|
function handleLoginSuccess() {
|