首页 > 其他分享 >企业微信登录,前端做跳转

企业微信登录,前端做跳转

时间:2022-11-22 10:23:29浏览次数:39  
标签:code name 登录 微信 wxcode href let 跳转 import

 

<template>
    <div class="register-page-wrapper">
<!--        <div class="attach" >
            <div class="attachTitle">附件</div>
        </div>-->
        <div style="display: flex;align-items: center;justify-content: center">
        <van-loading type="spinner" size="24px" color="#0094ff"  text-color="#0094ff ">企业微信登录中...</van-loading>
        </div>
    </div>
</template>
<script>


import {reqRegister} from "@/api/index";
import {addUpdateSFUser} from "@/api/web";
import store from "@/store";
import {getSFUser} from "../../../api/web";
import {validateForms} from "@/utils/webUtils";
import {formatTime, getPickList, doCacheData} from "@/utils";
import {addpage1, getpage1} from "@/api/user";
import axios from "axios";
import http from "@/utils/http";
import {
    showFullScreenLoading,
    tryHideFullScreenLoading,
} from "@/utils/loading";
import InfoLook from "@/components/common/InfoLook";
import PageFooter from "@/components/common/pageFooter";
import NewInfoLook from "@/components/common/newInfoLook";
export default {
    name: "CreateNewTask",
    components: {NewInfoLook, PageFooter, InfoLook},
    data() {
        return {
            pageTitle: "首页",
            info: null,
            then: false,
            currentTime: null,
            canSubmit: true,
            likeList: [],
            planList: [],
            goingList: [],
            finishList: [],
            imgList: [],
            count: {},
            code:""
        };
    },

    created() {
        var wxcode = this.getCode('code');
        if (wxcode != null) {
            this.$router.push({name: "homePage",params: {code: wxcode}});
        }else{
            // alert(location.href)
            // 授权后重定向的回调链接地址,请使用urlencode对链接进行处理
            // let redirect_uri = encodeURIComponent('https://xxxx')
            let redirect_uri = encodeURIComponent('https://xxxxx');
            let appid = "ww09fxxxxx";
            let AGENTID = '1000126';
            window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect`
        }
    },

    methods: {
        /* 截取地址栏code */
        getCode(name) {
            let href = location.href;
            return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(href) || [, ""])[1].replace(/\+/g, '%20')) || null;
        },
        afterRead(file) {
            this.imgList.push(file);
        },
    },
};

 

created() {
    this.getweixinCode();
},

methods: {
    /* 截取地址栏code */
    getCode(name) {
        let href = location.href;
        return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(href) || [, ""])[1].replace(/\+/g, '%20')) || null;
    },
    getweixinCode() {
        const vm = this;
        var wxcode = vm.$route.params.code;
        if (!!wxcode) {
            vm.login(wxcode)
        } else {
            this.$store.commit("gigi/deleteAll");
            store.commit("gigi/SET_ACTIVEINDEX", 0)
            vm.showtask(vm.$store.state.gigi.currentUser)
        }

    },

 

利用param丢失的属性来判断是不是第一次登录

标签:code,name,登录,微信,wxcode,href,let,跳转,import
From: https://www.cnblogs.com/laroux/p/16914268.html

相关文章