Commit d3967981 by 李伟康

修改地址交互、获取微信config增加重载

1 parent ee60db15
import util from '@/utils/util' import util from '@/utils/util'
import { Notify } from 'vant' import { Notify } from 'vant'
let requestCount = 0
let wwRequestCount = 0
const WxConfig = { const WxConfig = {
init (jsApiList = []) { init (jsApiList = []) {
const isWxWork = window.$ISWXWORK const isWxWork = window.$ISWXWORK
...@@ -7,29 +9,43 @@ const WxConfig = { ...@@ -7,29 +9,43 @@ const WxConfig = {
jsApiList.map(e => { jsApiList.map(e => {
if (e == 'chooseImage') jsApiList.push('getLocalImgData') if (e == 'chooseImage') jsApiList.push('getLocalImgData')
}) })
let [redirectUrl] = window.location.href.split('#')
if (isWxWork) { if (isWxWork) {
const STORAGE_PARAMS = util.getLocalStorage('wx_scrm_link_params') return this.getWWConfig(jsApiList).then(() => {
let data = { resolve()
corpId: STORAGE_PARAMS.corpId, })
method: 'scrm.api.work.wechat.get.agent.config', } else {
url: redirectUrl, return this.getWxConfig(jsApiList).then(() => {
appCode: 'DJQWGJ' resolve()
} })
this.getWxConfig(jsApiList).then(() => { }
console.log('wxconfig') })
wx.ready(() => { },
window.$HTTP({ getWWConfig (jsApiList) {
url: '/rop-scrm-wechat/router', wwRequestCount += 1
data let [redirectUrl] = window.location.href.split('#')
}).then(obj => { return new Promise((resolve) => {
if (obj) { const STORAGE_PARAMS = util.getLocalStorage('wx_scrm_link_params')
let data = {
corpId: STORAGE_PARAMS.corpId,
method: 'scrm.api.work.wechat.get.agent.config',
url: redirectUrl,
appCode: 'DJQWGJ'
}
this.getWxConfig(jsApiList).then(() => {
wx.ready(() => {
window.$HTTP({
url: '/rop-scrm-wechat/router',
data,
returnAll: true
}).then(({ code, data, message }) => {
if (code == '0') {
if (data) {
wx.agentConfig({ wx.agentConfig({
corpid: obj.corpId, // 必填,企业微信的corpid,必须与当前登录的企业一致 corpid: data.corpId, // 必填,企业微信的corpid,必须与当前登录的企业一致
agentid: obj.agentId, // 必填,企业微信的应用id (e.g. 1000247) agentid: data.agentId, // 必填,企业微信的应用id (e.g. 1000247)
timestamp: obj.timestamp, // 必填,生成签名的时间戳 timestamp: data.timestamp, // 必填,生成签名的时间戳
nonceStr: obj.nonceStr, // 必填,生成签名的随机串 nonceStr: data.nonceStr, // 必填,生成签名的随机串
signature: obj.signature, // 必填,签名,见附录-JS-SDK使用权限签名算法, signature: data.signature, // 必填,签名,见附录-JS-SDK使用权限签名算法,
jsApiList: ['getContext', ...jsApiList], jsApiList: ['getContext', ...jsApiList],
success (res) { success (res) {
console.log(res, 'ww_config') console.log(res, 'ww_config')
...@@ -37,47 +53,62 @@ const WxConfig = { ...@@ -37,47 +53,62 @@ const WxConfig = {
}, },
fail (err) { fail (err) {
console.log(err, 'ww_config') console.log(err, 'ww_config')
reject(err) Notify(JSONStringify(err))
} }
}) })
} else { } else {
Notify('网络异常') if (wwRequestCount < 3) this.getWWConfig(jsApiList)
else util.refreshPage('获取WWCONFIG失败').then(() => {
window.location.reload()
})
} }
}) } else {
if (wwRequestCount < 3) this.getWWConfig(jsApiList)
else util.refreshPage(message).then(() => {
window.location.reload()
})
}
}) })
}) })
} else { })
return this.getWxConfig(jsApiList).then(() => {
resolve()
})
}
}) })
}, },
getWxConfig (jsApiList) { getWxConfig (jsApiList) {
requestCount += 1
let [redirectUrl] = window.location.href.split('#') let [redirectUrl] = window.location.href.split('#')
return new Promise((resolve, reject) => { return new Promise((resolve) => {
window.$HTTP({ window.$HTTP({
url: '/rop-scrm-equity/router', url: '/rop-scrm-equity/router',
data: { data: {
url: redirectUrl, url: redirectUrl,
appId: window.$fetchConfig.appid, appId: window.$fetchConfig.appid,
method: 'scrm.api.equity.common.wechat.jsconfig' method: 'scrm.api.equity.common.wechat.jsconfig'
} },
}).then(data => { returnAll: true
if (data) { }).then(({ code, data, message }) => {
let obj = {} if (code == '0') {
Object.keys(data).map(key => { if (data) {
if (data[key]) obj[key] = data[key] let obj = {}
}) Object.keys(data).map(key => {
wx.config({ if (data[key]) obj[key] = data[key]
...obj, })
jsApiList, wx.config({
openTagList: ['wx-open-launch-weapp'] ...obj,
}) jsApiList,
resolve() openTagList: ['wx-open-launch-weapp']
})
resolve()
} else {
if (requestCount < 3) this.getWxConfig(jsApiList)
else util.refreshPage('获取WXCONFIG失败').then(() => {
window.location.reload()
})
}
} else { } else {
reject() if (requestCount < 3) this.getWxConfig(jsApiList)
Notify('网络异常') else util.refreshPage(message).then(() => {
window.location.reload()
})
} }
}) })
}) })
......
...@@ -198,6 +198,9 @@ ...@@ -198,6 +198,9 @@
.icon-address { .icon-address {
margin: 0 auto; margin: 0 auto;
} }
.auth-text{
font-size: 8px;
}
} }
} }
......
...@@ -173,7 +173,7 @@ const refreshPage = (message = '系统异常') => { ...@@ -173,7 +173,7 @@ const refreshPage = (message = '系统异常') => {
message, message,
theme: 'round-button', theme: 'round-button',
confirmButtonText: '点击重试', confirmButtonText: '点击重试',
confirmButtonColor: '#FF7336' confirmButtonColor: '#f13c3d'
}) })
} }
const toTop = () => { const toTop = () => {
......
...@@ -94,10 +94,16 @@ ...@@ -94,10 +94,16 @@
<div <div
class="address-btn" class="address-btn"
:key="distanceKey" :key="distanceKey"
@click="openLocation" @click="authLocation(detail)"
> >
<div class="sprite-icon icon-address"></div> <div class="sprite-icon icon-address"></div>
<template v-if="detail.distance">{{ detail.distance }}km</template> <template v-if="detail.distance">{{ detail.distance }}km</template>
<template v-else>
<div class="auth-text">
获取门店距离
</div>
</template>
</div> </div>
</template> </template>
</div> </div>
...@@ -313,17 +319,21 @@ export default { ...@@ -313,17 +319,21 @@ export default {
if (!this.ISWXWORK) wxConfig.updateAppMessageShareData(this.shareInfo) if (!this.ISWXWORK) wxConfig.updateAppMessageShareData(this.shareInfo)
else wxConfig.onMenuShareAppMessage(this.shareInfo) else wxConfig.onMenuShareAppMessage(this.shareInfo)
if (data.activityAddressLat && data.activityAddressLng) { if (data.activityAddressLat && data.activityAddressLng) {
wxConfig.getLocation().then(res => {
console.log(res)
mapApi.calculateDistance([res.latitude, res.longitude], [data.activityAddressLat, data.activityAddressLng]).then(({ elements: [address] }) => {
console.log(address)
this.detail.distance = Number((address.distance / 1000)).toFixed(2)
this.distanceKey = Date.now()
})
})
} }
}) })
}, },
authLocation (data) {
if (data.distance) this.openLocation()
else wxConfig.getLocation().then(res => {
console.log(res)
mapApi.calculateDistance([res.latitude, res.longitude], [data.activityAddressLat, data.activityAddressLng]).then(({ elements: [address] }) => {
console.log(address)
this.detail.distance = Number((address.distance / 1000)).toFixed(2)
this.distanceKey = Date.now()
})
})
},
imgError (index) { imgError (index) {
this.detail.activityVideos[index].poster = '' this.detail.activityVideos[index].poster = ''
}, },
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!