提交 e7f64c26 authored 作者: 王鹏飞's avatar 王鹏飞

feature: 增加登录校验

上级 fcb8b11e
......@@ -11,16 +11,16 @@
"dependencies": {
"axios": "^0.19.2",
"core-js": "^3.6.5",
"dayjs": "^1.8.28",
"dayjs": "^1.8.29",
"js-cookie": "^2.2.1",
"md5": "^2.2.1",
"qs": "^6.9.4",
"timeago.js": "^4.0.2",
"vant": "^2.9.1",
"vant": "^2.9.2",
"vue": "^2.6.11",
"vue-meta": "^2.4.0",
"vue-router": "^3.3.4",
"vuex": "^3.4.0"
"vuex": "^3.5.1"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~4.4.1",
......
......@@ -36,3 +36,8 @@ export function sendResetPasswordCode(data) {
export function logout() {
return httpRequest.post('https://learn-pbcsf.ezijing.com/api/clear/cookie')
}
// 获取用户信息
export function getUser() {
return httpRequest.get('/api/passport/account/get-user-info')
}
......@@ -77,6 +77,17 @@ Vue.filter('avatar', function(value) {
return value && value !== 'null' ? value : avatar
})
/* 导航守卫 */
router.beforeEach((to, from, next) => {
if (to.meta.requiredLogin) {
store.dispatch('checkLogin').then(isLogin => {
isLogin ? next() : next('/login')
})
return
}
next()
})
new Vue({
store,
router,
......
......@@ -152,7 +152,8 @@ const routes = [
{
path: '/submit',
name: 'submitStudent',
component: () => import('@/views/submitStudent/submitStudent.vue')
component: () => import('@/views/submitStudent/submitStudent.vue'),
meta: { requiredLogin: true }
}
]
......
import Vue from 'vue'
import Vuex from 'vuex'
import { getUser } from '@/api/account'
Vue.use(Vuex)
export default new Vuex.Store({
state: {
groupList: []
groupList: [],
user: {}
},
mutations: {
setGroupList(state, list) {
state.groupList = list
},
setUser(state, user) {
state.user = user
}
},
actions: {}
actions: {
getUser({ commit }) {
getUser().then(response => {
commit('setUser', response)
})
},
async checkLogin({ commit }) {
const isLogin = await getUser()
.then(response => {
if (response.code === 0) {
commit('setUser', response)
return true
} else {
commit('setUser', {})
return false
}
})
.catch(() => {
commit('setUser', {})
return false
})
return isLogin
}
}
})
......@@ -149,9 +149,9 @@ export default {
}
},
created() {
// if (this.isWechat && !this.checkWechatLogin()) {
// this.wechatLogin()
// }
if (this.isWechat && !this.checkWechatLogin()) {
this.wechatLogin()
}
}
}
</script>
......
......@@ -928,10 +928,10 @@
resolved "https://registry.npm.taobao.org/@types/q/download/@types/q-1.5.4.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40types%2Fq%2Fdownload%2F%40types%2Fq-1.5.4.tgz#15925414e0ad2cd765bfef58842f7e26a7accb24"
integrity sha1-FZJUFOCtLNdlv+9YhC9+JqesyyQ=
"@vant/icons@1.2.1":
version "1.2.1"
resolved "https://registry.npm.taobao.org/@vant/icons/download/@vant/icons-1.2.1.tgz#309fecb97a4989866f045ce676b545c454701c8f"
integrity sha1-MJ/suXpJiYZvBFzmdrVFxFRwHI8=
"@vant/icons@1.2.3":
version "1.2.3"
resolved "https://registry.yarnpkg.com/@vant/icons/-/icons-1.2.3.tgz#c46b7ddd32363f790944c3af974b73bda80df7a1"
integrity sha512-LMu1JGGgZqLYXVFRcuNRDCOWE7AX0vt/gFBkd9xMI7H9uMdNx2oO3YujgNVvVrrF8iufHwfwUv41HiwYMvU3zQ==
"@vue/babel-helper-vue-jsx-merge-props@^1.0.0":
version "1.0.0"
......@@ -2768,10 +2768,10 @@ dashdash@^1.12.0:
dependencies:
assert-plus "^1.0.0"
dayjs@^1.8.28:
version "1.8.28"
resolved "https://registry.npm.taobao.org/dayjs/download/dayjs-1.8.28.tgz?cache=0&sync_timestamp=1590637586330&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fdayjs%2Fdownload%2Fdayjs-1.8.28.tgz#37aa6201df483d089645cb6c8f6cef6f0c4dbc07"
integrity sha1-N6piAd9IPQiWRctsj2zvbwxNvAc=
dayjs@^1.8.29:
version "1.8.29"
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.8.29.tgz#5d23e341de6bfbd206c01136d2fb0f01877820f5"
integrity sha512-Vm6teig8ZWK7rH/lxzVGxZJCljPdmUr6q/3f4fr5F0VWNGVkZEjZOQJsAN8hUHUqn+NK4XHNEpJZS1MwLyDcLw==
de-indent@^1.0.2:
version "1.0.2"
......@@ -8007,13 +8007,13 @@ validate-npm-package-license@^3.0.1:
spdx-correct "^3.0.0"
spdx-expression-parse "^3.0.0"
vant@^2.8.6:
version "2.8.6"
resolved "https://registry.npm.taobao.org/vant/download/vant-2.8.6.tgz#83ffd70dd6fbf8c3d80fbd6f43f38311c26542ef"
integrity sha1-g//XDdb7+MPYD71vQ/ODEcJlQu8=
vant@^2.9.2:
version "2.9.2"
resolved "https://registry.yarnpkg.com/vant/-/vant-2.9.2.tgz#df7b9d6d3d8274c407659ec88feb5fa1a3a3a3f0"
integrity sha512-mPI0WGXFgDiF+gqoePz3cYt2ra2dIglIECU29vunUKsQxhEVkKLBEviAV3J+q+1A6NizLvp4xrdWdq67/maTiA==
dependencies:
"@babel/runtime" "7.x"
"@vant/icons" "1.2.1"
"@vant/icons" "1.2.3"
"@vue/babel-helper-vue-jsx-merge-props" "^1.0.0"
vue-lazyload "1.2.3"
......@@ -8112,6 +8112,11 @@ vue@^2.6.11:
resolved "https://registry.npm.taobao.org/vue/download/vue-2.6.11.tgz#76594d877d4b12234406e84e35275c6d514125c5"
integrity sha1-dllNh31LEiNEBuhONSdcbVFBJcU=
vuex@^3.5.1:
version "3.5.1"
resolved "https://registry.yarnpkg.com/vuex/-/vuex-3.5.1.tgz#f1b8dcea649bc25254cf4f4358081dbf5da18b3d"
integrity sha512-w7oJzmHQs0FM9LXodfskhw9wgKBiaB+totOdb8sNzbTB2KDCEEwEs29NzBZFh/lmEK1t5tDmM1vtsO7ubG1DFw==
watchpack-chokidar2@^2.0.0:
version "2.0.0"
resolved "https://registry.npm.taobao.org/watchpack-chokidar2/download/watchpack-chokidar2-2.0.0.tgz#9948a1866cbbd6cb824dea13a7ed691f6c8ddff0"
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论