Commit 195dfe0d by 姜雷

Merge branch 'test'

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