diff --git a/src/pages/login/comonents/PhoneLogin.tsx b/src/pages/login/comonents/PhoneLogin.tsx index 8bf932f..ce62d2d 100644 --- a/src/pages/login/comonents/PhoneLogin.tsx +++ b/src/pages/login/comonents/PhoneLogin.tsx @@ -7,10 +7,11 @@ import { useIsMobile } from '@/hooks/use-mobile'; import ClickTextCapt from "@/components/goCaptcha/ClickTextCapt.jsx"; interface PhoneLoginProps { - onLogin: (phone: string, code: string) => void; + onLogin?: (phone: string, code: string) => void; + handleLoginSuccess: (token: string) => void; } -const PhoneLogin: React.FC = ({ handleLoginSuccess }) => { +const PhoneLogin: React.FC = ({ onLogin, handleLoginSuccess }) => { const [phone, setPhone] = useState(''); const [code, setCode] = useState(''); const [countdown, setCountdown] = useState(0); @@ -60,6 +61,12 @@ const PhoneLogin: React.FC = ({ handleLoginSuccess }) => { return; } + // 如果有 onLogin 回调,先调用它 + if (onLogin) { + onLogin(phone, code); + return; + } + setIsLoading(true); try { const response = await request(`/api/login`, { diff --git a/src/pages/login/index.jsx b/src/pages/login/index.jsx index aa4a2a4..e475782 100644 --- a/src/pages/login/index.jsx +++ b/src/pages/login/index.jsx @@ -1,9 +1,13 @@ -import React from 'react'; +import React, { useState } from 'react'; import { useNavigate } from 'react-router-dom'; import PhoneLogin from './comonents/PhoneLogin'; +import WechatLogin from './comonents/WechatLogin'; +import { useIsMobile } from '@/hooks/use-mobile'; export default function Login() { const navigate = useNavigate(); + const [loginType, setLoginType] = useState('wechat'); // 'phone' | 'wechat' + const isMobile = useIsMobile(); const handleLoginSuccess = (token) => { localStorage.setItem('token', token); @@ -17,9 +21,40 @@ export default function Login() { } }, []); + // 切换登录方式的按钮 + const renderSwitchButton = () => ( +
+ +
+ ); + return (
- + {/* renderSwitchButton() */} + {loginType === 'phone' ? ( + + ) : ( + + )}
); } \ No newline at end of file diff --git a/src/utils/request.ts b/src/utils/request.ts index c04ce00..649c9b3 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -1,4 +1,5 @@ // 优先使用运行时配置,降级到构建时配置 +// 在开发环境使用代理,生产环境使用完整URL const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || ''; export async function request(url: string, options: RequestInit = {}) { const token = localStorage.getItem('token'); diff --git a/tsconfig.app.json b/tsconfig.app.json index 14ad442..92b5583 100644 --- a/tsconfig.app.json +++ b/tsconfig.app.json @@ -1,13 +1,33 @@ { - "compilerOptions": { - // ... - "baseUrl": ".", - "paths": { - "@/*": [ - "./src/*" - ] - } - // ... + "compilerOptions": { + "target": "ES2020", + "useDefineForClassFields": true, + "lib": ["ES2020", "DOM", "DOM.Iterable"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "allowSyntheticDefaultImports": true, + "esModuleInterop": true, + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true, + + /* Path mapping */ + "baseUrl": ".", + "paths": { + "@/*": ["./src/*"] } - } - \ No newline at end of file + }, + "include": ["src"], + "references": [{ "path": "./tsconfig.node.json" }] +} \ No newline at end of file diff --git a/vite.config.ts b/vite.config.ts index 405cd2f..e0a3eea 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -11,14 +11,14 @@ export default defineConfig({ port: 3000, open: true, host: true, - // 如果有跨域需求,可以添加代理配置 - // proxy: { - // '/api': { - // target: 'your-api-url', - // changeOrigin: true, - // rewrite: (path) => path.replace(/^\/api/, '') - // } - // } + // 代理配置解决跨域问题 + proxy: { + '/api': { + target: 'http://localhost:8082', + changeOrigin: true, + secure: false + } + } }, resolve: { alias: {