工作內(nèi)容
- fix ifish后臺查看供應(yīng)商電話顯示錯誤
- 調(diào)試微信jssdk接入
- 匯車替換jssdk api來獲取地理位置信息
handleViewUser(row) {
this.dialogUserInfoVisible = true;
if (row.role === 'VENDOR' || row.role === '供應(yīng)商') {
axios.get(`${API.ifish_vendors}?userId=${row.id}`)
.then((res) => {
this.userInfo.company = res.data.company;
this.userInfo.companyAddress = res.data.companyAddress;
// 如果角色是vendor從vendor數(shù)據(jù)中拿電話
this.userInfo.mobile = res.data.mobile;
});
} else {
this.userInfo.mobile = row.mobile;
}
this.userInfo.email = row.email;
this.userInfo.role = this.formatRole(row); // 格式化角色名
},
把配置微信jssdk封裝成通用函數(shù),方便復(fù)用
// 微信jssdk配置函數(shù)
wxConfig(jsApiList, url, debug = false) {
axios.get(`${API.wechat_jssdk_config}?url=${url}`)
.then((res) => {
const data = res.data.data;
wx.config({
debug, // 開啟調(diào)試模式,調(diào)用的所有api的返回值會在客戶端alert出來,若要查看傳入的參數(shù),可以在pc端打開,參數(shù)信息會通過log打出,僅在pc端時才會打印。
appId: data.appid, // 必填,公眾號的唯一標(biāo)識
timestamp: data.timestamp, // 必填,生成簽名的時間戳
nonceStr: data.nonceStr, // 必填,生成簽名的隨機(jī)串
signature: data.signature, // 必填,簽名,見附錄1
jsApiList // 必填,需要使用的JS接口列表,所有JS接口列表見附錄2
});
});
}
將更新用戶地理位置信息封裝在action中
export const UPDATE_LOCATION = ({commit}) => {
wx.ready(() => {
wx.getLocation({
type: 'wgs84', // 默認(rèn)為wgs84的gps坐標(biāo),如果要返回直接給openLocation用的火星坐標(biāo),可傳入'gcj02'
success: (res) => {
const latitude = res.latitude; // 緯度,浮點(diǎn)數(shù),范圍為90 ~ -90
const longitude = res.longitude; // 經(jīng)度,浮點(diǎn)數(shù),范圍為180 ~ -180。
commit(types.UPDATE_LOCATION, {latitude, longitude});
}
});
});
};
在全局路由鉤子afterEach中調(diào)用微信jssdk配置方法防止路由改變后失效問題
router.afterEach((route) => {
commit(types.UPDATE_LOADING, false)
// 每次路由改變后配置微信jssdk防止失效
Helper.wxConfig(wxJsApiList, encodeURIComponent(window.location.href));
})
總結(jié)
- 不足
- 微信jssdk配置放在全局路由鉤子函數(shù)中,無論頁面有沒有用到j(luò)ssdk api,只要路由改變就配置,可能存在性能問題