version temp2

This commit is contained in:
2025-10-24 17:08:42 +08:00
parent c1dd5551f0
commit 1a919d57ba
193 changed files with 15044 additions and 15687 deletions

View File

@@ -14,6 +14,16 @@ import { useSEO } from '@/composables/useSEO'
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
// 路由切换时的滚动行为
scrollBehavior(to, from, savedPosition) {
// 如果有保存的位置(浏览器前进/后退)
if (savedPosition) {
return savedPosition;
} else {
// 否则滚动到顶部
return { top: 0, behavior: "smooth" };
}
},
routes: [
{
path: '/',
@@ -349,56 +359,85 @@ NProgress.configure({
// 路由导航守卫
router.beforeEach(async (to, from, next) => {
NProgress.start() // 启动进度条
const isAuthenticated = localStorage.getItem('token')
const agentStore = useAgentStore()
const userStore = useUserStore()
const dialogStore = useDialogStore()
const { isWeChat } = useEnv()
const { isAgent, isLoaded } = storeToRefs(agentStore)
const { mobile, isLoggedIn } = storeToRefs(userStore)
NProgress.start(); // 启动进度条
const isAuthenticated = localStorage.getItem("token");
const agentStore = useAgentStore();
const userStore = useUserStore();
const dialogStore = useDialogStore();
const authStore = useAuthStore();
const { isWeChat } = useEnv();
const { isAgent, isLoaded } = storeToRefs(agentStore);
const { mobile, isLoggedIn } = storeToRefs(userStore);
const { isWeixinAuthing, weixinAuthComplete } = storeToRefs(authStore);
// 微信环境下,如果正在进行授权,等待授权完成
if (isWeChat.value && isWeixinAuthing.value && !weixinAuthComplete.value) {
// 等待授权完成,使用响应式监听
await new Promise((resolve) => {
const stopWatcher = watch(
[isWeixinAuthing, weixinAuthComplete],
([authing, complete]) => {
if (!authing || complete) {
stopWatcher();
resolve();
}
},
{ immediate: true }
);
});
}
// 处理需要登录的页面
if (to.meta.requiresAuth && !isAuthenticated) {
if (isWeChat.value) {
next('/')
location.reload()
// 微信环境下,如果授权失败或超时,重定向到首页
if (!weixinAuthComplete.value) {
next("/");
location.reload();
} else {
// 授权完成但仍无token可能是授权失败
next("/");
location.reload();
}
} else {
next('/login')
next("/login");
}
return
return;
}
// 已登录状态下的处理
if (isAuthenticated) {
// 确保用户信息已加载
if (!isLoggedIn.value) {
await userStore.fetchUserInfo()
await userStore.fetchUserInfo();
}
// 检查手机号绑定状态
// 只有在未绑定手机号且目标路由需要登录并且没有设置notNeedBindPhone时才弹出绑定手机号弹窗
if (!mobile.value && to.meta.requiresAuth && !to.meta.notNeedBindPhone) {
dialogStore.openBindPhone()
next(false)
return
if (
!mobile.value &&
to.meta.requiresAuth &&
!to.meta.notNeedBindPhone
) {
dialogStore.openBindPhone();
next(false);
return;
}
// 检查代理权限
if (to.meta.requiresAgent) {
if (!isLoaded.value) {
await agentStore.fetchAgentStatus()
await agentStore.fetchAgentStatus();
}
if (!isAgent.value) {
next('/agent/invitationAgentApply/self')
return
next("/agent/invitationAgentApply/self");
return;
}
}
}
// 其他情况正常通过
next()
next();
})
router.afterEach((to) => {