Commit 5346cdd4 by 肖康

全局拦截生成csrf uid

parent bca5d83e
Showing with 15 additions and 14 deletions
import App from './App'
import { request, setCookie, getCookie } from '@/util/util.js'
import { request} from '@/util/util.js'
import filters from '@/filters'
import router from '@/router/index.js'
import { RouterMount } from 'uni-simple-router'
import directive from '@/directive'
import w_md5 from '@/util/md5.js'
// #ifndef VUE3
import Vue from 'vue'
......@@ -20,17 +19,6 @@ Object.keys(filters).forEach(key => Vue.filter(key, filters[key]));
Vue.use(directive);
//生成临时Yo4teW_gid和Yo4teW_csrf
let time = parseInt(new Date().getTime() / 1000);
let gid_ = w_md5.hex_md5_32(w_md5.hex_md5_32(String(time) + Math.random()) + "usersign")
let csrf_ = w_md5.hex_md5_32(w_md5.hex_md5_32(String(time) + Math.random()) + "csrf")
if (!getCookie("Yo4teW_gid")) {
setCookie('Yo4teW_gid', gid_, 15);
}
if (!getCookie("Yo4teW_csrf")) {
setCookie('Yo4teW_csrf', csrf_, 15);
}
try {
......
// router/index.js
import Vue from 'vue'
import Router from 'uni-simple-router'
import {Ichunt_Api,Api_Url} from '@/util/api.js';
import { request,getCookie,setCookie} from '@/util/util.js'
Vue.use(Router)
//初始化
const router = new Router({
......@@ -139,6 +140,17 @@ const router = new Router({
//全局路由前置守卫
router.beforeEach((to, from, next) => {
//写入 Yo4teW_gid Yo4teW_csrf
if (!getCookie("Yo4teW_gid")) {
request(Api_Url + "/public/apiInit", 'get', {}).then(res => {
if (res.err_code === 0) {
setCookie('Yo4teW_gid', res.data.Yo4teW_gid, 15);
setCookie('Yo4teW_csrf', res.data.Yo4teW_csrf, 15);
next()
}
});
return
}
next()
})
// 全局路由后置守卫
......
......@@ -3,6 +3,7 @@ import API_BASE from '../util/api.js'
* 请求封装
*/
const request = (url = '', type = 'GET', param = {}, Loading, headertype) => {
//是否启动加载
if (Loading) {
uni.showLoading({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment