Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
Starter Web Vue
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
product
kim3-web-vue
Starter Web Vue
Commits
ea21c88e
Commit
ea21c88e
authored
Jun 27, 2021
by
水落(YangLei)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 路由逻辑处理
parent
42e2fa95
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
138 additions
and
96 deletions
+138
-96
src/api/index.js
src/api/index.js
+5
-0
src/pages/frame/layouts/AdminLayout.vue
src/pages/frame/layouts/AdminLayout.vue
+35
-7
src/pages/frame/view/login/Login.vue
src/pages/frame/view/login/Login.vue
+2
-12
src/pages/frame/view/template/PageTemplateView.vue
src/pages/frame/view/template/PageTemplateView.vue
+1
-1
src/pages/home/index.vue
src/pages/home/index.vue
+3
-0
src/pages/system/view/menu/MenuManagement.vue
src/pages/system/view/menu/MenuManagement.vue
+4
-19
src/utils/i18nUtil.js
src/utils/i18nUtil.js
+64
-57
src/utils/index.js
src/utils/index.js
+24
-0
No files found.
src/api/index.js
0 → 100644
View file @
ea21c88e
import
{
request
,
METHOD
}
from
'
@/utils
'
;
export
function
getUserDetailInfoApi
()
{
return
request
(
'
/api/v1/detail
'
,
METHOD
.
GET
);
}
src/pages/frame/layouts/AdminLayout.vue
View file @
ea21c88e
<
template
>
<
template
>
<a-layout
:class=
"['admin-layout', 'beauty-scroll']"
>
<a-layout
:class=
"['admin-layout', 'beauty-scroll']"
>
<drawer
v-if=
"isMobile"
v-model=
"drawerOpen"
>
<drawer
v-if=
"isMobile"
v-model=
"drawerOpen"
>
<side-menu
:theme=
"theme.mode"
:menuData=
"menuData"
:collapsed=
"false"
:collapsible=
"false"
@
menuSelect=
"onMenuSelect"
/>
<side-menu
:theme=
"theme.mode"
:menuData=
"menuData"
:collapsed=
"false"
:collapsible=
"false"
@
menuSelect=
"onMenuSelect"
/>
</drawer>
</drawer>
<side-menu
:class=
"[fixedSideBar ? 'fixed-side' : '']"
:theme=
"theme.mode"
v-else-if=
"layout === 'side' || layout === 'mix'"
:menuData=
"sideMenuData"
:collapsed=
"collapsed"
:collapsible=
"true"
/>
<side-menu
:class=
"[fixedSideBar ? 'fixed-side' : '']"
:theme=
"theme.mode"
v-else-if=
"layout === 'side' || layout === 'mix'"
:menuData=
"sideMenuData"
:collapsed=
"collapsed"
:collapsible=
"true"
/>
<div
v-if=
"fixedSideBar && !isMobile"
:style=
"`width: $
{sideMenuWidth}; min-width: ${sideMenuWidth};max-width: ${sideMenuWidth};`" class="virtual-side">
<div
</div>
v-if=
"fixedSideBar && !isMobile"
:style=
"`width: $
{sideMenuWidth}; min-width: ${sideMenuWidth};max-width: ${sideMenuWidth};`"
class="virtual-side"
>
</div>
<drawer
v-if=
"!hideSettingExtend"
v-model=
"showSetting"
placement=
"right"
>
<drawer
v-if=
"!hideSettingExtend"
v-model=
"showSetting"
placement=
"right"
>
<div
class=
"setting"
slot=
"handler"
>
<div
class=
"setting"
slot=
"handler"
>
...
@@ -17,8 +33,20 @@
...
@@ -17,8 +33,20 @@
</drawer>
</drawer>
<a-layout
class=
"admin-layout-main beauty-scroll"
>
<a-layout
class=
"admin-layout-main beauty-scroll"
>
<layout-top-header
:class=
"[
{'fixed-tabs': fixedTabs, 'fixed-header': fixedHeader, 'multi-page': multiPage}]" :style="headerStyle" :menuData="headMenuData" :collapsed="collapsed" @toggleCollapse="toggleCollapse" />
<layout-top-header
<a-layout-header
:class=
"['virtual-header',
{'fixed-tabs' : fixedTabs, 'fixed-header': fixedHeader, 'multi-page': multiPage}]" v-show="fixedHeader">
</a-layout-header>
:class=
"[
{ 'fixed-tabs': fixedTabs, 'fixed-header': fixedHeader, 'multi-page': multiPage }]"
:style="headerStyle"
:menuData="headMenuData"
:collapsed="collapsed"
@toggleCollapse="toggleCollapse"
/>
<a-layout-header
:class=
"[
'virtual-header',
{ 'fixed-tabs': fixedTabs, 'fixed-header': fixedHeader, 'multi-page': multiPage },
]"
v-show="fixedHeader"
>
</a-layout-header>
<a-layout-content
class=
"admin-layout-content"
:style=
"`min-height: $
{minHeight}px;`">
<a-layout-content
class=
"admin-layout-content"
:style=
"`min-height: $
{minHeight}px;`">
<div
style=
"position: relative"
>
<div
style=
"position: relative"
>
<slot></slot>
<slot></slot>
...
@@ -126,7 +154,7 @@ export default {
...
@@ -126,7 +154,7 @@ export default {
matched
=
matched
.
slice
(
0
,
matched
.
length
-
1
);
matched
=
matched
.
slice
(
0
,
matched
.
length
-
1
);
const
{
firstMenu
}
=
this
;
const
{
firstMenu
}
=
this
;
for
(
let
menu
of
firstMenu
)
{
for
(
let
menu
of
firstMenu
)
{
if
(
matched
.
findIndex
(
(
item
)
=>
item
.
path
===
menu
.
fullPath
)
!==
-
1
)
{
if
(
matched
.
findIndex
(
item
=>
item
.
path
===
menu
.
fullPath
)
!==
-
1
)
{
this
.
setActivatedFirst
(
menu
.
fullPath
);
this
.
setActivatedFirst
(
menu
.
fullPath
);
break
;
break
;
}
}
...
...
src/pages/frame/view/login/Login.vue
View file @
ea21c88e
...
@@ -78,7 +78,7 @@
...
@@ -78,7 +78,7 @@
<
script
>
<
script
>
import
CommonLayout
from
'
@/pages/frame/layouts/CommonLayout
'
;
import
CommonLayout
from
'
@/pages/frame/layouts/CommonLayout
'
;
import
{
login
}
from
'
@/pages/frame/services/accountService
'
;
import
{
login
}
from
'
@/pages/frame/services/accountService
'
;
import
{
setToken
,
clearToken
}
from
'
@/utils/requestUtil
'
;
import
{
setToken
,
clearToken
,
setUserId
}
from
'
@/utils
'
;
import
{
loadRoutes
}
from
'
@/utils/routerUtil
'
;
import
{
loadRoutes
}
from
'
@/utils/routerUtil
'
;
import
{
mapMutations
}
from
'
vuex
'
;
import
{
mapMutations
}
from
'
vuex
'
;
import
loginI18n
from
'
./i18n
'
;
import
loginI18n
from
'
./i18n
'
;
...
@@ -120,19 +120,9 @@ export default {
...
@@ -120,19 +120,9 @@ export default {
afterLogin
(
result
)
{
afterLogin
(
result
)
{
this
.
logging
=
false
;
this
.
logging
=
false
;
const
{
token
,
userId
}
=
result
;
const
{
token
,
userId
}
=
result
;
console
.
log
(
token
);
setToken
(
token
);
setToken
(
token
);
setUserId
(
userId
);
this
.
$router
.
replace
(
'
/dashboard/workbench
'
);
this
.
$router
.
replace
(
'
/dashboard/workbench
'
);
// this.setUser(user);
// this.setPermissions(permissions);
// this.setRoles(roles);
// setAuthorization({
// token: loginResult.data.token,
// expireAt: new Date(loginResult.data.expireAt),
// });
// // 获取路由配置
// loadRoutes(routers);
},
},
},
},
};
};
...
...
src/pages/frame/view/template/PageTemplateView.vue
View file @
ea21c88e
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
</
template
>
</
template
>
<
script
>
<
script
>
import
PageLayout
from
'
../../layouts/PageLayout
'
;
import
PageLayout
from
'
../../layouts/PageLayout
.vue
'
;
import
PageToggleTransition
from
'
@/components/transition/PageToggleTransition
'
;
import
PageToggleTransition
from
'
@/components/transition/PageToggleTransition
'
;
import
{
mapState
}
from
'
vuex
'
;
import
{
mapState
}
from
'
vuex
'
;
...
...
src/pages/home/index.vue
0 → 100644
View file @
ea21c88e
<
template
>
<h1>
Home
</h1>
</
template
>
src/pages/system/view/menu/MenuManagement.vue
View file @
ea21c88e
...
@@ -26,32 +26,17 @@
...
@@ -26,32 +26,17 @@
</template>
</template>
<
script
>
<
script
>
import
{
convertListToTree
}
from
'
@/utils
'
;
export
default
{
export
default
{
data
:
()
=>
({
data
:
()
=>
({
add
:
{},
add
:
{},
addBtn
:
{
text
:
'
新建
'
,
title
:
'
菜单配置
'
},
addBtn
:
{
text
:
'
新建
'
,
title
:
'
菜单配置
'
},
sortOrder
:
'
ascend
'
,
sortOrder
:
'
ascend
'
,
}),
}),
methods
:
{
methods
:
{
formatData
(
data
=
[])
{
formatData
:
convertListToTree
,
let
menu
,
res
=
[],
tmp
=
data
.
slice
();
while
((
menu
=
tmp
.
pop
()))
{
if
(
menu
.
parentMenuId
===
0
)
res
.
push
(
menu
);
else
{
for
(
const
resetMenu
of
data
)
{
if
(
menu
.
parentMenuId
===
resetMenu
.
menuId
)
{
resetMenu
.
children
?
resetMenu
.
children
.
push
(
menu
)
:
(
resetMenu
.
children
=
[
menu
]);
}
}
}
}
console
.
log
(
res
);
return
res
;
},
sorter
(
pre
,
next
)
{
sorter
(
pre
,
next
)
{
return
pre
.
viewIndex
-
next
.
viewIndex
;
return
pre
.
viewIndex
-
next
.
viewIndex
;
},
},
...
...
src/utils/i18nUtil.js
View file @
ea21c88e
import
routesI18n
from
'
@/router/i18n
'
import
routesI18n
from
'
@/router/i18n
'
;
import
{
getI18nKey
}
from
'
@/utils/routerUtil
'
import
{
getI18nKey
}
from
'
@/utils/routerUtil
'
;
/**
/**
* 根据 router options 配置生成 国际化语言
* 根据 router options 配置生成 国际化语言
...
@@ -9,23 +9,29 @@ import {getI18nKey} from '@/utils/routerUtil'
...
@@ -9,23 +9,29 @@ import {getI18nKey} from '@/utils/routerUtil'
* @returns {*}
* @returns {*}
*/
*/
function
generateI18n
(
lang
,
routes
,
valueKey
)
{
function
generateI18n
(
lang
,
routes
,
valueKey
)
{
routes
.
forEach
(
route
=>
{
routes
.
forEach
(
route
=>
{
let
keys
=
getI18nKey
(
route
.
fullPath
).
split
(
'
.
'
)
let
keys
=
getI18nKey
(
route
.
fullPath
).
split
(
'
.
'
);
let
value
=
valueKey
===
'
path
'
?
route
[
valueKey
].
split
(
'
/
'
).
filter
(
item
=>
!
item
.
startsWith
(
'
:
'
)
&&
item
!=
''
).
join
(
'
.
'
)
:
route
[
valueKey
]
console
.
log
(
keys
);
if
(
value
.
includes
(
'
_
'
))
{
let
value
=
value
=
value
.
replace
(
'
_
'
,
'
'
);
valueKey
===
'
path
'
value
=
value
.
toLowerCase
().
replace
(
/
(
|^
)[
a-z
]
/g
,
(
L
)
=>
L
.
toUpperCase
());
?
route
[
valueKey
]
}
.
split
(
'
/
'
)
else
{
.
filter
(
item
=>
!
item
.
startsWith
(
'
:
'
)
&&
item
!=
''
)
value
=
value
.
charAt
(
0
).
toUpperCase
()
+
value
.
toLowerCase
().
substring
(
1
)
.
join
(
'
.
'
)
}
:
route
[
valueKey
];
if
(
value
.
includes
(
'
_
'
))
{
lang
.
assignProps
(
keys
,
value
)
value
=
value
.
replace
(
'
_
'
,
'
'
);
if
(
route
.
children
)
{
value
=
value
.
toLowerCase
().
replace
(
/
(
|^
)[
a-z
]
/g
,
L
=>
L
.
toUpperCase
());
generateI18n
(
lang
,
route
.
children
,
valueKey
)
}
else
{
}
value
=
value
.
charAt
(
0
).
toUpperCase
()
+
value
.
toLowerCase
().
substring
(
1
);
})
}
return
lang
lang
.
assignProps
(
keys
,
value
);
if
(
route
.
children
)
{
generateI18n
(
lang
,
route
.
children
,
valueKey
);
}
});
return
lang
;
}
}
/**
/**
...
@@ -34,13 +40,17 @@ function generateI18n(lang, routes, valueKey) {
...
@@ -34,13 +40,17 @@ function generateI18n(lang, routes, valueKey) {
* @param parentPath
* @param parentPath
*/
*/
function
formatFullPath
(
routes
,
parentPath
=
''
)
{
function
formatFullPath
(
routes
,
parentPath
=
''
)
{
routes
.
forEach
(
route
=>
{
routes
.
forEach
(
route
=>
{
let
isFullPath
=
route
.
path
.
substring
(
0
,
1
)
===
'
/
'
let
isFullPath
=
route
.
path
.
substring
(
0
,
1
)
===
'
/
'
;
route
.
fullPath
=
isFullPath
?
route
.
path
:
(
parentPath
===
'
/
'
?
parentPath
+
route
.
path
:
parentPath
+
'
/
'
+
route
.
path
)
route
.
fullPath
=
isFullPath
if
(
route
.
children
)
{
?
route
.
path
formatFullPath
(
route
.
children
,
route
.
fullPath
)
:
parentPath
===
'
/
'
}
?
parentPath
+
route
.
path
})
:
parentPath
+
'
/
'
+
route
.
path
;
if
(
route
.
children
)
{
formatFullPath
(
route
.
children
,
route
.
fullPath
);
}
});
}
}
/**
/**
...
@@ -49,16 +59,16 @@ function formatFullPath(routes, parentPath = '') {
...
@@ -49,16 +59,16 @@ function formatFullPath(routes, parentPath = '') {
* @param routes
* @param routes
*/
*/
function
mergeI18nFromRoutes
(
i18n
,
routes
)
{
function
mergeI18nFromRoutes
(
i18n
,
routes
)
{
formatFullPath
(
routes
)
formatFullPath
(
routes
);
const
zh_CN
=
generateI18n
(
new
Object
(),
routes
,
'
name
'
)
const
zh_CN
=
generateI18n
(
new
Object
(),
routes
,
'
name
'
);
const
en_US
=
generateI18n
(
new
Object
(),
routes
,
'
path
'
)
const
en_US
=
generateI18n
(
new
Object
(),
routes
,
'
path
'
);
i18n
.
mergeLocaleMessage
(
'
zh_CN
'
,
zh_CN
)
i18n
.
mergeLocaleMessage
(
'
zh_CN
'
,
zh_CN
);
i18n
.
mergeLocaleMessage
(
'
en_US
'
,
en_US
)
i18n
.
mergeLocaleMessage
(
'
en_US
'
,
en_US
);
const
messages
=
routesI18n
.
messages
const
messages
=
routesI18n
.
messages
;
Object
.
keys
(
messages
).
forEach
(
lang
=>
{
Object
.
keys
(
messages
).
forEach
(
lang
=>
{
i18n
.
mergeLocaleMessage
(
lang
,
messages
[
lang
])
i18n
.
mergeLocaleMessage
(
lang
,
messages
[
lang
]);
})
});
}
}
/**
/**
...
@@ -68,25 +78,22 @@ function mergeI18nFromRoutes(i18n, routes) {
...
@@ -68,25 +78,22 @@ function mergeI18nFromRoutes(i18n, routes) {
* @returns {Object}
* @returns {Object}
*/
*/
Object
.
defineProperty
(
Object
.
prototype
,
'
assignProps
'
,
{
Object
.
defineProperty
(
Object
.
prototype
,
'
assignProps
'
,
{
writable
:
false
,
writable
:
false
,
enumerable
:
false
,
enumerable
:
false
,
configurable
:
true
,
configurable
:
true
,
value
:
function
(
keys
,
value
)
{
value
:
function
(
keys
,
value
)
{
let
props
=
this
let
props
=
this
;
for
(
let
i
=
0
;
i
<
keys
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
keys
.
length
;
i
++
)
{
let
key
=
keys
[
i
]
let
key
=
keys
[
i
];
if
(
i
==
keys
.
length
-
1
)
{
if
(
i
==
keys
.
length
-
1
)
{
props
[
key
]
=
value
props
[
key
]
=
value
;
}
else
{
}
else
{
props
[
key
]
=
props
[
key
]
==
undefined
?
{}
:
props
[
key
]
props
[
key
]
=
props
[
key
]
==
undefined
?
{}
:
props
[
key
];
props
=
props
[
key
]
props
=
props
[
key
];
}
}
}
}
return
this
return
this
;
}
},
})
})
;
export
{
export
{
mergeI18nFromRoutes
,
formatFullPath
};
mergeI18nFromRoutes
,
formatFullPath
}
src/utils/index.js
View file @
ea21c88e
export
{
default
as
langUtil
}
from
'
./langUtils
'
;
export
{
default
as
langUtil
}
from
'
./langUtils
'
;
export
*
from
'
./requestUtil
'
;
const
USERID_KEY
=
'
userId
'
;
export
function
getUserId
()
{
return
window
.
sessionStorage
.
getItem
(
USERID_KEY
)
||
''
;
}
export
function
setUserId
(
val
)
{
window
.
sessionStorage
.
setItem
(
USERID_KEY
,
val
);
}
/**
* 转变菜单列表为tree结构
* @param {Array} menuList 菜单列表
*/
export
function
convertListToTree
(
menuList
)
{
const
tempMenu
=
[...
menuList
];
for
(
const
menu
of
menuList
)
{
if
(
menu
.
parentMenuId
===
0
)
continue
;
const
parent
=
menuList
.
find
(
m
=>
m
.
menuId
===
menu
.
parentMenuId
);
parent
.
children
?
parent
.
children
.
push
(
menu
)
:
(
parent
.
children
=
[
menu
]);
}
return
tempMenu
.
filter
(
m
=>
m
.
parentMenuId
===
0
);
}
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