Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
app-manage-console
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
ReactNative
app-manage-console
Commits
09a7b4e1
提交
09a7b4e1
authored
9月 11, 2018
作者:
vipcxj
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feature: 模块中可以配置页面路由
上级
4c14d83c
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
124 行增加
和
14 行删除
+124
-14
routes.js
src/components/hoc/routes.js
+14
-10
index.js
src/components/table/dstable/index.js
+2
-2
router.js
src/router.js
+2
-2
layout.js
src/utils/layout.js
+106
-0
没有找到文件。
src/components/hoc/routes.js
浏览文件 @
09a7b4e1
...
@@ -4,17 +4,21 @@ const route = (routes) => {
...
@@ -4,17 +4,21 @@ const route = (routes) => {
const
Wrapper
=
({
children
})
=>
{
const
Wrapper
=
({
children
})
=>
{
return
children
||
null
;
return
children
||
null
;
};
};
Wrapper
.
route
=
{
if
(
routes
.
indexRoute
)
{
indexRoute
:
{
Wrapper
.
route
=
routes
;
onEnter
(
nextState
,
replace
)
{
}
else
{
if
(
routes
&&
routes
.
childRoutes
&&
routes
.
childRoutes
.
length
>
0
)
{
Wrapper
.
route
=
{
const
index
=
routes
.
childRoutes
[
0
];
indexRoute
:
{
replace
(
makePath
(
nextState
.
match
.
url
,
index
.
path
));
onEnter
(
nextState
,
replace
)
{
}
if
(
routes
&&
routes
.
childRoutes
&&
routes
.
childRoutes
.
length
>
0
)
{
const
index
=
routes
.
childRoutes
[
0
];
replace
(
makePath
(
nextState
.
match
.
url
,
index
.
path
));
}
},
},
},
}
,
...
routes
,
...
routes
,
};
}
;
}
return
Wrapper
;
return
Wrapper
;
};
};
...
...
src/components/table/dstable/index.js
浏览文件 @
09a7b4e1
...
@@ -20,12 +20,12 @@ const renderButton = (meta) => {
...
@@ -20,12 +20,12 @@ const renderButton = (meta) => {
if
(
meta
.
path
)
{
if
(
meta
.
path
)
{
const
onClick
=
(
e
)
=>
{
const
onClick
=
(
e
)
=>
{
e
.
preventDefault
();
e
.
preventDefault
();
push
(
`../
${
meta
.
path
}
`
,
{
...
meta
});
push
(
meta
.
path
,
{
...
meta
});
};
};
const
onKeyDown
=
(
e
)
=>
{
const
onKeyDown
=
(
e
)
=>
{
if
(
e
.
keyCode
===
13
)
{
if
(
e
.
keyCode
===
13
)
{
e
.
preventDefault
();
e
.
preventDefault
();
push
(
`../
${
meta
.
path
}
`
,
{
...
meta
});
push
(
meta
.
path
,
{
...
meta
});
}
}
};
};
// noinspection JSUnresolvedVariable
// noinspection JSUnresolvedVariable
...
...
src/router.js
浏览文件 @
09a7b4e1
...
@@ -118,8 +118,8 @@ const createRoutes = async (app, modules, groups, basePath) => {
...
@@ -118,8 +118,8 @@ const createRoutes = async (app, modules, groups, basePath) => {
fullPath
:
combinePath
(
basePath
,
name
),
fullPath
:
combinePath
(
basePath
,
name
),
name
:
showName
,
name
:
showName
,
};
};
if
(
layout
.
route
)
{
if
(
layout
.
route
||
layout
.
template
)
{
let
routeBundle
=
await
import
(
`./routes/main/modules/
${
layout
.
route
}
`
);
let
routeBundle
=
await
import
(
`./routes/main/modules/
${
layout
.
route
||
layout
.
template
}
`
);
routeBundle
=
routeBundle
.
default
||
routeBundle
;
routeBundle
=
routeBundle
.
default
||
routeBundle
;
const
binder
=
bindModel
(
app
,
info
,
layout
);
const
binder
=
bindModel
(
app
,
info
,
layout
);
routeBundle
=
routeBundle
(
binder
,
info
,
layout
);
routeBundle
=
routeBundle
(
binder
,
info
,
layout
);
...
...
src/utils/layout.js
0 → 100644
浏览文件 @
09a7b4e1
/* eslint-disable dot-notation,no-param-reassign,no-underscore-dangle */
import
{
makePath
}
from
'./helper'
;
const
Empty
=
({
children
})
=>
{
return
children
||
null
;
};
const
parsePageToRoute
=
(
page
,
componentMapper
)
=>
{
const
{
pages
,
childRoutes
,
component
,
...
route
}
=
page
;
if
(
!
component
)
{
route
.
component
=
Empty
;
}
else
{
const
comp
=
componentMapper
[
component
];
if
(
!
comp
)
{
throw
new
Error
(
`Invalid component:
${
component
}
.`
);
}
route
.
component
=
comp
;
}
const
thePages
=
pages
||
childRoutes
;
if
(
thePages
&&
thePages
.
length
>
0
)
{
route
.
childRoutes
=
thePages
.
map
(
p
=>
parsePageToRoute
(
p
,
componentMapper
));
}
};
const
dealWithPath
=
(
path
)
=>
{
if
(
!
path
||
path
===
'/'
)
{
return
[];
}
let
noStart
=
false
;
let
noEnd
=
false
;
if
(
path
.
startsWith
(
'/'
))
{
noStart
=
true
;
}
if
(
path
.
endsWith
(
'/'
))
{
noEnd
=
true
;
}
if
(
noStart
||
noEnd
)
{
path
=
path
.
substring
(
noStart
?
1
:
0
,
noEnd
?
(
path
.
length
-
1
)
:
path
.
length
);
}
return
path
.
split
(
'/'
);
};
const
findRoutesByPath
=
(
routes
,
path
)
=>
{
const
parts
=
dealWithPath
(
path
);
return
_findRoutesByPath
(
routes
,
parts
);
};
const
_findRouteByPath
=
(
route
,
parts
)
=>
{
if
(
parts
.
length
===
0
)
{
return
[];
}
const
[
current
,
...
others
]
=
parts
;
if
(
route
.
path
===
current
)
{
if
(
parts
.
length
>
1
)
{
if
(
route
.
childRoutes
)
{
const
res
=
_findRoutesByPath
(
route
.
childRoutes
,
others
);
if
(
res
.
length
>
0
)
{
return
[
route
,
...
res
];
}
else
{
return
[];
}
}
else
{
return
[];
}
}
else
{
return
[
route
];
}
}
};
const
_findRoutesByPath
=
(
routes
,
parts
)
=>
{
for
(
const
route
of
routes
)
{
const
res
=
_findRouteByPath
(
route
,
parts
);
if
(
res
.
length
>
0
)
{
return
res
;
}
}
return
[];
};
export
const
parseLayout
=
(
layout
,
componentMapper
)
=>
{
const
route
=
{};
if
(
layout
[
'pages'
]
||
layout
.
childRoutes
)
{
route
.
childRoutes
=
(
layout
[
'pages'
]
||
layout
.
childRoutes
).
map
(
page
=>
parsePageToRoute
(
page
,
componentMapper
));
}
else
{
throw
new
Error
(
'No pages is found!'
);
}
if
(
layout
.
entry
)
{
if
(
typeof
layout
.
entry
!==
'object'
)
{
throw
new
Error
(
'The
\'
entry
\'
must be an object with struct: { path: string, datasource: string, params: object }.'
);
}
const
{
path
:
entryPath
,
...
state
}
=
layout
.
entry
;
if
(
!
entryPath
||
findRoutesByPath
(
route
.
childRoutes
).
length
===
0
)
{
throw
new
Error
(
'The
\'
entry
\'
should have a valid path property.'
);
}
route
.
indexRoute
=
{
onEnter
(
nextState
,
replace
)
{
replace
(
makePath
(
nextState
.
match
.
url
,
entryPath
),
state
);
},
};
}
else
{
throw
new
Error
(
'No entry is found!'
);
}
return
route
;
};
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论