优化采购实时编辑与权限,支持先到货后补报价、按批次补录照片和批量附件上传。更新验收报告模板及明细选择,增加验收发票独立管理和付款前置校验。完善 BOM 数据权限及 App 更新兼容性。
33 lines
5.9 KiB
TypeScript
33 lines
5.9 KiB
TypeScript
import React,{useEffect,useRef,useState} from 'react';
|
||
import {ActivityIndicator,Pressable,ScrollView,Text,View} from 'react-native';
|
||
import {SafeAreaProvider,SafeAreaView} from 'react-native-safe-area-context';
|
||
import * as FileSystem from 'expo-file-system/legacy';
|
||
import * as SecureStore from 'expo-secure-store';
|
||
import {getOfficialPackage,officialAppOrigin,officialAppInternalOrigin,officialDownloadOrigin,type OfficialAppPackage} from './core/official-app-update';
|
||
import {downloadLegacyPackage} from './core/legacy-package-download';
|
||
|
||
/** Compatibility entry: verified download inside the app, then Android performs the signed upgrade. */
|
||
export default function LegacyUpgrade(){
|
||
const [release,setRelease]=useState<OfficialAppPackage|null>(null),[error,setError]=useState(''),[attempt,setAttempt]=useState(0),[busy,setBusy]=useState(false),[progress,setProgress]=useState(0),[phase,setPhase]=useState('正在下载');
|
||
const origin=useRef(officialAppOrigin),ctl=useRef<AbortController|null>(null),alive=useRef(true),locked=useRef(false);
|
||
const [selectedOrigin,setSelectedOrigin]=useState(officialAppOrigin);
|
||
useEffect(()=>{alive.current=true;const controller=new AbortController(),timer=setTimeout(()=>controller.abort(),15000);setError('');setRelease(null);
|
||
void(async()=>{const selected=await SecureStore.getItemAsync('cmvr.prod.connection').catch(()=>null);if(controller.signal.aborted)throw Error('取消检查');try{origin.current=officialDownloadOrigin((selected||officialAppOrigin).replace(/\/prod-api$/,''));}catch{origin.current=officialAppOrigin;}if(alive.current)setSelectedOrigin(origin.current);return getOfficialPackage(controller.signal,undefined,fetch,origin.current);})().then(value=>{if(alive.current&&!controller.signal.aborted)setRelease(value);}).catch(()=>{if(alive.current&&!controller.signal.aborted)setError('暂时无法连接更新服务,请检查当前内网或外网连接后重试。');}).finally(()=>clearTimeout(timer));
|
||
return()=>{alive.current=false;controller.abort();ctl.current?.abort();clearTimeout(timer);};},[attempt]);
|
||
async function install(){if(!release||locked.current)return;locked.current=true;setBusy(true);setError('');setProgress(0);const controller=new AbortController();ctl.current=controller;
|
||
try{const uri=await downloadLegacyPackage(release,origin.current,FileSystem,controller.signal,(stage,value)=>{if(alive.current){setPhase(stage==='verifying'?'正在校验':'正在下载');setProgress(value);}});if(controller.signal.aborted||!alive.current)return;const {File}=await import('expo-file-system');await new File(uri).preview({mimeType:'application/vnd.android.package-archive'});}
|
||
catch(e){if(alive.current)setError(e instanceof Error?e.message:'更新未完成,请重试。');}finally{locked.current=false;if(alive.current)setBusy(false);}
|
||
}
|
||
async function changeConnection(value:string){if(busy)return;try{await SecureStore.setItemAsync('cmvr.prod.connection',officialDownloadOrigin(value)+'/prod-api');setSelectedOrigin(value);setAttempt(n=>n+1);}catch{setError('未能保存连接方式,请重试。');}}
|
||
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>
|
||
<View style={{flexDirection:'row',gap:10}}>{[[officialAppOrigin,'外网'],[officialAppInternalOrigin,'公司内网']].map(([value,label])=><Pressable key={value} accessibilityRole="button" accessibilityLabel={label} accessibilityState={{selected:selectedOrigin===value,disabled:busy}} disabled={busy} onPress={()=>void changeConnection(value)} style={{flex:1,padding:12,borderRadius:8,alignItems:'center',backgroundColor:selectedOrigin===value?'#3563d9':'#edf2fb'}}><Text allowFontScaling={false} style={{color:selectedOrigin===value?'#fff':'#3563d9'}}>{label}</Text></Pressable>)}</View>
|
||
<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}
|
||
{busy&&<View style={{gap:8}}><Text allowFontScaling={false} style={{color:'#526174'}}>{phase} {progress}%</Text><View accessibilityRole="progressbar" accessibilityValue={{min:0,max:100,now:progress}} style={{height:7,backgroundColor:'#e5ebf5',borderRadius:4,overflow:'hidden'}}><View style={{width:`${progress}%`,height:7,backgroundColor:'#3563d9'}}/></View></View>}
|
||
{!!error&&<Text accessibilityRole="alert" allowFontScaling={false} style={{fontSize:13,lineHeight:21,color:'#bc3345'}}>{error}</Text>}
|
||
<Pressable accessibilityRole="button" accessibilityLabel={busy?'取消下载':'下载并安装'} disabled={!release} onPress={()=>{if(busy)ctl.current?.abort();else void install();}} style={{backgroundColor:!release?'#aac0f3':'#3563d9',paddingVertical:14,borderRadius:10,alignItems:'center'}}><Text allowFontScaling={false} style={{color:'#fff',fontWeight:'600',fontSize:15}}>{busy?'取消下载':'下载并安装'}</Text></Pressable>
|
||
{!busy&&<Pressable accessibilityRole="button" accessibilityLabel="重新检查" onPress={()=>setAttempt(n=>n+1)} style={{padding:10,alignItems:'center'}}><Text allowFontScaling={false} style={{color:'#3563d9',fontSize:13}}>重新检查</Text></Pressable>}
|
||
</View></ScrollView></SafeAreaView></SafeAreaProvider>;
|
||
}
|