Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Admin
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
周远喜
Admin
Commits
92334c13
Commit
92334c13
authored
Mar 22, 2020
by
周远喜
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
多语言和登陆限制功能添加
parent
af2e874e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
0 deletions
+29
-0
default.vue
layouts/default.vue
+1
-0
auth.js
middleware/auth.js
+7
-0
i18n.js
middleware/i18n.js
+21
-0
No files found.
layouts/default.vue
View file @
92334c13
...
@@ -15,6 +15,7 @@ import menuSider from '@/menu/sider';
...
@@ -15,6 +15,7 @@ import menuSider from '@/menu/sider';
import
{
frameInRoutes
}
from
'@/router/routes'
;
import
{
frameInRoutes
}
from
'@/router/routes'
;
export
default
{
export
default
{
middleware
:
'auth'
,
components
:
{
MainLayout
},
components
:
{
MainLayout
},
created
()
{
created
()
{
// const filterMenuSider = getMenuSider(menuSider, "home");
// const filterMenuSider = getMenuSider(menuSider, "home");
...
...
middleware/auth.js
0 → 100644
View file @
92334c13
import
util
from
'@/libs/util'
;
export
default
function
({
route
,
req
,
res
,
redirect
,
store
})
{
var
token
=
util
.
cookies
.
get
(
'token'
);
if
(
!
token
)
{
redirect
(
"/account/login"
);
}
}
\ No newline at end of file
middleware/i18n.js
0 → 100644
View file @
92334c13
export
default
function
({
isHMR
,
app
,
store
,
route
,
params
,
error
,
redirect
})
{
const
defaultLocale
=
app
.
i18n
.
fallbackLocale
// If middleware is called from hot module replacement, ignore it
if
(
isHMR
)
{
return
}
// Get locale from params
const
locale
=
params
.
lang
||
defaultLocale
if
(
!
store
.
state
.
locales
.
includes
(
locale
))
{
return
error
({
message
:
'This page could not be found.'
,
statusCode
:
404
})
}
// Set locale
store
.
commit
(
'SET_LANG'
,
locale
)
app
.
i18n
.
locale
=
store
.
state
.
locale
// If route is /<defaultLocale>/... -> redirect to /...
if
(
locale
===
defaultLocale
&&
route
.
fullPath
.
indexOf
(
'/'
+
defaultLocale
)
===
0
)
{
const
toReplace
=
'^/'
+
defaultLocale
+
(
route
.
fullPath
.
indexOf
(
'/'
+
defaultLocale
+
'/'
)
===
0
?
'/'
:
''
)
const
re
=
new
RegExp
(
toReplace
)
return
redirect
(
route
.
fullPath
.
replace
(
re
,
'/'
)
)
}
}
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