Commit fa1a7f59 by 李伟康

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

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