Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
frontend
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Schedules
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
h5-communicate
frontend
Commits
3fedbcb5
Commit
3fedbcb5
authored
Jun 08, 2020
by
熊成伟
Browse files
Options
Browse Files
Download
Plain Diff
debug
parents
f124542a
896aa567
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
88 additions
and
51 deletions
+88
-51
workspace.xml
.idea/workspace.xml
+0
-0
index.jsx
src/pages/Login/index.jsx
+16
-17
Work.jsx
src/pages/Work/Work.jsx
+16
-8
instance.js
src/utils/instance.js
+15
-17
request.js
src/utils/request.js
+41
-9
No files found.
.idea/workspace.xml
View file @
3fedbcb5
This diff is collapsed.
Click to expand it.
src/pages/Login/index.jsx
View file @
3fedbcb5
...
...
@@ -2,29 +2,28 @@ import React, { useEffect } from 'react';
import
{
useRequest
}
from
"@umijs/hooks"
;
import
axios
from
'axios'
;
import
{
withRouter
}
from
'react-router-dom'
import
axiosRequest
,
{
loading
}
from
'../../utils/request'
;
// import { postRequest } from '../../utils/request';
// import './index.less'
const
Login
=
(
props
)
=>
{
// axios.post('/dgbg/mobileLogin.view?userName=2012012099&password=1&clientFlag=123456')
// .then(function (response) {
// // handle success
// console.log(response);
// })
// .catch(function (error) {
// // handle error
// console.log(error);
// })
// .finally(function () {
// // always executed
// });
const
{
data
,
error
,
loading
}
=
useRequest
({
url
:
'/dgbg/mobileLogin.view?userName=2012012099&password=1&clientFlag=123456'
,
method
:
'post'
axiosRequest
({
method
:
'post'
,
url
:
'/dgbg/mobileLogin.view?userName=2012012099&clientFlag=123456&password=1'
,
}).
then
(
res
=>
{
// setOperates(res.operate || []);
});
// const { data, error, loading } = useRequest({
// url: '/dgbg/mobileLogin.view',
// method: 'post',
// // data: {
// // userName: '2012012099',
// // password: '1',
// // clientFlag: 12345
// // },
// });
return
(
<
div
>
...
...
src/pages/Work/Work.jsx
View file @
3fedbcb5
import
React
,
{
useState
}
from
'react'
;
import
{
useRequest
}
from
"@umijs/hooks"
;
import
React
,
{
useState
,
useEffect
}
from
'react'
;
import
{
ActivityIndicator
,
WhiteSpace
,
WingBlank
}
from
"antd-mobile"
;
import
axiosRequest
,
{
loading
}
from
'../../utils/request'
;
import
TopSearch
from
'../../components/TopSearch'
import
WorkCard
from
'../../components/WorkCard'
const
Work
=
()
=>
{
const
[
addStatus
,
setAddStatus
]
=
useState
(
false
);
const
[
operates
,
setOperates
]
=
useState
([]);
const
{
data
,
error
,
loading
}
=
useRequest
({
url
:
'/dgbg/mobileGetOperates.view?userName=2012012099&clientFlag=123456'
,
method
:
'post'
});
useEffect
(()
=>
{
loadOperates
();
},
[]);
const
loadOperates
=
()
=>
{
axiosRequest
({
method
:
'post'
,
url
:
'/dgbg/mobileGetOperates.view?userName=2012012099&clientFlag=123456'
,
}).
then
(
res
=>
{
setOperates
(
res
.
operate
||
[]);
});
}
const
commonEdit
=
()
=>
{
setAddStatus
(
!
addStatus
);
...
...
@@ -30,7 +39,6 @@ const Work = () => {
// const index = arr.findIndex(item => item.id == id);
// index > -1 && arr.splice(index, 1);
};
return
(
<
WingBlank
>
<
ActivityIndicator
...
...
@@ -45,7 +53,7 @@ const Work = () => {
title=
"事物管理"
addCommon=
{
commonEdit
}
addStatus=
{
addStatus
}
data=
{
data
&&
data
.
operate
.
map
(
item
=>
({
icon
:
''
,
text
:
item
.
NODENAME
}))
||
[]
}
data=
{
operates
.
map
(
item
=>
({
icon
:
''
,
text
:
item
.
NODENAME
}))
}
iconAction=
{
itemAdd
}
/>
</
WingBlank
>
...
...
src/utils/instance.js
View file @
3fedbcb5
import
axios
from
'axios'
;
import
{
parse
,
stringify
}
from
'qs'
;
import
{
Toast
}
from
'antd-mobile'
;
const
instance
=
axios
.
create
();
const
token
=
'bearer '
+
localStorage
.
getItem
(
"token"
);
...
...
@@ -46,8 +47,13 @@ export const createAPI = (baseURL) => {
headers
,
},
conf
.
opts
))
.
then
(
function
(
response
)
{
if
(
!
response
||
response
.
data
===
false
)
{
console
.
log
(
'response出错!'
,
response
);
return
false
;
}
// 保存到本地
if
(
!
response
||
!
response
.
data
)
{
console
.
log
(
'response出错, 无返回数据!'
,
response
);
return
false
;
};
if
(
response
.
data
&&
response
.
data
.
errorMessage
)
{
Toast
.
fail
(
response
.
data
.
errorMessage
);
return
false
;
}
// 保存到本地
if
(
response
&&
response
.
data
&&
response
.
data
.
access_token
)
{
defaultHeaders
=
{
token
:
'bearer '
+
response
.
data
.
access_token
,
...
...
@@ -55,32 +61,24 @@ export const createAPI = (baseURL) => {
localStorage
.
setItem
(
"token"
,
response
.
data
.
access_token
);
}
if
(
response
.
data
&&
response
.
data
.
success
||
response
.
data
&&
(
response
.
data
.
success
===
undefined
&&
response
.
data
.
error
===
undefined
)
)
{
if
(
response
.
data
)
{
return
response
.
data
;
}
else
{
message
.
error
(
response
.
data
&&
(
response
.
data
.
mesg
||
response
.
data
.
message
)
||
'操作出现错误!'
)
return
response
.
data
;
return
false
;
}
})
.
catch
(
error
=>
{
if
(
error
.
response
)
{
const
{
status
,
statusText
,
url
}
=
error
.
response
;
const
errortext
=
codeMessage
[
status
]
||
statusText
;
// notification.error({
// key: status,
// message: `请求错误 ${status}`,
// description: errortext,
// });
if
(
status
===
401
)
{
// @HACK
/* eslint-disable no-underscore-dangle */
history
.
push
(
'/user/login'
);
message
.
error
(
'登录过期或用户名密码错误!'
)
// TODO 重新登录
// history.push('/user/login');
Toast
.
fail
(
errortext
);
return
false
;
}
else
if
(
status
===
400
||
status
>
401
)
{
history
.
push
(
`/exception/
${
status
}
`
);
Toast
.
fail
(
errortext
);
}
}
return
false
;
...
...
src/utils/request.js
View file @
3fedbcb5
import
{
createAPI
}
from
'./instance'
;
export
const
apiUrl
=
'http://124.93.101.8:9988/dgbg/'
;
// export const apiUrl = 'http://124.93.101.8:9988/dgbg/';
export
const
apiUrl
=
'/'
;
// mobileLogin.view
// 测试账户:2012012099
// 密码:1
const
instance
=
createAPI
(
apiUrl
);
const
loadingCounter
=
()
=>
{
let
count
=
0
;
const
startLoading
=
()
=>
{
count
++
;
}
const
endLoading
=
()
=>
{
count
--
;
}
const
getCount
=
()
=>
count
;
return
{
startLoading
,
endLoading
,
getCount
}
};
const
instance
=
createAPI
(
apiUrl
);
let
loadingCount
=
loadingCounter
(
);
export
function
postRequest
(
url
,
params
=
{})
{
return
instance
({
method
:
'post'
,
url
:
url
,
opts
:
params
,
async
function
axiosRequest
(
option
=
{})
{
loadingCount
.
startLoading
();
const
res
=
await
instance
({
method
:
option
.
method
||
'get'
,
url
:
option
.
url
,
opts
:
option
.
body
||
null
,
});
}
\ No newline at end of file
loadingCount
.
endLoading
();
return
res
;
}
export
let
loading
=
loadingCount
.
getCount
()
>
0
;
export
default
axiosRequest
;
// export function postRequest(url, params = {}) {
// return instance({
// method: 'post',
// url: url,
// opts: params,
// });
// }
\ No newline at end of file
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