wl-design-mobile 0.8.13 → 0.8.15
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/README.md +6 -6
- package/api/doc.js +25 -25
- package/api/x1.js +56 -56
- package/btn/components/lambo-info-btn.vue +123 -123
- package/btn/components/lambo-primary-btn.vue +117 -117
- package/btn/components/lambo-text-btn.vue +116 -116
- package/btn/lambo-btn-divide.vue +35 -35
- package/btn/lambo-btn-group.vue +46 -46
- package/btn/lambo-btn-split-line.vue +41 -41
- package/btn/lambo-btn.vue +68 -68
- package/btn/lambo-extend-btn.vue +121 -121
- package/btn/lambo-icon-btn.vue +82 -82
- package/card-item/card-row-icon.vue +71 -71
- package/card-item/filtrate-row.vue +73 -73
- package/card-item/lambo-card-footer.vue +40 -40
- package/card-item/lambo-card-head.vue +66 -66
- package/card-item/lambo-card-row.vue +59 -59
- package/collapse/lambo-collapse.vue +93 -93
- package/config/config.js +14 -14
- package/detail/lambo-detail-grid.vue +58 -58
- package/detail/lambo-detail-row.vue +59 -59
- package/doc/file/compoents/lambo-file-list.vue +42 -42
- package/doc/file/compoents/lambo-file-row.vue +77 -77
- package/doc/file/lambo-file-upload-collapse.vue +107 -107
- package/doc/file-type/file-type.js +286 -286
- package/doc/img/comonents/lambo-img-grid.vue +109 -109
- package/doc/img/lambo-img-upload-collapse.vue +107 -109
- package/doc/img/styles/css/index.css +3 -3
- package/edit/list/Lambo-edit-list.vue +87 -87
- package/edit/list/lambo-edit-card-group.vue +100 -100
- package/edit/list/styles/css/index.css +39 -39
- package/edit/select/lambo-edit-date-range.vue +147 -147
- package/edit/select/lambo-edit-date-time.vue +122 -122
- package/edit/select/lambo-edit-date.vue +120 -120
- package/edit/select/lambo-edit-input-textarea.vue +91 -91
- package/edit/select/lambo-edit-input.vue +91 -91
- package/edit/select/lambo-edit-multi-select.vue +168 -168
- package/edit/select/lambo-edit-search-single-select.vue +186 -186
- package/edit/select/lambo-edit-single-select.vue +162 -162
- package/edit/select/styles/css/index.css +133 -133
- package/flow/approval/flow-approval.vue +552 -552
- package/flow/comps/flow-attachment-list.vue +230 -230
- package/flow/comps/flow-attachment-modal.vue +194 -194
- package/flow/comps/flow-copy-users.vue +358 -358
- package/flow/comps/flow-node-card.vue +150 -150
- package/flow/comps/flow-node-header.vue +172 -172
- package/flow/comps/flow-util.js +156 -156
- package/flow/comps/icons/approved.svg +11 -11
- package/flow/comps/icons/canceled.svg +11 -11
- package/flow/comps/icons/rejected.svg +11 -11
- package/flow/comps/icons/underway.svg +11 -11
- package/flow/detail/flow-detail.vue +467 -467
- package/flow/index.js +51 -51
- package/flow/lambo-flow-detail.vue +912 -912
- package/flow/lambo-flow-edit.vue +15 -15
- package/flow/submit/flow-submit.vue +383 -383
- package/icon/lambo-required-red-star.vue +47 -47
- package/icon/lambo-vector-icon.vue +71 -71
- package/list/lambo-list.vue +412 -294
- package/nav/lambo-top-nav.vue +81 -81
- package/order/comps/icons/approved.svg +10 -10
- package/order/comps/icons/underway.svg +10 -10
- package/order/comps/order-attachment-list.vue +228 -228
- package/order/comps/order-attachment-modal.vue +194 -194
- package/order/comps/order-node-card.vue +126 -126
- package/order/comps/order-node-header.vue +133 -133
- package/order/comps/order-util.js +132 -132
- package/order/detail/order-detail.vue +432 -432
- package/order/handle/order-handle.vue +517 -517
- package/order/index.js +33 -33
- package/package.json +1 -1
- package/search/lambo-date-range-page.vue +196 -196
- package/search/lambo-date-range.vue +111 -111
- package/search/lambo-date.vue +105 -105
- package/search/lambo-input.vue +74 -74
- package/search/lambo-multi-select.vue +129 -129
- package/search/lambo-org-select-page.vue +109 -109
- package/search/lambo-search-box.vue +61 -61
- package/search/lambo-search-single-select.vue +152 -152
- package/search/lambo-single-select.vue +123 -123
- package/search/lambo-week-date-select.vue +521 -521
- package/search/styles/css/index.css +138 -138
- package/styles/base.less +77 -77
- package/styles/components/btn.less +7 -7
- package/styles/components/search.less +33 -33
- package/styles/components/tag.less +181 -181
- package/styles/index.less +4 -4
- package/table/lambo-ag-table.vue +228 -227
- package/tag/lambo-tag.vue +23 -23
- package/title/lambo-title1.vue +151 -151
- package/title/lambo-title2.vue +37 -37
- package/title/lambo-title3.vue +77 -77
- package/util/assist.js +43 -43
- package/util/axios/cacheconf.js +19 -19
- package/util/axios/index.js +11 -11
- package/util/axios/interceptors.js +101 -101
- package/util/bus.js +4 -4
- package/util/jssdk-sczy.js +104 -104
- package/util/jssdk.js +565 -565
- package/util/math.js +76 -76
- package/util/token.js +36 -36
package/util/jssdk.js
CHANGED
|
@@ -1,565 +1,565 @@
|
|
|
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
|
-
console.log('当前是企业微信环境')
|
|
44
|
-
return '20'
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
let isWx = ua.match(/MicroMessenger/i) == 'micromessenger';
|
|
48
|
-
if (isWx) {
|
|
49
|
-
if(agentId){//如果有agentId认为是企业微信
|
|
50
|
-
console.log('当前是企业微信环境')
|
|
51
|
-
return '20'
|
|
52
|
-
}
|
|
53
|
-
console.log('当前是服务号环境')
|
|
54
|
-
return '10'
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (dd.env.platform != 'notInDingTalk') {
|
|
59
|
-
console.log('当前是钉钉环境')
|
|
60
|
-
return '30'
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return ''
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* 判断ios系统版本号是否大于14
|
|
68
|
-
* @returns {boolean}
|
|
69
|
-
*/
|
|
70
|
-
const isIos14AndMore = () =>{
|
|
71
|
-
// 判断ios手机版本号是否大于14,大于14就拿App.vue存储的url,否则拿当前页面的url
|
|
72
|
-
try {
|
|
73
|
-
const str = navigator.userAgent.toLowerCase()
|
|
74
|
-
const ver = str.match(/cpu iphone os (.*?) like mac os/)
|
|
75
|
-
if (!ver) {
|
|
76
|
-
return false
|
|
77
|
-
} else {
|
|
78
|
-
return Number(ver[1].split('_')[0]) >= 14
|
|
79
|
-
}
|
|
80
|
-
} catch (e) {
|
|
81
|
-
console.log('isIos14AndMore', e)
|
|
82
|
-
return false
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function getJsConfig(){
|
|
87
|
-
let url = window.location.href.split('#')[0].toString();
|
|
88
|
-
if (isIos14AndMore() && '10' === getAppType()) {
|
|
89
|
-
console.log('isIos14AndMore true')
|
|
90
|
-
url = sessionStorage.getItem('ios14ConfigUrl')?sessionStorage.getItem('ios14ConfigUrl'):url
|
|
91
|
-
}
|
|
92
|
-
return new Promise((resolve, reject)=>{
|
|
93
|
-
axios.post(config.platformServerContext + '/api/weixin/getJsConfig', {
|
|
94
|
-
appType: getAppType(),
|
|
95
|
-
appId: sessionStorage.getItem(APP_ID),
|
|
96
|
-
agentId: sessionStorage.getItem(AGENT_ID),
|
|
97
|
-
corpId: sessionStorage.getItem(CORP_ID),
|
|
98
|
-
appKey: sessionStorage.getItem(APP_KEY),
|
|
99
|
-
url: url
|
|
100
|
-
}).then((resp) => {
|
|
101
|
-
resolve(resp.data)
|
|
102
|
-
}).catch((error) => {
|
|
103
|
-
reject(error)
|
|
104
|
-
})
|
|
105
|
-
})
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function configWx(){
|
|
109
|
-
return new Promise((resolve, reject) =>{
|
|
110
|
-
getJsConfig().then((resp)=>{
|
|
111
|
-
wx.config({
|
|
112
|
-
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
|
|
113
|
-
appId: sessionStorage.getItem(APP_ID), // 必填,公众号的唯一标识
|
|
114
|
-
timestamp: resp.timestamp, // 必填,生成签名的时间戳
|
|
115
|
-
nonceStr: resp.noncestr, // 必填,生成签名的随机串
|
|
116
|
-
signature: resp.signature, // 必填,签名
|
|
117
|
-
jsApiList: ['chooseImage', 'uploadImage', 'downloadImage', 'getLocalImgData', 'openLocation', 'getLocation', 'scanQRCode', 'chooseWXPay', 'onHistoryBack','invoke','onLocationChange','previewFile'] // 必填,需要使用的JS接口列表
|
|
118
|
-
//jsApiList: ['chooseImage', 'uploadImage', 'downloadImage', 'getLocalImgData', 'openLocation', 'getLocation', 'scanQRCode', 'chooseWXPay', 'onHistoryBack','startLocationUpdateBackground','startLocationUpdate','onLocationChange','offLocationChange'] // 必填,需要使用的JS接口列表
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
wx.ready(() => {
|
|
122
|
-
console.log('微信初始化js-sdk成功');
|
|
123
|
-
resolve()
|
|
124
|
-
});
|
|
125
|
-
wx.error(res => {
|
|
126
|
-
console.log('微信初始化js-sdk失败' + res.errMsg);
|
|
127
|
-
console.log('友情提示:当前页面URL中不能有转义后的字符!(右上角复制链接查看)');
|
|
128
|
-
reject('微信初始化js-sdk失败' + res.errMsg)
|
|
129
|
-
});
|
|
130
|
-
}).catch((error)=>{
|
|
131
|
-
reject('请求服务端jssdk签名失败:'+error)
|
|
132
|
-
})
|
|
133
|
-
})
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function getConfigSignature(url) {
|
|
137
|
-
return new Promise((resolve,reject)=>{
|
|
138
|
-
axios.post(config.platformServerContext + '/api/weixin/getJsConfig', {
|
|
139
|
-
appType: getAppType(),
|
|
140
|
-
appId: sessionStorage.getItem(APP_ID),
|
|
141
|
-
agentId: sessionStorage.getItem(AGENT_ID),
|
|
142
|
-
corpId: sessionStorage.getItem(CORP_ID),
|
|
143
|
-
appKey: sessionStorage.getItem(APP_KEY),
|
|
144
|
-
url: url.split('#')[0]
|
|
145
|
-
}).then(resp=>{
|
|
146
|
-
console.log('getConfigSignature',resp)
|
|
147
|
-
let timestamp = resp.data.timestamp
|
|
148
|
-
let nonceStr = resp.data.noncestr
|
|
149
|
-
let signature = resp.data.signature
|
|
150
|
-
resolve({ timestamp, nonceStr, signature })
|
|
151
|
-
}).catch((error)=>{
|
|
152
|
-
console.log(error)
|
|
153
|
-
reject(error)
|
|
154
|
-
})
|
|
155
|
-
})
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function configWw(){
|
|
159
|
-
return new Promise((resolve, reject) =>{
|
|
160
|
-
ww.register({
|
|
161
|
-
corpId: sessionStorage.getItem(APP_ID), // 必填,当前用户企业所属企业ID
|
|
162
|
-
jsApiList: ['chooseImage', 'uploadImage', 'downloadImage', 'getLocalImgData', 'openLocation', 'getLocation', 'scanQRCode', 'chooseWXPay', 'onHistoryBack','invoke','onLocationChange','previewFile'], // 必填,需要使用的JSAPI列表
|
|
163
|
-
getConfigSignature, // 必填,根据url生成企业签名的回调函数
|
|
164
|
-
onConfigSuccess:(res) => {
|
|
165
|
-
console.log('企业微信初始化js-sdk成功');
|
|
166
|
-
console.log(res)
|
|
167
|
-
resolve()
|
|
168
|
-
},
|
|
169
|
-
onConfigFail:(res) =>{
|
|
170
|
-
console.log('企业微信初始化js-sdk失败' + res.errMsg);
|
|
171
|
-
console.log(res)
|
|
172
|
-
reject('企业微信初始化js-sdk失败' + res.errMsg)
|
|
173
|
-
}
|
|
174
|
-
})
|
|
175
|
-
})
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function configDd(){
|
|
179
|
-
return new Promise((resolve, reject)=>{
|
|
180
|
-
getJsConfig().then((resp)=>{
|
|
181
|
-
//钉钉js-api配置
|
|
182
|
-
console.log("当前页面:"+location.href);
|
|
183
|
-
dd.config({
|
|
184
|
-
agentId:sessionStorage.getItem(AGENT_ID),
|
|
185
|
-
corpId: sessionStorage.getItem(CORP_ID), // 必填,公众号的唯一标识
|
|
186
|
-
timeStamp: resp.timestamp, // 必填,生成签名的时间戳
|
|
187
|
-
nonceStr: resp.noncestr, // 必填,生成签名的随机串
|
|
188
|
-
signature: resp.signature, // 必填,签名
|
|
189
|
-
jsApiList: [
|
|
190
|
-
'getDeviceUUID',
|
|
191
|
-
'getLocation',
|
|
192
|
-
|
|
193
|
-
] // 必填,需要使用的jsapi列表,注意:不要带dd。
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
dd.ready(() => {
|
|
197
|
-
console.log('初始化钉钉 js-sdk成功');
|
|
198
|
-
resolve()
|
|
199
|
-
});
|
|
200
|
-
dd.error(res => {
|
|
201
|
-
console.log('初始化钉钉 js-sdk失败' + JSON.stringify(res));
|
|
202
|
-
console.log('友情提示:当前页面URL中不能有转义后的字符!(右上角复制链接查看)!');
|
|
203
|
-
reject('初始化钉钉 js-sdk失败' + JSON.stringify(res))
|
|
204
|
-
});
|
|
205
|
-
}).catch((error)=>{
|
|
206
|
-
reject('请求服务端jssdk签名失败:'+error)
|
|
207
|
-
})
|
|
208
|
-
})
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
let JsSDK = (function () {
|
|
212
|
-
function scanQRCode(){
|
|
213
|
-
return new Promise((resolve, reject) =>{
|
|
214
|
-
if(getAppType() === '30'){
|
|
215
|
-
dd.scan({
|
|
216
|
-
type: 'all',
|
|
217
|
-
success: (res) => {
|
|
218
|
-
console.log('钉钉扫码结果',res)
|
|
219
|
-
resolve(res.text)
|
|
220
|
-
},
|
|
221
|
-
fail: (err) => {
|
|
222
|
-
console.log('钉钉扫码失败',err)
|
|
223
|
-
reject('钉钉扫码失败:'+err)
|
|
224
|
-
},
|
|
225
|
-
complete: () => {},
|
|
226
|
-
});
|
|
227
|
-
}else{
|
|
228
|
-
configWx().then(()=>{
|
|
229
|
-
wx.scanQRCode({
|
|
230
|
-
desc: 'scanQRCode desc',
|
|
231
|
-
needResult: 1,
|
|
232
|
-
scanType: ["qrCode", "barCode"],
|
|
233
|
-
success: function (resp) {
|
|
234
|
-
console.log("微信扫码结果:",resp)
|
|
235
|
-
let result = resp.resultStr
|
|
236
|
-
resolve(result)
|
|
237
|
-
},
|
|
238
|
-
fail: function (res) {
|
|
239
|
-
console.log("失败res=>",res)
|
|
240
|
-
if (res.errMsg.indexOf('function_not_exist') > 0) {
|
|
241
|
-
reject('版本过低请升级');
|
|
242
|
-
} else {
|
|
243
|
-
reject("微信扫码失败,请联系系统管理员!");
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
})
|
|
247
|
-
}).catch((error)=>{
|
|
248
|
-
reject('微信扫码失败:'+error)
|
|
249
|
-
})
|
|
250
|
-
}
|
|
251
|
-
})
|
|
252
|
-
}
|
|
253
|
-
function takePhoto({count = 1} = {}){
|
|
254
|
-
return new Promise((resolve, reject) =>{
|
|
255
|
-
if(getAppType() === '30'){
|
|
256
|
-
reject('钉钉不支持此方式拍照')
|
|
257
|
-
}else{
|
|
258
|
-
configWx().then(()=>{
|
|
259
|
-
wx.chooseImage({
|
|
260
|
-
count: count, // 默认1
|
|
261
|
-
sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
|
|
262
|
-
sourceType: ['camera'], // 可以指定来源是相册还是相机,默认二者都有
|
|
263
|
-
success: async function (res) {
|
|
264
|
-
let localIds = res.localIds; // 返回选定照片的本地ID列表,localId可以作为img标签的src属性显示图片
|
|
265
|
-
Toast.loading({
|
|
266
|
-
duration: 0, // 持续展示 toast
|
|
267
|
-
forbidClick: false,
|
|
268
|
-
message: '正在上传',
|
|
269
|
-
});
|
|
270
|
-
let uploadPromises = localIds.map(localId => {
|
|
271
|
-
return new Promise((resolve, reject) => {
|
|
272
|
-
wx.uploadImage({
|
|
273
|
-
localId: localId, // 需要上传的图片的本地ID,由chooseImage接口获得
|
|
274
|
-
isShowProgressTips: 0, // 默认为1,显示进度提示
|
|
275
|
-
success: function (res) {
|
|
276
|
-
let serverId = res.serverId; // 返回图片的服务器端ID
|
|
277
|
-
resolve(serverId);
|
|
278
|
-
},
|
|
279
|
-
fail: function (error) {
|
|
280
|
-
reject(error);
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
});
|
|
284
|
-
});
|
|
285
|
-
try {
|
|
286
|
-
let serverIds = await Promise.all(uploadPromises);
|
|
287
|
-
console.log('choosePhoto', serverIds)
|
|
288
|
-
Toast.clear()
|
|
289
|
-
resolve({
|
|
290
|
-
appId: sessionStorage.getItem(APP_ID),
|
|
291
|
-
agentId: sessionStorage.getItem(AGENT_ID),
|
|
292
|
-
serverId: serverIds[0],
|
|
293
|
-
serverIds: serverIds
|
|
294
|
-
});
|
|
295
|
-
} catch (error) {
|
|
296
|
-
Toast.clear()
|
|
297
|
-
reject('上传图片失败:' + error);
|
|
298
|
-
}
|
|
299
|
-
// setTimeout(() => {
|
|
300
|
-
// wx.uploadImage({
|
|
301
|
-
// localId: localId, // 需要上传的图片的本地ID,由chooseImage接口获得
|
|
302
|
-
// isShowProgressTips: 0, // 默认为1,显示进度提示
|
|
303
|
-
// success: function (res) {
|
|
304
|
-
// Toast.clear()
|
|
305
|
-
// let serverId = res.serverId; // 返回图片的服务器端ID
|
|
306
|
-
// resolve({
|
|
307
|
-
// appId:sessionStorage.getItem(APP_ID),
|
|
308
|
-
// agentId:sessionStorage.getItem(AGENT_ID),
|
|
309
|
-
// serverId:serverId
|
|
310
|
-
// })
|
|
311
|
-
// }
|
|
312
|
-
// })
|
|
313
|
-
// }, 200);
|
|
314
|
-
},
|
|
315
|
-
cancel:function (){
|
|
316
|
-
reject('取消拍照')
|
|
317
|
-
}
|
|
318
|
-
})
|
|
319
|
-
}).catch((error)=>{
|
|
320
|
-
reject('微信拍照失败:'+error)
|
|
321
|
-
})
|
|
322
|
-
}
|
|
323
|
-
})
|
|
324
|
-
}
|
|
325
|
-
function choosePhoto({count = 1} = {}) {
|
|
326
|
-
return new Promise((resolve, reject) => {
|
|
327
|
-
if (getAppType() === '30') {
|
|
328
|
-
reject('钉钉不支持此方式选择照片');
|
|
329
|
-
} else {
|
|
330
|
-
configWx().then(() => {
|
|
331
|
-
wx.chooseImage({
|
|
332
|
-
count: count, // 默认1
|
|
333
|
-
sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
|
|
334
|
-
sourceType: ['album'], // 可以指定来源是相册还是相机,默认二者都有
|
|
335
|
-
success: async function (res) {
|
|
336
|
-
let localIds = res.localIds; // 返回选定照片的本地ID列表,localId可以作为img标签的src属性显示图片
|
|
337
|
-
Toast.loading({
|
|
338
|
-
duration: 0, // 持续展示 toast
|
|
339
|
-
forbidClick: false,
|
|
340
|
-
message: '正在上传',
|
|
341
|
-
});
|
|
342
|
-
let uploadPromises = localIds.map(localId => {
|
|
343
|
-
return new Promise((resolve, reject) => {
|
|
344
|
-
wx.uploadImage({
|
|
345
|
-
localId: localId, // 需要上传的图片的本地ID,由chooseImage接口获得
|
|
346
|
-
isShowProgressTips: 0, // 默认为1,显示进度提示
|
|
347
|
-
success: function (res) {
|
|
348
|
-
let serverId = res.serverId; // 返回图片的服务器端ID
|
|
349
|
-
resolve(serverId);
|
|
350
|
-
},
|
|
351
|
-
fail: function (error) {
|
|
352
|
-
reject(error);
|
|
353
|
-
}
|
|
354
|
-
});
|
|
355
|
-
});
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
try {
|
|
359
|
-
let serverIds = await Promise.all(uploadPromises);
|
|
360
|
-
console.log('choosePhoto',serverIds)
|
|
361
|
-
Toast.clear()
|
|
362
|
-
resolve({
|
|
363
|
-
appId: sessionStorage.getItem(APP_ID),
|
|
364
|
-
agentId: sessionStorage.getItem(AGENT_ID),
|
|
365
|
-
serverId:serverIds[0],
|
|
366
|
-
serverIds: serverIds
|
|
367
|
-
});
|
|
368
|
-
} catch (error) {
|
|
369
|
-
Toast.clear()
|
|
370
|
-
reject('上传图片失败:' + error);
|
|
371
|
-
}
|
|
372
|
-
},
|
|
373
|
-
cancel: function () {
|
|
374
|
-
reject('取消选择照片');
|
|
375
|
-
}
|
|
376
|
-
});
|
|
377
|
-
}).catch((error) => {
|
|
378
|
-
reject('微信选择照片失败:' + error);
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
function getLocation(){
|
|
384
|
-
return new Promise((resolve, reject)=>{
|
|
385
|
-
if(getAppType() === '30'){
|
|
386
|
-
configDd().then(()=>{
|
|
387
|
-
dd.getLocation({
|
|
388
|
-
targetAccuracy: '200',
|
|
389
|
-
cacheTimeout: 20,
|
|
390
|
-
coordinate: '1',
|
|
391
|
-
useCache: true,
|
|
392
|
-
withReGeocode: true,
|
|
393
|
-
type: 1,
|
|
394
|
-
success: (res) => {
|
|
395
|
-
console.log('钉钉获取当前位置结果:', res)
|
|
396
|
-
resolve(res)
|
|
397
|
-
},
|
|
398
|
-
fail: (error) => {
|
|
399
|
-
console.log('钉钉获取位置失败:', error)
|
|
400
|
-
reject('钉钉获取位置失败:'+error)
|
|
401
|
-
},
|
|
402
|
-
complete: () => {},
|
|
403
|
-
})
|
|
404
|
-
}).catch((error)=>{
|
|
405
|
-
reject('钉钉获取位置失败:'+error)
|
|
406
|
-
})
|
|
407
|
-
}else{
|
|
408
|
-
configWx().then(()=>{
|
|
409
|
-
wx.getLocation({
|
|
410
|
-
type: 'gcj02', //获取gcj02的坐标
|
|
411
|
-
success: (res) => {
|
|
412
|
-
//res.longitude 获取经度
|
|
413
|
-
//res.latitude 获取纬度
|
|
414
|
-
console.log(res);
|
|
415
|
-
resolve(res)
|
|
416
|
-
}, fail: (res) => {
|
|
417
|
-
console.log("微信获取位置失败。"+JSON.stringify(res));
|
|
418
|
-
reject("微信获取位置失败" + JSON.stringify(res))
|
|
419
|
-
}
|
|
420
|
-
});
|
|
421
|
-
}).catch((error)=>{
|
|
422
|
-
reject('微信获取位置失败:'+error)
|
|
423
|
-
})
|
|
424
|
-
}
|
|
425
|
-
})
|
|
426
|
-
}
|
|
427
|
-
function openLocation({longitude,latitude,name,address,scale= 15} = {}){
|
|
428
|
-
return new Promise((resolve, reject)=>{
|
|
429
|
-
if(getAppType() === '30'){
|
|
430
|
-
configDd().then(()=>{
|
|
431
|
-
dd.openLocation({
|
|
432
|
-
title: name,
|
|
433
|
-
address: address,
|
|
434
|
-
latitude: latitude,
|
|
435
|
-
longitude: longitude,
|
|
436
|
-
success: () => {
|
|
437
|
-
resolve()
|
|
438
|
-
},
|
|
439
|
-
fail: () => {
|
|
440
|
-
reject()
|
|
441
|
-
},
|
|
442
|
-
complete: () => {
|
|
443
|
-
resolve()
|
|
444
|
-
},
|
|
445
|
-
});
|
|
446
|
-
|
|
447
|
-
}).catch((error)=>{
|
|
448
|
-
reject('钉钉启动内置地图位置失败:'+error)
|
|
449
|
-
})
|
|
450
|
-
}else{
|
|
451
|
-
configWx().then(()=>{
|
|
452
|
-
wx.openLocation({
|
|
453
|
-
latitude: latitude,//目的地latitude
|
|
454
|
-
longitude: longitude,//目的地longitude
|
|
455
|
-
name: name,
|
|
456
|
-
address: address,
|
|
457
|
-
scale: scale//地图缩放大小,可根据情况具体调整
|
|
458
|
-
});
|
|
459
|
-
resolve()
|
|
460
|
-
}).catch((error)=>{
|
|
461
|
-
reject('微信启动内置地图失败:'+error)
|
|
462
|
-
})
|
|
463
|
-
}
|
|
464
|
-
})
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
function startAutoLBS({sceneId:sceneId}){
|
|
468
|
-
return new Promise((resolve, reject)=>{
|
|
469
|
-
if(getAppType() === '30'){
|
|
470
|
-
configDd().then(()=>{
|
|
471
|
-
dd.startLocating({
|
|
472
|
-
sceneId: sceneId,
|
|
473
|
-
useCache: true,
|
|
474
|
-
withReGeocode: false,
|
|
475
|
-
targetAccuracy: 200,
|
|
476
|
-
callBackInterval: 1000,
|
|
477
|
-
iOSDistanceFilter: 10,
|
|
478
|
-
success: (res) => {
|
|
479
|
-
resolve({longitude:res.longitude,latitude:res.latitude})
|
|
480
|
-
},
|
|
481
|
-
fail: () => {
|
|
482
|
-
reject()
|
|
483
|
-
},
|
|
484
|
-
complete: () => {
|
|
485
|
-
resolve()
|
|
486
|
-
},
|
|
487
|
-
});
|
|
488
|
-
}).catch((error)=>{
|
|
489
|
-
reject('钉钉启动内置地图位置失败:'+error)
|
|
490
|
-
})
|
|
491
|
-
}else if(getAppType() === '20'){
|
|
492
|
-
configWw().then(()=>{
|
|
493
|
-
ww.startAutoLBS({
|
|
494
|
-
type: 'gcj02',
|
|
495
|
-
success:()=>{
|
|
496
|
-
ww.onLocationChange(function(event) {
|
|
497
|
-
console.log('onLocationChange',event)
|
|
498
|
-
resolve({longitude:event.longitude,latitude:event.latitude})
|
|
499
|
-
})
|
|
500
|
-
},
|
|
501
|
-
fail:()=>{
|
|
502
|
-
reject()
|
|
503
|
-
}
|
|
504
|
-
}).then(resp => {
|
|
505
|
-
console.log('企业微信开启连续定位',resp)
|
|
506
|
-
})
|
|
507
|
-
}).catch((error)=>{
|
|
508
|
-
reject('企业微信开启连续定位失败:'+error)
|
|
509
|
-
})
|
|
510
|
-
}else{
|
|
511
|
-
reject('微信不支持连续定位')
|
|
512
|
-
}
|
|
513
|
-
})
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
function stopAutoLBS({sceneId:sceneId}){
|
|
517
|
-
return new Promise((resolve, reject)=>{
|
|
518
|
-
if(getAppType() === '30'){
|
|
519
|
-
configDd().then(()=>{
|
|
520
|
-
dd.stopLocating({
|
|
521
|
-
sceneId: sceneId,
|
|
522
|
-
success: () => {
|
|
523
|
-
resolve()
|
|
524
|
-
},
|
|
525
|
-
fail: () => {
|
|
526
|
-
reject()
|
|
527
|
-
},
|
|
528
|
-
complete: () => {
|
|
529
|
-
resolve()
|
|
530
|
-
},
|
|
531
|
-
});
|
|
532
|
-
resolve()
|
|
533
|
-
}).catch((error)=>{
|
|
534
|
-
reject('钉钉启动内置地图位置失败:'+error)
|
|
535
|
-
})
|
|
536
|
-
}else if(getAppType() === '20'){
|
|
537
|
-
configWw().then(()=>{
|
|
538
|
-
ww.stopAutoLBS().then(resp => {
|
|
539
|
-
console.log(resp)
|
|
540
|
-
resolve()
|
|
541
|
-
})
|
|
542
|
-
}).catch((error)=>{
|
|
543
|
-
reject('企业微信关闭连续定位失败:'+error)
|
|
544
|
-
})
|
|
545
|
-
}else{
|
|
546
|
-
reject('微信不支持连续定位')
|
|
547
|
-
}
|
|
548
|
-
})
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
// 公开API
|
|
552
|
-
return {
|
|
553
|
-
init:init,
|
|
554
|
-
takePhoto:takePhoto,
|
|
555
|
-
choosePhoto:choosePhoto,
|
|
556
|
-
scanQRCode: scanQRCode,
|
|
557
|
-
getLocation:getLocation,
|
|
558
|
-
openLocation:openLocation,
|
|
559
|
-
startAutoLBS:startAutoLBS,
|
|
560
|
-
stopAutoLBS:stopAutoLBS,
|
|
561
|
-
};
|
|
562
|
-
})();
|
|
563
|
-
|
|
564
|
-
export default JsSDK
|
|
565
|
-
|
|
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
|
+
console.log('当前是企业微信环境')
|
|
44
|
+
return '20'
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let isWx = ua.match(/MicroMessenger/i) == 'micromessenger';
|
|
48
|
+
if (isWx) {
|
|
49
|
+
if(agentId){//如果有agentId认为是企业微信
|
|
50
|
+
console.log('当前是企业微信环境')
|
|
51
|
+
return '20'
|
|
52
|
+
}
|
|
53
|
+
console.log('当前是服务号环境')
|
|
54
|
+
return '10'
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
if (dd.env.platform != 'notInDingTalk') {
|
|
59
|
+
console.log('当前是钉钉环境')
|
|
60
|
+
return '30'
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return ''
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 判断ios系统版本号是否大于14
|
|
68
|
+
* @returns {boolean}
|
|
69
|
+
*/
|
|
70
|
+
const isIos14AndMore = () =>{
|
|
71
|
+
// 判断ios手机版本号是否大于14,大于14就拿App.vue存储的url,否则拿当前页面的url
|
|
72
|
+
try {
|
|
73
|
+
const str = navigator.userAgent.toLowerCase()
|
|
74
|
+
const ver = str.match(/cpu iphone os (.*?) like mac os/)
|
|
75
|
+
if (!ver) {
|
|
76
|
+
return false
|
|
77
|
+
} else {
|
|
78
|
+
return Number(ver[1].split('_')[0]) >= 14
|
|
79
|
+
}
|
|
80
|
+
} catch (e) {
|
|
81
|
+
console.log('isIos14AndMore', e)
|
|
82
|
+
return false
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function getJsConfig(){
|
|
87
|
+
let url = window.location.href.split('#')[0].toString();
|
|
88
|
+
if (isIos14AndMore() && '10' === getAppType()) {
|
|
89
|
+
console.log('isIos14AndMore true')
|
|
90
|
+
url = sessionStorage.getItem('ios14ConfigUrl')?sessionStorage.getItem('ios14ConfigUrl'):url
|
|
91
|
+
}
|
|
92
|
+
return new Promise((resolve, reject)=>{
|
|
93
|
+
axios.post(config.platformServerContext + '/api/weixin/getJsConfig', {
|
|
94
|
+
appType: getAppType(),
|
|
95
|
+
appId: sessionStorage.getItem(APP_ID),
|
|
96
|
+
agentId: sessionStorage.getItem(AGENT_ID),
|
|
97
|
+
corpId: sessionStorage.getItem(CORP_ID),
|
|
98
|
+
appKey: sessionStorage.getItem(APP_KEY),
|
|
99
|
+
url: url
|
|
100
|
+
}).then((resp) => {
|
|
101
|
+
resolve(resp.data)
|
|
102
|
+
}).catch((error) => {
|
|
103
|
+
reject(error)
|
|
104
|
+
})
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function configWx(){
|
|
109
|
+
return new Promise((resolve, reject) =>{
|
|
110
|
+
getJsConfig().then((resp)=>{
|
|
111
|
+
wx.config({
|
|
112
|
+
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
|
|
113
|
+
appId: sessionStorage.getItem(APP_ID), // 必填,公众号的唯一标识
|
|
114
|
+
timestamp: resp.timestamp, // 必填,生成签名的时间戳
|
|
115
|
+
nonceStr: resp.noncestr, // 必填,生成签名的随机串
|
|
116
|
+
signature: resp.signature, // 必填,签名
|
|
117
|
+
jsApiList: ['chooseImage', 'uploadImage', 'downloadImage', 'getLocalImgData', 'openLocation', 'getLocation', 'scanQRCode', 'chooseWXPay', 'onHistoryBack','invoke','onLocationChange','previewFile'] // 必填,需要使用的JS接口列表
|
|
118
|
+
//jsApiList: ['chooseImage', 'uploadImage', 'downloadImage', 'getLocalImgData', 'openLocation', 'getLocation', 'scanQRCode', 'chooseWXPay', 'onHistoryBack','startLocationUpdateBackground','startLocationUpdate','onLocationChange','offLocationChange'] // 必填,需要使用的JS接口列表
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
wx.ready(() => {
|
|
122
|
+
console.log('微信初始化js-sdk成功');
|
|
123
|
+
resolve()
|
|
124
|
+
});
|
|
125
|
+
wx.error(res => {
|
|
126
|
+
console.log('微信初始化js-sdk失败' + res.errMsg);
|
|
127
|
+
console.log('友情提示:当前页面URL中不能有转义后的字符!(右上角复制链接查看)');
|
|
128
|
+
reject('微信初始化js-sdk失败' + res.errMsg)
|
|
129
|
+
});
|
|
130
|
+
}).catch((error)=>{
|
|
131
|
+
reject('请求服务端jssdk签名失败:'+error)
|
|
132
|
+
})
|
|
133
|
+
})
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function getConfigSignature(url) {
|
|
137
|
+
return new Promise((resolve,reject)=>{
|
|
138
|
+
axios.post(config.platformServerContext + '/api/weixin/getJsConfig', {
|
|
139
|
+
appType: getAppType(),
|
|
140
|
+
appId: sessionStorage.getItem(APP_ID),
|
|
141
|
+
agentId: sessionStorage.getItem(AGENT_ID),
|
|
142
|
+
corpId: sessionStorage.getItem(CORP_ID),
|
|
143
|
+
appKey: sessionStorage.getItem(APP_KEY),
|
|
144
|
+
url: url.split('#')[0]
|
|
145
|
+
}).then(resp=>{
|
|
146
|
+
console.log('getConfigSignature',resp)
|
|
147
|
+
let timestamp = resp.data.timestamp
|
|
148
|
+
let nonceStr = resp.data.noncestr
|
|
149
|
+
let signature = resp.data.signature
|
|
150
|
+
resolve({ timestamp, nonceStr, signature })
|
|
151
|
+
}).catch((error)=>{
|
|
152
|
+
console.log(error)
|
|
153
|
+
reject(error)
|
|
154
|
+
})
|
|
155
|
+
})
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function configWw(){
|
|
159
|
+
return new Promise((resolve, reject) =>{
|
|
160
|
+
ww.register({
|
|
161
|
+
corpId: sessionStorage.getItem(APP_ID), // 必填,当前用户企业所属企业ID
|
|
162
|
+
jsApiList: ['chooseImage', 'uploadImage', 'downloadImage', 'getLocalImgData', 'openLocation', 'getLocation', 'scanQRCode', 'chooseWXPay', 'onHistoryBack','invoke','onLocationChange','previewFile'], // 必填,需要使用的JSAPI列表
|
|
163
|
+
getConfigSignature, // 必填,根据url生成企业签名的回调函数
|
|
164
|
+
onConfigSuccess:(res) => {
|
|
165
|
+
console.log('企业微信初始化js-sdk成功');
|
|
166
|
+
console.log(res)
|
|
167
|
+
resolve()
|
|
168
|
+
},
|
|
169
|
+
onConfigFail:(res) =>{
|
|
170
|
+
console.log('企业微信初始化js-sdk失败' + res.errMsg);
|
|
171
|
+
console.log(res)
|
|
172
|
+
reject('企业微信初始化js-sdk失败' + res.errMsg)
|
|
173
|
+
}
|
|
174
|
+
})
|
|
175
|
+
})
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function configDd(){
|
|
179
|
+
return new Promise((resolve, reject)=>{
|
|
180
|
+
getJsConfig().then((resp)=>{
|
|
181
|
+
//钉钉js-api配置
|
|
182
|
+
console.log("当前页面:"+location.href);
|
|
183
|
+
dd.config({
|
|
184
|
+
agentId:sessionStorage.getItem(AGENT_ID),
|
|
185
|
+
corpId: sessionStorage.getItem(CORP_ID), // 必填,公众号的唯一标识
|
|
186
|
+
timeStamp: resp.timestamp, // 必填,生成签名的时间戳
|
|
187
|
+
nonceStr: resp.noncestr, // 必填,生成签名的随机串
|
|
188
|
+
signature: resp.signature, // 必填,签名
|
|
189
|
+
jsApiList: [
|
|
190
|
+
'getDeviceUUID',
|
|
191
|
+
'getLocation',
|
|
192
|
+
|
|
193
|
+
] // 必填,需要使用的jsapi列表,注意:不要带dd。
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
dd.ready(() => {
|
|
197
|
+
console.log('初始化钉钉 js-sdk成功');
|
|
198
|
+
resolve()
|
|
199
|
+
});
|
|
200
|
+
dd.error(res => {
|
|
201
|
+
console.log('初始化钉钉 js-sdk失败' + JSON.stringify(res));
|
|
202
|
+
console.log('友情提示:当前页面URL中不能有转义后的字符!(右上角复制链接查看)!');
|
|
203
|
+
reject('初始化钉钉 js-sdk失败' + JSON.stringify(res))
|
|
204
|
+
});
|
|
205
|
+
}).catch((error)=>{
|
|
206
|
+
reject('请求服务端jssdk签名失败:'+error)
|
|
207
|
+
})
|
|
208
|
+
})
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
let JsSDK = (function () {
|
|
212
|
+
function scanQRCode(){
|
|
213
|
+
return new Promise((resolve, reject) =>{
|
|
214
|
+
if(getAppType() === '30'){
|
|
215
|
+
dd.scan({
|
|
216
|
+
type: 'all',
|
|
217
|
+
success: (res) => {
|
|
218
|
+
console.log('钉钉扫码结果',res)
|
|
219
|
+
resolve(res.text)
|
|
220
|
+
},
|
|
221
|
+
fail: (err) => {
|
|
222
|
+
console.log('钉钉扫码失败',err)
|
|
223
|
+
reject('钉钉扫码失败:'+err)
|
|
224
|
+
},
|
|
225
|
+
complete: () => {},
|
|
226
|
+
});
|
|
227
|
+
}else{
|
|
228
|
+
configWx().then(()=>{
|
|
229
|
+
wx.scanQRCode({
|
|
230
|
+
desc: 'scanQRCode desc',
|
|
231
|
+
needResult: 1,
|
|
232
|
+
scanType: ["qrCode", "barCode"],
|
|
233
|
+
success: function (resp) {
|
|
234
|
+
console.log("微信扫码结果:",resp)
|
|
235
|
+
let result = resp.resultStr
|
|
236
|
+
resolve(result)
|
|
237
|
+
},
|
|
238
|
+
fail: function (res) {
|
|
239
|
+
console.log("失败res=>",res)
|
|
240
|
+
if (res.errMsg.indexOf('function_not_exist') > 0) {
|
|
241
|
+
reject('版本过低请升级');
|
|
242
|
+
} else {
|
|
243
|
+
reject("微信扫码失败,请联系系统管理员!");
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
})
|
|
247
|
+
}).catch((error)=>{
|
|
248
|
+
reject('微信扫码失败:'+error)
|
|
249
|
+
})
|
|
250
|
+
}
|
|
251
|
+
})
|
|
252
|
+
}
|
|
253
|
+
function takePhoto({count = 1} = {}){
|
|
254
|
+
return new Promise((resolve, reject) =>{
|
|
255
|
+
if(getAppType() === '30'){
|
|
256
|
+
reject('钉钉不支持此方式拍照')
|
|
257
|
+
}else{
|
|
258
|
+
configWx().then(()=>{
|
|
259
|
+
wx.chooseImage({
|
|
260
|
+
count: count, // 默认1
|
|
261
|
+
sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
|
|
262
|
+
sourceType: ['camera'], // 可以指定来源是相册还是相机,默认二者都有
|
|
263
|
+
success: async function (res) {
|
|
264
|
+
let localIds = res.localIds; // 返回选定照片的本地ID列表,localId可以作为img标签的src属性显示图片
|
|
265
|
+
Toast.loading({
|
|
266
|
+
duration: 0, // 持续展示 toast
|
|
267
|
+
forbidClick: false,
|
|
268
|
+
message: '正在上传',
|
|
269
|
+
});
|
|
270
|
+
let uploadPromises = localIds.map(localId => {
|
|
271
|
+
return new Promise((resolve, reject) => {
|
|
272
|
+
wx.uploadImage({
|
|
273
|
+
localId: localId, // 需要上传的图片的本地ID,由chooseImage接口获得
|
|
274
|
+
isShowProgressTips: 0, // 默认为1,显示进度提示
|
|
275
|
+
success: function (res) {
|
|
276
|
+
let serverId = res.serverId; // 返回图片的服务器端ID
|
|
277
|
+
resolve(serverId);
|
|
278
|
+
},
|
|
279
|
+
fail: function (error) {
|
|
280
|
+
reject(error);
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
try {
|
|
286
|
+
let serverIds = await Promise.all(uploadPromises);
|
|
287
|
+
console.log('choosePhoto', serverIds)
|
|
288
|
+
Toast.clear()
|
|
289
|
+
resolve({
|
|
290
|
+
appId: sessionStorage.getItem(APP_ID),
|
|
291
|
+
agentId: sessionStorage.getItem(AGENT_ID),
|
|
292
|
+
serverId: serverIds[0],
|
|
293
|
+
serverIds: serverIds
|
|
294
|
+
});
|
|
295
|
+
} catch (error) {
|
|
296
|
+
Toast.clear()
|
|
297
|
+
reject('上传图片失败:' + error);
|
|
298
|
+
}
|
|
299
|
+
// setTimeout(() => {
|
|
300
|
+
// wx.uploadImage({
|
|
301
|
+
// localId: localId, // 需要上传的图片的本地ID,由chooseImage接口获得
|
|
302
|
+
// isShowProgressTips: 0, // 默认为1,显示进度提示
|
|
303
|
+
// success: function (res) {
|
|
304
|
+
// Toast.clear()
|
|
305
|
+
// let serverId = res.serverId; // 返回图片的服务器端ID
|
|
306
|
+
// resolve({
|
|
307
|
+
// appId:sessionStorage.getItem(APP_ID),
|
|
308
|
+
// agentId:sessionStorage.getItem(AGENT_ID),
|
|
309
|
+
// serverId:serverId
|
|
310
|
+
// })
|
|
311
|
+
// }
|
|
312
|
+
// })
|
|
313
|
+
// }, 200);
|
|
314
|
+
},
|
|
315
|
+
cancel:function (){
|
|
316
|
+
reject('取消拍照')
|
|
317
|
+
}
|
|
318
|
+
})
|
|
319
|
+
}).catch((error)=>{
|
|
320
|
+
reject('微信拍照失败:'+error)
|
|
321
|
+
})
|
|
322
|
+
}
|
|
323
|
+
})
|
|
324
|
+
}
|
|
325
|
+
function choosePhoto({count = 1} = {}) {
|
|
326
|
+
return new Promise((resolve, reject) => {
|
|
327
|
+
if (getAppType() === '30') {
|
|
328
|
+
reject('钉钉不支持此方式选择照片');
|
|
329
|
+
} else {
|
|
330
|
+
configWx().then(() => {
|
|
331
|
+
wx.chooseImage({
|
|
332
|
+
count: count, // 默认1
|
|
333
|
+
sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
|
|
334
|
+
sourceType: ['album'], // 可以指定来源是相册还是相机,默认二者都有
|
|
335
|
+
success: async function (res) {
|
|
336
|
+
let localIds = res.localIds; // 返回选定照片的本地ID列表,localId可以作为img标签的src属性显示图片
|
|
337
|
+
Toast.loading({
|
|
338
|
+
duration: 0, // 持续展示 toast
|
|
339
|
+
forbidClick: false,
|
|
340
|
+
message: '正在上传',
|
|
341
|
+
});
|
|
342
|
+
let uploadPromises = localIds.map(localId => {
|
|
343
|
+
return new Promise((resolve, reject) => {
|
|
344
|
+
wx.uploadImage({
|
|
345
|
+
localId: localId, // 需要上传的图片的本地ID,由chooseImage接口获得
|
|
346
|
+
isShowProgressTips: 0, // 默认为1,显示进度提示
|
|
347
|
+
success: function (res) {
|
|
348
|
+
let serverId = res.serverId; // 返回图片的服务器端ID
|
|
349
|
+
resolve(serverId);
|
|
350
|
+
},
|
|
351
|
+
fail: function (error) {
|
|
352
|
+
reject(error);
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
});
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
try {
|
|
359
|
+
let serverIds = await Promise.all(uploadPromises);
|
|
360
|
+
console.log('choosePhoto',serverIds)
|
|
361
|
+
Toast.clear()
|
|
362
|
+
resolve({
|
|
363
|
+
appId: sessionStorage.getItem(APP_ID),
|
|
364
|
+
agentId: sessionStorage.getItem(AGENT_ID),
|
|
365
|
+
serverId:serverIds[0],
|
|
366
|
+
serverIds: serverIds
|
|
367
|
+
});
|
|
368
|
+
} catch (error) {
|
|
369
|
+
Toast.clear()
|
|
370
|
+
reject('上传图片失败:' + error);
|
|
371
|
+
}
|
|
372
|
+
},
|
|
373
|
+
cancel: function () {
|
|
374
|
+
reject('取消选择照片');
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
}).catch((error) => {
|
|
378
|
+
reject('微信选择照片失败:' + error);
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
function getLocation(){
|
|
384
|
+
return new Promise((resolve, reject)=>{
|
|
385
|
+
if(getAppType() === '30'){
|
|
386
|
+
configDd().then(()=>{
|
|
387
|
+
dd.getLocation({
|
|
388
|
+
targetAccuracy: '200',
|
|
389
|
+
cacheTimeout: 20,
|
|
390
|
+
coordinate: '1',
|
|
391
|
+
useCache: true,
|
|
392
|
+
withReGeocode: true,
|
|
393
|
+
type: 1,
|
|
394
|
+
success: (res) => {
|
|
395
|
+
console.log('钉钉获取当前位置结果:', res)
|
|
396
|
+
resolve(res)
|
|
397
|
+
},
|
|
398
|
+
fail: (error) => {
|
|
399
|
+
console.log('钉钉获取位置失败:', error)
|
|
400
|
+
reject('钉钉获取位置失败:'+error)
|
|
401
|
+
},
|
|
402
|
+
complete: () => {},
|
|
403
|
+
})
|
|
404
|
+
}).catch((error)=>{
|
|
405
|
+
reject('钉钉获取位置失败:'+error)
|
|
406
|
+
})
|
|
407
|
+
}else{
|
|
408
|
+
configWx().then(()=>{
|
|
409
|
+
wx.getLocation({
|
|
410
|
+
type: 'gcj02', //获取gcj02的坐标
|
|
411
|
+
success: (res) => {
|
|
412
|
+
//res.longitude 获取经度
|
|
413
|
+
//res.latitude 获取纬度
|
|
414
|
+
console.log(res);
|
|
415
|
+
resolve(res)
|
|
416
|
+
}, fail: (res) => {
|
|
417
|
+
console.log("微信获取位置失败。"+JSON.stringify(res));
|
|
418
|
+
reject("微信获取位置失败" + JSON.stringify(res))
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
}).catch((error)=>{
|
|
422
|
+
reject('微信获取位置失败:'+error)
|
|
423
|
+
})
|
|
424
|
+
}
|
|
425
|
+
})
|
|
426
|
+
}
|
|
427
|
+
function openLocation({longitude,latitude,name,address,scale= 15} = {}){
|
|
428
|
+
return new Promise((resolve, reject)=>{
|
|
429
|
+
if(getAppType() === '30'){
|
|
430
|
+
configDd().then(()=>{
|
|
431
|
+
dd.openLocation({
|
|
432
|
+
title: name,
|
|
433
|
+
address: address,
|
|
434
|
+
latitude: latitude,
|
|
435
|
+
longitude: longitude,
|
|
436
|
+
success: () => {
|
|
437
|
+
resolve()
|
|
438
|
+
},
|
|
439
|
+
fail: () => {
|
|
440
|
+
reject()
|
|
441
|
+
},
|
|
442
|
+
complete: () => {
|
|
443
|
+
resolve()
|
|
444
|
+
},
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
}).catch((error)=>{
|
|
448
|
+
reject('钉钉启动内置地图位置失败:'+error)
|
|
449
|
+
})
|
|
450
|
+
}else{
|
|
451
|
+
configWx().then(()=>{
|
|
452
|
+
wx.openLocation({
|
|
453
|
+
latitude: latitude,//目的地latitude
|
|
454
|
+
longitude: longitude,//目的地longitude
|
|
455
|
+
name: name,
|
|
456
|
+
address: address,
|
|
457
|
+
scale: scale//地图缩放大小,可根据情况具体调整
|
|
458
|
+
});
|
|
459
|
+
resolve()
|
|
460
|
+
}).catch((error)=>{
|
|
461
|
+
reject('微信启动内置地图失败:'+error)
|
|
462
|
+
})
|
|
463
|
+
}
|
|
464
|
+
})
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
function startAutoLBS({sceneId:sceneId}){
|
|
468
|
+
return new Promise((resolve, reject)=>{
|
|
469
|
+
if(getAppType() === '30'){
|
|
470
|
+
configDd().then(()=>{
|
|
471
|
+
dd.startLocating({
|
|
472
|
+
sceneId: sceneId,
|
|
473
|
+
useCache: true,
|
|
474
|
+
withReGeocode: false,
|
|
475
|
+
targetAccuracy: 200,
|
|
476
|
+
callBackInterval: 1000,
|
|
477
|
+
iOSDistanceFilter: 10,
|
|
478
|
+
success: (res) => {
|
|
479
|
+
resolve({longitude:res.longitude,latitude:res.latitude})
|
|
480
|
+
},
|
|
481
|
+
fail: () => {
|
|
482
|
+
reject()
|
|
483
|
+
},
|
|
484
|
+
complete: () => {
|
|
485
|
+
resolve()
|
|
486
|
+
},
|
|
487
|
+
});
|
|
488
|
+
}).catch((error)=>{
|
|
489
|
+
reject('钉钉启动内置地图位置失败:'+error)
|
|
490
|
+
})
|
|
491
|
+
}else if(getAppType() === '20'){
|
|
492
|
+
configWw().then(()=>{
|
|
493
|
+
ww.startAutoLBS({
|
|
494
|
+
type: 'gcj02',
|
|
495
|
+
success:()=>{
|
|
496
|
+
ww.onLocationChange(function(event) {
|
|
497
|
+
console.log('onLocationChange',event)
|
|
498
|
+
resolve({longitude:event.longitude,latitude:event.latitude})
|
|
499
|
+
})
|
|
500
|
+
},
|
|
501
|
+
fail:()=>{
|
|
502
|
+
reject()
|
|
503
|
+
}
|
|
504
|
+
}).then(resp => {
|
|
505
|
+
console.log('企业微信开启连续定位',resp)
|
|
506
|
+
})
|
|
507
|
+
}).catch((error)=>{
|
|
508
|
+
reject('企业微信开启连续定位失败:'+error)
|
|
509
|
+
})
|
|
510
|
+
}else{
|
|
511
|
+
reject('微信不支持连续定位')
|
|
512
|
+
}
|
|
513
|
+
})
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
function stopAutoLBS({sceneId:sceneId}){
|
|
517
|
+
return new Promise((resolve, reject)=>{
|
|
518
|
+
if(getAppType() === '30'){
|
|
519
|
+
configDd().then(()=>{
|
|
520
|
+
dd.stopLocating({
|
|
521
|
+
sceneId: sceneId,
|
|
522
|
+
success: () => {
|
|
523
|
+
resolve()
|
|
524
|
+
},
|
|
525
|
+
fail: () => {
|
|
526
|
+
reject()
|
|
527
|
+
},
|
|
528
|
+
complete: () => {
|
|
529
|
+
resolve()
|
|
530
|
+
},
|
|
531
|
+
});
|
|
532
|
+
resolve()
|
|
533
|
+
}).catch((error)=>{
|
|
534
|
+
reject('钉钉启动内置地图位置失败:'+error)
|
|
535
|
+
})
|
|
536
|
+
}else if(getAppType() === '20'){
|
|
537
|
+
configWw().then(()=>{
|
|
538
|
+
ww.stopAutoLBS().then(resp => {
|
|
539
|
+
console.log(resp)
|
|
540
|
+
resolve()
|
|
541
|
+
})
|
|
542
|
+
}).catch((error)=>{
|
|
543
|
+
reject('企业微信关闭连续定位失败:'+error)
|
|
544
|
+
})
|
|
545
|
+
}else{
|
|
546
|
+
reject('微信不支持连续定位')
|
|
547
|
+
}
|
|
548
|
+
})
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
// 公开API
|
|
552
|
+
return {
|
|
553
|
+
init:init,
|
|
554
|
+
takePhoto:takePhoto,
|
|
555
|
+
choosePhoto:choosePhoto,
|
|
556
|
+
scanQRCode: scanQRCode,
|
|
557
|
+
getLocation:getLocation,
|
|
558
|
+
openLocation:openLocation,
|
|
559
|
+
startAutoLBS:startAutoLBS,
|
|
560
|
+
stopAutoLBS:stopAutoLBS,
|
|
561
|
+
};
|
|
562
|
+
})();
|
|
563
|
+
|
|
564
|
+
export default JsSDK
|
|
565
|
+
|