Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
app-manage-console
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
ReactNative
app-manage-console
Commits
79118904
提交
79118904
authored
3月 29, 2018
作者:
vipcxj
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修复生产环境下路由各种问题
上级
87c8123a
隐藏空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
118 行增加
和
60 行删除
+118
-60
.webpackrc.js
.webpackrc.js
+5
-7
config.js
config.js
+44
-0
index.js
src/index.js
+4
-1
domain.js
src/models/domain.js
+2
-3
login.js
src/models/login.js
+5
-5
index.js
src/models/main/index.js
+3
-4
router.js
src/router.js
+6
-9
route.js
src/services/route.js
+17
-10
config.js
src/utils/config.js
+11
-7
helper.js
src/utils/helper.js
+21
-14
没有找到文件。
.webpackrc.js
浏览文件 @
79118904
const
config
=
require
(
'./config'
);
const
proxy
=
{
target
:
"http://192.168.1.22:8080"
,
changeOrigin
:
true
,
...
...
@@ -33,7 +35,7 @@ module.exports = {
hash
:
true
,
env
:
{
development
:
{
publicPath
:
"/"
,
publicPath
:
config
.
dev
.
publicPath
,
extraBabelPlugins
:
[
"dva-hmr"
,
"lodash"
,
...
...
@@ -46,16 +48,12 @@ module.exports = {
}
},
production
:
{
publicPath
:
"/bm/"
,
define
:
{
contextPath
:
"/bm"
,
apiContextPath
:
"/bm"
},
publicPath
:
config
.
prod
.
publicPath
,
extraBabelPlugins
:
[
"lodash"
,
[
"import"
,
{
"libraryName"
:
"antd"
,
"style"
:
true
}]
],
devtool
:
"hidden-source-map"
//
devtool: "hidden-source-map"
}
}
};
config.js
0 → 100644
浏览文件 @
79118904
const
makeSureEndsWithSlash
=
(
path
)
=>
{
if
(
!
path
||
!
path
.
endsWith
(
'/'
))
{
return
`
${
path
||
''
}
/`
;
}
else
{
return
path
;
}
};
const
makeSureStartsWithSlash
=
(
path
)
=>
{
if
(
!
path
||
!
path
.
startsWith
(
'/'
))
{
return
`/
${
path
||
''
}
`
;
}
else
{
return
path
;
}
};
const
tripEndSlash
=
(
path
)
=>
{
if
(
path
&&
path
.
endsWith
(
'/'
))
{
return
path
.
slice
(
0
,
path
.
length
-
1
);
}
else
{
return
path
;
}
};
const
contextPathDev
=
''
;
const
contextPathProd
=
'bm/console'
;
const
apiContextPathDev
=
''
;
const
apiContextPathProd
=
'bm'
;
module
.
exports
=
{
dev
:
{
publicPath
:
makeSureEndsWithSlash
(
makeSureStartsWithSlash
(
contextPathDev
)),
basename
:
tripEndSlash
(
makeSureStartsWithSlash
(
contextPathDev
)),
contextPath
:
tripEndSlash
(
makeSureStartsWithSlash
(
contextPathDev
)),
apiContextPath
:
tripEndSlash
(
makeSureStartsWithSlash
(
apiContextPathDev
)),
},
prod
:
{
publicPath
:
makeSureEndsWithSlash
(
makeSureStartsWithSlash
(
contextPathProd
)),
basename
:
tripEndSlash
(
makeSureStartsWithSlash
(
contextPathProd
)),
contextPath
:
tripEndSlash
(
makeSureStartsWithSlash
(
contextPathProd
)),
apiContextPath
:
tripEndSlash
(
makeSureStartsWithSlash
(
apiContextPathProd
)),
},
};
src/index.js
浏览文件 @
79118904
...
...
@@ -6,13 +6,16 @@ import { initApp } from './data/app';
import
appModel
from
'./models/app'
;
import
routerConfig
from
'./router'
;
import
{
processError
}
from
'./utils/error'
;
import
config
from
'./utils/config'
;
import
'./index.css'
;
moment
.
locale
(
'zh-cn'
);
// 1. Initialize
const
app
=
dva
({
history
:
getHistory
(),
history
:
getHistory
({
basename
:
config
.
basename
,
}),
onError
(
error
)
{
// eslint-disable-next-line no-console
processError
(
error
);
...
...
src/models/domain.js
浏览文件 @
79118904
import
{
routerRedux
}
from
'dva/router'
;
import
{
fetchDomains
,
switchDomain
,
currentDomain
}
from
'../services/domain'
;
import
{
fullPath
}
from
'../utils/helper'
;
import
{
getDomain
,
histories
,
setDomain
}
from
'../utils/auth'
;
import
config
from
'../utils/config'
;
...
...
@@ -33,9 +32,9 @@ export default {
yield
put
({
type
:
'queryInit'
,
payload
:
path
});
const
latest
=
yield
call
(
histories
.
getLatest
,
'module'
);
if
(
latest
&&
config
.
fastNavigationPage
)
{
yield
put
(
routerRedux
.
push
(
fullPath
(
'/fastNav'
)
));
yield
put
(
routerRedux
.
push
(
'/fastNav'
));
}
else
{
yield
put
(
routerRedux
.
push
(
fullPath
(
'/main'
)
));
yield
put
(
routerRedux
.
push
(
'/main'
));
}
},
},
...
...
src/models/login.js
浏览文件 @
79118904
...
...
@@ -2,7 +2,7 @@ import { routerRedux } from 'dva/router';
import
{
authorize
,
login
,
userInfo
}
from
'../services/login'
;
import
{
validate
as
passValidate
}
from
'../services/login/password'
;
import
{
requestCode
,
validate
as
ucaValidate
}
from
'../services/login/uca'
;
import
{
fullPath
,
encrypt
}
from
'../utils/helper'
;
import
{
encrypt
}
from
'../utils/helper'
;
import
{
setToken
,
setUser
,
setDomain
,
histories
}
from
'../utils/auth'
;
import
{
switchDomain
,
currentDomain
}
from
'../services/domain'
;
import
{
errors
}
from
'../utils/error'
;
...
...
@@ -16,7 +16,7 @@ const successAuthed = async (tokenId, userName, remember) => {
await
setUser
(
uInfo
.
id
,
uInfo
.
name
);
const
path
=
await
histories
.
getLatest
(
'domain'
);
if
(
!
path
)
{
getStore
().
dispatch
(
routerRedux
.
push
(
fullPath
(
'/domain'
)
));
getStore
().
dispatch
(
routerRedux
.
push
(
'/domain'
));
}
else
{
await
switchDomain
(
path
);
const
domain
=
await
currentDomain
();
...
...
@@ -24,12 +24,12 @@ const successAuthed = async (tokenId, userName, remember) => {
await
setDomain
(
domain
.
name
,
path
);
const
latest
=
await
histories
.
getLatest
(
'module'
);
if
(
latest
&&
config
.
fastNavigationPage
)
{
getStore
().
dispatch
(
routerRedux
.
push
(
fullPath
(
'/fastNav'
)
));
getStore
().
dispatch
(
routerRedux
.
push
(
'/fastNav'
));
}
else
{
getStore
().
dispatch
(
routerRedux
.
push
(
fullPath
(
'/main'
)
));
getStore
().
dispatch
(
routerRedux
.
push
(
'/main'
));
}
}
else
{
getStore
().
dispatch
(
routerRedux
.
push
(
fullPath
(
'/domain'
)
));
getStore
().
dispatch
(
routerRedux
.
push
(
'/domain'
));
}
}
};
...
...
src/models/main/index.js
浏览文件 @
79118904
...
...
@@ -3,7 +3,6 @@ import isString from 'lodash/isString';
import
{
logout
}
from
'../../services/main'
;
import
{
fetchDomains
,
switchDomain
,
currentDomain
}
from
'../../services/domain'
;
import
{
getMenus
,
getModuleInfo
}
from
'../../data/modules'
;
import
{
fullPath
}
from
'../../utils/helper'
;
import
{
delToken
,
getDomain
,
setDomain
,
delDomain
,
getUser
,
delUser
}
from
'../../utils/auth'
;
const
createMenu
=
async
(
configure
)
=>
{
...
...
@@ -107,12 +106,12 @@ export default {
const
{
path
,
name
}
=
yield
call
(
currentDomain
);
yield
call
(
setDomain
,
name
,
path
);
yield
put
({
type
:
'switchDomainSuccess'
,
payload
:
name
});
yield
put
(
routerRedux
.
push
(
fullPath
(
'/main'
)
));
yield
put
(
routerRedux
.
push
(
'/main'
));
},
*
fetchUser
(
ignored
,
{
put
,
call
})
{
const
user
=
yield
call
(
getUser
);
if
(
!
user
)
{
yield
put
(
routerRedux
.
push
(
fullPath
(
'/login'
)
));
yield
put
(
routerRedux
.
push
(
'/login'
));
}
yield
put
({
type
:
'queryUserSuccess'
,
payload
:
user
.
name
});
},
...
...
@@ -126,7 +125,7 @@ export default {
yield
call
(
delToken
);
yield
call
(
delUser
);
yield
call
(
delDomain
);
yield
put
(
routerRedux
.
push
(
fullPath
(
'/login'
)
));
yield
put
(
routerRedux
.
push
(
'/login'
));
},
},
...
...
src/router.js
浏览文件 @
79118904
...
...
@@ -5,14 +5,11 @@ import isString from 'lodash/isString';
import
get
from
'lodash/get'
;
import
config
from
'./utils/config'
;
import
{
isAuthed
,
hasDomain
,
histories
}
from
'./utils/auth'
;
import
{
fullPath
}
from
'./utils/helper'
;
import
{
processError
}
from
'./utils/error'
;
import
App
from
'./routes/app'
;
import
{
getMenus
,
getModuleInfo
,
getModuleLayout
}
from
'./data/modules'
;
import
Monk
from
'./routes/main/monk'
;
const
{
contextPath
}
=
config
;
const
registerModel
=
(
app
,
model
)
=>
{
// eslint-disable-next-line no-underscore-dangle
if
(
!
(
app
.
_models
.
filter
(
m
=>
m
.
namespace
===
model
.
namespace
).
length
===
1
))
{
...
...
@@ -22,13 +19,13 @@ const registerModel = (app, model) => {
const
maybeLogin
=
async
(
replace
)
=>
{
if
(
!
(
await
isAuthed
()))
{
return
replace
(
fullPath
(
'/login'
)
);
return
replace
(
'/login'
);
}
};
const
maybeSwitch
=
async
(
replace
)
=>
{
if
(
!
(
await
hasDomain
()))
{
return
replace
(
fullPath
(
'/domain'
)
);
return
replace
(
'/domain'
);
}
};
...
...
@@ -159,15 +156,15 @@ const createRoutes = async (app, modules, groups, basePath) => {
function
RouterConfig
({
history
,
app
})
{
const
routes
=
[
{
path
:
`
${
contextPath
}
/`
,
path
:
'/'
,
component
:
App
,
indexRoute
:
{
onEnter
:
(
nextState
,
replace
,
cb
)
=>
{
histories
.
getLatest
(
'module'
).
then
((
latest
)
=>
{
if
(
latest
&&
config
.
fastNavigationPage
)
{
replace
(
`
${
contextPath
}
/fastNav`
);
replace
(
'/fastNav'
);
}
else
{
replace
(
`
${
contextPath
}
/main`
);
replace
(
'/main'
);
}
cb
();
}).
catch
((
err
)
=>
{
...
...
@@ -220,7 +217,7 @@ function RouterConfig({ history, app }) {
getChildRoutes
:
(
nextState
,
cb
)
=>
{
getMenus
()
.
then
((
menus
)
=>
{
createRoutes
(
app
,
[],
menus
,
`
${
contextPath
}
/main`
)
createRoutes
(
app
,
[],
menus
,
'/main'
)
.
then
((
result
)
=>
{
cb
(
null
,
result
);
})
...
...
src/services/route.js
浏览文件 @
79118904
...
...
@@ -2,7 +2,7 @@ import createBrowserHistory from 'history/createBrowserHistory';
import
isString
from
'lodash/isString'
;
import
{
makePath
}
from
'../utils/helper'
;
const
processPath
=
(
base
,
path
,
withContext
=
tru
e
)
=>
{
const
processPath
=
(
base
,
path
,
withContext
=
fals
e
)
=>
{
if
(
isString
(
path
))
{
return
makePath
(
base
,
path
,
withContext
);
}
...
...
@@ -29,21 +29,28 @@ export const getHistory = (...args) => {
export
const
getLocation
=
()
=>
{
return
location
||
{};
};
export
const
destroyHistory
=
()
=>
{
if
(
history
&&
history
.
unlisten
)
{
history
.
unlisten
();
history
=
null
;
}
};
export
const
createHistory
=
(...
args
)
=>
{
destroyHistory
();
history
=
createBrowserHistory
(...
args
);
// noinspection JSUnresolvedFunction
history
.
listen
((
loc
)
=>
{
history
.
unlisten
=
history
.
listen
((
loc
)
=>
{
location
=
{
...
loc
};
});
return
history
;
};
export
const
push
=
(
path
,
state
,
withContext
=
true
)
=>
{
return
history
.
push
(
processPath
(
getHistoryBase
(
history
),
path
,
withContext
),
state
);
export
const
push
=
(
path
,
state
)
=>
{
return
history
.
push
(
processPath
(
getHistoryBase
(
history
),
path
,
false
),
state
);
};
export
const
replace
=
(
path
,
state
,
withContext
=
true
)
=>
{
return
history
.
replace
(
processPath
(
getHistoryBase
(
history
),
path
,
withContext
),
state
);
export
const
replace
=
(
path
,
state
)
=>
{
return
history
.
replace
(
processPath
(
getHistoryBase
(
history
),
path
,
false
),
state
);
};
export
const
go
=
(
n
)
=>
{
...
...
@@ -78,15 +85,15 @@ const getThisBase = (theThis) => {
}
};
export
const
thisPush
=
(
theThis
,
pathOrLoc
,
withContext
=
true
)
=>
{
export
const
thisPush
=
(
theThis
,
pathOrLoc
)
=>
{
checkThis
(
theThis
);
const
route
=
processPath
(
getThisBase
(
theThis
),
pathOrLoc
,
withContext
);
const
route
=
processPath
(
getThisBase
(
theThis
),
pathOrLoc
);
return
theThis
.
props
.
router
.
push
(
route
);
};
export
const
thisReplace
=
(
theThis
,
pathOrLoc
,
withContext
=
true
)
=>
{
export
const
thisReplace
=
(
theThis
,
pathOrLoc
)
=>
{
checkThis
(
theThis
);
const
route
=
processPath
(
getThisBase
(
theThis
),
pathOrLoc
,
withContext
);
const
route
=
processPath
(
getThisBase
(
theThis
),
pathOrLoc
);
return
theThis
.
props
.
router
.
replace
(
route
);
};
...
...
src/utils/config.js
浏览文件 @
79118904
import
baseConfig
from
'../../config'
;
/* eslint-disable no-undef */
/**
* Created by yaohx_169 on 2017/6/6.
...
...
@@ -48,17 +50,19 @@ const defaultDateFormat = 'YYYY-MM-DD';
const
defaultTimeFormat
=
'HH:mm:ss'
;
const
defaultDateTimeFormat
=
`
${
defaultDateFormat
}
${
defaultTimeFormat
}
`
;
// eslint-disable-next-line no-underscore-dangle
const
_apiContextPath
=
process
.
env
.
NODE_ENV
===
'development'
?
''
:
apiContextPath
;
// eslint-disable-next-line no-underscore-dangle
const
_contextPath
=
process
.
env
.
NODE_ENV
===
'development'
?
''
:
contextPath
;
const
dev
=
process
.
env
.
NODE_ENV
===
'development'
;
const
contextPath
=
dev
?
baseConfig
.
dev
.
contextPath
:
baseConfig
.
prod
.
contextPath
;
const
apiContextPath
=
dev
?
baseConfig
.
dev
.
apiContextPath
:
baseConfig
.
prod
.
apiContextPath
;
const
basename
=
dev
?
baseConfig
.
dev
.
basename
:
baseConfig
.
prod
.
basename
;
const
config
=
{
name
:
'Jbpm Demo'
,
footerText
:
'上海铂蓝信息科技有限公司'
,
logo
:
`
${
_contextPath
}
/logo.png`
,
contextPath
:
_contextPath
,
apiContextPath
:
_apiContextPath
,
logo
:
`
${
contextPath
}
/logo.png`
,
basename
,
contextPath
,
apiContextPath
,
productId
:
'big-machine-web-front'
,
fastNavigationPage
:
''
,
defaultDateFormat
,
...
...
src/utils/helper.js
浏览文件 @
79118904
...
...
@@ -57,33 +57,40 @@ export function locationOrigin(withContext = true) {
return
`
${
location
.
protocol
}
//
${
location
.
hostname
}${
location
.
port
?
':'
+
location
.
port
:
''
}${
withContext
?
contextPath
:
''
}
`
;
// eslint-disable-line
}
export
const
makePath
=
(
base
,
path
,
withContext
=
true
)
=>
{
export
const
makeSureEndsWithSlash
=
(
path
)
=>
{
if
(
!
path
||
!
path
.
endsWith
(
'/'
))
{
return
`
${
path
||
''
}
/`
;
}
else
{
return
path
;
}
};
const
makeSureStartsWithSlash
=
(
path
)
=>
{
if
(
!
path
||
!
path
.
startsWith
(
'/'
))
{
return
`/
${
path
||
''
}
`
;
}
else
{
return
path
;
}
};
export
const
makePath
=
(
base
,
path
,
withContext
=
false
)
=>
{
if
(
path
.
startsWith
(
'/'
))
{
return
withContext
?
`
${
contextPath
}${
path
}
`
:
path
;
}
const
basePath
=
base
.
endsWith
(
'/'
)
?
base
:
`
${
base
}
/`
;
const
basePath
=
makeSureEndsWithSlash
(
base
)
;
return
resolvePathname
(
path
,
basePath
);
};
export
function
currentPath
()
{
let
path
=
location
.
pathname
;
// eslint-disable-line
if
(
!
path
)
{
path
=
'/'
;
}
if
(
path
[
0
]
!==
'/'
)
{
path
=
`/
${
path
}
`
;
}
path
=
makeSureStartsWithSlash
(
path
);
if
(
path
.
slice
(
0
,
contextPath
.
length
)
===
contextPath
)
{
return
path
.
slice
(
contextPath
.
length
);
return
makeSureStartsWithSlash
(
path
.
slice
(
contextPath
.
length
)
);
}
else
{
return
'/'
;
return
path
;
}
}
export
function
fullPath
(
path
)
{
return
`
${
contextPath
}${
path
}
`
;
}
export
function
encrypt
(
text
)
{
const
jsEncrypt
=
createJSEncrypt
();
jsEncrypt
.
setPublicKey
(
pubKey
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论