From 0f3e728a79b299d85ef62fdc3019b5f10e10f5cb Mon Sep 17 00:00:00 2001 From: GYJ <1157756119@qq.com> Date: Sat, 23 Nov 2024 16:53:30 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E8=AF=9D=E8=AE=B0=E5=BD=95=E5=B1=95?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../czg/cashier_reserve/call/CallManager.java | 3 +- images/reserve/create.png | Bin 0 -> 651 bytes images/reserve/phone_fail.png | Bin 0 -> 1964 bytes images/reserve/phone_suc.png | Bin 0 -> 1687 bytes lib/common/channel/call_log_model.dart | 86 ++++++++++ lib/common/channel/channel_event.dart | 24 ++- lib/common/manager/event_manager.dart | 54 ++++++ lib/home/reserve_view.dart | 160 +++++++++++++++++- lib/home/reserve_view_model.dart | 21 ++- pubspec.lock | 8 + pubspec.yaml | 1 + 11 files changed, 343 insertions(+), 14 deletions(-) create mode 100644 images/reserve/create.png create mode 100644 images/reserve/phone_fail.png create mode 100644 images/reserve/phone_suc.png create mode 100644 lib/common/channel/call_log_model.dart create mode 100644 lib/common/manager/event_manager.dart diff --git a/android/app/src/main/java/com/czg/cashier_reserve/call/CallManager.java b/android/app/src/main/java/com/czg/cashier_reserve/call/CallManager.java index eba35fb..d810a5d 100644 --- a/android/app/src/main/java/com/czg/cashier_reserve/call/CallManager.java +++ b/android/app/src/main/java/com/czg/cashier_reserve/call/CallManager.java @@ -40,7 +40,7 @@ public class CallManager { @SuppressLint("Range") String number = cursor.getString(cursor.getColumnIndex(CallLog.Calls.NUMBER)); //号码 @SuppressLint("Range") long dateLong = cursor.getLong(cursor.getColumnIndex(CallLog.Calls.DATE)); //获取通话日期 @SuppressLint("SimpleDateFormat") String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(dateLong)); -// @SuppressLint("SimpleDateFormat") String time = new SimpleDateFormat("HH:mm").format(new Date(dateLong)); + @SuppressLint("SimpleDateFormat") String time = new SimpleDateFormat("HH:mm").format(new Date(dateLong)); @SuppressLint("Range") int duration = cursor.getInt(cursor.getColumnIndex(CallLog.Calls.DURATION));//获取通话时长,值为多少秒 @SuppressLint("Range") int type = cursor.getInt(cursor.getColumnIndex(CallLog.Calls.TYPE)); //获取通话类型:1.呼入2.呼出3.未接 // @SuppressLint("SimpleDateFormat") String dayCurrent = new SimpleDateFormat("dd").format(new Date()); @@ -53,6 +53,7 @@ public class CallManager { callLog.put("date", date); callLog.put("duration", duration); callLog.put("type", type); + callLog.put("time", time); } catch (Exception e) { e.printStackTrace(); } diff --git a/images/reserve/create.png b/images/reserve/create.png new file mode 100644 index 0000000000000000000000000000000000000000..bcdfda17154cbbaa78e500401da479ea8656f95b GIT binary patch literal 651 zcmV;60(AX}P)^04ES9piBTGzy!JhZh#vQCr~Gd?_FE3B1e)oNz<6`?p+TE z*M2lj()S9GNJPZ|hDa%gv>C!8gTX)`G)Qzpv6pT*ASCF3a_OGCGyApLlXPV>>4&?M z{Z>Enk&gkExYB6zh;Epb+l*pwOIk;Ggzm{;Nm@rZ6f%kfNw+!yeG+DP5M${X8qzo6 ziY-Ym(15-QGix5nVMw2anWd?8--Q{Lp6E6XS=eNiHP&r-jd0meOraJR6gz05yj!B~ zvZu`i?#bw`=^c&|ulB7*c%5mcq8Xw17Lf*EGq3{KB@d z%be62%`+iC*j`I7%IjBLXtO)bJJENz=zi(CpTJUH&Be{bT=DrU{{A4`GctG}&BL*i zgkvWOd%*wGbv3#Wp4VT{9LzP~44&vBi8qzS!=x`L&bIT4VV$muX(M#>gr82AZoOa+ z2_0d9{vcEhbcD4Z7zu!_s)16N?rgXk|Ag?_(6QP(IW)4)%M?y%a28~#>(S&-9z43< lAPl}x)T*KySQ7~Yz5)JH`~BN9_2>Wq002ovPDHLkV1kkUAWQ%N literal 0 HcmV?d00001 diff --git a/images/reserve/phone_fail.png b/images/reserve/phone_fail.png new file mode 100644 index 0000000000000000000000000000000000000000..22cc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>WXgLsB=`( z=p0f+DxfH<^`-QS&VCe8)*J-;p4w2T!Dczmf4i)2N%Utk>;Oi9a2w9??wM4^VoCM- z1%8P2FO0_{01|z}oxil?km0Hswu5o|c6&E&;X%8XJGhmh0a?LdlP;~*O-0dZ3uC&u zCfv9RQa7}qt`%^o;RG4mY9Co?KgIAv&1 zu$?#~h7179-&Nw$8!5^bZi|Sgr1hS*9k^ESuUauGetT2CK!zDxKlh zY#K?SV^7N2Wce*pK^M^0`krBrf>)9?kD?W2^&%fyNOGn#Cnkl1E}n{&ijmJleTyu_ ze`^qB!^v$Tv2I7KYA9NXdsIa4W2|T<7Y0YmnO2k)^|g?Wmx3ApNGesN)r+x8vYjA@ z2OB_7V*5ZtaR^zEAj*y`zsW(G&Q20JF)6s!#LAe;vj)sYQ5J|j999|>3oH7;g)X_S zsgD@MQoJAi)od_p>RX~4krgly2H)Dunx7f(X%5Ly=3Bed|B?Hl zM9*3ZKj#`NU?408A%fwgRAUr$N%5B9M)lyY+$%P`A;xi}xDgqs4sYq=ASn8`=V{+2 z=*F&vgHhtlDOL6p+~5FZOginAFc=rHpkwZc z*HpFn%83mIl!jnF81>6*Bi2WkpqTAsxjX|RMcHd7)`xt9hZP=)SCJs^DvD6b^Ootu zA82%y2|$tr>mFLna&IN=ks9`1d&1mpKPk + CallLogModel.fromJson(json.decode(str)); + +String callLogModelToJson(CallLogModel data) => json.encode(data.toJson()); + +class CallLogModel { + CallLogModel({ + String? number, + String? date, + num? duration, + num? type, + String? name, + String? time, + }) { + _number = number; + _date = date; + _duration = duration; + _type = type; + _name = name; + _time = time; + } + + CallLogModel.fromJson(dynamic json) { + _number = json['number']; + _date = json['date']; + _duration = json['duration']; + _type = json['type']; + _name = json['name']; + _time = json['time']; + } + + String? _number; + String? _date; + num? _duration; + num? _type; + String? _name; + String? _time; + + CallLogModel copyWith({ + String? number, + String? date, + num? duration, + num? type, + String? name, + String? time, + }) => + CallLogModel( + number: number ?? _number, + date: date ?? _date, + duration: duration ?? _duration, + type: type ?? _type, + name: name ?? _name, + time: time ?? _time, + ); + + String? get number => _number; + + String? get date => _date; + + num? get duration => _duration; + + num? get type => _type; + + String? get name => _name; + + String? get time => _time; + + Map toJson() { + final map = {}; + map['number'] = _number; + map['date'] = _date; + map['duration'] = _duration; + map['type'] = _type; + map['name'] = _name; + map['time'] = _time; + return map; + } +} diff --git a/lib/common/channel/channel_event.dart b/lib/common/channel/channel_event.dart index a17f83f..710937e 100644 --- a/lib/common/channel/channel_event.dart +++ b/lib/common/channel/channel_event.dart @@ -1,6 +1,10 @@ +import 'dart:convert'; + import 'package:cashier_reserve/common/print/print.dart'; import 'package:flutter/services.dart'; +import '../manager/event_manager.dart'; +import 'call_log_model.dart'; import 'names.dart'; class MyEventChannel { @@ -13,13 +17,19 @@ class MyEventChannel { channel.receiveBroadcastStream().listen((Object? o) { yjPrint("onGetCallLogResult"); yjPrint(o); - // AlipayPayResultEvent event = AlipayPayResultEvent(); - // if (o is int) { - // event.resultStatus = o; - // } else { - // event.resultStatus = int.parse(o as String); - // } - // EventManager.postEvent(event); + GetCallLogEvent event = GetCallLogEvent(); + if (o is String) { + event.isSuccess = true; + List list = json.decode(o); + List callLogs = []; + for (var item in list) { + callLogs.add(CallLogModel.fromJson(item)); + } + event.callLogs = callLogs.reversed.toList(); + } else { + event.isSuccess = false; + } + EventManager.postEvent(event); }, onError: (Object error) { yjPrint("onGetCallLogResult error"); }); diff --git a/lib/common/manager/event_manager.dart b/lib/common/manager/event_manager.dart new file mode 100644 index 0000000..2c523b1 --- /dev/null +++ b/lib/common/manager/event_manager.dart @@ -0,0 +1,54 @@ +import 'dart:async'; + +import 'package:cashier_reserve/common/channel/call_log_model.dart'; +import 'package:event_bus/event_bus.dart'; + + +class EventManager { + static EventBus? _eventBus; + + static final Map> _eventMap = {}; + + static EventBus? get eventBus => getEventBus(); + + static EventBus? getEventBus() { + _eventBus ??= EventBus(); + return _eventBus; + } + + static void postEvent(MyEvent event) { + getEventBus()!.fire(event); + } + + static void addListener(dynamic widget, void Function(T event) onData) { + StreamSubscription event = EventManager.eventBus!.on().listen((T e) { + onData(e); + }); + List? list = _eventMap[widget]; + list ??= []; + list.add(event); + _eventMap[widget] = list; + } + + static void cancelListener(dynamic widget) { + List? list = _eventMap[widget]; + if (list == null) { + return; + } + for (var event in list) { + event.cancel(); + } + } +} + +class MyEvent { + String name = ''; +} + +class GetCallLogEvent extends MyEvent { + List callLogs; + bool isLoadMore = false; + bool isSuccess = false; + + GetCallLogEvent({this.callLogs = const [], this.isLoadMore = false, this.isSuccess = false}); +} \ No newline at end of file diff --git a/lib/home/reserve_view.dart b/lib/home/reserve_view.dart index b7150d1..0a15701 100644 --- a/lib/home/reserve_view.dart +++ b/lib/home/reserve_view.dart @@ -1,5 +1,7 @@ import 'package:cashier_reserve/common/base/ui.dart'; import 'package:cashier_reserve/common/base/ui_model.dart'; +import 'package:cashier_reserve/common/channel/call_log_model.dart'; +import 'package:cashier_reserve/common/print/print.dart'; import 'package:cashier_reserve/home/reserve_view_model.dart'; import '../common/base/provider.dart'; @@ -43,7 +45,7 @@ class ReserveView extends BaseUI { width: 15, ), InkWell( - onTap: () {}, + onTap: () {}, child: SizedBox( width: 40, height: 40, @@ -84,7 +86,10 @@ class ReserveView extends BaseUI { width: 40, height: 40, child: Center( - child: Text("刷新", style: TextStyle(fontSize: 15, color: Colors.blue),), + child: Text( + "刷新", + style: TextStyle(fontSize: 15, color: Colors.blue), + ), ), ), ), @@ -95,7 +100,156 @@ class ReserveView extends BaseUI { Widget _buildContentView(BuildContext context, ReserveViewModel provider) { return Row( - children: [], + children: [ + _buildLeftContent(context, provider), + Expanded(child: _buildRightContent(context, provider)), + ], + ); + } + + Widget _buildLeftContent(BuildContext context, ReserveViewModel provider) { + yjPrint("callLogs length: ${provider.callLogs?.length}"); + return Column( + children: [ + Expanded( + child: SizedBox( + width: 430, + child: ListView.builder( + itemCount: provider.callLogs?.length ?? 0, + itemBuilder: (context, index) { + return _buildCallRecordItem(context, provider.callLogs?[index]); + }, + ), + )), + Container( + padding: const EdgeInsets.fromLTRB(20, 10, 20, 15), + child: InkWell( + onTap: () {}, + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(5), + color: const Color(0xff318AFE), + ), + width: 300, + height: 36, + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Image.asset( + 'images/reserve/create.png', + width: 20, + height: 20, + ), + const SizedBox( + width: 5, + ), + const Text( + "创建订单", + style: TextStyle(color: Colors.white, fontSize: 14), + ), + ], + ), + ), + ), + ) + ], + ); + } + + Widget _buildRightContent(BuildContext context, ReserveViewModel provider) { + return Container(); + } + + /// _buildCallRecordItem 通话记录item + Widget _buildCallRecordItem(BuildContext context, CallLogModel? model) { + return Container( + padding: const EdgeInsets.fromLTRB(15, 15, 15, 5), + child: Column( + children: [ + Row( + children: [ + Column( + children: [ + Image.asset( + (model?.type ?? 0) == 3 + ? "images/reserve/phone_fail.png" + : "images/reserve/phone_suc.png", + width: 24, + height: 24, + ), + const SizedBox(height: 2), + Text( + model?.time ?? "", + style: + const TextStyle(color: Color(0xff999999), fontSize: 12), + ), + ], + ), + const SizedBox(width: 10), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + model?.name ?? "未知电话", + style: + const TextStyle(color: Color(0xff333333), fontSize: 14), + ), + const SizedBox(height: 5), + Row( + children: [ + Text( + model?.number ?? "", + style: const TextStyle( + color: Color(0xff333333), fontSize: 14), + ), + const SizedBox( + width: 15, + ), + const Text( + "已消费0单", + style: + TextStyle(color: Color(0xff333333), fontSize: 14), + ), + const SizedBox( + width: 15, + ), + const Text( + "已撤0单", + style: + TextStyle(color: Color(0xff333333), fontSize: 14), + ), + ], + ), + ], + ), + const Expanded(child: SizedBox()), + InkWell( + onTap: () {}, + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(5), + border: + Border.all(color: const Color(0xff318AFE), width: 1), + ), + padding: const EdgeInsets.fromLTRB(20, 7, 20, 7), + child: const Text( + "处理", + style: TextStyle(color: Color(0xff318AFE), fontSize: 14), + ), + ), + ) + ], + ), + const SizedBox( + height: 10, + ), + Container( + height: 1, + color: const Color(0xffededed), + ), + ], + ), ); } diff --git a/lib/home/reserve_view_model.dart b/lib/home/reserve_view_model.dart index 61162a4..24f3d31 100644 --- a/lib/home/reserve_view_model.dart +++ b/lib/home/reserve_view_model.dart @@ -1,5 +1,8 @@ import 'package:cashier_reserve/common/base/ui_model.dart'; +import 'package:cashier_reserve/common/channel/call_log_model.dart'; import 'package:cashier_reserve/common/channel/channel_manager.dart'; +import 'package:cashier_reserve/common/manager/event_manager.dart'; +import 'package:cashier_reserve/common/print/print.dart'; class ReserveViewModel extends BaseUIModel { Map weekdayMap = { @@ -17,10 +20,22 @@ class ReserveViewModel extends BaseUIModel { 1: "明", 2: "后", }; + + List? callLogs = []; - // ReserveViewModel() { - // loadData(); - // } + ReserveViewModel() { + EventManager.addListener(this, (event) { + if (event.isSuccess) { + if (!event.isSuccess) { + return; + } + callLogs = event.callLogs; + notifyListeners(); + } + }); + + loadCallLog(); + } void loadCallLog() { ChannelManager.getCallLog("getCallLog"); diff --git a/pubspec.lock b/pubspec.lock index 0924138..4e57b1a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -97,6 +97,14 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.0.0" + event_bus: + dependency: "direct main" + description: + name: event_bus + sha256: "1a55e97923769c286d295240048fc180e7b0768902c3c2e869fe059aafa15304" + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.0.1" fake_async: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 773dc49..d71d3a5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -41,6 +41,7 @@ dependencies: cached_network_image: ^3.4.1 timeago: ^3.7.0 percent_indicator: ^4.0.1 + event_bus: ^2.0.1 dev_dependencies: flutter_test: