Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
app-manage-console
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
ReactNative
app-manage-console
Commits
e362f6b8
提交
e362f6b8
authored
11月 30, 2017
作者:
vipcxj
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
1.增加快速导航支持
上级
1ba9bbc8
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
162 行增加
和
13 行删除
+162
-13
domain.js
src/models/domain.js
+6
-1
login.js
src/models/login.js
+6
-1
router.js
src/router.js
+67
-11
math.js
src/utils/math.js
+83
-0
没有找到文件。
src/models/domain.js
浏览文件 @
e362f6b8
...
...
@@ -2,6 +2,7 @@ import { routerRedux } from 'dva/router';
import
{
fetchDomains
,
switchDomain
,
currentDomain
}
from
'../services/domain'
;
import
{
fullPath
}
from
'../utils/helper'
;
import
{
getDomain
,
setDomain
}
from
'../utils/auth'
;
import
config
from
'../utils/config'
;
export
default
{
...
...
@@ -30,7 +31,11 @@ export default {
const
{
path
,
name
}
=
yield
call
(
currentDomain
);
yield
call
(
setDomain
,
name
,
path
);
yield
put
({
type
:
'queryInit'
,
payload
:
path
});
yield
put
(
routerRedux
.
push
(
fullPath
(
'/main'
)));
if
(
config
.
fastNavigationPage
)
{
yield
put
(
routerRedux
.
push
(
fullPath
(
`/
${
config
.
fastNavigationPage
}
`
)));
}
else
{
yield
put
(
routerRedux
.
push
(
fullPath
(
'/main'
)));
}
},
},
...
...
src/models/login.js
浏览文件 @
e362f6b8
...
...
@@ -4,6 +4,7 @@ import { fullPath } from '../utils/helper';
import
{
setToken
,
setUser
,
setDomain
,
histories
}
from
'../utils/auth'
;
import
{
switchDomain
,
currentDomain
}
from
'../services/domain'
;
import
{
errors
}
from
'../utils/error'
;
import
config
from
'../utils/config'
;
export
default
{
namespace
:
'login'
,
...
...
@@ -40,7 +41,11 @@ export default {
yield
call
(
switchDomain
,
path
);
const
{
name
}
=
yield
call
(
currentDomain
);
yield
call
(
setDomain
,
name
,
path
);
yield
put
(
routerRedux
.
push
(
fullPath
(
'/main'
)));
if
(
config
.
fastNavigationPage
)
{
yield
put
(
routerRedux
.
push
(
fullPath
(
`/
${
config
.
fastNavigationPage
}
`
)));
}
else
{
yield
put
(
routerRedux
.
push
(
fullPath
(
'/main'
)));
}
}
},
},
...
...
src/router.js
浏览文件 @
e362f6b8
...
...
@@ -3,7 +3,7 @@ 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
{
isAuthed
,
hasDomain
,
histories
}
from
'./utils/auth'
;
import
{
fullPath
,
makePromise0
}
from
'./utils/helper'
;
import
{
processError
}
from
'./utils/error'
;
import
App
from
'./routes/app'
;
...
...
@@ -36,14 +36,28 @@ const authenticated = async (replace) => {
await
maybeSwitch
(
replace
);
};
const
createRoute
=
async
(
app
,
{
name
,
showName
,
modules
,
children
})
=>
{
const
combinePath
=
(
base
,
path
)
=>
{
if
(
!
base
)
{
return
path
;
}
if
(
base
[
base
.
length
-
1
]
===
'/'
)
{
return
`
${
base
}${
path
}
`
;
}
else
{
return
`
${
base
}
/
${
path
}
`
;
}
};
const
createRoute
=
async
(
app
,
group
,
basePath
)
=>
{
const
{
name
,
showName
,
modules
,
children
}
=
group
;
const
theFullPath
=
combinePath
(
basePath
,
name
);
// noinspection JSUnusedLocalSymbols
return
{
path
:
name
,
fullPath
:
theFullPath
,
name
:
showName
,
component
:
Monk
,
getChildRoutes
(
nextState
,
cb
)
{
createRoutes
(
app
,
modules
,
children
)
createRoutes
(
app
,
modules
,
children
,
theFullPath
)
.
then
((
result
)
=>
{
cb
(
null
,
result
);
})
...
...
@@ -55,7 +69,7 @@ const createRoute = async (app, { name, showName, modules, children }) => {
};
const
createRoutes
=
async
(
app
,
modules
,
groups
)
=>
{
const
createRoutes
=
async
(
app
,
modules
,
groups
,
basePath
)
=>
{
const
routes
=
[];
if
(
modules
)
{
for
(
const
module
of
modules
)
{
...
...
@@ -68,9 +82,10 @@ const createRoutes = async (app, modules, groups) => {
info
=
module
;
layout
=
module
.
layout
;
}
const
{
name
,
showName
}
=
info
;
const
{
name
,
showName
,
icon
,
description
}
=
info
;
const
route
=
{
path
:
name
,
fullPath
:
combinePath
(
basePath
,
name
),
name
:
showName
,
};
if
(
layout
.
route
)
{
...
...
@@ -91,12 +106,39 @@ const createRoutes = async (app, modules, groups) => {
if
(
route
.
onEnter
)
{
const
onEnter
=
route
.
onEnter
;
route
.
onEnter
=
(
nextState
,
replace
,
cb
)
=>
{
console
.
log
(
nextState
);
return
onEnter
(
nextState
,
replace
,
cb
);
if
(
nextState
&&
nextState
.
location
&&
nextState
.
location
.
pathname
===
route
.
fullPath
)
{
histories
.
pushHistory
(
'module'
,
{
name
,
showName
,
icon
,
description
,
path
:
route
.
fullPath
,
}).
then
(()
=>
new
Promise
((
resolve
,
reject
)
=>
{
onEnter
(
nextState
,
replace
,
(
err
,
res
)
=>
{
if
(
err
)
{
reject
(
err
);
}
else
{
resolve
(
res
);
}
});
})).
then
(()
=>
cb
()).
catch
(
err
=>
cb
(
err
));
}
else
{
return
onEnter
(
nextState
,
replace
,
cb
);
}
};
}
else
{
route
.
onEnter
=
(
nextState
)
=>
{
console
.
log
(
nextState
);
route
.
onEnter
=
(
nextState
,
replace
,
cb
)
=>
{
if
(
nextState
&&
nextState
.
location
&&
nextState
.
location
.
pathname
===
route
.
fullPath
)
{
histories
.
pushHistory
(
'module'
,
{
name
,
showName
,
icon
,
description
,
path
:
route
.
fullPath
,
}).
then
(()
=>
cb
()).
catch
(
err
=>
cb
(
err
));
}
else
{
cb
();
}
};
}
routes
.
push
(
route
);
...
...
@@ -104,7 +146,7 @@ const createRoutes = async (app, modules, groups) => {
}
if
(
groups
)
{
for
(
const
group
of
groups
)
{
routes
.
push
(
await
createRoute
(
app
,
group
));
routes
.
push
(
await
createRoute
(
app
,
group
,
basePath
));
}
}
return
routes
;
...
...
@@ -154,7 +196,7 @@ function RouterConfig({ history, app }) {
getChildRoutes
:
(
nextState
,
cb
)
=>
{
getMenus
()
.
then
((
menus
)
=>
{
createRoutes
(
app
,
[],
menus
)
createRoutes
(
app
,
[],
menus
,
`
${
contextPath
}
/main`
)
.
then
((
result
)
=>
{
cb
(
null
,
result
);
})
...
...
@@ -170,6 +212,20 @@ function RouterConfig({ history, app }) {
],
},
];
if
(
config
.
fastNavigationPage
)
{
routes
[
0
].
childRoutes
.
push
({
path
:
'fastNav'
,
onEnter
:
(
ignored
,
replace
,
cb
)
=>
{
authenticated
(
replace
).
then
(()
=>
cb
()).
catch
(
err
=>
cb
(
err
));
},
getComponent
(
ignored
,
cb
)
{
require
.
ensure
([],
(
require
)
=>
{
registerModel
(
app
,
require
(
'./models/main/modules/'
+
config
.
fastNavigationPage
));
// eslint-disable-line import/no-dynamic-require, prefer-template
cb
(
null
,
require
(
'./routes/main/modules/'
+
config
.
fastNavigationPage
));
// eslint-disable-line import/no-dynamic-require, prefer-template
},
'fastNav'
);
},
});
}
return
(
<
Router
history
=
{
history
}
routes
=
{
routes
}
onError
=
{
processError
}
/
>
);
...
...
src/utils/math.js
0 → 100644
浏览文件 @
e362f6b8
import
_
from
'lodash'
;
const
{
isString
,
get
,
sortBy
}
=
_
;
/**
* @callback KeyExtractor
* @param value
* @return key
*/
/**
* 获取用于对比的key
* @param value
* @param {string|KeyExtractor} [keyMethod]
* @return {*}
*/
const
getKey
=
(
value
,
keyMethod
)
=>
{
if
(
!
keyMethod
)
{
return
value
;
}
else
if
(
isString
(
keyMethod
))
{
return
get
(
value
,
keyMethod
);
}
else
{
return
keyMethod
(
value
);
}
};
/**
* 在数组中查找某个对象,并返回
* @param {Array} array
* @param toFind 查找目标
* @param {string|KeyExtractor} [key] 用于判断2个数据是否相同
* @return result 找到的对象
*/
const
findBy
=
(
array
,
toFind
,
key
)
=>
{
if
(
array
)
{
for
(
const
el
of
array
)
{
if
(
getKey
(
el
,
key
)
===
toFind
)
{
return
el
;
}
}
}
return
null
;
};
/**
* 计算频率数据
* @param {Array} array 数据
* @param {string|KeyExtractor} [key] 用于判断2个数据是否相同
* @param {string} [order=desc] 怎么排序,可选值为asc和desc
*/
export
const
toHistogram
=
(
array
,
key
,
order
=
'desc'
)
=>
{
if
(
!
array
||
array
.
length
===
0
)
{
return
[];
}
const
res
=
[];
let
newKey
;
if
(
!
key
)
{
newKey
=
'data'
;
}
else
if
(
isString
(
key
))
{
newKey
=
`data.
${
key
}
`
;
}
else
{
newKey
=
value
=>
key
(
value
.
data
);
}
for
(
const
el
of
array
)
{
const
find
=
findBy
(
res
,
getKey
(
el
,
key
),
newKey
);
if
(
find
)
{
++
find
.
num
;
}
else
{
res
.
push
({
data
:
el
,
num
:
1
,
});
}
}
switch
(
order
)
{
case
'asc'
:
return
_
(
res
).
sortBy
(
v
=>
v
.
num
).
reverse
().
value
();
case
'desc'
:
return
sortBy
(
res
,
v
=>
v
.
num
);
default
:
throw
new
Error
(
`unsupported order:
${
order
}
`
);
}
};
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论