Browse Source

0016674: 【新建档案】未绑定人证阅读器,点击读卡识别,提示“未连接读卡器,请连接读卡器后重试”,修改成“未绑定,请绑定后重试”(其他设备是提示“未绑定“)

finlay 1 year ago
parent
commit
a9afb50269

+ 29 - 11
lib/pages/patient/card_reader/controller.dart

@@ -3,26 +3,44 @@ import 'package:get/get.dart';
 import 'package:idread/model/id_card_info_model.dart';
 import 'package:vitalapp/architecture/utils/prompt_box.dart';
 import 'package:idread/idread.dart';
+import 'package:vitalapp/managers/interfaces/device.dart';
+import 'package:vitalapp/managers/interfaces/models/device.dart';
+import 'package:vnote_device_plugin/consts/types.dart';
 
 class CardReaderController extends GetxController {
   CardReaderController();
 
   bool isCardReaderConnected = false; // 是否连接读卡器
+  bool isCardReaderBinding = false; //是否绑定读卡器
 
   _initData() async {
-    bool result = await Idread.init();
-    if (result) {
-      bool start = await Idread.startRead();
-      if (start) {
-        Idread.dataStreamListen((data) {
-          if (data is IdCardInfoModel) {
-            onReadInfo(data);
-          }
-        });
+    var isBinding = await getDevice(DeviceTypes.IC_READER);
+    if (isBinding) {
+      bool result = await Idread.init();
+      if (result) {
+        bool start = await Idread.startRead();
+        if (start) {
+          Idread.dataStreamListen((data) {
+            if (data is IdCardInfoModel) {
+              onReadInfo(data);
+            }
+          });
+        }
       }
+      isCardReaderConnected = result;
+      update(["card_reader"]);
+    }
+  }
+
+  Future<bool> getDevice(String type) async {
+    List<DeviceModel> devices =
+        await Get.find<IDeviceManager>().getDeviceList();
+    var device = devices.firstWhereOrNull((element) => element.type == type);
+    if (device != null) {
+      return true;
+    } else {
+      return false;
     }
-    isCardReaderConnected = result;
-    update(["card_reader"]);
   }
 
   void checkReader() async {

+ 15 - 14
lib/pages/patient/card_reader/widgets/no_card_reader_view.dart

@@ -15,32 +15,33 @@ class NoCardReaderView extends GetView<CardReaderController> {
           color: Colors.red,
         ),
         const SizedBox(height: 20),
-        const Text(
-          '未绑定',
-          style: TextStyle(
+        Text(
+          controller.isCardReaderBinding ? '未连接读卡器' : '未绑定读卡器',
+          style: const TextStyle(
             fontSize: 26,
             fontWeight: FontWeight.bold,
           ),
         ),
         const SizedBox(height: 20),
-        const Text(
-          '请绑定后重试',
-          style: TextStyle(
+        Text(
+          controller.isCardReaderBinding ? "读卡器连接失败请检查" : '请在设置中心绑定读卡器',
+          style: const TextStyle(
             fontSize: 18,
             color: Colors.grey,
           ),
           textAlign: TextAlign.center,
         ),
         const SizedBox(height: 20),
-        ElevatedButton(
-          onPressed: () {
-            controller.checkReader();
-          },
-          child: const Text(
-            '重试',
-            style: TextStyle(fontSize: 20),
+        if (controller.isCardReaderBinding)
+          ElevatedButton(
+            onPressed: () {
+              controller.checkReader();
+            },
+            child: const Text(
+              '重试',
+              style: TextStyle(fontSize: 20),
+            ),
           ),
-        ),
         const SizedBox(height: 40),
       ],
     );