Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
app-manage-console
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
ReactNative
app-manage-console
Commits
aacf7a82
提交
aacf7a82
authored
9月 10, 2018
作者:
vipcxj
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
重写跳转api,提取getApp到data/app.js.
上级
2b5cba7e
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
32 行增加
和
52 行删除
+32
-52
app.js
src/data/app.js
+8
-0
index.js
src/index.js
+0
-9
login.js
src/models/login.js
+1
-1
router.js
src/router.js
+1
-1
route.js
src/services/route.js
+22
-41
没有找到文件。
src/data/app.js
浏览文件 @
aacf7a82
import
persistStore
from
'redux-persist/lib/persistStore'
;
import
{
histories
}
from
'../utils/auth'
;
const
data
=
{
...
...
@@ -15,3 +16,10 @@ export async function initApp(app) {
export
function
getApp
()
{
return
data
.
app
;
}
export
const
getStore
=
()
=>
{
return
data
.
app
.
_store
;
// eslint-disable-line no-underscore-dangle
};
// eslint-disable-next-line no-underscore-dangle
export
const
createPersistor
=
theApp
=>
persistStore
((
theApp
||
getApp
()).
_store
);
src/index.js
浏览文件 @
aacf7a82
...
...
@@ -3,7 +3,6 @@ import dva from 'dva';
import
createLoading
from
'dva-loading'
;
import
moment
from
'moment'
;
import
persistReducer
from
'redux-persist/lib/persistReducer'
;
import
persistStore
from
'redux-persist/lib/persistStore'
;
import
storage
from
'redux-persist/lib/storage'
;
import
{
getHistory
}
from
'./services/route'
;
import
{
initApp
}
from
'./data/app'
;
...
...
@@ -48,11 +47,3 @@ app.router(routerConfig);
// 5. Start
initApp
(
app
).
then
(
theApp
=>
theApp
.
start
(
'#root'
));
export
default
app
;
export
const
getStore
=
()
=>
{
return
app
.
_store
;
};
export
const
createPersistor
=
theApp
=>
persistStore
(
theApp
.
_store
);
src/models/login.js
浏览文件 @
aacf7a82
...
...
@@ -7,7 +7,7 @@ import { setToken, setUser, setDomain, histories } from '../utils/auth';
import
{
switchDomain
,
currentDomain
}
from
'../services/domain'
;
import
{
errors
}
from
'../utils/error'
;
import
config
from
'../utils/config'
;
import
{
getStore
}
from
'../
index
'
;
import
{
getStore
}
from
'../
data/app
'
;
const
successAuthed
=
async
(
tokenId
,
userName
,
remember
)
=>
{
await
histories
.
pushHistory
(
'userName'
,
null
,
remember
?
userName
:
''
);
...
...
src/router.js
浏览文件 @
aacf7a82
...
...
@@ -13,7 +13,7 @@ import App from './routes/app';
import
{
getMenus
,
getModuleInfo
,
getModuleLayout
}
from
'./data/modules'
;
import
{
bindModel
}
from
'./utils/model'
;
import
Monk
from
'./routes/main/monk'
;
import
{
createPersistor
}
from
'./
index
'
;
import
{
createPersistor
}
from
'./
data/app
'
;
import
styles
from
'./index.css'
;
...
...
src/services/route.js
浏览文件 @
aacf7a82
import
createBrowserHistory
from
'history/createBrowserHistory'
;
import
isString
from
'lodash/isString'
;
import
{
push
as
pushAction
,
replace
as
replaceAction
,
go
as
goAction
,
goBack
as
goBackAction
,
goForward
as
goForwardAction
,
}
from
'react-router-redux'
;
import
{
makePath
}
from
'../utils/helper'
;
import
{
getStore
}
from
'../data/app'
;
const
processPath
=
(
base
,
path
,
withContext
=
false
)
=>
{
if
(
isString
(
path
))
{
...
...
@@ -46,68 +54,41 @@ export const createHistory = (...args) => {
};
export
const
push
=
(
path
,
state
)
=>
{
return
history
.
push
(
processPath
(
getHistoryBase
(
history
),
path
,
false
),
state
);
return
getStore
().
dispatch
(
pushAction
(
processPath
(
getHistoryBase
(
history
),
path
,
false
),
state
)
);
};
export
const
replace
=
(
path
,
state
)
=>
{
return
history
.
replace
(
processPath
(
getHistoryBase
(
history
),
path
,
false
),
state
);
return
getStore
().
dispatch
(
replaceAction
(
processPath
(
getHistoryBase
(
history
),
path
,
false
),
state
)
);
};
export
const
go
=
(
n
)
=>
{
return
history
.
go
(
n
);
return
getStore
().
dispatch
(
goAction
(
n
)
);
};
export
const
goBack
=
()
=>
{
return
history
.
goBack
(
);
return
getStore
().
dispatch
(
goBackAction
()
);
};
export
const
goForward
=
()
=>
{
return
history
.
goForward
(
);
return
getStore
().
dispatch
(
goForwardAction
()
);
};
const
checkThis
=
(
theThis
)
=>
{
if
(
!
theThis
||
!
theThis
.
props
)
{
throw
new
Error
(
'The this is not a component.'
);
}
if
(
!
theThis
.
props
.
router
)
{
throw
new
Error
(
'please use withRouter.'
);
}
};
const
getThisBase
=
(
theThis
)
=>
{
if
(
theThis
.
props
.
location
)
{
return
theThis
.
props
.
location
.
pathname
;
}
else
if
(
typeof
window
!==
'undefined'
)
{
return
window
.
location
.
pathname
;
// eslint-disable-line no-undef
}
else
{
throw
new
Error
(
'can not find base path!'
);
}
};
export
const
thisPush
=
(
theThis
,
pathOrLoc
)
=>
{
checkThis
(
theThis
);
const
route
=
processPath
(
getThisBase
(
theThis
),
pathOrLoc
);
return
theThis
.
props
.
router
.
push
(
route
);
export
const
thisPush
=
(
theThis
,
pathOrLoc
,
state
)
=>
{
return
push
(
pathOrLoc
,
state
);
};
export
const
thisReplace
=
(
theThis
,
pathOrLoc
)
=>
{
checkThis
(
theThis
);
const
route
=
processPath
(
getThisBase
(
theThis
),
pathOrLoc
);
return
theThis
.
props
.
router
.
replace
(
route
);
export
const
thisReplace
=
(
theThis
,
pathOrLoc
,
state
)
=>
{
return
replace
(
pathOrLoc
,
state
);
};
export
const
thisGo
=
(
theThis
,
n
)
=>
{
checkThis
(
theThis
);
return
theThis
.
props
.
router
.
go
(
n
);
return
go
(
n
);
};
export
const
thisGoBack
=
(
theThis
)
=>
{
checkThis
(
theThis
);
return
theThis
.
props
.
router
.
goBack
();
export
const
thisGoBack
=
()
=>
{
return
goBack
();
};
export
const
thisGoForward
=
(
theThis
)
=>
{
checkThis
(
theThis
);
return
theThis
.
props
.
router
.
goForward
();
export
const
thisGoForward
=
()
=>
{
return
goForward
();
};
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论