cmvr-wms/mobile-app/src/ui.tsx
lixiaolong 149bde836f feat(assistant): 扩展业务助手功能支持更多文档类型和业务场景
- 新增 PDF 文档支持,包括格式校验和完整性检查
- 扩展 Word、TXT 和 ZIP 格式附件处理能力
- 添加 Excel 附件可选择仅作为业务文件不解析行数据
- 实现业务助手表格布局配置新增库存和预算字段
- 集成通知、反馈通知等新的业务助手动作类型
- 完善部门管理包含父级部门和排序字段支持
- 增强业务规则校验涵盖更多系统管理场景
- 优化附件上传限制提示信息更准确
- 添加生成文件下载的安全性校验机制
- 扩展测试覆盖确保各业务动作规则正确性
2026-10-18 08:49:30 +08:00

40 lines
6.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, { createContext, useContext } from 'react';
import { ActivityIndicator, Image, Pressable, ScrollView, StyleSheet, Text, TextInput, View, useColorScheme } from 'react-native';
import Ionicons from '@expo/vector-icons/Ionicons';
import {darkTheme,lightTheme} from './core/appearance';
export type Appearance = 'system' | 'light' | 'dark';
export const AppearanceContext=createContext<{mode:Appearance;setMode:(mode:Appearance)=>void}>({mode:'system',setMode:()=>{}});
export function useTheme() { const {mode}=useContext(AppearanceContext),system=useColorScheme();return (mode==='system'?system:mode) === 'dark'
? darkTheme : lightTheme; }
export type IconName=React.ComponentProps<typeof Ionicons>['name'];
export function Icon({name,size=22,color}:{name:IconName;size?:number;color?:string}){const t=useTheme();return <View aria-hidden accessibilityElementsHidden importantForAccessibility="no-hide-descendants"><Ionicons name={name} size={size} color={color||t.accent}/></View>;}
export function Avatar({name,uri,size=48}:{name:string;uri?:string;size?:number}){const t=useTheme();return <View style={{width:size,height:size,borderRadius:size/2,backgroundColor:t.soft,alignItems:'center',justifyContent:'center',overflow:'hidden'}}>{uri?<Image source={{uri}} style={{width:size,height:size}}/>:<Text style={{fontSize:size*.38,fontWeight:'700',color:t.accent}}>{name.slice(0,1)||'我'}</Text>}</View>;}
export function MenuItem({title,detail,icon,onPress,last=false}:{title:string;detail?:string;icon:IconName;onPress:()=>void;last?:boolean}){const t=useTheme();return <Pressable accessibilityRole="button" accessibilityLabel={title} onPress={onPress} style={({pressed})=>({flexDirection:'row',alignItems:'center',gap:13,minHeight:64,paddingVertical:12,opacity:pressed?.65:1,borderBottomWidth:last?0:1,borderColor:t.line})}><View style={{backgroundColor:t.soft,padding:9,borderRadius:12}}><Icon name={icon} size={21}/></View><View style={{flex:1,gap:4}}><Text style={{color:t.text,fontSize:16,fontWeight:'500'}}>{title}</Text>{!!detail&&<Text style={{color:t.muted,fontSize:12,lineHeight:18}}>{detail}</Text>}</View><Icon name="chevron-forward" size={17} color={t.muted}/></Pressable>;}
export function Button({ title, onPress, disabled, busy, secondary = false }: {
title: string; onPress: () => void; disabled?: boolean; busy?: boolean; secondary?: boolean;
}) { const t=useTheme(); return <Pressable accessibilityRole="button" accessibilityLabel={title}
accessibilityState={{ disabled: disabled || busy, busy }} onPress={onPress} disabled={disabled || busy}
style={({pressed})=>[s.button,{backgroundColor:secondary?t.soft:t.accent,opacity:disabled||busy?0.5:pressed?.75:1}]}>
{busy&&<ActivityIndicator color={secondary?t.accent:t.onAccent}/>}<Text style={{color:secondary?t.accent:t.onAccent,fontWeight:'600'}}>{title}</Text></Pressable>; }
export function Field({ label, value, onChange, secure, keyboard, multiline, disabled, maxLength }: {
label:string; value:string; onChange:(v:string)=>void; secure?:boolean; keyboard?:'decimal-pad'|'default'|'email-address'|'phone-pad'; multiline?:boolean; disabled?:boolean; maxLength?:number;
}) { const t=useTheme(); return <View style={{gap:7}}><Text style={{color:t.text,fontWeight:'500'}}>{label}</Text>
<TextInput accessibilityLabel={label} value={value} onChangeText={onChange} editable={!disabled} secureTextEntry={secure}
autoCapitalize="none" autoCorrect={false} keyboardType={keyboard} multiline={multiline} maxLength={maxLength}
style={[s.input,{color:t.text,borderColor:t.line,backgroundColor:t.card,minHeight:multiline?84:48}]}/></View>; }
export function Card({children}:{children:React.ReactNode}) {const t=useTheme();return <View style={[s.card,{backgroundColor:t.card,borderColor:t.line}]}>{children}</View>}
export function Note({children}:{children:React.ReactNode}) {const t=useTheme();return <Text accessibilityLiveRegion="polite" style={{color:t.muted,lineHeight:23}}>{children}</Text>}
export function Heading({children}:{children:React.ReactNode}) {const t=useTheme();return <Text style={{color:t.text,fontSize:21,fontWeight:'700'}}>{children}</Text>}
export function Choice({label,items,value,onChange,nameKey}:{label:string;items:Record<string,any>[];value:Record<string,any>|null;onChange:(item:Record<string,any>)=>void;nameKey:string}){
const t=useTheme(),[query,setQuery]=React.useState(''),[expanded,setExpanded]=React.useState(false);
const matches=items.filter(item=>String(item[nameKey]||item.areaCode||'').toLowerCase().includes(query.toLowerCase()));
return <View style={{gap:9}}><Text style={{color:t.text,fontWeight:'500'}}>{label}</Text><Pressable accessibilityRole="button" accessibilityLabel={`选择${label}`} accessibilityState={{expanded}} onPress={()=>setExpanded(v=>!v)} style={{flexDirection:'row',gap:12,alignItems:'center',padding:14,minHeight:50,borderWidth:1,borderColor:expanded?t.accent:t.line,borderRadius:10,backgroundColor:t.card}}><Text style={{flex:1,color:value?t.text:t.muted,lineHeight:22}}>{value?.[nameKey]||value?.areaCode||`请选择${label}`}</Text><Icon name={expanded?'chevron-up':'chevron-down'} size={17} color={t.muted}/></Pressable>
{expanded&&<Card><Field label={`搜索${label}`} value={query} onChange={setQuery}/><ScrollView nestedScrollEnabled keyboardShouldPersistTaps="handled" style={{maxHeight:240}}>{matches.slice(0,20).map(item=><Pressable accessibilityRole="button" accessibilityLabel={String(item[nameKey]||item.areaCode)} key={item.id} onPress={()=>{onChange(item);setExpanded(false);setQuery('');}} style={{paddingVertical:15,paddingHorizontal:4,borderBottomWidth:1,borderColor:t.line,flexDirection:'row',gap:10,alignItems:'center'}}><Text style={{color:value?.id===item.id?t.accent:t.text,flex:1,lineHeight:23}}>{item[nameKey]||item.areaCode}</Text>{value?.id===item.id&&<Icon name="checkmark" size={18}/>}</Pressable>)}</ScrollView>
{matches.length>20&&<Note>还有 {matches.length-20} 项,请输入名称缩小范围。</Note>}{!matches.length&&<Note>未找到匹配项。</Note>}</Card>}
</View>;
}
export const s=StyleSheet.create({fill:{flex:1},page:{padding:18,gap:16,paddingBottom:36},row:{flexDirection:'row',gap:10,alignItems:'center',flexWrap:'wrap'},
button:{minHeight:46,paddingHorizontal:16,paddingVertical:12,borderRadius:10,flexDirection:'row',gap:8,justifyContent:'center',alignItems:'center'},
input:{borderWidth:1,borderRadius:9,padding:12,fontSize:16},card:{padding:16,borderRadius:14,borderWidth:1,gap:12},header:{paddingHorizontal:18,paddingVertical:14,borderBottomWidth:1,gap:10},
pair:{flexDirection:'row',alignItems:'flex-start',gap:14},label:{width:96,flexShrink:0},value:{flex:1,lineHeight:22}});