| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- /**
- * Wechat v1.0.0
- * @Class Wechat
- * @description shopro-wechat 1.0.0 wehcat第三方登录组件
- * @Author llidongtony
- * @Date 2020-02-19
- * @Email lidongtony@qq.com
- */
- import store from '@/store/index.js'
- // import {
- // API_URL
- // } from '@/env'
- // #ifdef H5
- function checkHttps(){
- let ishttps = 'https:' == window.location.protocol ? true : false;
- return ishttps
- }
- let apiUrl = 'https://fd.joisen.net.cn/';
- let pathArr = apiUrl.split('://');
- let ishttps = checkHttps();
- ishttps ? (pathArr[0] = 'https') : (pathArr[0] = 'http');
- apiUrl = pathArr.join('://');
-
- // #endif
- export default class Wechat {
- async login() {
- // #ifdef H5
- this.wxOfficialAccountLogin();
- // #endif
- }
- // #ifdef H5
- wxOfficialAccountLogin() {
- // let oUrl = window.location.href;
- let oUrl = encodeURIComponent(window.location.href);
- window.location.replace('https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + store.state.appid +
- `&redirect_uri=${encodeURIComponent(`${apiUrl}h5/authen/login.html`)}&response_type=code&scope=snsapi_userinfo&state=` +
- oUrl)
- throw 'stop';
- }
- //临时登录获取OpenId 不入库不绑定用户
- wxOfficialAccountBaseLogin() {
- let oUrl = encodeURIComponent(window.location.href);
- window.location.replace('https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + store.appid +
- `&redirect_uri=${encodeURIComponent(`${apiUrl}h5/authen/login.html`)}&response_type=code&scope=snsapi_base&state=` +
- oUrl)
- throw 'stop';
- }
- // #endif
- // 小程序更新
- checkMiniProgramUpdate() {
- if (uni.canIUse('getUpdateManager')) {
- const updateManager = uni.getUpdateManager()
- updateManager.onCheckForUpdate(function(res) {
- // 请求完新版本信息的回调
- if (res.hasUpdate) {
- updateManager.onUpdateReady(function() {
- uni.showModal({
- title: '更新提示',
- content: '新版本已经准备好,是否重启应用?',
- success: function(res) {
- console.log('success====', res)
- // res: {errMsg: "showModal: ok", cancel: false, confirm: true}
- if (res.confirm) {
- // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
- updateManager.applyUpdate()
- }
- }
- })
- })
- updateManager.onUpdateFailed(function() {
- // 新的版本下载失败
- uni.showModal({
- title: '已经有新版本了哟~',
- content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~'
- })
- })
- }
- })
- }
- }
- }
|