Commit 0e0b85e9 by 姜雷

修改条码渲染根据传入服务改变

parent 6698c484
...@@ -16,13 +16,13 @@ ...@@ -16,13 +16,13 @@
} }
&.left { &.left {
.text-box { .text-box {
margin-left: 114px; margin-left: 50px;
} }
} }
&.right { &.right {
.text-box { .text-box {
position: absolute; position: absolute;
right: 114px; right: 50px;
} }
} }
.text { .text {
......
...@@ -11,6 +11,6 @@ export const CUSTOMER_SERVER_URL = ...@@ -11,6 +11,6 @@ export const CUSTOMER_SERVER_URL =
export const SCHOOL_MAIN_URL = 'https://internal-dev-school-main.168cad.top'; export const SCHOOL_MAIN_URL = 'https://internal-dev-school-main.168cad.top';
export const ANN_LINK_URL = 'https://ex-dev-wx.168cad.top/announcement/'; export const ANN_LINK_URL = 'https://ex-dev-wx.168cad.top/announcement/';
export const SHOWER_APP_URL = 'http://ex-shower-app-server.168cad.top'; export const SHOWER_APP_URL = 'http://ex-shower-app-server.168cad.top';
export const SOCKET_URL = 'ws://192.168.1.35:22153/ws'; export const SOCKET_URL = 'ws://dev-shower-wss1.168cad.top:9443/ws';
export const SMPRO_URL = 'https://ex-dev-dcxy-smapro-app.168cad.top'; export const SMPRO_URL = 'https://ex-dev-dcxy-smapro-app.168cad.top';
export const GX_URL = 'http://ex-dev-gx-app-server.168cad.top'; export const GX_URL = 'http://ex-dev-gx-app-server.168cad.top';
...@@ -223,8 +223,18 @@ class BarCode extends Component { ...@@ -223,8 +223,18 @@ class BarCode extends Component {
} }
drawBarCode() { drawBarCode() {
const { userinfo } = this.props; const { userinfo } = this.props;
const routeParams = this.$router.params;
let serviceId = '';
if (routeParams && routeParams.serviceId) {
serviceId =
routeParams.serviceId.length === 1
? '0' + routeParams.serviceId
: routeParams.serviceId;
}
console.log('serviceId: ', serviceId);
if (userinfo.idBar && userinfo.idBar.length > 2) { if (userinfo.idBar && userinfo.idBar.length > 2) {
let idBar = userinfo.idBar.substring(0, userinfo.idBar.length - 2) + '04'; let idBar =
userinfo.idBar.substring(0, userinfo.idBar.length - 2) + serviceId;
wxbarcode.barcode('BarCode', idBar, 646, 188); wxbarcode.barcode('BarCode', idBar, 646, 188);
wxbarcode.barcode('BarCodeBig', idBar, 700, 364); wxbarcode.barcode('BarCodeBig', idBar, 700, 364);
} else { } else {
......
...@@ -44,7 +44,6 @@ type IProps = PageStateProps & PageDispatchProps; ...@@ -44,7 +44,6 @@ type IProps = PageStateProps & PageDispatchProps;
type PageState = { type PageState = {
bluetoothState: boolean; bluetoothState: boolean;
task: Taro.SocketTask | null;
deviceInfo: DeviceInfo; deviceInfo: DeviceInfo;
sockedDone: boolean; sockedDone: boolean;
deviceDone: boolean; deviceDone: boolean;
...@@ -59,7 +58,7 @@ interface Shower { ...@@ -59,7 +58,7 @@ interface Shower {
let timer: number | null = null; let timer: number | null = null;
let reConnectting: boolean = false; let reConnectting: boolean = false;
let socketTask: Taro.SocketTask | null = null;
@connect( @connect(
({ userinfo, Shower }) => ({ ({ userinfo, Shower }) => ({
userinfo, userinfo,
...@@ -80,7 +79,6 @@ class Shower extends Component { ...@@ -80,7 +79,6 @@ class Shower extends Component {
super(props); super(props);
this.state = { this.state = {
bluetoothState: false, bluetoothState: false,
task: null,
sockedDone: false, sockedDone: false,
deviceDone: false, deviceDone: false,
showerState: false, showerState: false,
...@@ -106,18 +104,21 @@ class Shower extends Component { ...@@ -106,18 +104,21 @@ class Shower extends Component {
componentWillUnmount() { componentWillUnmount() {
this.closeBluetooth(); this.closeBluetooth();
this.closeDeviceSocket(); Taro.closeSocket();
timer && clearTimeout(timer);
timer = null;
reConnectting = false;
} }
connectDeviceSocket() { connectDeviceSocket() {
connectSocket(SOCKET_URL).then(task => { connectSocket(SOCKET_URL).then(task => {
socketTask = task;
task.onOpen(() => { task.onOpen(() => {
console.log('onOpen'); console.log('onOpen');
if (reConnectting) { if (reConnectting) {
this.reConnectDeviceSocket(true); this.reConnectDeviceSocket(true);
} }
this.setState({ this.setState({
task: task,
sockedDone: true, sockedDone: true,
}); });
task.send({ data: str2ab('{}') }); task.send({ data: str2ab('{}') });
...@@ -149,16 +150,14 @@ class Shower extends Component { ...@@ -149,16 +150,14 @@ class Shower extends Component {
task.onClose(e => { task.onClose(e => {
console.log('socked关闭', e, reConnectting, timer); console.log('socked关闭', e, reConnectting, timer);
this.setState({ this.setState({
task: null,
sockedDone: false, sockedDone: false,
}); });
socketTask = null;
if (e.code === StopCode) { if (e.code === StopCode) {
console.log('正确结束socket连接'); console.log('正确结束socket连接');
} else if (!reConnectting) { } else {
console.log('开始重连socket'); console.log('开始重连socket');
this.reConnectDeviceSocket(false); this.reConnectDeviceSocket(false);
} else {
console.log('断开socket', e);
} }
}); });
}); });
...@@ -185,25 +184,24 @@ class Shower extends Component { ...@@ -185,25 +184,24 @@ class Shower extends Component {
content: '请保持网络畅通正常', content: '请保持网络畅通正常',
}); });
} else { } else {
let newTimer = setTimeout(() => { timer = setTimeout(() => {
reConnectting = false; reConnectting = false;
}, 10000); }, 10000);
reConnectting = true; reConnectting = true;
timer = newTimer;
console.log(reConnectting, timer); console.log(reConnectting, timer);
this.connectDeviceSocket(); this.connectDeviceSocket();
} }
} }
sendDeviceCode() { sendDeviceCode() {
const { task, sockedDone, deviceDone } = this.state; const { sockedDone, deviceDone } = this.state;
const { bluetoothDevice } = this.props; const { bluetoothDevice } = this.props;
console.log('socket状态:', sockedDone, '蓝牙状态:', deviceDone); console.log('socket状态:', sockedDone, '蓝牙状态:', deviceDone);
if (sockedDone && task && deviceDone) { if (sockedDone && socketTask && deviceDone) {
let deviceData = '{<' + bluetoothDevice.code + '>}'; let deviceData = '{<' + bluetoothDevice.code + '>}';
console.log('<---发送设备编号:', deviceData); console.log('<---发送设备编号:', deviceData);
task.send({ socketTask.send({
data: str2ab(deviceData), data: str2ab(deviceData),
success: msg => { success: msg => {
console.log('发送设备编号:', msg, '--->'); console.log('发送设备编号:', msg, '--->');
...@@ -216,15 +214,12 @@ class Shower extends Component { ...@@ -216,15 +214,12 @@ class Shower extends Component {
} }
closeDeviceSocket() { closeDeviceSocket() {
const { task } = this.state; console.log('in close', socketTask, timer);
console.log('in close', task, timer); if (socketTask) {
if (task) { socketTask.close({
task.close({
code: StopCode, code: StopCode,
complete: () => { complete: () => {
this.setState({ socketTask = null;
task: null,
});
}, },
}); });
} }
...@@ -422,14 +417,13 @@ class Shower extends Component { ...@@ -422,14 +417,13 @@ class Shower extends Component {
this.closeDeviceSocket(); this.closeDeviceSocket();
this.closeBluetoothConnection(); this.closeBluetoothConnection();
} else { } else {
const { task } = this.state;
if ( if (
datastr.substring(0, 1) === '{' && datastr.substring(0, 1) === '{' &&
datastr.substring(datastr.length - 1, datastr.length) === '}' datastr.substring(datastr.length - 1, datastr.length) === '}'
) { ) {
console.log('<---发送完整数据: ', datastr); console.log('<---发送完整数据: ', datastr);
if (task) { if (socketTask) {
task.send({ socketTask.send({
data: str2ab(datastr), data: str2ab(datastr),
success: msg => { success: msg => {
console.log('发送完整数据:', msg, '--->'); console.log('发送完整数据:', msg, '--->');
...@@ -449,8 +443,8 @@ class Shower extends Component { ...@@ -449,8 +443,8 @@ class Shower extends Component {
abStr += datastr; abStr += datastr;
console.log('接受尾部数据后: ', abStr); console.log('接受尾部数据后: ', abStr);
console.log('<---发送完整数据: ', abStr); console.log('<---发送完整数据: ', abStr);
if (task) { if (socketTask) {
task.send({ socketTask.send({
data: str2ab(abStr), data: str2ab(abStr),
success: msg => { success: msg => {
console.log('发送完整数据:', msg, '--->'); console.log('发送完整数据:', msg, '--->');
...@@ -586,10 +580,9 @@ class Shower extends Component { ...@@ -586,10 +580,9 @@ class Shower extends Component {
msg.substring(0, 1) === '{' && msg.substring(0, 1) === '{' &&
msg.substring(msg.length - 1, msg.length) === '}' msg.substring(msg.length - 1, msg.length) === '}'
) { ) {
const { task } = this.state;
console.log('<---发送给socket完整数据: ', msg); console.log('<---发送给socket完整数据: ', msg);
task && socketTask &&
task.send({ socketTask.send({
data: str2ab(msg), data: str2ab(msg),
success: msg => { success: msg => {
console.log('发送给socket完整数据:', msg, '--->'); console.log('发送给socket完整数据:', msg, '--->');
...@@ -609,9 +602,8 @@ class Shower extends Component { ...@@ -609,9 +602,8 @@ class Shower extends Component {
console.log('接受尾部数据后: ', abStr); console.log('接受尾部数据后: ', abStr);
console.log('<---发送给socket完整数据: ', abStr); console.log('<---发送给socket完整数据: ', abStr);
const { task } = this.state; socketTask &&
task && socketTask.send({
task.send({
data: str2ab(abStr), data: str2ab(abStr),
success: msg => { success: msg => {
console.log('发送给socket完整数据:', msg, '--->'); console.log('发送给socket完整数据:', msg, '--->');
......
...@@ -113,7 +113,7 @@ class WaterDispenser extends Component { ...@@ -113,7 +113,7 @@ class WaterDispenser extends Component {
toggleCodeState() { toggleCodeState() {
Taro.redirectTo({ Taro.redirectTo({
url: `/pages/BarCode/BarCode?backPage=${encodeURIComponent( url: `/pages/BarCode/BarCode?serviceId=9&backPage=${encodeURIComponent(
'/pages/WaterDispenser/WaterDispenser', '/pages/WaterDispenser/WaterDispenser',
)}`, )}`,
}); });
......
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