Commit 31630d4a by zhangleyuan

Merge branch 'feature/zhangleyuan/20210105/wechat-authorize' into dev

parents e7686764 2fbefe86
......@@ -59,6 +59,7 @@
"postcss-normalize": "8.0.1",
"postcss-preset-env": "6.7.0",
"postcss-safe-parser": "4.0.1",
"query-string": "^6.13.8",
"react": "^16.13.1",
"react-app-polyfill": "^1.0.6",
"react-dev-utils": "^10.2.1",
......
/*
* @Author: 吴文洁
* @Date: 2020-08-31 09:34:31
* @LastEditors: 吴文洁
* @LastEditTime: 2020-08-31 09:35:36
* @LastEditors: zhangleyuan
* @LastEditTime: 2021-01-05 15:43:31
* @Description:
* @Copyright: 杭州杰竞科技有限公司 版权所有
*/
......@@ -32,27 +32,12 @@ class Axios {
params: any,
options: FetchOptions = { requestType: 'json' }
): 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) => {
const { NewVersion, currentUserInstInfo } = window;
const { instId } = currentUserInstInfo;
const instance: AxiosInstance = axios.create({
timeout: TIME_OUT,
responseType: 'json',
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',
}
});
......
/*
* @Author: 吴文洁
* @Date: 2020-08-31 09:34:51
* @LastEditors: 吴文洁
* @LastEditTime: 2020-08-31 09:35:25
* @LastEditors: zhangleyuan
* @LastEditTime: 2021-01-05 15:33:19
* @Description:
* @Copyright: 杭州杰竞科技有限公司 版权所有
*/
......@@ -22,10 +22,13 @@ class Service {
static Sales(url: string, params: any, option: any) {
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) {
return Axios.post('POST', url, params, option);
}
}
export default Service;
\ No newline at end of file
import React from 'react';
import Service from '@/common/js/service';
import { AppId } from '@/common/js/config'
import queryString from 'query-string';
import './index.less';
class Authorize extends React.Component {
constructor(props) {
super(props);
this.state = {
code:'',
ticket:'',
hasBindWechat:false
}
}
componentDidMount() {
const searchParams = this.props.location.search;
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
}
Service.hades('/anon/hades/changeTicketState',params).then(
)
}
wechatLogin = () => {
wechatAuthorize = () => {
let path = window.location.origin + window.location.pathname;
let htmlUrl = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + AppId +
'&redirect_uri=' + encodeURIComponent(path) +
'&response_type=code&scope=snsapi_userinfo&state=state#wechat_redirect';
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() {
const { hasBindWechat } = this.state
return (
<div className="authorize-page">
<div>
<img src="https://image.xiaomaiketang.com/xm/HsCjyKTbWw.png" className="avatar-img"></img>
</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>
)
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment