Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
najiu-admin-template
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
najiu-frontend
najiu-admin-template
Commits
c6b766d8
Commit
c6b766d8
authored
Jun 11, 2021
by
无木
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(route): dynamically introduce components error
修复后台权限模式下,加载IFrame类型的路由时会丢失component的问题
parent
a222ec85
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
6 deletions
+44
-6
menu.ts
mock/sys/menu.ts
+30
-2
routeHelper.ts
src/router/helper/routeHelper.ts
+14
-4
No files found.
mock/sys/menu.ts
View file @
c6b766d8
...
...
@@ -168,6 +168,34 @@ const sysRoute = {
],
};
const
linkRoute
=
{
path
:
'
/link
'
,
name
:
'
Link
'
,
component
:
'
LAYOUT
'
,
meta
:
{
icon
:
'
ion:tv-outline
'
,
title
:
'
routes.demo.iframe.frame
'
,
},
children
:
[
{
path
:
'
doc
'
,
name
:
'
Doc
'
,
meta
:
{
title
:
'
routes.demo.iframe.doc
'
,
frameSrc
:
'
https://vvbin.cn/doc-next/
'
,
},
},
{
path
:
'
https://vvbin.cn/doc-next/
'
,
name
:
'
DocExternal
'
,
component
:
'
LAYOUT
'
,
meta
:
{
title
:
'
routes.demo.iframe.docExternal
'
,
},
},
],
};
export
default
[
{
url
:
'
/basic-api/getMenuList
'
,
...
...
@@ -184,10 +212,10 @@ export default [
}
const
id
=
checkUser
.
userId
;
if
(
!
id
||
id
===
'
1
'
)
{
return
resultSuccess
([
dashboardRoute
,
authRoute
,
levelRoute
,
sysRoute
]);
return
resultSuccess
([
dashboardRoute
,
authRoute
,
levelRoute
,
sysRoute
,
linkRoute
]);
}
if
(
id
===
'
2
'
)
{
return
resultSuccess
([
dashboardRoute
,
authRoute
,
levelRoute
]);
return
resultSuccess
([
dashboardRoute
,
authRoute
,
levelRoute
,
linkRoute
]);
}
},
},
...
...
src/router/helper/routeHelper.ts
View file @
c6b766d8
...
...
@@ -7,8 +7,12 @@ import { warn } from '/@/utils/log';
import
{
createRouter
,
createWebHashHistory
}
from
'
vue-router
'
;
export
type
LayoutMapKey
=
'
LAYOUT
'
;
const
IFRAME
=
()
=>
import
(
'
/@/views/sys/iframe/FrameBlank.vue
'
);
const
LayoutMap
=
new
Map
<
LayoutMapKey
,
()
=>
Promise
<
typeof
import
(
'
*.vue
'
)
>>
();
const
LayoutMap
=
new
Map
<
String
,
()
=>
Promise
<
typeof
import
(
'
*.vue
'
)
>>
();
LayoutMap
.
set
(
'
LAYOUT
'
,
LAYOUT
);
LayoutMap
.
set
(
'
IFRAME
'
,
IFRAME
);
let
dynamicViewsModules
:
Record
<
string
,
()
=>
Promise
<
Recordable
>>
;
...
...
@@ -17,10 +21,18 @@ function asyncImportRoute(routes: AppRouteRecordRaw[] | undefined) {
dynamicViewsModules
=
dynamicViewsModules
||
import
.
meta
.
glob
(
'
../../views/**/*.{vue,tsx}
'
);
if
(
!
routes
)
return
;
routes
.
forEach
((
item
)
=>
{
if
(
!
item
.
component
&&
item
.
meta
?.
frameSrc
)
{
item
.
component
=
'
IFRAME
'
;
}
const
{
component
,
name
}
=
item
;
const
{
children
}
=
item
;
if
(
component
)
{
item
.
component
=
dynamicImport
(
dynamicViewsModules
,
component
as
string
);
const
layoutFound
=
LayoutMap
.
get
(
component
);
if
(
layoutFound
)
{
item
.
component
=
layoutFound
;
}
else
{
item
.
component
=
dynamicImport
(
dynamicViewsModules
,
component
as
string
);
}
}
else
if
(
name
)
{
item
.
component
=
getParentLayout
();
}
...
...
@@ -53,8 +65,6 @@ function dynamicImport(
// Turn background objects into routing objects
export
function
transformObjToRoute
<
T
=
AppRouteModule
>
(
routeList
:
AppRouteModule
[]):
T
[]
{
LayoutMap
.
set
(
'
LAYOUT
'
,
LAYOUT
);
routeList
.
forEach
((
route
)
=>
{
if
(
route
.
component
)
{
if
((
route
.
component
as
string
).
toUpperCase
()
===
'
LAYOUT
'
)
{
...
...
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