chatapp-h5/h5/js/pageConfig-BUpLPO7w-1776148658686.js
2026-04-14 17:58:21 +08:00

2 lines
5.9 KiB
JavaScript

import{o as M,ao as F,U as z,ap as O,aq as x,ar as Y,as as C,at as q,au as V,av as $,i as J,ae as K,af as Q,g as u,e as X,p as Z,f as j,s as ee,a9 as T,r as m,u as ne}from"./index-CIAVq8iD-1776148658686.js";import{a as ae}from"./toast-aIWCznBB-1776148658686.js";function oe(i={}){const{needsBankBalance:t=!0,needsWorkStatistics:p=!0,needsTeamInfo:g=!1,needsRouteGuard:W=!0,forceRefresh:P=!1,onDataLoaded:k,onConnectionSuccess:o,onConnectionFailed:v}=i,A=ne(),y=m(!1),c=m(!1),l=m({}),B=m(null),a=T({id:"-",account:"-",userNickname:"user",name:"user",userAvatar:""}),d=T({hostSalary:0,currentSalary:0}),s=T({anchorType:"Chat",minutesProgress:0,minutesTotal:120,giftTask:0}),E=async()=>{console.group("🔗 APP Connection Process"),console.debug("🚀 Starting APP connection...");try{if(!J())return console.debug("🌐 Browser environment detected"),c.value=!0,console.groupEnd(),o&&o({environment:"browser"}),{success:!0,environment:"browser"};if(K()){console.debug("✅ APP already connected and valid"),c.value=!0;const n=Q();return n&&(l.value=n,console.debug("🔧 Using cached HTTP headers")),console.groupEnd(),o&&o({environment:"app",fromCache:!0}),{success:!0,environment:"app",fromCache:!0}}if(u.isConnecting())return console.debug("⏳ Connection already in progress, waiting..."),await u.getConnectionPromise(),c.value=!0,console.debug("✅ Connected via existing process"),console.groupEnd(),o&&o({environment:"app",fromCache:!0}),{success:!0,environment:"app",fromCache:!0};console.debug("📱 Establishing new APP connection...");const e=await new Promise((n,h)=>{const f=new Promise((L,D)=>{X(async U=>{try{const r=Z(U);r.success?(l.value=j(r.data),console.debug("🔧 Setting HTTP headers..."),await ee(l.value),c.value=!0,u.setConnected(l.value),console.debug("🎉 APP connection established successfully"),L({success:!0,environment:"app",fromCache:!1})):(console.error("❌ Failed to parse access origin:",r.error),u.reset(),D(new Error(r.error)))}catch(r){console.error("❌ Connection process failed:",r),u.reset(),D(r)}})});u.setConnecting(f),f.then(n).catch(h)});return console.debug("✅ Connection completed successfully"),console.groupEnd(),o&&o(e),e}catch(e){return console.error("❌ Connection failed:",e),c.value=!1,console.groupEnd(),v&&v(e),e.message&&e.message.includes("parse access")&&A.push({path:"/not_app",query:{message:e.message}}),{success:!1,error:e.message}}},w=async()=>{if(!P){const n=q();if(n){a.id=n.account,a.account=n.account,a.userNickname=n.userNickname,a.userAvatar=n.userAvatar;return}}const e=await V();e.status&&e.body&&(a.id=e.body.account,a.account=e.body.account,a.userNickname=e.body.userNickname,a.userAvatar=e.body.userAvatar)},I=async()=>{if(g){if(!P){const e=x();if(e)return console.log("teamInfo:",e),e}try{console.debug("🏢 Fetching team information...");const e=await Y();e&&e.status&&e.body?(console.debug("✅ Team information retrieved successfully"),C(e.body.teamProfile||e.body)):(console.warn("⚠️ Team entry response invalid or empty"),C(null))}catch(e){if(console.debug("🔴 Team info fetch error:",e),e.response&&e.response.body&&e.response.body.errorCode){const n=e.response.body.errorCode;switch(n){case 6025:console.debug("🚫 User is not a team member (6025)");break;case 6010:console.debug("🚫 Team not found or disbanded (6010)");break;default:console.debug("❌ Other team error:",n,e.response.body.message)}}C(null)}}},S=async()=>{if(t){y.value=!0;try{const e=await O();e.status&&typeof e.body=="number"?d.currentSalary=e.body.toFixed(2):d.currentSalary=0}catch(e){console.error("Failed to fetch bank balance:",e),d.currentSalary=0,ae("Failed to load balance. Please try again.")}finally{y.value=!1}}},R=async()=>{if(p)try{const e=await F("DAILY",z());if(e.status&&e.body){s.anchorType="Chat";const n=Number(e.body.ownTime)||0,h=Number(e.body.otherTime)||0,f=n+h;s.minutesProgress=f>=s.minutesTotal?s.minutesTotal:f,s.giftTask=e.body.acceptGiftValue||0}}catch(e){console.error("获取工作统计失败:",e)}},N=async()=>{console.debug("📊 Starting data initialization...");try{const e=[];e.push(w()),g&&e.push(I()),t&&e.push(S()),p&&e.push(R()),await Promise.all(e),W&&await $(A,z()),k&&k({userProfile:B.value,userInfo:a,salaryInfo:d,taskInfo:s}),console.debug("✅ Data initialization completed")}catch(e){console.error("❌ Data initialization failed:",e)}},G=()=>{a.userAvatar=""},_=()=>a.name&&a.name.length>0?a.name.charAt(0).toUpperCase():"U",b=async()=>{console.debug("📄 Page initialization started");try{(await E()).success?(console.debug("🔗 Connection successful, initializing data..."),await N()):console.warn("⚠️ Connection failed, skipping data initialization")}catch(e){console.error("❌ Page initialization failed:",e)}};return M(b),{loading:y,appConnected:c,headerInfo:l,userProfile:B,userInfo:a,salaryInfo:d,taskInfo:s,connectToApp:E,initializePageData:N,fetchUserInfo:w,fetchTeamInfo:I,fetchBankBalance:S,fetchWorkStatistics:R,handleImageError:G,getAvatarPlaceholder:_,initializePage:b,reinitialize:b}}const H={HOST_CENTER:{needsBankBalance:!0,needsWorkStatistics:!0,needsRouteGuard:!0,title:"Host Center",userTag:"👑 Host"},COIN_SELLER:{needsBankBalance:!0,needsWorkStatistics:!1,needsRouteGuard:!0,title:"Coin Seller",userTag:"💰 Coin Seller"},AGENCY_CENTER:{needsBankBalance:!0,needsWorkStatistics:!0,needsRouteGuard:!0,title:"Agency Center",userTag:"🏢 Agency"},BD_LEADER_CENTER:{needsBankBalance:!0,needsWorkStatistics:!1,needsRouteGuard:!0,title:"BD Leader Center",userTag:"📈 BD Leader"},BD_CENTER:{needsBankBalance:!0,needsWorkStatistics:!1,needsRouteGuard:!0,title:"BD Center",userTag:"📈 BD"},APPLY:{needsBankBalance:!1,needsWorkStatistics:!1,needsRouteGuard:!1,title:"Apply",userTag:null},ADMIN_CENTER:{needsBankBalance:!1,needsWorkStatistics:!1,needsRouteGuard:!0,title:"ADMIN Center",userTag:"ADMIN"}};function te(i){const t=H[i];return t||(console.warn(`未找到页面配置: ${i}`),H.HOST_CENTER)}function ie(i,t={}){const g={...te(i),...t};return oe(g)}export{ie as u};