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()|| !(process.env.NODE_ENV === "development") ){
- if (isWeiXin()) {
- if (checkOpenId) {
- if (!openId) {
- this.getOpenId();
- } else {
-
- }
- }
- } else{
- alert("请使用微信打开本页面")
- }
- }else{
- carhelp.setOpenId(process.car.openId)
- }
-
-
- },
-
- getOpenId() {
-
- const code = getUrlParam('code');
- var openId = carhelp.getOpenId()
- if (!openId) {
- if (!code) {
- var url = document.URL;
- var getUrl= getWeixinRedirectURI(process.car.VUE_APP_WXAPPID, url);
-
- window.location.href = getUrl;
- } else {
-
- API_WeiXin.getDataByCode(code).then(response => {
-
- carhelp.setOpenId(response.data.openid)
- openId = response.data.openid;
- carhelp.set("xpgj_wx_user_info",response.data)
-
- location.reload();
- }).catch(error => {
- console.log(error);
- });
- }
- }
- }
- }
- module.exports = app
|