- 实现基于角色的采购报价权限检查,仅超级管理员和采购经理角色可查看报价 - 替换原有的仓库采购管理权限检查为新的报价权限函数 - 在采购单据组件中更新报价字段显示权限逻辑 - 集成文件管理功能,支持文档附件上传下载 - 添加移动端应用更新提示和发布功能 - 增强采购历史更正服务的安全访问控制 - 重构报价访问工具类以支持细粒度字段过滤 - 添加单元测试验证新的权限控制逻辑
35 lines
5.1 KiB
TypeScript
35 lines
5.1 KiB
TypeScript
import React,{useMemo,useState} from 'react';
|
||
import {FlatList,KeyboardAvoidingView,Modal,Platform,Pressable,View} from 'react-native';
|
||
import {SafeAreaView} from 'react-native-safe-area-context';
|
||
import {Icon,useTheme} from '../ui';
|
||
import {Text,TextInput} from '../typography';
|
||
type Item=Record<string,any>;
|
||
const recent=new Map<string,string[]>();
|
||
const identity=(item:Item)=>String(item.id??item.userId??item.value??item.areaCode??'');
|
||
export function Choice({label,items,value,onChange,nameKey,disabled=false}:{label:string;items:Item[];value:Item|null;onChange:(item:Item)=>void;nameKey:string;disabled?:boolean}){
|
||
const t=useTheme(),[query,setQuery]=useState(''),[open,setOpen]=useState(false);
|
||
const matches=useMemo(()=>{
|
||
const words=query.trim().toLocaleLowerCase().split(/\s+/).filter(Boolean),seen=new Set<string>();
|
||
const filtered=items.filter(item=>{const id=identity(item);if(!id||seen.has(id))return false;seen.add(id);return words.every(word=>[item[nameKey],item.areaCode,item.userName,item.nickName,item.projectName].filter(Boolean).join(' ').toLocaleLowerCase().includes(word));});
|
||
if(query.trim())return filtered;
|
||
const selected=identity(value||{}),previous=recent.get(label)||[];
|
||
return filtered.map((item,index)=>({item,index,rank:identity(item)===selected?-2:previous.includes(identity(item))?previous.indexOf(identity(item)):100})).sort((a,b)=>a.rank-b.rank||a.index-b.index).map(v=>v.item);
|
||
},[items,value,query,label,nameKey]);
|
||
function choose(item:Item){recent.set(label,[identity(item),...(recent.get(label)||[]).filter(id=>id!==identity(item))].slice(0,5));onChange(item);setOpen(false);setQuery('');}
|
||
const close=()=>{setOpen(false);setQuery('');};
|
||
return <View style={{gap:6}}><Text style={{color:t.text,fontSize:13,lineHeight:19}}>{label}</Text>
|
||
<Pressable accessibilityRole="button" accessibilityLabel={`选择${label}`} accessibilityState={{expanded:open,disabled}} disabled={disabled} onPress={()=>setOpen(true)} style={{minHeight:44,paddingHorizontal:12,paddingVertical:10,borderWidth:1,borderColor:t.line,borderRadius:9,backgroundColor:t.card,flexDirection:'row',alignItems:'center',gap:8,opacity:disabled?.55:1}}>
|
||
<Text style={{flex:1,color:value?t.text:t.muted,fontSize:14,lineHeight:20}}>{value?.[nameKey]||value?.areaCode||`请选择${label}`}</Text><Icon name="chevron-down" size={16} color={t.muted}/>
|
||
</Pressable>
|
||
{open&&<Modal visible transparent animationType="slide" onRequestClose={close}><KeyboardAvoidingView style={{flex:1}} behavior={Platform.OS==='ios'?'padding':undefined}><View style={{flex:1,backgroundColor:'rgba(10,20,35,.42)',justifyContent:'flex-end'}}>
|
||
<Pressable accessibilityRole="button" accessibilityLabel="关闭选择" onPress={close} style={{flex:1}}/>
|
||
<SafeAreaView edges={['bottom']} style={{backgroundColor:t.card,borderTopLeftRadius:18,borderTopRightRadius:18,maxHeight:'82%',minHeight:320,width:'100%',maxWidth:600,alignSelf:'center'}}>
|
||
<View style={{paddingHorizontal:16,paddingTop:8,flexDirection:'row',alignItems:'center'}}><Text style={{flex:1,fontSize:16,fontWeight:'600',color:t.text}}>选择{label}</Text><Pressable accessibilityRole="button" accessibilityLabel="关闭选择" onPress={close} style={{minHeight:44,minWidth:44,alignItems:'center',justifyContent:'center'}}><Icon name="close" size={20} color={t.muted}/></Pressable></View>
|
||
<View style={{marginHorizontal:16,marginBottom:8,borderWidth:1,borderColor:t.line,borderRadius:9,paddingHorizontal:10,flexDirection:'row',alignItems:'center'}}><Icon name="search-outline" size={17} color={t.muted}/><TextInput accessibilityLabel={`搜索${label}`} placeholder={`搜索${label}`} placeholderTextColor={t.muted} value={query} onChangeText={setQuery} autoCorrect={false} style={{flex:1,minHeight:44,paddingHorizontal:8,fontSize:14,color:t.text}}/>{!!query&&<Pressable accessibilityRole="button" accessibilityLabel="清除搜索" onPress={()=>setQuery('')} style={{padding:10}}><Icon name="close-circle" size={17} color={t.muted}/></Pressable>}</View>
|
||
<Text style={{paddingHorizontal:16,paddingBottom:6,color:t.muted,fontSize:12,lineHeight:18}}>{matches.length} 项{!query.trim()?' · 当前选择和最近使用优先':''}</Text>
|
||
<FlatList keyboardShouldPersistTaps="handled" data={matches} keyExtractor={identity} initialNumToRender={15} contentContainerStyle={{paddingHorizontal:16,paddingBottom:12}} ListEmptyComponent={<Text style={{padding:24,textAlign:'center',color:t.muted}}>没有匹配项,试试其他名称</Text>} renderItem={({item})=>{const selected=identity(item)===identity(value||{});return <Pressable accessibilityRole="button" accessibilityLabel={String(item[nameKey]||item.areaCode)} accessibilityState={{selected}} onPress={()=>choose(item)} style={{minHeight:48,paddingVertical:12,borderBottomWidth:1,borderColor:t.line,flexDirection:'row',alignItems:'center',gap:10}}><Text style={{flex:1,color:selected?t.accent:t.text,fontSize:14,lineHeight:21}}>{item[nameKey]||item.areaCode}</Text>{selected&&<Icon name="checkmark" size={18}/>}</Pressable>;}}/>
|
||
</SafeAreaView>
|
||
</View></KeyboardAvoidingView></Modal>}
|
||
</View>;
|
||
}
|