Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
app-manage-console
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
ReactNative
app-manage-console
Commits
76451936
提交
76451936
authored
9月 07, 2017
作者:
vipcxj
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
模块信息获取机制大改。
上级
c465c148
隐藏空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
320 行增加
和
170 行删除
+320
-170
.roadhogrc.js
.roadhogrc.js
+3
-2
SiderMenu.js
src/components/layout/sider/SiderMenu.js
+0
-2
modules.js
src/data/modules.js
+122
-39
index.js
src/models/main/index.js
+70
-53
test.js
src/register/modules/test.js
+39
-0
router.js
src/router.js
+73
-60
datasource.js
src/services/datasource.js
+5
-5
main.js
src/services/main.js
+0
-5
modules.js
src/services/modules.js
+8
-4
没有找到文件。
.roadhogrc.js
浏览文件 @
76451936
const
proxy
=
{
"target"
:
"http://192.168.1.
5:809
0"
,
"target"
:
"http://192.168.1.
121:818
0"
,
"changeOrigin"
:
true
,
"pathRewrite"
:
{
"^/api"
:
"/big-machine/restful-services"
...
...
@@ -28,7 +28,8 @@ module.exports = {
"/api/user"
:
proxy
,
"/api/domain"
:
proxy
,
"/api/datasource"
:
proxy
,
"/api/modules"
:
proxy
,
"/api/module"
:
proxy
,
"/api/configure"
:
proxy
,
}
},
"production"
:
{
...
...
src/components/layout/sider/SiderMenu.js
浏览文件 @
76451936
...
...
@@ -73,8 +73,6 @@ SiderMenu.propTypes = {
name
:
PropTypes
.
string
,
icon
:
PropTypes
.
string
,
text
:
PropTypes
.
string
,
hint
:
PropTypes
.
string
,
path
:
PropTypes
.
string
,
children
:
PropTypes
.
array
,
})),
};
...
...
src/data/modules.js
浏览文件 @
76451936
import
{
flatMap
}
from
'lodash'
;
import
{
fetchMenus
,
fetchModuleInfos
,
fetchModuleLayout
}
from
'../services/modules'
;
const
data
=
{
init
:
false
,
modules
:
[],
flags
:
{
menus
:
false
,
infos
:
false
,
layout
:
false
,
},
menus
:
[],
infos
:
[],
layout
:
[],
};
export
default
data
;
export
const
setModules
=
(
modules
)
=>
{
data
.
init
=
true
;
data
.
modules
=
modules
;
// export const setMenus = (menus) => {
// data.init = true;
// data.menus = menus;
// };
const
combineMenu
=
(
menu1
,
menu2
)
=>
{
return
{
...
menu2
,
children
:
combineMenus
(
menu1
.
children
,
menu2
.
children
),
};
};
export
const
getModules
=
()
=>
{
return
data
.
modules
;
const
combineMenus
=
(
menus1
,
menus2
)
=>
{
const
menus
=
[...
menus1
];
for
(
const
menu
of
menus2
)
{
let
find
=
false
;
for
(
const
i
in
menus
)
{
if
(
menus
[
i
].
name
===
menu
.
name
)
{
menus
[
i
]
=
combineMenu
(
menus
[
i
],
menu
);
find
=
true
;
break
;
}
}
if
(
!
find
)
{
menus
.
push
(
menu
);
}
}
return
menus
;
};
export
const
isInited
=
()
=>
{
return
data
.
init
;
export
const
getMenus
=
async
()
=>
{
if
(
!
data
.
flags
.
menus
)
{
const
context
=
require
.
context
(
'../register/modules'
,
true
,
/^.*
\.(
js|jsx|json
)
/
);
const
staticMenus
=
flatMap
(
context
.
keys
(),
context
);
const
dynamicMenus
=
await
fetchMenus
();
data
.
menus
=
combineMenus
(
staticMenus
,
dynamicMenus
);
data
.
flags
.
menus
=
true
;
}
return
data
.
menus
;
};
// noinspection EqualityComparisonWithCoercionJS
export
const
getModule
=
id
=>
data
.
modules
.
filter
(
m
=>
m
.
id
==
id
).
pop
();
// eslint-disable-line eqeqeq, max-len
export
const
invalidateMenus
=
()
=>
{
data
.
flags
.
menus
=
false
;
};
export
const
getPath
=
(
id
)
=>
{
const
module
=
getModule
(
id
);
if
(
module
.
parent
)
{
const
parent
=
getModule
(
module
.
parent
);
return
[...
getPath
(
parent
.
id
),
id
];
}
else
{
return
[
id
];
export
const
getModuleInfos
=
async
()
=>
{
if
(
!
data
.
flags
.
infos
)
{
data
.
infos
=
await
fetchModuleInfos
();
data
.
flags
.
infos
=
true
;
}
return
data
.
infos
;
};
export
const
getChildren
=
(
id
)
=>
{
const
children
=
[];
for
(
const
module
of
data
.
modules
)
{
// noinspection EqualityComparisonWithCoercionJS
if
(
module
.
parent
==
id
)
{
// eslint-disable-line eqeqeq
children
.
push
(
module
);
}
}
return
children
;
export
const
getModuleInfo
=
async
(
name
)
=>
{
const
infos
=
await
getModuleInfos
();
return
(
infos
||
[]).
filter
(
info
=>
info
.
name
===
name
).
pop
();
};
export
function
foreachModule
(
callback
)
{
for
(
const
module
of
data
.
modules
)
{
callback
(
module
);
}
}
export
const
invalidateInfos
=
()
=>
{
data
.
flags
.
infos
=
false
;
};
export
const
setModuleConfigure
=
(
id
,
configur
e
)
=>
{
const
module
=
getModule
(
id
);
if
(
module
)
{
module
.
configure
=
configur
e
;
export
const
getModuleLayout
=
async
(
nam
e
)
=>
{
if
(
!
data
.
flags
.
layout
)
{
data
.
layout
=
await
fetchModuleLayout
(
name
);
data
.
flags
.
layout
=
tru
e
;
}
return
data
.
layout
;
};
export
const
getModuleConfigure
=
(
id
)
=>
{
const
module
=
getModule
(
id
);
return
module
?
module
.
configure
:
null
;
export
const
invalidateLayout
=
()
=>
{
data
.
flags
.
layout
=
false
;
};
// export const setModules = (modules) => {
// data.init = true;
// data.modules = modules;
// };
//
// export const getModules = () => {
// return data.modules;
// };
//
// export const isInited = () => {
// return data.init;
// };
//
// // noinspection EqualityComparisonWithCoercionJS
// export const getModule = id => data.modules.filter(m => m.id == id).pop(); // eslint-disable-line eqeqeq, max-len
//
// export const getPath = (id) => {
// const module = getModule(id);
// if (module.parent) {
// const parent = getModule(module.parent);
// return [...getPath(parent.id), id];
// } else {
// return [id];
// }
// };
//
// export const getChildren = (id) => {
// const children = [];
// for (const module of data.modules) {
// // noinspection EqualityComparisonWithCoercionJS
// if (module.parent == id) { // eslint-disable-line eqeqeq
// children.push(module);
// }
// }
// return children;
// };
//
// export function foreachModule(callback) {
// for (const module of data.modules) {
// callback(module);
// }
// }
//
// export const setModuleConfigure = (id, configure) => {
// const module = getModule(id);
// if (module) {
// module.configure = configure;
// }
// };
//
// export const getModuleConfigure = (id) => {
// const module = getModule(id);
// return module ? module.configure : null;
// };
src/models/main/index.js
浏览文件 @
76451936
import
{
routerRedux
}
from
'dva/router'
;
import
{
logout
,
fetchModuleInfos
}
from
'../../services/main'
;
import
{
logout
}
from
'../../services/main'
;
import
{
fetchDomains
,
switchDomain
,
currentDomain
}
from
'../../services/domain'
;
import
{
cookie
}
from
'../../utils/config'
;
import
{
setModules
,
getModules
,
getModule
,
getPath
,
foreachModule
,
isInited
}
from
'../../data/modules'
;
import
{
getMenus
}
from
'../../data/modules'
;
import
{
setCookie
,
delCookie
,
fullPath
,
getCookie
}
from
'../../utils/helper'
;
const
createMenus
=
()
=>
{
const
menus
=
[];
const
makePath
=
(
_menus
,
path
)
=>
{
if
(
path
.
length
===
0
)
{
return
null
;
}
const
[
cur
,
...
rest
]
=
path
;
const
find
=
_menus
.
filter
(
menu
=>
menu
.
name
===
`
${
cur
}
`
).
pop
();
if
(
find
)
{
if
(
rest
.
length
===
0
)
{
return
find
;
}
else
{
return
makePath
(
find
.
children
,
rest
);
}
}
else
{
let
container
=
_menus
;
for
(
const
id
of
path
)
{
const
m
=
getModule
(
id
);
const
menu
=
{
name
:
`
${
m
.
id
}
`
,
text
:
m
.
name
,
children
:
[],
};
container
.
push
(
menu
);
container
=
menu
.
children
;
}
}
};
const
makeIcon
=
(
menu
)
=>
{
const
children
=
menu
.
children
;
if
(
children
.
length
===
0
)
{
menu
.
icon
=
'file'
;
// eslint-disable-line no-param-reassign
}
else
{
menu
.
icon
=
'folder'
;
// eslint-disable-line no-param-reassign
for
(
const
child
of
children
)
{
makeIcon
(
child
);
}
}
const
createMenu
=
(
configure
)
=>
{
return
{
name
:
configure
.
name
,
icon
:
configure
.
icon
,
text
:
configure
.
showName
,
children
:
[
...(
configure
.
children
||
[]).
map
(
child
=>
createMenu
(
child
)),
...(
configure
.
modules
||
[]).
map
(
module
=>
({
name
:
module
.
name
,
icon
:
module
.
icon
,
text
:
module
.
showName
,
})),
],
};
foreachModule
((
module
)
=>
{
const
path
=
getPath
(
module
.
id
);
makePath
(
menus
,
path
);
});
for
(
const
menu
of
menus
)
{
makeIcon
(
menu
);
}
return
menus
;
};
const
createMenus
=
(
menusConfigure
)
=>
{
return
(
menusConfigure
||
[]).
map
(
configure
=>
createMenu
(
configure
));
};
// const createMenus = () => {
// const menus = [];
// const makePath = (_menus, path) => {
// if (path.length === 0) {
// return null;
// }
// const [cur, ...rest] = path;
// const find = _menus.filter(menu => menu.name === `${cur}`).pop();
// if (find) {
// if (rest.length === 0) {
// return find;
// } else {
// return makePath(find.children, rest);
// }
// } else {
// let container = _menus;
// for (const id of path) {
// const m = getModule(id);
// const menu = {
// name: `${m.id}`,
// text: m.name,
// children: [],
// };
// container.push(menu);
// container = menu.children;
// }
// }
// };
// const makeIcon = (menu) => {
// const children = menu.children;
// if (children.length === 0) {
// menu.icon = 'file'; // eslint-disable-line no-param-reassign
// } else {
// menu.icon = 'folder'; // eslint-disable-line no-param-reassign
// for (const child of children) {
// makeIcon(child);
// }
// }
// };
// foreachModule((module) => {
// const path = getPath(module.id);
// makePath(menus, path);
// });
// for (const menu of menus) {
// makeIcon(menu);
// }
// return menus;
// };
export
default
{
namespace
:
'main'
,
...
...
@@ -101,11 +121,8 @@ export default {
yield
put
({
type
:
'queryUserSuccess'
,
payload
:
user
});
},
*
fetchModules
(
action
,
{
put
,
call
})
{
if
(
!
isInited
())
{
const
modules
=
yield
call
(
fetchModuleInfos
);
setModules
(
modules
);
}
yield
put
({
type
:
'queryMenusSuccess'
,
payload
:
createMenus
(
getModules
())
});
const
configures
=
yield
call
(
getMenus
);
yield
put
({
type
:
'queryMenusSuccess'
,
payload
:
createMenus
(
configures
)
});
},
*
logout
(
action
,
{
put
,
call
})
{
yield
call
(
logout
);
...
...
src/register/modules/test.js
0 → 100644
浏览文件 @
76451936
export
default
[
{
name
:
'group0'
,
showName
:
'测试组0'
,
children
:
[
{
name
:
'group00'
,
showName
:
'测试组00'
,
modules
:
[{
name
:
'test0'
,
showName
:
'测试模块0'
,
layout
:
{
route
:
'task'
,
},
}],
},
],
},
{
name
:
'group1'
,
showName
:
'测试组1'
,
modules
:
[
{
name
:
'test1'
,
showName
:
'测试模块1'
,
layout
:
{
route
:
'task'
,
},
},
{
name
:
'test2'
,
showName
:
'测试模块2'
,
layout
:
{
route
:
'task'
,
},
},
],
},
];
src/router.js
浏览文件 @
76451936
import
React
from
'react'
;
import
PropTypes
from
'prop-types'
;
import
{
Router
}
from
'dva/router'
;
import
_
from
'lodash'
;
import
config
from
'./utils/config'
;
import
{
isAuthed
,
hasDomain
}
from
'./utils/auth'
;
import
{
fullPath
,
makePromise0
}
from
'./utils/helper'
;
import
{
fetchModuleInfos
}
from
'./services/main'
;
import
App
from
'./routes/app'
;
import
{
isInited
,
setModules
,
foreachModule
,
getChildren
}
from
'./data/modules'
;
import
{
getMenus
,
getModuleInfo
,
getModuleLayout
}
from
'./data/modules'
;
import
Monk
from
'./routes/main/monk'
;
const
{
contextPath
}
=
config
;
...
...
@@ -35,66 +35,66 @@ const authenticated = (nextState, replace) => {
maybeSwitch
(
nextState
,
replace
);
};
const
createRoute
=
async
(
app
,
module
)
=>
{
const
route
=
{
path
:
`
${
module
.
id
}
`
,
name
:
module
.
name
,
};
if
(
!
module
.
group
)
{
if
(
module
.
route
)
{
const
modelBundle
=
await
makePromise0
(
require
(
'bundle!./models/main/modules/'
+
module
.
route
+
'/index.js'
));
// eslint-disable-line import/no-dynamic-require, prefer-template, global-require
registerModel
(
app
,
modelBundle
);
const
routeBundle
=
await
makePromise0
(
require
(
'bundle!./routes/main/modules/'
+
module
.
route
+
'/index.js'
));
// eslint-disable-line import/no-dynamic-require, prefer-template, global-require
route
.
component
=
routeBundle
;
if
(
routeBundle
.
route
)
{
for
(
const
key
in
routeBundle
.
route
)
{
if
({}.
hasOwnProperty
.
call
(
routeBundle
.
route
,
key
))
{
route
[
key
]
=
routeBundle
.
route
[
key
];
}
}
}
}
else
{
route
.
component
=
Monk
;
}
}
else
{
route
.
component
=
Monk
;
route
.
getChildRoutes
=
(
nextState
,
cb
)
=>
{
createModuleRoutes
(
app
,
getChildren
(
module
.
id
))
const
createRoute
=
async
(
app
,
{
name
,
showName
,
modules
,
children
})
=>
{
// noinspection JSUnusedLocalSymbols
return
{
path
:
name
,
name
:
showName
,
component
:
Monk
,
getChildRoutes
(
nextState
,
cb
)
{
createRoutes
(
app
,
modules
,
children
)
.
then
((
result
)
=>
{
cb
(
null
,
result
);
})
.
catch
((
err
)
=>
{
cb
(
err
,
null
);
});
};
}
return
route
;
},
};
};
const
fetchModules
=
async
()
=>
{
if
(
!
isInited
())
{
setModules
(
await
fetchModuleInfos
());
}
const
modules
=
[];
foreachModule
((
module
)
=>
{
if
(
!
module
.
parent
)
{
modules
.
push
(
module
);
}
});
return
modules
;
};
const
create
ModuleRoutes
=
async
(
app
,
module
s
)
=>
{
const
create
Routes
=
async
(
app
,
modules
,
group
s
)
=>
{
const
routes
=
[];
for
(
const
module
of
modules
)
{
routes
.
push
(
await
createRoute
(
app
,
module
));
if
(
modules
)
{
for
(
const
module
of
modules
)
{
let
info
;
let
layout
;
if
(
_
.
isString
(
module
))
{
info
=
await
getModuleInfo
(
module
);
layout
=
await
getModuleLayout
(
module
);
}
else
{
info
=
module
;
layout
=
module
.
layout
;
}
const
{
name
,
showName
}
=
info
;
const
route
=
{
path
:
name
,
name
:
showName
,
};
if
(
layout
.
route
)
{
const
modelBundle
=
await
makePromise0
(
require
(
'bundle!./models/main/modules/'
+
layout
.
route
+
'/index.js'
));
// eslint-disable-line import/no-dynamic-require, prefer-template, global-require
registerModel
(
app
,
modelBundle
);
const
routeBundle
=
await
makePromise0
(
require
(
'bundle!./routes/main/modules/'
+
layout
.
route
+
'/index.js'
));
// eslint-disable-line import/no-dynamic-require, prefer-template, global-require
route
.
component
=
routeBundle
;
if
(
routeBundle
.
route
)
{
for
(
const
key
in
routeBundle
.
route
)
{
if
({}.
hasOwnProperty
.
call
(
routeBundle
.
route
,
key
))
{
route
[
key
]
=
routeBundle
.
route
[
key
];
}
}
}
}
else
{
route
.
component
=
Monk
;
}
routes
.
push
(
route
);
}
}
if
(
groups
)
{
for
(
const
group
of
groups
)
{
routes
.
push
(
await
createRoute
(
app
,
group
));
}
}
routes
.
push
({
path
:
'*'
,
onEnter
(
nextState
,
replace
)
{
replace
(
fullPath
(
'/main'
));
},
});
return
routes
;
};
...
...
@@ -136,15 +136,9 @@ function RouterConfig({ history, app }) {
},
'main'
);
},
getChildRoutes
:
(
nextState
,
cb
)
=>
{
fetchModules
()
.
then
(()
=>
{
const
lvl0
=
[];
foreachModule
((
module
)
=>
{
if
(
!
module
.
parent
)
{
lvl0
.
push
(
module
);
}
});
createModuleRoutes
(
app
,
lvl0
)
getMenus
()
.
then
((
menus
)
=>
{
createRoutes
(
app
,
[],
menus
)
.
then
((
result
)
=>
{
cb
(
null
,
result
);
})
...
...
@@ -155,6 +149,25 @@ function RouterConfig({ history, app }) {
.
catch
((
err
)
=>
{
cb
(
err
,
null
);
});
// fetchModules()
// .then(() => {
// const lvl0 = [];
// foreachModule((module) => {
// if (!module.parent) {
// lvl0.push(module);
// }
// });
// createModuleRoutes(app, lvl0)
// .then((result) => {
// cb(null, result);
// })
// .catch((err) => {
// cb(err, null);
// });
// })
// .catch((err) => {
// cb(err, null);
// });
},
},
],
...
...
src/services/datasource.js
浏览文件 @
76451936
...
...
@@ -75,27 +75,27 @@ export async function getGlobalDatasourceMeta(name) {
}
export
async
function
calcModuleDatasource
(
mdName
,
dsName
,
{
pst
,
psz
,
filters
=
[],
sortBys
=
[],
sortTypes
=
[],
params
=
{}
})
{
return
request
(
`/api/module
s/module
/
${
mdName
}
/datasource/
${
dsName
}
`
,
makeQueryParams
({
pst
,
psz
,
filters
,
sortBys
,
sortTypes
,
params
}));
return
request
(
`/api/module
/user
/
${
mdName
}
/datasource/
${
dsName
}
`
,
makeQueryParams
({
pst
,
psz
,
filters
,
sortBys
,
sortTypes
,
params
}));
}
export
async
function
countModuleDatasource
(
mdName
,
dsName
,
{
filters
=
[],
params
=
{}
})
{
return
request
(
`/api/module
s/module
/
${
mdName
}
/datasource/
${
dsName
}
/count`
,
makeQueryParams
({
filters
,
params
}));
return
request
(
`/api/module
/user
/
${
mdName
}
/datasource/
${
dsName
}
/count`
,
makeQueryParams
({
filters
,
params
}));
}
export
async
function
updateModuleDatasource
(
mdName
,
dsName
,
key
,
params
=
{})
{
return
post
(
`/api/module
s/module
/
${
mdName
}
/datasource/
${
dsName
}
/update`
,
{
return
post
(
`/api/module
/user
/
${
mdName
}
/datasource/
${
dsName
}
/update`
,
{
key
,
params
,
});
}
export
async
function
createModuleDatasource
(
mdName
,
dsName
,
params
=
{})
{
return
post
(
`/api/module
s/module
/
${
mdName
}
/datasource/
${
dsName
}
/create`
,
{
return
post
(
`/api/module
/user
/
${
mdName
}
/datasource/
${
dsName
}
/create`
,
{
params
,
});
}
export
async
function
getModuleDatasourceMeta
(
mdName
,
dsName
)
{
return
request
(
`/api/module
s/module
/
${
mdName
}
/datasource/
${
dsName
}
/meta`
);
return
request
(
`/api/module
/user
/
${
mdName
}
/datasource/
${
dsName
}
/meta`
);
}
src/services/main.js
浏览文件 @
76451936
import
request
from
'../utils/request'
;
import
post
from
'../utils/post'
;
export
async
function
logout
()
{
return
post
(
'/api/auth/logout'
);
}
export
async
function
fetchModuleInfos
()
{
return
request
(
'/api/module/all/info'
);
}
src/services/modules.js
浏览文件 @
76451936
import
request
from
'../utils/request'
;
export
async
function
allModuleInfo
s
()
{
return
request
(
'/api/
modules/info
'
);
export
async
function
fetchMenu
s
()
{
return
request
(
'/api/
configure/user/menus
'
);
}
export
async
function
getModuleConfigure
(
name
)
{
return
request
(
`/api/modules/module/
${
name
}
/configure`
);
export
async
function
fetchModuleInfos
()
{
return
request
(
'/api/module/user/info'
);
}
export
async
function
fetchModuleLayout
(
name
)
{
return
request
(
`/api/module/user/
${
name
}
/layout`
);
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论