cmvr-wms/mobile-app/src/LegacyUpgrade.tsx

21 lines
3.4 KiB
TypeScript
Raw Normal View History

import React,{useEffect,useState} from 'react';
import {ActivityIndicator,Linking,Pressable,ScrollView,Text,View} from 'react-native';
import {SafeAreaProvider,SafeAreaView} from 'react-native-safe-area-context';
import {getOfficialPackage,officialPackageUrl,type OfficialAppPackage} from './core/official-app-update';
/** Recovery entry for signed OTA channels whose APK predates the installer bridge. */
export default function LegacyUpgrade(){
const [release,setRelease]=useState<OfficialAppPackage|null>(null),[error,setError]=useState(''),[attempt,setAttempt]=useState(0),[busy,setBusy]=useState(false);
useEffect(()=>{let alive=true;const controller=new AbortController(),timer=setTimeout(()=>controller.abort(),15000);setError('');setRelease(null);void getOfficialPackage(controller.signal).then(value=>{if(alive)setRelease(value);}).catch(()=>{if(alive)setError('暂时无法连接下载服务,请联网后重试。');}).finally(()=>clearTimeout(timer));return()=>{alive=false;controller.abort();clearTimeout(timer);};},[attempt]);
async function open(){if(!release||busy)return;setBusy(true);setError('');try{await Linking.openURL(officialPackageUrl(release));}catch{setError('未能打开浏览器,请确认手机已安装浏览器后重试。');}finally{setBusy(false);}}
return <SafeAreaProvider><SafeAreaView style={{flex:1,backgroundColor:'#f4f7fc'}}><ScrollView contentContainerStyle={{flexGrow:1,justifyContent:'center',padding:24}}><View style={{width:'100%',maxWidth:420,alignSelf:'center',backgroundColor:'#fff',padding:24,borderRadius:20,gap:18}}>
<Text allowFontScaling={false} style={{fontSize:13,color:'#3563d9'}}>设备科综合管理系统</Text><Text allowFontScaling={false} style={{fontSize:21,fontWeight:'700',color:'#182337'}}>升级至正式新版</Text>
<Text allowFontScaling={false} style={{fontSize:14,lineHeight:23,color:'#526174'}}>当前旧版本需要通过浏览器下载安装包,再由手机系统完成安装。直接覆盖安装即可,无需卸载原应用。</Text>
{release?<><Text allowFontScaling={false} style={{fontSize:14,fontWeight:'600',color:'#182337'}}>版本 {release.versionName} · {(release.size/1024**2).toFixed(1)} MB</Text>{release.notes.map((note,index)=><Text key={index} allowFontScaling={false} style={{fontSize:13,lineHeight:21,color:'#526174'}}>• {note}</Text>)}</>:!error?<ActivityIndicator color="#3563d9"/>:null}
{!!error&&<Text accessibilityRole="alert" allowFontScaling={false} style={{fontSize:13,lineHeight:21,color:'#bc3345'}}>{error}</Text>}
<Pressable accessibilityRole="button" accessibilityLabel="浏览器下载安装" disabled={!release||busy} onPress={()=>void open()} style={{backgroundColor:!release||busy?'#aac0f3':'#3563d9',paddingVertical:14,borderRadius:10,alignItems:'center'}}><Text allowFontScaling={false} style={{color:'#fff',fontWeight:'600',fontSize:15}}>{busy?'正在打开…':'浏览器下载安装'}</Text></Pressable>
<Pressable accessibilityRole="button" accessibilityLabel="重新检查" onPress={()=>setAttempt(n=>n+1)} style={{padding:10,alignItems:'center'}}><Text allowFontScaling={false} style={{color:'#3563d9',fontSize:13}}>重新检查</Text></Pressable>
<Text allowFontScaling={false} style={{fontSize:12,lineHeight:20,color:'#7a8697'}}>下载后在浏览器中打开安装包;如有提示,允许浏览器安装应用。账号和原有数据无需重新录入。</Text>
</View></ScrollView></SafeAreaView></SafeAreaProvider>;
}