Commit 997efc74 authored by Damon's avatar Damon

feat: 用户授权拦截

parent 56507c13
...@@ -3,8 +3,6 @@ export default { ...@@ -3,8 +3,6 @@ export default {
onLaunch: function () { onLaunch: function () {
// 版本更新 // 版本更新
this.updateApp() this.updateApp()
// 检查登录是否已过期
this.checkLogin()
}, },
onShow: function () { onShow: function () {
console.log('App Show') console.log('App Show')
...@@ -13,27 +11,6 @@ export default { ...@@ -13,27 +11,6 @@ export default {
console.log('App Hide') console.log('App Hide')
}, },
methods: { methods: {
checkLogin() {
if (this.vuex_token) {
uni.checkSession({
success: (result) => {
//session_key 未过期,并且在本生命周期一直有效
console.log("session未过期", result)
},
fail: (error) => {
// session_key 已经失效,需要重新执行登录流程
console.log("error", error)
this.$u.route({
url: 'pages/login/index'
})
}
})
} else {
this.$u.route({
url: 'pages/login/index'
})
}
},
/* 版本更新 */ /* 版本更新 */
updateApp() { updateApp() {
if (uni.canIUse('getUpdateManager')) { if (uni.canIUse('getUpdateManager')) {
......
...@@ -45,7 +45,7 @@ const install = (Vue, vm) => { ...@@ -45,7 +45,7 @@ const install = (Vue, vm) => {
vm.$u.toast('验证失败,请重新登录'); vm.$u.toast('验证失败,请重新登录');
setTimeout(() => { setTimeout(() => {
// 此为uView的方法,详见路由相关文档 // 此为uView的方法,详见路由相关文档
vm.$u.route('/pages/user/login') vm.$u.route('/pages/login/index')
}, 1500) }, 1500)
return false; return false;
} else { } else {
......
...@@ -76,7 +76,6 @@ ...@@ -76,7 +76,6 @@
"path": "customer", "path": "customer",
"name": "mineCustomer", "name": "mineCustomer",
"style": { "style": {
"navigationStyle": "custom",
"navigationBarTitleText": "联系客服", "navigationBarTitleText": "联系客服",
"enablePullDownRefresh": false, "enablePullDownRefresh": false,
"disableScroll": true "disableScroll": true
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
<u-cell-group> <u-cell-group>
<u-cell-item icon="star" title="个人信息" value="完善度40%"></u-cell-item> <u-cell-item icon="star" title="个人信息" value="完善度40%"></u-cell-item>
<u-cell-item icon="photo" title="我的题库"></u-cell-item> <u-cell-item icon="photo" title="我的题库"></u-cell-item>
<u-cell-item icon="coupon" title="联系客服"></u-cell-item> <u-cell-item icon="coupon" title="联系客服" @tap="toUrl('pages/mine/customer')"></u-cell-item>
<u-cell-item icon="coupon" title="退出登录" @tap="logout"></u-cell-item> <u-cell-item icon="coupon" title="退出登录" @tap="logout"></u-cell-item>
</u-cell-group> </u-cell-group>
</view> </view>
...@@ -46,6 +46,11 @@ ...@@ -46,6 +46,11 @@
url: 'pages/login/index' url: 'pages/login/index'
}) })
}, },
toUrl(url) {
this.$u.route({
url: url
})
},
logout() { logout() {
this.$u.vuex('vuex_token', '') this.$u.vuex('vuex_token', '')
this.$u.vuex('userInfo', {}) this.$u.vuex('userInfo', {})
......
...@@ -18,18 +18,8 @@ export default { ...@@ -18,18 +18,8 @@ export default {
} }
}, },
onShow() { onShow() {
this.checkLogin()
}, },
methods: { methods: {
checkLogin() {
if (this.vuex_token) {
uni.checkSession({
success: (result) => {
this.$u.route({ type: 'back' })
}
})
}
},
wxLogin() { wxLogin() {
// 获取code 小程序专有,用户登录凭证。 // 获取code 小程序专有,用户登录凭证。
uni.getUserProfile({ uni.getUserProfile({
......
<template>
<view class="content">
<view>
<text class="title">{{title}}</text>
</view>
</view>
</template>
<script>
export default {
data() {
return {
title: '我的客服'
}
},
onLoad() {
},
methods: {
}
}
</script>
<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.logo {
height: 200rpx;
width: 200rpx;
margin: 200rpx auto 50rpx auto;
}
.text-area {
display: flex;
justify-content: center;
}
.title {
font-size: 36rpx;
color: #8f8f94;
}
</style>
import { RouterMount, createRouter } from 'uni-simple-router' import { RouterMount, createRouter } from 'uni-simple-router'
import store from '@/store/index.js'
const router = createRouter({ const router = createRouter({
platform: process.env.VUE_APP_PLATFORM, platform: process.env.VUE_APP_PLATFORM,
routes: [...ROUTES], routes: [...ROUTES],
}) })
//全局路由前置守卫 // 检测登录白名单,无需登录也可访问的页面
const whiteList = ['index', 'cert', 'mine', 'login']
// 全局路由前置守卫
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
const token = store.state.vuex_token
// 进入需要授权的页面,未登录跳转
if (!whiteList.includes(to.name) && !token) {
next({ name: 'login', NAVTYPE: 'push' })
}
next() next()
}) })
......
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