2026-10-18 08:49:30 +08:00
import React , { useContext } from 'react' ;
import { Image , Pressable , ScrollView , Text , View } from 'react-native' ;
import Constants from 'expo-constants' ;
import * as Updates from 'expo-updates' ;
import { AppearanceContext , Avatar , Button , Card , Heading , Icon , MenuItem , Note , s , useTheme , type IconName } from '../ui' ;
import { imagePath } from '../core/account' ;
import { usePrivateImage } from '../files' ;
import { ApiClient } from '../core/network' ;
import type { Module , Row } from '../core/modules' ;
2026-10-20 10:04:17 +08:00
const icons :Record < string , IconName > = { arrival : 'checkmark-circle-outline' , use : 'file-tray-outline' , move : 'swap-horizontal-outline' , count : 'clipboard-outline' , stock : 'cube-outline' , purchase : 'cart-outline' , pending : 'download-outline' , in : 'file-tray-full-outline' , loans : 'swap-horizontal-outline' , check : 'clipboard-outline' , out : 'file-tray-outline' , production : 'construct-outline' } ;
const hints :Record < string , string > = { arrival : '登记到货、逐次验收合格数量' , use : '选择库存,核对后领用出库' , move : '同项目库存更换实际存放库区' , count : '现场清点,登记实际数量' , stock : '查询物品、数量和所在库区' , purchase : '采购明细与报价进展' , pending : '核对物品,现场办理入库' , in : '追溯每一次入库' , loans : '查询项目间借还进度' , check : '查看盘点记录、确认盘点' , out : '查看领用与退回记录' , production : '查询任务、产量与执行状态' } ;
2026-10-18 08:49:30 +08:00
type Props = { api :ApiClient ; user :Row ; module s : Module [ ] ; open : ( name :string ) = > void ; go : ( tab :string ) = > void ; ai :boolean } ;
export function Workspace ( { api , user , module s , open , go , ai } : Props ) {
const t = useTheme ( ) , uri = usePrivateImage ( api , imagePath ( user . avatar ) ) ; const hour = new Date ( ) . getHours ( ) , greeting = hour < 11 ? ' 早上好 ' : hour < 14 ? ' 中午好 ' : hour < 18 ? ' 下午好 ' : ' 晚上好 ' ;
2026-10-20 10:04:17 +08:00
const quick = [ 'arrival' , 'pending' , 'use' , 'move' , 'count' ] . map ( k = > module s.find ( m = > m . key === k ) ) . filter ( ( m ) : m is Module = > ! ! m ) ;
2026-10-18 08:49:30 +08:00
return < ScrollView contentContainerStyle = { [ s . page , { paddingTop :12 , paddingBottom :24 } ] } >
< View style = { [ s . row , { justifyContent : 'space-between' } ] } > < View style = { { gap :5 , flex :1 } } > < Text style = { { color :t.muted , fontSize :13 } } > { new Date ( ) . toLocaleDateString ( 'zh-CN' , { month : 'long' , day : 'numeric' , weekday : 'long' } ) } < / Text > < Heading > { greeting } , { user . nickName || user . userName } < / Heading > < / View > < Pressable accessibilityRole = "button" accessibilityLabel = "打开我的" onPress = { ( ) = > go ( 'me' ) } > < Avatar name = { user . nickName || user . userName } uri = { uri } size = { 46 } / > < / Pressable > < / View >
< View style = { { padding :23 , borderRadius :24 , backgroundColor :t.hero , gap :16 , overflow : 'hidden' } } > < View accessible = { false } style = { { position : 'absolute' , right : - 35 , top : - 60 , width :190 , height :190 , borderRadius :95 , backgroundColor : 'rgba(255,255,255,.09)' } } / > < Text style = { { color : '#dfeaff' , fontSize :12 , letterSpacing :2 } } > CMVR · 移 动 工 作 空 间 < / Text > < Text style = { { color : '#fff' , fontSize :27 , fontWeight : '700' , lineHeight :38 } } > 现 场 事 务 , { '\n' } 随 手 办 。 < / Text > < Text style = { { color : '#e0eaff' , lineHeight :21 , fontSize :13 } } > 找 物 资 、 查 进 度 、 办 入 库 。 { '\n' } 把 时 间 留 给 真 正 重 要 的 工 作 。 < / Text > < Pressable accessibilityRole = "button" accessibilityLabel = "进入业务中心" onPress = { ( ) = > go ( 'business' ) } style = { { flexDirection : 'row' , alignItems : 'center' , gap :8 , alignSelf : 'flex-start' , backgroundColor : 'rgba(255,255,255,.17)' , borderRadius :20 , paddingVertical :10 , paddingHorizontal :15 } } > < Text style = { { color : '#fff' , fontWeight : '600' } } > 开 始 办 理 < / Text > < Icon name = "arrow-forward" color = "#fff" size = { 17 } / > < / Pressable > < / View >
< View style = { [ s . row , { justifyContent : 'space-between' , marginTop :6 } ] } > < Text style = { { color :t.text , fontSize :18 , fontWeight : '700' } } > 常 用 操 作 < / Text > < Pressable accessibilityRole = "button" accessibilityLabel = "查看全部业务" onPress = { ( ) = > go ( 'business' ) } style = { { padding :8 } } > < Text style = { { color :t.muted , fontSize :13 } } > 全 部 业 务 → < / Text > < / Pressable > < / View >
< View style = { { flexDirection : 'row' , flexWrap : 'wrap' , gap :12 } } > { quick . map ( m = > < Pressable accessibilityRole = "button" accessibilityLabel = { m . title } key = { m . key } onPress = { ( ) = > open ( m . key ) } style = { ( { pressed } ) = > ( { width : '46%' , flexGrow :1 , padding :17 , gap :13 , borderRadius :19 , backgroundColor :t.card , borderWidth :1 , borderColor :t.line , opacity :pressed ? . 7 : 1 } ) } > < View style = { { alignSelf : 'flex-start' , padding :11 , backgroundColor :t.soft , borderRadius :13 } } > < Icon name = { icons [ m . key ] } size = { 25 } / > < / View > < Text style = { { color :t.text , fontSize :16 , fontWeight : '600' } } > { m . title } < / Text > < Text style = { { color :t.muted , fontSize :12 , lineHeight :18 } } > { hints [ m . key ] } < / Text > < / Pressable > ) } < / View >
{ ! quick . length && < Note > 你 的 移 动 业 务 入 口 尚 未 配 置 , 可 请 管 理 员 协 助 确 认 工 作 范 围 。 < / Note > }
{ ai && < Pressable accessibilityRole = "button" accessibilityLabel = "与 AI 对话" onPress = { ( ) = > go ( 'assistant' ) } > < Card > < View style = { s . row } > < Image source = { require ( '../../assets/assistant.png' ) } style = { { width :46 , height :46 , borderRadius :23 } } / > < View style = { { flex :1 , gap :5 } } > < Text style = { { color :t.text , fontSize :17 , fontWeight : '700' } } > 不 确 定 怎 么 操 作 ? 问 我 就 好 < / Text > < Text style = { { color :t.muted , fontSize :12 , lineHeight :18 } } > 说 需 求 、 传 图 片 , 也 可 以 继 续 补 充 < / Text > < / View > < Icon name = "arrow-forward" size = { 20 } / > < / View > < / Card > < / Pressable > }
< Pressable accessibilityRole = "button" accessibilityLabel = "问题与建议" onPress = { ( ) = > open ( 'feedback' ) } style = { [ s . row , { padding :10 , justifyContent : 'center' } ] } > < Icon name = "chatbubble-ellipses-outline" size = { 17 } color = { t . muted } / > < Text style = { { color :t.muted , fontSize :12 } } > 遇 到 问 题 ? 告 诉 我 们 , 让 工 作 更 顺 畅 < / Text > < / Pressable >
< / ScrollView > ;
}
export function BusinessHub ( { module s , open } : { module s : Module [ ] ; open : ( name :string ) = > void } ) {
2026-10-20 10:04:17 +08:00
const t = useTheme ( ) ; return < ScrollView contentContainerStyle = { s . page } > < Heading > 在 现 场 , 也 能 从 容 处 理 < / Heading > < Note > 常 用 现 场 操 作 优 先 , 其 他 业 务 随 时 查 询 ; 提 交 前 均 先 核 对 。 < / Note > { [ [ '现场办理' , [ 'arrival' , 'pending' , 'use' , 'move' , 'count' ] ] , [ '查询与记录' , [ 'stock' , 'purchase' , 'production' , 'in' , 'out' , 'loans' , 'check' ] ] ] . map ( ( [ label , keys ] ) = > { const entries = ( keys as string [ ] ) . map ( key = > module s.find ( m = > m . key === key ) ) . filter ( ( m ) : m is Module = > ! ! m ) ; return entries . length ? < View key = { label as string } style = { { gap :10 , marginTop :6 } } > < Text style = { { color :t.muted , fontSize :13 , fontWeight : '600' , paddingLeft :4 } } > { label as string } < / Text > < Card > { entries . map ( ( m , i ) = > < MenuItem key = { m . key } title = { m . title } detail = { hints [ m . key ] } icon = { icons [ m . key ] } onPress = { ( ) = > open ( m . key ) } last = { i === entries . length - 1 } / > ) } < / Card > < / View > : null ; } ) } { ! module s.length && < Note > 暂 未 分 配 移 动 业 务 , 可 请 管 理 员 协 助 确 认 。 < / Note > } < / ScrollView > ;
2026-10-18 08:49:30 +08:00
}
export function Me ( { api , user , open } : { api :ApiClient ; user :Row ; open : ( name :string ) = > void } ) {
const t = useTheme ( ) , uri = usePrivateImage ( api , imagePath ( user . avatar ) ) ; return < ScrollView contentContainerStyle = { s . page } > < Pressable accessibilityRole = "button" accessibilityLabel = "个人资料" onPress = { ( ) = > open ( 'profile' ) } > < View style = { [ s . row , { paddingVertical :12 , gap :16 } ] } > < Avatar name = { user . nickName || user . userName } uri = { uri } size = { 70 } / > < View style = { { flex :1 , gap :7 } } > < Text style = { { color :t.text , fontSize :24 , fontWeight : '700' } } > { user . nickName || user . userName } < / Text > < Text style = { { color :t.muted , fontSize :13 } } > 账 号 { user . userName } < / Text > < Text style = { { color :t.muted , fontSize :12 } } > { user . dept ? . deptName || '个人工作空间' } < / Text > < / View > < Icon name = "chevron-forward" color = { t . muted } / > < / View > < / Pressable >
< Card > < MenuItem title = "个人资料" detail = "昵称、手机号码和邮箱" icon = "person-outline" onPress = { ( ) = > open ( 'profile' ) } / > < MenuItem title = "账号与密码" detail = "管理当前账号的登录密码" icon = "lock-closed-outline" onPress = { ( ) = > open ( 'password' ) } last / > < / Card >
< Card > < MenuItem title = "问题与建议" detail = "发现问题、提出需求,支持添加图片" icon = "chatbubble-ellipses-outline" onPress = { ( ) = > open ( 'feedback' ) } / > < MenuItem title = "我的反馈" detail = "查看处理进展与负责人回复" icon = "receipt-outline" onPress = { ( ) = > open ( 'feedback-list' ) } last / > < / Card >
< Card > < MenuItem title = "设置" detail = "外观、内网连接及应用更新" icon = "settings-outline" onPress = { ( ) = > open ( 'settings' ) } / > < MenuItem title = "关于应用" icon = "information-circle-outline" onPress = { ( ) = > open ( 'about' ) } last / > < / Card >
< Text style = { { color :t.muted , fontSize :11 , textAlign : 'center' , letterSpacing :2 , marginTop :8 } } > CMVR · 让 工 作 更 简 单 < / Text >
< / ScrollView > ;
}
2026-10-20 10:04:17 +08:00
export function Settings ( { updateText , environment , baseUrl , connection , logout , about = false } : { updateText :string ; environment :string ; baseUrl :string ; connection? :React.ReactNode ; logout : ( ) = > void ; about? :boolean } ) {
2026-10-18 08:49:30 +08:00
const t = useTheme ( ) , { mode , setMode } = useContext ( AppearanceContext ) ;
return < ScrollView contentContainerStyle = { s . page } > { about ? < > < View style = { { alignItems : 'center' , paddingVertical :24 , gap :12 } } > < View style = { { backgroundColor :t.accent , padding :20 , borderRadius :25 } } > < Icon name = "layers-outline" color = "#fff" size = { 43 } / > < / View > < Heading > CMVR 移 动 工 作 空 间 < / Heading > < Note > 把 业 务 带 到 现 场 , 让 协 作 更 轻 松 。 < / Note > < / View > < Card > < Note > 应 用 版 本 { Constants . expoConfig ? . version } < / Note > < Note > 当 前 环 境 { environment === 'prod' ? '正式环境' : '开发环境' } < / Note > < Note > 更 新 标 识 { Updates . updateId ? . slice ( 0 , 8 ) || '内置版本' } < / Note > < / Card > < Card > < Heading > 数 据 与 安 全 < / Heading > < Note > 业 务 数 据 来 自 公 司 内 网 服 务 。 可 见 数 据 和 可 用 操 作 由 后 台 权 限 决 定 ; AI 操 作 须 经 人 工 确 认 , 查 询 直 接 返 回 。 < / Note > < Note > 请 仅 在 可 信 的 公 司 网 络 使 用 。 不 要 在 反 馈 或 AI 对 话 中 填 写 密 码 和 授 权 码 。 < / Note > < / Card > < / > : < >
< Card > < Heading > 外 观 < / Heading > < Note > 选 择 适 合 你 的 阅 读 方 式 。 < / Note > < View style = { s . row } > { ( [ [ 'system' , '跟随系统' ] , [ 'light' , '浅色' ] , [ 'dark' , '深色' ] ] as const ) . map ( ( [ value , label ] ) = > < Button key = { value } title = { ` ${ mode === value ? '✓ ' : '' } ${ label } ` } secondary = { mode !== value } onPress = { ( ) = > setMode ( value ) } / > ) } < / View > < / Card >
2026-10-20 10:04:17 +08:00
{ connection || < Card > < Heading > 内 网 连 接 < / Heading > < Note > 当 前 : { environment === 'prod' ? '正式环境' : '开发环境' } < / Note > < Text selectable style = { { color :t.text , lineHeight :22 } } > { baseUrl } < / Text > < Note > 正 式 服 务 由 安 装 包 固 定 , 避 免 误 切 环 境 。 < / Note > < / Card > }
2026-10-18 08:49:30 +08:00
< Card > < Heading > 应 用 更 新 < / Heading > < Note > { updateText } < / Note > < Note > 启 动 时 自 动 检 查 内 网 更 新 。 下 载 完 成 后 下 次 启 动 生 效 , 不 会 中 断 当 前 表 单 。 原 生 能 力 变 更 仍 需 安 装 新 版 。 < / Note > < Note > 版 本 { Constants . expoConfig ? . version } · { Updates . updateId ? . slice ( 0 , 8 ) || '内置版本' } < / Note > < / Card >
< Button title = "退出登录" secondary onPress = { logout } / >
< / > } < / ScrollView > ;
}