Commit fa1a7f59 by 李伟康

wx is not defined 增加刷新页面提示

1 parent 7584082c
......@@ -3,14 +3,15 @@ import { Notify } from 'vant'
let requestCount = 0
let wwRequestCount = 0
const WxConfig = {
async init(jsApiList = []) {
async init (jsApiList = []) {
const isWxWork = window.$ISWXWORK
jsApiList.map(e => {
if (e == 'chooseImage') jsApiList.push('getLocalImgData')
})
await this[isWxWork ? 'getWWConfig' : 'getWxConfig'](jsApiList)
},
getWWConfig(jsApiList) {
/**企微 */
getWWConfig (jsApiList) {
wwRequestCount += 1
let [redirectUrl] = window.location.href.split('#')
return new Promise(resolve => {
......@@ -39,10 +40,10 @@ const WxConfig = {
nonceStr: data.nonceStr, // 必填,生成签名的随机串
signature: data.signature, // 必填,签名,见附录-JS-SDK使用权限签名算法,
jsApiList: ['getContext', ...jsApiList],
success(res) {
success (res) {
resolve()
},
fail(err) {
fail (err) {
Notify(message)
// util.refreshPage(JSONStringify(err)).then(() => {
// window.location.reload()
......@@ -71,7 +72,8 @@ const WxConfig = {
})
})
},
getWxConfig(jsApiList) {
/**微信 */
getWxConfig (jsApiList) {
requestCount += 1
let [redirectUrl] = window.location.href.split('#')
return new Promise(resolve => {
......@@ -92,12 +94,28 @@ const WxConfig = {
Object.keys(data).map(key => {
if (data[key]) obj[key] = data[key]
})
wx.config({
...obj,
jsApiList,
openTagList: ['wx-open-launch-weapp']
})
resolve()
try {
if (wx) {
wx.config({
...obj,
jsApiList,
openTagList: ['wx-open-launch-weapp']
})
resolve()
} else throw false
} catch (error) {
util.refreshPage('加载wxconfig失败','重试').then(() => {
window.location.reload()
})
}
// window.WXJDK.onload = e => {
// wx.config({
// ...obj,
// jsApiList,
// openTagList: ['wx-open-launch-weapp']
// })
// resolve()
// }
} else {
if (requestCount < 3) this.getWxConfig(jsApiList)
else {
......@@ -118,7 +136,7 @@ const WxConfig = {
})
})
},
ready(callBack) {
ready (callBack) {
const isWxWork = window.$ISWXWORK
return new Promise((resolve, reject) => {
if (isWxWork)
......@@ -152,18 +170,18 @@ const WxConfig = {
})
},
/**获取地理位置接口 */
getLocation(type = 'gcj02') {
getLocation (type = 'gcj02') {
return this.ready(resolve => {
wx.getLocation({
type, // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
success(res) {
success (res) {
resolve(res)
}
})
})
},
/**打开地图导航 */
openLocation(params) {
openLocation (params) {
return this.ready(resolve => {
let { latitude, longitude, name, address, scale = '18', infoUrl = '' } = params
wx.openLocation({
......@@ -173,7 +191,7 @@ const WxConfig = {
address,
scale,
infoUrl,
success(res) {
success (res) {
console.log(res)
resolve(res)
}
......@@ -181,7 +199,7 @@ const WxConfig = {
})
},
/**支付 */
chooseWXPay({ timestamp, nonceStr, packages, signType, paySign }) {
chooseWXPay ({ timestamp, nonceStr, packages, signType, paySign }) {
return this.ready(resolve => {
wx.chooseWXPay({
timestamp, // 支付签名时间戳,注意微信js sdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
......@@ -189,21 +207,21 @@ const WxConfig = {
package: packages, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=\*\*\*)
signType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
paySign, // 支付签名
success(res) {
success (res) {
window.vm.showToast('支付成功')
resolve(res)
},
fail() {
fail () {
window.vm.showToast('已取消支付')
},
cancel() {
cancel () {
window.vm.showToast('支付失败,请重试')
}
})
})
},
/**设置分享内容 */
updateAppMessageShareData(params) {
updateAppMessageShareData (params) {
// title, // 分享标题
// desc: '', // 分享描述
// link: '', // 分享链接,该链接域名或路径必须与当前页面对应的公众号 JS 安全域名一致
......@@ -219,7 +237,7 @@ const WxConfig = {
})
},
/**分享朋友圈内容 */
updateTimelineShareData(params) {
updateTimelineShareData (params) {
delete params.desc
// title, // 分享标题
// link: '', // 分享链接,该链接域名或路径必须与当前页面对应的公众号 JS 安全域名一致
......@@ -243,7 +261,7 @@ const WxConfig = {
* type: '', // 分享类型,music、video或link,不填默认为link
* dataUrl: '', // 如果 type 是music或video,则要提供数据链接,默认为空
*/
onMenuShareAppMessage(params) {
onMenuShareAppMessage (params) {
return new Promise(resolve => {
wx.onMenuShareAppMessage({
success: function () {
......@@ -255,7 +273,7 @@ const WxConfig = {
})
},
/**获取“分享到朋友圈”按钮点击状态及自定义分享内容接口(即将废弃) */
onMenuShareTimeline(params) {
onMenuShareTimeline (params) {
delete params.desc
return new Promise(resolve => {
wx.onMenuShareTimeline({
......@@ -268,7 +286,7 @@ const WxConfig = {
})
},
/**企微自定义转发到会话 */
shareAppMessage(params) {
shareAppMessage (params) {
// title: '', // 分享标题
// desc: '', // 分享描述
// link: '', // 分享链接
......@@ -287,7 +305,7 @@ const WxConfig = {
"path": "pages/home/index.html", // 所需跳转的小程序内页面路径及参数。非必填
*
*/
launchMiniprogram(params) {
launchMiniprogram (params) {
return new Promise((resolve, reject) => {
wx.invoke('launchMiniprogram', params, function (res) {
if (res.err_msg == 'launchMiniprogram:ok') resolve(res)
......
......@@ -68,19 +68,22 @@ let body = document.getElementsByTagName('head')[0],
ISWXWORK = false,
IsIOS = /(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent),
ISMiniprogram = window.__wxjs_environment === 'miniprogram'
window.WXJDK = WXJDK
WXJDK.src = '//res.wx.qq.com/open/js/jweixin-1.6.0.js'
// WXJDK.src = `//res.wx.qq.com/open/js/jweixin-1.6.0.js?${Date.now()}`
if (Boolean(ua.match(/MicroMessenger/i)) && Boolean(ua.match(/wxwork/i))) {
//是否企微
WXJDK.src = '//res.wx.qq.com/open/js/jweixin-1.2.0.js'
WWJDK.src = '//open.work.weixin.qq.com/wwopen/js/jwxwork-1.0.0.js'
ISWXWORK = true
}
body.appendChild(WXJDK)
if (WWJDK.src) body.appendChild(WWJDK)
window.$ISWXWORK = ISWXWORK
util.setLocalStorage('is_wxwork', ISWXWORK)
Vue.prototype.ISWXWORK = ISWXWORK
Vue.prototype.ISMOBILE = util.isMobileDevice()
body.appendChild(WXJDK)
if (WWJDK.src) body.appendChild(WWJDK)
window.$IsIOS = IsIOS
Vue.prototype.IsIOS = IsIOS
window.$ISMiniprogram = ISMiniprogram
......
......@@ -162,18 +162,18 @@ const jumpChildrenPage = (to, params) => {
const setClipboardData = data => {
wx.setClipboardData({
data,
success(res) {
success (res) {
Toast('复制成功')
}
})
}
/**接口请求时失败让用户刷新 */
const refreshPage = (message = '系统异常') => {
const refreshPage = (message = '系统异常', confirmButtonText) => {
return Dialog.alert({
message,
theme: 'round-button',
confirmButtonText: '点击重试',
confirmButtonText: confirmButtonText || '点击重试',
confirmButtonColor: '#f13c3d'
})
}
......@@ -270,7 +270,7 @@ const draggable = (drag, fun, target) => {
var disX, disY, left, top, starX, starY, oLeft, oTop
drag.addEventListener(startEvt, startFun)
function startFun(event) {
function startFun (event) {
// console.log('event', )
let className = event.target.className
if (!drag.id || className.includes(target)) return
......@@ -292,7 +292,7 @@ const draggable = (drag, fun, target) => {
document.addEventListener(endEvt, endFun)
}
function moveFun(event) {
function moveFun (event) {
// 兼容IE浏览器
var e = event || window.event
left = (e.touches ? e.touches[0].clientX : e.clientX) - disX
......@@ -312,7 +312,7 @@ const draggable = (drag, fun, target) => {
drag.style.left = left + 'px'
drag.style.top = top + 'px'
}
function endFun(event) {
function endFun (event) {
drag.style.cursor = ''
document.removeEventListener(moveEvt, moveFun)
document.removeEventListener(endEvt, endFun)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!