import{r as e,j as o}from"./jsx-runtime-BnbLqBWP.js";import{B as s}from"./button-crrhp8Py.js";import{g as t,a as n}from"./config-D3MzvER9.js";import{u as l}from"./components-B5_r6Vif.js";import"./_commonjsHelpers-TUi1EdFu.js";import"./index-BYVAcnYn.js";import"./utils-G3MRPmKb.js";import"./index-C4j0XBvN.js";import"./router-BXPf1XsM.js";import"./single-fetch-vTdWVr6V.js";const c={hideNavigation:!0};function a(){const{corpid:c,agentid:a,APP_DOMAIN:i,APP_URL:r}=l(),[d,m]=e.useState(null),[x,g]=e.useState(""),[h,p]=e.useState(!1),[u,w]=e.useState(!1),[f,j]=e.useState(!1);e.useEffect((()=>{w(!0),console.log("[详细日志] 检测到浏览器环境")}),[]),e.useEffect((()=>{if(u){const e=navigator.userAgent.toLowerCase(),o=e.includes("wxwork")||e.includes("wework");j(o),console.log("[详细日志] 检测到浏览器环境: ",e),console.log("[详细日志] 是否在企业微信内: ",o);const s=new URL(window.location.href).searchParams.get("error");if(s&&(console.log("[详细日志] URL中包含错误信息:",s),m(s),s.includes("错误码:"))){const e=s.match(/\(错误码: (\d+), 错误消息: (.*?)\)/);if(e&&e.length>=3){const o=e[1],s=e[2];let t="";switch(o){case"40029":t="授权码无效,可能是二维码已过期,请重新扫码";break;case"40013":case"41001":t="企业微信访问令牌异常,请联系管理员";break;case"42001":t="企业微信访问令牌已过期,请重新扫码";break;case"60011":t="用户不在当前企业中,请确认您是否已加入企业";break;default:t=`企业微信错误: ${s}`}g(t),console.log("[详细日志] 解析出的错误详情:",t)}}console.log("[详细日志] 当前企业微信授权页面URL:",window.location.href)}}),[u]);e.useEffect((()=>{if(!u)return;const e=i||t(),o=r||n();console.log("[详细日志] 当前域名环境:"),console.log(`- window.location.origin: ${window.location.origin}`),console.log(`- window.location.host: ${window.location.host}`),console.log(`- window.location.hostname: ${window.location.hostname}`),console.log(`- APP_DOMAIN (loader): ${i}`),console.log(`- APP_URL (loader): ${r}`),console.log(`- APP_DOMAIN (config): ${t()}`),console.log(`- APP_URL (config): ${n()}`),console.log(`- domain (使用中): ${e}`),console.log(`- appUrl (使用中): ${o}`);const s=window.location.hostname.endsWith(".pages.dev");console.log(`- 是否为Cloudflare Pages环境: ${s}`)}),[u,i,r]);const y=`https://buy.dorapush.com/qywx/qrcode?state=${encodeURIComponent("/my-tasks")}&redirect_uri=${encodeURIComponent("https://buy.dorapush.com/qywx/callback")}`;return console.log("[详细日志] 二维码iframe URL:",y),o.jsxs("div",{className:"flex min-h-screen items-center justify-center bg-white px-4 py-12 sm:px-6 lg:px-8",children:[o.jsxs("div",{className:"text-center mb-8",children:[o.jsx("h2",{className:"text-2xl font-bold text-gray-900",children:f?"企业微信登录":"企业微信扫码登录"}),o.jsx("p",{className:"mt-2 text-sm text-gray-600",children:f?"您正在使用企业微信,点击下方按钮登录":"请使用企业微信扫描二维码登录系统"}),o.jsxs("p",{className:"mt-2 text-sm text-gray-600",children:[o.jsx("strong",{children:"注意:"}),"只有已加入团队的用户才能成功登录"]}),o.jsx("p",{className:"mt-2 text-sm text-gray-600",children:"若您尚未加入团队,请联系管理员获取邀请"}),o.jsx("p",{className:"mt-2 text-sm text-gray-600",children:'登录时请在企业微信选择"待加入企业/团队"选项'}),d&&o.jsxs("div",{className:"mt-4 p-4 bg-red-50 text-red-600 rounded-md",children:[o.jsx("p",{className:"font-medium",children:d}),x&&o.jsx("p",{className:"mt-2 text-sm",children:x}),o.jsx("button",{onClick:()=>{console.log("[详细日志] 用户点击重试按钮"),window.location.href="/qywx/login"},className:"mt-3 px-4 py-2 bg-red-100 hover:bg-red-200 text-red-700 rounded transition-colors",children:"重试登录"})]})]}),o.jsx("div",{className:"bg-white p-8 rounded-lg shadow-sm w-full max-w-md",children:f?o.jsxs("div",{className:"flex flex-col items-center",children:[o.jsx(s,{onClick:()=>{console.log("[详细日志] 用户点击登录按钮,准备跳转");const e=`https://buy.dorapush.com/qywx/auto-login?redirect=${encodeURIComponent("/my-tasks")}`;console.log("[详细日志] 跳转到buy域名处理登录:",e),window.location.href=e},className:"w-full max-w-xs py-6 text-lg",children:"点击登录"}),o.jsx("p",{className:"mt-4 text-xs text-gray-500",children:"点击按钮后将使用您的企业微信账号进行登录"})]}):c&&a?o.jsx("div",{id:"wechat-login-container",className:"flex justify-center",style:{height:"400px"},children:u&&o.jsx("iframe",{src:y,frameBorder:"0",scrolling:"no",style:{width:"100%",height:"100%",border:"none"},title:"企业微信扫码登录"})}):o.jsx("div",{className:"text-center text-red-500",children:"企业微信配置信息缺失,请检查环境变量设置"})})]})}export{a as default,c as handle};