|
@@ -1,48 +1,25 @@
|
|
import Vue from 'vue';
|
|
import Vue from 'vue';
|
|
import {allocations} from '@/api/configget';
|
|
import {allocations} from '@/api/configget';
|
|
import Router from '@/router'
|
|
import Router from '@/router'
|
|
-import {
|
|
|
|
- getToken
|
|
|
|
-} from '@/utils/auth'
|
|
|
|
-let isfot = false
|
|
|
|
-export const wxAuth = async (ifHome, next, to) => {
|
|
|
|
- if (isfot) return
|
|
|
|
|
|
+import {getToken} from '@/utils/auth'
|
|
|
|
+
|
|
|
|
+export const wxAuth = (pushindex, next) => {
|
|
const wechatConfigUrl = location.href.split('#')[0]
|
|
const wechatConfigUrl = location.href.split('#')[0]
|
|
- if (window.wechatConfigUrl === wechatConfigUrl && window.WWOpenData) {
|
|
|
|
- if (getToken()) {
|
|
|
|
- if (ifHome) {
|
|
|
|
- Router.push({
|
|
|
|
- name: 'home'
|
|
|
|
- })
|
|
|
|
- } else {
|
|
|
|
- if (next) {
|
|
|
|
- next()
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return Promise.resolve()
|
|
|
|
- } else {
|
|
|
|
- try {
|
|
|
|
- await wxConfigByCorp(ifHome, wechatConfigUrl, next)
|
|
|
|
- window.wechatConfigUrl = wechatConfigUrl
|
|
|
|
- return Promise.resolve()
|
|
|
|
- } catch (error) {
|
|
|
|
- return Promise.reject(error)
|
|
|
|
- }
|
|
|
|
|
|
+ if(!window.WWOpenData){
|
|
|
|
+ console.log('url:'+wechatConfigUrl)
|
|
|
|
+ wxConfigByCorp(wechatConfigUrl, pushindex, next)
|
|
|
|
+ }else{
|
|
|
|
+ next();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-async function wxConfigByCorp(ifHome, body, next) {
|
|
|
|
- isfot = true
|
|
|
|
|
|
+async function wxConfigByCorp(url, pushindex, next) {
|
|
var data;
|
|
var data;
|
|
- await allocations(body).then((res) => {
|
|
|
|
- if (res.data.code == 1) {
|
|
|
|
- data = res.data.data
|
|
|
|
- }
|
|
|
|
- }).catch(() => {})
|
|
|
|
|
|
+ await allocations(url).then((res) => {data = res.data.data})
|
|
const wxConfigParams = data.config
|
|
const wxConfigParams = data.config
|
|
const appSignature = data.agentConfig
|
|
const appSignature = data.agentConfig
|
|
- await Vue.prototype.$wx.config({ // 鉴权(企业的身份与权限)
|
|
|
|
|
|
+
|
|
|
|
+ Vue.prototype.$wx.config({ // 鉴权(企业的身份与权限)
|
|
beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
|
|
beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
|
|
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
|
|
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
|
|
appId: wxConfigParams.appId, // 必填,企业微信的corpID
|
|
appId: wxConfigParams.appId, // 必填,企业微信的corpID
|
|
@@ -57,9 +34,11 @@ async function wxConfigByCorp(ifHome, body, next) {
|
|
'invoke',
|
|
'invoke',
|
|
'hideOptionMenu',
|
|
'hideOptionMenu',
|
|
'showOptionMenu'
|
|
'showOptionMenu'
|
|
- ] // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
|
|
|
|
|
|
+ ]
|
|
});
|
|
});
|
|
- await Vue.prototype.$wx.ready(function() {
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ Vue.prototype.$wx.ready(function() {
|
|
const u = navigator.userAgent;
|
|
const u = navigator.userAgent;
|
|
const isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; // 安卓
|
|
const isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; // 安卓
|
|
const isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); // ios终端
|
|
const isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); // ios终端
|
|
@@ -72,19 +51,9 @@ async function wxConfigByCorp(ifHome, body, next) {
|
|
signature: appSignature.signature, // 必填,签名,见附录-JS-SDK使用权限签名算法
|
|
signature: appSignature.signature, // 必填,签名,见附录-JS-SDK使用权限签名算法
|
|
jsApiList: ['selectExternalContact'], //必填
|
|
jsApiList: ['selectExternalContact'], //必填
|
|
success: function(res) { // 回调 // wx.agentConfig成功回调后,WWOpenData 才会注入到 window 对象上面
|
|
success: function(res) { // 回调 // wx.agentConfig成功回调后,WWOpenData 才会注入到 window 对象上面
|
|
- isfot = false
|
|
|
|
- if (next) {
|
|
|
|
- next()
|
|
|
|
- }
|
|
|
|
- if (ifHome) {
|
|
|
|
- console.log('--跳转首页--')
|
|
|
|
- Router.push({
|
|
|
|
- name: 'home'
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
|
|
+ if (next){next()}
|
|
},
|
|
},
|
|
fail: function(res) {
|
|
fail: function(res) {
|
|
- console.log('fail'+res)
|
|
|
|
if (res.errMsg.indexOf('function not exist') > -1) {
|
|
if (res.errMsg.indexOf('function not exist') > -1) {
|
|
alert('版本过低请升级')
|
|
alert('版本过低请升级')
|
|
}
|
|
}
|
|
@@ -98,25 +67,11 @@ async function wxConfigByCorp(ifHome, body, next) {
|
|
timestamp: appSignature.timestamp, // 必填,生成签名的时间戳
|
|
timestamp: appSignature.timestamp, // 必填,生成签名的时间戳
|
|
nonceStr: appSignature.nonceStr, // 必填,生成签名的随机串
|
|
nonceStr: appSignature.nonceStr, // 必填,生成签名的随机串
|
|
signature: appSignature.signature, // 必填,签名,见附录-JS-SDK使用权限签名算法
|
|
signature: appSignature.signature, // 必填,签名,见附录-JS-SDK使用权限签名算法
|
|
- jsApiList: [
|
|
|
|
- 'openUserProfile',
|
|
|
|
- 'previewFile'
|
|
|
|
- ], // 必填
|
|
|
|
|
|
+ jsApiList: ['openUserProfile','previewFile'], // 必填
|
|
success(res) {
|
|
success(res) {
|
|
- console.log('agentConfig', res);
|
|
|
|
- isfot = false
|
|
|
|
- if (next) {
|
|
|
|
- next()
|
|
|
|
- }
|
|
|
|
- if (ifHome) {
|
|
|
|
- console.log('跳转首页')
|
|
|
|
- Router.push({
|
|
|
|
- name: 'home'
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
|
|
+ if (next) {next()}
|
|
},
|
|
},
|
|
fail(res) {
|
|
fail(res) {
|
|
- console.log('err', res);
|
|
|
|
if (res.errMsg.indexOf('function not exist') > -1) {
|
|
if (res.errMsg.indexOf('function not exist') > -1) {
|
|
alert('版本过低请升级');
|
|
alert('版本过低请升级');
|
|
}
|
|
}
|
|
@@ -124,4 +79,7 @@ async function wxConfigByCorp(ifHome, body, next) {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
+ Vue.prototype.$wx.error(function(res){
|
|
|
|
+ console.log('$wx.error'+res);
|
|
|
|
+ });
|
|
}
|
|
}
|