Browse Source

feat: 连接WiFi

develop
song 4 years ago
parent
commit
fb4cce598c
  1. 3
      CHANGELOG.md
  2. 79
      src/components/Wifi/Wifi.vue
  3. 2
      src/mixins/tool.js
  4. 176
      src/pagesProject/project/components/Evaluated/components/ProcessRestore - 副本.vue
  5. 29
      src/pagesProject/project/components/Evaluated/components/ProcessRestore.vue
  6. 15
      src/pagesYanyuan/family-info/family-info.vue
  7. 46
      src/pagesYanyuan/hold-all/hold-all.vue
  8. 10
      src/pagesYanyuan/wifi-binding/wifi-binding.vue

3
CHANGELOG.md

@ -1,4 +1,4 @@
# 0.1.0 (2021-12-31)
# 0.1.0 (2022-01-19)
### 🌟 新功能
范围|描述|commitId
@ -168,6 +168,7 @@
- | 修改角色栏组件 | [a54c601](http://101.201.226.163:3000/binbin0314/yanyuan_js/commits/a54c601)
- | 修改角色栏骨架屏 | [c18efb3](http://101.201.226.163:3000/binbin0314/yanyuan_js/commits/c18efb3)
- | 修改试题查询判断 | [4128f3d](http://101.201.226.163:3000/binbin0314/yanyuan_js/commits/4128f3d)
修改部分bug | 修改部分bug | [92bdab1](http://101.201.226.163:3000/binbin0314/yanyuan_js/commits/92bdab1)
- | 修改长者信息回显bug | [ef1b4bf](http://101.201.226.163:3000/binbin0314/yanyuan_js/commits/ef1b4bf)
- | 切换到默认项目角色没有激活状态的bug | [438d448](http://101.201.226.163:3000/binbin0314/yanyuan_js/commits/438d448)
- | 切换日历时查询小红点 | [7091789](http://101.201.226.163:3000/binbin0314/yanyuan_js/commits/7091789)

79
src/components/Wifi/Wifi.vue

@ -0,0 +1,79 @@
<template>
<view class="container">
<view class="page-body">
<view class="btn-area">
<u-button type="primary" @click="sendTCP">发送TCP</u-button>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return { tcp: null };
},
props: {
name: { type: String, default: '' },
password: { type: String, default: '' },
},
onUnload() {},
onLoad() {},
methods: {
sendTCP() {
console.log('发送');
if (!this.tcp) {
this.tcp = wx.createTCPSocket();
}
console.log('this.tcp', this.tcp);
this.tcp.connect({
address: '192.168.4.1',
port: 1001,
});
console.log('链接this.tcp', this.tcp);
this.tcp.write(`#${this.name}:${this.password}$`);
console.log('write-this.tcp', this.tcp);
this.tcp.onMessage((message, remoteInfo, localInfo) => {
console.log(message, remoteInfo, localInfo);
// tcp
// this.tcp = null;
if (message) {
this.tcp = null;
this.tcp.close();
this.$t.page.openPage('/pagesYanyuan/hold-all/hold-all');
}
});
},
},
};
</script>
<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.logo {
height: 200rpx;
width: 200rpx;
margin-top: 200rpx;
margin-left: auto;
margin-right: auto;
margin-bottom: 50rpx;
}
.text-area {
display: flex;
justify-content: center;
}
.title {
font-size: 36rpx;
color: #8f8f94;
}
</style>

2
src/mixins/tool.js

@ -153,6 +153,7 @@ export default {
* @param { array } keyUserIds 老人id
*/
async applyFamily() {
console.log('申请成为家属');
try {
let params = {};
if (this.applyFamilyInfo && this.applyFamilyInfo.name) {
@ -160,6 +161,7 @@ export default {
} else {
params = { keyUserIds: this.keyUserIds };
}
console.log('params', params);
await this.$u.api.applyFamily(params);
this.transferContent = '申请已提交,请等待审核';
this.$t.page.openPage(`/pagesYanyuan/transfer-page/transfer-page?type=jiashu&msg=${this.transferContent}`);

176
src/pagesProject/project/components/Evaluated/components/ProcessRestore - 副本.vue

@ -0,0 +1,176 @@
<template>
<view class="canvas-box w-full">
<canvas style="width: 100%; height: 450px" canvas-id="firstCanvas"></canvas>
</view>
</template>
<script>
export default {
props: { trainResult: { type: Object, default: () => {} } },
data() {
return {
canvas: null,
context: null,
points: [],
timers: [],
width: '',
};
},
mounted() {
this.$nextTick(() => {
const query = uni.createSelectorQuery().in(this);
query
.selectAll('.canvas-box')
.boundingClientRect(data => {
if (data && data.length) {
this.width = data[0].width;
this.clearTimers();
this.initCanvas();
this.drawImage(this.width);
}
})
.exec();
});
},
methods: {
//
clearTimers() {
if (this.timers.length) {
this.timers.forEach(item => {
item && clearTimeout(item);
});
this.timers = [];
}
},
// canvas ctx
initCanvas() {
this.canvas = this.$refs['reduceCanvas'];
this.context = uni.createCanvasContext('firstCanvas', this);
},
//
drawImage(width) {
const { context } = this;
const { cardUrl, lines } = this.trainResult;
let that = this;
uni.downloadFile({
url: cardUrl,
success: function (res) {
context.drawImage(res.tempFilePath, 0, 0, width, 450);
context.draw(true);
//
lines.forEach(item => {
that.drawPath(item, width);
});
},
fail(error) {
console.error('图片加载失败:', error);
},
});
},
/**
* 绘制路径
* 图片坐标是155,194
*/
drawPath(str, width) {
const data = this.generatePathData(str);
const ctx = this.context;
this.timers.push(
setTimeout(() => {
if (!this.trainResult.lines || this.trainResult.lines.length === 0) {
return;
}
ctx.beginPath();
ctx.setLineWidth(10);
ctx.setStrokeStyle('#1890ff');
const x = (+data[0][0] * width) / 155;
const y = (+data[0][1] * 450) / 194;
ctx.moveTo(x, y);
if (data.length === 1) {
// 1
ctx.arc(x, y, 2, 0, Math.PI * 2, false);
ctx.fill();
}
}, +data[0][2]),
);
for (let i = 1, len = data.length; i < len; i++) {
if (!this.trainResult.lines || this.trainResult.lines.length === 0) return;
this.timers.push(
setTimeout(() => {
if (!this.trainResult.lines || this.trainResult.lines.length === 0) {
return;
}
if (i > 1) {
this.clearAndDraw(data, i, width);
} else {
const x = (+data[i][0] * width) / 155;
const y = (+data[i][1] * 450) / 194;
ctx.lineTo(x, y);
ctx.stroke();
ctx.draw(true);
}
ctx.closePath();
// }, +data[i][2]),
}, this.getIntervalTime(+data[i][2], +str.operateTime, +data[0][2])),
);
}
},
clearAndDraw(data, i, width) {
if (!data || data.length < 1 || i >= data.length) return;
const ctx = this.context;
const x = (+data[0][0] * width) / 155;
const y = (+data[0][1] * 450) / 194;
ctx.moveTo(x, y);
for (let j = 1; j < i + 1; j++) {
const x = (+data[j][0] * width) / 155;
const y = (+data[j][1] * 450) / 194;
ctx.lineTo(x, y);
if (j === i) {
ctx.stroke();
ctx.draw(true);
}
}
},
/**
* 计算间隔时间
* 第一条线的操作时间
* 每条线的第一个点的时间
* 时间 = 当前线条的操作时间 - 第一条线的操作时间+ 当前点的时间-同一条线的第一个点的时间
*/
getIntervalTime(pointTime, operateTime, firstPointTime) {
const { lines } = this.trainResult;
let time = 0;
time = operateTime - lines[0].operateTime + (pointTime - firstPointTime);
return time;
},
/**
* 生成绘制每段路径的数据
* @param {string} str 每条路径的数据"x,y,time;x,y,time"
* @return {array} result [[x,y,time]]
*/
generatePathData(str) {
if (!str || !str.line) return;
let result = [];
str.line.split(';').forEach(point => {
result.push(point.split(','));
});
return result;
},
},
};
</script>
<style scoped lang="scss"></style>

29
src/pagesProject/project/components/Evaluated/components/ProcessRestore.vue

@ -55,7 +55,7 @@ export default {
//
drawImage(width) {
const { context } = this;
const { cardUrl, lines } = this.trainResult;
const { cardUrl, points } = this.trainResult;
let that = this;
uni.downloadFile({
@ -64,9 +64,10 @@ export default {
context.drawImage(res.tempFilePath, 0, 0, width, 450);
context.draw(true);
//
lines.forEach(item => {
that.drawPath(item, width);
});
// points.forEach(item => {
// that.drawPath(item, width);
// });
that.drawPath(points, width);
},
fail(error) {
console.error('图片加载失败:', error);
@ -84,7 +85,7 @@ export default {
this.timers.push(
setTimeout(() => {
if (!this.trainResult.lines || this.trainResult.lines.length === 0) {
if (!this.trainResult.points || this.trainResult.points.length === 0) {
return;
}
ctx.beginPath();
@ -102,10 +103,10 @@ export default {
);
for (let i = 1, len = data.length; i < len; i++) {
if (!this.trainResult.lines || this.trainResult.lines.length === 0) return;
if (!this.trainResult.points || this.trainResult.points.length === 0) return;
this.timers.push(
setTimeout(() => {
if (!this.trainResult.lines || this.trainResult.lines.length === 0) {
if (!this.trainResult.points || this.trainResult.points.length === 0) {
return;
}
@ -150,9 +151,9 @@ export default {
* 时间 = 当前线条的操作时间 - 第一条线的操作时间+ 当前点的时间-同一条线的第一个点的时间
*/
getIntervalTime(pointTime, operateTime, firstPointTime) {
const { lines } = this.trainResult;
const { points } = this.trainResult;
let time = 0;
time = operateTime - lines[0].operateTime + (pointTime - firstPointTime);
time = operateTime - points[0].operateTime + (pointTime - firstPointTime);
return time;
},
@ -162,10 +163,14 @@ export default {
* @return {array} result [[x,y,time]]
*/
generatePathData(str) {
if (!str || !str.line) return;
if (!str || !str.length) return;
let result = [];
str.line.split(';').forEach(point => {
result.push(point.split(','));
str.forEach(point => {
let arr = [];
for (let i in point) {
arr.push(point[i]);
}
result.push(arr);
});
return result;
},

15
src/pagesYanyuan/family-info/family-info.vue

@ -38,16 +38,17 @@ export default {
/**
* 申请成为家属
*/
submit() {
async submit() {
if (!this.validationRequired()) return;
this.params.keyUserIds = this.keyUserIds;
this.setApplyFamilyInfo(this.params);
this.$refs.uTips.show({
title: '用户信息添加成功, 即将申请成为家属',
type: 'success',
duration: '2000',
});
this.$t.page.openPage('/pagesYanyuan/transfer-page/transfer-page?type=jiashu');
await this.applyFamily();
// this.$refs.uTips.show({
// title: ', ',
// type: 'success',
// duration: '2000',
// });
// this.$t.page.openPage('/pagesYanyuan/transfer-page/transfer-page?type=jiashu');
},
//

46
src/pagesYanyuan/hold-all/hold-all.vue

@ -1,19 +1,21 @@
<template>
<view class="bg-white flex flex-col px-2">
<view class="flex flex-nowrap text-xs text-gray-400 my-2">
<view class="flex flex-nowrap mt-3">
<view class="flex-1"></view>
<u-button type="primary" text="添加WiFi" size="mini" :plain="true" @click="openBinding">添加WiFi</u-button>
</view>
<!-- <view class="flex flex-nowrap text-xs text-gray-400 my-2">
提示:
<view v-for="(tip, tipIndex) in tips" :key="tipIndex" class="flex flex-nowrap items-center ml-3">
<view class="w-2 h-2 rounded-full mr-1" :class="tip.bg"></view>
{{ tip.value }}
</view>
</view>
</view> -->
<view v-if="lists && lists.length">
<view v-for="item in lists" :key="item.toolId">
<view class="flex justify-between items-center py-3 border-b">
<view class="flex flex-row items-center">
<view
class="mr-2"
:class="
<!-- :class="
item.equipmentStatus === 0
? 'text-gray-500'
: item.equipmentStatus === 1
@ -21,13 +23,12 @@
: item.equipmentStatus === 2
? 'text-yellow-500'
: 'text-red-500'
"
>
" -->
<view class="mr-2">
{{ item.code }}
</view>
<view class="flex items-center text-gray-400" @click="getUserName(item.equipmentId)">
<u-icon
:class="
<!-- :class="
item.equipmentStatus === 0
? 'text-gray-500'
: item.equipmentStatus === 1
@ -35,16 +36,14 @@
: item.equipmentStatus === 2
? 'text-yellow-500'
: 'text-red-500'
"
name="error-circle"
size="36"
></u-icon>
" -->
<u-icon name="error-circle" size="36"></u-icon>
</view>
</view>
<view class="flex flex-nowrap items-center">
<view class="flex items-center text-gray-400">
<u-icon v-if="item.wifiStatus === 1" name="wifi" color="#1890FF" size="36"></u-icon>
<u-icon v-else @click="openBinding" name="wifi" color="#999999" size="36"></u-icon>
<u-icon v-else name="wifi" color="#999999" size="36"></u-icon>
</view>
<view class="battery-box ml-3">
<view class="battery-text u-font-10 font-light">{{ item.electricQuantity }}</view>
@ -94,15 +93,16 @@ export default {
methods: {
openBinding() {
uni.navigateToMiniProgram({
appId: 'wx1989853133e3da70',
path: '',
extraData: {},
success(res) {
//
console.log('打开成功res: ', res);
},
});
// uni.navigateToMiniProgram({
// appId: 'wx1989853133e3da70',
// path: '',
// extraData: {},
// success(res) {
// //
// console.log('res: ', res);
// },
// });
this.$t.page.openPage('/pagesYanyuan/wifi-binding/wifi-binding');
},
setWidth(res) {

10
src/pagesYanyuan/wifi-binding/wifi-binding.vue

@ -4,12 +4,16 @@
<u-icon name="wifi"></u-icon>
</view>
<view class="font-semibold mb-5 text-base">ccsens_5G</view>
<view class="bg-white w-full flex justify-between items-center py-2 px-3">
<text class="mr-3">WIFI名称</text>
<u-input v-model="name" placeholder="请输入" input-align="right" class="text-base" />
</view>
<view class="bg-white w-full flex justify-between items-center py-2 px-3">
<text class="mr-3">WIFI密码</text>
<u-input v-model="value" placeholder="请输入" input-align="right" class="text-base" />
<u-input v-model="password" placeholder="请输入" input-align="right" class="text-base" />
</view>
<view class="flex w-full px-3 pt-10">
<u-button type="primary" class="w-full">绑定</u-button>
<Wifi :name="name" :password="password" class="w-full" />
</view>
</view>
</template>
@ -17,7 +21,7 @@
<script>
export default {
data() {
return { value: '' };
return { name: 'ccsens_pen', password: '' };
},
};
</script>

Loading…
Cancel
Save