wl-design-mobile 0.5.3 → 0.5.5

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.
@@ -129,6 +129,5 @@
129
129
 
130
130
  .cell-group-div {
131
131
  flex: 1;
132
- overflow-y: auto;
133
132
  margin-top: 44px;
134
133
  }
package/package.json CHANGED
@@ -1,31 +1,33 @@
1
- {
2
- "name": "wl-design-mobile",
3
- "version": "0.5.3",
4
- "description": "",
5
- "main": "index.js",
6
- "author": "finch",
7
- "license": "ISC",
8
- "publishConfig": {
9
- "access": "public",
10
- "registry": "https://registry.npmjs.org/",
11
- "files": [
12
- "!**/.*",
13
- "!**/CHANGELOG.md",
14
- "**/*"
15
- ]
16
- },
17
- "dependencies": {
18
- "core-js": "^3.8.3",
19
- "vant": "^2.13.2",
20
- "vue-router": "^3.0.5",
21
- "moment": "^2.30.1",
22
- "axios": "^1.7.2",
23
- "dingtalk-jsapi": "^3.0.12",
24
- "weixin-js-sdk": "^1.6.5",
25
- "@wecom/jssdk": "^1.4.5"
26
- },
27
- "devDependencies": {
28
- "vue": "^2.6.14"
29
- },
30
- "scripts": {}
31
- }
1
+ {
2
+ "name": "wl-design-mobile",
3
+ "version": "0.5.5",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "publish": "pnpm publish --access public --no-git-checks"
8
+ },
9
+ "author": "finch",
10
+ "license": "ISC",
11
+ "publishConfig": {
12
+ "access": "public",
13
+ "registry": "https://registry.npmjs.org/",
14
+ "files": [
15
+ "!**/.*",
16
+ "!**/CHANGELOG.md",
17
+ "**/*"
18
+ ]
19
+ },
20
+ "dependencies": {
21
+ "core-js": "^3.8.3",
22
+ "vant": "^2.13.2",
23
+ "vue-router": "^3.0.5",
24
+ "moment": "^2.30.1",
25
+ "axios": "^1.7.2",
26
+ "dingtalk-jsapi": "^3.0.12",
27
+ "weixin-js-sdk": "^1.6.5",
28
+ "@wecom/jssdk": "^1.4.5"
29
+ },
30
+ "devDependencies": {
31
+ "vue": "^2.6.14"
32
+ }
33
+ }
@@ -132,7 +132,6 @@
132
132
 
133
133
  .cell-group-div {
134
134
  flex: 1;
135
- /*overflow-y: auto;*/
136
135
  margin-top: 44px;
137
136
  }
138
137
 
package/util/jssdk.js CHANGED
@@ -1,508 +1,523 @@
1
- import wx from "weixin-js-sdk";
2
- import * as ww from '@wecom/jssdk'
3
- import * as dd from 'dingtalk-jsapi';
4
- import config from '../config/config'
5
- import {axios} from '../util/axios'
6
- import {Toast } from 'vant'
7
-
8
- let appId,agentId,corpId,appKey
9
-
10
- const APP_ID = 'JsSdk_appId'
11
- const AGENT_ID = 'JsSdk_agentId'
12
- const CORP_ID = 'JsSdk_corpId'
13
- const APP_KEY = 'JsSdk_appKey'
14
-
15
- function init({appId:a,agentId:b,corpId:c,appKey:d}){
16
- appId = a
17
- agentId = b
18
- corpId = c
19
- appKey = d
20
-
21
- if(appId){
22
- sessionStorage.setItem(APP_ID,appId)
23
- }
24
-
25
- if(agentId){
26
- sessionStorage.setItem(AGENT_ID,agentId)
27
- }
28
-
29
- if(corpId){
30
- sessionStorage.setItem(CORP_ID,corpId)
31
- }
32
-
33
- if(appKey){
34
- sessionStorage.setItem(APP_KEY,appKey)
35
- }
36
- }
37
-
38
-
39
- function getAppType() {
40
- let ua = navigator.userAgent.toLowerCase();
41
- let isWxWork = ua.match(/WxWork/i) == 'wxwork';
42
- if (isWxWork) {
43
- return '20'
44
- }
45
-
46
- let isWx = ua.match(/MicroMessenger/i) == 'micromessenger';
47
- if (isWx) {
48
- if(agentId){//如果有agentId认为是企业微信
49
- return '20'
50
- }
51
- return '10'
52
- }
53
-
54
- if (dd.env.platform != 'notInDingTalk') {
55
- return '30'
56
- }
57
-
58
- return ''
59
- }
60
-
61
- function getJsConfig(){
62
- let url = window.location.href.split('#')[0]
63
- return new Promise((resolve, reject)=>{
64
- axios.post(config.platformServerContext + '/api/weixin/getJsConfig', {
65
- appType: getAppType(),
66
- appId: sessionStorage.getItem(APP_ID),
67
- agentId: sessionStorage.getItem(AGENT_ID),
68
- corpId: sessionStorage.getItem(CORP_ID),
69
- appKey: sessionStorage.getItem(APP_KEY),
70
- url: url
71
- }).then((resp) => {
72
- resolve(resp.data)
73
- }).catch((error) => {
74
- reject(error)
75
- })
76
- })
77
- }
78
-
79
- function configWx(){
80
- return new Promise((resolve, reject) =>{
81
- getJsConfig().then((resp)=>{
82
- wx.config({
83
- debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
84
- appId: sessionStorage.getItem(APP_ID), // 必填,公众号的唯一标识
85
- timestamp: resp.timestamp, // 必填,生成签名的时间戳
86
- nonceStr: resp.noncestr, // 必填,生成签名的随机串
87
- signature: resp.signature, // 必填,签名
88
- jsApiList: ['chooseImage', 'uploadImage', 'downloadImage', 'getLocalImgData', 'openLocation', 'getLocation', 'scanQRCode', 'chooseWXPay', 'onHistoryBack','invoke','onLocationChange','previewFile'] // 必填,需要使用的JS接口列表
89
- //jsApiList: ['chooseImage', 'uploadImage', 'downloadImage', 'getLocalImgData', 'openLocation', 'getLocation', 'scanQRCode', 'chooseWXPay', 'onHistoryBack','startLocationUpdateBackground','startLocationUpdate','onLocationChange','offLocationChange'] // 必填,需要使用的JS接口列表
90
- });
91
-
92
- wx.ready(() => {
93
- console.log('微信初始化js-sdk成功');
94
- resolve()
95
- });
96
- wx.error(res => {
97
- console.log('微信初始化js-sdk失败' + res.errMsg);
98
- console.log('友情提示:若想成功,则需通过params传参(而不是query)!!!');
99
- reject('微信初始化js-sdk失败' + res.errMsg)
100
- });
101
- }).catch((error)=>{
102
- reject('请求服务端jssdk签名失败:'+error)
103
- })
104
- })
105
- }
106
-
107
- function getConfigSignature(url) {
108
- return new Promise((resolve,reject)=>{
109
- axios.post(config.platformServerContext + '/api/weixin/getJsConfig', {
110
- appType: getAppType(),
111
- appId: sessionStorage.getItem(APP_ID),
112
- agentId: sessionStorage.getItem(AGENT_ID),
113
- corpId: sessionStorage.getItem(CORP_ID),
114
- appKey: sessionStorage.getItem(APP_KEY),
115
- url: url.split('#')[0]
116
- }).then(resp=>{
117
- console.log('getConfigSignature',resp)
118
- let timestamp = resp.data.timestamp
119
- let nonceStr = resp.data.noncestr
120
- let signature = resp.data.signature
121
- resolve({ timestamp, nonceStr, signature })
122
- }).catch((error)=>{
123
- console.log(error)
124
- reject(error)
125
- })
126
- })
127
- }
128
-
129
- function configWw(){
130
- return new Promise((resolve, reject) =>{
131
- ww.register({
132
- corpId: sessionStorage.getItem(APP_ID), // 必填,当前用户企业所属企业ID
133
- jsApiList: ['chooseImage', 'uploadImage', 'downloadImage', 'getLocalImgData', 'openLocation', 'getLocation', 'scanQRCode', 'chooseWXPay', 'onHistoryBack','invoke','onLocationChange','previewFile'], // 必填,需要使用的JSAPI列表
134
- getConfigSignature, // 必填,根据url生成企业签名的回调函数
135
- onConfigSuccess:(res) => {
136
- console.log('企业微信初始化js-sdk成功');
137
- console.log(res)
138
- resolve()
139
- },
140
- onConfigFail:(res) =>{
141
- console.log('企业微信初始化js-sdk失败' + res.errMsg);
142
- console.log(res)
143
- reject('企业微信初始化js-sdk失败' + res.errMsg)
144
- }
145
- })
146
- })
147
- }
148
-
149
- function configDd(){
150
- return new Promise((resolve, reject)=>{
151
- getJsConfig().then((resp)=>{
152
- //钉钉js-api配置
153
- console.log("当前页面:"+location.href);
154
- dd.config({
155
- agentId:sessionStorage.getItem(AGENT_ID),
156
- corpId: sessionStorage.getItem(CORP_ID), // 必填,公众号的唯一标识
157
- timeStamp: resp.timestamp, // 必填,生成签名的时间戳
158
- nonceStr: resp.noncestr, // 必填,生成签名的随机串
159
- signature: resp.signature, // 必填,签名
160
- jsApiList: [
161
- 'getDeviceUUID',
162
- 'getLocation',
163
-
164
- ] // 必填,需要使用的jsapi列表,注意:不要带dd。
165
- });
166
-
167
- dd.ready(() => {
168
- console.log('初始化钉钉 js-sdk成功');
169
- resolve()
170
- });
171
- dd.error(res => {
172
- console.log('初始化钉钉 js-sdk失败' + JSON.stringify(res));
173
- console.log('友情提示:若想成功,则需通过params传参(而不是query)!!!');
174
- reject('初始化钉钉 js-sdk失败' + JSON.stringify(res))
175
- });
176
- }).catch((error)=>{
177
- reject('请求服务端jssdk签名失败:'+error)
178
- })
179
- })
180
- }
181
-
182
- let JsSDK = (function () {
183
- function scanQRCode(){
184
- return new Promise((resolve, reject) =>{
185
- if(getAppType() === '30'){
186
- dd.scan({
187
- type: 'all',
188
- success: (res) => {
189
- console.log('钉钉扫码结果',res)
190
- resolve(res.text)
191
- },
192
- fail: (err) => {
193
- console.log('钉钉扫码失败',err)
194
- reject('钉钉扫码失败:'+err)
195
- },
196
- complete: () => {},
197
- });
198
- }else{
199
- configWx().then(()=>{
200
- wx.scanQRCode({
201
- desc: 'scanQRCode desc',
202
- needResult: 1,
203
- scanType: ["qrCode", "barCode"],
204
- success: function (resp) {
205
- console.log("微信扫码结果:",resp)
206
- let result = resp.resultStr
207
- resolve(result)
208
- },
209
- fail: function (res) {
210
- console.log("失败res=>",res)
211
- if (res.errMsg.indexOf('function_not_exist') > 0) {
212
- reject('版本过低请升级');
213
- } else {
214
- reject("微信扫码失败,请联系系统管理员!");
215
- }
216
- }
217
- })
218
- }).catch((error)=>{
219
- reject('微信扫码失败:'+error)
220
- })
221
- }
222
- })
223
- }
224
- function takePhoto(){
225
- return new Promise((resolve, reject) =>{
226
- if(getAppType() === '30'){
227
- reject('钉钉不支持此方式拍照')
228
- }else{
229
- configWx().then(()=>{
230
- wx.chooseImage({
231
- count: 1, // 默认1
232
- sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
233
- sourceType: ['camera'], // 可以指定来源是相册还是相机,默认二者都有
234
- success: function (res) {
235
- let localIds = res.localIds; // 返回选定照片的本地ID列表,localId可以作为img标签的src属性显示图片
236
- let localId = localIds[0];
237
- Toast.loading({
238
- duration: 0, // 持续展示 toast
239
- forbidClick: false,
240
- message: '正在上传',
241
- });
242
- setTimeout(() => {
243
- wx.uploadImage({
244
- localId: localId, // 需要上传的图片的本地ID,由chooseImage接口获得
245
- isShowProgressTips: 0, // 默认为1,显示进度提示
246
- success: function (res) {
247
- Toast.clear()
248
- let serverId = res.serverId; // 返回图片的服务器端ID
249
- resolve({
250
- appId:sessionStorage.getItem(APP_ID),
251
- agentId:sessionStorage.getItem(AGENT_ID),
252
- serverId:serverId
253
- })
254
- }
255
- })
256
- }, 200);
257
- },
258
- cancel:function (){
259
- reject('取消拍照')
260
- }
261
- })
262
- }).catch((error)=>{
263
- reject('微信拍照失败:'+error)
264
- })
265
- }
266
- })
267
- }
268
- function choosePhoto({count = 1} = {}) {
269
- return new Promise((resolve, reject) => {
270
- if (getAppType() === '30') {
271
- reject('钉钉不支持此方式选择照片');
272
- } else {
273
- configWx().then(() => {
274
- wx.chooseImage({
275
- count: count, // 默认1
276
- sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
277
- sourceType: ['album'], // 可以指定来源是相册还是相机,默认二者都有
278
- success: async function (res) {
279
- let localIds = res.localIds; // 返回选定照片的本地ID列表,localId可以作为img标签的src属性显示图片
280
- Toast.loading({
281
- duration: 0, // 持续展示 toast
282
- forbidClick: false,
283
- message: '正在上传',
284
- });
285
- let uploadPromises = localIds.map(localId => {
286
- return new Promise((resolve, reject) => {
287
- wx.uploadImage({
288
- localId: localId, // 需要上传的图片的本地ID,由chooseImage接口获得
289
- isShowProgressTips: 0, // 默认为1,显示进度提示
290
- success: function (res) {
291
- let serverId = res.serverId; // 返回图片的服务器端ID
292
- resolve(serverId);
293
- },
294
- fail: function (error) {
295
- reject(error);
296
- }
297
- });
298
- });
299
- });
300
-
301
- try {
302
- let serverIds = await Promise.all(uploadPromises);
303
- console.log('choosePhoto',serverIds)
304
- Toast.clear()
305
- resolve({
306
- appId: sessionStorage.getItem(APP_ID),
307
- agentId: sessionStorage.getItem(AGENT_ID),
308
- serverId:serverIds[0],
309
- serverIds: serverIds
310
- });
311
- } catch (error) {
312
- Toast.clear()
313
- reject('上传图片失败:' + error);
314
- }
315
- },
316
- cancel: function () {
317
- reject('取消选择照片');
318
- }
319
- });
320
- }).catch((error) => {
321
- reject('微信选择照片失败:' + error);
322
- });
323
- }
324
- });
325
- }
326
- function getLocation(){
327
- return new Promise((resolve, reject)=>{
328
- if(getAppType() === '30'){
329
- configDd().then(()=>{
330
- dd.getLocation({
331
- targetAccuracy: '200',
332
- cacheTimeout: 20,
333
- coordinate: '1',
334
- useCache: true,
335
- withReGeocode: true,
336
- type: 1,
337
- success: (res) => {
338
- console.log('钉钉获取当前位置结果:', res)
339
- resolve(res)
340
- },
341
- fail: (error) => {
342
- console.log('钉钉获取位置失败:', error)
343
- reject('钉钉获取位置失败:'+error)
344
- },
345
- complete: () => {},
346
- })
347
- }).catch((error)=>{
348
- reject('钉钉获取位置失败:'+error)
349
- })
350
- }else{
351
- configWx().then(()=>{
352
- wx.getLocation({
353
- type: 'gcj02', //获取gcj02的坐标
354
- success: (res) => {
355
- //res.longitude 获取经度
356
- //res.latitude 获取纬度
357
- console.log(res);
358
- resolve(res)
359
- }, fail: (res) => {
360
- console.log("微信获取位置失败。"+JSON.stringify(res));
361
- reject("微信获取位置失败" + JSON.stringify(res))
362
- }
363
- });
364
- }).catch((error)=>{
365
- reject('微信获取位置失败:'+error)
366
- })
367
- }
368
- })
369
- }
370
- function openLocation({longitude,latitude,name,address,scale= 15} = {}){
371
- return new Promise((resolve, reject)=>{
372
- if(getAppType() === '30'){
373
- configDd().then(()=>{
374
- dd.openLocation({
375
- title: name,
376
- address: address,
377
- latitude: latitude,
378
- longitude: longitude,
379
- success: () => {
380
- resolve()
381
- },
382
- fail: () => {
383
- reject()
384
- },
385
- complete: () => {
386
- resolve()
387
- },
388
- });
389
-
390
- }).catch((error)=>{
391
- reject('钉钉启动内置地图位置失败:'+error)
392
- })
393
- }else{
394
- configWx().then(()=>{
395
- wx.openLocation({
396
- latitude: latitude,//目的地latitude
397
- longitude: longitude,//目的地longitude
398
- name: name,
399
- address: address,
400
- scale: scale//地图缩放大小,可根据情况具体调整
401
- });
402
- resolve()
403
- }).catch((error)=>{
404
- reject('微信启动内置地图失败:'+error)
405
- })
406
- }
407
- })
408
- }
409
-
410
- function startAutoLBS({sceneId:sceneId}){
411
- return new Promise((resolve, reject)=>{
412
- if(getAppType() === '30'){
413
- configDd().then(()=>{
414
- dd.startLocating({
415
- sceneId: sceneId,
416
- useCache: true,
417
- withReGeocode: false,
418
- targetAccuracy: 200,
419
- callBackInterval: 1000,
420
- iOSDistanceFilter: 10,
421
- success: (res) => {
422
- resolve({longitude:res.longitude,latitude:res.latitude})
423
- },
424
- fail: () => {
425
- reject()
426
- },
427
- complete: () => {
428
- resolve()
429
- },
430
- });
431
- }).catch((error)=>{
432
- reject('钉钉启动内置地图位置失败:'+error)
433
- })
434
- }else if(getAppType() === '20'){
435
- configWw().then(()=>{
436
- ww.startAutoLBS({
437
- type: 'gcj02',
438
- success:()=>{
439
- ww.onLocationChange(function(event) {
440
- console.log('onLocationChange',event)
441
- resolve({longitude:event.longitude,latitude:event.latitude})
442
- })
443
- },
444
- fail:()=>{
445
- reject()
446
- }
447
- }).then(resp => {
448
- console.log('企业微信开启连续定位',resp)
449
- })
450
- }).catch((error)=>{
451
- reject('企业微信开启连续定位失败:'+error)
452
- })
453
- }else{
454
- reject('微信不支持连续定位')
455
- }
456
- })
457
- }
458
-
459
- function stopAutoLBS({sceneId:sceneId}){
460
- return new Promise((resolve, reject)=>{
461
- if(getAppType() === '30'){
462
- configDd().then(()=>{
463
- dd.stopLocating({
464
- sceneId: sceneId,
465
- success: () => {
466
- resolve()
467
- },
468
- fail: () => {
469
- reject()
470
- },
471
- complete: () => {
472
- resolve()
473
- },
474
- });
475
- resolve()
476
- }).catch((error)=>{
477
- reject('钉钉启动内置地图位置失败:'+error)
478
- })
479
- }else if(getAppType() === '20'){
480
- configWw().then(()=>{
481
- ww.stopAutoLBS().then(resp => {
482
- console.log(resp)
483
- resolve()
484
- })
485
- }).catch((error)=>{
486
- reject('企业微信关闭连续定位失败:'+error)
487
- })
488
- }else{
489
- reject('微信不支持连续定位')
490
- }
491
- })
492
- }
493
-
494
- // 公开API
495
- return {
496
- init:init,
497
- takePhoto:takePhoto,
498
- choosePhoto:choosePhoto,
499
- scanQRCode: scanQRCode,
500
- getLocation:getLocation,
501
- openLocation:openLocation,
502
- startAutoLBS:startAutoLBS,
503
- stopAutoLBS:stopAutoLBS,
504
- };
505
- })();
506
-
507
- export default JsSDK
508
-
1
+ import wx from "weixin-js-sdk";
2
+ import * as ww from '@wecom/jssdk'
3
+ import * as dd from 'dingtalk-jsapi';
4
+ import config from '../config/config'
5
+ import {axios} from '../util/axios'
6
+ import {Toast } from 'vant'
7
+
8
+ let appId,agentId,corpId,appKey
9
+
10
+ const APP_ID = 'JsSdk_appId'
11
+ const AGENT_ID = 'JsSdk_agentId'
12
+ const CORP_ID = 'JsSdk_corpId'
13
+ const APP_KEY = 'JsSdk_appKey'
14
+
15
+ function init({appId:a,agentId:b,corpId:c,appKey:d}){
16
+ appId = a
17
+ agentId = b
18
+ corpId = c
19
+ appKey = d
20
+
21
+ if(appId){
22
+ sessionStorage.setItem(APP_ID,appId)
23
+ }
24
+
25
+ if(agentId){
26
+ sessionStorage.setItem(AGENT_ID,agentId)
27
+ }
28
+
29
+ if(corpId){
30
+ sessionStorage.setItem(CORP_ID,corpId)
31
+ }
32
+
33
+ if(appKey){
34
+ sessionStorage.setItem(APP_KEY,appKey)
35
+ }
36
+ }
37
+
38
+
39
+ function getAppType() {
40
+ let ua = navigator.userAgent.toLowerCase();
41
+ let isWxWork = ua.match(/WxWork/i) == 'wxwork';
42
+ if (isWxWork) {
43
+ return '20'
44
+ }
45
+
46
+ let isWx = ua.match(/MicroMessenger/i) == 'micromessenger';
47
+ if (isWx) {
48
+ if(agentId){//如果有agentId认为是企业微信
49
+ return '20'
50
+ }
51
+ return '10'
52
+ }
53
+
54
+ if (dd.env.platform != 'notInDingTalk') {
55
+ return '30'
56
+ }
57
+
58
+ return ''
59
+ }
60
+
61
+ function getCurrentUrl() {
62
+ // iOS 14+需要特殊处理
63
+ if (isIOS14Plus()) {
64
+ return window.location.origin +
65
+ window.location.pathname +
66
+ window.location.search
67
+ }
68
+ return window.location.href.split('#')[0]
69
+ }
70
+
71
+ function isIOS14Plus() {
72
+ const os = navigator.userAgent
73
+ return /iPhone OS 1[4-9]/.test(os) || /iPhone OS [2-9]\d/.test(os)
74
+ }
75
+
76
+ function getJsConfig(){
77
+ let url = getCurrentUrl()
78
+ return new Promise((resolve, reject)=>{
79
+ axios.post(config.platformServerContext + '/api/weixin/getJsConfig', {
80
+ appType: getAppType(),
81
+ appId: sessionStorage.getItem(APP_ID),
82
+ agentId: sessionStorage.getItem(AGENT_ID),
83
+ corpId: sessionStorage.getItem(CORP_ID),
84
+ appKey: sessionStorage.getItem(APP_KEY),
85
+ url: url
86
+ }).then((resp) => {
87
+ resolve(resp.data)
88
+ }).catch((error) => {
89
+ reject(error)
90
+ })
91
+ })
92
+ }
93
+
94
+ function configWx(){
95
+ return new Promise((resolve, reject) =>{
96
+ getJsConfig().then((resp)=>{
97
+ wx.config({
98
+ debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
99
+ appId: sessionStorage.getItem(APP_ID), // 必填,公众号的唯一标识
100
+ timestamp: resp.timestamp, // 必填,生成签名的时间戳
101
+ nonceStr: resp.noncestr, // 必填,生成签名的随机串
102
+ signature: resp.signature, // 必填,签名
103
+ jsApiList: ['chooseImage', 'uploadImage', 'downloadImage', 'getLocalImgData', 'openLocation', 'getLocation', 'scanQRCode', 'chooseWXPay', 'onHistoryBack','invoke','onLocationChange','previewFile'] // 必填,需要使用的JS接口列表
104
+ //jsApiList: ['chooseImage', 'uploadImage', 'downloadImage', 'getLocalImgData', 'openLocation', 'getLocation', 'scanQRCode', 'chooseWXPay', 'onHistoryBack','startLocationUpdateBackground','startLocationUpdate','onLocationChange','offLocationChange'] // 必填,需要使用的JS接口列表
105
+ });
106
+
107
+ wx.ready(() => {
108
+ console.log('微信初始化js-sdk成功');
109
+ resolve()
110
+ });
111
+ wx.error(res => {
112
+ console.log('微信初始化js-sdk失败' + res.errMsg);
113
+ console.log('友情提示:若想成功,则需通过params传参(而不是query)!!!');
114
+ reject('微信初始化js-sdk失败' + res.errMsg)
115
+ });
116
+ }).catch((error)=>{
117
+ reject('请求服务端jssdk签名失败:'+error)
118
+ })
119
+ })
120
+ }
121
+
122
+ function getConfigSignature(url) {
123
+ return new Promise((resolve,reject)=>{
124
+ axios.post(config.platformServerContext + '/api/weixin/getJsConfig', {
125
+ appType: getAppType(),
126
+ appId: sessionStorage.getItem(APP_ID),
127
+ agentId: sessionStorage.getItem(AGENT_ID),
128
+ corpId: sessionStorage.getItem(CORP_ID),
129
+ appKey: sessionStorage.getItem(APP_KEY),
130
+ url: url.split('#')[0]
131
+ }).then(resp=>{
132
+ console.log('getConfigSignature',resp)
133
+ let timestamp = resp.data.timestamp
134
+ let nonceStr = resp.data.noncestr
135
+ let signature = resp.data.signature
136
+ resolve({ timestamp, nonceStr, signature })
137
+ }).catch((error)=>{
138
+ console.log(error)
139
+ reject(error)
140
+ })
141
+ })
142
+ }
143
+
144
+ function configWw(){
145
+ return new Promise((resolve, reject) =>{
146
+ ww.register({
147
+ corpId: sessionStorage.getItem(APP_ID), // 必填,当前用户企业所属企业ID
148
+ jsApiList: ['chooseImage', 'uploadImage', 'downloadImage', 'getLocalImgData', 'openLocation', 'getLocation', 'scanQRCode', 'chooseWXPay', 'onHistoryBack','invoke','onLocationChange','previewFile'], // 必填,需要使用的JSAPI列表
149
+ getConfigSignature, // 必填,根据url生成企业签名的回调函数
150
+ onConfigSuccess:(res) => {
151
+ console.log('企业微信初始化js-sdk成功');
152
+ console.log(res)
153
+ resolve()
154
+ },
155
+ onConfigFail:(res) =>{
156
+ console.log('企业微信初始化js-sdk失败' + res.errMsg);
157
+ console.log(res)
158
+ reject('企业微信初始化js-sdk失败' + res.errMsg)
159
+ }
160
+ })
161
+ })
162
+ }
163
+
164
+ function configDd(){
165
+ return new Promise((resolve, reject)=>{
166
+ getJsConfig().then((resp)=>{
167
+ //钉钉js-api配置
168
+ console.log("当前页面:"+location.href);
169
+ dd.config({
170
+ agentId:sessionStorage.getItem(AGENT_ID),
171
+ corpId: sessionStorage.getItem(CORP_ID), // 必填,公众号的唯一标识
172
+ timeStamp: resp.timestamp, // 必填,生成签名的时间戳
173
+ nonceStr: resp.noncestr, // 必填,生成签名的随机串
174
+ signature: resp.signature, // 必填,签名
175
+ jsApiList: [
176
+ 'getDeviceUUID',
177
+ 'getLocation',
178
+
179
+ ] // 必填,需要使用的jsapi列表,注意:不要带dd。
180
+ });
181
+
182
+ dd.ready(() => {
183
+ console.log('初始化钉钉 js-sdk成功');
184
+ resolve()
185
+ });
186
+ dd.error(res => {
187
+ console.log('初始化钉钉 js-sdk失败' + JSON.stringify(res));
188
+ console.log('友情提示:若想成功,则需通过params传参(而不是query)!!!');
189
+ reject('初始化钉钉 js-sdk失败' + JSON.stringify(res))
190
+ });
191
+ }).catch((error)=>{
192
+ reject('请求服务端jssdk签名失败:'+error)
193
+ })
194
+ })
195
+ }
196
+
197
+ let JsSDK = (function () {
198
+ function scanQRCode(){
199
+ return new Promise((resolve, reject) =>{
200
+ if(getAppType() === '30'){
201
+ dd.scan({
202
+ type: 'all',
203
+ success: (res) => {
204
+ console.log('钉钉扫码结果',res)
205
+ resolve(res.text)
206
+ },
207
+ fail: (err) => {
208
+ console.log('钉钉扫码失败',err)
209
+ reject('钉钉扫码失败:'+err)
210
+ },
211
+ complete: () => {},
212
+ });
213
+ }else{
214
+ configWx().then(()=>{
215
+ wx.scanQRCode({
216
+ desc: 'scanQRCode desc',
217
+ needResult: 1,
218
+ scanType: ["qrCode", "barCode"],
219
+ success: function (resp) {
220
+ console.log("微信扫码结果:",resp)
221
+ let result = resp.resultStr
222
+ resolve(result)
223
+ },
224
+ fail: function (res) {
225
+ console.log("失败res=>",res)
226
+ if (res.errMsg.indexOf('function_not_exist') > 0) {
227
+ reject('版本过低请升级');
228
+ } else {
229
+ reject("微信扫码失败,请联系系统管理员!");
230
+ }
231
+ }
232
+ })
233
+ }).catch((error)=>{
234
+ reject('微信扫码失败:'+error)
235
+ })
236
+ }
237
+ })
238
+ }
239
+ function takePhoto(){
240
+ return new Promise((resolve, reject) =>{
241
+ if(getAppType() === '30'){
242
+ reject('钉钉不支持此方式拍照')
243
+ }else{
244
+ configWx().then(()=>{
245
+ wx.chooseImage({
246
+ count: 1, // 默认1
247
+ sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
248
+ sourceType: ['camera'], // 可以指定来源是相册还是相机,默认二者都有
249
+ success: function (res) {
250
+ let localIds = res.localIds; // 返回选定照片的本地ID列表,localId可以作为img标签的src属性显示图片
251
+ let localId = localIds[0];
252
+ Toast.loading({
253
+ duration: 0, // 持续展示 toast
254
+ forbidClick: false,
255
+ message: '正在上传',
256
+ });
257
+ setTimeout(() => {
258
+ wx.uploadImage({
259
+ localId: localId, // 需要上传的图片的本地ID,由chooseImage接口获得
260
+ isShowProgressTips: 0, // 默认为1,显示进度提示
261
+ success: function (res) {
262
+ Toast.clear()
263
+ let serverId = res.serverId; // 返回图片的服务器端ID
264
+ resolve({
265
+ appId:sessionStorage.getItem(APP_ID),
266
+ agentId:sessionStorage.getItem(AGENT_ID),
267
+ serverId:serverId
268
+ })
269
+ }
270
+ })
271
+ }, 200);
272
+ },
273
+ cancel:function (){
274
+ reject('取消拍照')
275
+ }
276
+ })
277
+ }).catch((error)=>{
278
+ reject('微信拍照失败:'+error)
279
+ })
280
+ }
281
+ })
282
+ }
283
+ function choosePhoto({count = 1} = {}) {
284
+ return new Promise((resolve, reject) => {
285
+ if (getAppType() === '30') {
286
+ reject('钉钉不支持此方式选择照片');
287
+ } else {
288
+ configWx().then(() => {
289
+ wx.chooseImage({
290
+ count: count, // 默认1
291
+ sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
292
+ sourceType: ['album'], // 可以指定来源是相册还是相机,默认二者都有
293
+ success: async function (res) {
294
+ let localIds = res.localIds; // 返回选定照片的本地ID列表,localId可以作为img标签的src属性显示图片
295
+ Toast.loading({
296
+ duration: 0, // 持续展示 toast
297
+ forbidClick: false,
298
+ message: '正在上传',
299
+ });
300
+ let uploadPromises = localIds.map(localId => {
301
+ return new Promise((resolve, reject) => {
302
+ wx.uploadImage({
303
+ localId: localId, // 需要上传的图片的本地ID,由chooseImage接口获得
304
+ isShowProgressTips: 0, // 默认为1,显示进度提示
305
+ success: function (res) {
306
+ let serverId = res.serverId; // 返回图片的服务器端ID
307
+ resolve(serverId);
308
+ },
309
+ fail: function (error) {
310
+ reject(error);
311
+ }
312
+ });
313
+ });
314
+ });
315
+
316
+ try {
317
+ let serverIds = await Promise.all(uploadPromises);
318
+ console.log('choosePhoto',serverIds)
319
+ Toast.clear()
320
+ resolve({
321
+ appId: sessionStorage.getItem(APP_ID),
322
+ agentId: sessionStorage.getItem(AGENT_ID),
323
+ serverId:serverIds[0],
324
+ serverIds: serverIds
325
+ });
326
+ } catch (error) {
327
+ Toast.clear()
328
+ reject('上传图片失败:' + error);
329
+ }
330
+ },
331
+ cancel: function () {
332
+ reject('取消选择照片');
333
+ }
334
+ });
335
+ }).catch((error) => {
336
+ reject('微信选择照片失败:' + error);
337
+ });
338
+ }
339
+ });
340
+ }
341
+ function getLocation(){
342
+ return new Promise((resolve, reject)=>{
343
+ if(getAppType() === '30'){
344
+ configDd().then(()=>{
345
+ dd.getLocation({
346
+ targetAccuracy: '200',
347
+ cacheTimeout: 20,
348
+ coordinate: '1',
349
+ useCache: true,
350
+ withReGeocode: true,
351
+ type: 1,
352
+ success: (res) => {
353
+ console.log('钉钉获取当前位置结果:', res)
354
+ resolve(res)
355
+ },
356
+ fail: (error) => {
357
+ console.log('钉钉获取位置失败:', error)
358
+ reject('钉钉获取位置失败:'+error)
359
+ },
360
+ complete: () => {},
361
+ })
362
+ }).catch((error)=>{
363
+ reject('钉钉获取位置失败:'+error)
364
+ })
365
+ }else{
366
+ configWx().then(()=>{
367
+ wx.getLocation({
368
+ type: 'gcj02', //获取gcj02的坐标
369
+ success: (res) => {
370
+ //res.longitude 获取经度
371
+ //res.latitude 获取纬度
372
+ console.log(res);
373
+ resolve(res)
374
+ }, fail: (res) => {
375
+ console.log("微信获取位置失败。"+JSON.stringify(res));
376
+ reject("微信获取位置失败" + JSON.stringify(res))
377
+ }
378
+ });
379
+ }).catch((error)=>{
380
+ reject('微信获取位置失败:'+error)
381
+ })
382
+ }
383
+ })
384
+ }
385
+ function openLocation({longitude,latitude,name,address,scale= 15} = {}){
386
+ return new Promise((resolve, reject)=>{
387
+ if(getAppType() === '30'){
388
+ configDd().then(()=>{
389
+ dd.openLocation({
390
+ title: name,
391
+ address: address,
392
+ latitude: latitude,
393
+ longitude: longitude,
394
+ success: () => {
395
+ resolve()
396
+ },
397
+ fail: () => {
398
+ reject()
399
+ },
400
+ complete: () => {
401
+ resolve()
402
+ },
403
+ });
404
+
405
+ }).catch((error)=>{
406
+ reject('钉钉启动内置地图位置失败:'+error)
407
+ })
408
+ }else{
409
+ configWx().then(()=>{
410
+ wx.openLocation({
411
+ latitude: latitude,//目的地latitude
412
+ longitude: longitude,//目的地longitude
413
+ name: name,
414
+ address: address,
415
+ scale: scale//地图缩放大小,可根据情况具体调整
416
+ });
417
+ resolve()
418
+ }).catch((error)=>{
419
+ reject('微信启动内置地图失败:'+error)
420
+ })
421
+ }
422
+ })
423
+ }
424
+
425
+ function startAutoLBS({sceneId:sceneId}){
426
+ return new Promise((resolve, reject)=>{
427
+ if(getAppType() === '30'){
428
+ configDd().then(()=>{
429
+ dd.startLocating({
430
+ sceneId: sceneId,
431
+ useCache: true,
432
+ withReGeocode: false,
433
+ targetAccuracy: 200,
434
+ callBackInterval: 1000,
435
+ iOSDistanceFilter: 10,
436
+ success: (res) => {
437
+ resolve({longitude:res.longitude,latitude:res.latitude})
438
+ },
439
+ fail: () => {
440
+ reject()
441
+ },
442
+ complete: () => {
443
+ resolve()
444
+ },
445
+ });
446
+ }).catch((error)=>{
447
+ reject('钉钉启动内置地图位置失败:'+error)
448
+ })
449
+ }else if(getAppType() === '20'){
450
+ configWw().then(()=>{
451
+ ww.startAutoLBS({
452
+ type: 'gcj02',
453
+ success:()=>{
454
+ ww.onLocationChange(function(event) {
455
+ console.log('onLocationChange',event)
456
+ resolve({longitude:event.longitude,latitude:event.latitude})
457
+ })
458
+ },
459
+ fail:()=>{
460
+ reject()
461
+ }
462
+ }).then(resp => {
463
+ console.log('企业微信开启连续定位',resp)
464
+ })
465
+ }).catch((error)=>{
466
+ reject('企业微信开启连续定位失败:'+error)
467
+ })
468
+ }else{
469
+ reject('微信不支持连续定位')
470
+ }
471
+ })
472
+ }
473
+
474
+ function stopAutoLBS({sceneId:sceneId}){
475
+ return new Promise((resolve, reject)=>{
476
+ if(getAppType() === '30'){
477
+ configDd().then(()=>{
478
+ dd.stopLocating({
479
+ sceneId: sceneId,
480
+ success: () => {
481
+ resolve()
482
+ },
483
+ fail: () => {
484
+ reject()
485
+ },
486
+ complete: () => {
487
+ resolve()
488
+ },
489
+ });
490
+ resolve()
491
+ }).catch((error)=>{
492
+ reject('钉钉启动内置地图位置失败:'+error)
493
+ })
494
+ }else if(getAppType() === '20'){
495
+ configWw().then(()=>{
496
+ ww.stopAutoLBS().then(resp => {
497
+ console.log(resp)
498
+ resolve()
499
+ })
500
+ }).catch((error)=>{
501
+ reject('企业微信关闭连续定位失败:'+error)
502
+ })
503
+ }else{
504
+ reject('微信不支持连续定位')
505
+ }
506
+ })
507
+ }
508
+
509
+ // 公开API
510
+ return {
511
+ init:init,
512
+ takePhoto:takePhoto,
513
+ choosePhoto:choosePhoto,
514
+ scanQRCode: scanQRCode,
515
+ getLocation:getLocation,
516
+ openLocation:openLocation,
517
+ startAutoLBS:startAutoLBS,
518
+ stopAutoLBS:stopAutoLBS,
519
+ };
520
+ })();
521
+
522
+ export default JsSDK
523
+