123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- import carhelp from '@/utils/mixin.js'
- import * as API_WeiXin from '@/apis/weixin.js'
- import {
- getUrlParam,
- getWeixinRedirectURI,
- isWeiXin
- } from '@/utils'
- var checkOpenId = true; //是否需要获取openId
- var openId = carhelp.getOpenId();
- var app = {
- init: function() {
- if (isWeiXin()) {
- if (checkOpenId) {
- if (!openId) {
- this.getOpenId();
- } else {
- //this.getDataByOpenId();
- }
- }
- } else {
- if (checkOpenId) {
- /* mui.alert('请使用微信浏览打开!', '提示', function() {
- //info.innerText = '你刚关闭了警告框';
- }); */
- }
- }
- },
- getDataByOpenId() {
- API_WeiXin.getDataByOpenId(openId).then(response => {
- var token = response ? response.token : '';
- carhelp.setToken(token);
- }).catch(error => {
- mui.toast(error);
- })
- },
- getOpenId() {
- const code = getUrlParam('code');
- var openId = carhelp.getOpenId()
- if (!openId) {
- if (!code) {
- var url = document.URL;
- window.location.href = getWeixinRedirectURI(process.car.VUE_APP_WXAPPID, url);
- } else {
- API_WeiXin.getDataByCode(code).then(response => {
- carhelp.setOpenId(response.data.openid)
- openId = response.data.openid;
- //this.getDataByOpenId()
- }).catch(error => {
- console.log(error);
- });
- }
- }
- }
- }
- module.exports = app
|