Quellcode durchsuchen

内蒙项目,外设多合一,品牌和连接方式等参数使用同一份配置

guohh vor 3 Jahren
Ursprung
Commit
1d875b7cd2

+ 1 - 54
2021/nm-zsyt/ipu/connect-config.html

@ -29,60 +29,7 @@
29 29
    </header>
30 30
  </div>
31 31
  <div class="ipu-flex-col ipu-flex-col-auto">
32
    <div class="ipu-flex-content">
33
      <div class="ipu-tab ipu-tab-fixed ipu-tab-button" id="tabFixed">
34
        <div class="ipu-tab-head">
35
          <ul>
36
          <!--  <li class="ipu-current">身份证读卡器</li>
37
            <li class="">sim卡读卡器</li>-->
38
          </ul>
39
        </div>
40
        <div class="ipu-tab-body">
41
          <ul>
42
           <!-- <li class="ipu-current">
43
44
              <div class="demo-item">
45
                <p class="demo-title">读卡器连接方式</p>
46
                <div class="demo-body">
47
                  <div class="ipu-list">
48
                    <ul>
49
                      <li class="ipu-list-item">
50
                        <div class="ipu-list-item-inner">
51
                          <label class="ipu-radio">
52
                            <input type="radio" name="cardreader_connection">蓝牙
53
                          </label>
54
                        </div>
55
                      </li>
56
                      <li class="ipu-list-item">
57
                        <div class="ipu-list-item-inner">
58
                          <label class="ipu-radio">
59
                            <input type="radio" name="cardreader_connection">OTG
60
                          </label>
61
62
                        </div>
63
                      </li>
64
                      <li class="ipu-list-item">
65
                        <div class="ipu-list-item-inner">
66
                          <label class="ipu-radio">
67
                            <input type="radio" name="cardreader_connection">NFC
68
                          </label>
69
70
                        </div>
71
                      </li>
72
                    </ul>
73
                  </div>
74
                </div>
75
              </div>
76
            </li>
77
            <li class="">
78
              <div class="demo-body">
79
                <div class="demo-content">
80
                </div>
81
              </div>
82
            </li>-->
83
          </ul>
84
        </div>
85
      </div>
32
    <div class="ipu-flex-content" id="content">
86 33
    </div>
87 34
  </div>
88 35
</div>

+ 43 - 83
2021/nm-zsyt/ipu/js/connect-config.js

@ -1,59 +1,35 @@
1 1
$(function () {
2 2
3
  var contentRoot = $("#content");
4
3 5
  // 设备连接配置项
4
  var configs = [{
5
    name: '身份证读卡器',
6
    items: [{
7
      label: '类型',
8
      name: 'ID_DEVICE_TYPE',
9
      options: [{
10
        name: '森锐', value: 'SR',
11
      }, {
12
        name: '三元达', value: 'SYD',
13
      }, {
14
        name: '中移在线', value: 'ZYZX',
15
      }]
6
  var configItems = [{
7
    label: '类型',
8
    name: 'DEVICE_BRAND_TYPE',
9
    options: [{
10
      name: '森锐', value: 'SR',
11
    }, {
12
      name: '三元达', value: 'SYD',
16 13
    }, {
17
      label: '连接方式',
18
      name: 'ID_CONNECT_TYPE',
19
      options: [{
20
        name: '蓝牙', value: 'bt',
21
      }, {
22
        name: 'OTG', value: 'otg',
23
      }, {
24
        name: 'NFC', value: 'nfc',
25
      }]
14
      name: '中移在线', value: 'ZYZX',
26 15
    }]
27 16
  }, {
28
    name: 'SIM卡读卡器',
29
    items: [{
30
      label: '类型',
31
      name: 'SIM_DEVICE_TYPE',
32
      options: [{
33
        name: '森锐', value: 'SR',
34
      }, {
35
        name: '三元达', value: 'SYD',
36
      }, {
37
        name: '中移在线', value: 'ZYZX',
38
      }]
17
    label: '连接方式',
18
    name: 'DEVICE_CONNECT_TYPE',
19
    options: [{
20
      name: '蓝牙', value: 'bt',
39 21
    }, {
40
      label: '连接方式',
41
      name: 'SIM_CONNECT_TYPE',
42
      options: [{
43
        name: '蓝牙', value: 'bt',
44
      }, {
45
        name: 'OTG', value: 'otg',
46
      }, {
47
        name: 'NFC', value: 'nfc',
48
      }]
22
      name: 'OTG', value: 'otg',
49 23
    }, {
50
      label: '蓝牙地址',
51
      name: 'SIM_BT_ADDRESS',
52
      type: 'input',
53
      clickFun: function (callback) {
54
        AndroidWebView.btDeviceList(callback)
55
      }
24
      name: 'NFC', value: 'nfc',
56 25
    }]
26
  }, {
27
    label: '蓝牙地址',
28
    name: 'DEVICE_BT_ADDRESS',
29
    type: 'input',
30
    clickFun: function (callback) {
31
      AndroidWebView.btDeviceList(callback)
32
    }
57 33
  }];
58 34
59 35
  // 设置连接信息
@ -62,12 +38,9 @@ $(function () {
62 38
  }
63 39
64 40
  // 初始化配置项
65
  function iniTabItem(config) {
66
    var tabIemHead = "<li>" + config.name + "</li>";
67
    $(tabIemHead).appendTo(".ipu-tab-head>ul:first");
68
69
    var tabIemBody = '';
70
    $(config.items).each(function (i, item) {
41
  function iniConfigItem(items) {
42
    var contentHtml = '';
43
    $(items).each(function (i, item) {
71 44
      var optionStr = '';
72 45
73 46
      if ($.isArray(item.options)) {
@ -81,7 +54,7 @@ $(function () {
81 54
            '                    </li>'
82 55
        });
83 56
84
      } else if (item.type == 'select') {
57
      } else if (item.type == 'input') {
85 58
        var readonly = item.clickFun ? 'readonly' : '';
86 59
        optionStr = optionStr + '<li class="ipu-list-item">\n' +
87 60
          '                <div class="ipu-list-item-inner">\n' +
@ -94,62 +67,49 @@ $(function () {
94 67
95 68
        // 绑定事件
96 69
        if (item.clickFun) {
97
          $(".ipu-tab-body").on("click", "input[name='" + item.name + "']", function () {
70
          contentRoot.on("click", "input[name='" + item.name + "']", function () {
98 71
            var input = $(this);
99 72
            item.clickFun(function (result) {
100 73
              input.val(result);
74
              setConnectConfig(input.attr("name"), input.val());
101 75
            });
102 76
          });
103 77
        }
104 78
      }
105 79
106
      tabIemBody = tabIemBody + '<div class="demo-item"><p class="demo-title">' + item.label + '</p>' +
80
      contentHtml = contentHtml + '<div class="demo-item"><p class="demo-title">' + item.label + '</p>' +
107 81
        '<div class="demo-body"><div class="ipu-list"><ul>' + optionStr + '</ul></div></div></div>';
108 82
    });
109 83
110
    tabIemBody = '<li>' + tabIemBody + '</li>';
111
    $(tabIemBody).appendTo(".ipu-tab-body>ul:first");
84
    $(contentHtml).appendTo(contentRoot);
112 85
  }
113 86
114
  // 更新配置初始
115
  function setInputVal(obj) {
116
    for (var key in obj) {
117
      if (obj[key]) { // 缓存有值
118
        $("input[name='" + key + "']").val(obj[key]);
87
  // 初始化配置项
88
  function initConfigItemValue() {
89
    AndroidWebView.getDeviceConfig(function (obj) {
90
      for (var key in obj) {
91
        if (obj[key]) { // 缓存有值
92
          $("input[name='" + key + "']").val(obj[key]);
93
        }
119 94
      }
120
    }
95
    });
121 96
  }
122 97
123 98
  // 页面初始化
124 99
  function init() {
125 100
    // 初始化配置项
126
    $(configs).each(function (i, config) {
127
      iniTabItem(config);
128
    });
129
130
    // 读取身份证缓存数据
131
    AndroidWebView.getIdReaderConfig(setInputVal);
101
    iniConfigItem(configItems);
132 102
133
    // 读取默认配置
134
    AndroidWebView.getSimReaderConfig(setInputVal);
103
    // 读取身份证缓存数据,更新配置初始值
104
    initConfigItemValue();
135 105
  }
136 106
137 107
  // 页面事件绑定
138 108
  function bindEvent() {
139 109
    // 保存配置项变动
140
    $(".ipu-tab-body input").change(function () {
110
    $("input", contentRoot).change(function () {
141 111
      setConnectConfig($(this).attr("name"), $(this).val());
142 112
    });
143
144
    // tab切换
145
    $(".ipu-tab-head").on("click", "li", function () {
146
      $(this).addClass("ipu-current").siblings(".ipu-current").removeClass("ipu-current");
147
      var index = $(this).index();
148
      $(".ipu-tab-body>ul>li:eq(" + index + ")").addClass("ipu-current").siblings(".ipu-current").removeClass("ipu-current");
149
    });
150
151
    // 选中tab第一项显示
152
    $(".ipu-tab-head>ul>li:first").click();
153 113
  }
154 114
155 115
  init();

+ 28 - 73
2021/nm-zsyt/ipu/js/frame/android-webview.js

@ -2,14 +2,10 @@
2 2
(function () {
3 3
  // 依赖IPU框架ipu-mobile.js
4 4
5
  // 身份证设备连接配置缓存key
6
  var KEY_ID_DEVICE_TYPE = 'ID_DEVICE_TYPE';    // 身份证读取设备类型缓存key
7
  var KEY_ID_CONNECT_TYPE = 'ID_CONNECT_TYPE';  // 身份证读取设备连接方式缓存key
8
9
  // SIM设备连接配置缓存key
10
  var KEY_SIM_DEVICE_TYPE = 'SIM_DEVICE_TYPE';      // sim读取设备类型缓存key
11
  var KEY_SIM_CONNECT_TYPE = 'SIM_CONNECT_TYPE';    // sim读取设备连接类型缓存key
12
  var KEY_SIM_BT_ADDRESS = 'SIM_BT_ADDRESS';        // sim读取蓝牙设备地址缓存keymobile.js
5
  // 外设连接配置缓存key
6
  var KEY_DEVICE_BRAND_TYPE = 'DEVICE_BRAND_TYPE';      // 外设品牌类型缓存key
7
  var KEY_DEVICE_CONNECT_TYPE = 'DEVICE_CONNECT_TYPE';  // 外设连接方式缓存key
8
  var KEY_DEVICE_BT_ADDRESS = 'DEVICE_BT_ADDRESS';      // 外设蓝牙地址缓存key
13 9
14 10
  var SIM_SUCCESS_PREFIX = '0&';                    // 读写卡返回结果成功时字符前缀
15 11
@ -22,81 +18,40 @@
22 18
    getCache: IpuMobile.getOfflineCache,           // 读取离线缓存
23 19
24 20
    /**
25
     * 设置身份证读卡器类型
26
     * @param {string} type 读卡器类型,SR/SYD/ZYZX分别代表森锐/三元达/中移在线
27
     */
28
    setIdReaderType: function (type) {
29
      this.setCache(KEY_ID_DEVICE_TYPE, type);
30
    },
31
32
    /**
33
     * 设置身份证读卡器连接方式
34
     * @param {string} connection 连接方式 bt\otg\nfc
35
     */
36
    setIdReaderConnection: function (connection) {
37
      this.setCache(KEY_ID_CONNECT_TYPE, connection);
38
    },
39
40
    /**
41
     * 设置sim读卡器设备类型
42
     * @param {string} deviceType 设备类型
43
     */
44
    setSimReaderDeviceType: function (deviceType) {
45
      this.setCache(KEY_SIM_DEVICE_TYPE, deviceType);
46
    },
47
48
    /**
49
     * 设置sim读卡器连接方式
50
     * @param {string} connectType 设备连接方式
21
     * 设置外设品牌
22
     * @param {string} type 连接设备类型,SR/SYD/ZYZX分别代表森锐/三元达/中移在线
51 23
     */
52
    setSimReaderConnection: function (connectType) {
53
      this.setCache(KEY_SIM_CONNECT_TYPE, connectType);
24
    setDeviceBrandType: function (type) {
25
      this.setCache(KEY_DEVICE_BRAND_TYPE, type);
54 26
    },
55 27
56 28
    /**
57
     * 设置sim读卡器蓝牙地址,可通过 AndroidWebView.btDeviceList()获取
58
     * @param {string} btnAddress 蓝牙设备地址
29
     * 设置外设连接方式
30
     * @param {string} type 连接方式 bt\otg\nfc
59 31
     */
60
    setSimReaderBtnAddress: function (btnAddress) {
61
      this.setCache(KEY_SIM_BT_ADDRESS, btnAddress);
32
    setDeviceConnection: function (type) {
33
      this.setCache(KEY_DEVICE_CONNECT_TYPE, type);
62 34
    },
63 35
64 36
    /**
65
     * 读取身份证读卡器设备连接配置,蓝牙参数在设备驱动中配置不用传参
37
     * 读取外设连接配置,蓝牙参数在设备驱动中配置不用传参
66 38
     *
67 39
     * @param {function} callback 回调函数
68
     * @param {Object} callback.obj 后面两个参数及值组成的json对象
40
     * @param {Object} callback.obj 后面参数及值组成的json对象
69 41
     * @param {string} callback.deviceType 设备类型
70 42
     * @param {string} callback.connectType 连接类型
43
     * @param {string} callback.btAddress 设备蓝牙地址
71 44
     */
72
    getIdReaderConfig: function (callback) {
45
    getDeviceConfig: function (callback) {
73 46
      this.getCache(function (cacheResult) {  // deviceType, connectType存储在缓存,不直接通过调用传递参数
74 47
        cacheResult = JSON.parse(cacheResult);
75
        var deviceType = cacheResult[KEY_ID_DEVICE_TYPE];
76
        var connectType = cacheResult[KEY_ID_CONNECT_TYPE];
77
        callback(cacheResult, deviceType, connectType);
78
      }, [KEY_ID_DEVICE_TYPE, KEY_ID_CONNECT_TYPE]);
48
        var deviceType = cacheResult[KEY_DEVICE_BRAND_TYPE];
49
        var connectType = cacheResult[KEY_DEVICE_CONNECT_TYPE];
50
        var btAddress = cacheResult[KEY_DEVICE_BT_ADDRESS];
51
        callback(cacheResult, deviceType, connectType, btAddress);
52
      }, [KEY_DEVICE_BRAND_TYPE, KEY_DEVICE_CONNECT_TYPE, KEY_DEVICE_BT_ADDRESS]);
79 53
    },
80 54
81
    /**
82
     * 读取SIm蓝牙设备连接配置
83
     *
84
     * @param {function} callback 回调函数
85
     * @param {Object} callback.obj 后面三个参数及值组成的json对象
86
     * @param {string} callback.deviceType 设备类型
87
     * @param {string} callback.connectType 连接类型
88
     * @param {string} callback.btnAddress 设备蓝牙地址,
89
     */
90
    getSimReaderConfig: function (callback) {
91
      // 如需使用js内存缓存,可优化此方法,取一次后缓存起来,不用每次读取缓存
92
      this.getCache(function (cacheResult) {  // deviceType, connectType存储在缓存,不直接通过调用传递参数
93
        cacheResult = JSON.parse(cacheResult);
94
        var deviceType = cacheResult[KEY_SIM_DEVICE_TYPE];
95
        var connectType = cacheResult[KEY_SIM_CONNECT_TYPE];
96
        var btnAddress = cacheResult[KEY_SIM_BT_ADDRESS];
97
        callback(cacheResult, deviceType, connectType, btnAddress);
98
      }, [KEY_SIM_DEVICE_TYPE, KEY_SIM_CONNECT_TYPE, KEY_SIM_BT_ADDRESS]);
99
    },
100 55
101 56
    /**
102 57
     * 获取蓝牙设备地址
@ -215,7 +170,7 @@
215 170
     * @param {string} timeStamp 时间戳
216 171
     */
217 172
    getCardAndUp: function (callbackKey, isTakePicture, opId, timeStamp) {
218
      this.getIdReaderConfig(function (obj, deviceType, connectType) {
173
      this.getDeviceConfig(function (obj, deviceType, connectType) {
219 174
        IpuMobile.getCardAndUp(function (result) { // IPU插件不直接返回json对象,只返回json字符串
220 175
          result = JSON.parse(result);
221 176
          if (result.code && !result.errorCode) { // 客户端返回的字段是code,项目使用字段是errorCode
@ -258,7 +213,7 @@
258 213
        }
259 214
      }
260 215
261
      this.getSimReaderConfig(function (obj, deviceType, connectType, btnAddress) {
216
      this.getDeviceConfig(function (obj, deviceType, connectType, btnAddress) {
262 217
        count++;  // 调一次插件,计数加1
263 218
        IpuMobile.getCardSN(function (result) {
264 219
          count--;
@ -282,7 +237,7 @@
282 237
     * @param {string} callback.result 空卡序列号
283 238
     */
284 239
    getCardSN: function (callback) {
285
      this.getSimReaderConfig(function (obj, deviceType, connectType, btnAddress) {
240
      this.getDeviceConfig(function (obj, deviceType, connectType, btnAddress) {
286 241
        IpuMobile.getCardSN(function (result) {
287 242
          callback(SIM_SUCCESS_PREFIX + result);
288 243
        }, deviceType, connectType, {btnAddress: btnAddress});
@ -296,7 +251,7 @@
296 251
     * @param {string} callback.result ICCID信息
297 252
     */
298 253
    getICCID: function (callback) {
299
      this.getSimReaderConfig(function (obj, deviceType, connectType, btnAddress) {
254
      this.getDeviceConfig(function (obj, deviceType, connectType, btnAddress) {
300 255
        IpuMobile.getICCID(function (result) {
301 256
          callback(SIM_SUCCESS_PREFIX + result);
302 257
        }, deviceType, connectType, {btnAddress: btnAddress});
@ -310,7 +265,7 @@
310 265
     * @param {string} callback.result IMSI信息
311 266
     */
312 267
    getIMSI: function (callback) {
313
      this.getSimReaderConfig(function (obj, deviceType, connectType, btnAddress) {
268
      this.getDeviceConfig(function (obj, deviceType, connectType, btnAddress) {
314 269
        IpuMobile.getIMSI(function (result) {
315 270
          callback(SIM_SUCCESS_PREFIX + result);
316 271
        }, deviceType, connectType, {btnAddress: btnAddress});
@ -325,7 +280,7 @@
325 280
     * @param {string} callback.result 回调函数参数,
326 281
     */
327 282
    isEmptyCard: function (callback) {
328
      this.getSimReaderConfig(function (obj, deviceType, connectType, btnAddress) {
283
      this.getDeviceConfig(function (obj, deviceType, connectType, btnAddress) {
329 284
        IpuMobile.isEmptyCard(function (result) {
330 285
          callback(SIM_SUCCESS_PREFIX + result);
331 286
        }, deviceType, connectType, {btnAddress: btnAddress});
@ -339,7 +294,7 @@
339 294
     * @param {function} callback 回调函数
340 295
     */
341 296
    writeSIM: function (data, callback) {
342
      this.getSimReaderConfig(function (obj, deviceType, connectType, btnAddress) {
297
      this.getDeviceConfig(function (obj, deviceType, connectType, btnAddress) {
343 298
        IpuMobile.writeSIM(function (result) {
344 299
          callback(SIM_SUCCESS_PREFIX + result);
345 300
        }, deviceType, connectType, {btnAddress: btnAddress});