diff --git a/src/api/wallet.js b/src/api/wallet.js index 9e98565..0860187 100644 --- a/src/api/wallet.js +++ b/src/api/wallet.js @@ -70,6 +70,13 @@ export function getTeamEntry() { return get('/team/entry') } +/** + * 获取用户信息(仅用户信息) + */ +export function getMemberProfile() { + return get('/team/member/profile') +} + /** * 校验金币销售商权限 * @returns {Promise} 返回是否具有销售商权限 diff --git a/src/utils/routeGuard.js b/src/utils/routeGuard.js index 3a1ef51..0542ba5 100644 --- a/src/utils/routeGuard.js +++ b/src/utils/routeGuard.js @@ -4,7 +4,7 @@ */ import { permissionManager, PAGES, USER_ROLES } from './permissionManager.js' -import { getUserIdentity, getTeamEntry } from '../api/wallet.js' +import {getUserIdentity, getMemberProfile} from '../api/wallet.js' import {getUserId, setUserInfo} from './userStore.js' import { connectApplication, parseAccessOrigin, parseHeader, setHttpHeaders, isInApp } from './appBridge.js' import { appConnectionManager, isAppConnected } from './appConnectionManager.js' @@ -115,14 +115,12 @@ class AppConnectionChecker { try { console.debug('👤 Fetching user info after connection...') - const response = await getTeamEntry() + const response = await getMemberProfile() if (response && response.status && response.body) { // 缓存用户信息 - if (response.body.memberProfile) { - setUserInfo(response.body.memberProfile, response.body.teamProfile) - console.debug('✅ User info cached successfully') - } + console.debug('✅ User info cached successfully') + setUserInfo(response.body, null) } else { console.warn('⚠️ Failed to get team entry or invalid response') } diff --git a/src/utils/usePageInitialization.js b/src/utils/usePageInitialization.js index a27c0ce..32ff88b 100644 --- a/src/utils/usePageInitialization.js +++ b/src/utils/usePageInitialization.js @@ -1,11 +1,10 @@ -// src/composables/usePageInitialization.js import { ref, reactive, onMounted } from 'vue' import { useRouter } from 'vue-router' -import { getBankBalance, getTeamEntry, getTeamMemberWorkStatistics } from '../api/wallet.js' +import {getBankBalance, getMemberProfile, getTeamMemberWorkStatistics} from '../api/wallet.js' import { connectApplication, parseAccessOrigin, parseHeader, setHttpHeaders, isInApp } from '../utils/appBridge.js' import { appConnectionManager, isAppConnected, getAppHeaderInfo } from '../utils/appConnectionManager.js' import { checkAndRedirect } from '../utils/routeGuard.js' -import { getUserId, setUserInfo } from '../utils/userStore.js' +import { getUserId } from '../utils/userStore.js' import { showError } from '../utils/toast.js' /** @@ -24,6 +23,7 @@ export function usePageInitialization(options = {}) { const { needsBankBalance = true, needsWorkStatistics = true, + needsTeamInfo = false, needsRouteGuard = true, onDataLoaded, onConnectionSuccess, @@ -194,6 +194,15 @@ export function usePageInitialization(options = {}) { } } + const fetchUserInfo = async () => { + const res = await getMemberProfile() + if (res.status && res.body) { + userInfo.id = res.body.account + userInfo.userNickname = res.body.userNickname + userInfo.userAvatar = res.body.userAvatar + } + } + /** * 获取银行余额 */ @@ -241,60 +250,6 @@ export function usePageInitialization(options = {}) { } } - /** - * 获取团队入口信息 - */ - const fetchTeamEntry = async () => { - try { - const response = await getTeamEntry() - - if (response && response.status && response.body) { - userProfile.value = response.body - - // 缓存用户信息 - if (response.body.memberProfile) { - setUserInfo(response.body.memberProfile, response.body.teamProfile) - - // 更新用户信息显示 - userInfo.userNickname = response.body.memberProfile.userNickname - userInfo.id = response.body.memberProfile.account - userInfo.userAvatar = response.body.memberProfile.userAvatar - } - - return response.body.memberProfile?.id - } - } catch (error) { - console.error('获取团队信息失败:', error) - - // 检查错误状态码 - const errorMessage = error.message || '' - const errorStatus = error.response?.status || error.status - - console.log('Error details:', { errorMessage, errorStatus, error }) - - // HTTP 406错误通常表示NOT_TEAM_MEMBER,应该跳转到apply - if (errorStatus === 406 || errorMessage.includes('406')) { - console.log('跳转到 apply 页面') - await router.replace('/apply') - return null - } - - // HTTP 401错误表示未授权,应该跳转到not_app - if (errorStatus === 401 || errorMessage.includes('401')) { - console.log('跳转到 not_app 页面') - await router.replace({ - path: '/not_app', - query: { message: errorMessage } - }) - return null - } - - // 其他错误,记录但不跳转 - console.warn('未处理的错误:', error) - } - return null - } - /** * 数据初始化函数 */ @@ -302,40 +257,42 @@ export function usePageInitialization(options = {}) { console.debug('📊 Starting data initialization...') try { - // 获取团队信息 - const teamEntryResult = await fetchTeamEntry() - if (teamEntryResult != null) { - // 并行获取银行余额和工作统计(提高性能) - const dataPromises = [] + const dataPromises = [] - if (needsBankBalance) { - dataPromises.push(fetchBankBalance()) - } + dataPromises.push(fetchUserInfo()) - if (needsWorkStatistics) { - dataPromises.push(fetchWorkStatistics()) - } - - // 等待所有数据加载完成 - await Promise.all(dataPromises) - - // 使用路由守卫进行身份检查和重定向 - if (needsRouteGuard) { - await checkAndRedirect(router, teamEntryResult) - } - - // 触发数据加载完成回调 - if (onDataLoaded) { - onDataLoaded({ - userProfile: userProfile.value, - userInfo: userInfo, - salaryInfo: salaryInfo, - taskInfo: taskInfo - }) - } - - console.debug('✅ Data initialization completed') + if (needsTeamInfo) { + // dataPromises.push() } + + if (needsBankBalance) { + dataPromises.push(fetchBankBalance()) + } + + if (needsWorkStatistics) { + dataPromises.push(fetchWorkStatistics()) + } + + // 等待所有数据加载完成 + await Promise.all(dataPromises) + + // 使用路由守卫进行身份检查和重定向 + if (needsRouteGuard) { + await checkAndRedirect(router, getUserId()) + } + + // 触发数据加载完成回调 + if (onDataLoaded) { + onDataLoaded({ + userProfile: userProfile.value, + userInfo: userInfo, + salaryInfo: salaryInfo, + taskInfo: taskInfo + }) + } + + console.debug('✅ Data initialization completed') + } catch (error) { console.error('❌ Data initialization failed:', error) } @@ -400,7 +357,6 @@ export function usePageInitialization(options = {}) { initializePageData, fetchBankBalance, fetchWorkStatistics, - fetchTeamEntry, handleImageError, getAvatarPlaceholder, initializePage, diff --git a/src/views/BDCenterView.vue b/src/views/BDCenterView.vue index d08074e..ee6acda 100644 --- a/src/views/BDCenterView.vue +++ b/src/views/BDCenterView.vue @@ -86,9 +86,7 @@ import { ref } from 'vue' import { useRouter } from 'vue-router' import MobileHeader from '../components/MobileHeader.vue' -import { getUserIdentity, getTeamEntry } from '../api/wallet.js' import {getAgentMonthLastTarget, getAgentMonthTarget, getTeamMemberCount} from '../api/teamBill.js' -import { setUserInfo } from '../utils/userStore.js' import { getTeamId } from '@/utils/userStore.js' import {usePageInitializationWithConfig} from "@/utils/pageConfig.js"; import {isInApp} from "@/utils/appBridge.js"; @@ -96,9 +94,6 @@ import {isInApp} from "@/utils/appBridge.js"; const router = useRouter() // 当前身份 -const currentIdentity = ref('bd') -const userProfile = ref(null) -const identityChecked = ref(false) const teamMemberCount = ref(0) const loadingMemberCount = ref(false) @@ -137,99 +132,6 @@ const getAgentMonth = async () => { } -const goToNotification = () => { - router.push('/bd-setting') -} - -// 获取团队入口信息 -const fetchTeamEntry = async () => { - try { - const response = await getTeamEntry() - - if (response && response.status && response.body) { - userProfile.value = response.body - - // 缓存用户信息 - if (response.body.memberProfile) { - setUserInfo(response.body.memberProfile, response.body.teamProfile) - - // 更新用户信息显示 - userInfo.userNickname = response.body.memberProfile.userNickname - userInfo.id = response.body.memberProfile.account - userInfo.userAvatar = response.body.memberProfile.userAvatar - } - - // 获取用户ID后检查身份 - const userId = response.body.memberProfile?.id - if (userId) { - await checkUserIdentity(userId) - } - - return userId - } - } catch (error) { - console.error('获取团队信息失败:', error) - // HTTP 406错误通常表示NOT_TEAM_MEMBER - if (error.message && error.message.includes('406')) { - await router.push('/apply') - return - } - if (error.message && error.message.includes('401')) { - await router.push({ - path: '/not_app', - query: { message: error.message } - }) - return - } - } - return null -} - -// 获取用户身份并自动跳转 -const checkUserIdentity = async (userId) => { - if (!userId) { - console.error('用户ID不存在') - return - } - - // 防止重复检查 - if (identityChecked.value) { - console.debug('身份已检查,跳过') - return - } - - try { - identityChecked.value = true - const response = await getUserIdentity(userId) - - if (response && response.status && response.body) { - const { freightAgent, anchor, agent } = response.body - - console.debug('用户身份权限:', { freightAgent, anchor, agent }) - - // 根据优先级判断:freightAgent > anchor > agent > bd(默认) - if (freightAgent) { - console.debug('跳转到 coin-seller') - // router.replace('/coin-seller') - } else if (agent) { - console.debug('跳转到 agency-center') - // router.replace('/agency-center') - } else if (anchor) { - console.debug('跳转到 host-center') - // router.replace('/host-center') - } else { - // 如果没有任何权限,保持在BD页面 - console.debug('保持在 bd-center') - currentIdentity.value = 'bd' - } - } - } catch (error) { - console.error('获取用户身份失败:', error) - // 出错时保持在BD页面 - currentIdentity.value = 'bd' - } -} - const goToTeamMember = () => { router.push('/team-member') } diff --git a/src/views/LoadingView.vue b/src/views/LoadingView.vue index 8580b25..1dcdd29 100644 --- a/src/views/LoadingView.vue +++ b/src/views/LoadingView.vue @@ -49,7 +49,7 @@ import { ref, onMounted, onUnmounted } from 'vue' import { useRouter } from 'vue-router' import { isInApp, connectApplication, parseAccessOrigin, parseHeader, setHttpHeaders } from '../utils/appBridge.js' import { appConnectionManager } from '../utils/appConnectionManager.js' -import { getTeamEntry } from '../api/wallet.js' +import {getMemberProfile} from '../api/wallet.js' import { setUserInfo } from '../utils/userStore.js' const router = useRouter() @@ -162,16 +162,13 @@ const waitForLoadingComplete = () => { const navigateToTargetPage = async () => { try { // 尝试获取用户信息来判断跳转目标 - const response = await getTeamEntry() + const response = await getMemberProfile() if (response && response.status && response.body) { // 有团队信息,根据默认设置跳转到主页 - const memberProfile = response.body.memberProfile + const memberProfile = response.body if (memberProfile) { - setUserInfo(memberProfile, response.body.teamProfile) - - // 根据用户身份跳转到对应页面 - // 这里可以根据需要调整默认跳转逻辑 + setUserInfo(memberProfile, null) router.replace('/host-center') } else { router.replace('/apply')