Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
study
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Damon
study
Commits
997efc74
Commit
997efc74
authored
Jul 12, 2021
by
Damon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 用户授权拦截
parent
56507c13
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
65 additions
and
37 deletions
+65
-37
App.vue
src/App.vue
+0
-23
http.interceptor.js
src/common/http.interceptor.js
+1
-1
pages.json
src/pages.json
+0
-1
mine.vue
src/pages/index/mine.vue
+6
-1
index.vue
src/pages/login/index.vue
+0
-10
customer.vue
src/pages/mine/customer.vue
+48
-0
router.js
src/router.js
+10
-1
No files found.
src/App.vue
View file @
997efc74
...
...
@@ -3,8 +3,6 @@ export default {
onLaunch
:
function
()
{
// 版本更新
this
.
updateApp
()
// 检查登录是否已过期
this
.
checkLogin
()
},
onShow
:
function
()
{
console
.
log
(
'App Show'
)
...
...
@@ -13,27 +11,6 @@ export default {
console
.
log
(
'App Hide'
)
},
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
()
{
if
(
uni
.
canIUse
(
'getUpdateManager'
))
{
...
...
src/common/http.interceptor.js
View file @
997efc74
...
...
@@ -45,7 +45,7 @@ const install = (Vue, vm) => {
vm
.
$u
.
toast
(
'验证失败,请重新登录'
);
setTimeout
(()
=>
{
// 此为uView的方法,详见路由相关文档
vm
.
$u
.
route
(
'/pages/
user/login
'
)
vm
.
$u
.
route
(
'/pages/
login/index
'
)
},
1500
)
return
false
;
}
else
{
...
...
src/pages.json
View file @
997efc74
...
...
@@ -76,7 +76,6 @@
"path"
:
"customer"
,
"name"
:
"mineCustomer"
,
"style"
:
{
"navigationStyle"
:
"custom"
,
"navigationBarTitleText"
:
"联系客服"
,
"enablePullDownRefresh"
:
false
,
"disableScroll"
:
true
...
...
src/pages/index/mine.vue
View file @
997efc74
...
...
@@ -14,7 +14,7 @@
<u-cell-group>
<u-cell-item
icon=
"star"
title=
"个人信息"
value=
"完善度40%"
></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-group>
</view>
...
...
@@ -46,6 +46,11 @@
url
:
'pages/login/index'
})
},
toUrl
(
url
)
{
this
.
$u
.
route
({
url
:
url
})
},
logout
()
{
this
.
$u
.
vuex
(
'vuex_token'
,
''
)
this
.
$u
.
vuex
(
'userInfo'
,
{})
...
...
src/pages/login/index.vue
View file @
997efc74
...
...
@@ -18,18 +18,8 @@ export default {
}
},
onShow
()
{
this
.
checkLogin
()
},
methods
:
{
checkLogin
()
{
if
(
this
.
vuex_token
)
{
uni
.
checkSession
({
success
:
(
result
)
=>
{
this
.
$u
.
route
({
type
:
'back'
})
}
})
}
},
wxLogin
()
{
// 获取code 小程序专有,用户登录凭证。
uni
.
getUserProfile
({
...
...
src/pages/mine/customer.vue
View file @
997efc74
<
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
:
200
rpx
;
width
:
200
rpx
;
margin
:
200
rpx
auto
50
rpx
auto
;
}
.text-area
{
display
:
flex
;
justify-content
:
center
;
}
.title
{
font-size
:
36
rpx
;
color
:
#8f8f94
;
}
</
style
>
src/router.js
View file @
997efc74
import
{
RouterMount
,
createRouter
}
from
'uni-simple-router'
import
store
from
'@/store/index.js'
const
router
=
createRouter
({
platform
:
process
.
env
.
VUE_APP_PLATFORM
,
routes
:
[...
ROUTES
],
})
//全局路由前置守卫
// 检测登录白名单,无需登录也可访问的页面
const
whiteList
=
[
'index'
,
'cert'
,
'mine'
,
'login'
]
// 全局路由前置守卫
router
.
beforeEach
((
to
,
from
,
next
)
=>
{
const
token
=
store
.
state
.
vuex_token
// 进入需要授权的页面,未登录跳转
if
(
!
whiteList
.
includes
(
to
.
name
)
&&
!
token
)
{
next
({
name
:
'login'
,
NAVTYPE
:
'push'
})
}
next
()
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment