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
Show 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
>
<a-layout
:class=
"['admin-layout', 'beauty-scroll']"
>
<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>
<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"
>
<div
class=
"setting"
slot=
"handler"
>
...
...
@@ -17,8 +33,20 @@
</drawer>
<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" />
<a-layout-header
:class=
"['virtual-header',
{'fixed-tabs' : fixedTabs, 'fixed-header': fixedHeader, 'multi-page': multiPage}]" v-show="fixedHeader">
</a-layout-header>
<layout-top-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;`">
<div
style=
"position: relative"
>
<slot></slot>
...
...
@@ -126,7 +154,7 @@ export default {
matched
=
matched
.
slice
(
0
,
matched
.
length
-
1
);
const
{
firstMenu
}
=
this
;
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
);
break
;
}
...
...
src/pages/frame/view/login/Login.vue
View file @
ea21c88e
...
...
@@ -78,7 +78,7 @@
<
script
>
import
CommonLayout
from
'
@/pages/frame/layouts/CommonLayout
'
;
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
{
mapMutations
}
from
'
vuex
'
;
import
loginI18n
from
'
./i18n
'
;
...
...
@@ -120,19 +120,9 @@ export default {
afterLogin
(
result
)
{
this
.
logging
=
false
;
const
{
token
,
userId
}
=
result
;
console
.
log
(
token
);
setToken
(
token
);
setUserId
(
userId
);
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 @@
</
template
>
<
script
>
import
PageLayout
from
'
../../layouts/PageLayout
'
;
import
PageLayout
from
'
../../layouts/PageLayout
.vue
'
;
import
PageToggleTransition
from
'
@/components/transition/PageToggleTransition
'
;
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 @@
</template>
<
script
>
import
{
convertListToTree
}
from
'
@/utils
'
;
export
default
{
data
:
()
=>
({
add
:
{},
addBtn
:
{
text
:
'
新建
'
,
title
:
'
菜单配置
'
},
sortOrder
:
'
ascend
'
,
}),
methods
:
{
formatData
(
data
=
[])
{
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
;
},
formatData
:
convertListToTree
,
sorter
(
pre
,
next
)
{
return
pre
.
viewIndex
-
next
.
viewIndex
;
},
...
...
src/utils/i18nUtil.js
View file @
ea21c88e
import
routesI18n
from
'
@/router/i18n
'
import
{
getI18nKey
}
from
'
@/utils/routerUtil
'
import
routesI18n
from
'
@/router/i18n
'
;
import
{
getI18nKey
}
from
'
@/utils/routerUtil
'
;
/**
* 根据 router options 配置生成 国际化语言
...
...
@@ -10,22 +10,28 @@ import {getI18nKey} from '@/utils/routerUtil'
*/
function
generateI18n
(
lang
,
routes
,
valueKey
)
{
routes
.
forEach
(
route
=>
{
let
keys
=
getI18nKey
(
route
.
fullPath
).
split
(
'
.
'
)
let
value
=
valueKey
===
'
path
'
?
route
[
valueKey
].
split
(
'
/
'
).
filter
(
item
=>
!
item
.
startsWith
(
'
:
'
)
&&
item
!=
''
).
join
(
'
.
'
)
:
route
[
valueKey
]
let
keys
=
getI18nKey
(
route
.
fullPath
).
split
(
'
.
'
);
console
.
log
(
keys
);
let
value
=
valueKey
===
'
path
'
?
route
[
valueKey
]
.
split
(
'
/
'
)
.
filter
(
item
=>
!
item
.
startsWith
(
'
:
'
)
&&
item
!=
''
)
.
join
(
'
.
'
)
:
route
[
valueKey
];
if
(
value
.
includes
(
'
_
'
))
{
value
=
value
.
replace
(
'
_
'
,
'
'
);
value
=
value
.
toLowerCase
().
replace
(
/
(
|^
)[
a-z
]
/g
,
(
L
)
=>
L
.
toUpperCase
());
}
else
{
value
=
value
.
charAt
(
0
).
toUpperCase
()
+
value
.
toLowerCase
().
substring
(
1
)
value
=
value
.
toLowerCase
().
replace
(
/
(
|^
)[
a-z
]
/g
,
L
=>
L
.
toUpperCase
());
}
else
{
value
=
value
.
charAt
(
0
).
toUpperCase
()
+
value
.
toLowerCase
().
substring
(
1
);
}
lang
.
assignProps
(
keys
,
value
)
lang
.
assignProps
(
keys
,
value
);
if
(
route
.
children
)
{
generateI18n
(
lang
,
route
.
children
,
valueKey
)
generateI18n
(
lang
,
route
.
children
,
valueKey
);
}
})
return
lang
});
return
lang
;
}
/**
...
...
@@ -35,12 +41,16 @@ function generateI18n(lang, routes, valueKey) {
*/
function
formatFullPath
(
routes
,
parentPath
=
''
)
{
routes
.
forEach
(
route
=>
{
let
isFullPath
=
route
.
path
.
substring
(
0
,
1
)
===
'
/
'
route
.
fullPath
=
isFullPath
?
route
.
path
:
(
parentPath
===
'
/
'
?
parentPath
+
route
.
path
:
parentPath
+
'
/
'
+
route
.
path
)
let
isFullPath
=
route
.
path
.
substring
(
0
,
1
)
===
'
/
'
;
route
.
fullPath
=
isFullPath
?
route
.
path
:
parentPath
===
'
/
'
?
parentPath
+
route
.
path
:
parentPath
+
'
/
'
+
route
.
path
;
if
(
route
.
children
)
{
formatFullPath
(
route
.
children
,
route
.
fullPath
)
formatFullPath
(
route
.
children
,
route
.
fullPath
);
}
})
});
}
/**
...
...
@@ -49,16 +59,16 @@ function formatFullPath(routes, parentPath = '') {
* @param routes
*/
function
mergeI18nFromRoutes
(
i18n
,
routes
)
{
formatFullPath
(
routes
)
const
zh_CN
=
generateI18n
(
new
Object
(),
routes
,
'
name
'
)
const
en_US
=
generateI18n
(
new
Object
(),
routes
,
'
path
'
)
formatFullPath
(
routes
);
const
zh_CN
=
generateI18n
(
new
Object
(),
routes
,
'
name
'
);
const
en_US
=
generateI18n
(
new
Object
(),
routes
,
'
path
'
);
i18n
.
mergeLocaleMessage
(
'
zh_CN
'
,
zh_CN
)
i18n
.
mergeLocaleMessage
(
'
en_US
'
,
en_US
)
const
messages
=
routesI18n
.
messages
i18n
.
mergeLocaleMessage
(
'
zh_CN
'
,
zh_CN
);
i18n
.
mergeLocaleMessage
(
'
en_US
'
,
en_US
);
const
messages
=
routesI18n
.
messages
;
Object
.
keys
(
messages
).
forEach
(
lang
=>
{
i18n
.
mergeLocaleMessage
(
lang
,
messages
[
lang
])
})
i18n
.
mergeLocaleMessage
(
lang
,
messages
[
lang
]);
});
}
/**
...
...
@@ -71,22 +81,19 @@ Object.defineProperty(Object.prototype, 'assignProps', {
writable
:
false
,
enumerable
:
false
,
configurable
:
true
,
value
:
function
(
keys
,
value
)
{
let
props
=
this
value
:
function
(
keys
,
value
)
{
let
props
=
this
;
for
(
let
i
=
0
;
i
<
keys
.
length
;
i
++
)
{
let
key
=
keys
[
i
]
let
key
=
keys
[
i
];
if
(
i
==
keys
.
length
-
1
)
{
props
[
key
]
=
value
props
[
key
]
=
value
;
}
else
{
props
[
key
]
=
props
[
key
]
==
undefined
?
{}
:
props
[
key
]
props
=
props
[
key
]
props
[
key
]
=
props
[
key
]
==
undefined
?
{}
:
props
[
key
];
props
=
props
[
key
];
}
}
return
this
}
})
return
this
;
},
})
;
export
{
mergeI18nFromRoutes
,
formatFullPath
}
export
{
mergeI18nFromRoutes
,
formatFullPath
};
src/utils/index.js
View file @
ea21c88e
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