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
57a1c76d
Commit
57a1c76d
authored
Apr 07, 2021
by
zhangleyuan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:改成hooks写法
parent
8c1d2f65
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
116 additions
and
49 deletions
+116
-49
src/modules/workWxAuthorize/index.jsx
+116
-49
No files found.
src/modules/workWxAuthorize/index.jsx
View file @
57a1c76d
import
React
from
'react'
;
import
React
,
{
useState
,
useEffect
,
useRef
}
from
"react"
;
import
Service
from
'@/common/js/service'
;
import
'./index.less'
;
class
WorkWxAuthorize
extends
React
.
Component
{
constructor
(
props
)
{
super
(
props
);
this
.
state
=
{
scanState
:
''
,
messageText
:
''
}
}
componentDidMount
()
{
function
WorkWxAuthorize
(
props
){
const
[
scanState
,
setScanState
]
=
useState
(
''
);
const
[
messageText
,
setMessageText
]
=
useState
(
''
);
useEffect
(()
=>
{
const
code
=
window
.
getParameterByName
(
'code'
);
if
(
!
code
){
this
.
workWechatAuthorize
();
workWechatAuthorize
();
}
else
{
console
.
log
(
'我已经重新进来了'
)
this
.
workWechatLogin
();
workWechatLogin
();
}
}
workWechatLogin
=
()
=>
{
},[])
function
workWechatLogin
(){
const
code
=
window
.
getParameterByName
(
'code'
);
const
ticket
=
window
.
getParameterByName
(
'ticket'
);
const
storeId
=
window
.
getParameterByName
(
'storeId'
);
...
...
@@ -30,55 +27,125 @@ class WorkWxAuthorize extends React.Component {
storeId
}).
then
((
res
)
=>
{
if
(
res
.
code
==
200
)
{
this
.
setState
({
scanState
:
'success'
})
setScanState
(
'success'
);
}
else
{
let
message
=
res
.
message
.
split
(
','
).
join
(
'<br />'
)
this
.
setState
({
scanState
:
'error'
,
messageText
:
message
})
setScanState
(
'error'
);
setMessageText
(
message
);
}
})
}
workWechatAuthorize
=
()
=>
{
function
workWechatAuthorize
()
{
const
params
=
{}
Service
.
hades
(
'anon/hades/getCorpTrainSuiteId'
,
params
).
then
((
res
)
=>
{
let
path
=
window
.
location
.
href
;
const
htmlUrl
=
`https://open.weixin.qq.com/connect/oauth2/authorize?appid=
${
res
.
result
}
&redirect_uri=
${
encodeURIComponent
(
path
)}
&response_type=code&scope=snsapi_privateinfo&state=STATE#wechat_redirect`
window
.
location
.
href
=
htmlUrl
;
})
}
render
()
{
const
{
scanState
,
messageText
}
=
this
.
state
;
return
(
<
div
className=
"work-authorize-page"
>
<
div
className=
"box"
>
{
scanState
===
'success'
&&
<
div
className=
"success"
>
<
img
src=
"https://image.xiaomaiketang.com/xm/iRkcMHPHba.png"
alt=
""
/>
<
p
>
扫码成功
</
p
>
</
div
>
}
{
scanState
===
'error'
&&
<
div
className=
"error"
>
<
img
src=
"https://image.xiaomaiketang.com/xm/6kSAYFMm2r.png
"
alt=
""
/>
<
p
className=
'message'
>
{
messageText
}
return
(
<
div
className=
"work-authorize-page"
>
<
div
className=
"box"
>
{
scanState
===
'success'
&&
<
div
className=
"success"
>
<
img
src=
"https://image.xiaomaiketang.com/xm/iRkcMHPHba.png"
alt=
""
/>
<
p
>
扫码成功
</
p
>
</
div
>
}
</
div
>
}
{
scanState
===
'error'
&&
<
div
className=
"error"
>
<
img
src=
"https://image.xiaomaiketang.com/xm/6kSAYFMm2r.png
"
alt=
""
/>
<
p
className=
'message'
>
{
messageText
}
</
p
>
</
div
>
}
</
div
>
)
}
</
div
>
)
}
// class WorkWxAuthorize extends React.Component {
// constructor(props) {
// super(props);
// this.state = {
// scanState:'',
// messageText:''
// }
// }
// componentDidMount() {
// const code = window.getParameterByName('code');
// if(!code){
// this.workWechatAuthorize();
// }else{
// console.log('我已经重新进来了')
// this.workWechatLogin();
// }
// }
// workWechatLogin= ()=>{
// const code = window.getParameterByName('code');
// const ticket = window.getParameterByName('ticket');
// const storeId = window.getParameterByName('storeId');
// Service.hades("anon/hades/wXWorkUserTicketLogin", {
// appTermEnum: 'XIAOMAI_CLOUD_CLASS_PC_WEB_CUSTOMER',
// code,
// ticket,
// storeId
// }).then((res) => {
// if (res.code == 200) {
// this.setState({
// scanState:'success'
// })
// } else {
// let message = res.message.split(',').join('<br />')
// this.setState({
// scanState:'error',
// messageText:message
// })
// }
// })
// }
// workWechatAuthorize = () => {
// const params = {}
// Service.hades('anon/hades/getCorpTrainSuiteId',params).then((res)=>{
// let path = window.location.href;
// const htmlUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${res.result}&redirect_uri=${encodeURIComponent(path)}&response_type=code&scope=snsapi_privateinfo&state=STATE#wechat_redirect`
// window.location.href = htmlUrl;
// })
// }
// render() {
// const { scanState,messageText} = this.state;
// return (
// <div className="work-authorize-page">
// <div className="box">
// { scanState === 'success' &&
// <div className="success">
// <img src="https://image.xiaomaiketang.com/xm/iRkcMHPHba.png" alt=""/>
// <p>
// 扫码成功
// </p>
// </div>
// }
// { scanState === 'error' &&
// <div className="error">
// <img src="https://image.xiaomaiketang.com/xm/6kSAYFMm2r.png
// " alt="" />
// <p className='message'>
// { messageText }
// </p>
// </div>
// }
// </div>
// </div>
// )
// }
// }
export
default
WorkWxAuthorize
;
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