提交 fc3e25e3 authored 作者: 钟是志's avatar 钟是志

登录接口组件修改

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