wl-design-mobile 0.4.6 → 0.4.8
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 +57 -44
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, // 必填,签名
|
|
@@ -235,8 +240,8 @@ let JsSDK = (function () {
|
|
|
235
240
|
success: function (res) {
|
|
236
241
|
let serverId = res.serverId; // 返回图片的服务器端ID
|
|
237
242
|
resolve({
|
|
238
|
-
appId:sessionStorage.getItem(
|
|
239
|
-
agentId:sessionStorage.getItem(
|
|
243
|
+
appId:sessionStorage.getItem(APP_ID),
|
|
244
|
+
agentId:sessionStorage.getItem(AGENT_ID),
|
|
240
245
|
serverId:serverId
|
|
241
246
|
})
|
|
242
247
|
}
|
|
@@ -253,49 +258,57 @@ let JsSDK = (function () {
|
|
|
253
258
|
}
|
|
254
259
|
})
|
|
255
260
|
}
|
|
256
|
-
function choosePhoto({count = 1} = {}){
|
|
257
|
-
return new Promise((resolve, reject) =>{
|
|
258
|
-
if(getAppType() === '30'){
|
|
259
|
-
reject('钉钉不支持此方式选择照片')
|
|
260
|
-
}else{
|
|
261
|
-
configWx().then(()=>{
|
|
261
|
+
function choosePhoto({count = 1} = {}) {
|
|
262
|
+
return new Promise((resolve, reject) => {
|
|
263
|
+
if (getAppType() === '30') {
|
|
264
|
+
reject('钉钉不支持此方式选择照片');
|
|
265
|
+
} else {
|
|
266
|
+
configWx().then(() => {
|
|
262
267
|
wx.chooseImage({
|
|
263
268
|
count: count, // 默认1
|
|
264
269
|
sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
|
|
265
270
|
sourceType: ['album'], // 可以指定来源是相册还是相机,默认二者都有
|
|
266
|
-
success: function (res) {
|
|
271
|
+
success: async function (res) {
|
|
267
272
|
let localIds = res.localIds; // 返回选定照片的本地ID列表,localId可以作为img标签的src属性显示图片
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
localIds.forEach((localId) =>{
|
|
273
|
+
|
|
274
|
+
let uploadPromises = localIds.map(localId => {
|
|
275
|
+
return new Promise((resolve, reject) => {
|
|
272
276
|
wx.uploadImage({
|
|
273
277
|
localId: localId, // 需要上传的图片的本地ID,由chooseImage接口获得
|
|
274
278
|
isShowProgressTips: 1, // 默认为1,显示进度提示
|
|
275
279
|
success: function (res) {
|
|
276
280
|
let serverId = res.serverId; // 返回图片的服务器端ID
|
|
277
|
-
|
|
281
|
+
resolve(serverId);
|
|
282
|
+
},
|
|
283
|
+
fail: function (error) {
|
|
284
|
+
reject(error);
|
|
278
285
|
}
|
|
279
|
-
})
|
|
280
|
-
})
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
});
|
|
281
289
|
|
|
290
|
+
try {
|
|
291
|
+
let serverIds = await Promise.all(uploadPromises);
|
|
292
|
+
console.log('choosePhoto',serverIds)
|
|
282
293
|
resolve({
|
|
283
|
-
appId:sessionStorage.getItem(
|
|
284
|
-
agentId:sessionStorage.getItem(
|
|
294
|
+
appId: sessionStorage.getItem(APP_ID),
|
|
295
|
+
agentId: sessionStorage.getItem(AGENT_ID),
|
|
285
296
|
serverId:serverIds[0],
|
|
286
|
-
serverIds:serverIds
|
|
287
|
-
})
|
|
288
|
-
}
|
|
297
|
+
serverIds: serverIds
|
|
298
|
+
});
|
|
299
|
+
} catch (error) {
|
|
300
|
+
reject('上传图片失败:' + error);
|
|
301
|
+
}
|
|
289
302
|
},
|
|
290
|
-
cancel:function (){
|
|
291
|
-
reject('取消选择照片')
|
|
303
|
+
cancel: function () {
|
|
304
|
+
reject('取消选择照片');
|
|
292
305
|
}
|
|
293
|
-
})
|
|
294
|
-
}).catch((error)=>{
|
|
295
|
-
reject('微信选择照片失败:'+error)
|
|
296
|
-
})
|
|
306
|
+
});
|
|
307
|
+
}).catch((error) => {
|
|
308
|
+
reject('微信选择照片失败:' + error);
|
|
309
|
+
});
|
|
297
310
|
}
|
|
298
|
-
})
|
|
311
|
+
});
|
|
299
312
|
}
|
|
300
313
|
function getLocation(){
|
|
301
314
|
return new Promise((resolve, reject)=>{
|