1. 【修复】申请退款后积分等操作可能出现错误的问题 2. 【修复】拼团支付可能出现支付错误的问题 3. 【修复】退款申请后的订单流程优化和积分赠送的问题 4. 【修复】回收站中的商品无法恢复的问题 5. 【修复】一号通短信查询记录不完整的问题 6. 【修复】用户管理批量加分组,标签的问题 7. 【修复】积分日志搜索显示有误的问题 8. 【修复】手动发送优惠券可能会出错的问题 9. 【修复】核销订单创建在某种条件下会出错的问题 10. 【修复】移动端商品详情,购物车等样式兼容问题 11. 【修复】业务流程性的优化
276 lines
5.5 KiB
JavaScript
276 lines
5.5 KiB
JavaScript
// #ifdef H5
|
|
import WechatJSSDK from "@/plugin/jweixin-module/index.js";
|
|
|
|
|
|
import {
|
|
getWechatConfig,
|
|
wechatAuth
|
|
} from "@/api/public";
|
|
import {
|
|
WX_AUTH,
|
|
STATE_KEY,
|
|
LOGINTYPE,
|
|
BACK_URL
|
|
} from '@/config/cache';
|
|
import {
|
|
parseQuery
|
|
} from '@/utils';
|
|
import store from '@/store';
|
|
import Cache from '@/utils/cache';
|
|
|
|
class AuthWechat {
|
|
|
|
constructor() {
|
|
//微信实例化对象
|
|
this.instance = WechatJSSDK;
|
|
//是否实例化
|
|
this.status = false;
|
|
|
|
this.initConfig = {};
|
|
|
|
}
|
|
|
|
isAndroid(){
|
|
let u = navigator.userAgent;
|
|
return u.indexOf('Android') > -1 || u.indexOf('Adr') > -1;
|
|
}
|
|
|
|
signLink() {
|
|
if (typeof window.entryUrl === 'undefined' || window.entryUrl === '') {
|
|
window.entryUrl = location.href.split('#')[0]
|
|
}
|
|
return /(Android)/i.test(navigator.userAgent) ? location.href.split('#')[0] : window.entryUrl;
|
|
}
|
|
|
|
|
|
/**
|
|
* 初始化wechat(分享配置)
|
|
*/
|
|
wechat() {
|
|
return new Promise((resolve, reject) => {
|
|
// if (this.status && !this.isAndroid()) return resolve(this.instance);
|
|
getWechatConfig()
|
|
.then(res => {
|
|
this.instance.config(res.data);
|
|
this.initConfig = res.data;
|
|
this.status = true;
|
|
this.instance.ready(() => {
|
|
resolve(this.instance);
|
|
})
|
|
}).catch(err => {
|
|
this.status = false;
|
|
reject(err);
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 验证是否初始化
|
|
*/
|
|
verifyInstance() {
|
|
let that = this;
|
|
return new Promise((resolve, reject) => {
|
|
if (that.instance === null && !that.status) {
|
|
that.wechat().then(res => {
|
|
resolve(that.instance);
|
|
}).catch(() => {
|
|
return reject();
|
|
})
|
|
} else {
|
|
return resolve(that.instance);
|
|
}
|
|
})
|
|
}
|
|
// 微信公众号的共享地址
|
|
openAddress() {
|
|
return new Promise((resolve, reject) => {
|
|
this.wechat().then(wx => {
|
|
this.toPromise(wx.openAddress).then(res => {
|
|
resolve(res);
|
|
}).catch(err => {
|
|
reject(err);
|
|
});
|
|
}).catch(err => {
|
|
reject(err);
|
|
})
|
|
});
|
|
}
|
|
|
|
// 获取经纬度;
|
|
location(){
|
|
return new Promise((resolve, reject) => {
|
|
this.wechat().then(wx => {
|
|
this.toPromise(wx.getLocation,{type: 'wgs84'}).then(res => {
|
|
resolve(res);
|
|
}).catch(err => {
|
|
reject(err);
|
|
});
|
|
}).catch(err => {
|
|
reject(err);
|
|
})
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 微信支付
|
|
* @param {Object} config
|
|
*/
|
|
pay(config) {
|
|
return new Promise((resolve, reject) => {
|
|
this.wechat().then((wx) => {
|
|
this.toPromise(wx.chooseWXPay, config).then(res => {
|
|
resolve(res);
|
|
}).catch(res => {
|
|
console.log('js中的错误',res)
|
|
resolve(res);
|
|
});
|
|
}).catch(res => {
|
|
reject(res);
|
|
});
|
|
});
|
|
}
|
|
|
|
toPromise(fn, config = {}) {
|
|
return new Promise((resolve, reject) => {
|
|
fn({
|
|
...config,
|
|
success(res) {
|
|
resolve(res);
|
|
},
|
|
fail(err) {
|
|
reject(err);
|
|
},
|
|
complete(err) {
|
|
reject(err);
|
|
},
|
|
cancel(err) {
|
|
reject(err);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 自动去授权
|
|
*/
|
|
oAuth() {
|
|
if (uni.getStorageSync(WX_AUTH) && store.state.app.token) return;
|
|
const {
|
|
code
|
|
} = parseQuery();
|
|
if (!code) return this.toAuth();
|
|
}
|
|
|
|
clearAuthStatus() {
|
|
|
|
}
|
|
|
|
/**
|
|
* 授权登录获取token
|
|
* @param {Object} code
|
|
*/
|
|
auth(code) {
|
|
return new Promise((resolve, reject) => {
|
|
let loginType = Cache.get(LOGINTYPE);
|
|
wechatAuth(code, Cache.get("spread"), loginType)
|
|
.then(({
|
|
data
|
|
}) => {
|
|
// let expires_time = data.expires_time.substring(0, 19);
|
|
// expires_time = expires_time.replace(/-/g, '/');
|
|
// expires_time = new Date(expires_time).getTime();
|
|
// let newTime = Math.round(new Date() / 1000);
|
|
store.commit("LOGIN", {
|
|
token: data.token
|
|
// time: expires_time - newTime
|
|
});
|
|
Cache.set(WX_AUTH, code);
|
|
Cache.clear(STATE_KEY);
|
|
// Cache.clear('spread');
|
|
loginType && Cache.clear(LOGINTYPE);
|
|
resolve();
|
|
})
|
|
.catch(reject);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 获取跳转授权后的地址
|
|
* @param {Object} appId
|
|
*/
|
|
getAuthUrl(appId) {
|
|
const redirect_uri = encodeURIComponent(
|
|
`${location.origin}/pages/auth/index?back_url=` +
|
|
encodeURIComponent(
|
|
encodeURIComponent(
|
|
uni.getStorageSync(BACK_URL) ?
|
|
uni.getStorageSync(BACK_URL) :
|
|
location.pathname + location.search
|
|
)
|
|
)
|
|
);
|
|
uni.removeStorageSync(BACK_URL);
|
|
const state = encodeURIComponent(
|
|
("" + Math.random()).split(".")[1] + "authorizestate"
|
|
);
|
|
uni.setStorageSync(STATE_KEY, state);
|
|
return `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_userinfo&state=${state}#wechat_redirect`;
|
|
}
|
|
|
|
/**
|
|
* 跳转自动登录
|
|
*/
|
|
toAuth() {
|
|
let that = this;
|
|
this.wechat().then(wx => {
|
|
location.href = this.getAuthUrl(that.initConfig.appId);
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 绑定事件
|
|
* @param {Object} name 事件名
|
|
* @param {Object} config 参数
|
|
*/
|
|
wechatEvevt(name, config) {
|
|
let that = this;
|
|
return new Promise((resolve, reject) => {
|
|
let configDefault = {
|
|
fail(res) {
|
|
if (that.instance) return reject({
|
|
is_ready: true,
|
|
wx: that.instance
|
|
});
|
|
that.verifyInstance().then(wx => {
|
|
return reject({
|
|
is_ready: true,
|
|
wx: wx
|
|
});
|
|
})
|
|
},
|
|
success(res) {
|
|
return resolve(res,2222);
|
|
}
|
|
};
|
|
Object.assign(configDefault, config);
|
|
that.wechat().then(wx => {
|
|
if (typeof name === 'object') {
|
|
name.forEach(item => {
|
|
wx[item] && wx[item](configDefault)
|
|
})
|
|
} else {
|
|
wx[name] && wx[name](configDefault)
|
|
}
|
|
})
|
|
});
|
|
}
|
|
|
|
isWeixin() {
|
|
return navigator.userAgent.toLowerCase().indexOf("micromessenger") !== -1;
|
|
}
|
|
|
|
}
|
|
|
|
export default new AuthWechat();
|
|
// #endif
|