wxConfig.js
3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import util from '@/utils/util'
import { Notify } from 'vant'
const WxConfig = {
init (jsApiList) {
return new Promise((resolve, reject) => {
jsApiList.map(e => {
if (e == 'chooseImage') jsApiList.push('getLocalImgData')
})
let [redirectUrl] = window.location.href.split('#')
let appId = util.getAppId()
return window.$HTTP({
url: '/rop-scrm-equity/router',
data: {
url: redirectUrl,
appId,
method: 'scrm.api.equity.common.wechat.jsconfig'
}
}).then(data => {
if (data) {
let obj = {}
Object.keys(data).map(key => {
if (data[key]) obj[key] = data[key]
})
wx.config({
...obj,
jsApiList,
openTagList: ['wx-open-launch-weapp']
})
resolve()
} else {
reject()
Notify('网络异常')
}
})
})
},
ready (callBack) {
return new Promise((resolve, reject) => {
wx.ready(() => {
callBack(resolve, reject)
})
})
},
/**获取地理位置接口 */
getLocation (type = 'gcj02') {
return this.ready((resolve) => {
wx.getLocation({
type, // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
success (res) {
resolve(res)
}
})
})
},
openLocation (params) {
return this.ready(resolve => {
let { latitude, longitude, name, address, scale = '18', infoUrl = '' } = params
wx.openLocation({
latitude,
longitude,
name,
address,
scale,
infoUrl,
success (res) {
console.log(res)
resolve(res)
}
})
})
},
/**支付 */
chooseWXPay ({ timestamp, nonceStr, packages, signType, paySign }) {
return this.ready(resolve => {
wx.chooseWXPay({
timestamp, // 支付签名时间戳,注意微信js sdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
nonceStr, // 支付签名随机串,不长于 32 位
package: packages, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=\*\*\*)
signType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
paySign, // 支付签名
success (res) {
window.vm.showToast('支付成功')
resolve(res)
},
fail () {
window.vm.showToast('已取消支付')
},
cancel () {
window.vm.showToast('支付失败,请重试')
}
})
})
},
updateAppMessageShareData (params) {
// title, // 分享标题
// desc: '', // 分享描述
// link: '', // 分享链接,该链接域名或路径必须与当前页面对应的公众号 JS 安全域名一致
// imgUrl: '', // 分享图标
return this.ready(resolve => {
wx.updateAppMessageShareData({
...params,
success: function () {
resolve()
// 设置成功
}
})
})
}
}
export default WxConfig