Commit 09371b1d by 姜雷

Merge branch 'develop' into test

parents 79c03d98 0fed48a4
......@@ -84,7 +84,6 @@ class Pay extends Component {
readId: '',
},
};
this.checkBluetoothAndWs();
}
componentWillMount() {
......@@ -95,6 +94,7 @@ class Pay extends Component {
payId: prepayConfig[0].id,
});
}
this.checkBluetoothAndWs();
}
componentWillUnmount() {
......@@ -103,55 +103,67 @@ class Pay extends Component {
}
connectDeviceSocket() {
Taro.connectSocket({ url: SOCKET_URL }).then(task => {
socketTask = task;
task.onOpen(() => {
console.log('onOpen');
if (reConnectting) {
this.reConnectDeviceSocket(true);
}
this.setState({
sockedDone: true,
let connectHandle;
if (socketTask) {
connectHandle = new Promise(resolve => resolve(socketTask));
} else {
connectHandle = Taro.connectSocket({ url: SOCKET_URL }).then(task => {
socketTask = task;
task.onOpen(() => {
console.log('onOpen');
if (reConnectting) {
this.reConnectDeviceSocket(true);
}
this.setState({
sockedDone: true,
});
task.send({ data: str2ab('{}') });
this.sendDeviceCode();
});
task.send({ data: str2ab('{}') });
this.sendDeviceCode();
});
task.onMessage(res => {
const msg: string = ab2str(res.data);
console.log('获取socket消息: ', msg);
if (msg === '[0]') {
console.log('结束蓝牙以及socket: ', msg);
// this.closeDeviceSocket();
// this.closeBluetoothConnection();
} else if (msg === '[]') {
} else {
if (msg.length > 100) {
this.sendMessageToDevice('[]');
} else if (msg.length > 20) {
for (let index = 0; index <= Math.floor(msg.length / 20); index++) {
let str = msg.substring(index * 20, (index + 1) * 20);
this.sendMessageToDevice(str);
}
task.onMessage(res => {
const msg: string = ab2str(res.data);
console.log('获取socket消息: ', msg);
if (msg === '[0]') {
console.log('结束蓝牙以及socket: ', msg);
// this.closeDeviceSocket();
// this.closeBluetoothConnection();
} else if (msg === '[]') {
} else {
if (msg) {
this.sendMessageToDevice(msg);
if (msg.length > 100) {
this.sendMessageToDevice('[]');
} else if (msg.length > 20) {
for (
let index = 0;
index <= Math.floor(msg.length / 20);
index++
) {
let str = msg.substring(index * 20, (index + 1) * 20);
this.sendMessageToDevice(str);
}
} else {
if (msg) {
this.sendMessageToDevice(msg);
}
}
}
}
});
task.onClose(e => {
console.log('socked关闭', e, reConnectting, timer);
this.setState({
sockedDone: false,
});
socketTask = null;
if (e.code === StopCode) {
console.log('正确结束socket连接');
} else {
console.log('开始重连socket');
this.reConnectDeviceSocket(false);
}
task.onClose(e => {
console.log('socked关闭', e, reConnectting, timer);
this.setState({
sockedDone: false,
});
socketTask = null;
if (e.code === StopCode) {
console.log('正确结束socket连接');
} else {
console.log('开始重连socket');
this.reConnectDeviceSocket(false);
}
});
});
}
connectHandle.then(() => {
console.log('socket done');
});
}
......@@ -220,6 +232,7 @@ class Pay extends Component {
}
}
checkIsShower(): boolean {
return true;
const { device } = this.props;
return device.serviceId === 5;
}
......@@ -250,7 +263,7 @@ class Pay extends Component {
},
() => {
this.startConnectDevice();
},
}
);
})
.catch(err => {
......@@ -390,7 +403,7 @@ class Pay extends Component {
let abStr = '';
Taro.onBLECharacteristicValueChange(res => {
console.log(
`characteristic ${res.characteristicId} has changed, now is ${res.value}`,
`characteristic ${res.characteristicId} has changed, now is ${res.value}`
);
console.log(res.value);
let datastr = ab2str(res.value);
......@@ -445,7 +458,7 @@ class Pay extends Component {
Taro.onBLEConnectionStateChange(res => {
// const { showerState } = this.state;
console.log(
`device ${res.deviceId} state has changed, connected: ${res.connected}`,
`device ${res.deviceId} state has changed, connected: ${res.connected}`
);
if (res.connected) {
this.setState({
......@@ -640,7 +653,7 @@ class Pay extends Component {
let service = services.find(
item =>
item.uuid.toLocaleLowerCase() ===
'6e401103-b5a3-f393-e0a9-e50e24dcca9e',
'6e401103-b5a3-f393-e0a9-e50e24dcca9e'
);
if (!service) {
service = services[0];
......@@ -763,7 +776,7 @@ class Pay extends Component {
AES.decrypt(payStr, Utf8.parse(key), {
mode: ECBmode,
padding: PaddingPkcs7,
}).toString(Utf8),
}).toString(Utf8)
);
console.log('payData:', payData);
Taro.requestPayment({
......@@ -838,28 +851,28 @@ class Pay extends Component {
const { device, prepayConfig, userinfo } = this.props;
const { payId } = this.state;
return (
<View className='Pay'>
<View className='Pay-info'>
<View className='Pay-info-item'>
<View className="Pay">
<View className="Pay-info">
<View className="Pay-info-item">
<Text>服务类型</Text>
<Text>{device.serviceName ? device.serviceName : ''}</Text>
</View>
<View className='Pay-info-item'>
<View className="Pay-info-item">
<Text>设备编号</Text>
<Text>{device.code ? device.code : ''}</Text>
</View>
<View className='Pay-info-item'>
<View className="Pay-info-item">
<Text>设备位置</Text>
<Text className='Pay-info-position'>{device.position}</Text>
<Text className="Pay-info-position">{device.position}</Text>
</View>
{device.rates.length && (
<View className='Pay-info-item'>
<View className="Pay-info-item">
<Text>适用费率</Text>
<View className='Pay-info-rate'>
<View className="Pay-info-rate">
{device.rates.map(item => (
<View key='name' className='Pay-info-rate-item'>
<Text className='Pay-info-rate-name'>{item.name}</Text>
<Text className='Pay-info-rate-mark'>{item.mark}</Text>
<View key="name" className="Pay-info-rate-item">
<Text className="Pay-info-rate-name">{item.name}</Text>
<Text className="Pay-info-rate-mark">{item.mark}</Text>
</View>
))}
{/* <View className='Pay-info-rate-item'>
......@@ -874,17 +887,17 @@ class Pay extends Component {
</View>
)}
</View>
<View className='Pay-tip'>
<View className="Pay-tip">
{device.refundMode === DeviceRefundMode.notRefund
? '温馨提示:设备成功开启后,未使用金额将不会退换!'
: '温馨提示:如本次预付款未全部使用,系统将在使用结束后半小时内自动退还剩余金额,请留意查收!'}
</View>
<View className='Pay-money'>
<View className="Pay-money">
{prepayConfig &&
prepayConfig.length &&
prepayConfig.map(payConfig => (
<View
key='id'
key="id"
className={`Pay-money-item ${
payConfig.id == payId ? 'seleted' : ''
}`}
......@@ -898,13 +911,13 @@ class Pay extends Component {
<Input className='Pay-money-item' placeholder='输入>0.5数额' /> */}
</View>
{userinfo.isAuth ? (
<Button className='Pay-btn' onClick={this.payHandle}>
<Button className="Pay-btn" onClick={this.payHandle}>
确定支付
</Button>
) : (
<Button
className='Pay-btn'
open-type='getPhoneNumber'
className="Pay-btn"
open-type="getPhoneNumber"
onGetphonenumber={this.getPhoneHandle}>
确定支付
</Button>
......
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