提交 087cd718 authored 作者: 徐立's avatar 徐立
......@@ -7,10 +7,25 @@ import FormdataWrapper from '../utils/object-to-formdata-custom';
import { isJSON } from '../utils/utils';
let ws = null;
/**
* props 定义
* url: 二维码url
* show: 是否显示二维码Modal
* wxSocketGateWay: webscoket 链接地址
* mockServer: 接口地址前缀 用于获取sessionid;
* */
export default class LoginWithQrCode extends Component {
constructor(props) {
super(props);
const { wxSocketGateWay, mockServer } = this.props;
this.wxSocketGateWay = wxSocketGateWay;
this.mockServer = mockServer;
if(!wxSocketGateWay){
this.wxSocketGateWay = config.wxSocketGateWay;
}
if(!mockServer){
this.mockServer = config.mockServer;
}
this.state = {
connectTimes: 0,
sessionId: '',
......@@ -42,11 +57,11 @@ export default class LoginWithQrCode extends Component {
message.warning('服务器错误,无法使用扫码登录');
return false;
}
if (!config.wxSocketGateWay) {
if (!this.wxSocketGateWay) {
return console.warn('没有配置socket接口地址,无法使用消息中心接口');
}
ws = new WebSocket(`${config.wxSocketGateWay}/${sessionId}`);
ws = new WebSocket(`${this.wxSocketGateWay}/${sessionId}`);
ws.onopen = (evt) => {
that.setState({
connectStatus: true,
......@@ -99,7 +114,7 @@ export default class LoginWithQrCode extends Component {
Accept: 'application/json',
},
};
fetch(`${config.mockServer}/wx/` + 'wxAuthApi/getScanSessionId', options)
fetch(`${this.mockServer}/wx/` + 'wxAuthApi/getScanSessionId', options)
.then(response => {
if (response.status !== 200) {
return response.text();
......
import React from 'react';
import LoginWithQrCode from './LoginWithQrCode';
export default function LoginByQrCode({ url, LoginType }) {
/**
* url 二维码url
* LoginType: 1 表示 显示二维码 其他不显示
* wxSocketGateWay: websocket链接地址 'ws://scjoyedu.eicp.net:51337/wswx/test106/socket/'
* mockServer: 获取sessionId 接口前缀 'http://scjoyedu.eicp.net:51337/test106',
* */
export default function LoginByQrCode({ url, LoginType, wxSocketGateWay, mockServer }) {
return (
<div>
<div style={{ backgroundColor: 'white', width: 288, padding: 10, margin: 'auto' }}>
<LoginWithQrCode url={url} show={LoginType === 1}/>
<LoginWithQrCode
url={url}
show={LoginType === 1}
mockServer={mockServer}
wxSocketGateWay={wxSocketGateWay}
/>
</div>
<div style={{ marginTop: 20, color: 'white' }}>
请使用
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论