Commit d9bc19fd by hank

token 认证失败

parent 1f647aaf
...@@ -29,10 +29,10 @@ var extra = '7'; ...@@ -29,10 +29,10 @@ var extra = '7';
var wrapHref = ( mode === 'development' ? 'http://web-comment.iyunfish.cn' : 'http://wanda-qj.maxrocky.com') + '/relay/contest/h5/7'; var wrapHref = ( mode === 'development' ? 'http://web-comment.iyunfish.cn' : 'http://wanda-qj.maxrocky.com') + '/relay/contest/h5/7';
//首页地址 //首页地址
var indexHref = url + weburl + '/7'; var indexHref = url + '/video/index.html';
// 个人中心地址 // 个人中心地址
var userCenterHref = url + weburl + '/newuser/7'; var userCenterHref = url + '/video/user.html';
var shareImg = url + weburl + '/static/share.jpg'; var shareImg = url + '/static/share.jpg';
var signHref = 'http://mr-static.maxrocky.com/h5/wanda/dzgp/index.html' var signHref = 'http://mr-static.maxrocky.com/h5/wanda/dzgp/index.html'
export default{ export default{
server, server,
......
...@@ -13,6 +13,7 @@ axios.interceptors.request.use( ...@@ -13,6 +13,7 @@ axios.interceptors.request.use(
config => { config => {
// Do something before request is sent // Do something before request is sent
// console.log(config.url) // console.log(config.url)
// console.log(store.state.token, 'accessToken')
if (store.state.token) { if (store.state.token) {
config.headers['accessToken'] = store.state.token // 让每个请求携带token--['ticket']为自定义key 请根据实际情况自行修改 config.headers['accessToken'] = store.state.token // 让每个请求携带token--['ticket']为自定义key 请根据实际情况自行修改
} }
...@@ -60,7 +61,7 @@ axios.interceptors.response.use( ...@@ -60,7 +61,7 @@ axios.interceptors.response.use(
*/ */
err => { err => {
if (err && err.response) { if (err && err.response) {
if(err.response.data.code == 1001000 || err.response.data.code == 101) { if(err.response.data.code == 100100 || err.response.data.code == 100101) {
store.dispatch('getAuth').then() store.dispatch('getAuth').then()
} }
switch (err.response.status) { switch (err.response.status) {
......
...@@ -62,7 +62,7 @@ export default new Vuex.Store({ ...@@ -62,7 +62,7 @@ export default new Vuex.Store({
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.get('/contest/user/info', { axios.get('/contest/user/info', {
headers: { headers: {
'accessToken': window.localStorage.getItem('token') 'accessToken': state.token
} }
}).then(res => { }).then(res => {
state.userInfo = res.data.data state.userInfo = res.data.data
...@@ -78,6 +78,7 @@ export default new Vuex.Store({ ...@@ -78,6 +78,7 @@ export default new Vuex.Store({
}, },
actions: { actions: {
getAuth({commit,state}) { getAuth({commit,state}) {
window.localStorage.removeItem('token')
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.get('/weixin/info').then(res => { axios.get('/weixin/info').then(res => {
window.localStorage.setItem('callbackurl', location.href) window.localStorage.setItem('callbackurl', location.href)
...@@ -87,9 +88,10 @@ export default new Vuex.Store({ ...@@ -87,9 +88,10 @@ export default new Vuex.Store({
}, },
getToken({commit,state}, code){ getToken({commit,state}, code){
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.get('weixin/callback', { axios.get('/weixin/callback', {
params : { params : {
code code,
type: 1
} }
}).then(res => { }).then(res => {
window.localStorage.setItem('token', res.data.data.accessToken) window.localStorage.setItem('token', res.data.data.accessToken)
......
...@@ -44,7 +44,7 @@ export default { ...@@ -44,7 +44,7 @@ export default {
this.hiddenBar(); this.hiddenBar();
// 请求入围信息,提前加载入围的信息防止入围公告闪烁 // 请求入围信息,提前加载入围的信息防止入围公告闪烁
store.commit('getRuweiInfo'); // store.commit('getRuweiInfo');
}, },
mounted() { mounted() {
if(localStorage.getItem('token')) { if(localStorage.getItem('token')) {
......
...@@ -20,7 +20,7 @@ axios.defaults.baseURL = api.server; ...@@ -20,7 +20,7 @@ axios.defaults.baseURL = api.server;
axios.defaults.timeout = 10000; axios.defaults.timeout = 10000;
// axios.defaults.headers.common['systemtype'] = api.extra; // axios.defaults.headers.common['systemtype'] = api.extra;
import '@/modules/js/request' import '@/modules/js/request.js'
import fastclick from 'fastclick' import fastclick from 'fastclick'
fastclick.attach(document.body) fastclick.attach(document.body)
...@@ -61,7 +61,7 @@ router.beforeEach((to, from, next) => { ...@@ -61,7 +61,7 @@ router.beforeEach((to, from, next) => {
var theRequest = new Object(); var theRequest = new Object();
if (url.indexOf('?') != -1) { if (url.indexOf('?') != -1) {
var str = url.substr(1); var str = url.substr(1);
strs = str.split('&'); var strs = str.split('&');
for (var i = 0; i < strs.length; i++) { for (var i = 0; i < strs.length; i++) {
theRequest[strs[i].split('=')[0]] = decodeURI(strs[i].split('=')[1]); theRequest[strs[i].split('=')[0]] = decodeURI(strs[i].split('=')[1]);
} }
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<title>云上丹寨 摄影月赛</title> <title>云上丹寨 摄影月赛</title>
<script type="text/javascript" src="http://js.tarsocial.com/h5stat-2.1.1.vue.js"></script> <script type="text/javascript" src="https://js.tarsocial.com/h5stat-2.1.1.vue.js"></script>
</head> </head>
<body> <body>
......
...@@ -13,6 +13,7 @@ import '@/modules/js/flexible.js'; ...@@ -13,6 +13,7 @@ import '@/modules/js/flexible.js';
import axios from 'axios'; import axios from 'axios';
import api from '@/modules/js/api.js'; import api from '@/modules/js/api.js';
axios.defaults.baseURL = api.server; axios.defaults.baseURL = api.server;
import '@/modules/js/request.js' // api 拦截器
// axios.defaults.headers.common['systemtype'] = api.extra; // axios.defaults.headers.common['systemtype'] = api.extra;
...@@ -24,8 +25,6 @@ window.$eventbus = new Vue(); ...@@ -24,8 +25,6 @@ window.$eventbus = new Vue();
// import store from './store'; // import store from './store';
import store from '../../modules/store'; import store from '../../modules/store';
var _hmt = _hmt || []; var _hmt = _hmt || [];
(function () { (function () {
var hm = document.createElement("script"); var hm = document.createElement("script");
...@@ -35,7 +34,23 @@ var _hmt = _hmt || []; ...@@ -35,7 +34,23 @@ var _hmt = _hmt || [];
})(); })();
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
const list = ['/', '/detail', '/address'] // 将需要切换效果的路由名称组成一个数组 function getQuery(key) {
var url = location.search; //获取url中"?"符后的字串
var theRequest = new Object();
if (url.indexOf('?') != -1) {
var str = url.substr(1);
var strs = str.split('&');
for (var i = 0; i < strs.length; i++) {
theRequest[strs[i].split('=')[0]] = decodeURI(strs[i].split('=')[1]);
}
}
if (key) {
return theRequest[key];
} else {
return theRequest;
}
}
const list = ['/', '/detail', '/imgup'] // 将需要切换效果的路由名称组成一个数组
const toName = to.path // 即将进入的路由名字 const toName = to.path // 即将进入的路由名字
const fromName = from.path // 即将离开的路由名字 const fromName = from.path // 即将离开的路由名字
const toIndex = list.indexOf(toName) // 进入下标 const toIndex = list.indexOf(toName) // 进入下标
...@@ -51,17 +66,23 @@ router.beforeEach((to, from, next) => { ...@@ -51,17 +66,23 @@ router.beforeEach((to, from, next) => {
} }
store.state.viewDirection = direction //这里使用vuex进行赋值 store.state.viewDirection = direction //这里使用vuex进行赋值
if (_hmt) { if (_hmt) {
if (to.path) { if (to.path) {
_hmt.push(['_trackPageview', '/#' + to.fullPath]); _hmt.push(['_trackPageview', '/#' + to.fullPath]);
} }
} }
if (getQuery('code') && !store.state.token) {
return next() store.dispatch('getToken', getQuery('code')).then(res => {
next()
})
} else {
next()
}
}) })
Vue.prototype.$randomText = function() { Vue.prototype.$randomText = function () {
function RandomNumBoth(Min, Max) { function RandomNumBoth(Min, Max) {
var Range = Max - Min; var Range = Max - Min;
var Rand = Math.random(); var Rand = Math.random();
...@@ -69,7 +90,7 @@ Vue.prototype.$randomText = function() { ...@@ -69,7 +90,7 @@ Vue.prototype.$randomText = function() {
return num; return num;
} }
var num = RandomNumBoth(1,11); var num = RandomNumBoth(1, 11);
var str = null; var str = null;
switch (num) { switch (num) {
......
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