EWG01PDemo/pages/records/records.vue
2025-01-17 13:55:44 +08:00

189 lines
4.7 KiB
Vue

<template>
<view>
<uni-list>
<uni-card :isFull="true" v-for="item in records" :key="item.id">
<!-- <uni-row>
<uni-col>
<view>{{item.device_name}} - {{item.check_point}}</view>
</uni-col>
</uni-row> -->
<uni-row>
<uni-col :span="22">
<view>速度: {{item.velocity}} mm/s</view>
</uni-col>
<uni-col :span="2">
<uni-icons fontFamily="iconfont" :size="20" @click="waveChart(item.id)">{{'\ue644'}}</uni-icons>
</uni-col>
</uni-row>
<uni-row>
<uni-col>
<view>加速度: {{item.acceleration}} m/s<sup>2</sup></view>
</uni-col>
</uni-row>
<uni-row>
<uni-col>
<view>位移: {{item.displacement}} &micro;m</view>
</uni-col>
</uni-row>
<uni-row>
<uni-col>
<view>温度: {{item.temperature}} &deg;C</view>
</uni-col>
</uni-row>
<uni-row>
<uni-col :span="22">
<view>测量时间: {{item.operate_time}}</view>
</uni-col>
<uni-col :span="2">
<uni-icons type="trash" size="18" :size="26" @click="remove(item.id)"></uni-icons>
</uni-col>
</uni-row>
</uni-card>
</uni-list>
</view>
</template>
<script lang="ts">
import Vue from 'vue';
import db from '@/service/db';
const select = 'select * from records order by operate_time desc';
let page = 1;
export default Vue.extend({
data() {
return {
records: <any>[]
};
},
async onLoad() {
this.load();
},
onPullDownRefresh() {
this.load();
uni.stopPullDownRefresh();
},
onReachBottom() {
this.loadNext();
},
methods: {
async load() {
page = 1;
this.records = await db.selectPage(select, page);
},
async loadNext() {
page++;
const nextPage = await db.selectPage(select, page);
this.records.push(...nextPage);
},
remove(id: number) {
uni.showModal({
title: '确认操作',
icon: 'info',
content: '确定要删除吗?',
success: (res) => {
if (res.confirm) {
db.deleteTableData('records', 'id', id).then(
() => {
this.load();
uni.showToast({
title: '删除成功',
icon: 'success',
mask: true
});
},
(e) => {
uni.showModal({
title: '删除失败',
icon: 'error',
showCancel: false,
content: JSON.stringify(e)
})
}
);
} else if (res.cancel) {
console.log('用户点击取消');
}
}
})
db.deleteTableData('records', 'id', id);
},
// toChart(){
// uni.navigateTo({
// url: './chart'
// });
// },
waveChart(id: number){
uni.navigateTo({
url: `./wave_chart?id=${id}`
});
},
exportData() {
// plus.io.resolveLocalFileSystemURL("_doc/shuto.db", function(entry) {
// console.log(`${entry.fullPath} : ${entry.isFile}`);
// plus.android.requestPermissions(["android.permission.READ_EXTERNAL_STORAGE", "android.permission.WRITE_EXTERNAL_STORAGE"], (i) => {
// console.log('permission granted: ' + i);
// plus.io.resolveLocalFileSystemURL("_downloads", function(destEntry) {
// console.log(`${destEntry.fullPath} : ${destEntry.isFile}`);
// entry.copyTo(destEntry, "shuto_backup.db", result => {
// console.log(`${result.fullPath} : ${result.isFile}`);
// }, e => {
// console.error(e);
// });
// })
// }, (e) => {
// console.error('prmission grant error: ' + e);
// });
// }
// );
plus.io.resolveLocalFileSystemURL("_doc/shuto.db", function(entry) {
uni.showLoading({ title: '上传中...' });
uni.uploadFile({
url: 'http://8.214.43.244:38899/upload', //仅为示例,非真实的接口地址
filePath: entry.fullPath,
name: 'file',
formData: {
'device': uni.getDeviceInfo().deviceId
},
success: (uploadFileRes) => {
console.log(uploadFileRes.data);
uni.hideLoading();
uni.showToast({
title: '上传成功',
icon: 'success',
mask: true
});
},
fail: (e) => {
console.log(JSON.stringify(e));
uni.hideLoading();
uni.showModal({
title: '错误信息',
showCancel: false,
content: '上传失败'
})
},
complete: () => {
uni.hideLoading();
}
});
// uploadTask.onProgressUpdate((res) => {
// console.log('上传进度' + res.progress);
// console.log('已经上传的数据长度' + res.totalBytesSent);
// console.log('预期需要上传的数据总长度' + res.totalBytesExpectedToSend);
// uni.showLoading({ title: '上传中... ' + res.progress });
// });
});
}
}
});
</script>
<style>
</style>