import { useState } from 'react'; import { View, Text, Button, ScrollView } from '@tarojs/components'; import Taro from '@tarojs/taro'; import { useAuthStore } from '../../stores/auth'; import { useElderClass } from '../../hooks/useElderClass'; import './index.scss'; export default function Login() { const modeClass = useElderClass(); const [needBind, setNeedBind] = useState(false); const [agreed, setAgreed] = useState(false); const { login, bindPhone, loading, isMedicalStaff } = useAuthStore(); // 登录页不应用关怀模式(正常模式尺寸已足够大) const loginClass = ''; const navigateAfterLogin = () => { if (isMedicalStaff()) { Taro.redirectTo({ url: '/pages/doctor/index' }); } else { Taro.switchTab({ url: '/pages/index/index' }); } }; const handleWechatLogin = async () => { if (!agreed) { Taro.showToast({ title: '请先阅读并同意用户协议', icon: 'none' }); return; } try { const { code } = await Taro.login(); const result = await login(code); if (result) { navigateAfterLogin(); } else { setNeedBind(true); Taro.showToast({ title: '请授权手机号完成绑定', icon: 'none' }); } } catch (err: any) { const msg = err?.message || '登录失败,请重试'; Taro.showToast({ title: msg.substring(0, 20), icon: 'none', duration: 3000 }); } }; const handleGetPhone = async (e: { detail: { errMsg: string; encryptedData: string; iv: string } }) => { if (!agreed) { Taro.showToast({ title: '请先阅读并同意用户协议', icon: 'none' }); return; } if (e.detail.errMsg !== 'getPhoneNumber:ok') { Taro.showToast({ title: '需要授权手机号', icon: 'none' }); return; } const { encryptedData, iv } = e.detail; try { const success = await bindPhone(encryptedData, iv); if (success) { navigateAfterLogin(); } } catch (err: any) { const msg = err?.message || '绑定失败'; Taro.showModal({ title: '绑定手机号失败', content: msg, confirmText: '重新登录', cancelText: '取消', success: (res) => { if (res.confirm) { setNeedBind(false); } }, }); } }; return ( {/* 品牌区 */} + 健康管理 您的专属健康管家 {/* 装饰线 */} {/* 登录按钮 */} {!needBind ? ( ) : ( )} {/* 协议 */} setAgreed(!agreed)}> {agreed && } 我已阅读并同意 Taro.navigateTo({ url: '/pages/legal/user-agreement' })}>《用户服务协议》 Taro.navigateTo({ url: '/pages/legal/privacy-policy' })}>《隐私政策》 {/* 暂不登录 */} Taro.reLaunch({ url: '/pages/index/index' })}> 暂不登录,先看看 ); }