From ffbdb5c57ad07e7c693efe2e3811443ceb422441 Mon Sep 17 00:00:00 2001 From: des <18638715007@163.com> Date: Tue, 26 May 2026 20:40:05 +0800 Subject: [PATCH] =?UTF-8?q?UI=20=E5=88=9D=E4=BD=93=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/main.dart | 118 ++++++++++------------------------------- lib/models/models.dart | 44 +++++++++++++++ lib/pages/import.dart | 49 +++++++++++++++++ test/widget_test.dart | 30 ----------- 4 files changed, 120 insertions(+), 121 deletions(-) create mode 100644 lib/pages/import.dart delete mode 100644 test/widget_test.dart diff --git a/lib/main.dart b/lib/main.dart index 6c69776..1a81bd5 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,15 +1,16 @@ import 'package:flutter/material.dart'; import 'package:flutter_carbon/flutter_carbon.dart'; +import 'package:report_manage/pages/import.dart'; import 'container.dart'; void main() { - runApp(const MyApp()); + runApp(MyApp()); } class MyApp extends StatelessWidget { - const MyApp({super.key}); - + MyApp({super.key}); + final GlobalKey _navKey = GlobalKey(); // This widget is the root of your application. @override Widget build(BuildContext context) { @@ -19,97 +20,32 @@ class MyApp extends StatelessWidget { home: CarbonUIShell( appName: "报表管理", sideNavItems: [ - CarbonNavItem(label: "数据导入",), - CarbonNavItem(label: "销售明细",), + CarbonNavItem( + label: "数据导入", + icon: CarbonIcons.upload, + onTap: () { + _navKey.currentState?.pushReplacement( + MaterialPageRoute(builder: (_) => ImportPage()), + ); + }, + ), + CarbonNavItem( + label: "销售明细", + icon: CarbonIcons.table, + onTap: () { + _navKey.currentState?.pushReplacement( + MaterialPageRoute(builder: (_) => ZContainer()), + ); + }, + ), ], - child: ZContainer() - ), - ); - } -} - -class MyHomePage extends StatefulWidget { - const MyHomePage({super.key, required this.title}); - - // This widget is the home page of your application. It is stateful, meaning - // that it has a State object (defined below) that contains fields that affect - // how it looks. - - // This class is the configuration for the state. It holds the values (in this - // case the title) provided by the parent (in this case the App widget) and - // used by the build method of the State. Fields in a Widget subclass are - // always marked "final". - - final String title; - - @override - State createState() => _MyHomePageState(); -} - -class _MyHomePageState extends State { - int _counter = 0; - - void _incrementCounter() { - setState(() { - // This call to setState tells the Flutter framework that something has - // changed in this State, which causes it to rerun the build method below - // so that the display can reflect the updated values. If we changed - // _counter without calling setState(), then the build method would not be - // called again, and so nothing would appear to happen. - _counter++; - }); - } - - @override - Widget build(BuildContext context) { - // This method is rerun every time setState is called, for instance as done - // by the _incrementCounter method above. - // - // The Flutter framework has been optimized to make rerunning build methods - // fast, so that you can just rebuild anything that needs updating rather - // than having to individually change instances of widgets. - return Scaffold( - appBar: AppBar( - // TRY THIS: Try changing the color here to a specific color (to - // Colors.amber, perhaps?) and trigger a hot reload to see the AppBar - // change color while the other colors stay the same. - backgroundColor: Theme.of(context).colorScheme.inversePrimary, - // Here we take the value from the MyHomePage object that was created by - // the App.build method, and use it to set our appbar title. - title: Text(widget.title), - ), - body: Center( - // Center is a layout widget. It takes a single child and positions it - // in the middle of the parent. - child: Column( - // Column is also a layout widget. It takes a list of children and - // arranges them vertically. By default, it sizes itself to fit its - // children horizontally, and tries to be as tall as its parent. - // - // Column has various properties to control how it sizes itself and - // how it positions its children. Here we use mainAxisAlignment to - // center the children vertically; the main axis here is the vertical - // axis because Columns are vertical (the cross axis would be - // horizontal). - // - // TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint" - // action in the IDE, or press "p" in the console), to see the - // wireframe for each widget. - mainAxisAlignment: .center, - children: [ - const Text('You have pushed the button this many times:'), - Text( - '$_counter', - style: Theme.of(context).textTheme.headlineMedium, - ), - ], + child: Navigator( + key: _navKey, + onGenerateRoute: (setting) { + return MaterialPageRoute(builder: (_) => ImportPage()); + }, ), ), - floatingActionButton: FloatingActionButton( - onPressed: _incrementCounter, - tooltip: 'Increment', - child: const Icon(Icons.add), - ), ); } } diff --git a/lib/models/models.dart b/lib/models/models.dart index 5685422..150a6a3 100644 --- a/lib/models/models.dart +++ b/lib/models/models.dart @@ -1,4 +1,7 @@ import 'package:drift/drift.dart'; +import 'package:drift_flutter/drift_flutter.dart'; + +part 'models.g.dart'; /// 导入记录表定义 class ImportRecord extends Table { @@ -24,5 +27,46 @@ class SaleDetail extends Table { TextColumn get objName => text()(); /// 进销单据性质 + TextColumn get type => text().map(const SaleDetailTypeConverter())(); + /// 关联导入记录 ID + IntColumn get importId => integer().references(ImportRecord, #id)(); +} + +enum SaleDetailType { + bill('挂账', 'BILL', ['挂账']), + cash('现金', 'CASH', ['挂账']), + online('线上支付', 'ONLINE', ['挂账']); + + final String desc; + final String code; + final List identity; + static final Map map = { + for (var type in SaleDetailType.values) type.code: type, + }; + const SaleDetailType(this.desc, this.code, this.identity); + static SaleDetailType? of(String param) => map[param]; +} + +class SaleDetailTypeConverter extends TypeConverter { + const SaleDetailTypeConverter(); + + @override + SaleDetailType fromSql(String code) => SaleDetailType.of(code)!; + + @override + String toSql(SaleDetailType type) => type.code; +} + +// 添加数据库类 +@DriftDatabase(tables: [ImportRecord, SaleDetail]) +class AppDatabase extends _$AppDatabase { + AppDatabase([QueryExecutor? executor]) : super(executor ?? _openConnection()); + + @override + int get schemaVersion => 1; + + static QueryExecutor _openConnection() { + return driftDatabase(name: 'my_database'); + } } diff --git a/lib/pages/import.dart b/lib/pages/import.dart new file mode 100644 index 0000000..d9e93c5 --- /dev/null +++ b/lib/pages/import.dart @@ -0,0 +1,49 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_carbon/flutter_carbon.dart'; + +class ImportPage extends StatefulWidget { + @override + State createState() => ImportState(); +} + +class ImportState extends State { + @override + Widget build(BuildContext context) { + return Padding( + padding: .all(24), + child: Column( + children: [ + Row( + mainAxisAlignment: .end, + children: [ + CarbonButton(child: Text('导入数据'), onPressed: () => print("点击按钮")), + ], + ), + CarbonDataTable( + headers: [ + CarbonDataTableHeader(key: 'time', label: '导入时间'), + CarbonDataTableHeader(key: 'fileName', label: '文件名称'), + CarbonDataTableHeader(key: 'remark', label: '导入备注'), + ], + rows: [ + CarbonDataTableRow( + cells: [ + CarbonDataTableCell(child: Text("2025-05-21")), + CarbonDataTableCell(child: Text("进货单.xlsx")), + CarbonDataTableCell(child: Text("总之这就是备注啦")), + ], + ), + CarbonDataTableRow( + cells: [ + CarbonDataTableCell(child: Text("2025-05-26")), + CarbonDataTableCell(child: Text("销售单.xlsx")), + CarbonDataTableCell(child: Text("二次备注")), + ], + ), + ], + ), + ], + ), + ); + } +} diff --git a/test/widget_test.dart b/test/widget_test.dart deleted file mode 100644 index ff9f370..0000000 --- a/test/widget_test.dart +++ /dev/null @@ -1,30 +0,0 @@ -// This is a basic Flutter widget test. -// -// To perform an interaction with a widget in your test, use the WidgetTester -// utility in the flutter_test package. For example, you can send tap and scroll -// gestures. You can also use WidgetTester to find child widgets in the widget -// tree, read text, and verify that the values of widget properties are correct. - -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; - -import 'package:report_manage/main.dart'; - -void main() { - testWidgets('Counter increments smoke test', (WidgetTester tester) async { - // Build our app and trigger a frame. - await tester.pumpWidget(const MyApp()); - - // Verify that our counter starts at 0. - expect(find.text('0'), findsOneWidget); - expect(find.text('1'), findsNothing); - - // Tap the '+' icon and trigger a frame. - await tester.tap(find.byIcon(Icons.add)); - await tester.pump(); - - // Verify that our counter has incremented. - expect(find.text('0'), findsNothing); - expect(find.text('1'), findsOneWidget); - }); -}