wl-design-mobile 0.4.5 → 0.4.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.
- package/package.json +1 -1
- package/util/jssdk.js +73 -52
package/package.json
CHANGED
package/util/jssdk.js
CHANGED
|
@@ -6,6 +6,11 @@ import {axios} from '../util/axios'
|
|
|
6
6
|
|
|
7
7
|
let appId,agentId,corpId,appKey
|
|
8
8
|
|
|
9
|
+
const APP_ID = 'JsSdk_appId'
|
|
10
|
+
const AGENT_ID = 'JsSdk_agentId'
|
|
11
|
+
const CORP_ID = 'JsSdk_corpId'
|
|
12
|
+
const APP_KEY = 'JsSdk_appKey'
|
|
13
|
+
|
|
9
14
|
function init({appId:a,agentId:b,corpId:c,appKey:d}){
|
|
10
15
|
appId = a
|
|
11
16
|
agentId = b
|
|
@@ -13,19 +18,19 @@ function init({appId:a,agentId:b,corpId:c,appKey:d}){
|
|
|
13
18
|
appKey = d
|
|
14
19
|
|
|
15
20
|
if(appId){
|
|
16
|
-
sessionStorage.setItem(
|
|
21
|
+
sessionStorage.setItem(APP_ID,appId)
|
|
17
22
|
}
|
|
18
23
|
|
|
19
24
|
if(agentId){
|
|
20
|
-
sessionStorage.setItem(
|
|
25
|
+
sessionStorage.setItem(AGENT_ID,agentId)
|
|
21
26
|
}
|
|
22
27
|
|
|
23
28
|
if(corpId){
|
|
24
|
-
sessionStorage.setItem(
|
|
29
|
+
sessionStorage.setItem(CORP_ID,corpId)
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
if(appKey){
|
|
28
|
-
sessionStorage.setItem(
|
|
33
|
+
sessionStorage.setItem(APP_KEY,appKey)
|
|
29
34
|
}
|
|
30
35
|
}
|
|
31
36
|
|
|
@@ -57,10 +62,10 @@ function getJsConfig(){
|
|
|
57
62
|
return new Promise((resolve, reject)=>{
|
|
58
63
|
axios.post(config.platformServerContext + '/api/weixin/getJsConfig', {
|
|
59
64
|
appType: getAppType(),
|
|
60
|
-
appId: sessionStorage.getItem(
|
|
61
|
-
agentId: sessionStorage.getItem(
|
|
62
|
-
corpId: sessionStorage.getItem(
|
|
63
|
-
appKey: sessionStorage.getItem(
|
|
65
|
+
appId: sessionStorage.getItem(APP_ID),
|
|
66
|
+
agentId: sessionStorage.getItem(AGENT_ID),
|
|
67
|
+
corpId: sessionStorage.getItem(CORP_ID),
|
|
68
|
+
appKey: sessionStorage.getItem(APP_KEY),
|
|
64
69
|
url: url
|
|
65
70
|
}).then((resp) => {
|
|
66
71
|
resolve(resp.data)
|
|
@@ -75,7 +80,7 @@ function configWx(){
|
|
|
75
80
|
getJsConfig().then((resp)=>{
|
|
76
81
|
wx.config({
|
|
77
82
|
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
|
|
78
|
-
appId: sessionStorage.getItem(
|
|
83
|
+
appId: sessionStorage.getItem(APP_ID), // 必填,公众号的唯一标识
|
|
79
84
|
timestamp: resp.timestamp, // 必填,生成签名的时间戳
|
|
80
85
|
nonceStr: resp.noncestr, // 必填,生成签名的随机串
|
|
81
86
|
signature: resp.signature, // 必填,签名
|
|
@@ -102,10 +107,10 @@ function getConfigSignature(url) {
|
|
|
102
107
|
return new Promise((resolve,reject)=>{
|
|
103
108
|
axios.post(config.platformServerContext + '/api/weixin/getJsConfig', {
|
|
104
109
|
appType: getAppType(),
|
|
105
|
-
appId: sessionStorage.getItem(
|
|
106
|
-
agentId: sessionStorage.getItem(
|
|
107
|
-
corpId: sessionStorage.getItem(
|
|
108
|
-
appKey: sessionStorage.getItem(
|
|
110
|
+
appId: sessionStorage.getItem(APP_ID),
|
|
111
|
+
agentId: sessionStorage.getItem(AGENT_ID),
|
|
112
|
+
corpId: sessionStorage.getItem(CORP_ID),
|
|
113
|
+
appKey: sessionStorage.getItem(APP_KEY),
|
|
109
114
|
url: url.split('#')[0]
|
|
110
115
|
}).then(resp=>{
|
|
111
116
|
console.log('getConfigSignature',resp)
|
|
@@ -123,7 +128,7 @@ function getConfigSignature(url) {
|
|
|
123
128
|
function configWw(){
|
|
124
129
|
return new Promise((resolve, reject) =>{
|
|
125
130
|
ww.register({
|
|
126
|
-
corpId: sessionStorage.getItem(
|
|
131
|
+
corpId: sessionStorage.getItem(APP_ID), // 必填,当前用户企业所属企业ID
|
|
127
132
|
jsApiList: ['chooseImage', 'uploadImage', 'downloadImage', 'getLocalImgData', 'openLocation', 'getLocation', 'scanQRCode', 'chooseWXPay', 'onHistoryBack','invoke','onLocationChange','previewFile'], // 必填,需要使用的JSAPI列表
|
|
128
133
|
getConfigSignature, // 必填,根据url生成企业签名的回调函数
|
|
129
134
|
onConfigSuccess:(res) => {
|
|
@@ -146,8 +151,8 @@ function configDd(){
|
|
|
146
151
|
//钉钉js-api配置
|
|
147
152
|
console.log("当前页面:"+location.href);
|
|
148
153
|
dd.config({
|
|
149
|
-
agentId:sessionStorage.getItem(
|
|
150
|
-
corpId: sessionStorage.getItem(
|
|
154
|
+
agentId:sessionStorage.getItem(AGENT_ID),
|
|
155
|
+
corpId: sessionStorage.getItem(CORP_ID), // 必填,公众号的唯一标识
|
|
151
156
|
timeStamp: resp.timestamp, // 必填,生成签名的时间戳
|
|
152
157
|
nonceStr: resp.noncestr, // 必填,生成签名的随机串
|
|
153
158
|
signature: resp.signature, // 必填,签名
|
|
@@ -222,7 +227,7 @@ let JsSDK = (function () {
|
|
|
222
227
|
}else{
|
|
223
228
|
configWx().then(()=>{
|
|
224
229
|
wx.chooseImage({
|
|
225
|
-
count: 1, // 默认
|
|
230
|
+
count: 1, // 默认1
|
|
226
231
|
sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
|
|
227
232
|
sourceType: ['camera'], // 可以指定来源是相册还是相机,默认二者都有
|
|
228
233
|
success: function (res) {
|
|
@@ -231,19 +236,20 @@ let JsSDK = (function () {
|
|
|
231
236
|
setTimeout(() => {
|
|
232
237
|
wx.uploadImage({
|
|
233
238
|
localId: localId, // 需要上传的图片的本地ID,由chooseImage接口获得
|
|
234
|
-
isShowProgressTips:
|
|
239
|
+
isShowProgressTips: 1, // 默认为1,显示进度提示
|
|
235
240
|
success: function (res) {
|
|
236
241
|
let serverId = res.serverId; // 返回图片的服务器端ID
|
|
237
242
|
resolve({
|
|
238
|
-
appId:sessionStorage.getItem(
|
|
239
|
-
agentId:sessionStorage.getItem(
|
|
240
|
-
serverId:serverId
|
|
243
|
+
appId:sessionStorage.getItem(APP_ID),
|
|
244
|
+
agentId:sessionStorage.getItem(AGENT_ID),
|
|
245
|
+
serverId:serverId
|
|
246
|
+
})
|
|
241
247
|
}
|
|
242
248
|
})
|
|
243
249
|
}, 200);
|
|
244
250
|
},
|
|
245
251
|
cancel:function (){
|
|
246
|
-
reject('
|
|
252
|
+
reject('取消拍照')
|
|
247
253
|
}
|
|
248
254
|
})
|
|
249
255
|
}).catch((error)=>{
|
|
@@ -252,42 +258,57 @@ let JsSDK = (function () {
|
|
|
252
258
|
}
|
|
253
259
|
})
|
|
254
260
|
}
|
|
255
|
-
function choosePhoto(){
|
|
256
|
-
return new Promise((resolve, reject) =>{
|
|
257
|
-
if(getAppType() === '30'){
|
|
258
|
-
reject('钉钉不支持此方式选择照片')
|
|
259
|
-
}else{
|
|
260
|
-
configWx().then(()=>{
|
|
261
|
+
function choosePhoto({count = 1} = {}) {
|
|
262
|
+
return new Promise((resolve, reject) => {
|
|
263
|
+
if (getAppType() === '30') {
|
|
264
|
+
reject('钉钉不支持此方式选择照片');
|
|
265
|
+
} else {
|
|
266
|
+
configWx().then(() => {
|
|
261
267
|
wx.chooseImage({
|
|
262
|
-
count:
|
|
268
|
+
count: count, // 默认1
|
|
263
269
|
sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
|
|
264
|
-
sourceType: ['album'
|
|
265
|
-
success: function (res) {
|
|
270
|
+
sourceType: ['album'], // 可以指定来源是相册还是相机,默认二者都有
|
|
271
|
+
success: async function (res) {
|
|
266
272
|
let localIds = res.localIds; // 返回选定照片的本地ID列表,localId可以作为img标签的src属性显示图片
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
273
|
+
|
|
274
|
+
let uploadPromises = localIds.map(localId => {
|
|
275
|
+
return new Promise((resolve, reject) => {
|
|
276
|
+
wx.uploadImage({
|
|
277
|
+
localId: localId, // 需要上传的图片的本地ID,由chooseImage接口获得
|
|
278
|
+
isShowProgressTips: 1, // 默认为1,显示进度提示
|
|
279
|
+
success: function (res) {
|
|
280
|
+
let serverId = res.serverId; // 返回图片的服务器端ID
|
|
281
|
+
resolve(serverId);
|
|
282
|
+
},
|
|
283
|
+
fail: function (error) {
|
|
284
|
+
reject(error);
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
try {
|
|
291
|
+
let serverIds = await Promise.all(uploadPromises);
|
|
292
|
+
|
|
293
|
+
resolve({
|
|
294
|
+
appId: sessionStorage.getItem(APP_ID),
|
|
295
|
+
agentId: sessionStorage.getItem(AGENT_ID),
|
|
296
|
+
serverId:serverIds[0],
|
|
297
|
+
serverIds: serverIds
|
|
298
|
+
});
|
|
299
|
+
} catch (error) {
|
|
300
|
+
reject('上传图片失败:' + error);
|
|
301
|
+
}
|
|
281
302
|
},
|
|
282
|
-
cancel:function (){
|
|
283
|
-
reject('取消选择照片')
|
|
303
|
+
cancel: function () {
|
|
304
|
+
reject('取消选择照片');
|
|
284
305
|
}
|
|
285
|
-
})
|
|
286
|
-
}).catch((error)=>{
|
|
287
|
-
reject('微信选择照片失败:'+error)
|
|
288
|
-
})
|
|
306
|
+
});
|
|
307
|
+
}).catch((error) => {
|
|
308
|
+
reject('微信选择照片失败:' + error);
|
|
309
|
+
});
|
|
289
310
|
}
|
|
290
|
-
})
|
|
311
|
+
});
|
|
291
312
|
}
|
|
292
313
|
function getLocation(){
|
|
293
314
|
return new Promise((resolve, reject)=>{
|