mirror of
https://gitee.com/java110/MicroCommunityWeb.git
synced 2026-02-25 14:17:54 +08:00
优化代码
This commit is contained in:
parent
fa7dbd793f
commit
da2136c48e
@ -241,7 +241,12 @@
|
||||
}
|
||||
|
||||
//建立websocket 消息连接
|
||||
let _userId = vc.getData('/nav/getUserInfo').userId;
|
||||
let user = vc.getData('/nav/getUserInfo');
|
||||
if (!user.hasOwnProperty('userId')) {
|
||||
return;
|
||||
}
|
||||
|
||||
let _userId = user.userId;
|
||||
|
||||
let _protocol = window.location.protocol;
|
||||
let url = '';
|
||||
|
||||
@ -1,23 +1,37 @@
|
||||
/**
|
||||
入驻小区
|
||||
**/
|
||||
(function (vc) {
|
||||
(function (vc) {
|
||||
vc.extends({
|
||||
data: {
|
||||
parkingAreaControlCarInoutInfo: {
|
||||
inImg:'/img/carInout.jpg',
|
||||
outImg:'/img/carInout.jpg'
|
||||
|
||||
inImg: '/img/carInout.jpg',
|
||||
outImg: '/img/carInout.jpg'
|
||||
|
||||
}
|
||||
},
|
||||
_initMethod: function () {
|
||||
|
||||
|
||||
},
|
||||
_initEvent: function () {
|
||||
|
||||
vc.on('parkingAreaControlCarInout', 'notify', function (_param) {
|
||||
let _parkingAreaControl = _param.parkingAreaControl;
|
||||
let _data = _param.data;
|
||||
if (_data.action != 'IN_OUT') {
|
||||
return;
|
||||
}
|
||||
if (_parkingAreaControl.inMachineId == _data.extMachineId) {
|
||||
$that.parkingAreaControlCarInoutInfo.inImg = "data:image/png;base64," + _data.img;
|
||||
}
|
||||
|
||||
if (_parkingAreaControl.outMachineId == _data.extMachineId) {
|
||||
$that.parkingAreaControlCarInoutInfo.outImg = "data:image/png;base64," + _data.img;
|
||||
}
|
||||
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
})(window.vc);
|
||||
@ -7,7 +7,8 @@
|
||||
amount: '',
|
||||
remark: '',
|
||||
type: '1101',
|
||||
payCharge: ''
|
||||
payCharge: '',
|
||||
machineId: ''
|
||||
}
|
||||
},
|
||||
_initMethod: function () {
|
||||
@ -50,10 +51,12 @@
|
||||
function (json, res) {
|
||||
//vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
|
||||
let _data = JSON.parse(json);
|
||||
$('#parkingAreaControlCustomCarInoutModel').modal('hide');
|
||||
if (_data.code != 0) {
|
||||
vc.toast(_data.msg);
|
||||
} else {
|
||||
vc.toast(_data.msg);
|
||||
vc.emit('parkingAreaControlFee', 'clear', {})
|
||||
}
|
||||
},
|
||||
function (errInfo, error) {
|
||||
@ -68,7 +71,8 @@
|
||||
amount: '',
|
||||
remark: '',
|
||||
type: '1101',
|
||||
payCharge: ''
|
||||
payCharge: '',
|
||||
machineId: ''
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-2 col-form-label">停车时间</label>
|
||||
<div class="col-sm-8">
|
||||
<input v-model="parkingAreaControlFeeInfo.time" disabled="disabled" type="text" placeholder="停车时间"
|
||||
<input v-model="parkingAreaControlFeeInfo.inOutTime" disabled="disabled" type="text" placeholder="停车时间"
|
||||
class="form-control">
|
||||
</div>
|
||||
</div>
|
||||
@ -37,7 +37,8 @@
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-2 col-form-label">应收</label>
|
||||
<div class="col-sm-8">
|
||||
<input v-model="parkingAreaControlFeeInfo.payCharge" type="text" disabled="disabled" placeholder="应收" class="form-control">
|
||||
<input v-model="parkingAreaControlFeeInfo.payCharge" type="text" disabled="disabled" placeholder="应收"
|
||||
class="form-control">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
@ -53,7 +54,8 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group text-center">
|
||||
<button class="btn btn-primary" type="button" v-on:click="saveTempFeeInfo()">临时车收费</button>
|
||||
<button class="btn btn-primary" type="button" :disabled="parkingAreaControlFeeInfo.pay==0"
|
||||
v-on:click="saveTempFeeInfo()">临时车收费</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -6,18 +6,37 @@
|
||||
data: {
|
||||
parkingAreaControlFeeInfo: {
|
||||
carNum: "",
|
||||
time: "",
|
||||
inOutTime: "",
|
||||
payCharge: 0.0,
|
||||
pay: 0.0,
|
||||
remark: "",
|
||||
open: "",
|
||||
openMsg: "",
|
||||
machineId: ''
|
||||
}
|
||||
},
|
||||
_initMethod: function () {
|
||||
|
||||
},
|
||||
_initEvent: function () {
|
||||
vc.on('parkingAreaControlFee', 'notify', function (_data) {
|
||||
if (_data.action != 'FEE_INFO') {
|
||||
return;
|
||||
}
|
||||
let _machineId = $that.parkingAreaControlFeeInfo.machineId;
|
||||
vc.copyObject(_data, $that.parkingAreaControlFeeInfo);
|
||||
$that.parkingAreaControlFeeInfo.openMsg = _data.remark;
|
||||
$that.parkingAreaControlFeeInfo.pay = _data.payCharge;
|
||||
$that.parkingAreaControlFeeInfo.remark = '';
|
||||
$that.parkingAreaControlFeeInfo.machineId = _machineId;
|
||||
});
|
||||
vc.on('parkingAreaControlFee', 'changeMachine', function (_data) {
|
||||
$that.parkingAreaControlFeeInfo.machineId = _data.machineId;
|
||||
})
|
||||
|
||||
vc.on('parkingAreaControlFee', 'clear', function () {
|
||||
$that.clearParkingAreaControlFeeInfo();
|
||||
});
|
||||
|
||||
},
|
||||
methods: {
|
||||
@ -27,7 +46,22 @@
|
||||
carNum: $that.parkingAreaControlFeeInfo.carNum,
|
||||
amount: $that.parkingAreaControlFeeInfo.pay,
|
||||
payCharge: $that.parkingAreaControlFeeInfo.payCharge,
|
||||
machineId: $that.parkingAreaControlFeeInfo.machineId
|
||||
})
|
||||
},
|
||||
clearParkingAreaControlFeeInfo: function () {
|
||||
let _machineId = $that.parkingAreaControlFeeInfo.machineId;
|
||||
|
||||
$that.parkingAreaControlFeeInfo = {
|
||||
carNum: "",
|
||||
inOutTime: "",
|
||||
payCharge: 0.0,
|
||||
pay: 0.0,
|
||||
remark: "",
|
||||
open: "",
|
||||
openMsg: "",
|
||||
machineId: _machineId
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -59,6 +59,9 @@
|
||||
//创建一个socket实例
|
||||
let wsUrl = "";
|
||||
let _enterMachineId = $that.parkingAreaControlVideoInfo.inMachineId;
|
||||
vc.emit('parkingAreaControl', 'notify', {
|
||||
inMachineId: _enterMachineId
|
||||
});
|
||||
$that.parkingAreaControlVideoInfo.inMachines.forEach((item) => {
|
||||
if (item.machineId == _enterMachineId) {
|
||||
wsUrl = item.machineIp;
|
||||
@ -109,6 +112,13 @@
|
||||
//创建一个socket实例
|
||||
let wsUrl = "";
|
||||
let _outMachineId = $that.parkingAreaControlVideoInfo.outMachineId;
|
||||
vc.emit('parkingAreaControl', 'notify', {
|
||||
outMachineId: _outMachineId
|
||||
});
|
||||
vc.emit('parkingAreaControlFee', 'changeMachine', {
|
||||
machineId: _outMachineId
|
||||
});
|
||||
|
||||
let paId = "";
|
||||
$that.parkingAreaControlVideoInfo.outMachines.forEach((item) => {
|
||||
if (item.machineId == _outMachineId) {
|
||||
@ -206,8 +216,17 @@
|
||||
});
|
||||
},
|
||||
customCarIn: function (_type) {
|
||||
let _machineId = $that.parkingAreaControlVideoInfo.inMachineId;
|
||||
if (_type != '1101') {
|
||||
_machineId = $that.parkingAreaControlVideoInfo.outMachineId;
|
||||
}
|
||||
if (!_machineId) {
|
||||
vc.toast('请选择摄像头');
|
||||
return;
|
||||
}
|
||||
vc.emit('parkingAreaControlCustomCarInout', 'open', {
|
||||
type: _type
|
||||
type: _type,
|
||||
machineId: _machineId
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -6,18 +6,23 @@
|
||||
data: {
|
||||
parkingAreaControlInfo: {
|
||||
_currentTab: 'parkingAreaControlCarInout',
|
||||
paId: ''
|
||||
paId: '',
|
||||
inMachineId: '',
|
||||
outMachineId: '',
|
||||
|
||||
}
|
||||
},
|
||||
_initMethod: function () {
|
||||
$that.parkingAreaControlInfo.paId = vc.getParam('paId');
|
||||
$that._initParkingAreaWs();
|
||||
vc.emit('parkingAreaControlVideo', 'notify', {
|
||||
paId: $that.parkingAreaControlInfo.paId
|
||||
});
|
||||
},
|
||||
_initEvent: function () {
|
||||
$that._initParkingAreaWs();
|
||||
vc.on('parkingAreaControl', 'notify', function (_param) {
|
||||
vc.copyObject(_param, $that.parkingAreaControlInfo);
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
changeTab: function (_tab) {
|
||||
@ -26,7 +31,7 @@
|
||||
paId: $that.parkingAreaControlInfo.paId
|
||||
})
|
||||
},
|
||||
_initParkingAreaWs:function(){
|
||||
_initParkingAreaWs: function () {
|
||||
let clientId = vc.uuid();
|
||||
let heartCheck = {
|
||||
timeout: 30000, // 9分钟发一次心跳,比server端设置的连接时间稍微小一点,在接近断开的情况下以通信的方式去重置连接时间。
|
||||
@ -48,7 +53,7 @@
|
||||
}
|
||||
websocket.send("{'cmd':'ping'}");
|
||||
self.pingTime = _pingTime;
|
||||
|
||||
|
||||
heartCheck.reset().start(); // 如果获取到消息,说明连接是正常的,重置心跳检测
|
||||
} else {
|
||||
console.log("断开状态,尝试重连");
|
||||
@ -57,7 +62,7 @@
|
||||
}, this.timeout)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let _protocol = window.location.protocol;
|
||||
let url = '';
|
||||
if (_protocol.startsWith('https')) {
|
||||
@ -65,12 +70,15 @@
|
||||
"wss://" + window.location.host + "/ws/parkingArea/" +
|
||||
$that.parkingAreaControlInfo.paId + "/" + clientId;
|
||||
} else {
|
||||
// url =
|
||||
// "ws://" + window.location.host + "/ws/parkingArea/" +
|
||||
// $that.parkingAreaControlInfo.paId + "/" + clientId;
|
||||
url =
|
||||
"ws://" + window.location.host + "/ws/parkingArea/" +
|
||||
"ws://demo.homecommunity.cn:9011/ws/parkingArea/" +
|
||||
$that.parkingAreaControlInfo.paId + "/" + clientId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if ("WebSocket" in window) {
|
||||
websocket = new WebSocket(url);
|
||||
} else if ("MozWebSocket" in window) {
|
||||
@ -78,7 +86,7 @@
|
||||
} else {
|
||||
websocket = new SockJS(url);
|
||||
}
|
||||
|
||||
|
||||
//连接发生错误的回调方法
|
||||
websocket.onerror = function (_err) {
|
||||
console.log("初始化失败", _err);
|
||||
@ -87,13 +95,13 @@
|
||||
message: "连接失败,请检查网络"
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
//连接成功建立的回调方法
|
||||
websocket.onopen = function () {
|
||||
heartCheck.reset().start();
|
||||
console.log("ws初始化成功");
|
||||
};
|
||||
|
||||
|
||||
//接收到消息的回调方法
|
||||
websocket.onmessage = function (event) {
|
||||
heartCheck.reset().start();
|
||||
@ -104,14 +112,14 @@
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_data.code == 200) {
|
||||
toastr.info(_data.msg);
|
||||
} else {
|
||||
toastr.error(_data.msg);
|
||||
}
|
||||
|
||||
vc.emit('parkingAreaControlCarInout', 'notify', {
|
||||
data: _data,
|
||||
parkingAreaControl: $that.parkingAreaControlInfo
|
||||
});
|
||||
vc.emit('parkingAreaControlFee', 'notify', _data);
|
||||
};
|
||||
|
||||
|
||||
//连接关闭的回调方法
|
||||
websocket.onclose = function () {
|
||||
console.log("初始化失败");
|
||||
@ -121,7 +129,7 @@
|
||||
message: "连接关闭,请刷新浏览器"
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
//监听窗口关闭事件,当窗口关闭时,主动去关闭websocket连接,防止连接还没断开就关闭窗口,server端会抛异常。
|
||||
window.onbeforeunload = function () {
|
||||
websocket.close();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user