合并代码,增加权限

This commit is contained in:
万昕放 2025-03-11 10:21:14 +08:00
commit 9eacc3b59c
2 changed files with 52 additions and 27 deletions

View File

@ -136,3 +136,5 @@
},
"vueVersion" : "2"
}
/* ios *//* SDK *//* *//* */

View File

@ -13,7 +13,8 @@
<text class="title" v-if="power>0" style="padding-left: 5px;">电量:{{power}}</text>
</uni-col>
<uni-col :span="4">
<button @click="toggleConnect()" type="primary" :plain="connected" :disabled="deviceId == ''" size="mini">
<button @click="toggleConnect()" type="primary" :plain="connected" :disabled="deviceId == ''"
size="mini">
{{connected ? '断开' : '连接'}}
</button>
</uni-col>
@ -36,7 +37,7 @@
</uni-data-select> -->
<uni-row>
<uni-col :span="12">
<button @click="collectVib()" type="primary" :disabled="!connected || processing">测振</button>
<button @click="collectVib()" type="primary" :disabled="!connected || processing">测振</button>
</uni-col>
<uni-col :span="12">
<view class="padding">
@ -123,7 +124,10 @@
<script>
import Vue from 'vue';
import db from '@/service/db';
import {devices, checkPoints} from '@/service/common';
import {
devices,
checkPoints
} from '@/service/common';
import * as echarts from '@/uni_modules/lime-echart/static/echarts.min';
const Ewg = uni.requireNativePlugin('UniCollectionUtils');
@ -139,6 +143,7 @@
const _now = formatTime(new Date());
return _now;
}
function formatTime(d, fmt = 'yyyy-MM-dd hh:mm:ss') {
const opt = {
'y+': d.getFullYear().toString(), //
@ -155,7 +160,8 @@
if (/(y+)/.test(k)) {
dateString = dateString.replace(ret[1], opt[k].substring(4 - ret[1].length))
} else {
dateString = dateString.replace(ret[1], (ret[1].length === 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, '0')))
dateString = dateString.replace(ret[1], (ret[1].length === 1) ? (opt[k]) : (opt[k].padStart(ret[1]
.length, '0')))
}
}
}
@ -202,19 +208,25 @@
}
});
plus.android.requestPermissions(["android.permission.ACCESS_FINE_LOCATION"], (i) => {
console.log('permission granted: ' + i);
console.log(i);
}, (e) => {
console.error('prmission grant error: ' + e);
console.error(e);
});
plus.android.requestPermissions(["android.permission.BLUETOOTH_CONNECT"], (i) => {
console.log(i);
}, (e) => {
console.error(e);
});
plus.android.requestPermissions(["android.permission.BLUETOOTH_CONNECT"]);
plus.android.requestPermissions(["android.permission.BLUETOOTH_SCAN"]);
// initBL();
},
onUnload() {
},
onUnload() {},
methods: {
toggleConnect() {
uni.showLoading({ title: '加载中' });
uni.showLoading({
title: '加载中'
});
if (this.connected) {
Ewg.disConnect(this.deviceId, (res) => {
console.log("断开设备", JSON.stringify((res)));
@ -222,8 +234,7 @@
this.connected = false;
uni.hideLoading();
});
}
else {
} else {
Ewg.connect(this.deviceId, (res) => {
console.log("连接设备", JSON.stringify((res)))
this.msg = '设备已连接';
@ -234,7 +245,9 @@
},
collectTemp() {
this.msg = '正在测温';
uni.showLoading({ title: this.msg });
uni.showLoading({
title: this.msg
});
this.processing = true;
this.r.temperature = null;
Ewg.collectTemp("0.95", (res) => {
@ -246,8 +259,7 @@
this.power = res.battery;
this.msg = `温度结果:${JSON.stringify((res))}`;
this.saved = false;
}
else {
} else {
this.r.temperature = null;
this.power = -1;
this.msg = `测温异常:${JSON.stringify((res))}`;
@ -258,7 +270,9 @@
collectVib() {
this.msg = '正在测振';
this.openPop();
uni.showLoading({ title: this.msg });
uni.showLoading({
title: this.msg
});
// TODO:
this.processing = true;
this.r.velocity = null;
@ -284,8 +298,7 @@
// this.power = res.battery;
// this.msg = ``;
// this.saved = false;
}
else {
} else {
this.r.velocity = null;
this.r.acceleration = null;
this.r.displacement = null;
@ -311,8 +324,7 @@
if (did?.startsWith('expert-')) {
this.deviceId = did.substring('expert-'.length);
uni.setStorageSync('deviceId', this.deviceId);
}
else {
} else {
this.msg = `error device: ${did}`;
}
}
@ -359,7 +371,7 @@
this.$refs.popup.open();
},
async initChart() {
this.$refs.wChart.init(echarts,
this.$refs.wChart.init(echarts,
chart => chart.setOption({
// grid: {
// left: 40,
@ -374,7 +386,7 @@
show: true
},
axisLabel: {
formatter: function (value, index) {
formatter: function(value, index) {
return Math.round(value * 10) / 10;
},
// showMaxLabel: true,
@ -405,15 +417,16 @@
name: '速度',
yAxisIndex: 0,
}]
}),
{ locale: "ZH" },
}), {
locale: "ZH"
},
);
uni.onWindowResize(res => {
this.$refs.wChart?.resize();
});
},
closePop() {
this.$refs.popup.close();
this.$refs.popup.close();
},
saveCheck() {
this.r.acceleration = vibData.acceleration;
@ -437,7 +450,14 @@
for (let i = 0; i < point; i++) {
times.push(i * timespace);
}
this.$refs.wChart.setOption({xAxis: {data: times}, series: [{data: wave}]});
this.$refs.wChart.setOption({
xAxis: {
data: times
},
series: [{
data: wave
}]
});
}
}
});
@ -469,14 +489,17 @@
padding: 20px;
background-color: #fff;
}
.title {
font-size: 16px;
}
.chart-pop {
width: 100vw;
}
.center {
display:flex;
justify-content:center;
display: flex;
justify-content: center;
}
</style>