Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wechat-common
Overview
Overview
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
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xiaomai-cloud-class
wechat-common
Commits
2fbefe86
Commit
2fbefe86
authored
Jan 05, 2021
by
zhangleyuan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:接口联调
parent
ed5f966d
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
26 deletions
+58
-26
src/common/js/axios.ts
+3
-18
src/common/js/service.ts
+7
-3
src/modules/authorize/index.jsx
+48
-5
No files found.
src/common/js/axios.ts
View file @
2fbefe86
/*
/*
* @Author: 吴文洁
* @Author: 吴文洁
* @Date: 2020-08-31 09:34:31
* @Date: 2020-08-31 09:34:31
* @LastEditors:
吴文洁
* @LastEditors:
zhangleyuan
* @LastEditTime: 202
0-08-31 09:35:36
* @LastEditTime: 202
1-01-05 15:43:31
* @Description:
* @Description:
* @Copyright: 杭州杰竞科技有限公司 版权所有
* @Copyright: 杭州杰竞科技有限公司 版权所有
*/
*/
...
@@ -32,27 +32,12 @@ class Axios {
...
@@ -32,27 +32,12 @@ class Axios {
params
:
any
,
params
:
any
,
options
:
FetchOptions
=
{
requestType
:
'json'
}
options
:
FetchOptions
=
{
requestType
:
'json'
}
):
Promise
<
any
>
{
):
Promise
<
any
>
{
const
_url
=
`
${
url
}
?p=w&v=v
${
VERSION
}
&userType=
${
USER_TYPE
}
&token=
${
User
.
getToken
()}
&uid=
${
User
.
getUid
()}
&tid=
${
User
.
getTid
()}
&aid=
${
User
.
getAid
()}
`
;
const
_url
=
`
${
url
}
`
;
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
{
NewVersion
,
currentUserInstInfo
}
=
window
;
const
{
instId
}
=
currentUserInstInfo
;
const
instance
:
AxiosInstance
=
axios
.
create
({
const
instance
:
AxiosInstance
=
axios
.
create
({
timeout
:
TIME_OUT
,
timeout
:
TIME_OUT
,
responseType
:
'json'
,
responseType
:
'json'
,
headers
:
{
headers
:
{
instId
,
p
:
'w'
,
v
:
'VERSION'
,
vn
:
`v
${
VERSION
}
`
,
project
:
PROJECT
,
userType
:
USER_TYPE
,
cid
:
User
.
getCid
(),
uid
:
User
.
getUid
(),
tid
:
User
.
getTid
(),
token
:
User
.
getToken
(),
bizAccountId
:
User
.
getAid
(),
xmVersion
:
NewVersion
?
'5.0'
:
'4.0'
,
'Content-Type'
:
options
.
requestType
===
'json'
?
'application/json; charset=UTF-8'
:
'application/x-www-form-urlencoded'
,
'Content-Type'
:
options
.
requestType
===
'json'
?
'application/json; charset=UTF-8'
:
'application/x-www-form-urlencoded'
,
}
}
});
});
...
...
src/common/js/service.ts
View file @
2fbefe86
/*
/*
* @Author: 吴文洁
* @Author: 吴文洁
* @Date: 2020-08-31 09:34:51
* @Date: 2020-08-31 09:34:51
* @LastEditors:
吴文洁
* @LastEditors:
zhangleyuan
* @LastEditTime: 202
0-08-31 09:35:25
* @LastEditTime: 202
1-01-05 15:33:19
* @Description:
* @Description:
* @Copyright: 杭州杰竞科技有限公司 版权所有
* @Copyright: 杭州杰竞科技有限公司 版权所有
*/
*/
...
@@ -22,10 +22,13 @@ class Service {
...
@@ -22,10 +22,13 @@ class Service {
static
Sales
(
url
:
string
,
params
:
any
,
option
:
any
)
{
static
Sales
(
url
:
string
,
params
:
any
,
option
:
any
)
{
return
Axios
.
post
(
'POST'
,
`sales/
${
url
}
`
,
params
,
option
);
return
Axios
.
post
(
'POST'
,
`sales/
${
url
}
`
,
params
,
option
);
}
}
static
hades
(
url
:
string
,
params
:
any
,
option
:
any
)
{
return
Axios
.
post
(
'POST'
,
`hades/
${
url
}
`
,
params
,
option
);
}
static
post
(
url
:
string
,
params
:
any
,
option
:
any
)
{
static
post
(
url
:
string
,
params
:
any
,
option
:
any
)
{
return
Axios
.
post
(
'POST'
,
url
,
params
,
option
);
return
Axios
.
post
(
'POST'
,
url
,
params
,
option
);
}
}
}
}
export
default
Service
;
export
default
Service
;
\ No newline at end of file
src/modules/authorize/index.jsx
View file @
2fbefe86
...
@@ -8,30 +8,73 @@ class Authorize extends React.Component {
...
@@ -8,30 +8,73 @@ class Authorize extends React.Component {
constructor
(
props
)
{
constructor
(
props
)
{
super
(
props
);
super
(
props
);
this
.
state
=
{
this
.
state
=
{
code
:
''
,
ticket
:
''
,
hasBindWechat
:
false
}
}
}
}
componentDidMount
()
{
componentDidMount
()
{
const
searchParams
=
this
.
props
.
location
.
search
const
searchParams
=
this
.
props
.
location
.
search
;
console
.
log
(
'参数'
,
queryString
.
parse
(
searchParams
));
const
{
code
,
ticket
}
=
queryString
.
parse
(
searchParams
);
this
.
setState
({
code
,
ticket
})
if
(
!
code
){
this
.
setState
({
ticketState
:
"SCAN_SUCCESS"
},()
=>
this
.
changeCodeState
())
}
else
{
this
.
getWechatUserInfo
();
}
}
changeCodeState
=
()
=>
{
let
{
ticket
,
ticketState
}
=
this
.
state
;
const
params
=
{
ticket
,
ticketState
}
}
wechatLogin
=
()
=>
{
Service
.
hades
(
'/anon/hades/changeTicketState'
,
params
).
then
(
)
}
wechatAuthorize
=
()
=>
{
let
path
=
window
.
location
.
origin
+
window
.
location
.
pathname
;
let
path
=
window
.
location
.
origin
+
window
.
location
.
pathname
;
let
htmlUrl
=
'https://open.weixin.qq.com/connect/oauth2/authorize?appid='
+
AppId
+
let
htmlUrl
=
'https://open.weixin.qq.com/connect/oauth2/authorize?appid='
+
AppId
+
'&redirect_uri='
+
encodeURIComponent
(
path
)
+
'&redirect_uri='
+
encodeURIComponent
(
path
)
+
'&response_type=code&scope=snsapi_userinfo&state=state#wechat_redirect'
;
'&response_type=code&scope=snsapi_userinfo&state=state#wechat_redirect'
;
window
.
location
.
href
=
htmlUrl
;
window
.
location
.
href
=
htmlUrl
;
}
}
getWechatUserInfo
=
()
=>
{
let
{
ticket
,
code
}
=
this
.
state
;
const
params
=
{
appTermEnum
:
"XIAOMAI_CLOUD_CLASS_PC_WEB_ADMIN"
,
code
,
storeId
:
"1192022572770412395"
,
ticket
}
Service
.
hades
(
'/anon/hades/bindWeChat'
,
params
).
then
(
this
.
setState
({
hasBindWechat
:
true
})
)
}
render
()
{
render
()
{
const
{
hasBindWechat
}
=
this
.
state
return
(
return
(
<
div
className=
"authorize-page"
>
<
div
className=
"authorize-page"
>
<
div
>
<
div
>
<
img
src=
"https://image.xiaomaiketang.com/xm/HsCjyKTbWw.png"
className=
"avatar-img"
></
img
>
<
img
src=
"https://image.xiaomaiketang.com/xm/HsCjyKTbWw.png"
className=
"avatar-img"
></
img
>
</
div
>
</
div
>
<
div
>
<
div
>
<
button
className=
"login-btn"
onClick=
{
this
.
wechatLogin
}
>
微信登录
</
button
>
{
!
hasBindWechat
&&
<
button
className=
"login-btn"
onClick=
{
this
.
wechatAuthorize
}
>
微信登录
</
button
>
}
{
hasBindWechat
&&
<
button
className=
"login-btn"
onClick=
{
this
.
wechatAuthorize
}
>
已登录
</
button
>
}
</
div
>
</
div
>
</
div
>
</
div
>
)
)
}
}
}
}
...
...
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