Ruoyi bypasses the login page to access other customized pages, and obtains permissions after logging in to the customized official account page.

 1. Add whitelist routing path path

2. Configure the routing path

component: (resolve) => require(['@/views/wxgzh/Login'], resolve),// 白名单

3. When logging in to an official account, you need to save the token value returned by the backend. User information can be automatically obtained after logging in with a customized official account.

Otherwise, every time router.beforeEach((to, from, next) => {...} in the permission.js file is judged according to the global front guard , the whitelist interface will jump.

(1) If there is no token value, it will return to the default login page.

(2) If there is a token value, the user information will be automatically obtained  store.dispatch('GetInfo').then(() => {...} encapsulated in the vuex file src\store\modules\user.js

import { setToken } from "@/utils/auth"; // Access token value interface

 setToken(response.token); // Access token, with whitelist permissions

The main code of the wxLogin.vue page is as follows:

import { setToken } from "@/utils/auth"; // 存取token值接口,在上面引用


// vant表单验证
      this.$refs.forms.validate().then(() => {
          // 验证通过
          login(this.form).then((response) => {
            if (response.code == 200) {
              setToken(response.token); // 存取token,有白名单权限
              localStorage.setItem("active", 0); // 存储vant标签切换值
              this.$router.push({ path: "/notice" }); // 跳转路由
            } else {
              this.finished = false;
            }
          });
        })
        .catch(() => {
          //验证失败
          console.log("false");
        });

 The permission.js file is as follows: The global front guard determines whether there is a route every time the page jumps.

 If the vuex file encapsulated by the system is src\store\modules\ user.js , the file is as follows:

After the public account is successfully logged in, information such as user roles, user permissions, etc. will be printed and displayed;

Guess you like

Origin blog.csdn.net/m0_61601708/article/details/129947068