Browse Source

feat: 修改连接WiFi逻辑

tall
song 4 years ago
parent
commit
74248c7dd1
  1. 3
      CHANGELOG.md
  2. 77
      src/components/Wifi/Wifi.vue

3
CHANGELOG.md

@ -1,4 +1,4 @@
# 0.1.0 (2022-01-28)
# 0.1.0 (2022-02-08)
### 🌟 新功能
范围|描述|commitId
@ -235,6 +235,7 @@
task任务逻辑完善 | 减少初始global及regular的不必要请求 | [bd4bd38](https://101.201.226.163:50022/DIGITAL_MEDICAL/yanyuan/commits/bd4bd38)
- | title.vue根据页面栈显示返回按钮;标题文本超出显示... | [0cbacf4](https://101.201.226.163:50022/DIGITAL_MEDICAL/yanyuan/commits/0cbacf4)
- | WiFi界面修改,还原线条变细 | [6aa12e1](https://101.201.226.163:50022/DIGITAL_MEDICAL/yanyuan/commits/6aa12e1)
WiFi修复 | WiFi修复 | [63b253e](https://101.201.226.163:50022/DIGITAL_MEDICAL/yanyuan/commits/63b253e)
### 📝 文档

77
src/components/Wifi/Wifi.vue

@ -11,7 +11,7 @@
<script>
export default {
data() {
return { tcp: null };
return { tcp: null, isConnected: false, isSend: false };
},
props: {
@ -23,35 +23,70 @@ export default {
onLoad() {},
methods: {
sendTCP() {
// this.$t.ui.showLoading('...');
let that = this;
console.log('发送');
if (!this.tcp) {
this.tcp = wx.createTCPSocket();
if (!that.tcp) {
that.tcp = wx.createTCPSocket();
}
console.log('this.tcp', this.tcp);
this.tcp.connect({
address: '192.168.4.1',
port: 1001,
console.log('that.tcp', that.tcp);
if (!that.isConnected) {
that.tcp.connect({
address: '192.168.4.1',
port: 1001,
});
}
console.log('连接this.tcp', that.tcp);
if (that.isConnected) {
that.tcp.write(`#${that.name}:${that.password}$`);
that.tcp.write(`#${that.name}:${that.password}$`);
console.log('write-this.tcp', that.tcp);
}
//
that.tcp.onConnect(() => {
console.log('监听连接状态');
that.isConnected = true;
if (!that.isSend) {
console.log('监听连接状态,发送');
that.tcp.write(`#${that.name}:${that.password}$`);
that.tcp.write(`#${that.name}:${that.password}$`);
}
});
console.log('链接this.tcp', this.tcp);
this.tcp.write(`#${this.name}:${this.password}$`);
this.tcp.write(`#${this.name}:${this.password}$`);
console.log('write-this.tcp', this.tcp);
this.tcp.onMessage((message, remoteInfo, localInfo) => {
// this.$t.ui.hideLoading();
//
that.tcp.onMessage((message, remoteInfo, localInfo) => {
console.log(message, remoteInfo, localInfo);
// tcp
// this.tcp = null;
// that.tcp = null;
if (message) {
this.tcp = null;
this.tcp.close();
this.$t.page.openPage('/pagesYanyuan/hold-all/hold-all');
console.log('成功, 返回上一页', that.tcp);
that.isSend = true;
that.tcp.close();
console.log('关闭 跳转');
that.$t.page.openPage('/pagesYanyuan/hold-all/hold-all');
}
});
// setTimeout(() => {
// this.$t.ui.hideLoading();
// }, 10000);
//
that.tcp.offConnect(() => {
console.log('断开连接', that.isSend);
if (!that.isSend) {
that.tcp.connect({
address: '192.168.4.1',
port: 1001,
});
} else {
that.isConnected = false;
that.isSend = false;
}
});
//
that.tcp.onClose(() => {
that.isConnected = false;
that.isSend = false;
that.tcp = null;
});
},
},
};

Loading…
Cancel
Save