Commit 352eb86b by 陈玉桐

增加授权校验

parent ce006eeb
...@@ -3,25 +3,35 @@ import App from './App.vue' ...@@ -3,25 +3,35 @@ import App from './App.vue'
import router from './router' import router from './router'
import store from './store' import store from './store'
import './styles/index.scss'; // global css import './styles/index.scss'; // global css
import request from './utils/request'
import setWechatTitle from './utils/setWechatTitle' import setWechatTitle from './utils/setWechatTitle'
Vue.config.productionTip = false Vue.config.productionTip = false
function getUrlParam(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
var r = window.location.search.substr(1).match(reg); //匹配目标参数
if (r != null) return decodeURI(r[2]); return null; //返回参数值
}
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
console.log(localStorage.getItem("token")) if(!getUrlParam('token')){//地址不携带 token
if(!localStorage.getItem("token")){ //本地没有存储 token 去请求授权 ,有存储token直接跳转
// localStorage.setItem("token","") if(!localStorage.getItem("token")){
next() request({
// // 这个redirectUrl用 当前页路径 url: '/api/MarketingToolApi/Wechat/index',
// let redirectUrl = window.location.href method: 'post'
// redirectUrl = encodeURIComponent(redirectUrl) }).then(response => {
// console.log(redirectUrl) })
// const appid='wx0201b63e761568b8' }else{
// window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirectUrl}&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect` next()
}else{ }
}else{//地址携带 token 获取url上的值 并存储 再跳转
localStorage.setItem("token",getUrlParam('token'))
next() next()
} }
}) })
router.afterEach((transition) => { router.afterEach((transition) => {
......
...@@ -141,15 +141,6 @@ export default { ...@@ -141,15 +141,6 @@ export default {
// console.log(response) // console.log(response)
// }) // })
// request({
// url: '/api/MarketingToolApi/Wechat/getWechatOpenid',
// method: 'get',
// params: {
// code : '021XpJNm1rmTCq0lZxPm1GH3Om1XpJNh'
// }
// }).then(response => {
// console.log(response)
// })
this.loadingShow = true this.loadingShow = true
request({ request({
url: '/api/MarketingToolApi/Posters/template', url: '/api/MarketingToolApi/Posters/template',
......
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 to comment