Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
ant-design-pro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
duanledexianxianxian
ant-design-pro
Commits
aa01d58c
Commit
aa01d58c
authored
Jun 24, 2019
by
duanledexianxianxian
😁
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sync code
parent
3c02868d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
85 additions
and
52 deletions
+85
-52
src/config.js
src/config.js
+5
-4
src/pages/system/parameter/models/business.js
src/pages/system/parameter/models/business.js
+3
-2
src/utils/kim-request.js
src/utils/kim-request.js
+7
-5
src/utils/request.js
src/utils/request.js
+70
-41
No files found.
src/config.js
View file @
aa01d58c
// import store from './utils/store';
// import store from './utils/store';
export
default
{
export
default
{
baseUrl
:
'
http://
platform.kuopu.net/9
080
'
,
baseUrl
:
'
http://
127.0.0.1:8
080
'
,
storeNameSpace
:
'
kim
'
,
storeNameSpace
:
'
kim
'
,
headers
:
()
=>
({
headers
:
()
=>
({
Authorization
:
Authorization
:
'
eyJhbGciOiJIUzI1NiJ9.eyJ1aWQiOjMzLCJ1c24iOiLmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrociLCJzdGEiOjE1NjEzMzQ2MDkwMTEsImxpZCI6Im91eWFuZ2JveXUifQ.eriHWClI-ST9CuEJuoU608KTKxIhf4XUxOSslzwT6K8
'
,
'
eyJhbGciOiJIUzI1NiJ9.eyJ1aWQiOjMzLCJ1c24iOiLmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrociLCJzdGEiOjE1NjEzNDQyNDg5ODksImxpZCI6Im91eWFuZ2JveXUifQ.FbY-QQLgq8H9CWSo1FhCPgXZJQtte5lhAPC4W45mHmo
'
,
}),
}),
successCode
:
'
sys.success
'
,
// 后台正常返回错误编码
};
};
src/pages/system/parameter/models/business.js
View file @
aa01d58c
...
@@ -40,10 +40,11 @@ export default {
...
@@ -40,10 +40,11 @@ export default {
effects
:
{
effects
:
{
// 获取列表数据
// 获取列表数据
*
getList
({
payload
},
{
call
,
put
})
{
*
getList
({
payload
},
{
call
,
put
})
{
const
{
data
}
=
yield
call
(
service
.
getList
,
payload
);
const
result
=
yield
call
(
service
.
getList
,
payload
);
console
.
log
(
result
);
yield
put
({
yield
put
({
type
:
'
save
'
,
type
:
'
save
'
,
payload
:
{
...
data
},
payload
:
{
...
result
.
data
},
});
});
},
},
// 增加
// 增加
...
...
src/utils/kim-request.js
View file @
aa01d58c
...
@@ -26,15 +26,15 @@ class HttpRequest {
...
@@ -26,15 +26,15 @@ class HttpRequest {
getInsideConfig
()
{
getInsideConfig
()
{
const
config
=
{
const
config
=
{
baseURL
:
this
.
options
.
baseUrl
,
baseURL
:
this
.
options
.
baseUrl
,
// baseURL
timeout
:
10000
,
responseType
:
'
json
'
,
'
x-requested-with
'
:
'
XMLHttpRequest
'
,
withCredentials
:
false
,
// default
headers
:
{
headers
:
{
'
x-requested-with
'
:
'
XMLHttpRequest
'
,
'
Access-Control-Allow-Origin
'
:
'
*
'
,
'
Access-Control-Allow-Origin
'
:
'
*
'
,
'
Content-Type
'
:
'
application/json
'
,
'
Content-Type
'
:
'
application/json
'
,
Accept
:
'
application/json
'
,
Accept
:
'
application/json
'
,
withCredentials
:
false
,
// default
timeout
:
10000
,
responseType
:
'
json
'
,
...
this
.
options
.
headers
,
...
this
.
options
.
headers
,
},
},
};
};
...
@@ -60,11 +60,13 @@ class HttpRequest {
...
@@ -60,11 +60,13 @@ class HttpRequest {
// 响应拦截
// 响应拦截
instance
.
interceptors
.
response
.
use
(
instance
.
interceptors
.
response
.
use
(
res
=>
{
res
=>
{
// success
this
.
destroy
(
url
);
this
.
destroy
(
url
);
const
{
data
,
status
}
=
res
;
const
{
data
,
status
}
=
res
;
return
{
data
,
status
,
statusText
:
codeMessage
[
status
]
};
return
{
data
,
status
,
statusText
:
codeMessage
[
status
]
};
},
},
error
=>
{
error
=>
{
// error
this
.
destroy
(
url
);
this
.
destroy
(
url
);
const
errorResult
=
JSON
.
parse
(
JSON
.
stringify
(
error
));
const
errorResult
=
JSON
.
parse
(
JSON
.
stringify
(
error
));
const
errorInfo
=
error
.
response
;
const
errorInfo
=
error
.
response
;
...
...
src/utils/request.js
View file @
aa01d58c
...
@@ -20,12 +20,11 @@ const errorHandler = error => {
...
@@ -20,12 +20,11 @@ const errorHandler = error => {
}
}
};
};
const
axios
=
new
HttpRequest
({
/**
baseUrl
,
* 组装url
headers
:
headers
()
||
{},
* @param {url} url
errorHandler
,
* @param {配置参数} more
});
*/
const
mergeApi
=
(
url
,
more
)
=>
{
const
mergeApi
=
(
url
,
more
)
=>
{
if
(
more
&&
more
.
apiPrefix
&&
typeof
more
.
apiPrefix
===
'
string
'
)
{
if
(
more
&&
more
.
apiPrefix
&&
typeof
more
.
apiPrefix
===
'
string
'
)
{
return
`
${
config
.
apiPrefix
}${
url
}
`
;
return
`
${
config
.
apiPrefix
}${
url
}
`
;
...
@@ -36,45 +35,78 @@ const mergeApi = (url, more) => {
...
@@ -36,45 +35,78 @@ const mergeApi = (url, more) => {
return
url
;
return
url
;
};
};
const
axios
=
new
HttpRequest
({
baseUrl
,
headers
:
headers
()
||
{},
errorHandler
,
});
/**
* 正常返回结果处理
* @param {返回请求数据} response
* @param {配置项} more
*/
const
checkCode
=
(
response
,
more
)
=>
{};
export
default
function
request
(
url
,
options
=
{},
more
=
{})
{
let
newOptions
=
options
;
newOptions
.
url
=
url
;
if
(
more
.
headers
)
{
newOptions
=
{
...
options
,
headers
:
more
.
headers
};
}
return
axios
.
request
(
newOptions
).
then
(
response
=>
checkCode
(
response
,
more
));
}
const
get
=
(
url
,
data
,
more
=
{})
=>
const
get
=
(
url
,
data
,
more
=
{})
=>
axios
.
request
({
request
(
method
:
'
get
'
,
// default
`
${
mergeApi
(
url
,
more
)}
`
,
url
:
`
${
mergeApi
(
url
,
more
)}
`
,
{
params
:
data
,
method
:
'
get
'
,
// default
...
more
,
params
:
data
,
});
},
more
,
);
const
post
=
(
url
,
data
,
more
=
{})
=>
const
post
=
(
url
,
data
,
more
=
{})
=>
axios
.
request
({
request
(
method
:
'
post
'
,
// default
`
${
mergeApi
(
url
,
more
)}
`
,
url
:
`
${
mergeApi
(
url
,
more
)}
`
,
{
data
,
method
:
'
post
'
,
// default
...
more
,
data
,
});
},
more
,
);
const
put
=
(
url
,
data
,
more
=
{})
=>
const
put
=
(
url
,
data
,
more
=
{})
=>
axios
.
request
({
request
(
method
:
'
put
'
,
// default
`
${
mergeApi
(
url
,
more
)}
`
,
url
:
`
${
mergeApi
(
url
,
more
)}
`
,
{
data
,
method
:
'
put
'
,
// default
...
more
,
data
,
});
},
more
,
);
const
del
=
(
url
,
data
,
more
=
{})
=>
const
del
=
(
url
,
data
,
more
=
{})
=>
axios
.
request
({
request
(
method
:
'
delete
'
,
// default
`
${
mergeApi
(
url
,
more
)}
`
,
url
:
`
${
mergeApi
(
url
,
more
)}
`
,
{
data
,
method
:
'
delete
'
,
// default
...
more
,
data
,
});
},
more
,
);
const
patch
=
(
url
,
data
,
more
=
{})
=>
const
patch
=
(
url
,
data
,
more
=
{})
=>
axios
.
request
({
request
(
method
:
'
patch
'
,
// default
`
${
mergeApi
(
url
,
more
)}
`
,
url
:
`
${
mergeApi
(
url
,
more
)}
`
,
{
data
,
method
:
'
patch
'
,
// default
...
more
,
data
,
});
...
more
,
},
more
,
);
const
formDataUpload
=
(
url
,
data
,
more
=
{})
=>
{
const
formDataUpload
=
(
url
,
data
,
more
=
{})
=>
{
const
formData
=
new
FormData
();
const
formData
=
new
FormData
();
...
@@ -83,10 +115,7 @@ const formDataUpload = (url, data, more = {}) => {
...
@@ -83,10 +115,7 @@ const formDataUpload = (url, data, more = {}) => {
formData
.
append
(
key
,
data
[
key
]);
formData
.
append
(
key
,
data
[
key
]);
});
});
}
}
axios
.
request
({
post
(
`
${
mergeApi
(
url
,
more
)}
`
,
formData
,
{
method
:
'
post
'
,
// default
url
:
`
${
mergeApi
(
url
,
more
)}
`
,
data
:
formData
,
headers
:
{
headers
:
{
'
Content-Type
'
:
'
multipart/form-data
'
,
'
Content-Type
'
:
'
multipart/form-data
'
,
},
},
...
@@ -100,4 +129,4 @@ const uploadFile = (url, data, type = 'formData', more = {}) => {
...
@@ -100,4 +129,4 @@ const uploadFile = (url, data, type = 'formData', more = {}) => {
}
}
};
};
export
{
axios
as
request
,
get
,
post
,
put
,
del
,
patch
,
uploadFile
};
export
{
request
,
get
,
post
,
put
,
del
,
patch
,
uploadFile
};
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