Commit 0917214c by yaxiLiuu

Merge branch 'dev' of git.mjitech.com:zhangxin/max_android_panel into dev

parents 7b2c4ebd b0614921
...@@ -16,7 +16,7 @@ let json = { ...@@ -16,7 +16,7 @@ let json = {
"address": "华贸商业街(新光天地与利兹卡尔顿酒店之间广场)" "address": "华贸商业街(新光天地与利兹卡尔顿酒店之间广场)"
} }
} }
} };
const saveStoreInfo = (data)=>{ const saveStoreInfo = (data)=>{
return{ return{
...@@ -25,7 +25,7 @@ const saveStoreInfo = (data)=>{ ...@@ -25,7 +25,7 @@ const saveStoreInfo = (data)=>{
} }
}; };
const getStoreInfo = ()=>{ const getStoreInfo = (storeId)=>{
return(dispatch)=>{ return(dispatch)=>{
// fetch(domain + '/web/pad_warehouse/getMachineData.action',{ // fetch(domain + '/web/pad_warehouse/getMachineData.action',{
// credentials : 'include', // credentials : 'include',
......
import swiperContainers from './swiperContainer' import swiperContainers from './swiperContainer'
import showPage from './showPage' import showPage from './showPage'
import socketType from './socketType'
module.exports = {swiperContainers,...showPage} module.exports = {swiperContainers,...showPage,socketType}
\ No newline at end of file \ No newline at end of file
const socketType = {
GETSTOREINFO:'GETSTOREINFO',
GETSOCKETMSG:'GETSOCKETMSG'
}
module.exports = socketType;
\ No newline at end of file
...@@ -18,7 +18,9 @@ import HomeContainer from '../HomeContainer/HomeContainer' ...@@ -18,7 +18,9 @@ import HomeContainer from '../HomeContainer/HomeContainer'
import FinishAskContainer from '../FinishAskContainer/FinishAskContainer' import FinishAskContainer from '../FinishAskContainer/FinishAskContainer'
import ChooseTaskContainer from '../ChooseTaskContainer/ChooseTaskContainer' import ChooseTaskContainer from '../ChooseTaskContainer/ChooseTaskContainer'
import Button from '../../components/CommonComponent/ButtonComponent/ButtonComponent'; import Button from '../../components/CommonComponent/ButtonComponent/ButtonComponent';
import Clock from '../../components/CommonComponent/ClockComponent/ClockComponent' import Clock from '../../components/CommonComponent/ClockComponent/ClockComponent';
import {on,remove} from '../../util/event';
require('./index.css'); require('./index.css');
...@@ -38,7 +40,6 @@ const defaultPopupInfo = { ...@@ -38,7 +40,6 @@ const defaultPopupInfo = {
class PageContainer extends React.Component { class PageContainer extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
// UTILPATH.socket.getIp();
this.state = { this.state = {
showPage : showPage[2], showPage : showPage[2],
lastPage : '', lastPage : '',
...@@ -46,7 +47,8 @@ class PageContainer extends React.Component { ...@@ -46,7 +47,8 @@ class PageContainer extends React.Component {
popupInfo : defaultPopupInfo, popupInfo : defaultPopupInfo,
pageStyle : {}, pageStyle : {},
lastPageStyle:{}, lastPageStyle:{},
showClock : false //关门页面显示倒计时 showClock : false, //关门页面显示倒计时
headerInfo : {}
}; };
this.getPages = this.getPages.bind(this); this.getPages = this.getPages.bind(this);
this.showPopup = this.showPopup.bind(this); this.showPopup = this.showPopup.bind(this);
...@@ -63,6 +65,8 @@ class PageContainer extends React.Component { ...@@ -63,6 +65,8 @@ class PageContainer extends React.Component {
this.overTimeSolve = this.overTimeSolve.bind(this); this.overTimeSolve = this.overTimeSolve.bind(this);
this.failCloseDoor = this.failCloseDoor.bind(this); this.failCloseDoor = this.failCloseDoor.bind(this);
this.judgeDoorStatus = this.judgeDoorStatus.bind(this); this.judgeDoorStatus = this.judgeDoorStatus.bind(this);
this.getSocketMsg = this.getSocketMsg.bind(this);
this.changePages = this.changePages.bind(this);
this.maxCountBackTime = 300; this.maxCountBackTime = 300;
this.count = 1000; this.count = 1000;
...@@ -70,15 +74,48 @@ class PageContainer extends React.Component { ...@@ -70,15 +74,48 @@ class PageContainer extends React.Component {
this.countBackTime = -1; this.countBackTime = -1;
} }
componentWillMount() {
let {dispatch} = this.props;
dispatch(getStoreInfo());
let pages = this.getPages(); connectOk(){
this.setState({ console.log("connectOk")
page : pages }
componentWillMount() {
let that = this;
on(CONFIG.socketType.GETSTOREINFO,this,function (data) {
console.log("==GETSTOREINFO===")
console.log(data)
dispatch(getStoreInfo(data.storeId));
})
on(CONFIG.socketType.GETSOCKETMSG,this,function (data) {
console.log("==GETSTOREINFO===")
console.log(data)
console.log(this);
that.getSocketMsg(data)
}) })
}
getSocketMsg(data){
switch (data.type){
case 'SUCCESS_OPENDOOR':
//执行开门
this.setState({
showPage : showPage[1]
},()=>{
this.beginCountBack();
});
break;
case 'SUCCESS_CLOSEDOOR':
//关门成功
this.setState({
showPage : showPage[7],
showClock : false,
popupInfo : defaultPopupInfo
});
break;
}
} }
componentDidMount(){ componentDidMount(){
// this.beginCountBack() // this.beginCountBack()
} }
...@@ -89,7 +126,12 @@ class PageContainer extends React.Component { ...@@ -89,7 +126,12 @@ class PageContainer extends React.Component {
componentWillUnmount(){ componentWillUnmount(){
} }
changePages(page){
this.setState({
showPage : page,
popupInfo : defaultPopupInfo
})
}
//开始倒计时,看有没有操作,只是在整个开门过程中才监听 //开始倒计时,看有没有操作,只是在整个开门过程中才监听
......
...@@ -29,5 +29,6 @@ function renderPage(store) { ...@@ -29,5 +29,6 @@ function renderPage(store) {
let store = activateVendor(); let store = activateVendor();
UTILPATH.socket.getIp();
renderPage(store); renderPage(store);
\ No newline at end of file
let events = {};
const on = (name,self,callback)=>{
let tuple = [self,callback];
let cb = events[name];
if(Array.isArray(cb)){
cb.push(tuple);
}else {
events[name] = [tuple];
}
};
const emit = (name,data)=>{
let callbacks = events[name];
if(Array.isArray(callbacks)){
callbacks.map((tuple)=>{
let self = tuple[0];
let callback = tuple[1];
callback.call(self,data);
})
}
};
const remove = (name,self)=>{
let callbacks = events[name];
if(Array.isArray(callbacks)){
events[name] = callbacks.filter(turple=>turple[0] !== self)
}
};
module.exports = {on,emit,remove};
\ No newline at end of file
import fetch from 'isomorphic-fetch' import fetch from 'isomorphic-fetch';
import {emit} from './event'
let domainIp = '192.168.10.';
let domainIp = '192.168.199.';
let initIndex = 1; let initIndex = 1;
let totalIndex = 255 / 5; let totalIndex = 255 / 5;
...@@ -28,10 +30,11 @@ const parseJson = (response)=>{ ...@@ -28,10 +30,11 @@ const parseJson = (response)=>{
return response.json(); return response.json();
}; };
const getIp = (cb)=>{ const getIp = ()=>{
console.log("getIp : ",initIndex) console.log("getIp : ",initIndex)
for(let i = initIndex; i < (totalIndex + initIndex) ; i++){ for(let i = initIndex; i < (totalIndex + initIndex) ; i++){
let url = 'http://' + domainIp + i + ':9999/getmyid'; let url = 'http://' + domainIp + i + ':9999/getmyid';
console.log(url)
fetch( url ,{ fetch( url ,{
// credentials : 'include', // credentials : 'include',
method : 'GET', method : 'GET',
...@@ -44,7 +47,7 @@ const getIp = (cb)=>{ ...@@ -44,7 +47,7 @@ const getIp = (cb)=>{
if(data.storeId){ if(data.storeId){
let wsUrl = 'ws://' + domainIp + i + ':7788/notify?from=plant&storeId='+data.storeId; let wsUrl = 'ws://' + domainIp + i + ':7788/notify?from=plant&storeId='+data.storeId;
currentIpIndex = i; currentIpIndex = i;
init(wsUrl,cb); init(i,data.storeId);
} }
}) })
...@@ -87,9 +90,10 @@ const testIp = (ip) => { ...@@ -87,9 +90,10 @@ const testIp = (ip) => {
if(data.storeId){ if(data.storeId){
window.storeId = data.storeId; window.storeId = data.storeId;
window.localIp = domainIp + i; window.localIp = domainIp + i;
let wsUrl = 'ws://' + domainIp + i + ':7788/notify?from=plant&storeId='+data.storeId; let wsUrl = 'ws://' + domainIp + i + ':7788/notify?from=plant&storeId='+data.storeId;
currentIpIndex = i; currentIpIndex = i;
init(wsUrl,cb); init(i,data.storeId);
} }
}) })
.catch((err) =>{ .catch((err) =>{
...@@ -104,10 +108,12 @@ const testIp = (ip) => { ...@@ -104,10 +108,12 @@ const testIp = (ip) => {
} }
const init = (url,cb)=>{ const init = (ip,storeid)=>{
console.log("init :" ,url);
if("WebSocket" in window && !ws && url){ let wsUrl = 'ws://' + domainIp + ip + ':7788/notify?from=plant&storeId=' + storeid;
ws = new WebSocket(url); console.log("init :" ,wsUrl);
if("WebSocket" in window && !ws && ip && storeid){
ws = new WebSocket(wsUrl);
ws.onopen = function() ws.onopen = function()
{ {
...@@ -119,16 +125,17 @@ const init = (url,cb)=>{ ...@@ -119,16 +125,17 @@ const init = (url,cb)=>{
inteval = null; inteval = null;
initIndex = 1; initIndex = 1;
failTotal = 1; failTotal = 1;
cb();
console.log("open"); console.log("open");
isFalse = false; isFalse = false;
emit(CONFIG.socketType.GETSTOREINFO,{ip:domainIp+ip,storeId:storeid})
}; };
ws.onmessage = function (evt) ws.onmessage = function (evt)
{ {
var received_msg = evt.data; var received_msg = JSON.parse(evt.data); //String
console.log("数据已接收..."); console.log("数据已接收...");
emit(CONFIG.socketType.GETSOCKETMSG,received_msg);
}; };
ws.onclose = function(err) ws.onclose = function(err)
......
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