Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
zhangzhonghua
/
BoneHouse_Business_APP
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d459e3e0
authored
Apr 25, 2021
by
wong.peiyi
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
配置信息、异常处理
parent
20b4460d
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
252 additions
and
20 deletions
src/pages/index/index.tsx
src/pages/mine/mine.tsx
src/services/request.ts
src/services/service.ts
src/stores/store.ts
src/stores/system.ts
src/utils/transform.ts
src/utils/utils.ts
src/pages/index/index.tsx
View file @
d459e3e0
/*
* @FilePath: /BoneHouse_Business_APP/src/pages/index/index.tsx
* @Author: peii
* @Date: 2021-04-24 22:45:15
* @Vision: 1.0
* @Description: 首页
*
* @Revision:
*
*/
import
React
,
{
Component
}
from
'react'
import
{
View
,
Text
,
TouchableOpacity
,
Image
,
ScrollView
}
from
'react-native'
import
{
View
,
Text
,
TouchableOpacity
,
Image
,
ScrollView
,
RefreshControl
}
from
'react-native'
import
slashScreen
from
'react-native-splash-screen'
import
{
observer
,
inject
}
from
'mobx-react'
import
{
IFunction
}
from
'bonehouse'
...
...
@@ -11,30 +22,65 @@ import styles from './index.styl'
type
IProps
=
{
store
:
{
token
:
string
getBizFuns
:
Function
functionIcons
:
any
[]
getBizFuns
:
Function
setNavigation
:
Function
}
sysStore
:
{
getSysProfile
:
Function
}
}
class
Index
extends
Component
<
IProps
>
{
state
=
{
refreshing
:
false
,
}
constructor
(
props
)
{
super
(
props
)
this
.
onRefresh
=
this
.
onRefresh
.
bind
(
this
)
}
componentDidMount
()
{
slashScreen
.
hide
()
this
.
props
.
store
.
setNavigation
(
this
.
props
.
navigation
)
setTimeout
(()
=>
{
const
{
navigation
,
store
}
=
this
.
props
!
store
.
token
&&
navigation
.
navigate
(
'Signin'
)
this
.
getSysProfile
()
},
0
)
}
/**
* @description: 下拉刷新
* @param {*}
* @return {*}
*/
onRefresh
()
{
this
.
setState
({
refreshing
:
true
})
this
.
getSysProfile
().
finally
(()
=>
this
.
setState
({
refreshing
:
false
}))
}
async
getSysProfile
()
{
this
.
props
.
sysStore
.
getSysProfile
()
}
render
()
{
const
{
navigation
,
store
}
=
this
.
props
const
{
refreshing
}
=
this
.
state
const
funs
=
store
.
getBizFuns
()
return
(
<
View
style=
{
styles
.
index
}
>
<
Header
title=
"骨科智慧仓"
back=
{
false
}
/>
<
ScrollView
style=
{
g
(
styles
,
'biz'
)
}
>
<
ScrollView
style=
{
g
(
styles
,
'biz'
)
}
refreshControl=
{
<
RefreshControl
refreshing=
{
refreshing
}
onRefresh=
{
this
.
onRefresh
}
/>
}
>
<
View
style=
{
g
(
styles
,
'biz-view'
)
}
>
{
funs
.
map
(
fun
=>
{
return
(
...
...
@@ -58,4 +104,4 @@ class Index extends Component<IProps> {
}
}
export
default
inject
(
'store'
)(
observer
(
Index
))
export
default
inject
(
'store'
,
'sysStore'
)(
observer
(
Index
))
src/pages/mine/mine.tsx
View file @
d459e3e0
/*
* @FilePath: /BoneHouse_Business_APP/src/pages/mine/mine.tsx
* @Author: peii
* @Date: 2021-04-24 22:45:15
* @Vision: 1.0
* @Description: 我的页面
*
* @Revision:
*
*/
import
React
,
{
Component
}
from
'react'
import
{
View
,
Text
,
ScrollView
,
Image
,
SafeAreaView
}
from
'react-native'
import
{
List
}
from
'@ant-design/react-native'
...
...
src/services/request.ts
View file @
d459e3e0
/*
* @FilePath: /BoneHouse_Business_APP/src/services/request.ts
* @Author: peii
* @Date: 2021-04-24 22:45:15
* @Vision: 1.0
* @Description:
*
* @Revision:
*
*/
// @ts-nocheck
import
*
as
R
from
'ramda'
import
{
isBlank
}
from
'../utils/utils'
import
{
isBlank
,
show
,
genPid
}
from
'../utils/utils'
import
{
stringify
}
from
'querystring'
import
Store
from
'../stores/store'
import
container
from
'../inversify'
...
...
@@ -14,19 +24,34 @@ interface RequestConfig {
headers
:
any
}
let
requestQueue
=
[]
export
const
request
=
(
args
:
Partial
<
RequestConfig
>
)
=>
{
const
store
=
container
.
get
<
Store
>
(
TYPES
.
Store
)
let
cancel
=
null
let
isCancel
=
false
const
p
=
new
Promise
((
resolve
,
reject
)
=>
{
cancel
=
()
=>
{
isCancel
=
true
reject
({
errorCode
:
400
,
errorMsg
:
'取消'
})
}
return
new
Promise
((
resolve
,
reject
)
=>
{
let
options
:
any
=
{
headers
:
{
'Content-Type'
:
'application/json'
,
},
method
:
R
.
propOr
(
'get'
,
'method'
,
args
),
reTries
:
R
.
propOr
(
3
,
'reTries'
,
args
),
needToken
:
R
.
propOr
(
true
,
'needToken'
,
args
),
...
args
,
}
if
(
options
.
needToken
)
{
options
.
data
.
accessToken
=
store
.
token
}
args
.
data
=
transformObject
(
args
.
data
,
'toLine'
)
options
=
R
.
cond
([
[
R
.
propEq
(
'method'
,
'get'
),
...
...
@@ -42,39 +67,67 @@ export const request = (args: Partial<RequestConfig>) => {
fetch
(
store
.
host
+
options
.
url
,
options
)
.
then
(
res
=>
res
.
json
())
.
then
(
res
=>
{
if
(
isCancel
)
return
console
.
log
(
'返回结果:'
,
res
)
R
.
ifElse
(
fetchSuccess
,
()
=>
resolve
(
transformObject
(
res
,
'toHump'
)),
()
=>
{
removeRequestByPid
(
pid
)
resolve
(
transformObject
(
res
,
'toHump'
))
},
()
=>
{
throw
res
},
)(
res
)
})
.
catch
(
e
=>
{
if
(
requestTimes
<=
options
.
reTries
)
{
if
(
isCancel
)
return
if
(
requestTimes
<
options
.
reTries
)
{
return
doRequest
()
}
// TODO: 登录判断
// failHandler(e)
// throw e
failHandler
(
e
,
store
,
pid
)
})
}
doRequest
()
})
const
pid
=
genPid
()
requestQueue
.
push
({
pid
,
p
,
cancel
})
return
p
.
catch
(
e
=>
{
return
e
})
}
const
fetchSuccess
=
R
.
propEq
(
'error_code'
,
0
)
const
failHandler
=
async
(
err
:
any
)
=>
{
const
removeRequestByPid
=
pid
=>
{
requestQueue
=
R
.
compose
(
R
.
remove
(
R
.
__
,
1
,
requestQueue
),
R
.
findIndex
(
R
.
propEq
(
'pid'
,
pid
)),
)(
requestQueue
)
}
const
failHandler
=
async
(
err
:
any
,
store
:
Store
,
pid
)
=>
{
R
.
ifElse
(
isBlank
,
()
=>
{
// Message.error(`${err.status} ${err.statusText}`
)
show
(
err
.
status
?
`
${
err
.
status
}
${
err
.
statusText
}
`
:
err
.
message
)
},
()
=>
{
// Message.error(`${err.code} ${err.msg}`)
if
(
err
.
error_code
===
41006
)
{
show
(
err
.
error_msg
)
removeRequestByPid
(
pid
)
R
.
map
(
p
=>
{
p
.
cancel
()
},
requestQueue
)
requestQueue
=
[]
store
.
navigation
.
navigate
(
'Signin'
)
}
else
{
show
(
err
.
error_msg
)
removeRequestByPid
(
pid
)
}
},
)(
err
.
code
)
)(
err
.
error_code
)
return
err
}
src/services/service.ts
View file @
d459e3e0
/*
* @FilePath: /BoneHouse_Business_APP/src/services/service.ts
* @Author: peii
* @Date: 2021-04-24 22:45:15
* @Vision: 1.0
* @Description: 网络服务
*
* @Revision:
*
*/
import
{
request
}
from
'./request'
import
{
injectable
}
from
'inversify'
...
...
src/stores/store.ts
View file @
d459e3e0
import
{
observable
,
action
,
runInAction
,
computed
,
decorate
,
toJS
}
from
'mobx'
/*
* @FilePath: /BoneHouse_Business_APP/src/stores/store.ts
* @Author: peii
* @Date: 2021-04-24 22:45:15
* @Vision: 1.0
* @Description: 一般性store
*
* @Revision:
*
*/
import
{
observable
,
action
,
runInAction
,
toJS
,
flow
}
from
'mobx'
import
{
persist
}
from
'mobx-persist'
import
{
injectable
}
from
'inversify'
import
{
injectable
,
inject
}
from
'inversify'
import
{
NativeModules
}
from
'react-native'
import
{
IFunction
}
from
'bonehouse'
import
*
as
R
from
'ramda'
...
...
@@ -29,6 +39,8 @@ export default class Store {
MOBILE_TRANSFER_APPLICATION
:
require
(
'../assets/images/trans_order.png'
),
}
@
observable
navigation
=
null
/**
* 首页功能列表
* @returns IFunction[]
...
...
@@ -65,6 +77,11 @@ export default class Store {
setFunctions
(
functions
:
IFunction
[])
{
this
.
functions
=
functions
}
@
action
setNavigation
(
navigation
:
any
)
{
this
.
navigation
=
navigation
}
}
runInAction
(()
=>
{
...
...
src/stores/system.ts
View file @
d459e3e0
import
{
observable
,
action
,
flow
}
from
'mobx'
/*
* @FilePath: /BoneHouse_Business_APP/src/stores/system.ts
* @Author: peii
* @Date: 2021-04-24 22:45:15
* @Vision: 1.0
* @Description: 系统store
*
* @Revision:
*
*/
import
{
observable
,
flow
,
runInAction
}
from
'mobx'
import
{
persist
}
from
'mobx-persist'
import
{
injectable
}
from
'inversify'
import
{
injectable
,
inject
}
from
'inversify'
import
*
as
R
from
'ramda'
import
Service
from
'../services/service'
import
{
TYPES
}
from
'../inversify/types'
import
{
toBinaryNumber
}
from
'../utils/utils'
@
injectable
()
export
default
class
System
{
@
inject
(
TYPES
.
Service
)
private
service
!
:
Service
@
persist
@
observable
sysProfiles
=
{
// APP借货仓库显隐及是否必填
OBS_MOBILE_BOR_WARE_REQUIRED
:
'00'
,
// APP消耗是否显示部门权限
OBS_MOBILE_CONSU_DEPARTMENT_DISPLAY
:
'00'
,
// APP消耗是否显示医生权限
OBS_MOBILE_CONSU_DOCTOR_DISPLAY
:
'00'
,
// APP消耗是否显示跟台员权限
OBS_MOBILE_CONSU_FOLLOW_DISPLAY
:
'00'
,
// APP下单是否显示部门权限
OBS_MOBILE_DEPARTMENT_DISPLAY
:
'00'
,
// APP下单是否显示业务经理权限
OBS_MOBILE_BM_DISPLAY
:
'00'
,
// APP下单是否显示跟台员权限
OBS_MOBILE_SUR_FOLLOWER_DISPLAY
:
'00'
,
// APP下单是否显示送货员权限
OBS_MOBILE_DELIVERYMAN_DISPLAY
:
'00'
,
// APP器械消耗展示价格权限
OBS_MOBILE_EQU_CON_DISPLAY_PRICE
:
'N'
,
}
/**
* @description: 获取系统配置
* @param {*} function
* @return {*}
*/
getSysProfile
=
flow
(
function
*
(
this
:
System
)
{
const
getProfiles
=
async
(
key
:
any
)
=>
{
const
res
=
(
await
this
.
service
.
getSysProfile
({
profileCode
:
key
}))
as
any
runInAction
(()
=>
{
// @ts-ignore
this
.
sysProfiles
[
key
]
=
isNaN
(
res
.
data
.
profileValue
)
?
res
.
data
.
profileValue
:
toBinaryNumber
(
res
.
data
.
profileValue
)
})
}
R
.
compose
(
R
.
map
(
getProfiles
),
R
.
keys
)(
this
.
sysProfiles
)
})
}
src/utils/transform.ts
View file @
d459e3e0
/*
* @FilePath: /BoneHouse_Business_APP/src/utils/transform.ts
* @Author: peii
* @Date: 2021-04-24 22:45:15
* @Vision: 1.0
* @Description:
*
* @Revision:
*
*/
import
*
as
R
from
'ramda'
import
{
isBlank
}
from
'./utils'
...
...
@@ -39,7 +49,7 @@ export function transformObject(obj: ITransObj, type: ITransformTypes = 'toHump'
R
.
map
((
key
:
string
)
=>
{
const
dKey
=
fn
.
call
(
null
,
key
)
if
(
R
.
type
(
item
[
key
])
===
'Array'
||
R
.
type
(
item
[
key
])
===
'Object'
)
{
desc
[
dKey
]
=
isBlank
(
item
[
key
])
?
item
[
key
]
:
transformObject
(
item
[
key
])
desc
[
dKey
]
=
isBlank
(
item
[
key
])
?
item
[
key
]
:
transformObject
(
item
[
key
]
,
type
)
}
else
{
desc
[
dKey
]
=
item
[
key
]
}
...
...
src/utils/utils.ts
View file @
d459e3e0
/*
* @FilePath: /BoneHouse_Business_APP/src/utils/utils.ts
* @Author: peii
* @Date: 2021-04-24 22:45:15
* @Vision: 1.0
* @Description:
*
* @Revision:
*
*/
// @ts-nocheck
import
*
as
R
from
'ramda'
import
{
Dimensions
,
Platform
}
from
'react-native'
...
...
@@ -107,3 +117,23 @@ export const isIphoneX = (): boolean => {
(
screenH
===
XS_MAX_HEIGHT
&&
screenW
===
XS_MAX_WIDTH
))
)
}
/**
* 生成随机ID
* @returns
*/
export
const
genPid
=
():
string
=>
{
return
new
Date
().
getTime
()
+
Math
.
random
()
*
1000
}
/**
* @description: 转成二进制字符串
* @param {number} n
* @return {string}
*/
export
const
toBinaryNumber
=
(
n
:
number
|
string
,
len
=
2
):
string
=>
{
if
(
isNaN
(
n
))
return
n
let
binN
=
parseInt
(
n
).
toString
(
2
)
while
(
R
.
length
(
binN
)
<
len
)
binN
=
'0'
+
binN
return
binN
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment