633 lines
14 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<!-- 已废弃 -->
<view class="qualitySpringback">
<headers :showBack="true">
<view class="headerName">
回弹仪
</view>
</headers>
<view class="content">
<view class="chart_wrap">
<view class="title" style="color: #488DEC;">·测量情况·</view>
<view class="flex">
<view class="chart">
<image class="chart_img" src="/static/measure1.png"></image>
<view class="chart_text">
<view class="value">{{totalSurveyNum}}</view>
<view class="name">全部测量<br />构件</view>
</view>
</view>
<view class="chart">
<image class="chart_img" src="/static/measure2.png" style="height: 257rpx;"></image>
<view class="chart_text">
<view class="value">{{abnormalSurveyNum}}</view>
<view class="name">不合格<br />构件</view>
</view>
</view>
</view>
</view>
<view class="title">
<text style="color: #2A2B5B; opacity: 0.4;">·设备列表·</text>
<button type="primary" plain @click="initBluetoothAdapter()" size="mini" class="searchBluetooth">
<icon v-show="!isSearching" class="searchIcon" color="#007aff" type="search" size="15" />
<loadingGig v-show="isSearching"></loadingGig>
<!-- <image src="/static/loading.png" class="loadingIcon"></image> -->
{{isSearching?'搜索蓝牙中':'搜索蓝牙'}}
</button>
</view>
<!-- <input type="text" v-model="sendData" placeholder="" style="border:1px solid red;padding: 10rpx 20rpx;margin-bottom: 20rpx;" />
<button type="default" @click="send()">发送数据</button> -->
<view class="listItem"
:class="(bleDeviceId==item.deviceId&&isLinkFinished=='连接成功')?'linkFinishedItem':'value'"
v-for="(item,index) in bluetooth" @click="conn(item)" :key="index">
<view class="item_name">蓝牙编码<text class="value">{{item.name?item.name:item.deviceId}}</text></view>
<view class="item_name">信号强度<text class="value">{{item.RSSI}}</text></view>
<!-- <view class="item_name">边接状态<text class="value">{{isLink[index]==0?'未连接':isLink[index]==1?'连接中...':isLink[index]==2?'连接成功':
isLink[index]==3?'连接失败':isLink[index]==4?'已断开':''
}}</text></view> -->
<view class="item_name">连接状态<text
:class="bleDeviceId==item.deviceId?'primaryText':'value'">{{bleDeviceId==item.deviceId?isLinkFinished:'未连接'}}</text>
</view>
<view class="animateBox" v-show="bleDeviceId==item.deviceId&&isLinkFinished=='连接中...'">
</view>
</view>
<view class="placeholderBox" v-if="bluetooth.length==0">
<image class="noDataImg" src="/static/noData.png"></image>
<view class="text">暂未搜到蓝牙设备</view>
</view>
<view class="start_wrap">
<view class="start_btn" @click="measureBtn">开始测量</view>
</view>
</view>
<view class="tabBarBox">
<view class="item active">
<image src="/static/personManage/index.png" class="img"></image>
<view class="txt">
首页
</view>
</view>
<view class="item" @click="goHasMeasure">
<image src="/static/personManage/location.png" class="img"></image>
<view class="txt">
已测量
</view>
</view>
<view class="item" @click="queryStaff">
<image src="/static/personManage/search.png" class="img"></image>
<view class="txt">
浇筑令
</view>
</view>
</view>
</view>
</view>
</template>
<script>
var times = 0
const app = getApp()
import {
getBlooth,
createBLE,
DeviceFound
} from '@/static/js/BLEConn.js';
import loadingGig from "@/components/loadingGig.vue"
export default {
components: {
loadingGig
},
data() {
return {
projectDetail: '',
bluetooth: [],
isLink: [],
totalSurveyNum: 0,
abnormalSurveyNum: 0,
sendData: '24535253F8230D0A',
bleDeviceId: '',
bleName: '',
isLinkFinished: '未连接', // 未连接 连接中... 连接成功 连接失败
isSearching: false,
}
},
onLoad() {
//24535253F8230D0A 正在回弹采集命令
//2445525396230D0A 停止回弹采集命令
//24524449DF230D0A 获取设备信息命令
this.projectDetail = JSON.parse(uni.getStorageSync('projectDetail'));
this.getDevTotal();
this.initBluetoothAdapter()
// this.bluetooth=[
// {
// name:'aaaa',deviceId:'11111111',RSSI:'12'
// }
// ]
},
methods: {
//初始化蓝牙模块
initBluetoothAdapter() {
let self = this
uni.openBluetoothAdapter({
success: function(res) {
// console.log('search.js[onLoad]: openBluetoothAdapter success')
app.globalData.BluetoothState = true
self.startSearchDevs() // 搜索附近蓝牙
},
fail: function(err) {
// console.log('search.js[onLoad]: openBluetoothAdapter fail')
if (err.errCode === 10001) { // 手机蓝牙未开启
app.globalData.BluetoothState = false
uni.showModal({
title: '提示',
content: '请开启手机蓝牙',
showCancel: false
})
} else {
console.log(err.errMsg)
}
}
})
},
startSearchDevs(){
this.isSearching=true
let self=this
uni.startBluetoothDevicesDiscovery({
allowDuplicatesKey: false,
success(res) {
console.log(res, 'startBluetoothDevicesDiscovery')
uni.onBluetoothDeviceFound(function(devices) {
console.log(devices, '搜索到蓝牙设备')
self.isSearching=false
var isExist = false
if (devices.deviceId) {
for (let item of self.bluetooth) {
if (item.deviceId === devices.deviceId) {
isExist = true
break;
}
}
!isExist
if(devices.name){
self.bluetooth.push(devices)
}
}
else if (devices.devices) {
for (let item of self.bluetooth) {
if (item.deviceId === devices.devices[0].deviceId) {
isExist = true
break;
}
}
!isExist
if(devices.devices[0].name){
self.bluetooth.push(devices.devices[0])
}
}
else if (devices[0]) {
for (let item of self.bluetooth) {
if (item.deviceId === devices[0].deviceId) {
isExist = true
break;
}
}
!isExist
if(devices[0].name){
self.bluetooth.push(devices[0])
}
// self.setData({
// devs: self.bluetooth
// })
}
})
},
fail(err) {
console.log('startBluetoothDevicesDiscovery',err)
}
})
},
addDevice(devName, devNo) {
this.sendRequest({
url: 'xmgl/massReboundMeasureDev/add',
method: 'post',
hideLoading: 'true',
data: {
projectSn: this.projectDetail.projectSn,
devName: devName,
devNo: devNo
},
success: (res) => {
}
})
},
async closeDevConnect(id) {
if (this.bleDeviceId) {
let that = this
uni.closeBLEConnection({
deviceId: this.bleDeviceId,
success(res) {
console.log('断开上一个连接的蓝牙')
that.bleDeviceId = ''
that.bleName = ''
that.isLinkFinished = '未连接'
}
})
}
},
// 2. 选中蓝牙并连接
async conn(item) {
// console.log(item)
// uni.showLoading({
// title: "正在连接...",
// icon: "loading",
// mask: true
// })
// await this.closeDevConnect(item.deviceId)
if (this.bleDeviceId) {
let that = this
// that.closeBle().then(res => {
// // this.closeDiv = false
// // this.clear()
// // uni.hideLoading()
// console.log('断开蓝牙成功')
// }).catch(err => {
// // uni.hideLoading()
// console.log('断开蓝牙失败')
// })
// return new Promise((resolve, reject) => {
uni.closeBLEConnection({
deviceId: this.bleDeviceId,
success(res) {
console.log('断开上一个连接的蓝牙')
if (that.bleDeviceId == item.deviceId && (that.isLinkFinished == '连接成功')) {
that.bleDeviceId = ''
that.bleName = ''
that.isLinkFinished = '未连接'
uni.showToast({
title: '已断开连接'
})
}
}
})
// })
if (this.bleDeviceId == item.deviceId && (that.isLinkFinished != '连接失败')) {
console.log('停止接下来的操作')
return false
}
}
// console.log('执行完closeDevConnect')
this.bleDeviceId = item.deviceId
this.bleName = item.name
this.isLinkFinished = '连接中...'
// connBLESuc++
let create = true // 判断有没有进入createBLE
// '49535343-FE7D-4AE5-8FA9-9FAFD205E455'
await createBLE(item, '00001800-0000-1000-8000-00805F9B34FB').then(res => {
console.log('createBLE ' + res)
create = false
this.isLinkFinished = '连接成功'
this.addDevice(item.name, item.deviceId)
}).catch(err => {
// uni.hideLoading()
// setTimeout(() => {
// uni.showToast({
// title: '连接失败'
// })
// }, 500)
this.isLinkFinished = '连接失败'
create = false
// console.log('失败' + connBLESuc, err)
// if (connBLESuc <= 3) {
// this.conn(item)
// uni.showLoading({
// title: this.other.reconnection,
// // title: "重连中...",
// icon: "loading",
// mask: true
// })
// } else {
// uni.hideLoading()
// connBLESuc = 0
// setTimeout(() => {
// uni.showToast({
// title: this.other.fail,
// // title: "连接失败",
// icon: "none"
// })
// }, 500)
// }
})
setTimeout(() => {
if (create) {
console.log('没有进入回调')
this.isLinkFinished = '连接失败'
// uni.hideLoading()
// setTimeout(() => {
// uni.showToast({
// // title: this.other.fail,
// title: "连接失败",
// icon: "none"
// })
// }, 500)
}
}, 3000)
},
getDevTotal() {
let that = this;
this.sendRequest({
url: 'xmgl/massReboundSurveyArea/selectProjectCount',
method: 'post',
data: {
projectSn: that.projectDetail.projectSn
},
success: res => {
that.totalSurveyNum = res.result.totalSurveyNum;
that.abnormalSurveyNum = res.result.abnormalSurveyNum;
}
})
},
measureBtn() {
if (this.isLinkFinished != '连接成功') {
uni.showToast({
title: '请先连接蓝牙'
})
} else {
uni.navigateTo({
url: './selectPage?isAdd=true'
});
}
},
goHasMeasure() {
uni.navigateTo({
url: './selectPage?isAdd=false'
});
},
queryStaff() {
uni.navigateTo({
url: './pouringOrderManage'
});
}
}
}
</script>
<style scoped lang="scss">
.flex {
display: flex;
align-items: center;
justify-content: space-around;
}
.flex2 {
display: flex;
align-items: center;
}
.flex3 {
display: flex;
align-items: center;
justify-content: space-between;
}
.title {
text-align: center;
font-size: 30rpx;
letter-spacing: 1.4px;
line-height: 21px;
margin-bottom: 16rpx;
position: relative;
}
.content {
padding: 20rpx 30rpx 64rpx;
box-sizing: border-box;
width: 100%;
}
.chart_wrap {
width: 100%;
box-shadow: 0 4rpx 20rpx 0 rgba(212, 220, 236, 0.65);
border-radius: 16rpx;
background-color: rgba(251, 251, 255, 1);
box-sizing: border-box;
padding: 20rpx 0 40rpx;
margin-top: 20rpx;
margin-bottom: 40rpx;
}
.chart {
position: relative;
width: 266rpx;
height: 269rpx;
}
.chart_img {
width: 266rpx;
height: 269rpx;
position: absolute;
top: 0;
right: 0;
left: 0;
bottom: 0;
z-index: 2;
}
.chart_text {
z-index: 999;
text-align: center;
position: relative;
top: 50%;
/*偏移*/
margin-top: -38px;
}
.chart_text .value {
font-size: 60rpx;
font-weight: 700;
}
.chart_text .name {
color: #54547C;
font-size: 30rpx;
line-height: 36rpx;
}
.listItem {
line-height: 52rpx;
margin-top: 30rpx;
box-shadow: 0 4rpx 20rpx 0 rgba(212, 220, 236, 0.65);
border-radius: 10rpx;
padding: 20rpx 30rpx;
font-size: 28rpx;
position: relative;
}
.linkFinishedItem {
background-color: rgba(219, 231, 243, 0.2);
}
.animateBox {
position: absolute;
left: 0;
top: 5%;
width: 80px;
height: 90%;
background: linear-gradient(to right, rgba(219, 231, 243, 0.2), rgba(219, 231, 243, 0.8), #dbe7f3);
filter: blur(4px);
animation: mymove 1s infinite;
}
@keyframes mymove {
from {
left: 0px;
}
to {
left: 80%;
}
}
@-webkit-keyframes mymove
/*Safari and Chrome*/
{
from {
left: 0px;
}
to {
left: 80%;
}
}
.item_name {
color: rgba(42, 43, 91, 0.6);
}
.item .value {
color: #2A2B5B;
}
.item .active {
color: $uni-color-primary;
}
.start_wrap {
margin-top: 80rpx;
margin-bottom: 80rpx;
}
.start_btn {
text-align: center;
pos-bottom: 40rpx;
line-height: 90rpx;
width: 60%;
margin: 0 auto;
background-color: rgba(72, 141, 236, 1);
color: #fff;
border-radius: 70rpx;
box-shadow: 0 4rpx 4px 0 rgba(43, 141, 243, 0.42);
}
.start_btn:active {
background-color: rgba(65, 129, 254, 0.8);
}
.searchBluetooth {
position: absolute;
right: 0px;
top: -10rpx;
padding: 0 16rpx;
}
.tabBarBox {
display: flex;
align-items: center;
font-size: 24rpx;
border-top: 1px solid rgba(151, 151, 151, 0.2);
position: fixed;
bottom: 0;
left: 0;
width: 100%;
height: 64rpx;
background-color: white;
z-index: 22;
.item {
flex: 1;
// display: inline-flex;
text-align: center;
color: rgba(148, 149, 173, 1);
.img {
width: 70rpx;
height: 70rpx;
}
&.active {
color: rgba(72, 141, 236, 1);
}
}
}
.placeholderBox {
margin: 100rpx auto;
}
.searchIcon {
vertical-align: middle;
margin-right: 6rpx;
}
.loadingIcon {
width: 30rpx;
height: 30rpx;
vertical-align: middle;
margin-right: 6rpx;
animation: mymove2 0.5s infinite;
}
@keyframes mymove2 {
from {
transform: rotate(0deg);
}
to {
transform: rotate(180deg);
}
}
@-webkit-keyframes mymove2
/*Safari and Chrome*/
{
from {
transform: rotate(0deg);
}
to {
transform: rotate(180deg);
}
}
</style>