cmvr-wms/mobile-app/src/screens/LoginView.tsx
lixiaolong 95effeeff2 feat(app): 优化移动端应用配置和功能实现
- 添加生产环境服务器地址配置支持内外网切换
- 实现采购列表只看我创建的功能开关
- 更新构建脚本中的默认生产环境API地址
- 优化采购单表格单元格编辑体验改用自动补全组件
- 调整应用更新检查逻辑增强生产环境兼容性
- 修复开发服务器切换时的一些验证问题
- 增强应用启动时的服务地址配置灵活性
2026-10-29 17:27:46 +08:00

35 lines
8.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React,{useState} from 'react';
import {ActivityIndicator,Image,KeyboardAvoidingView,Platform,Pressable,ScrollView,StyleSheet,View} from 'react-native';
import {Text,TextInput} from '../typography';
import {Icon} from '../ui';
import type {Row} from '../core/modules';
type Props={environment:string;username:string;password:string;code:string;captcha:Row|null;busy:boolean;connecting:boolean;error:string;server:string;connection?:React.ReactNode;setUsername:(v:string)=>void;setPassword:(v:string)=>void;setCode:(v:string)=>void;refresh:()=>void;submit:()=>void};
export function LoginView(p:Props){
const dev=p.environment!=='prod',[visible,setVisible]=useState(false),[settings,setSettings]=useState(false);
const accent=dev?'#ffbb68':'#60e0cf';
const icon=dev?require('../../assets/brand/app-icon-blue-dev.png'):require('../../assets/brand/app-icon-blue-prod.png');
const input=(label:string,value:string,change:(v:string)=>void,kind:'person-outline'|'lock-closed-outline'|'shield-checkmark-outline',secure=false)=><View style={{gap:7,flex:1,minWidth:0}}><Text style={styles.label}>{label}</Text><View style={styles.inputWrap}><Icon name={kind} size={18} color="#7b91a8"/><TextInput accessibilityLabel={label} value={value} onChangeText={change} editable={!p.busy} secureTextEntry={secure&&!visible} autoCapitalize="none" autoCorrect={false} placeholder={label==='验证码'?'输入验证码':`请输入${label}`} placeholderTextColor="#9aabba" returnKeyType={secure?'go':'next'} onSubmitEditing={secure?p.submit:undefined} style={styles.input}/>{secure&&<Pressable accessibilityRole="button" accessibilityLabel={visible?'隐藏密码':'显示密码'} accessibilityState={{disabled:p.busy}} disabled={p.busy} onPress={()=>setVisible(v=>!v)} style={styles.iconButton}><Icon name={visible?'eye-off-outline':'eye-outline'} size={19} color="#7189a0"/></Pressable>}</View></View>;
return <KeyboardAvoidingView style={styles.page} behavior={Platform.OS==='ios'?'padding':undefined}>
<View pointerEvents="none" style={styles.heroImage}><Image accessible={false} source={require('../../assets/brand/login-tech-background.jpg')} resizeMode="cover" style={{width:'100%',height:600}}/><View style={[StyleSheet.absoluteFill,{backgroundColor:'rgba(2,13,30,.16)'}]}/></View>
<ScrollView keyboardShouldPersistTaps="handled" contentContainerStyle={styles.scroll}>
<View style={styles.brand}><Image accessible={false} source={icon} style={styles.mark}/><View style={{flex:1,minWidth:0,gap:3}}><Text style={styles.brandName}>招商车研</Text><Text style={styles.department}>研发中心 · 设备仪器科</Text></View><View style={[styles.badge,{borderColor:dev?'#94724a':'#31696d'}]}><View style={{width:5,height:5,borderRadius:3,backgroundColor:accent}}/><Text style={{color:accent,fontSize:11,lineHeight:17}}>{dev?'开发环境':'正式环境'}</Text></View></View>
<View style={styles.intro}><Text style={styles.title}>设备科综合管理系统</Text><Text style={styles.subtitle}>连接研发现场,让每一项业务清晰有序</Text></View>
<View style={styles.card}>
<View style={{gap:4,marginBottom:4}}><Text style={styles.cardTitle}>登录工作空间</Text><Text style={styles.hint}>{dev?'请连接公司内网,使用现有账号登录':'使用现有账号登录,可选择外网或公司内网'}</Text></View>
{input('登录账号',p.username,p.setUsername,'person-outline')}
{input('密码',p.password,p.setPassword,'lock-closed-outline',true)}
{!!p.captcha&&p.captcha.captchaEnabled!==false&&<View style={{flexDirection:'row',gap:10,alignItems:'flex-end'}}>{input('验证码',p.code,p.setCode,'shield-checkmark-outline')}<Pressable accessibilityRole="button" accessibilityLabel="刷新验证码" disabled={p.busy} onPress={p.refresh} style={styles.captcha}>{p.captcha.img?<Image source={{uri:`data:image/png;base64,${p.captcha.img}`}} resizeMode="contain" style={{width:106,height:46}}/>:<Text style={styles.hint}>点击刷新</Text>}</Pressable></View>}
{!!p.error&&<View accessibilityRole="alert" style={styles.error}><Icon name="alert-circle-outline" size={18} color="#ce3e46"/><Text style={{flex:1,minWidth:0,color:'#ad3038',fontSize:13,lineHeight:20}}>{p.error}</Text></View>}
<Pressable accessibilityRole="button" accessibilityLabel="登录" accessibilityState={{disabled:!p.captcha||p.busy,busy:p.busy}} disabled={!p.captcha||p.busy} onPress={p.submit} style={({pressed})=>[styles.submit,{backgroundColor:'#216fc2',opacity:!p.captcha||p.busy?.5:pressed?.8:1}]}>{p.busy?<ActivityIndicator color="#ffffff"/>:<><Text style={styles.submitText}>登录</Text><Icon name="arrow-forward" size={18} color="#ffffff"/></>}</Pressable>
<View style={styles.statusRow}><View style={{flexDirection:'row',alignItems:'center',gap:6,flex:1,minWidth:0}}>{p.connecting?<ActivityIndicator size="small" color="#66829d"/>:<Icon name={p.captcha?'shield-checkmark-outline':'cloud-offline-outline'} size={15} color={p.captcha?'#298c73':'#8497a8'}/>}<Text style={styles.status}>{p.connecting?'正在连接服务…':p.captcha?'服务连接正常':'暂未连接服务'}</Text></View><Pressable accessibilityRole="button" accessibilityLabel="重新连接" disabled={p.busy||p.connecting} onPress={p.refresh} style={styles.reconnect}><Text style={{fontSize:12,color:'#246db4'}}>重新连接</Text></Pressable></View>
</View>
{!dev&&!!p.connection&&p.connection}
{dev&&!!p.connection&&<><Pressable accessibilityRole="button" accessibilityLabel="开发服务设置" accessibilityState={{expanded:settings}} onPress={()=>setSettings(v=>!v)} style={styles.settings}><Icon name="settings-outline" size={15} color="#66839f"/><Text style={{fontSize:12,color:'#4e7195'}}>开发服务设置</Text><Icon name={settings?'chevron-up':'chevron-down'} size={14} color="#66839f"/></Pressable>{settings&&<View style={{borderRadius:14,overflow:'hidden'}}>{p.connection}</View>}</>}
<View style={styles.footer}><View style={{height:1,width:24,backgroundColor:'#cddbe8'}}/><Text style={{fontSize:11,lineHeight:17,color:'#849bb1',textAlign:'center'}}>CMVR · 设备与研发同行</Text><View style={{height:1,width:24,backgroundColor:'#cddbe8'}}/></View>
</ScrollView>
</KeyboardAvoidingView>;
}
const styles=StyleSheet.create({page:{flex:1,minHeight:0,backgroundColor:'#f3f7fb'},heroImage:{position:'absolute',top:0,left:0,right:0,height:260,overflow:'hidden',backgroundColor:'#0a2844'},scroll:{paddingHorizontal:22,paddingTop:24,paddingBottom:24,flexGrow:1,width:'100%',maxWidth:480,alignSelf:'center'},brand:{flexDirection:'row',alignItems:'center',gap:10},mark:{width:46,height:46,borderRadius:12},brandName:{color:'#f5faff',fontSize:21,lineHeight:29,fontWeight:'700',letterSpacing:2},department:{color:'#bbcfdf',fontSize:12,lineHeight:19},badge:{flexDirection:'row',alignItems:'center',gap:5,borderWidth:1,borderRadius:20,paddingHorizontal:8,paddingVertical:4,backgroundColor:'#071b31'},intro:{paddingTop:54,paddingBottom:25,gap:6},title:{color:'#f1faff',fontSize:24,lineHeight:34,fontWeight:'700',letterSpacing:1,textShadowColor:'#001122',textShadowRadius:8,textShadowOffset:{width:0,height:1}},subtitle:{color:'#d8e8f3',fontSize:12,lineHeight:20,textShadowColor:'#001122',textShadowRadius:8,textShadowOffset:{width:0,height:1}},card:{borderWidth:1,borderColor:'#e2ebf4',borderRadius:20,padding:20,gap:16,backgroundColor:'#ffffff',shadowColor:'#244769',shadowOpacity:.12,shadowRadius:24,elevation:5},cardTitle:{color:'#1b344b',fontSize:18,lineHeight:25,fontWeight:'600'},hint:{color:'#71869a',fontSize:12,lineHeight:19},label:{color:'#405a71',fontSize:13,lineHeight:19},inputWrap:{flexDirection:'row',alignItems:'center',borderWidth:1,borderColor:'#d8e4ef',borderRadius:10,backgroundColor:'#f7fafe',paddingLeft:12,minHeight:48},input:{flex:1,minWidth:0,paddingHorizontal:10,paddingVertical:11,minHeight:48,color:'#263e54',fontSize:14,lineHeight:22},iconButton:{minWidth:44,minHeight:46,justifyContent:'center',alignItems:'center'},captcha:{width:108,minHeight:48,borderRadius:10,overflow:'hidden',backgroundColor:'#e9f2fa',alignItems:'center',justifyContent:'center'},submit:{minHeight:48,flexDirection:'row',gap:10,justifyContent:'center',alignItems:'center',borderRadius:10,marginTop:3,padding:10},submitText:{color:'#ffffff',fontSize:15,lineHeight:22,fontWeight:'700'},statusRow:{flexDirection:'row',alignItems:'center',gap:6,marginTop:-7,marginBottom:-10},status:{color:'#71899e',fontSize:11,lineHeight:18,flexShrink:1},reconnect:{minHeight:44,justifyContent:'center',paddingLeft:8},error:{flexDirection:'row',alignItems:'flex-start',gap:7,backgroundColor:'#fff1f1',borderRadius:9,padding:10},settings:{minHeight:44,flexDirection:'row',gap:7,alignItems:'center',justifyContent:'center',marginTop:5},footer:{flexDirection:'row',gap:12,alignItems:'center',justifyContent:'center',paddingTop:26}});