hrsass-native-mobile 1.1.2 → 1.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,11 +10,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
10
10
 
11
11
  var uuid = require('uuid');
12
12
 
13
+ var cookiePrefix = 'NATIVE_LOGIN_';
14
+
13
15
  /**
14
- * 钉钉核心API
15
- * @author john.gao
16
+ * 地址栏参数
17
+ * @param {string} name 参数名称
16
18
  */
17
-
18
19
  var getQueryString = function getQueryString(name) {
19
20
  var result = null;
20
21
  var url = location.hash ? location.hash.indexOf('?') !== -1 ? '?' + location.hash.split('?')[1] : location.hash : location.search;
@@ -32,31 +33,101 @@ var getQueryString = function getQueryString(name) {
32
33
  return result;
33
34
  };
34
35
 
35
- var configUrl = 'dingding/getsign/'; //获取钉钉配置参数
36
- var checkUrl = 'dingding/checklogin/'; //检查是否可以自动登录
37
- var corpId = getQueryString('corpid');
36
+ /**
37
+ * 获取cookie
38
+ */
39
+ var getCookie = function getCookie(name) {
40
+ var arr,
41
+ reg = new RegExp('(^| )' + cookiePrefix + name + '=([^;]*)(;|$)');
42
+ if (arr = document.cookie.match(reg)) {
43
+ var result = null;
44
+ try {
45
+ result = decodeURIComponent(arr[2]);
46
+ } catch (e) {
47
+ result = arr[2];
48
+ }
49
+ try {
50
+ result = JSON.parse(result);
51
+ } catch (e) {}
52
+ return result;
53
+ } else return null;
54
+ };
55
+
56
+ /**
57
+ * 设置cookie
58
+ */
59
+ var setCookie = function setCookie(name, value, seconds) {
60
+ seconds = seconds || 0;
61
+ var expires = "";
62
+ if (seconds != 0) {
63
+ //设置cookie时间
64
+ var date = new Date();
65
+ date.setTime(date.getTime() + seconds * 1000);
66
+ expires = "; expires=" + date.toGMTString();
67
+ }
68
+ document.cookie = cookiePrefix + name + "=" + escape(value) + expires + "; path=/";
69
+ };
70
+
71
+ /**
72
+ * 钉钉核心API
73
+ * edit by
74
+ * @author john.gao
75
+ */
38
76
 
39
77
  var DdCore = {
40
78
  url: '', //接口前缀
79
+ /**
80
+ * 获取Customer Code
81
+ */
82
+ getCustomerCode: function getCustomerCode() {
83
+ return getCookie('customerCode');
84
+ },
85
+
86
+ /**
87
+ * 获取code
88
+ */
89
+ getCode: function getCode() {
90
+ return getCookie('code');
91
+ },
92
+
93
+ /**
94
+ * 获取corpid
95
+ */
96
+ getCoprId: function getCoprId() {
97
+ return getCookie('corpid');
98
+ },
99
+
100
+ /**
101
+ * 获取openId
102
+ */
103
+ getOpenId: function getOpenId() {
104
+ return getCookie('openId');
105
+ },
106
+
41
107
  /**
42
108
  * 判断钉钉是否可以免密登录
43
109
  * @param callback 回调函数
44
110
  */
45
- isAutoLogin: function isAutoLogin(json) {
111
+ isAutoLogin: function isAutoLogin(callback) {
46
112
  var _this = this;
47
113
 
48
- this.url = json.url;
49
- var callback = json.callback;
50
- this.getConfig().then(function (res) {
51
- _this.getAuthCode(res.response, function (resCode) {
52
- _this.checkAutoLogin(false, resCode.code).then(function (resLogin) {
53
- if (resLogin.success) {
54
- callback(resLogin.response);
55
- } else {
56
- callback({});
57
- }
58
- });
114
+ var customerCode = getQueryString('customerCode');
115
+ if (customerCode) {
116
+ setCookie('customerCode', customerCode);
117
+ }
118
+ var code = getQueryString('code');
119
+ if (code) {
120
+ setCookie('code', code);
121
+ }
122
+
123
+ this.getConfig(function (res) {
124
+ //暂时没有企业需要定位
125
+ // this.getAuthCode(res, (resCode) => {
126
+ // console.log('getAuthCode', resCode);
127
+ _this.checkAutoLogin(function (resLogin) {
128
+ callback(resLogin);
59
129
  });
130
+ // })
60
131
  });
61
132
  },
62
133
 
@@ -64,11 +135,14 @@ var DdCore = {
64
135
  /**
65
136
  * 第一步,向自身服务器请求获取配置参数
66
137
  */
67
- getConfig: function getConfig() {
68
- return axios.request(this.url, '' + configUrl + corpId, {
69
- hideError: true,
70
- type: 'get',
71
- params: {}
138
+ getConfig: function getConfig(callback) {
139
+ var param = {
140
+ type: '4',
141
+ url: location.href.split('#')[0]
142
+ };
143
+ param.customerCode = this.getCustomerCode();
144
+ axios.post('/platform/wechat/wechatSign.nolog', param).then(function (data) {
145
+ callback && callback(data);
72
146
  });
73
147
  },
74
148
 
@@ -80,9 +154,9 @@ var DdCore = {
80
154
  */
81
155
  getAuthCode: function getAuthCode(res, callback) {
82
156
  dd.config({
83
- agentId: res.agentId,
84
- corpId: corpId,
85
- timeStamp: res.timeStamp,
157
+ agentId: res.appId,
158
+ corpId: res.corpId,
159
+ timeStamp: res.timestamp,
86
160
  nonceStr: res.nonceStr,
87
161
  signature: res.signature,
88
162
  jsApiList: ['device.base.getUUID', 'device.base.getInterface', 'device.geolocation.get', 'runtime.info', 'biz.contact.choose', 'device.notification.confirm', 'device.notification.alert', 'device.notification.prompt', 'biz.ding.post', 'biz.util.openLink']
@@ -92,7 +166,7 @@ var DdCore = {
92
166
  corpId: corpId,
93
167
  onSuccess: callback,
94
168
  onFail: function onFail(err) {
95
- console.log(err);
169
+ callback();
96
170
  }
97
171
  });
98
172
  });
@@ -108,13 +182,16 @@ var DdCore = {
108
182
  * @param flag true:缓存存在userid
109
183
  * @param userId_Code 企业id或者授权码
110
184
  */
111
- checkAutoLogin: function checkAutoLogin(flag, userId_Code) {
112
- var type = flag ? 'dduserid/' : 'authcode/';
113
- return axios.request(this.url, '' + checkUrl + type + corpId + '/' + userId_Code, {
114
- type: 'get',
115
- params: {
116
- noToken: true
185
+ checkAutoLogin: function checkAutoLogin(callback) {
186
+ var param = { type: '4' };
187
+ param.code = this.getCode();
188
+ param.customerCode = this.getCustomerCode();
189
+ axios.post('/platform/wechat/wechatCheckLogin.nolog', param).then(function (res) {
190
+ console.log('wechatCheckLogin.nolog', res);
191
+ if (res && res.user && res.user.openId) {
192
+ setCookie('openId', res.user.openId);
117
193
  }
194
+ callback(res);
118
195
  });
119
196
  },
120
197
 
@@ -140,6 +217,21 @@ var DdCore = {
140
217
  });
141
218
  },
142
219
 
220
+ /**
221
+ * 退出
222
+ */
223
+ logOut: function logOut(callback) {
224
+ var param = {
225
+ openId: this.getOpenId(),
226
+ type: '4',
227
+ customerCode: this.getCustomerCode()
228
+ };
229
+ var loginOutUrl = '/platform/wechat/wechatLogOut.nolog';
230
+ axios.post(loginOutUrl, param).then(function (res) {
231
+ callback && callback(res);
232
+ });
233
+ },
234
+
143
235
 
144
236
  /**
145
237
  * 获取热点信息
@@ -186,10 +278,11 @@ var DdUI = {
186
278
  dd.biz.navigation.setTitle({
187
279
  title: title
188
280
  });
189
- var setText = $.i18n["my_setTitle"],
190
- searchText = $.i18n["search"],
191
- rightText = "",
192
- isShow = false;
281
+ // let setText = $.i18n["my_setTitle"],
282
+ // searchText = $.i18n["search"],
283
+ // toRoute = "",
284
+ // rightText = "",
285
+ // isShow = false;
193
286
  // switch (pageObj.route) {
194
287
  // case "work/work":
195
288
  // rightText = setText;
@@ -205,14 +298,14 @@ var DdUI = {
205
298
  // isShow = false;
206
299
  // break;
207
300
  // }
208
- dd.biz.navigation.setRight({
209
- show: isShow,
210
- control: true,
211
- text: rightText,
212
- onSuccess: function onSuccess(result) {
213
- // history.push(targetRoute);
214
- }
215
- });
301
+ // dd.biz.navigation.setRight({
302
+ // show: isShow,
303
+ // control: true,
304
+ // text: rightText,
305
+ // onSuccess: (result) => {
306
+ // // history.push(targetRoute);
307
+ // }
308
+ // })
216
309
  },
217
310
 
218
311
 
@@ -250,36 +343,6 @@ var DdUI = {
250
343
  }
251
344
  };
252
345
 
253
- /**
254
- * 判断是否为空对象
255
- * @param {Object} obj 对象
256
- * @return {Boolean} true or false
257
- */
258
- var isEmptyObject = function isEmptyObject(obj) {
259
- return obj === undefined || obj === null || Object.keys(obj).length === 0 ? true : false;
260
- };
261
-
262
- /**
263
- * 地址栏参数
264
- * @param {string} name 参数名称
265
- */
266
- var getQueryString$1 = function getQueryString(name) {
267
- var result = null;
268
- var url = location.hash ? location.hash.indexOf('?') !== -1 ? '?' + location.hash.split('?')[1] : location.hash : location.search;
269
- url = decodeURIComponent(url);
270
- if (url.indexOf("?") != -1) {
271
- var str = url.substr(1);
272
- var strArr = str.split("&");
273
- for (var i = 0; i < strArr.length; i++) {
274
- if (strArr[i].split("=")[0] == name) {
275
- result = unescape(strArr[i].split("=")[1]);
276
- break;
277
- }
278
- }
279
- }
280
- return result;
281
- };
282
-
283
346
  var _extends = Object.assign || function (target) {
284
347
  for (var i = 1; i < arguments.length; i++) {
285
348
  var source = arguments[i];
@@ -297,42 +360,8 @@ var _extends = Object.assign || function (target) {
297
360
  /**
298
361
  * 微信API
299
362
  * @author john.gao
363
+ * edit by david on 2020/12/18
300
364
  */
301
- var cookiePrefix = 'LOGIN_WECHAT_';
302
- /**
303
- * 获取cookie
304
- */
305
- function getCookie(name) {
306
- var arr,
307
- reg = new RegExp('(^| )' + cookiePrefix + name + '=([^;]*)(;|$)');
308
- if (arr = document.cookie.match(reg)) {
309
- var result = null;
310
- try {
311
- result = decodeURIComponent(arr[2]);
312
- } catch (e) {
313
- result = arr[2];
314
- }
315
- try {
316
- result = JSON.parse(result);
317
- } catch (e) {}
318
- return result;
319
- } else return null;
320
- }
321
-
322
- /**
323
- * 设置cookie
324
- */
325
- function setCookie(name, value, seconds) {
326
- seconds = seconds || 0;
327
- var expires = "";
328
- if (seconds != 0) {
329
- //设置cookie时间
330
- var date = new Date();
331
- date.setTime(date.getTime() + seconds * 1000);
332
- expires = "; expires=" + date.toGMTString();
333
- }
334
- document.cookie = cookiePrefix + name + "=" + escape(value) + expires + "; path=/";
335
- }
336
365
 
337
366
  var WeCore = {
338
367
  url: '', //接口前缀
@@ -342,25 +371,25 @@ var WeCore = {
342
371
  * @param callback 回调函数
343
372
  */
344
373
  isAutoLogin: function isAutoLogin(callback) {
345
- var _this = this;
374
+ var _this2 = this;
346
375
 
347
- var wechatType = getQueryString$1('type');
376
+ var wechatType = getQueryString('type');
348
377
  if (wechatType === '2') {
349
378
  //企业微信
350
379
  setCookie('wechatType', 'corp');
351
380
  }
352
- var customerCode = getQueryString$1('customerCode');
381
+ var customerCode = getQueryString('customerCode');
353
382
  if (customerCode) {
354
383
  setCookie('customerCode', customerCode);
355
384
  }
356
- var openId = getQueryString$1('code');
357
- if (openId) {
358
- setCookie('code', openId);
385
+ var code = getQueryString('code');
386
+ if (code) {
387
+ setCookie('code', code);
359
388
  }
360
389
 
361
390
  this.getSign(function (configRes) {
362
- _this.setConfig(configRes, function () {
363
- _this.checkAutoLogin(callback);
391
+ _this2.setConfig(_extends({}, configRes, { jsApiList: ['onHistoryBack', 'closeWindow'] }), function () {
392
+ _this2.checkAutoLogin(callback, configRes);
364
393
  });
365
394
  });
366
395
  },
@@ -398,8 +427,13 @@ var WeCore = {
398
427
  * 向自身服务器请求获取配置参数
399
428
  */
400
429
  getSign: function getSign(callback) {
430
+ if ('android' === this.getOS() || 'corp' === this.getWechatType()) {
431
+ this.initUrl = location.href.split('#')[0];
432
+ } else {
433
+ !this.initUrl && (this.initUrl = location.href.split('#')[0]);
434
+ }
401
435
  var param = {
402
- url: location.href.split('#')[0]
436
+ url: this.initUrl
403
437
  };
404
438
  var wechatType = this.getWechatType();
405
439
  var configUrl = '/platform/wechat/wechatSign.nolog';
@@ -412,6 +446,15 @@ var WeCore = {
412
446
  }
413
447
  });
414
448
  },
449
+ initPermission: function initPermission(callback) {
450
+ var _this3 = this;
451
+
452
+ this.getSign(function (configRes) {
453
+ _this3.setConfig(configRes, function () {
454
+ callback && callback();
455
+ });
456
+ });
457
+ },
415
458
  setConfig: function setConfig(data, callback) {
416
459
  wx.config({
417
460
  // beta: true, //变化url的SPA
@@ -420,7 +463,7 @@ var WeCore = {
420
463
  timestamp: data.timestamp,
421
464
  nonceStr: data.nonceStr,
422
465
  signature: data.signature,
423
- jsApiList: data.jsApiList || ['getLocation', 'openBluetoothAdapter', 'closeBluetoothAdapter', 'startBeaconDiscovery', 'stopBeaconDiscovery', 'onBeaconUpdate', 'onHistoryBack', 'closeWindow']
466
+ jsApiList: data.jsApiList || ['getLocation', 'openBluetoothAdapter', 'closeBluetoothAdapter', 'startBeaconDiscovery', 'stopBeaconDiscovery', 'onBeaconUpdate', 'onHistoryBack', 'closeWindow', 'getBeacons']
424
467
  });
425
468
  wx.ready(function () {
426
469
  setTimeout(function () {
@@ -433,13 +476,17 @@ var WeCore = {
433
476
  /**
434
477
  * 第三步:判断是否可以免密登录
435
478
  */
436
- checkAutoLogin: function checkAutoLogin(callback) {
479
+ checkAutoLogin: function checkAutoLogin(callback, configRes) {
437
480
  var param = { code: this.getWechatCode() };
481
+ var mobile = getQueryString('mobile');
438
482
  var checkUrl = '/platform/wechat/wechatCheckLogin.nolog';
439
483
  var wechatType = this.getWechatType();
440
484
 
441
485
  param.customerCode = this.getCustomerCode();
442
486
  param.type = wechatType === 'corp' ? '2' : '1';
487
+ if (mobile) {
488
+ param.mobile = mobile;
489
+ }
443
490
  axios.post(checkUrl, param).then(function (res) {
444
491
  if (res && res.user && res.user.openId) {
445
492
  setCookie('openId', res.user.openId);
@@ -470,33 +517,44 @@ var WeCore = {
470
517
  },
471
518
 
472
519
 
520
+ previewFile: function previewFile(opt, callback) {
521
+ var _this4 = this;
522
+
523
+ if ('corp' === this.getWechatType()) {
524
+ this.getSign(function (config) {
525
+ _this4.setConfig(config, function () {
526
+ wx.previewFile(opt);
527
+ });
528
+ });
529
+ callback({ hasError: false });
530
+ } else {
531
+ callback({ hasError: true, msg: '暂不支持预览' });
532
+ }
533
+ },
534
+
473
535
  /**
474
536
  * 获取GPS定位
475
537
  * @param callback
476
538
  */
477
539
  getGPS: function getGPS(callback) {
478
- var _this2 = this;
540
+ var _this5 = this;
479
541
 
480
542
  this.getSign(function (configRes) {
481
- 'android' === _this2.getOS() || 'corp' === _this2.getWechatType() ? _this2.setConfig(configRes, function () {
543
+ //2020-12-11 全部走config
544
+ var type = _this5.getWechatType();
545
+ _this5.setConfig(configRes, function () {
482
546
  wx.getLocation({
483
547
  type: 'gcj02',
484
548
  success: function success(res) {
485
549
  callback && callback(res);
486
550
  },
487
- fail: function fail() {
551
+ fail: function fail(res) {
552
+ Native.log(res && res.errMsg, { method: 'wx.getLocation', type: type });
553
+ console.log('GPS fail', res);
488
554
  callback && callback(null);
489
555
  }
490
556
  });
491
- }) : wx.getLocation({
492
- type: 'gcj02',
493
- success: function success(res) {
494
- callback && callback(res);
495
- },
496
- fail: function fail() {
497
- callback && callback(null);
498
- }
499
- });
557
+ }) ;
500
558
  });
501
559
  },
502
560
  openBluetoothAdapter: function openBluetoothAdapter(callback) {
@@ -511,8 +569,8 @@ var WeCore = {
511
569
  });
512
570
  },
513
571
  getWifi: function getWifi(callback) {
514
- var wechatType = this.getWechatType();
515
- if (wechatType === 'corp') {
572
+ var type = this.getWechatType();
573
+ if (type === 'corp') {
516
574
  var self = this;
517
575
  self.getSign(function (configRes) {
518
576
  configRes.jsApiList = ['startWifi', 'getConnectedWifi'];
@@ -526,12 +584,14 @@ var WeCore = {
526
584
  callback(res.wifi);
527
585
  },
528
586
  fail: function fail(res) {
587
+ Native.log(res && res.errMsg, { method: 'wx.getConnectedWifi', type: type });
529
588
  console.log('getConnectedWifi fail', res);
530
589
  callback({});
531
590
  }
532
591
  });
533
592
  },
534
593
  fail: function fail(res) {
594
+ Native.log(res && res.errMsg, { method: 'wx.startWifi', type: type });
535
595
  console.log('startWifi fail', res);
536
596
  callback({});
537
597
  }
@@ -567,42 +627,41 @@ var WeCore = {
567
627
 
568
628
 
569
629
  /**
570
- *
571
- * @param {Object}} self this指向
572
- * @param {Number} timeout 超时时间
630
+ *
631
+ * @param {Object}} self this指向
632
+ * @param {Number} timeout 超时时间
573
633
  */
574
634
  setBluetoothTimeout: function setBluetoothTimeout(self, params, callback) {
575
- var _this3 = this;
576
-
577
635
  if (!self.bluetoothTimeout) {
578
636
  self.bluetoothTimeout = setTimeout(function () {
579
637
  if (!self.isBluetoothStoped) {
580
638
  wx.stopBeaconDiscovery({
581
639
  complete: function complete() {
582
640
  // if (this.getOS() === 'android') {
583
- var loadCount = params.loadCount || 5;
584
- if (self.getBluetoothCount == loadCount) {
641
+ var loadCount = params.loadCount || 3;
642
+ if (self.getBluetoothCount >= loadCount) {
643
+ self.destoryBlutooth(self);
585
644
  callback({
586
645
  success: false,
587
646
  error: '蓝牙获取失败'
588
647
  });
589
- self.destoryBlutooth(self);
590
- // } else {
591
- // self.destoryBlutooth(self, ()=>{
592
- // self.getWechatBluetooth(self, params, callback);
593
- // })
594
- // }
595
648
  } else {
596
- callback({
597
- success: false,
598
- error: '蓝牙获取失败'
649
+ self.destoryBlutooth(self, function () {
650
+ self.getWechatBluetooth(self, params, callback);
599
651
  });
600
- self.destoryBlutooth(self);
601
652
  }
653
+ // }
654
+ // else {
655
+ // callback({
656
+ // success: false,
657
+ // error: '蓝牙获取失败'
658
+ // })
659
+ // self.destoryBlutooth(self);
660
+ // }
602
661
  }
603
662
  });
604
663
  }
605
- if (_this3.bluetoothTimeout) {
664
+ if (self.bluetoothTimeout) {
606
665
  clearTimeout(self.bluetoothTimeout);
607
666
  self.bluetoothTimeout = null;
608
667
  }
@@ -615,14 +674,15 @@ var WeCore = {
615
674
  * 企业微信: 获取蓝牙设备列表
616
675
  */
617
676
  getBluetooth: function getBluetooth(params, callback) {
618
- var _this4 = this;
677
+ var _this6 = this;
619
678
 
620
679
  var wechatType = this.getWechatType();
621
680
  if (wechatType === 'corp') {
622
681
  this.getBluetoothCount = 0;
623
682
  this.getSign(function (config) {
624
- _this4.setConfig(config, function () {
625
- _this4.getWechatBluetooth(_this4, params, callback);
683
+ _this6.setConfig(config, function () {
684
+ console.log('load Bluetooth');
685
+ _this6.getWechatBluetooth2(_this6, params, callback);
626
686
  });
627
687
  });
628
688
  } else {
@@ -630,6 +690,57 @@ var WeCore = {
630
690
  }
631
691
  },
632
692
 
693
+ getBeacons: function getBeacons(count, param, callback) {
694
+ if (count < 1) {
695
+ callback({ success: !1 });
696
+ return;
697
+ }
698
+ var _this = this;
699
+ setTimeout(function () {
700
+ wx.getBeacons({
701
+ success: function success(e) {
702
+ console.log('getBeacons success', e);
703
+ var beacons = e.beacons;
704
+ var r = beacons.find(function (item, index) {
705
+ var id = item.uuid.toLowerCase();
706
+ return param.uuids.indexOf(id) > -1;
707
+ });
708
+ if (!r) {
709
+ _this.getBeacons(--count, param, callback);
710
+ return;
711
+ }
712
+ callback({ success: true, list: [r] });
713
+ },
714
+ fail: function fail(res) {
715
+ Native.log(res && res.errMsg, { method: 'wx.getBeacons', type: _this.getWechatType() });
716
+ console.log('getBeacons fail', res), _this.getBeacons(--count, param, callback);
717
+ }
718
+ });
719
+ }, count === param.loadCount ? 0 : param.timeout || 1000);
720
+ },
721
+ getWechatBluetooth2: function getWechatBluetooth2(_this, param, callback) {
722
+ console.log('param', param);
723
+ wx.startBeaconDiscovery({
724
+ uuids: param.uuids,
725
+ success: function success(res) {
726
+ console.log('startBeaconDiscovery success');
727
+ _this.getBeacons(param.loadCount, param, function (result) {
728
+ wx.stopBeaconDiscovery({
729
+ complete: function complete(res) {
730
+ console.log('stopBeaconDiscovery', res);
731
+ console.log(result);
732
+ callback(result);
733
+ }
734
+ });
735
+ });
736
+ },
737
+ fail: function fail(res) {
738
+ Native.log(res && res.errMsg, { method: 'wx.startBeaconDiscovery', type: _this.getWechatType() });
739
+ console.log('startBeaconDiscovery fail', res);
740
+ callback({ success: false });
741
+ }
742
+ });
743
+ },
633
744
 
634
745
  /**
635
746
  * 获取蓝牙
@@ -674,12 +785,14 @@ var WeCore = {
674
785
  complete: function complete() {
675
786
  self.setBluetoothTimeout(self, params, callback);
676
787
  },
677
- fail: function fail(errMsg) {
788
+ fail: function fail(res) {
789
+ Native.log(res && res.errMsg, { method: 'wx.startBeaconDiscovery', type: self.getWechatType() });
790
+ console.log('startBeaconDiscovery fail', res);
678
791
  wx.stopBeaconDiscovery({
679
792
  complete: function complete() {
680
793
  callback({
681
794
  success: false,
682
- error: errMsg
795
+ error: res
683
796
  });
684
797
  self.destoryBlutooth(self);
685
798
  }
@@ -715,41 +828,6 @@ var WeCore = {
715
828
  * 蓝信API
716
829
  * @author Groot.xie
717
830
  */
718
- var cookiePrefix$1 = 'LOGIN_LANXIN_';
719
- /**
720
- * 获取cookie
721
- */
722
- function getCookie$1(name) {
723
- var arr,
724
- reg = new RegExp('(^| )' + cookiePrefix$1 + name + '=([^;]*)(;|$)');
725
- if (arr = document.cookie.match(reg)) {
726
- var result = null;
727
- try {
728
- result = decodeURIComponent(arr[2]);
729
- } catch (e) {
730
- result = arr[2];
731
- }
732
- try {
733
- result = JSON.parse(result);
734
- } catch (e) {}
735
- return result;
736
- } else return null;
737
- }
738
-
739
- /**
740
- * 设置cookie
741
- */
742
- function setCookie$1(name, value, seconds) {
743
- seconds = seconds || 0;
744
- var expires = "";
745
- if (seconds != 0) {
746
- //设置cookie时间
747
- var date = new Date();
748
- date.setTime(date.getTime() + seconds * 1000);
749
- expires = "; expires=" + date.toGMTString();
750
- }
751
- document.cookie = cookiePrefix$1 + name + "=" + escape(value) + expires + "; path=/";
752
- }
753
831
 
754
832
  var LxCore = {
755
833
  url: '', //接口前缀
@@ -758,13 +836,13 @@ var LxCore = {
758
836
  * @param callback 回调函数
759
837
  */
760
838
  isAutoLogin: function isAutoLogin(callback) {
761
- var customerCode = getQueryString$1('customerCode');
762
- var openId = getQueryString$1('code');
839
+ var customerCode = getQueryString('customerCode');
840
+ var code = getQueryString('code');
763
841
  if (customerCode) {
764
- setCookie$1('customerCode', customerCode);
842
+ setCookie('customerCode', customerCode);
765
843
  }
766
- if (openId) {
767
- setCookie$1('code', openId);
844
+ if (code) {
845
+ setCookie('code', code);
768
846
  }
769
847
 
770
848
  this.checkAutoLogin(callback);
@@ -781,7 +859,7 @@ var LxCore = {
781
859
 
782
860
  axios.post(checkUrl, param).then(function (res) {
783
861
  if (res && res.user && res.user.openId) {
784
- setCookie$1('openId', res.user.openId);
862
+ setCookie('openId', res.user.openId);
785
863
  }
786
864
  callback(res);
787
865
  });
@@ -830,17 +908,17 @@ var LxCore = {
830
908
 
831
909
  // 获取CustomerCode
832
910
  getCustomerCode: function getCustomerCode() {
833
- return getQueryString$1('customerCode') || getCookie$1('customerCode');
911
+ return getQueryString('customerCode') || getCookie('customerCode');
834
912
  },
835
913
 
836
914
  // 获取code
837
915
  getLanxinCode: function getLanxinCode() {
838
- return getQueryString$1('code') || getCookie$1('code');
916
+ return getQueryString('code') || getCookie('code');
839
917
  },
840
918
 
841
919
  // 获取openId
842
920
  getOpenId: function getOpenId() {
843
- return getCookie$1('openId');
921
+ return getCookie('openId');
844
922
  },
845
923
  getOS: function getOS() {
846
924
  var result = '';
@@ -876,12 +954,15 @@ var MapCore = {
876
954
  map.addControl(geolocation);
877
955
  geolocation.getCurrentPosition();
878
956
  AMap.event.addListener(geolocation, 'complete', function (data) {
957
+ console.log('AMap complete', data);
879
958
  callback && callback({
880
959
  longitude: data.position.getLng(),
881
960
  latitude: data.position.getLat()
882
961
  });
883
962
  });
884
963
  AMap.event.addListener(geolocation, 'error', function (data) {
964
+ console.log('AMap error', data);
965
+ Native.log(data && data.message, { method: 'AMap.Geolocation', type: 'h5' });
885
966
  callback && callback();
886
967
  });
887
968
  });
@@ -891,6 +972,7 @@ var MapCore = {
891
972
  /**
892
973
  * 中间件
893
974
  * @author john.gao
975
+ * edit by david on 2020/12/18
894
976
  */
895
977
 
896
978
  /**
@@ -902,8 +984,12 @@ var getOS = function getOS() {
902
984
  var u = navigator.userAgent;
903
985
  if (u.indexOf('DingTalk') > -1) {
904
986
  result.type = 'dd';
987
+ } else if (u.indexOf('miniProgram') > -1) {
988
+ result.type = 'miniprogram';
905
989
  } else if (u.indexOf('MicroMessenger') > -1) {
906
990
  result.type = 'wechat';
991
+ } else if (u.indexOf('WandaOA') > -1) {
992
+ result.type = 'wanxin';
907
993
  } else if (u.indexOf('Lanxin') > -1) {
908
994
  result.type = 'lanxin';
909
995
  } else if (u.indexOf('Android') > -1 || u.indexOf('Adr') > -1) {
@@ -948,7 +1034,10 @@ var _isNativeIos = function _isNativeIos() {
948
1034
  return isNative;
949
1035
  };
950
1036
 
951
- var Native = {
1037
+ var Native$1 = {
1038
+ getQueryString: getQueryString,
1039
+ getCookie: getCookie,
1040
+ setCookie: setCookie,
952
1041
  /**
953
1042
  * 平台类型
954
1043
  */
@@ -1110,35 +1199,38 @@ var Native = {
1110
1199
  }
1111
1200
  },
1112
1201
 
1202
+ /**
1203
+ * 初始化js权限
1204
+ * @param callback 回调函数
1205
+ */
1206
+ initPermission: function initPermission(callback) {
1207
+ switch (this.OS.type) {
1208
+ case 'wechat':
1209
+ WeCore.initPermission(callback);
1210
+ break;
1211
+ default:
1212
+ callback && callback();
1213
+ break;
1214
+ }
1215
+ },
1216
+
1113
1217
  /**
1114
1218
  * 是否自动登录
1115
1219
  * @param callback 回调函数
1116
1220
  * 回调参数::isLogin true:是自动登录 false 不是自动登录
1117
1221
  */
1118
- isLogin: function isLogin(_callback) {
1119
- var _this = this;
1120
-
1222
+ isLogin: function isLogin(callback) {
1121
1223
  console.warn('this.OS.type:', this.OS.type);
1122
1224
  switch (this.OS.type) {
1123
1225
  case 'dd':
1124
- DdCore.isAutoLogin({
1125
- url: url,
1126
- callback: function callback(result) {
1127
- if (isEmptyObject(result)) {
1128
- _callback(false);
1129
- } else {
1130
- //保存钉钉的userid
1131
- if (result.dduserid != undefined) _this.setCache('ddUserId', result.dduserid);
1132
- _this.setCache('userLogin', result.userinfo);
1133
- _callback(result.islogin);
1134
- }
1135
- }
1226
+ DdCore.isAutoLogin(function (result) {
1227
+ callback(result);
1136
1228
  });
1137
1229
  break;
1138
1230
  case 'wechat':
1139
1231
  WeCore.isAutoLogin(function (res) {
1140
1232
  //保存微信的openid
1141
- _callback(res);
1233
+ callback(res);
1142
1234
  //todo 循环访问页面问题
1143
1235
  // if (res.error && res.error.code == 300) {
1144
1236
  // location.href = 'https://' + location.host + '/wechat';
@@ -1153,16 +1245,16 @@ var Native = {
1153
1245
  break;
1154
1246
  case 'lanxin':
1155
1247
  LxCore.isAutoLogin(function (res) {
1156
- return _callback(res);
1248
+ return callback(res);
1157
1249
  });
1158
1250
  break;
1159
1251
  case 'android':
1160
1252
  this.getCache('', function (val) {
1161
- _callback(val);
1253
+ callback(val);
1162
1254
  });
1163
1255
  break;
1164
1256
  default:
1165
- _callback({
1257
+ callback({
1166
1258
  user: JSON.parse(this.getCache('userInfo')),
1167
1259
  token: this.getCache('token')
1168
1260
  });
@@ -1175,17 +1267,11 @@ var Native = {
1175
1267
  * @param {Object} history 路由历史
1176
1268
  * @param callback
1177
1269
  */
1178
- exit: function exit(callback, apiUrl) {
1270
+ exit: function exit(callback) {
1271
+ //不需要清除的缓存
1179
1272
  switch (this.OS.type) {
1180
1273
  case 'dd':
1181
- var ddUserId = this.getCache('ddUserId');
1182
- axios.post('/dingding/logout/' + ddUserId, {
1183
- type: 'get',
1184
- params: {}
1185
- }).then(function (res) {
1186
- if (res.success) ;
1187
- callback && callback(res);
1188
- });
1274
+ DdCore.logOut(callback);
1189
1275
  break;
1190
1276
  case 'wechat':
1191
1277
  WeCore.logOut(callback);
@@ -1245,7 +1331,7 @@ var Native = {
1245
1331
  * @returns {Array}
1246
1332
  */
1247
1333
  getValidateList: function getValidateList(type, list, map) {
1248
- var _this2 = this;
1334
+ var _this = this;
1249
1335
 
1250
1336
  var arr = [],
1251
1337
  _map = map ? map : {
@@ -1288,7 +1374,7 @@ var Native = {
1288
1374
  } else {
1289
1375
  arr = list.filter(function (o) {
1290
1376
  if (o.pwd_type == 'finger') {
1291
- return _this2.OS.fingerAllow && o.enable == '1';
1377
+ return _this.OS.fingerAllow && o.enable == '1';
1292
1378
  } else {
1293
1379
  return o.enable == '1';
1294
1380
  }
@@ -1319,25 +1405,34 @@ var Native = {
1319
1405
  * 写日志
1320
1406
  * @param value
1321
1407
  */
1322
- log: function log(path, value) {
1323
- switch (this.OS.type) {
1324
- case 'dd':
1325
- case 'wechat':
1326
- //TODO 如何记录日志
1327
- $.get('./error?value=' + value);
1328
- break;
1329
- case 'android':
1330
- case 'ios':
1331
- this.callNative({
1332
- method: 'log',
1333
- path: path,
1334
- value: value
1335
- });
1336
- break;
1337
- default:
1338
- $.get('./error?value=' + value);
1339
- break;
1340
- }
1408
+ log: function log(message) {
1409
+ var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1410
+
1411
+ window.PerformanceAddError && window.PerformanceAddError({
1412
+ msg: message || '',
1413
+ n: 'native',
1414
+ method: opt.type || this.OS.type,
1415
+ sendData: opt.sendData,
1416
+ resourceUrl: opt.method
1417
+ });
1418
+ // switch (this.OS.type) {
1419
+ // case 'dd':
1420
+ // case 'wechat':
1421
+ // //TODO 如何记录日志
1422
+ // $.get(`./error?value=${value}`)
1423
+ // break;
1424
+ // case 'android':
1425
+ // case 'ios':
1426
+ // this.callNative({
1427
+ // method: 'log',
1428
+ // path: path,
1429
+ // value: value
1430
+ // })
1431
+ // break;
1432
+ // default:
1433
+ // $.get(`./error?value=${value}`)
1434
+ // break;
1435
+ // }
1341
1436
  },
1342
1437
  getSystemInfo: function getSystemInfo(callback) {
1343
1438
  var json = {
@@ -1346,12 +1441,7 @@ var Native = {
1346
1441
  };
1347
1442
  switch (this.OS.type) {
1348
1443
  case 'dd':
1349
- DdCore.getUUID(function (result) {
1350
- if (result) {
1351
- json.device = result.uuid;
1352
- }
1353
- callback && callback(json);
1354
- });
1444
+ callback && callback(json);
1355
1445
  break;
1356
1446
  case 'wechat':
1357
1447
  var openId = this.getCache('openId');
@@ -1376,6 +1466,21 @@ var Native = {
1376
1466
  },
1377
1467
 
1378
1468
 
1469
+ /**
1470
+ * 文件预览
1471
+ */
1472
+ previewFile: function previewFile(opt, callback) {
1473
+ switch (this.OS.type) {
1474
+ case 'wechat':
1475
+ WeCore.previewFile(opt, callback);
1476
+ break;
1477
+ default:
1478
+ callback({ hasError: true, msg: '暂不支持预览' });
1479
+ break;
1480
+ }
1481
+ },
1482
+
1483
+
1379
1484
  /**
1380
1485
  * 获取GPS定位
1381
1486
  */
@@ -1383,7 +1488,8 @@ var Native = {
1383
1488
  var opts = Object.assign({}, {
1384
1489
  method: 'getGPS'
1385
1490
  }, params);
1386
- switch (this.OS.type) {
1491
+ var type = params.type || this.OS.type;
1492
+ switch (type) {
1387
1493
  case 'dd':
1388
1494
  var recode = params.recode;
1389
1495
  DdCore.getGPS(recode, function (res) {
@@ -1542,7 +1648,7 @@ var Native = {
1542
1648
  };
1543
1649
 
1544
1650
  if (window.Native === undefined) {
1545
- window.Native = Native;
1651
+ window.Native = Native$1;
1546
1652
  }
1547
1653
 
1548
1654
  var index = window.Native;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var uuid=require("uuid"),getQueryString=function(e){var t=null,o=location.hash?-1!==location.hash.indexOf("?")?"?"+location.hash.split("?")[1]:location.hash:location.search;if(-1!=(o=decodeURIComponent(o)).indexOf("?"))for(var n=o.substr(1).split("&"),i=0;i<n.length;i++)if(n[i].split("=")[0]==e){t=unescape(n[i].split("=")[1]);break}return t},configUrl="dingding/getsign/",checkUrl="dingding/checklogin/",corpId=getQueryString("corpid"),DdCore={url:"",isAutoLogin:function(e){var t=this;this.url=e.url;var o=e.callback;this.getConfig().then(function(e){t.getAuthCode(e.response,function(e){t.checkAutoLogin(!1,e.code).then(function(e){e.success?o(e.response):o({})})})})},getConfig:function(){return axios.request(this.url,""+configUrl+corpId,{hideError:!0,type:"get",params:{}})},getAuthCode:function(e,t){dd.config({agentId:e.agentId,corpId:corpId,timeStamp:e.timeStamp,nonceStr:e.nonceStr,signature:e.signature,jsApiList:["device.base.getUUID","device.base.getInterface","device.geolocation.get","runtime.info","biz.contact.choose","device.notification.confirm","device.notification.alert","device.notification.prompt","biz.ding.post","biz.util.openLink"]}),dd.ready(function(){dd.runtime.permission.requestAuthCode({corpId:corpId,onSuccess:t,onFail:function(e){console.log(e)}})}),dd.error(function(e){console.log("dd error: "+JSON.stringify(e))})},checkAutoLogin:function(e,t){var o=e?"dduserid/":"authcode/";return axios.request(this.url,checkUrl+o+corpId+"/"+t,{type:"get",params:{noToken:!0}})},getGPS:function(e,t){dd.ready(function(){dd.device.geolocation.get({targetAccuracy:200,coordinate:1,withReGeocode:e,onSuccess:function(e){t&&t(e)},onFail:function(e){console.log(JSON.stringify(e))}})})},getWiFi:function(t){dd.ready(function(){dd.device.base.getInterface({onSuccess:function(e){t&&t(e)},onFail:function(e){console.log(JSON.stringify(e))}})})},getUUID:function(t){dd.ready(function(){dd.device.base.getUUID({onSuccess:function(e){t&&t(e)},onFail:function(){t&&t()}})})}},DdUI={setTitle:function(e){dd.biz.navigation.setTitle({title:e});$.i18n.my_setTitle,$.i18n.search;dd.biz.navigation.setRight({show:!1,control:!0,text:"",onSuccess:function(){}})},setEvent:function(t){dd.ready(function(){-1<navigator.userAgent.indexOf("Android")?document.addEventListener("backbutton",function(e){e.preventDefault(),t()},!1):dd.biz.navigation.setLeft({show:!0,control:!0,showIcon:!0,onSuccess:function(){t()}})})},close:function(){dd.biz.navigation.close()}},isEmptyObject=function(e){return null==e||0===Object.keys(e).length},getQueryString$1=function(e){var t=null,o=location.hash?-1!==location.hash.indexOf("?")?"?"+location.hash.split("?")[1]:location.hash:location.search;if(-1!=(o=decodeURIComponent(o)).indexOf("?"))for(var n=o.substr(1).split("&"),i=0;i<n.length;i++)if(n[i].split("=")[0]==e){t=unescape(n[i].split("=")[1]);break}return t},_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var n in o)Object.prototype.hasOwnProperty.call(o,n)&&(e[n]=o[n])}return e},cookiePrefix="LOGIN_WECHAT_";function getCookie(e){var t,o=new RegExp("(^| )"+cookiePrefix+e+"=([^;]*)(;|$)");if(t=document.cookie.match(o)){var n=null;try{n=decodeURIComponent(t[2])}catch(e){n=t[2]}try{n=JSON.parse(n)}catch(e){}return n}return null}function setCookie(e,t,o){var n="";if(0!=(o=o||0)){var i=new Date;i.setTime(i.getTime()+1e3*o),n="; expires="+i.toGMTString()}document.cookie=cookiePrefix+e+"="+escape(t)+n+"; path=/"}var WeCore={url:"",isAutoLogin:function(t){var o=this;"2"===getQueryString$1("type")&&setCookie("wechatType","corp");var e=getQueryString$1("customerCode");e&&setCookie("customerCode",e);var n=getQueryString$1("code");n&&setCookie("code",n),this.getSign(function(e){o.setConfig(e,function(){o.checkAutoLogin(t)})})},getCustomerCode:function(){return getCookie("customerCode")},getWechatType:function(){return getCookie("wechatType")},getWechatCode:function(){return getCookie("code")},getOpenId:function(){return getCookie("openId")},getSign:function(t){var e={url:location.href.split("#")[0]},o=this.getWechatType();e.customerCode=this.getCustomerCode(),e.type="corp"===o?"2":"1",axios.post("/platform/wechat/wechatSign.nolog",e).then(function(e){t&&t(e)})},setConfig:function(e,t){wx.config({debug:!!e.debug,appId:e.appId,timestamp:e.timestamp,nonceStr:e.nonceStr,signature:e.signature,jsApiList:e.jsApiList||["getLocation","openBluetoothAdapter","closeBluetoothAdapter","startBeaconDiscovery","stopBeaconDiscovery","onBeaconUpdate","onHistoryBack","closeWindow"]}),wx.ready(function(){setTimeout(function(){t&&t()},100)})},checkAutoLogin:function(t){var e={code:this.getWechatCode()},o=this.getWechatType();e.customerCode=this.getCustomerCode(),e.type="corp"===o?"2":"1",axios.post("/platform/wechat/wechatCheckLogin.nolog",e).then(function(e){e&&e.user&&e.user.openId&&setCookie("openId",e.user.openId),t(e)})},logOut:function(t){var e={openId:this.getOpenId(),type:"corp"===this.getWechatType()?"2":"1",customerCode:this.getCustomerCode()};axios.post("/platform/wechat/wechatLogOut.nolog",e).then(function(e){t&&t(e)})},getOS:function(){var e="",t=navigator.userAgent;return-1<t.indexOf("Android")?e="android":t.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)&&(e="ios"),e},getGPS:function(t){var o=this;this.getSign(function(e){"android"===o.getOS()||"corp"===o.getWechatType()?o.setConfig(e,function(){wx.getLocation({type:"gcj02",success:function(e){t&&t(e)},fail:function(){t&&t(null)}})}):wx.getLocation({type:"gcj02",success:function(e){t&&t(e)},fail:function(){t&&t(null)}})})},openBluetoothAdapter:function(t){wx.openBluetoothAdapter({success:function(e){console.info("openBluetoothAdapter success",e),t(_extends({},e,{isSuccess:!0}))},fail:function(e){t(_extends({},e,{isSuccess:!1}))}})},getWifi:function(t){if("corp"===this.getWechatType()){var o=this;o.getSign(function(e){e.jsApiList=["startWifi","getConnectedWifi"],o.setConfig(e,function(){wx.startWifi({success:function(e){console.info("startWifi success",e),wx.getConnectedWifi({success:function(e){console.log("getConnectedWifi success",e),t(e.wifi)},fail:function(e){console.log("getConnectedWifi fail",e),t({})}})},fail:function(e){console.log("startWifi fail",e),t({})}})})})}else t({})},destoryBlutooth:function(e,t){e.isBluetoothStoped=!0,e.isBluetoothStopping=!1,e.bluetoothTimeout&&(clearTimeout(e.bluetoothTimeout),e.bluetoothTimeout=null),"corp"===this.getWechatType()&&wx.closeBluetoothAdapter({success:function(){t&&t()}})},setBluetoothTimeout:function(e,t,o){var n=this;e.bluetoothTimeout||(e.bluetoothTimeout=setTimeout(function(){e.isBluetoothStoped||wx.stopBeaconDiscovery({complete:function(){t.loadCount;e.getBluetoothCount,o({success:!1,error:"蓝牙获取失败"}),e.destoryBlutooth(e)}}),n.bluetoothTimeout&&(clearTimeout(e.bluetoothTimeout),e.bluetoothTimeout=null)},t.timeout||1e4))},getBluetooth:function(t,o){var n=this;"corp"===this.getWechatType()?(this.getBluetoothCount=0,this.getSign(function(e){n.setConfig(e,function(){n.getWechatBluetooth(n,t,o)})})):o([])},getWechatBluetooth:function(t,o,n){t.openBluetoothAdapter(function(e){console.log("openBluetoothAdapter",e),e.isSuccess?(console.log(t.getBluetoothCount,t.isBluetoothStopping,t.isBluetoothStoped,t.bluetoothTimeout),t.getBluetoothCount++,t.isBluetoothStopping=!1,t.isBluetoothStoped=!1,t.bluetoothTimeout&&(clearTimeout(t.bluetoothTimeout),t.bluetoothTimeout=null),wx.startBeaconDiscovery({uuids:o.uuids,success:function(){t.setBluetoothTimeout(t,o,n),wx.onBeaconUpdate(function(e){console.log("onBeaconUpdate",JSON.stringify(e.beacons)),t.beacons=e.beacons,t.isBluetoothStopping||(t.isBluetoothStopping=!0,wx.stopBeaconDiscovery({complete:function(){n({success:!0,list:t.beacons}),t.destoryBlutooth(t)}}))})},complete:function(){t.setBluetoothTimeout(t,o,n)},fail:function(e){wx.stopBeaconDiscovery({complete:function(){n({success:!1,error:e}),t.destoryBlutooth(t)}})}})):n({success:!1,error:"请开启蓝牙"})})},setEvent:function(e){wx.ready(function(){try{wx.onHistoryBack(function(){return e&&e(),!1})}catch(e){console.warn(e+", 请使用企业微信平台登录")}})},close:function(){wx.closeWindow()}},cookiePrefix$1="LOGIN_LANXIN_";function getCookie$1(e){var t,o=new RegExp("(^| )"+cookiePrefix$1+e+"=([^;]*)(;|$)");if(t=document.cookie.match(o)){var n=null;try{n=decodeURIComponent(t[2])}catch(e){n=t[2]}try{n=JSON.parse(n)}catch(e){}return n}return null}function setCookie$1(e,t,o){var n="";if(0!=(o=o||0)){var i=new Date;i.setTime(i.getTime()+1e3*o),n="; expires="+i.toGMTString()}document.cookie=cookiePrefix$1+e+"="+escape(t)+n+"; path=/"}var LxCore={url:"",isAutoLogin:function(e){var t=getQueryString$1("customerCode"),o=getQueryString$1("code");t&&setCookie$1("customerCode",t),o&&setCookie$1("code",o),this.checkAutoLogin(e)},checkAutoLogin:function(t){var e={code:this.getLanxinCode(),customerCode:this.getCustomerCode(),type:"3"};axios.post("/platform/wechat/wechatCheckLogin.nolog",e).then(function(e){e&&e.user&&e.user.openId&&setCookie$1("openId",e.user.openId),t(e)})},logOut:function(t){var e={openId:this.getOpenId(),customerCode:this.getCustomerCode(),type:"3"};axios.post("/platform/wechat/wechatLogOut.nolog",e).then(function(e){t&&t(e)})},getGPS:function(t){lx.getLocation({type:"gcj02",success:function(e){return t&&t(e)},fail:function(){return t&&t(null)}})},getWifi:function(t){lx.wifiDeviceInfo({success:function(e){return t(e)},fail:function(){return t({})}})},getCustomerCode:function(){return getQueryString$1("customerCode")||getCookie$1("customerCode")},getLanxinCode:function(){return getQueryString$1("code")||getCookie$1("code")},getOpenId:function(){return getCookie$1("openId")},getOS:function(){var e="",t=navigator.userAgent;return-1<t.indexOf("Android")?e="android":t.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)&&(e="ios"),e}},MapCore={getGPS:function(t){var e=void 0,o=void 0;(e=new AMap.Map("")).plugin("AMap.Geolocation",function(){o=new AMap.Geolocation({enableHighAccuracy:!0,timeout:1e4}),e.addControl(o),o.getCurrentPosition(),AMap.event.addListener(o,"complete",function(e){t&&t({longitude:e.position.getLng(),latitude:e.position.getLat()})}),AMap.event.addListener(o,"error",function(e){t&&t()})})}},getOS=function(){var e={},t=navigator.userAgent;return-1<t.indexOf("DingTalk")?e.type="dd":-1<t.indexOf("MicroMessenger")?e.type="wechat":-1<t.indexOf("Lanxin")?e.type="lanxin":-1<t.indexOf("Android")||-1<t.indexOf("Adr")?e.type=_isNativeAndroid()?"android":"h5":t.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)?e.type=_isNativeIos()?"ios":"h5":e.type="windows",e},_isNativeAndroid=function(){var t=!0;try{android.callWithDict(JSON.stringify({method:"test"}))}catch(e){t=!1}return t},_isNativeIos=function(){var t=!0;try{ios.callWithDict({method:"test"})}catch(e){t=!1}return t},Native={OS:getOS(),callbackMap:new Map,isNativeAndroid:function(){return _isNativeAndroid()},isNativeIos:function(){return _isNativeIos()},getNavigation:function(e){var t=1;switch(this.OS.type){case"dd":t=e?3==e?2:e:4;break;default:e&&(t=e)}return t},setDingTalkMenu:function(e,t){switch(this.OS.type){case"dd":DdUI.setEvent(function(){0<=t.indexOf(e.location.pathname)?DdUI.close():e.goBack()});break;case"wechat":"corp"===WeCore.wechatType&&WeCore.setEvent(function(){0<=t.indexOf(e.location.pathname)?WeCore.close():e.goBack()})}},setTitle:function(e){switch(this.OS.type){case"dd":DdUI.setTitle(e)}},getCache:function(e,t){var o="";switch(this.OS.type){case"android":this.callNative({method:"getCache",key:e},function(e){t?t(e):o=e});break;default:o=window.localStorage.getItem(e)}return o},setCache:function(e,t){switch(this.OS.type){case"android":this.callNative({method:"setCache",key:e,value:t});break;default:window.localStorage.setItem(e,t)}},removeCache:function(e){switch(this.OS.type){case"android":this.callNative({method:"removeCache",key:e});break;default:window.localStorage.removeItem(e)}},login:function(e,t){switch(this.OS.type){case"dd":e.dingTalkLogin(t);break;case"wechat":t.wechatType=WeCore.getWechatType(),e.weChatLogin(t);break;case"lanxin":e.lanXinLogin(t);break;default:e.login(t)}},isLogin:function(t){var o=this;switch(console.warn("this.OS.type:",this.OS.type),this.OS.type){case"dd":DdCore.isAutoLogin({url:url,callback:function(e){isEmptyObject(e)?t(!1):(null!=e.dduserid&&o.setCache("ddUserId",e.dduserid),o.setCache("userLogin",e.userinfo),t(e.islogin))}});break;case"wechat":WeCore.isAutoLogin(function(e){t(e)});break;case"lanxin":LxCore.isAutoLogin(function(e){return t(e)});break;case"android":this.getCache("",function(e){t(e)});break;default:t({user:JSON.parse(this.getCache("userInfo")),token:this.getCache("token")})}},exit:function(t){switch(this.OS.type){case"dd":var e=this.getCache("ddUserId");axios.post("/dingding/logout/"+e,{type:"get",params:{}}).then(function(e){e.success,t&&t(e)});break;case"wechat":WeCore.logOut(t);break;case"lanxin":LxCore.logOut(t);break;default:t&&t()}},callNative:function(e,t){var o=uuid.v4(),n={_callback_key_:o};for(var i in"string"==typeof e&&(e={method:e}),e)n[i]=e[i];switch(this.callbackMap.set(o,t),this.OS.type){case"ios":ios.callWithDict(n);break;case"android":android.callWithDict(JSON.stringify(n))}},callFront:function(e,t){var o=JSON.parse(t);this.callbackMap.has(e)&&(this.callbackMap.get(e)(o),this.callbackMap.delete(e))},getValidateList:function(e,t,o){var n=this,i=[],c=o||{num:"密码解锁",hand:"手势解锁",finger:"指纹解锁"};switch(this.OS.type){case"dd":case"android":i=1==e?[{pwd_type:"num",label:c.num},{pwd_type:"hand",label:c.hand}]:t.filter(function(e){return"1"==e.enable&&("hand"==e.pwd_type||"num"==e.pwd_type)});break;case"ios":1==e?(i=[{pwd_type:"num",label:c.num},{pwd_type:"hand",label:c.hand}],this.OS.fingerAllow&&i.push({pwd_type:"finger",label:c.finger})):i=t.filter(function(e){return"finger"==e.pwd_type?n.OS.fingerAllow&&"1"==e.enable:"1"==e.enable});break;default:i=1==e?[{pwd_type:"num",label:c.num},{pwd_type:"hand",label:c.hand}]:t.filter(function(e){return"1"==e.enable&&("hand"==e.pwd_type||"num"==e.pwd_type)})}return i},log:function(e,t){switch(this.OS.type){case"dd":case"wechat":$.get("./error?value="+t);break;case"android":case"ios":this.callNative({method:"log",path:e,value:t});break;default:$.get("./error?value="+t)}},getSystemInfo:function(t){var o={success:!0,device:""};switch(this.OS.type){case"dd":DdCore.getUUID(function(e){e&&(o.device=e.uuid),t&&t(o)});break;case"wechat":var e=this.getCache("openId");o.device=e,t&&t(o);break;case"lanxin":t&&t({device:this.getCache("openId")});break;case"android":case"ios":this.callNative("getSystemInfo",function(e){t&&t(e)});break;default:t&&t(o)}},getGPS:function(e,o){var t=Object.assign({},{method:"getGPS"},e);switch(this.OS.type){case"dd":var n=e.recode;DdCore.getGPS(n,function(e){var t=Object.assign({},{success:!0},e);o&&o(t)});break;case"wechat":WeCore.getGPS(function(e){var t={success:!1};null!=e&&(t=Object.assign({},{success:!0},e)),o&&o(t)});break;case"lanxin":LxCore.getGPS(function(e){var t={success:!1};null!=e&&(t=Object.assign({},{success:!0},e)),o&&o(t)});break;case"android":case"ios":this.callNative(t,function(e){o&&o(e)});break;case"h5":MapCore.getGPS(function(e){var t=Object.assign({},{success:!0},e);o&&o(t)})}},getWiFi:function(i){switch(this.OS.type){case"dd":DdCore.getWiFi(function(e){var t={mac:e.macIp,name:e.ssid};i&&i(t)});break;case"wechat":WeCore.getWifi(function(e){var t={};e.BSSID&&(t.mac=e.BSSID.toLowerCase(),t.name=e.SSID),i&&i(t)});break;case"lanxin":LxCore.getWifi(function(e){var t={};e.bssid&&(t.mac=e.bssid.toLowerCase(),t.name=e.ssid),i&&i(t)});break;case"android":case"ios":this.callNative({method:"getWiFi"},function(e){if(e.mac){var t=[],o=e.mac.split(":");for(var n in o)1==o[n].length&&(o[n]="0"+o[n]),t.push(o[n]);e.mac=t.join(":")}i&&i(e)})}},getBlueTooth:function(e,t){switch(this.OS.type){case"wechat":WeCore.getBluetooth(e,function(e){t&&t(e)});break;case"android":case"ios":this.callNative({method:"getBlueTooth"},function(e){t&&t(e)});break;default:t&&t({success:!0,list:[]})}},destoryBlutooth:function(t){switch(this.OS.type){case"wechat":WeCore.destoryBlutooth(WeCore,function(e){t&&t(e)});break;case"android":case"ios":this.callNative({method:"destoryBlutooth"},function(e){t&&t(e)});break;default:t&&t()}}};void 0===window.Native&&(window.Native=Native);var index=window.Native;exports.Native=index;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var uuid=require("uuid"),cookiePrefix="NATIVE_LOGIN_",getQueryString=function(e){var t=null,o=location.hash?-1!==location.hash.indexOf("?")?"?"+location.hash.split("?")[1]:location.hash:location.search;if(-1!=(o=decodeURIComponent(o)).indexOf("?"))for(var n=o.substr(1).split("&"),i=0;i<n.length;i++)if(n[i].split("=")[0]==e){t=unescape(n[i].split("=")[1]);break}return t},getCookie=function(e){var t,o=new RegExp("(^| )"+cookiePrefix+e+"=([^;]*)(;|$)");if(t=document.cookie.match(o)){var n=null;try{n=decodeURIComponent(t[2])}catch(e){n=t[2]}try{n=JSON.parse(n)}catch(e){}return n}return null},setCookie=function(e,t,o){var n="";if(0!=(o=o||0)){var i=new Date;i.setTime(i.getTime()+1e3*o),n="; expires="+i.toGMTString()}document.cookie=cookiePrefix+e+"="+escape(t)+n+"; path=/"},DdCore={url:"",getCustomerCode:function(){return getCookie("customerCode")},getCode:function(){return getCookie("code")},getCoprId:function(){return getCookie("corpid")},getOpenId:function(){return getCookie("openId")},isAutoLogin:function(t){var o=this,e=getQueryString("customerCode");e&&setCookie("customerCode",e);var n=getQueryString("code");n&&setCookie("code",n),this.getConfig(function(e){o.checkAutoLogin(function(e){t(e)})})},getConfig:function(t){var e={type:"4",url:location.href.split("#")[0]};e.customerCode=this.getCustomerCode(),axios.post("/platform/wechat/wechatSign.nolog",e).then(function(e){t&&t(e)})},getAuthCode:function(e,t){dd.config({agentId:e.appId,corpId:e.corpId,timeStamp:e.timestamp,nonceStr:e.nonceStr,signature:e.signature,jsApiList:["device.base.getUUID","device.base.getInterface","device.geolocation.get","runtime.info","biz.contact.choose","device.notification.confirm","device.notification.alert","device.notification.prompt","biz.ding.post","biz.util.openLink"]}),dd.ready(function(){dd.runtime.permission.requestAuthCode({corpId:corpId,onSuccess:t,onFail:function(){t()}})}),dd.error(function(e){console.log("dd error: "+JSON.stringify(e))})},checkAutoLogin:function(t){var e={type:"4"};e.code=this.getCode(),e.customerCode=this.getCustomerCode(),axios.post("/platform/wechat/wechatCheckLogin.nolog",e).then(function(e){console.log("wechatCheckLogin.nolog",e),e&&e.user&&e.user.openId&&setCookie("openId",e.user.openId),t(e)})},getGPS:function(e,t){dd.ready(function(){dd.device.geolocation.get({targetAccuracy:200,coordinate:1,withReGeocode:e,onSuccess:function(e){t&&t(e)},onFail:function(e){console.log(JSON.stringify(e))}})})},logOut:function(t){var e={openId:this.getOpenId(),type:"4",customerCode:this.getCustomerCode()};axios.post("/platform/wechat/wechatLogOut.nolog",e).then(function(e){t&&t(e)})},getWiFi:function(t){dd.ready(function(){dd.device.base.getInterface({onSuccess:function(e){t&&t(e)},onFail:function(e){console.log(JSON.stringify(e))}})})},getUUID:function(t){dd.ready(function(){dd.device.base.getUUID({onSuccess:function(e){t&&t(e)},onFail:function(){t&&t()}})})}},DdUI={setTitle:function(e){dd.biz.navigation.setTitle({title:e})},setEvent:function(t){dd.ready(function(){-1<navigator.userAgent.indexOf("Android")?document.addEventListener("backbutton",function(e){e.preventDefault(),t()},!1):dd.biz.navigation.setLeft({show:!0,control:!0,showIcon:!0,onSuccess:function(){t()}})})},close:function(){dd.biz.navigation.close()}},_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var n in o)Object.prototype.hasOwnProperty.call(o,n)&&(e[n]=o[n])}return e},WeCore={url:"",isAutoLogin:function(t){var o=this;"2"===getQueryString("type")&&setCookie("wechatType","corp");var e=getQueryString("customerCode");e&&setCookie("customerCode",e);var n=getQueryString("code");n&&setCookie("code",n),this.getSign(function(e){o.setConfig(_extends({},e,{jsApiList:["onHistoryBack","closeWindow"]}),function(){o.checkAutoLogin(t,e)})})},getCustomerCode:function(){return getCookie("customerCode")},getWechatType:function(){return getCookie("wechatType")},getWechatCode:function(){return getCookie("code")},getOpenId:function(){return getCookie("openId")},getSign:function(t){"android"===this.getOS()||"corp"===this.getWechatType()?this.initUrl=location.href.split("#")[0]:this.initUrl||(this.initUrl=location.href.split("#")[0]);var e={url:this.initUrl},o=this.getWechatType();e.customerCode=this.getCustomerCode(),e.type="corp"===o?"2":"1",axios.post("/platform/wechat/wechatSign.nolog",e).then(function(e){t&&t(e)})},initPermission:function(t){var o=this;this.getSign(function(e){o.setConfig(e,function(){t&&t()})})},setConfig:function(e,t){wx.config({debug:!!e.debug,appId:e.appId,timestamp:e.timestamp,nonceStr:e.nonceStr,signature:e.signature,jsApiList:e.jsApiList||["getLocation","openBluetoothAdapter","closeBluetoothAdapter","startBeaconDiscovery","stopBeaconDiscovery","onBeaconUpdate","onHistoryBack","closeWindow","getBeacons"]}),wx.ready(function(){setTimeout(function(){t&&t()},100)})},checkAutoLogin:function(t){var e={code:this.getWechatCode()},o=getQueryString("mobile"),n=this.getWechatType();e.customerCode=this.getCustomerCode(),e.type="corp"===n?"2":"1",o&&(e.mobile=o),axios.post("/platform/wechat/wechatCheckLogin.nolog",e).then(function(e){e&&e.user&&e.user.openId&&setCookie("openId",e.user.openId),t(e)})},logOut:function(t){var e={openId:this.getOpenId(),type:"corp"===this.getWechatType()?"2":"1",customerCode:this.getCustomerCode()};axios.post("/platform/wechat/wechatLogOut.nolog",e).then(function(e){t&&t(e)})},getOS:function(){var e="",t=navigator.userAgent;return-1<t.indexOf("Android")?e="android":t.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)&&(e="ios"),e},previewFile:function(t,e){var o=this;"corp"===this.getWechatType()?(this.getSign(function(e){o.setConfig(e,function(){wx.previewFile(t)})}),e({hasError:!1})):e({hasError:!0,msg:"暂不支持预览"})},getGPS:function(o){var n=this;this.getSign(function(e){var t=n.getWechatType();n.setConfig(e,function(){wx.getLocation({type:"gcj02",success:function(e){o&&o(e)},fail:function(e){Native.log(e&&e.errMsg,{method:"wx.getLocation",type:t}),console.log("GPS fail",e),o&&o(null)}})})})},openBluetoothAdapter:function(t){wx.openBluetoothAdapter({success:function(e){console.info("openBluetoothAdapter success",e),t(_extends({},e,{isSuccess:!0}))},fail:function(e){t(_extends({},e,{isSuccess:!1}))}})},getWifi:function(t){var o=this.getWechatType();if("corp"===o){var n=this;n.getSign(function(e){e.jsApiList=["startWifi","getConnectedWifi"],n.setConfig(e,function(){wx.startWifi({success:function(e){console.info("startWifi success",e),wx.getConnectedWifi({success:function(e){console.log("getConnectedWifi success",e),t(e.wifi)},fail:function(e){Native.log(e&&e.errMsg,{method:"wx.getConnectedWifi",type:o}),console.log("getConnectedWifi fail",e),t({})}})},fail:function(e){Native.log(e&&e.errMsg,{method:"wx.startWifi",type:o}),console.log("startWifi fail",e),t({})}})})})}else t({})},destoryBlutooth:function(e,t){e.isBluetoothStoped=!0,e.isBluetoothStopping=!1,e.bluetoothTimeout&&(clearTimeout(e.bluetoothTimeout),e.bluetoothTimeout=null),"corp"===this.getWechatType()&&wx.closeBluetoothAdapter({success:function(){t&&t()}})},setBluetoothTimeout:function(t,o,n){t.bluetoothTimeout||(t.bluetoothTimeout=setTimeout(function(){t.isBluetoothStoped||wx.stopBeaconDiscovery({complete:function(){var e=o.loadCount||3;t.getBluetoothCount>=e?(t.destoryBlutooth(t),n({success:!1,error:"蓝牙获取失败"})):t.destoryBlutooth(t,function(){t.getWechatBluetooth(t,o,n)})}}),t.bluetoothTimeout&&(clearTimeout(t.bluetoothTimeout),t.bluetoothTimeout=null)},o.timeout||1e4))},getBluetooth:function(t,o){var n=this;"corp"===this.getWechatType()?(this.getBluetoothCount=0,this.getSign(function(e){n.setConfig(e,function(){console.log("load Bluetooth"),n.getWechatBluetooth2(n,t,o)})})):o([])},getBeacons:function(o,n,i){if(o<1)i({success:!1});else{var c=this;setTimeout(function(){wx.getBeacons({success:function(e){console.log("getBeacons success",e);var t=e.beacons.find(function(e,t){var o=e.uuid.toLowerCase();return-1<n.uuids.indexOf(o)});t?i({success:!0,list:[t]}):c.getBeacons(--o,n,i)},fail:function(e){Native.log(e&&e.errMsg,{method:"wx.getBeacons",type:c.getWechatType()}),console.log("getBeacons fail",e),c.getBeacons(--o,n,i)}})},o===n.loadCount?0:n.timeout||1e3)}},getWechatBluetooth2:function(t,e,o){console.log("param",e),wx.startBeaconDiscovery({uuids:e.uuids,success:function(){console.log("startBeaconDiscovery success"),t.getBeacons(e.loadCount,e,function(t){wx.stopBeaconDiscovery({complete:function(e){console.log("stopBeaconDiscovery",e),console.log(t),o(t)}})})},fail:function(e){Native.log(e&&e.errMsg,{method:"wx.startBeaconDiscovery",type:t.getWechatType()}),console.log("startBeaconDiscovery fail",e),o({success:!1})}})},getWechatBluetooth:function(t,o,n){t.openBluetoothAdapter(function(e){console.log("openBluetoothAdapter",e),e.isSuccess?(console.log(t.getBluetoothCount,t.isBluetoothStopping,t.isBluetoothStoped,t.bluetoothTimeout),t.getBluetoothCount++,t.isBluetoothStopping=!1,t.isBluetoothStoped=!1,t.bluetoothTimeout&&(clearTimeout(t.bluetoothTimeout),t.bluetoothTimeout=null),wx.startBeaconDiscovery({uuids:o.uuids,success:function(){t.setBluetoothTimeout(t,o,n),wx.onBeaconUpdate(function(e){console.log("onBeaconUpdate",JSON.stringify(e.beacons)),t.beacons=e.beacons,t.isBluetoothStopping||(t.isBluetoothStopping=!0,wx.stopBeaconDiscovery({complete:function(){n({success:!0,list:t.beacons}),t.destoryBlutooth(t)}}))})},complete:function(){t.setBluetoothTimeout(t,o,n)},fail:function(e){Native.log(e&&e.errMsg,{method:"wx.startBeaconDiscovery",type:t.getWechatType()}),console.log("startBeaconDiscovery fail",e),wx.stopBeaconDiscovery({complete:function(){n({success:!1,error:e}),t.destoryBlutooth(t)}})}})):n({success:!1,error:"请开启蓝牙"})})},setEvent:function(e){wx.ready(function(){try{wx.onHistoryBack(function(){return e&&e(),!1})}catch(e){console.warn(e+", 请使用企业微信平台登录")}})},close:function(){wx.closeWindow()}},LxCore={url:"",isAutoLogin:function(e){var t=getQueryString("customerCode"),o=getQueryString("code");t&&setCookie("customerCode",t),o&&setCookie("code",o),this.checkAutoLogin(e)},checkAutoLogin:function(t){var e={code:this.getLanxinCode(),customerCode:this.getCustomerCode(),type:"3"};axios.post("/platform/wechat/wechatCheckLogin.nolog",e).then(function(e){e&&e.user&&e.user.openId&&setCookie("openId",e.user.openId),t(e)})},logOut:function(t){var e={openId:this.getOpenId(),customerCode:this.getCustomerCode(),type:"3"};axios.post("/platform/wechat/wechatLogOut.nolog",e).then(function(e){t&&t(e)})},getGPS:function(t){lx.getLocation({type:"gcj02",success:function(e){return t&&t(e)},fail:function(){return t&&t(null)}})},getWifi:function(t){lx.wifiDeviceInfo({success:function(e){return t(e)},fail:function(){return t({})}})},getCustomerCode:function(){return getQueryString("customerCode")||getCookie("customerCode")},getLanxinCode:function(){return getQueryString("code")||getCookie("code")},getOpenId:function(){return getCookie("openId")},getOS:function(){var e="",t=navigator.userAgent;return-1<t.indexOf("Android")?e="android":t.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)&&(e="ios"),e}},MapCore={getGPS:function(t){var e=void 0,o=void 0;(e=new AMap.Map("")).plugin("AMap.Geolocation",function(){o=new AMap.Geolocation({enableHighAccuracy:!0,timeout:1e4}),e.addControl(o),o.getCurrentPosition(),AMap.event.addListener(o,"complete",function(e){console.log("AMap complete",e),t&&t({longitude:e.position.getLng(),latitude:e.position.getLat()})}),AMap.event.addListener(o,"error",function(e){console.log("AMap error",e),Native.log(e&&e.message,{method:"AMap.Geolocation",type:"h5"}),t&&t()})})}},getOS=function(){var e={},t=navigator.userAgent;return-1<t.indexOf("DingTalk")?e.type="dd":-1<t.indexOf("miniProgram")?e.type="miniprogram":-1<t.indexOf("MicroMessenger")?e.type="wechat":-1<t.indexOf("WandaOA")?e.type="wanxin":-1<t.indexOf("Lanxin")?e.type="lanxin":-1<t.indexOf("Android")||-1<t.indexOf("Adr")?e.type=_isNativeAndroid()?"android":"h5":t.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)?e.type=_isNativeIos()?"ios":"h5":e.type="windows",e},_isNativeAndroid=function(){var t=!0;try{android.callWithDict(JSON.stringify({method:"test"}))}catch(e){t=!1}return t},_isNativeIos=function(){var t=!0;try{ios.callWithDict({method:"test"})}catch(e){t=!1}return t},Native$1={getQueryString:getQueryString,getCookie:getCookie,setCookie:setCookie,OS:getOS(),callbackMap:new Map,isNativeAndroid:function(){return _isNativeAndroid()},isNativeIos:function(){return _isNativeIos()},getNavigation:function(e){var t=1;switch(this.OS.type){case"dd":t=e?3==e?2:e:4;break;default:e&&(t=e)}return t},setDingTalkMenu:function(e,t){switch(this.OS.type){case"dd":DdUI.setEvent(function(){0<=t.indexOf(e.location.pathname)?DdUI.close():e.goBack()});break;case"wechat":"corp"===WeCore.wechatType&&WeCore.setEvent(function(){0<=t.indexOf(e.location.pathname)?WeCore.close():e.goBack()})}},setTitle:function(e){switch(this.OS.type){case"dd":DdUI.setTitle(e)}},getCache:function(e,t){var o="";switch(this.OS.type){case"android":this.callNative({method:"getCache",key:e},function(e){t?t(e):o=e});break;default:o=window.localStorage.getItem(e)}return o},setCache:function(e,t){switch(this.OS.type){case"android":this.callNative({method:"setCache",key:e,value:t});break;default:window.localStorage.setItem(e,t)}},removeCache:function(e){switch(this.OS.type){case"android":this.callNative({method:"removeCache",key:e});break;default:window.localStorage.removeItem(e)}},login:function(e,t){switch(this.OS.type){case"dd":e.dingTalkLogin(t);break;case"wechat":t.wechatType=WeCore.getWechatType(),e.weChatLogin(t);break;case"lanxin":e.lanXinLogin(t);break;default:e.login(t)}},initPermission:function(e){switch(this.OS.type){case"wechat":WeCore.initPermission(e);break;default:e&&e()}},isLogin:function(t){switch(console.warn("this.OS.type:",this.OS.type),this.OS.type){case"dd":DdCore.isAutoLogin(function(e){t(e)});break;case"wechat":WeCore.isAutoLogin(function(e){t(e)});break;case"lanxin":LxCore.isAutoLogin(function(e){return t(e)});break;case"android":this.getCache("",function(e){t(e)});break;default:t({user:JSON.parse(this.getCache("userInfo")),token:this.getCache("token")})}},exit:function(e){switch(this.OS.type){case"dd":DdCore.logOut(e);break;case"wechat":WeCore.logOut(e);break;case"lanxin":LxCore.logOut(e);break;default:e&&e()}},callNative:function(e,t){var o=uuid.v4(),n={_callback_key_:o};for(var i in"string"==typeof e&&(e={method:e}),e)n[i]=e[i];switch(this.callbackMap.set(o,t),this.OS.type){case"ios":ios.callWithDict(n);break;case"android":android.callWithDict(JSON.stringify(n))}},callFront:function(e,t){var o=JSON.parse(t);this.callbackMap.has(e)&&(this.callbackMap.get(e)(o),this.callbackMap.delete(e))},getValidateList:function(e,t,o){var n=this,i=[],c=o||{num:"密码解锁",hand:"手势解锁",finger:"指纹解锁"};switch(this.OS.type){case"dd":case"android":i=1==e?[{pwd_type:"num",label:c.num},{pwd_type:"hand",label:c.hand}]:t.filter(function(e){return"1"==e.enable&&("hand"==e.pwd_type||"num"==e.pwd_type)});break;case"ios":1==e?(i=[{pwd_type:"num",label:c.num},{pwd_type:"hand",label:c.hand}],this.OS.fingerAllow&&i.push({pwd_type:"finger",label:c.finger})):i=t.filter(function(e){return"finger"==e.pwd_type?n.OS.fingerAllow&&"1"==e.enable:"1"==e.enable});break;default:i=1==e?[{pwd_type:"num",label:c.num},{pwd_type:"hand",label:c.hand}]:t.filter(function(e){return"1"==e.enable&&("hand"==e.pwd_type||"num"==e.pwd_type)})}return i},log:function(e,t){var o=1<arguments.length&&void 0!==t?t:{};window.PerformanceAddError&&window.PerformanceAddError({msg:e||"",n:"native",method:o.type||this.OS.type,sendData:o.sendData,resourceUrl:o.method})},getSystemInfo:function(t){var e={success:!0,device:""};switch(this.OS.type){case"dd":t&&t(e);break;case"wechat":var o=this.getCache("openId");e.device=o,t&&t(e);break;case"lanxin":t&&t({device:this.getCache("openId")});break;case"android":case"ios":this.callNative("getSystemInfo",function(e){t&&t(e)});break;default:t&&t(e)}},previewFile:function(e,t){switch(this.OS.type){case"wechat":WeCore.previewFile(e,t);break;default:t({hasError:!0,msg:"暂不支持预览"})}},getGPS:function(e,o){var t=Object.assign({},{method:"getGPS"},e);switch(e.type||this.OS.type){case"dd":var n=e.recode;DdCore.getGPS(n,function(e){var t=Object.assign({},{success:!0},e);o&&o(t)});break;case"wechat":WeCore.getGPS(function(e){var t={success:!1};null!=e&&(t=Object.assign({},{success:!0},e)),o&&o(t)});break;case"lanxin":LxCore.getGPS(function(e){var t={success:!1};null!=e&&(t=Object.assign({},{success:!0},e)),o&&o(t)});break;case"android":case"ios":this.callNative(t,function(e){o&&o(e)});break;case"h5":MapCore.getGPS(function(e){var t=Object.assign({},{success:!0},e);o&&o(t)})}},getWiFi:function(i){switch(this.OS.type){case"dd":DdCore.getWiFi(function(e){var t={mac:e.macIp,name:e.ssid};i&&i(t)});break;case"wechat":WeCore.getWifi(function(e){var t={};e.BSSID&&(t.mac=e.BSSID.toLowerCase(),t.name=e.SSID),i&&i(t)});break;case"lanxin":LxCore.getWifi(function(e){var t={};e.bssid&&(t.mac=e.bssid.toLowerCase(),t.name=e.ssid),i&&i(t)});break;case"android":case"ios":this.callNative({method:"getWiFi"},function(e){if(e.mac){var t=[],o=e.mac.split(":");for(var n in o)1==o[n].length&&(o[n]="0"+o[n]),t.push(o[n]);e.mac=t.join(":")}i&&i(e)})}},getBlueTooth:function(e,t){switch(this.OS.type){case"wechat":WeCore.getBluetooth(e,function(e){t&&t(e)});break;case"android":case"ios":this.callNative({method:"getBlueTooth"},function(e){t&&t(e)});break;default:t&&t({success:!0,list:[]})}},destoryBlutooth:function(t){switch(this.OS.type){case"wechat":WeCore.destoryBlutooth(WeCore,function(e){t&&t(e)});break;case"android":case"ios":this.callNative({method:"destoryBlutooth"},function(e){t&&t(e)});break;default:t&&t()}}};void 0===window.Native&&(window.Native=Native$1);var index=window.Native;exports.Native=index;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hrsass-native-mobile",
3
- "version": "1.1.2",
3
+ "version": "1.1.7",
4
4
  "description": "connect h5 to android and ios",
5
5
  "main": "index.js",
6
6
  "scripts": {