feat(client): 移动壳基建——底部 5 tab + 我的 hub + 统一底部 sheet + 移动组件四件套

对齐移动原型体系(m-*.html)的 Stage 0 共享基建,桌面形态零改动:

- 导航:router 新增 branch 9(/me 我的 + /me/license 授权屏);窄屏 tab 根
  (库存/入库/出库/财务/我的)出底部 MTabBar,二级屏隐藏 tabbar + 顶栏返回箭头
  (PopScope 拦系统返回键防退 app);窄屏 Drawer/汉堡删除;窄屏顶栏对齐 m-top
  (标题 + 主题/通知铃/头像→我的)
- sheet:showMSheet(grip/标题/86vh/键盘避让)+ showAdaptiveSheet;六个共享
  弹层呈现函数加窄屏 sheet 分支(订单/往来/财务往来/商品编辑抽屉 + 退单/登记收支
  dialog 的 asSheet 形态)
- 徽章:DsBadge/StatusPill/StatusBadge 加图标变体(默认圆点零漂移)+
  status_icon_map 转录原型 BADGE_ICON 28 词
- 组件:MKpiGrid(2×2 可点 KPI)/ MSearchRow(搜索+状态钮+详搜钮)/
  MHubGroup(hub 入口组)/ showThemeSheet(主题外观 sheet)
- 授权:_LicensePanel/_SettingsCard 抽取为公共 LicensePanel/SettingsCard,
  窄屏授权跳转 /me/license
- golden:app_shell_mobile + me 各三主题(390×844@2x);全量 259 测试绿,
  check_ds_code / check-l1-sync 闸过

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-07-04 11:56:04 +08:00
parent b683adece9
commit be9afcf68d
34 changed files with 1851 additions and 390 deletions
+16 -2
View File
@@ -20,6 +20,8 @@ import '../../screens/settings/settings_screen.dart';
import '../../screens/settings/users_screen.dart';
import '../../screens/about/about_screen.dart';
import '../../screens/devices/device_management_screen.dart';
import '../../screens/me/me_screen.dart';
import '../../screens/me/license_screen.dart';
import '../auth/auth_state.dart';
Page<void> _noTransition(Widget child) => NoTransitionPage<void>(child: child);
@@ -104,8 +106,10 @@ final appRouterProvider = Provider<GoRouter>((ref) {
// 及其页面 State 常驻,跨栏目切换不再销毁上一页(半填表单/内部 tab/滚动位置保活)。
// 分支顺序必须与 AppShell._navItems 一致(navigationShell.currentIndex 据此高亮)。
StatefulShellRoute.indexedStack(
builder: (context, state, navigationShell) =>
AppShell(navigationShell: navigationShell),
// location 透传给壳:窄屏据此判定 tab 根 / 二级屏(底部 tabbar 显隐与返回箭头)。
builder: (context, state, navigationShell) => AppShell(
navigationShell: navigationShell,
location: state.matchedLocation),
branches: [
// 0 入库管理
StatefulShellBranch(routes: [
@@ -206,6 +210,16 @@ final appRouterProvider = Provider<GoRouter>((ref) {
path: '/about',
pageBuilder: (_, __) => _noTransition(const AboutScreen())),
]),
// 9 我的(移动 hub,原型 m-me.html;桌面侧栏无此项,仅窄屏底部 tab 入口)
StatefulShellBranch(routes: [
GoRoute(
path: '/me',
pageBuilder: (_, __) => _noTransition(const MeScreen())),
// 授权管理独立屏(原型 m-license.html,从「我的」系统组进入)
GoRoute(
path: '/me/license',
pageBuilder: (_, __) => _noTransition(const LicenseScreen())),
]),
],
),
],
+23
View File
@@ -0,0 +1,23 @@
// screens/me/license_screen.dart — 授权管理独立屏(镜像原型 m-license.html)。
// 移动端从「我的 → 系统 → 授权管理」进入(/me/license);内容 = 公共 LicensePanel
// 四卡(授权信息 / 在线购买续费 / 兑换券 / 降级规则),与桌面设置授权 tab 同源。
import 'package:flutter/material.dart';
import '../../core/theme/context_tokens.dart';
import '../settings/license_panel.dart';
class LicenseScreen extends StatelessWidget {
const LicenseScreen({super.key});
@override
Widget build(BuildContext context) {
final t = context.tokens;
return Container(
color: t.bg,
child: const SingleChildScrollView(
padding: EdgeInsets.all(14),
child: LicensePanel(),
),
);
}
}
+208
View File
@@ -0,0 +1,208 @@
// screens/me/me_screen.dart — 「我的」hub(镜像原型 m-me.html,移动愿景导航中枢)。
// 结构:用户头卡(54 渐变圆头像 + 真名 + 店名·账号 + 角色徽章)
// + 经营管理组(往来单位/基础数据/库存盘点)
// + 系统组(用户管理/授权管理/设备管理/系统设置/主题外观/关于我们)
// + 退出登录(确认 sheet)。窄屏底部 tab「我的」入口;桌面侧栏不含此屏。
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:lucide_icons_flutter/lucide_icons.dart';
import '../../core/auth/auth_state.dart';
import '../../core/theme/app_dims.g.dart';
import '../../core/theme/context_tokens.dart';
import '../../providers/shop_provider.dart';
import '../../widgets/ds/ds_atoms.dart';
import '../../widgets/ds/m_hub.dart';
import '../../widgets/ds/m_sheet.dart';
import '../../widgets/ds/status_icon_map.dart';
import '../../widgets/theme_sheet.dart';
String _roleLabel(String role) {
switch (role) {
case 'superadmin':
return '超级管理员';
case 'admin':
return '管理员';
case 'readonly':
return '只读';
default:
return '操作员';
}
}
class MeScreen extends ConsumerWidget {
const MeScreen({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final t = context.tokens;
final user = ref.watch(authStateProvider).user;
final shopName =
ref.watch(shopInfoProvider).valueOrNull?.name ?? user?.shopNo ?? '';
return Container(
color: t.bg,
child: ListView(
padding: const EdgeInsets.all(14),
children: [
if (user != null) _header(t, user, shopName),
MHubGroup(label: '经营管理', items: [
MHubItem(
icon: LucideIcons.users,
label: '往来单位',
onTap: () => context.go('/partners')),
MHubItem(
icon: LucideIcons.layoutGrid,
label: '基础数据',
onTap: () => context.go('/products')),
MHubItem(
icon: LucideIcons.clipboardCheck,
label: '库存盘点',
onTap: () => context.go('/inventory/check')),
]),
MHubGroup(label: '系统', items: [
MHubItem(
icon: LucideIcons.userPlus,
label: '用户管理',
onTap: () => context.go('/settings/users')),
MHubItem(
icon: LucideIcons.trendingUp,
label: '授权管理',
onTap: () => context.go('/me/license')),
MHubItem(
icon: LucideIcons.monitorSmartphone,
label: '设备管理',
onTap: () => context.go('/devices')),
MHubItem(
icon: LucideIcons.settings,
label: '系统设置',
onTap: () => context.go('/settings')),
MHubItem(
icon: LucideIcons.shirt,
label: '主题外观',
onTap: () => showThemeSheet(context)),
MHubItem(
icon: LucideIcons.info,
label: '关于我们',
onTap: () => context.go('/about')),
]),
const SizedBox(height: 18),
_LogoutButton(onConfirm: () {
ref.read(authStateProvider.notifier).logout();
context.go('/login');
}),
],
),
);
}
/// 用户头卡(原型 .me-hd):surface 卡 + 54 渐变圆头像 + 名/店·账号 + 角色徽章。
Widget _header(dynamic t, AuthUser user, String shopName) {
final name = user.realName.isNotEmpty ? user.realName : user.username;
final initial = name.isNotEmpty ? name.characters.first : '';
final roleLabel = _roleLabel(user.role);
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: t.surface,
border: Border.all(color: t.border),
borderRadius: BorderRadius.circular(AppDims.rLg),
),
child: Row(children: [
Container(
width: 54,
height: 54,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [t.primary, t.primaryDark],
),
shape: BoxShape.circle,
),
alignment: Alignment.center,
child: Text(initial,
style: TextStyle(
color: t.onPrimary,
fontSize: 22,
fontWeight: FontWeight.w800)),
),
const SizedBox(width: 14),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(name,
style: TextStyle(
fontSize: AppDims.fsH2,
fontWeight: FontWeight.w700,
color: t.heading)),
const SizedBox(height: 3),
Text('$shopName · ${user.username}',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: AppDims.fsSm, color: t.muted)),
],
),
),
DsBadge(roleLabel,
tone: DsBadgeTone.info, icon: statusIcon(roleLabel)),
]),
);
}
}
class _LogoutButton extends StatelessWidget {
final VoidCallback onConfirm;
const _LogoutButton({required this.onConfirm});
@override
Widget build(BuildContext context) {
final t = context.tokens;
// Material 自带(InkWell 水波 + golden 直挂无 Scaffold 场景)
return Material(
color: t.surface,
borderRadius: BorderRadius.circular(AppDims.rMd),
child: InkWell(
onTap: () => _confirm(context),
borderRadius: BorderRadius.circular(AppDims.rMd),
child: Container(
height: 44,
alignment: Alignment.center,
decoration: BoxDecoration(
border: Border.all(color: t.border),
borderRadius: BorderRadius.circular(AppDims.rMd),
),
child: Text('退出登录',
style: TextStyle(
fontSize: AppDims.fsBody,
fontWeight: FontWeight.w600,
color: t.danger)),
),
),
);
}
void _confirm(BuildContext context) {
showMSheet<void>(
context,
title: '退出登录',
builder: (ctx) => Text('确认退出当前账号?',
style: TextStyle(
fontSize: AppDims.fsBody, color: ctx.tokens.text)),
actions: [
Builder(
builder: (ctx) =>
DsButton('取消', onPressed: () => Navigator.of(ctx).pop())),
Builder(
builder: (ctx) => DsButton('退出登录',
variant: DsBtnVariant.danger, onPressed: () {
Navigator.of(ctx).pop();
onConfirm();
}),
),
],
);
}
}
@@ -0,0 +1,214 @@
// screens/settings/license_panel.dart — 授权管理面板(自 settings_screen.dart 抽取为公共组件)。
// 四卡:授权信息 / 在线购买续费(PurchaseCard, admin only) / 兑换券 / 到期降级规则。
// 桌面:SettingsScreen 授权 tab 内嵌;移动:独立屏 LicenseScreen/me/license)复用。
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:intl/intl.dart';
import 'package:url_launcher/url_launcher.dart';
import '../../core/auth/auth_state.dart';
import '../../core/config/app_info.dart';
import '../../core/config/license_copy.dart';
import '../../core/responsive/responsive.dart';
import '../../core/theme/app_dims.g.dart';
import '../../core/theme/app_fonts.dart';
import '../../core/theme/context_tokens.dart';
import '../../core/utils/clock.dart';
import '../../providers/license_provider.dart';
import '../../widgets/ds/ds_atoms.dart';
import '../../widgets/ds/ds_toast.dart';
import '../../widgets/write_guard.dart';
import 'purchase_card.dart';
import 'settings_card.dart';
class LicensePanel extends ConsumerStatefulWidget {
const LicensePanel({super.key});
@override
ConsumerState<LicensePanel> createState() => _LicensePanelState();
}
class _LicensePanelState extends ConsumerState<LicensePanel> {
final _voucherCtrl = TextEditingController();
bool _redeeming = false;
@override
void dispose() {
_voucherCtrl.dispose();
super.dispose();
}
Future<void> _redeem() async {
final code = _voucherCtrl.text.trim();
if (code.isEmpty) {
showDsToast(context, '请输入兑换券短码');
return;
}
setState(() => _redeeming = true);
try {
await ref.read(licenseRepositoryProvider).activate(code);
ref.invalidate(licenseProvider);
_voucherCtrl.clear();
if (mounted) {
showDsToast(context, '兑换成功,已续期 ✓', bg: context.tokens.success);
}
} catch (e) {
if (mounted) {
showDsToast(context, '兑换失败:$e', bg: context.tokens.danger);
}
} finally {
if (mounted) setState(() => _redeeming = false);
}
}
@override
Widget build(BuildContext context) {
final t = context.tokens;
final lic = ref.watch(licenseProvider).valueOrNull;
final role = ref.watch(authStateProvider.select((s) => s.user?.role));
final isAdmin = role == 'admin' || role == 'superadmin';
final expires = lic?.expiresAt != null
? DateFormat('yyyy-MM-dd').format(lic!.expiresAt!)
: '';
// 状态/剩余天数走可注入时钟(golden 确定化),不用 model 内的 DateTime.now()
final active = lic?.isActive == true &&
(lic?.expiresAt == null || lic!.expiresAt!.isAfter(appNow()));
final days = lic?.expiresAt != null
? lic!.expiresAt!.difference(appNow()).inDays.clamp(0, 99999)
: null;
final licCells = [
_licCell(t, '授权状态', active ? '已授权' : '未授权',
color: active ? t.success : t.warn),
_licCell(t, '到期日', expires),
_licCell(t, '剩余天数', days != null ? '$days' : ''),
];
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// ── 卡1:授权信息(3 cell,自「关于我们」迁入)──
SettingsCard(
title: '授权信息',
desc: '当前门店的授权状态与有效期,续期时长在现有到期时间上叠加',
child: context.isMobile
? Column(children: [
for (final c in licCells)
Padding(
padding: const EdgeInsets.only(bottom: 10), child: c),
])
: Row(children: [
for (var i = 0; i < licCells.length; i++) ...[
if (i > 0) const SizedBox(width: 14),
Expanded(child: licCells[i]),
],
]),
),
const SizedBox(height: 16),
// ── 卡2:在线购买 / 续费(后端 purchase 接口 admin only
// 非管理员引导看官网价格页)──
if (isAdmin)
const SettingsCard(
title: '在线购买 / 续费',
desc: '选择套餐支付宝支付,到账后授权自动续期',
child: PurchaseCard(),
)
else
SettingsCard(
title: '在线购买 / 续费',
desc: '在线购买仅门店管理员可操作',
child: Row(children: [
Text('在线购买请联系门店管理员 · ',
style: TextStyle(fontSize: AppDims.fsSm, color: t.muted)),
InkWell(
onTap: () =>
launchUrl(Uri.parse('${AppInfo.website}/#pricing')),
child: Text('查看套餐价格 →',
style: TextStyle(
fontSize: AppDims.fsSm,
fontWeight: FontWeight.w600,
color: t.primary)),
),
]),
),
const SizedBox(height: 16),
// ── 卡3:兑换券(原型 .redeeminput + 按钮,max 520)──
SettingsCard(
title: '兑换券',
desc: '输入兑换券短码续期',
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 520),
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('兑换券短码',
style: TextStyle(
fontSize: AppDims.fsSm, color: t.muted)),
const SizedBox(height: 6),
DsInput(
controller: _voucherCtrl,
hintText: '输入兑换券短码',
),
],
),
),
const SizedBox(width: 10),
WriteGuard(
child: DsButton(_redeeming ? '兑换中…' : '兑换续期',
variant: DsBtnVariant.primary,
onPressed: _redeeming ? null : _redeem),
),
],
),
),
),
const SizedBox(height: 16),
// ── 卡4:到期后的降级规则(现有能力保留)──
SettingsCard(
title: '到期后的降级规则',
desc: '授权到期后系统各功能的可用性说明',
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
for (final note in LicenseCopy.degradationNotes())
Padding(
padding: const EdgeInsets.only(top: 3),
child: Text('· $note',
style: TextStyle(fontSize: AppDims.fsSm, color: t.muted)),
),
],
),
),
],
);
}
/// 原型 .lic-cell(与「关于我们」同款):lk 11 muted + lv 17/700/mono。
Widget _licCell(dynamic t, String label, String value, {Color? color}) =>
Container(
padding: const EdgeInsets.fromLTRB(16, 14, 16, 14),
decoration: BoxDecoration(
color: t.bg,
border: Border.all(color: t.borderSubtle),
borderRadius: BorderRadius.circular(AppDims.rMd),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(label,
style: TextStyle(fontSize: AppDims.fsXs, color: t.muted)),
const SizedBox(height: 6),
Text(value,
style: TextStyle(
fontSize: AppDims.fsH2,
fontWeight: FontWeight.w700,
fontFamily: AppFonts.mono,
fontFamilyFallback: AppFonts.monoFallback,
color: color ?? t.heading)),
],
),
);
}
@@ -0,0 +1,60 @@
// screens/settings/settings_card.dart — 设置面板卡(自 settings_screen.dart 抽取为公共组件,
// 供 SettingsScreen 各面板与独立授权屏 LicenseScreen 复用)。
// 原型右侧 .cardsurface / 1px border / r-lg / padding 22 24 / mb18
// h2 17 heading + desc 12 muted(可带右上角按钮)。
import 'package:flutter/material.dart';
import '../../core/theme/app_dims.g.dart';
import '../../core/theme/context_tokens.dart';
class SettingsCard extends StatelessWidget {
final String title;
final String desc;
final Widget child;
final Widget? trailing;
const SettingsCard(
{super.key,
required this.title,
required this.desc,
required this.child,
this.trailing});
@override
Widget build(BuildContext context) {
final t = context.tokens;
return Container(
margin: const EdgeInsets.only(bottom: 18),
padding: const EdgeInsets.fromLTRB(24, 22, 24, 22),
decoration: BoxDecoration(
color: t.surface,
border: Border.all(color: t.border),
borderRadius: BorderRadius.circular(AppDims.rLg),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(title,
style: TextStyle(
fontSize: AppDims.fsH2,
fontWeight: FontWeight.w700,
color: t.heading)),
const SizedBox(height: 3),
Text(desc,
style: TextStyle(fontSize: AppDims.fsSm, color: t.muted)),
],
),
),
if (trailing != null) trailing!,
]),
const SizedBox(height: 16),
child,
],
),
);
}
}
@@ -7,23 +7,17 @@ import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:intl/intl.dart';
import 'package:lucide_icons_flutter/lucide_icons.dart';
import 'package:url_launcher/url_launcher.dart';
import '../../core/auth/auth_state.dart';
import '../../core/config/app_info.dart';
import '../../core/config/license_copy.dart';
import '../../core/responsive/responsive.dart';
import '../../core/theme/app_dims.g.dart';
import '../../core/theme/app_tokens.g.dart';
import '../../core/theme/context_tokens.dart';
import '../../core/theme/theme_controller.dart';
import '../../core/utils/clock.dart';
import '../../core/utils/dialog_util.dart';
import '../../models/number_rule.dart';
import '../../models/shop.dart';
import '../../providers/license_provider.dart';
import '../../providers/number_rule_provider.dart';
import '../../providers/shop_provider.dart';
import '../../providers/user_provider.dart';
@@ -32,7 +26,8 @@ import '../../widgets/ds/ds_atoms.dart';
import '../../widgets/ds/ds_menu.dart';
import '../../widgets/ds/ds_table.dart';
import '../../widgets/write_guard.dart';
import 'purchase_card.dart';
import 'license_panel.dart';
import 'settings_card.dart';
import 'users_screen.dart' show userRoleBadge, userStatusBadge;
import '../../core/theme/app_fonts.dart';
import '../../widgets/ds/ds_toast.dart';
@@ -175,7 +170,7 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
0 => const _StoreInfoPanel(),
1 => _usersPanel(),
2 => _numberPanel(),
3 => const _LicensePanel(),
3 => const LicensePanel(),
4 => const _PrefPanel(),
_ => const SizedBox(),
};
@@ -184,7 +179,7 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
Widget _usersPanel() {
final t = context.tokens;
final async = ref.watch(userListProvider);
return _SettingsCard(
return SettingsCard(
title: '用户管理',
desc: '管理门店成员与权限角色',
trailing: DsButton('管理全部用户',
@@ -250,7 +245,7 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
Widget _numberPanel() {
final t = context.tokens;
final async = ref.watch(numberRuleListProvider);
return _SettingsCard(
return SettingsCard(
title: '编号规则',
desc: '单据编号的前缀 / 日期格式 / 序号',
child: async.when(
@@ -364,59 +359,6 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
}
}
/// 原型右侧 .cardsurface / 1px border / r-lg / padding 22 24 / mb18
/// h2 17 heading + desc 12 muted(可带右上角按钮)。
class _SettingsCard extends StatelessWidget {
final String title;
final String desc;
final Widget child;
final Widget? trailing;
const _SettingsCard(
{required this.title,
required this.desc,
required this.child,
this.trailing});
@override
Widget build(BuildContext context) {
final t = context.tokens;
return Container(
margin: const EdgeInsets.only(bottom: 18),
padding: const EdgeInsets.fromLTRB(24, 22, 24, 22),
decoration: BoxDecoration(
color: t.surface,
border: Border.all(color: t.border),
borderRadius: BorderRadius.circular(AppDims.rLg),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(title,
style: TextStyle(
fontSize: AppDims.fsH2,
fontWeight: FontWeight.w700,
color: t.heading)),
const SizedBox(height: 3),
Text(desc,
style: TextStyle(fontSize: AppDims.fsSm, color: t.muted)),
],
),
),
if (trailing != null) trailing!,
]),
const SizedBox(height: 16),
child,
],
),
);
}
}
// ── 面板 1:门店信息(内联表单)──────────────────────────────
class _StoreInfoPanel extends ConsumerStatefulWidget {
const _StoreInfoPanel();
@@ -511,7 +453,7 @@ class _StoreInfoPanelState extends ConsumerState<_StoreInfoPanel> {
// 授权过期 >7 天同样禁编辑(后端 LicenseGuard 会 403,这里不误导)
!WriteGuard.licenseBlocked(ref);
return _SettingsCard(
return SettingsCard(
title: '门店信息',
desc: '用于单据抬头、对账与多端展示',
child: async.when(
@@ -641,199 +583,6 @@ class _StoreInfoPanelState extends ConsumerState<_StoreInfoPanel> {
}
}
// ── 面板 4:授权管理 ───────────────────────────────────────
class _LicensePanel extends ConsumerStatefulWidget {
const _LicensePanel();
@override
ConsumerState<_LicensePanel> createState() => _LicensePanelState();
}
class _LicensePanelState extends ConsumerState<_LicensePanel> {
final _voucherCtrl = TextEditingController();
bool _redeeming = false;
@override
void dispose() {
_voucherCtrl.dispose();
super.dispose();
}
Future<void> _redeem() async {
final code = _voucherCtrl.text.trim();
if (code.isEmpty) {
showDsToast(context, '请输入兑换券短码');
return;
}
setState(() => _redeeming = true);
try {
await ref.read(licenseRepositoryProvider).activate(code);
ref.invalidate(licenseProvider);
_voucherCtrl.clear();
if (mounted) {
showDsToast(context, '兑换成功,已续期 ✓', bg: context.tokens.success);
}
} catch (e) {
if (mounted) {
showDsToast(context, '兑换失败:$e', bg: context.tokens.danger);
}
} finally {
if (mounted) setState(() => _redeeming = false);
}
}
@override
Widget build(BuildContext context) {
final t = context.tokens;
final lic = ref.watch(licenseProvider).valueOrNull;
final role = ref.watch(authStateProvider.select((s) => s.user?.role));
final isAdmin = role == 'admin' || role == 'superadmin';
final expires = lic?.expiresAt != null
? DateFormat('yyyy-MM-dd').format(lic!.expiresAt!)
: '';
// 状态/剩余天数走可注入时钟(golden 确定化),不用 model 内的 DateTime.now()
final active = lic?.isActive == true &&
(lic?.expiresAt == null || lic!.expiresAt!.isAfter(appNow()));
final days = lic?.expiresAt != null
? lic!.expiresAt!.difference(appNow()).inDays.clamp(0, 99999)
: null;
final licCells = [
_licCell(t, '授权状态', active ? '已授权' : '未授权',
color: active ? t.success : t.warn),
_licCell(t, '到期日', expires),
_licCell(t, '剩余天数', days != null ? '$days' : ''),
];
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// ── 卡1:授权信息(3 cell,自「关于我们」迁入)──
_SettingsCard(
title: '授权信息',
desc: '当前门店的授权状态与有效期,续期时长在现有到期时间上叠加',
child: context.isMobile
? Column(children: [
for (final c in licCells)
Padding(
padding: const EdgeInsets.only(bottom: 10), child: c),
])
: Row(children: [
for (var i = 0; i < licCells.length; i++) ...[
if (i > 0) const SizedBox(width: 14),
Expanded(child: licCells[i]),
],
]),
),
const SizedBox(height: 16),
// ── 卡2:在线购买 / 续费(后端 purchase 接口 admin only
// 非管理员引导看官网价格页)──
if (isAdmin)
const _SettingsCard(
title: '在线购买 / 续费',
desc: '选择套餐支付宝支付,到账后授权自动续期',
child: PurchaseCard(),
)
else
_SettingsCard(
title: '在线购买 / 续费',
desc: '在线购买仅门店管理员可操作',
child: Row(children: [
Text('在线购买请联系门店管理员 · ',
style: TextStyle(fontSize: AppDims.fsSm, color: t.muted)),
InkWell(
onTap: () =>
launchUrl(Uri.parse('${AppInfo.website}/#pricing')),
child: Text('查看套餐价格 →',
style: TextStyle(
fontSize: AppDims.fsSm,
fontWeight: FontWeight.w600,
color: t.primary)),
),
]),
),
const SizedBox(height: 16),
// ── 卡3:兑换券(原型 .redeeminput + 按钮,max 520)──
_SettingsCard(
title: '兑换券',
desc: '输入兑换券短码续期',
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 520),
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('兑换券短码',
style: TextStyle(
fontSize: AppDims.fsSm, color: t.muted)),
const SizedBox(height: 6),
DsInput(
controller: _voucherCtrl,
hintText: '输入兑换券短码',
),
],
),
),
const SizedBox(width: 10),
WriteGuard(
child: DsButton(_redeeming ? '兑换中…' : '兑换续期',
variant: DsBtnVariant.primary,
onPressed: _redeeming ? null : _redeem),
),
],
),
),
),
const SizedBox(height: 16),
// ── 卡4:到期后的降级规则(现有能力保留)──
_SettingsCard(
title: '到期后的降级规则',
desc: '授权到期后系统各功能的可用性说明',
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
for (final note in LicenseCopy.degradationNotes())
Padding(
padding: const EdgeInsets.only(top: 3),
child: Text('· $note',
style: TextStyle(fontSize: AppDims.fsSm, color: t.muted)),
),
],
),
),
],
);
}
/// 原型 .lic-cell(与「关于我们」同款):lk 11 muted + lv 17/700/mono。
Widget _licCell(dynamic t, String label, String value, {Color? color}) =>
Container(
padding: const EdgeInsets.fromLTRB(16, 14, 16, 14),
decoration: BoxDecoration(
color: t.bg,
border: Border.all(color: t.borderSubtle),
borderRadius: BorderRadius.circular(AppDims.rMd),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(label,
style: TextStyle(fontSize: AppDims.fsXs, color: t.muted)),
const SizedBox(height: 6),
Text(value,
style: TextStyle(
fontSize: AppDims.fsH2,
fontWeight: FontWeight.w700,
fontFamily: AppFonts.mono,
fontFamilyFallback: AppFonts.monoFallback,
color: color ?? t.heading)),
],
),
);
}
// ── 面板 5:偏好设置(主题三卡 + 默认仓库)───────────────────
class _PrefPanel extends ConsumerWidget {
const _PrefPanel();
@@ -852,7 +601,7 @@ class _PrefPanel extends ConsumerWidget {
final warehouses = ref.watch(warehouseListProvider).valueOrNull ?? const [];
final defaultWh = warehouses.where((w) => w.isDefault).firstOrNull;
return _SettingsCard(
return SettingsCard(
title: '偏好设置',
desc: '主题与默认值,仅影响当前账号在本端的体验',
child: Column(
+186 -101
View File
@@ -12,6 +12,7 @@ import '../../core/config/license_copy.dart';
import '../../core/responsive/responsive.dart';
import '../../core/theme/context_tokens.dart';
import '../../core/theme/app_chrome.g.dart';
import '../../core/theme/app_dims.g.dart';
import '../../providers/connectivity_provider.dart';
import '../../providers/session_heartbeat.dart';
import '../../providers/shop_provider.dart';
@@ -24,6 +25,8 @@ import '../../widgets/notification_bell.dart';
import '../../widgets/app_status_bar.dart';
import '../../widgets/ds/ds_atoms.dart';
import '../../widgets/ds/ds_toast.dart';
import '../../widgets/ds/m_tab_bar.dart';
import '../../widgets/theme_sheet.dart';
/// 侧栏导航项(含其 StatefulShellRoute 分支序号 = router 中的 branch index)。
class _NavItem {
@@ -59,6 +62,47 @@ const _navGroups = <_NavGroup>[
]),
];
// ── 窄屏底部 tab(对齐原型 mobile-shell.js TABS:库存/入库/出库/财务/我的)──
// (图标, 文案, branch index)branch index 对应 router StatefulShellRoute 分支序号。
const _mobileTabs = <(IconData, String, int)>[
(LucideIcons.box, '库存', 2),
(LucideIcons.download, '入库', 0),
(LucideIcons.upload, '出库', 1),
(LucideIcons.receiptText, '财务', 3),
(LucideIcons.user, '我的', 9),
];
/// 窄屏 tab 根路由白名单:命中显示底部 tabbar;未命中即二级屏(隐藏 tabbar + 返回箭头)。
const _tabRoots = {'/inventory', '/stock-in', '/stock-out', '/finance', '/me'};
/// branch index → 底部 tab 高亮位;4-9(往来/基础数据/设备/设置/关于/我的)归「我的域」。
int _tabForBranch(int branch) => switch (branch) {
2 => 0,
0 => 1,
1 => 2,
3 => 3,
_ => 4,
};
/// 窄屏顶栏标题(对齐原型 m-top data-title)。
String _mobileTitle(String loc) {
if (loc.startsWith('/stock-in')) return '入库管理';
if (loc.startsWith('/stock-out')) return '出库管理';
if (loc == '/inventory/check') return '库存盘点';
if (loc.startsWith('/inventory')) return '库存管理';
if (loc.startsWith('/finance')) return '财务管理';
if (loc.startsWith('/partners')) return '往来单位';
if (loc.startsWith('/products/')) return '商品详情';
if (loc.startsWith('/products')) return '基础数据';
if (loc.startsWith('/devices')) return '设备管理';
if (loc == '/settings/users') return '用户管理';
if (loc.startsWith('/settings')) return '系统设置';
if (loc.startsWith('/about')) return '关于我们';
if (loc == '/me/license') return '授权管理';
if (loc.startsWith('/me')) return '我的';
return '';
}
String _roleLabel(String role) {
switch (role) {
case 'superadmin':
@@ -76,7 +120,11 @@ class AppShell extends ConsumerStatefulWidget {
/// StatefulShellRoute 注入的导航壳:各栏目分支 Navigator 的 IndexedStack
/// 跨栏目切换时各分支页面 State 常驻(保住半填表单 / 内部 tab / 滚动位置)。
final StatefulNavigationShell navigationShell;
const AppShell({super.key, required this.navigationShell});
/// 当前匹配路由(router 透传):窄屏据此判定 tab 根 / 二级屏。
final String location;
const AppShell(
{super.key, required this.navigationShell, required this.location});
@override
ConsumerState<AppShell> createState() => _AppShellState();
@@ -86,7 +134,6 @@ class _AppShellState extends ConsumerState<AppShell> {
final String _loginTime = DateFormat('HH:mm:ss').format(AppStatusBar.clock());
bool _forceDialogShown = false;
bool _licenseDialogShown = false;
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
/// 打开账号菜单(个人设置 / 退出登录)。[anchorContext] = 用户区组件的 context
/// 据其实测宽度让菜单等宽(不溢出内容区)、据其位置把菜单**完整弹到按钮正上方**
@@ -137,6 +184,24 @@ class _AppShellState extends ConsumerState<AppShell> {
context.go('/login');
}
/// 窄屏二级屏返回:分支内有栈先 pop;分支根按来源兜底(商品详情→列表,其余→我的)。
void _backFromSecondary() {
if (context.canPop()) {
context.pop();
return;
}
final loc = widget.location;
if (loc.startsWith('/products/')) {
context.go('/products');
} else if (loc.startsWith('/stock-in/')) {
context.go('/stock-in');
} else if (loc.startsWith('/stock-out/')) {
context.go('/stock-out');
} else {
context.go('/me');
}
}
@override
Widget build(BuildContext context) {
final user = ref.watch(authStateProvider).user;
@@ -155,14 +220,15 @@ class _AppShellState extends ConsumerState<AppShell> {
final updateInfo = ref.watch(updateProvider).valueOrNull;
final licenseInfo = ref.watch(licenseProvider).valueOrNull;
return SelectionArea(
// 窄屏导航形态(对齐原型移动壳):tab 根显示底部 tabbar,二级屏隐藏 tabbar
// 并在顶栏出返回箭头(_buildTopBar 内)。
final isTabRoot = _tabRoots.contains(widget.location);
final Widget shell = SelectionArea(
child: Scaffold(
key: _scaffoldKey,
drawer: isMobile ? _buildDrawer(context, user) : null,
drawerEnableOpenDragGesture: !kIsWeb && isMobile,
body: Column(
children: [
_buildTopBar(context, user, isMobile, topInset),
_buildTopBar(context, user, isMobile, isTabRoot, topInset),
Expanded(
child: Row(
children: [
@@ -182,46 +248,125 @@ class _AppShellState extends ConsumerState<AppShell> {
),
],
),
bottomNavigationBar: isMobile && isTabRoot
? MTabBar(
items: [for (final t in _mobileTabs) MTabItem(t.$1, t.$2)],
currentIndex:
_tabForBranch(widget.navigationShell.currentIndex),
onTap: (i) => _goBranch(_mobileTabs[i].$3),
)
: null,
),
);
// 窄屏二级屏拦截系统返回键:分支根直接返回会退出 app,改走 _backFromSecondary
// 回「我的」。Web 不拦截(浏览器历史由 go_router 管理)。
if (!kIsWeb && isMobile && !isTabRoot) {
return PopScope(
canPop: false,
onPopInvokedWithResult: (didPop, _) {
if (!didPop) _backFromSecondary();
},
child: shell,
);
}
return shell;
}
// ── 顶栏(原型 .top, 56h):左两级品牌;右 主题器 + 通知铃 ───────────────────
Widget _buildTopBar(
BuildContext context, AuthUser? user, bool isMobile, double topInset) {
// ── 顶栏 ─────────────────────────────────────────────────────────────────
// 桌面(原型 .top, 56h):左两级品牌;右 主题器 + 通知铃。
// 窄屏(原型 .m-top, 52h):左 返回箭头(二级屏)/门店品牌(tab 根) + 屏标题;
// 右 主题 + 通知铃 + 头像(→我的)。
Widget _buildTopBar(BuildContext context, AuthUser? user, bool isMobile,
bool isTabRoot, double topInset) {
final t = context.tokens;
if (isMobile) {
return Container(
height: 52 + topInset,
decoration: BoxDecoration(
color: t.topBg,
border: Border(bottom: BorderSide(color: t.topBorder)),
),
padding: EdgeInsets.only(
top: topInset, left: isTabRoot ? 14 : 6, right: 14),
child: Row(
children: [
if (!isTabRoot)
IconButton(
icon: Icon(LucideIcons.arrowLeft, color: t.topFg, size: 22),
tooltip: '返回',
onPressed: _backFromSecondary,
),
Expanded(
child: Row(children: [
Flexible(
child: Text(
_mobileTitle(widget.location),
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: t.topFg,
fontSize: AppDims.fsTitle,
fontWeight: FontWeight.w700),
),
),
if (WriteGuard.isReadonly(ref)) ...[
const SizedBox(width: 10),
_readonlyBadge(t.topControl),
],
]),
),
const SizedBox(width: 10),
IconButton(
icon: Icon(LucideIcons.shirt, color: t.topFg, size: 19),
tooltip: '主题外观',
onPressed: () => showThemeSheet(context),
),
const NotificationBell(),
const SizedBox(width: 8),
// 头像(.m-av 28px 圆)→ 我的
InkWell(
onTap: () => _goBranch(9),
borderRadius: BorderRadius.circular(999),
child: Container(
width: 28,
height: 28,
decoration:
BoxDecoration(color: t.primary, shape: BoxShape.circle),
alignment: Alignment.center,
child: Text(
_avatarInitial(user),
style: TextStyle(
color: t.onPrimary,
fontSize: AppDims.fsSm,
fontWeight: FontWeight.w700),
),
),
),
],
),
);
}
return Container(
height: 56 + topInset,
decoration: BoxDecoration(
color: t.topBg,
border: Border(bottom: BorderSide(color: t.topBorder)),
),
padding:
EdgeInsets.only(top: topInset, left: isMobile ? 6 : 18, right: 14),
padding: EdgeInsets.only(top: topInset, left: 18, right: 14),
child: Row(
children: [
// 左组(占满剩余空间,靠左):把右组(主题器+铃)挤到最右
Expanded(
child: Row(
children: [
if (isMobile) ...[
IconButton(
icon: Icon(LucideIcons.menu, color: t.topFg),
tooltip: '菜单',
onPressed: () => _scaffoldKey.currentState?.openDrawer(),
),
const SizedBox(width: 2),
],
// 软件品牌(岩美酒库)—— 桌面常显,窄屏让位给门店
if (!isMobile) ...[
const _SoftwareBrand(),
Container(
width: 1,
height: 20,
color: t.topBorder,
margin: const EdgeInsets.symmetric(horizontal: 8),
),
],
// 软件品牌(岩美酒库)
const _SoftwareBrand(),
Container(
width: 1,
height: 20,
color: t.topBorder,
margin: const EdgeInsets.symmetric(horizontal: 8),
),
// 门店品牌(御品轩名酒坊)——点开门店信息;过长省略
Flexible(child: _ShopBrand(user: user)),
if (WriteGuard.isReadonly(ref)) ...[
@@ -241,6 +386,13 @@ class _AppShellState extends ConsumerState<AppShell> {
);
}
String _avatarInitial(AuthUser? user) {
final name = user == null
? ''
: (user.realName.isNotEmpty ? user.realName : user.username);
return name.isNotEmpty ? name.characters.first : '';
}
Widget _readonlyBadge(Color bg) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
@@ -349,75 +501,6 @@ class _AppShellState extends ConsumerState<AppShell> {
);
}
/// 窄屏(手机)侧滑抽屉导航:与侧栏同分组结构。
Widget _buildDrawer(BuildContext context, AuthUser? user) {
final t = context.tokens;
return Drawer(
child: Container(
color: t.sideBg,
child: SafeArea(
child: Column(
children: [
if (user != null)
Container(
width: double.infinity,
padding: const EdgeInsets.fromLTRB(16, 16, 16, 12),
color: t.topBg,
child: Row(
children: [
const _SoftwareBrandMark(size: 30),
const SizedBox(width: 8),
const Text('岩美酒库',
style: TextStyle(
color: AppChrome.onAccent,
fontSize: 17,
fontWeight: FontWeight.w700)),
],
),
),
Expanded(
child: ListView(
padding: const EdgeInsets.symmetric(horizontal: 12),
children: [
for (final g in _navGroups) ...[
_navLabel(t, g.label),
for (final item in g.items)
_SidebarNav(
item: item,
active:
widget.navigationShell.currentIndex == item.index,
onTap: () {
Navigator.pop(context);
_goBranch(item.index);
},
),
],
],
),
),
if (user != null) ...[
Container(
height: 1,
color: t.sideBorder,
margin: const EdgeInsets.symmetric(horizontal: 16)),
ListTile(
leading: Icon(LucideIcons.logOut, color: t.sideFg),
title: Text('退出登录',
style: TextStyle(
color: t.sideActiveFg, fontWeight: FontWeight.w500)),
onTap: () {
Navigator.pop(context);
_logout();
},
),
],
],
),
),
),
);
}
// ── 顶部横幅(更新 / 强制更新 / 授权 / 离线):保持原有行为 ───────────────────
List<Widget> _buildBanners(
BuildContext context,
@@ -553,7 +636,9 @@ class _AppShellState extends ConsumerState<AppShell> {
overflow: TextOverflow.ellipsis),
),
TextButton(
onPressed: () => context.go('/settings?tab=license'),
// 窄屏授权入口是独立屏(我的→授权管理),宽屏保持设置授权 tab
onPressed: () => context.go(
context.isMobile ? '/me/license' : '/settings?tab=license'),
style:
TextButton.styleFrom(foregroundColor: AppChrome.onAccentFaint),
child: const Text('去激活'),
@@ -584,7 +669,7 @@ class _AppShellState extends ConsumerState<AppShell> {
? DsBtnVariant.primary
: DsBtnVariant.danger, onPressed: () {
Navigator.pop(_);
ctx.go('/settings?tab=license');
ctx.go(ctx.isMobile ? '/me/license' : '/settings?tab=license');
}),
],
),
+11 -5
View File
@@ -92,10 +92,13 @@ class DsButton extends StatelessWidget {
enum DsBadgeTone { ok, danger, warn, info, accent, muted }
/// 原型 .badgeh22 / pad 0 9 / r-pill / fs-sm fw600 + 前导圆点(6px, currentColor)。
/// [icon] 非空 → 图标徽章变体(原型 .badge.bi12px 图标替圆点,icons.js BADGE_ICON
/// 拍板「圆点→代表图标」);默认 null 保持圆点形态(桌面存量 golden 零漂移)。
class DsBadge extends StatelessWidget {
final String label;
final DsBadgeTone tone;
const DsBadge(this.label, {super.key, this.tone = DsBadgeTone.ok});
final IconData? icon;
const DsBadge(this.label, {super.key, this.tone = DsBadgeTone.ok, this.icon});
@override
Widget build(BuildContext context) {
@@ -116,10 +119,13 @@ class DsBadge extends StatelessWidget {
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 6,
height: 6,
decoration: BoxDecoration(color: fg, shape: BoxShape.circle)),
if (icon != null)
Icon(icon, size: 12, color: fg)
else
Container(
width: 6,
height: 6,
decoration: BoxDecoration(color: fg, shape: BoxShape.circle)),
const SizedBox(width: 5),
Text(label,
style: TextStyle(
+103
View File
@@ -0,0 +1,103 @@
// widgets/ds/m_hub.dart — 移动 hub 入口组(镜像原型 mobile-atoms .m-hub / .m-section)。
// 组 = 可选分组标题(.m-section) + 圆角组卡;行 = 34×34 圆角图标底(.hic brand50/primary)
// + 文案(fs-body) + 右侧 (.hchev faint);行间 border-subtle 分隔。
import 'package:flutter/material.dart';
import 'package:lucide_icons_flutter/lucide_icons.dart';
import '../../core/theme/app_dims.g.dart';
import '../../core/theme/context_tokens.dart';
class MHubItem {
final IconData icon;
final String label;
final VoidCallback? onTap;
/// 自定义尾部(如角标 / 当前值文案);null → 默认 › 箭头。
final Widget? trailing;
const MHubItem({
required this.icon,
required this.label,
this.onTap,
this.trailing,
});
}
class MHubGroup extends StatelessWidget {
/// 分组标题(.m-section);null 不渲染。
final String? label;
final List<MHubItem> items;
const MHubGroup({super.key, this.label, required this.items});
@override
Widget build(BuildContext context) {
final t = context.tokens;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (label != null)
Padding(
padding: const EdgeInsets.fromLTRB(2, 16, 2, 8),
child: Text(label!,
style: TextStyle(
fontSize: AppDims.fsSm,
fontWeight: FontWeight.w700,
letterSpacing: .4,
color: t.muted)),
),
// Material 自带(InkWell 水波 + golden 直挂无 Scaffold 场景)
Material(
color: t.surface,
clipBehavior: Clip.antiAlias,
shape: RoundedRectangleBorder(
side: BorderSide(color: t.border),
borderRadius: BorderRadius.circular(AppDims.rLg),
),
child: Column(children: [
for (var i = 0; i < items.length; i++)
_MHubRow(item: items[i], last: i == items.length - 1),
]),
),
],
);
}
}
class _MHubRow extends StatelessWidget {
final MHubItem item;
final bool last;
const _MHubRow({required this.item, required this.last});
@override
Widget build(BuildContext context) {
final t = context.tokens;
return InkWell(
onTap: item.onTap,
child: Container(
padding: const EdgeInsets.all(14),
decoration: BoxDecoration(
border: last
? null
: Border(bottom: BorderSide(color: t.borderSubtle)),
),
child: Row(children: [
Container(
width: 34,
height: 34,
decoration: BoxDecoration(
color: t.brand50,
borderRadius: BorderRadius.circular(AppDims.rMd),
),
child: Icon(item.icon, size: 18, color: t.primary),
),
const SizedBox(width: 12),
Expanded(
child: Text(item.label,
style: TextStyle(fontSize: AppDims.fsBody, color: t.text)),
),
item.trailing ??
Icon(LucideIcons.chevronRight, size: 18, color: t.faint),
]),
),
);
}
}
+131
View File
@@ -0,0 +1,131 @@
// widgets/ds/m_kpi_grid.dart — 移动 2×2 KPI 网格(镜像原型 mobile-atoms .m-kpi)。
// 卡:surface / 1px border / r-lg / pad 12·14kl=fs-xs muted(可带 13px brand400 图标);
// kv=fs-h2 w800 headingkd=fs-xsup/down/warn 三色)。
// KPI 即筛选:onTap 非空可点,selected 态描边 primary(对齐 m-stock-*-list 可点 KPI)。
import 'package:flutter/material.dart';
import '../../core/theme/app_dims.g.dart';
import '../../core/theme/context_tokens.dart';
enum MKpiDeltaTone { normal, up, down, warn }
class MKpiItem {
final String label;
final String value;
final IconData? icon;
final String? delta;
final MKpiDeltaTone deltaTone;
final VoidCallback? onTap;
final bool selected;
const MKpiItem({
required this.label,
required this.value,
this.icon,
this.delta,
this.deltaTone = MKpiDeltaTone.normal,
this.onTap,
this.selected = false,
});
}
class MKpiGrid extends StatelessWidget {
final List<MKpiItem> items;
const MKpiGrid({super.key, required this.items});
@override
Widget build(BuildContext context) {
// 两列网格 gap10:按行切分,用 Row/Expanded 保证等宽等高。
final rows = <List<MKpiItem>>[];
for (var i = 0; i < items.length; i += 2) {
rows.add(items.sublist(i, (i + 2).clamp(0, items.length)));
}
return Column(
children: [
for (var r = 0; r < rows.length; r++) ...[
if (r > 0) const SizedBox(height: 10),
IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
for (var c = 0; c < 2; c++) ...[
if (c > 0) const SizedBox(width: 10),
Expanded(
child: c < rows[r].length
? _MKpiCard(item: rows[r][c])
: const SizedBox.shrink(),
),
],
],
),
),
],
],
);
}
}
class _MKpiCard extends StatelessWidget {
final MKpiItem item;
const _MKpiCard({required this.item});
@override
Widget build(BuildContext context) {
final t = context.tokens;
final deltaColor = switch (item.deltaTone) {
MKpiDeltaTone.up => t.success,
MKpiDeltaTone.down => t.danger,
MKpiDeltaTone.warn => t.warn,
MKpiDeltaTone.normal => t.muted,
};
final card = Container(
padding: const EdgeInsets.fromLTRB(14, 12, 14, 12),
decoration: BoxDecoration(
border: Border.all(color: item.selected ? t.primary : t.border),
borderRadius: BorderRadius.circular(AppDims.rLg),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(children: [
if (item.icon != null) ...[
Icon(item.icon, size: 13, color: t.brand400),
const SizedBox(width: 5),
],
Expanded(
child: Text(item.label,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: AppDims.fsXs, color: t.muted)),
),
]),
const SizedBox(height: 5),
Text(item.value,
style: TextStyle(
fontSize: AppDims.fsH2,
fontWeight: FontWeight.w800,
letterSpacing: .2,
color: t.heading)),
if (item.delta != null) ...[
const SizedBox(height: 3),
Text(item.delta!,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: AppDims.fsXs, color: deltaColor)),
],
],
),
);
// Material 自带(InkWell 水波 + golden 直挂无 Scaffold 场景)
return Material(
color: t.surface,
borderRadius: BorderRadius.circular(AppDims.rLg),
child: item.onTap == null
? card
: InkWell(
onTap: item.onTap,
borderRadius: BorderRadius.circular(AppDims.rLg),
child: card,
),
);
}
}
+151
View File
@@ -0,0 +1,151 @@
// widgets/ds/m_search_row.dart — 移动搜索行(镜像原型 m-stock-*-list 搜索区终态):
// 搜索框(.m-search 42h, flex) + 纯文字状态钮(选中转 primary)+ 图标详细搜索钮(激活转 primary)。
// 状态/详搜钮为可选;不传对应回调即不渲染(如库存屏只有搜索框)。
import 'package:flutter/material.dart';
import 'package:lucide_icons_flutter/lucide_icons.dart';
import '../../core/theme/app_dims.g.dart';
import '../../core/theme/context_tokens.dart';
class MSearchRow extends StatelessWidget {
final TextEditingController? controller;
final String hint;
final ValueChanged<String>? onChanged;
final ValueChanged<String>? onSubmitted;
/// 状态筛选钮当前文案(如「全部」「待审核」);null 不渲染该钮。
final String? statusLabel;
/// 状态钮是否处于筛选中(非「全部」)→ primary 高亮。
final bool statusActive;
final VoidCallback? onStatusTap;
/// 详细搜索钮是否有生效条件 → primary 高亮;[onFilterTap] null 不渲染该钮。
final bool filterActive;
final VoidCallback? onFilterTap;
const MSearchRow({
super.key,
this.controller,
this.hint = '',
this.onChanged,
this.onSubmitted,
this.statusLabel,
this.statusActive = false,
this.onStatusTap,
this.filterActive = false,
this.onFilterTap,
});
@override
Widget build(BuildContext context) {
final t = context.tokens;
return Row(children: [
// .m-search42h / surface / border / r-md / 放大镜 17
// Material 自带(TextField 需 Material 祖先 + golden 直挂无 Scaffold 场景)
Expanded(
child: Material(
color: t.surface,
shape: RoundedRectangleBorder(
side: BorderSide(color: t.border),
borderRadius: BorderRadius.circular(AppDims.rMd),
),
child: Container(
height: 42,
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Row(children: [
Icon(LucideIcons.search, size: 17, color: t.muted),
const SizedBox(width: 8),
Expanded(
child: TextField(
controller: controller,
onChanged: onChanged,
onSubmitted: onSubmitted,
style: TextStyle(fontSize: AppDims.fsBody, color: t.text),
decoration: InputDecoration(
isCollapsed: true,
contentPadding: EdgeInsets.zero,
border: InputBorder.none,
enabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
filled: false,
hintText: hint,
hintStyle:
TextStyle(fontSize: AppDims.fsBody, color: t.faint),
),
),
),
if (controller != null)
ValueListenableBuilder<TextEditingValue>(
valueListenable: controller!,
builder: (context, value, _) {
if (value.text.isEmpty) return const SizedBox.shrink();
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
controller!.clear();
onChanged?.call('');
onSubmitted?.call('');
},
child: Padding(
padding: const EdgeInsets.only(left: 6),
child: Icon(LucideIcons.x, size: 15, color: t.muted),
),
);
},
),
]),
),
),
),
// 状态筛选钮(纯文字,无箭头;筛选中转 primary)
if (statusLabel != null) ...[
const SizedBox(width: 8),
_pillBtn(
t,
active: statusActive,
onTap: onStatusTap,
child: Text(statusLabel!,
style: TextStyle(
fontSize: AppDims.fsBody,
fontWeight: statusActive ? FontWeight.w600 : FontWeight.w500,
color: statusActive ? t.primary : t.text)),
),
],
// 详细搜索钮(图标;有生效条件转 primary)
if (onFilterTap != null) ...[
const SizedBox(width: 8),
_pillBtn(
t,
active: filterActive,
onTap: onFilterTap,
child: Icon(LucideIcons.listFilter,
size: 18, color: filterActive ? t.primary : t.text),
),
],
]);
}
Widget _pillBtn(dynamic t,
{required bool active, VoidCallback? onTap, required Widget child}) {
// Material 自带(InkWell 水波 + golden 直挂无 Scaffold 场景)
return Material(
color: active ? t.brand50 : t.surface,
borderRadius: BorderRadius.circular(AppDims.rMd),
child: InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(AppDims.rMd),
child: Container(
height: 42,
padding: const EdgeInsets.symmetric(horizontal: 13),
alignment: Alignment.center,
decoration: BoxDecoration(
border: Border.all(color: active ? t.primary : t.border),
borderRadius: BorderRadius.circular(AppDims.rMd),
),
child: child,
),
),
);
}
}
+180
View File
@@ -0,0 +1,180 @@
// widgets/ds/m_sheet.dart — 统一移动底部 sheet(镜像原型 mobile-atoms .m-sheet)。
// 结构:grip(36×4) + 标题行(m-sheet-h:标题 + X) + 滚动体(m-sheet-b) + 可选底部操作条。
// max 高 86vh、顶部 r-xl 圆角、SelectionArea 可选中复制;键盘弹出自动避让。
import 'package:flutter/material.dart';
import 'package:lucide_icons_flutter/lucide_icons.dart';
import '../../core/responsive/responsive.dart';
import '../../core/theme/app_chrome.g.dart';
import '../../core/theme/app_dims.g.dart';
import '../../core/theme/context_tokens.dart';
import '../../core/utils/dialog_util.dart';
/// 打开移动底部 sheet(对齐原型 mobile-shell openSheet)。
/// - [title] 为 null 时只渲染 grip,内容自带头部(详情抽屉复用场景)。
/// - [scrollable] true:内容包 SingleChildScrollViewfalse:内容自管布局
/// (需自带定界高度,如 SizedBox(height:…),供 Column/Expanded 正常工作)。
/// - [actions] 底部固定操作条(原型 .m-actionbar 形态:横排等分按钮)。
Future<T?> showMSheet<T>(
BuildContext context, {
String? title,
required WidgetBuilder builder,
bool scrollable = true,
double maxHeightFactor = 0.86,
List<Widget>? actions,
}) {
return showModalBottomSheet<T>(
context: context,
isScrollControlled: true,
useSafeArea: true,
backgroundColor: Colors.transparent,
barrierColor: AppChrome.scrim, // .m-sheet-mask --scrim
builder: (ctx) {
final t = ctx.tokens;
final maxH = MediaQuery.of(ctx).size.height * maxHeightFactor;
final viewInsets = MediaQuery.of(ctx).viewInsets.bottom;
return Padding(
// 键盘弹出时整体上移(sheet 内含输入框场景)
padding: EdgeInsets.only(bottom: viewInsets),
child: Container(
clipBehavior: Clip.antiAlias,
constraints: BoxConstraints(maxHeight: maxH),
decoration: BoxDecoration(
color: t.surface,
borderRadius:
const BorderRadius.vertical(top: Radius.circular(AppDims.rXl)),
),
// sheet 是独立 overlay(在 app_shell 的 SelectionArea 之外)→ 自带一层
child: SelectionArea(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// .grip
Center(
child: Container(
width: 36,
height: 4,
margin: const EdgeInsets.only(top: 8, bottom: 2),
decoration: BoxDecoration(
color: t.border,
borderRadius: BorderRadius.circular(AppDims.rPill),
),
),
),
if (title != null)
Container(
padding: const EdgeInsets.fromLTRB(16, 10, 16, 12),
decoration: BoxDecoration(
border:
Border(bottom: BorderSide(color: t.borderSubtle)),
),
child: Row(children: [
Expanded(
child: Text(title,
style: TextStyle(
fontSize: AppDims.fsTitle,
fontWeight: FontWeight.w700,
color: t.heading)),
),
InkWell(
onTap: () => Navigator.of(ctx).pop(),
child: Icon(LucideIcons.x, size: 20, color: t.muted),
),
]),
),
Flexible(
child: scrollable
? SingleChildScrollView(
padding: const EdgeInsets.fromLTRB(16, 14, 16, 14),
child: Builder(builder: builder),
)
: Builder(builder: builder),
),
if (actions != null)
Container(
padding: const EdgeInsets.fromLTRB(16, 12, 16, 12),
decoration: BoxDecoration(
border: Border(top: BorderSide(color: t.borderSubtle)),
),
child: Row(children: [
for (var i = 0; i < actions.length; i++) ...[
if (i > 0) const SizedBox(width: 10),
Expanded(child: actions[i]),
],
]),
),
],
),
),
),
);
},
);
}
/// 自适应弹层:窄屏走底部 sheet,宽屏走既有 showAppDialogDialog 卡)。
/// 供各屏的筛选 / 轻表单 / 选项选择统一调用,减少 isMobile 样板分支。
Future<T?> showAdaptiveSheet<T>(
BuildContext context, {
required String title,
required WidgetBuilder builder,
List<Widget>? actions,
double desktopWidth = 480,
}) {
if (context.isMobile) {
return showMSheet<T>(context,
title: title, builder: builder, actions: actions);
}
return showAppDialog<T>(
context: context,
builder: (ctx) {
final t = ctx.tokens;
return Dialog(
shape:
RoundedRectangleBorder(borderRadius: BorderRadius.circular(AppDims.rLg)),
child: SizedBox(
width: ctx.dialogWidth(desktopWidth),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(20, 18, 20, 0),
child: Row(children: [
Expanded(
child: Text(title,
style: TextStyle(
fontSize: AppDims.fsTitle,
fontWeight: FontWeight.w700,
color: t.heading)),
),
InkWell(
onTap: () => Navigator.of(ctx).pop(),
child: Icon(LucideIcons.x, size: 18, color: t.muted),
),
]),
),
Flexible(
child: SingleChildScrollView(
padding: const EdgeInsets.fromLTRB(20, 14, 20, 18),
child: Builder(builder: builder),
),
),
if (actions != null)
Padding(
padding: const EdgeInsets.fromLTRB(20, 0, 20, 18),
child: Row(children: [
for (var i = 0; i < actions.length; i++) ...[
if (i > 0) const SizedBox(width: 10),
Expanded(child: actions[i]),
],
]),
),
],
),
),
);
},
);
}
+65
View File
@@ -0,0 +1,65 @@
// widgets/ds/m_tab_bar.dart — 移动底部 tab 栏(镜像原型 mobile-atoms .m-tabbar / .m-tab)。
// min-height 56 / surface 底 / border-top / SafeArea bottom
// 项 = 22px 图标 + fs-xs 文案,激活 primary,未激活 muted。
import 'package:flutter/material.dart';
import '../../core/theme/app_dims.g.dart';
import '../../core/theme/context_tokens.dart';
class MTabItem {
final IconData icon;
final String label;
const MTabItem(this.icon, this.label);
}
class MTabBar extends StatelessWidget {
final List<MTabItem> items;
final int currentIndex;
final ValueChanged<int> onTap;
const MTabBar({
super.key,
required this.items,
required this.currentIndex,
required this.onTap,
});
@override
Widget build(BuildContext context) {
final t = context.tokens;
// Material 自带(InkWell 水波 + golden 直挂无 Scaffold 场景)
return Material(
color: t.surface,
shape: Border(top: BorderSide(color: t.border)),
child: SafeArea(
top: false,
child: SizedBox(
height: 56,
child: Row(children: [
for (var i = 0; i < items.length; i++)
Expanded(
child: InkWell(
onTap: () => onTap(i),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(items[i].icon,
size: 22,
color: i == currentIndex ? t.primary : t.muted),
const SizedBox(height: 3),
Text(items[i].label,
style: TextStyle(
fontSize: AppDims.fsXs,
fontWeight: i == currentIndex
? FontWeight.w600
: FontWeight.w400,
color: i == currentIndex ? t.primary : t.muted)),
],
),
),
),
]),
),
),
);
}
}
@@ -0,0 +1,50 @@
// widgets/ds/status_icon_map.dart — 状态词 → 徽章图标映射。
// 单一真相源镜像:原型 icons.js 的 BADGE_ICON2026-07-04 拍板:全系统圆点→代表图标),
// 逐词转录为 LucideIcons。新增状态先在原型 icons.js 登记,再同步到此表。
import 'package:flutter/widgets.dart';
import 'package:lucide_icons_flutter/lucide_icons.dart';
const Map<String, IconData> kStatusIcons = {
// 库存状态
'在售': LucideIcons.shoppingCart, // i-cart
'预警': LucideIcons.triangleAlert, // i-alert
'缺货': LucideIcons.x, // i-close
// 单据状态
'草稿': LucideIcons.fileText, // i-ic06
'待审核': LucideIcons.clock, // i-ic04
'已审核': LucideIcons.check, // i-check
'已拒绝': LucideIcons.x, // i-close
'已通过': LucideIcons.check, // i-check
'已驳回': LucideIcons.x, // i-close
'部分退单': LucideIcons.undo2, // i-undo
'已退单': LucideIcons.undo2, // i-undo
'待定价': LucideIcons.japaneseYen, // i-yen
// 通用启停 / 往来类型
'启用': LucideIcons.check, // i-check
'停用': LucideIcons.x, // i-close
'供应商': LucideIcons.box, // i-box
'客户': LucideIcons.user, // i-ic37
'两者': LucideIcons.refreshCw, // i-refresh
// 角色
'管理员': LucideIcons.shield, // i-shield-2
'普通': LucideIcons.user, // i-ic37
'只读': LucideIcons.eye, // i-eye
// 设备 / 会话
'在线': LucideIcons.wifi, // i-wifi
'离线': LucideIcons.wifiOff, // i-wifi-off
// 盘点
'进行中': LucideIcons.clock, // i-ic04
'已完成': LucideIcons.check, // i-check
// 兑换券
'未使用': LucideIcons.tag, // i-tag
'已兑换': LucideIcons.check, // i-check
'作废': LucideIcons.x, // i-close
// 财务
'未结清': LucideIcons.clock, // i-ic04
'已结清': LucideIcons.check, // i-check
'收款': LucideIcons.download, // i-download
'付款': LucideIcons.upload, // i-upload
};
/// 查状态词对应图标;未登记返回 null(调用方回退圆点形态)。
IconData? statusIcon(String label) => kStatusIcons[label];
+52 -11
View File
@@ -13,6 +13,7 @@ import '../providers/finance_provider.dart';
import '../providers/partner_provider.dart';
import 'date_picker_field.dart';
import 'ds/ds_atoms.dart';
import 'ds/m_sheet.dart';
import 'searchable_option_field.dart';
import 'ds/ds_toast.dart';
@@ -22,6 +23,15 @@ Future<void> showFinanceEntryDialog(
String type = 'receipt',
int? partnerId,
}) {
// 窄屏:底部 sheet 形态(对齐原型移动 sheet 交互范式)
if (context.isMobile) {
return showMSheet<void>(
context,
title: '登记收支',
builder: (_) =>
_FinanceEntryDialog(type: type, partnerId: partnerId, asSheet: true),
);
}
return showAppDialog(
context: context,
builder: (_) => _FinanceEntryDialog(type: type, partnerId: partnerId),
@@ -31,7 +41,11 @@ Future<void> showFinanceEntryDialog(
class _FinanceEntryDialog extends ConsumerStatefulWidget {
final String type;
final int? partnerId;
const _FinanceEntryDialog({required this.type, this.partnerId});
/// true → sheet 形态(外层 showMSheet 提供标题/滚动,按钮内联在表单尾部)。
final bool asSheet;
const _FinanceEntryDialog(
{required this.type, this.partnerId, this.asSheet = false});
@override
ConsumerState<_FinanceEntryDialog> createState() =>
@@ -85,12 +99,47 @@ class _FinanceEntryDialogState extends ConsumerState<_FinanceEntryDialog> {
@override
Widget build(BuildContext context) {
final partners = ref.watch(allPartnersProvider).valueOrNull?.data ?? [];
if (widget.asSheet) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
_form(),
const SizedBox(height: 18),
Row(children: [
Expanded(
child: DsButton('取消',
onPressed:
_saving ? null : () => Navigator.of(context).pop()),
),
const SizedBox(width: 10),
Expanded(
flex: 2,
child: DsButton(_saving ? '保存中…' : '保存',
variant: DsBtnVariant.primary,
onPressed: _saving ? null : _save),
),
]),
],
);
}
return AlertDialog(
title: const Text('登记收支'),
content: SizedBox(
width: context.dialogWidth(420),
child: Form(
child: _form(),
),
actions: [
DsButton('取消',
onPressed: _saving ? null : () => Navigator.of(context).pop()),
DsButton(_saving ? '保存中…' : '保存',
variant: DsBtnVariant.primary, onPressed: _saving ? null : _save),
],
);
}
Widget _form() {
final partners = ref.watch(allPartnersProvider).valueOrNull?.data ?? [];
return Form(
key: _formKey,
child: Column(
mainAxisSize: MainAxisSize.min,
@@ -151,14 +200,6 @@ class _FinanceEntryDialogState extends ConsumerState<_FinanceEntryDialog> {
)),
],
),
),
),
actions: [
DsButton('取消',
onPressed: _saving ? null : () => Navigator.of(context).pop()),
DsButton(_saving ? '保存中…' : '保存',
variant: DsBtnVariant.primary, onPressed: _saving ? null : _save),
],
);
}
}
@@ -7,12 +7,14 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:intl/intl.dart';
import 'package:lucide_icons_flutter/lucide_icons.dart';
import '../core/responsive/responsive.dart';
import '../core/theme/app_chrome.g.dart';
import '../core/theme/app_dims.g.dart';
import '../core/theme/context_tokens.dart';
import '../models/finance.dart';
import '../providers/finance_provider.dart';
import 'ds/ds_atoms.dart';
import 'ds/m_sheet.dart';
import 'finance_entry_dialog.dart';
import 'write_guard.dart';
import '../core/theme/app_fonts.dart';
@@ -50,6 +52,18 @@ Future<void> showFinancePartnerDrawer(
BuildContext context, {
required PartnerFinanceRow row,
}) {
// 窄屏:底部 sheet 形态(对齐原型移动 sheet 交互范式)
if (context.isMobile) {
return showMSheet<void>(
context,
title: null,
scrollable: false,
builder: (ctx) => SizedBox(
height: MediaQuery.of(ctx).size.height * 0.86,
child: _FinancePartnerDrawer(row: row),
),
);
}
return showGeneralDialog<void>(
context: context,
useRootNavigator: false,
+12 -6
View File
@@ -132,15 +132,18 @@ class KpiCard extends StatelessWidget {
/// 状态徽章(还原原型 `.badge`:圆点 + 文字同色 + 软底 pill)。
/// 用于库存「在售/预警/缺货」等派生状态;色与软底全走 token。
/// [icon] 非空 → 图标徽章变体(原型 .badge.bi),默认圆点(存量 golden 零漂移)。
class StatusPill extends StatelessWidget {
final String label;
final Color color;
final Color background;
final IconData? icon;
const StatusPill(
{super.key,
required this.label,
required this.color,
required this.background});
required this.background,
this.icon});
@override
Widget build(BuildContext context) {
@@ -154,11 +157,14 @@ class StatusPill extends StatelessWidget {
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 6,
height: 6,
decoration: BoxDecoration(color: color, shape: BoxShape.circle),
),
if (icon != null)
Icon(icon, size: 12, color: color)
else
Container(
width: 6,
height: 6,
decoration: BoxDecoration(color: color, shape: BoxShape.circle),
),
const SizedBox(width: 5),
Text(label,
style: TextStyle(
@@ -3,9 +3,11 @@ import 'dart:math' as math;
import 'package:flutter/material.dart';
import '../core/responsive/responsive.dart';
import '../core/theme/context_tokens.dart';
import '../core/theme/app_dims.g.dart';
import '../core/theme/app_fonts.dart';
import 'ds/m_sheet.dart';
/// 右侧滑入抽屉呈现(对齐原型 .drawer / .drawer-mask)。
/// useRootNavigator:false → 只覆盖内容区(分支 Navigator),不盖侧栏/顶栏。
@@ -15,6 +17,20 @@ Future<T?> showOrderDetailDrawer<T>(
BuildContext context, {
required WidgetBuilder builder,
}) {
// 窄屏:底部 sheet 形态(原型 m-stock-*-list openOrder 详情 sheet);
// OrderDetailDrawer 自带「单号 + X」头部,title:null 只出 grip
// scrollable:false + 定界高 → 内部 Column/Expanded 布局照常工作。
if (context.isMobile) {
return showMSheet<T>(
context,
title: null,
scrollable: false,
builder: (ctx) => SizedBox(
height: MediaQuery.of(ctx).size.height * 0.86,
child: Builder(builder: builder),
),
);
}
return showGeneralDialog<T>(
context: context,
useRootNavigator: false,
+35 -2
View File
@@ -6,6 +6,7 @@ import '../core/theme/context_tokens.dart';
import '../core/utils/dialog_util.dart';
import 'ds/ds_atoms.dart';
import 'ds/ds_toast.dart';
import 'ds/m_sheet.dart';
/// 退单状态小徽章(none 返回 null 不显示)。partial=部分退单(amber)full=已退单(红)。
Widget? returnStateBadge(BuildContext context, String state) {
@@ -66,6 +67,25 @@ Future<bool?> showOrderReturnDialog({
required List<ReturnLine> lines,
required Future<void> Function(List<int> itemIds) onSubmit,
}) {
// 窄屏:底部 sheet 形态(原型 m-stock-*-list openReturn 退单 sheet
if (context.isMobile) {
return showMSheet<bool>(
context,
title: null,
scrollable: false,
builder: (ctx) => SizedBox(
height: MediaQuery.of(ctx).size.height * 0.86,
child: _OrderReturnDialog(
title: title,
meta: meta,
isOut: isOut,
lines: lines,
onSubmit: onSubmit,
asSheet: true,
),
),
);
}
return showAppDialog<bool>(
context: context,
builder: (_) => _OrderReturnDialog(
@@ -85,12 +105,16 @@ class _OrderReturnDialog extends StatefulWidget {
final List<ReturnLine> lines;
final Future<void> Function(List<int> itemIds) onSubmit;
/// true → sheet 形态(外层 showMSheet 提供 grip/圆角,本体不再包 Dialog)。
final bool asSheet;
const _OrderReturnDialog({
required this.title,
required this.meta,
required this.isOut,
required this.lines,
required this.onSubmit,
this.asSheet = false,
});
@override
@@ -200,12 +224,22 @@ class _OrderReturnDialogState extends State<_OrderReturnDialog> {
.where((l) => _staged.contains(l.itemId))
.fold<double>(0, (s, l) => s + l.quantity);
// sheet 形态:外层已定界高,本体直接铺 Column(头/明细/底结构同 Dialog)。
if (widget.asSheet) return _body(stagedQty);
return Dialog(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
child: SizedBox(
width: context.dialogWidth(820),
height: 560,
child: Column(
child: _body(stagedQty),
),
);
}
Widget _body(double stagedQty) {
return Builder(
builder: (context) => Column(
children: [
// 头部
Padding(
@@ -328,7 +362,6 @@ class _OrderReturnDialogState extends State<_OrderReturnDialog> {
),
),
],
),
),
);
}
@@ -8,6 +8,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:intl/intl.dart';
import 'package:lucide_icons_flutter/lucide_icons.dart';
import '../core/responsive/responsive.dart';
import '../core/theme/app_chrome.g.dart';
import '../core/theme/app_dims.g.dart';
import '../core/theme/context_tokens.dart';
@@ -15,6 +16,7 @@ import '../models/finance.dart';
import '../models/partner.dart';
import '../providers/partner_provider.dart';
import 'ds/ds_atoms.dart';
import 'ds/m_sheet.dart';
import 'write_guard.dart';
import '../core/theme/app_fonts.dart';
import 'ds/ds_toast.dart';
@@ -27,6 +29,19 @@ Future<void> showPartnerDetailDrawer(
({double recv, double pay})? balance,
VoidCallback? onEdit,
}) {
// 窄屏:底部 sheet 形态(原型 m-partners openP 详情 sheet
if (context.isMobile) {
return showMSheet<void>(
context,
title: null,
scrollable: false,
builder: (ctx) => SizedBox(
height: MediaQuery.of(ctx).size.height * 0.86,
child: _PartnerDetailDrawer(
partner: partner, balance: balance, onEdit: onEdit),
),
);
}
return showGeneralDialog<void>(
context: context,
useRootNavigator: false,
@@ -12,6 +12,7 @@ import 'package:image_picker/image_picker.dart';
import 'package:lucide_icons_flutter/lucide_icons.dart';
import '../core/config/app_config.dart';
import '../core/responsive/responsive.dart';
import '../core/theme/app_chrome.g.dart';
import '../core/theme/app_dims.g.dart';
import '../core/theme/context_tokens.dart';
@@ -21,6 +22,7 @@ import '../providers/product_option_provider.dart';
import '../providers/product_provider.dart';
import 'ds/ds_atoms.dart';
import 'ds/grid_combo_cell.dart';
import 'ds/m_sheet.dart';
import 'searchable_option_field.dart';
import 'fullscreen_image_viewer.dart';
import 'write_guard.dart';
@@ -36,6 +38,23 @@ Future<void> showProductEditorDrawer(
double? cost,
String? status, // 在售 / 预警 / 缺货
}) {
// 窄屏:底部 sheet 形态(原型 m-inventory openItem 内嵌公开页编辑)
if (context.isMobile) {
return showMSheet<void>(
context,
title: null,
scrollable: false,
builder: (ctx) => SizedBox(
height: MediaQuery.of(ctx).size.height * 0.86,
child: _ProductEditorDrawer(
productId: productId,
qty: qty,
unit: unit,
cost: cost,
status: status),
),
);
}
return showGeneralDialog<void>(
context: context,
useRootNavigator: false,
+11 -2
View File
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import '../core/theme/context_tokens.dart';
import 'ds/status_icon_map.dart';
import 'kpi_card.dart';
enum OrderStatus { draft, pending, approved, rejected }
@@ -21,7 +22,11 @@ extension OrderStatusLabel on OrderStatus {
class StatusBadge extends StatelessWidget {
final OrderStatus status;
const StatusBadge(this.status, {super.key});
/// true → 图标徽章变体(icons.js BADGE_ICON 映射,移动端调用点显式启用);
/// 默认 false 保持圆点(桌面存量 golden 零漂移)。
final bool withIcon;
const StatusBadge(this.status, {super.key, this.withIcon = false});
@override
Widget build(BuildContext context) {
@@ -33,6 +38,10 @@ class StatusBadge extends StatelessWidget {
OrderStatus.approved => (t.success, t.successBg),
OrderStatus.rejected => (t.danger, t.dangerBg),
};
return StatusPill(label: status.label, color: fg, background: bg);
return StatusPill(
label: status.label,
color: fg,
background: bg,
icon: withIcon ? statusIcon(status.label) : null);
}
}
+89
View File
@@ -0,0 +1,89 @@
// widgets/theme_sheet.dart — 主题外观选择 sheet(镜像原型 mobile-shell openThemeSheet)。
// m-opt 行式三主题(A 经典蓝 / B 琥珀 / C 酒窖)+ 四色 swatch 预览,选中出勾。
// 写入 themeControllerProvider(持久化),与桌面 ThemePickerPill 同源。
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lucide_icons_flutter/lucide_icons.dart';
import '../core/theme/app_dims.g.dart';
import '../core/theme/app_tokens.g.dart';
import '../core/theme/context_tokens.dart';
import '../core/theme/theme_controller.dart';
import 'ds/m_sheet.dart';
// (key, 名称, 说明)——与桌面 _PrefPanel._themes / 原型 THEMES 同文案。
const _themes = [
('a', 'A · 经典蓝', '浅色 · 默认'),
('b', 'B · 琥珀', '深色'),
('c', 'C · 酒窖', '暖浅色'),
];
/// 打开主题外观选择 sheet。
Future<void> showThemeSheet(BuildContext context) {
return showMSheet<void>(
context,
title: '主题外观',
builder: (ctx) => Consumer(builder: (ctx, ref, _) {
final t = ctx.tokens;
final current = ref.watch(themeControllerProvider);
return Column(children: [
for (var i = 0; i < _themes.length; i++) ...[
Builder(builder: (_) {
final (key, name, desc) = _themes[i];
final sel = key == current;
final preview = appTokensOf(key);
return InkWell(
onTap: () {
ref.read(themeControllerProvider.notifier).set(key);
Navigator.of(ctx).pop();
},
child: Container(
padding: const EdgeInsets.symmetric(vertical: 13),
decoration: BoxDecoration(
border: i == _themes.length - 1
? null
: Border(bottom: BorderSide(color: t.borderSubtle)),
),
child: Row(children: [
// 四色 swatchprimary/primary-dark/page/accent,与桌面 tcard 同序)
ClipRRect(
borderRadius: BorderRadius.circular(AppDims.rSm),
child: SizedBox(
width: 56,
height: 24,
child: Row(children: [
Expanded(child: Container(color: preview.primary)),
Expanded(child: Container(color: preview.primaryDark)),
Expanded(child: Container(color: preview.page)),
Expanded(child: Container(color: preview.accent)),
]),
),
),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(name,
style: TextStyle(
fontSize: AppDims.fsBody,
fontWeight:
sel ? FontWeight.w600 : FontWeight.w500,
color: sel ? t.primary : t.text)),
Text(desc,
style: TextStyle(
fontSize: AppDims.fsXs, color: t.muted)),
],
),
),
if (sel)
Icon(LucideIcons.check, size: 18, color: t.primary),
]),
),
);
}),
],
]);
}),
);
}
@@ -78,7 +78,8 @@ GoRouter _router() => GoRouter(
initialLocation: '/inventory',
routes: [
StatefulShellRoute.indexedStack(
builder: (ctx, state, shell) => AppShell(navigationShell: shell),
builder: (ctx, state, shell) =>
AppShell(navigationShell: shell, location: state.matchedLocation),
branches: [
_branch('/stock-in'),
_branch('/stock-out'),
@@ -0,0 +1,126 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:go_router/go_router.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:jiu_client/core/auth/auth_state.dart';
import 'package:jiu_client/core/theme/themes.dart';
import 'package:jiu_client/models/shop.dart';
import 'package:jiu_client/providers/shop_provider.dart';
import 'package:jiu_client/providers/license_provider.dart';
import 'package:jiu_client/providers/update_provider.dart';
import 'package:jiu_client/providers/connectivity_provider.dart';
import 'package:jiu_client/providers/session_heartbeat.dart';
import 'package:jiu_client/screens/shell/app_shell.dart';
import 'package:jiu_client/widgets/app_status_bar.dart';
import '../support/golden_harness.dart';
/// 移动壳 golden × 三主题(390×844 @2x):窄屏顶栏(标题 + 主题/铃/头像)
/// + 底部 5 tab(库存/入库/出库/财务/我的,库存激活)——对齐原型移动壳
/// mobile-shell.jsm-top + m-tabbar)。二级屏返回箭头形态另see me golden。
/// 更新基准:flutter test --update-goldens test/golden/app_shell_mobile_golden_test.dart
class _FakeAuth extends AuthNotifier {
_FakeAuth() {
state = const AuthState(
user: AuthUser(
accessToken: 't',
refreshToken: 'r',
id: 1,
username: 'wang',
realName: '王经理',
shopNo: 'DSJH-001',
shopId: 1,
role: 'admin'),
);
}
}
class _FakeUpdate extends UpdateNotifier {
@override
Future<AppUpdateInfo?> build() async => null;
}
class _FakeLicense extends LicenseNotifier {
@override
Future<LicenseInfo?> build() async => null;
}
const _shop = ShopInfo(
id: 1,
code: 'DSJH-001',
name: '鼎晟酒行',
address: '浙江省杭州市',
phone: '0571-88886666',
managerName: '王经理');
List<Override> _overrides() => [
authStateProvider.overrideWith((ref) => _FakeAuth()),
shopInfoProvider.overrideWith((ref) => _shop),
licenseProvider.overrideWith(() => _FakeLicense()),
updateProvider.overrideWith(() => _FakeUpdate()),
connectivityProvider
.overrideWith((ref) => ConnectivityNotifier(skipInit: true)),
sessionHeartbeatProvider.overrideWith((ref) => SessionHeartbeat(ref)),
appVersionProvider.overrideWith((ref) => 'v1.0.72'),
isReadonlyProvider.overrideWithValue(false),
];
StatefulShellBranch _branch(String path) => StatefulShellBranch(routes: [
GoRoute(path: path, builder: (_, __) => const SizedBox.expand()),
]);
GoRouter _router() => GoRouter(
initialLocation: '/inventory',
routes: [
StatefulShellRoute.indexedStack(
builder: (ctx, state, shell) =>
AppShell(navigationShell: shell, location: state.matchedLocation),
branches: [
_branch('/stock-in'),
_branch('/stock-out'),
_branch('/inventory'),
_branch('/finance'),
_branch('/partners'),
_branch('/products'),
_branch('/devices'),
_branch('/settings'),
_branch('/about'),
_branch('/me'),
],
),
],
);
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
SharedPreferences.setMockInitialValues({});
AppStatusBar.clock = () => DateTime(2026, 7, 13, 9, 30, 15);
AppStatusBar.ticking = false;
for (final theme in const ['a', 'b', 'c']) {
testWidgets('app shell mobile · theme $theme', (tester) async {
await ensureGoldenFonts();
tester.view.physicalSize = const Size(780, 1688); // 390×844 @2x
tester.view.devicePixelRatio = 2.0;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(ProviderScope(
overrides: _overrides(),
child: MaterialApp.router(
debugShowCheckedModeBanner: false,
theme: withGoldenFont(buildTheme(theme)),
routerConfig: _router(),
),
));
await tester.pumpAndSettle();
await expectLater(
find.byType(MaterialApp),
matchesGoldenFile('goldens/app_shell_mobile_$theme.png'),
);
});
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

+51
View File
@@ -0,0 +1,51 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';
import 'package:jiu_client/core/auth/auth_state.dart';
import 'package:jiu_client/models/shop.dart';
import 'package:jiu_client/providers/shop_provider.dart';
import 'package:jiu_client/screens/me/me_screen.dart';
import '../support/golden_harness.dart';
/// 「我的」hub golden × 三主题(390×844 @2x):用户头卡(渐变头像 + 角色徽章)
/// + 经营管理组 3 项 + 系统组 6 项 + 退出登录——对齐原型 m-me.html。
/// 更新基准:flutter test --update-goldens test/golden/me_golden_test.dart
class _FakeAuth extends AuthNotifier {
_FakeAuth() {
state = const AuthState(
user: AuthUser(
accessToken: 't',
refreshToken: 'r',
id: 1,
username: '13800138000',
realName: '王经理',
shopNo: 'DSJH-001',
shopId: 1,
role: 'admin'),
);
}
}
const _shop = ShopInfo(
id: 1,
code: 'DSJH-001',
name: '鼎晟酒行',
address: '浙江省杭州市',
phone: '0571-88886666',
managerName: '王经理');
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
goldenAcrossThemes(
'me screen',
child: () => const MeScreen(),
goldenPrefix: 'me',
logical: const Size(390, 844),
overrides: () => [
authStateProvider.overrideWith((ref) => _FakeAuth()),
shopInfoProvider.overrideWith((ref) => _shop),
],
);
}
+2 -1
View File
@@ -79,7 +79,8 @@ GoRouter _router(String initialPath, WidgetBuilder screen) => GoRouter(
initialLocation: initialPath,
routes: [
StatefulShellRoute.indexedStack(
builder: (ctx, state, shell) => AppShell(navigationShell: shell),
builder: (ctx, state, shell) =>
AppShell(navigationShell: shell, location: state.matchedLocation),
branches: [
for (final p in const [
'/stock-in',
+2 -1
View File
@@ -55,7 +55,8 @@ GoRouter _router() => GoRouter(
initialLocation: '/inventory',
routes: [
StatefulShellRoute.indexedStack(
builder: (ctx, state, shell) => AppShell(navigationShell: shell),
builder: (ctx, state, shell) =>
AppShell(navigationShell: shell, location: state.matchedLocation),
branches: [
for (final p in const [
'/stock-in',