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 个修改的文件
包含
159 行增加
和
10 行删除
+159
-10
domain.js
src/models/domain.js
+5
-0
login.js
src/models/login.js
+5
-0
router.js
src/router.js
+66
-10
math.js
src/utils/math.js
+83
-0
没有找到文件。
src/models/domain.js
浏览文件 @
e362f6b8
...
@@ -2,6 +2,7 @@ import { routerRedux } from 'dva/router';
...
@@ -2,6 +2,7 @@ import { routerRedux } from 'dva/router';
import
{
fetchDomains
,
switchDomain
,
currentDomain
}
from
'../services/domain'
;
import
{
fetchDomains
,
switchDomain
,
currentDomain
}
from
'../services/domain'
;
import
{
fullPath
}
from
'../utils/helper'
;
import
{
fullPath
}
from
'../utils/helper'
;
import
{
getDomain
,
setDomain
}
from
'../utils/auth'
;
import
{
getDomain
,
setDomain
}
from
'../utils/auth'
;
import
config
from
'../utils/config'
;
export
default
{
export
default
{
...
@@ -30,7 +31,11 @@ export default {
...
@@ -30,7 +31,11 @@ export default {
const
{
path
,
name
}
=
yield
call
(
currentDomain
);
const
{
path
,
name
}
=
yield
call
(
currentDomain
);
yield
call
(
setDomain
,
name
,
path
);
yield
call
(
setDomain
,
name
,
path
);
yield
put
({
type
:
'queryInit'
,
payload
:
path
});
yield
put
({
type
:
'queryInit'
,
payload
:
path
});
if
(
config
.
fastNavigationPage
)
{
yield
put
(
routerRedux
.
push
(
fullPath
(
`/
${
config
.
fastNavigationPage
}
`
)));
}
else
{
yield
put
(
routerRedux
.
push
(
fullPath
(
'/main'
)));
yield
put
(
routerRedux
.
push
(
fullPath
(
'/main'
)));
}
},
},
},
},
...
...
src/models/login.js
浏览文件 @
e362f6b8
...
@@ -4,6 +4,7 @@ import { fullPath } from '../utils/helper';
...
@@ -4,6 +4,7 @@ import { fullPath } from '../utils/helper';
import
{
setToken
,
setUser
,
setDomain
,
histories
}
from
'../utils/auth'
;
import
{
setToken
,
setUser
,
setDomain
,
histories
}
from
'../utils/auth'
;
import
{
switchDomain
,
currentDomain
}
from
'../services/domain'
;
import
{
switchDomain
,
currentDomain
}
from
'../services/domain'
;
import
{
errors
}
from
'../utils/error'
;
import
{
errors
}
from
'../utils/error'
;
import
config
from
'../utils/config'
;
export
default
{
export
default
{
namespace
:
'login'
,
namespace
:
'login'
,
...
@@ -40,8 +41,12 @@ export default {
...
@@ -40,8 +41,12 @@ export default {
yield
call
(
switchDomain
,
path
);
yield
call
(
switchDomain
,
path
);
const
{
name
}
=
yield
call
(
currentDomain
);
const
{
name
}
=
yield
call
(
currentDomain
);
yield
call
(
setDomain
,
name
,
path
);
yield
call
(
setDomain
,
name
,
path
);
if
(
config
.
fastNavigationPage
)
{
yield
put
(
routerRedux
.
push
(
fullPath
(
`/
${
config
.
fastNavigationPage
}
`
)));
}
else
{
yield
put
(
routerRedux
.
push
(
fullPath
(
'/main'
)));
yield
put
(
routerRedux
.
push
(
fullPath
(
'/main'
)));
}
}
}
},
},
},
},
subscriptions
:
{},
subscriptions
:
{},
...
...
src/router.js
浏览文件 @
e362f6b8
...
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
...
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import
{
Router
}
from
'dva/router'
;
import
{
Router
}
from
'dva/router'
;
import
_
from
'lodash'
;
import
_
from
'lodash'
;
import
config
from
'./utils/config'
;
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
{
fullPath
,
makePromise0
}
from
'./utils/helper'
;
import
{
processError
}
from
'./utils/error'
;
import
{
processError
}
from
'./utils/error'
;
import
App
from
'./routes/app'
;
import
App
from
'./routes/app'
;
...
@@ -36,14 +36,28 @@ const authenticated = async (replace) => {
...
@@ -36,14 +36,28 @@ const authenticated = async (replace) => {
await
maybeSwitch
(
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
// noinspection JSUnusedLocalSymbols
return
{
return
{
path
:
name
,
path
:
name
,
fullPath
:
theFullPath
,
name
:
showName
,
name
:
showName
,
component
:
Monk
,
component
:
Monk
,
getChildRoutes
(
nextState
,
cb
)
{
getChildRoutes
(
nextState
,
cb
)
{
createRoutes
(
app
,
modules
,
children
)
createRoutes
(
app
,
modules
,
children
,
theFullPath
)
.
then
((
result
)
=>
{
.
then
((
result
)
=>
{
cb
(
null
,
result
);
cb
(
null
,
result
);
})
})
...
@@ -55,7 +69,7 @@ const createRoute = async (app, { name, showName, modules, children }) => {
...
@@ -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
=
[];
const
routes
=
[];
if
(
modules
)
{
if
(
modules
)
{
for
(
const
module
of
modules
)
{
for
(
const
module
of
modules
)
{
...
@@ -68,9 +82,10 @@ const createRoutes = async (app, modules, groups) => {
...
@@ -68,9 +82,10 @@ const createRoutes = async (app, modules, groups) => {
info
=
module
;
info
=
module
;
layout
=
module
.
layout
;
layout
=
module
.
layout
;
}
}
const
{
name
,
showName
}
=
info
;
const
{
name
,
showName
,
icon
,
description
}
=
info
;
const
route
=
{
const
route
=
{
path
:
name
,
path
:
name
,
fullPath
:
combinePath
(
basePath
,
name
),
name
:
showName
,
name
:
showName
,
};
};
if
(
layout
.
route
)
{
if
(
layout
.
route
)
{
...
@@ -91,12 +106,39 @@ const createRoutes = async (app, modules, groups) => {
...
@@ -91,12 +106,39 @@ const createRoutes = async (app, modules, groups) => {
if
(
route
.
onEnter
)
{
if
(
route
.
onEnter
)
{
const
onEnter
=
route
.
onEnter
;
const
onEnter
=
route
.
onEnter
;
route
.
onEnter
=
(
nextState
,
replace
,
cb
)
=>
{
route
.
onEnter
=
(
nextState
,
replace
,
cb
)
=>
{
console
.
log
(
nextState
);
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
);
return
onEnter
(
nextState
,
replace
,
cb
);
}
};
};
}
else
{
}
else
{
route
.
onEnter
=
(
nextState
)
=>
{
route
.
onEnter
=
(
nextState
,
replace
,
cb
)
=>
{
console
.
log
(
nextState
);
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
);
routes
.
push
(
route
);
...
@@ -104,7 +146,7 @@ const createRoutes = async (app, modules, groups) => {
...
@@ -104,7 +146,7 @@ const createRoutes = async (app, modules, groups) => {
}
}
if
(
groups
)
{
if
(
groups
)
{
for
(
const
group
of
groups
)
{
for
(
const
group
of
groups
)
{
routes
.
push
(
await
createRoute
(
app
,
group
));
routes
.
push
(
await
createRoute
(
app
,
group
,
basePath
));
}
}
}
}
return
routes
;
return
routes
;
...
@@ -154,7 +196,7 @@ function RouterConfig({ history, app }) {
...
@@ -154,7 +196,7 @@ function RouterConfig({ history, app }) {
getChildRoutes
:
(
nextState
,
cb
)
=>
{
getChildRoutes
:
(
nextState
,
cb
)
=>
{
getMenus
()
getMenus
()
.
then
((
menus
)
=>
{
.
then
((
menus
)
=>
{
createRoutes
(
app
,
[],
menus
)
createRoutes
(
app
,
[],
menus
,
`
${
contextPath
}
/main`
)
.
then
((
result
)
=>
{
.
then
((
result
)
=>
{
cb
(
null
,
result
);
cb
(
null
,
result
);
})
})
...
@@ -170,6 +212,20 @@ function RouterConfig({ history, app }) {
...
@@ -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
(
return
(
<
Router
history
=
{
history
}
routes
=
{
routes
}
onError
=
{
processError
}
/
>
<
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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论