合并代码,增加权限

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" "vueVersion" : "2"
} }
/* ios *//* SDK *//* *//* */

View File

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