diff --git a/mobile-app/src/App.tsx b/mobile-app/src/App.tsx index 7382508..9af2272 100644 --- a/mobile-app/src/App.tsx +++ b/mobile-app/src/App.tsx @@ -65,6 +65,7 @@ function Root(){ {page&&} {selected?.title||titles[page||tab]} + {!!selected?.guide&&Alert.alert(selected.title+' · 操作指引',selected.guide)} style={{padding:10}}>} {!page&&{variant==='prod'?'内网工作空间':'开发环境'}} @@ -83,9 +84,9 @@ function Root(){ } function Login({api,onLogin}:{api:ApiClient;onLogin:(token:string)=>Promise}){ const [username,setUsername]=useState(''),[password,setPassword]=useState(''),[code,setCode]=useState(''); - const [captcha,setCaptcha]=useState(null),[error,setError]=useState(''),[busy,setBusy]=useState(false); + const [captcha,setCaptcha]=useState(null),[error,setError]=useState(''),[busy,setBusy]=useState(false),[connecting,setConnecting]=useState(true); const lock=useRef(false),seq=useRef(0); - const refresh=useCallback(async()=>{const current=++seq.current;try{const data=await api.request('/captchaImage',{anonymous:true});if(current===seq.current){setCaptcha(data);setCode('');setError('');}}catch(e){if(current===seq.current)setError((e as Error).message);}},[api]); + const refresh=useCallback(async()=>{const current=++seq.current;setConnecting(true);setCaptcha(null);setError('');try{let data:Row;try{data=await api.request('/captchaImage',{anonymous:true});}catch(e){if((e as {code?:number}).code!==409)throw e;data=await api.request('/captchaImage',{anonymous:true});}if(current===seq.current){setCaptcha(data);setCode('');}}catch(e){if(current===seq.current)setError((e as Error).message);}finally{if(current===seq.current)setConnecting(false);}},[api]); useEffect(()=>{void refresh();return()=>{seq.current++;};},[refresh]); async function submit(){if(lock.current)return;if(!captcha){setError('请先连接服务获取登录信息。');return;} if(!username.trim()||!password||captcha.captchaEnabled!==false&&!code.trim()){setError('请填写账号、密码和验证码。');return;} @@ -94,10 +95,11 @@ function Login({api,onLogin}:{api:ApiClient;onLogin:(token:string)=>Promise CMVR · 项目物资管理欢迎回到工作空间请连接公司内网,使用现有账号登录。 - {captcha?.captchaEnabled!==false&&<> + {connecting&&正在连接内网服务,准备登录信息…} + {!!captcha&&captcha.captchaEnabled!==false&&<> {!!captcha?.img&&void refresh()}>}} {!!error&&{error}}