| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452 |
- <template>
- <view>
- <view class="status_bar"></view>
- <view class="" style="position: relative;top: 64px;">
- <view style="position: fixed;z-index: 10000000;width: 100%;background-color: #000000;">
- <uni-nav-bar @clickLeft="clickLeft" left-icon="back" left-text="返回" title="历史数据"></uni-nav-bar>
- </view>
- <view class="graph">
- <view class="canvasbox">
- <view class="canvastishi" v-if="!canvastishiTF">
- 暂无数据
- </view>
- <canvas v-if="canvastishiTF" canvas-id="canvasColumnA" id="canvasColumnA" class="charts" @touchstart="touchLineA($event)"
- @touchmove="moveLineA($event)" @touchend="touchEndLineA($event)" disable-scroll=true :style="{'width':cWidth*pixelRatio+'px','height':cHeight*pixelRatio+'px', 'transform': 'scale('+(1/pixelRatio)+')','margin-left':-cWidth*(pixelRatio-1)/2+'px','margin-top':-cHeight*(pixelRatio-1)/2+'px'}"></canvas>
- </view>
- <view class="selecttimes">
- <view class="newtimes">
- <view class="newtimes_state" @click="pickshow = !pickshow">
- <view class="oldtimes_left">
- <image :src="'http://static.yfpyx.com/bigdata_app'+'/image/prevention/841f87bfd8abb1b09610fa0789f9d8e.png'" mode=""></image>
- 开始时间:{{this.begintime|timeFormat()}}
- </view>
- <view class="oldtimes_left">
- <u-icon name="arrow-down"></u-icon>
- </view>
- <u-picker mode="time" v-model="pickshow" :params="params" @confirm="pickone"></u-picker>
- </view>
- <view class="newtimes_end" @click="picktwoshow = !picktwoshow">
- <view class="oldtimes_left">
- <image :src="'http://static.yfpyx.com/bigdata_app'+'/image/prevention/1acfe2751c01d3786cdc49b83d7e505.png'" mode=""></image>
- 结束时间:{{this.end|timeFormat()}}
- </view>
- <view class="oldtimes_left">
- <u-icon name="arrow-down"></u-icon>
- </view>
- <u-picker mode="time" v-model="picktwoshow" :params="params" @confirm="picktwo"></u-picker>
- </view>
- <p class="tishi" v-if="tishiTF">请选择正确的结束时间</p>
- <view class="btnser" @click="serter">
- 搜 索
- </view>
- </view>
- </view>
- <view class="condition">
- <scroll-view scroll-top="0" scroll-x="true" class="scroll-X">
- <!-- @scrolltoupper="upper" @scrolltolower="lower" @scroll="scroll" -->
- <table class="table">
- <tr class="tr">
- <th class="th">日期</th>
- <th class="th" v-for="key,index in historydatas.conf" :key="'a'+index" v-if="key">{{key.replace("#","(")+")"}}</th>
- </tr>
- <tr class="tr" v-for="(items,index) in historydatas.data" :key="'b'+index" v-if="!forbidden">
- <td class="td">{{items.time|timeFormat()}}</td>
- <td class="td" v-for="keys in items.dat" v-if="keys">{{parseFloat(keys)==-99.99?"N/A":parseFloat(keys)}}</td>
- </tr>
- <tr class="tr" v-if="forbidden">
- <td class="td" v-for="item in 10">暂无数据</td>
- </tr>
- </table>
- </scroll-view>
- <view class="pagenumber">
- <button @click="prev">上一页</button>
- <view class="pagenumber_page">
- 第{{page}}页
- </view>
- <view class="pagenumber_page">
- 共 {{pagesum}} 页
- </view>
- <button @click="next" :disabled="forbidden">下一页</button>
- </view>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- import uCharts from '../../components/js_sdk/u-charts/u-charts/u-charts.js';
- var canvasColumnA = null;
- var presenttime = +new Date();
- export default {
- data() {
- return {
- cWidth: '400',
- cHeight: '400',
- pixelRatio: 1,
- canvastishiTF: false,
- id: "",
- begintime: '', //开始时间
- end: '', //结束时间
- titletext: ["24小时", "近一个月", "近半年", "近一年"],
- titleidnex: 0,
- pickshow: false, //选择时间一
- picktwoshow: false, //选择时间二
- params: { //时间格式
- year: true,
- month: true,
- day: true,
- hour: true,
- minute: true,
- second: false
- },
- tishiTF: false, //提示
- historydatas: [],
- page: 1,
- forbidden: false,
- pagesum: null
- }
- },
- methods: { //weather.weather.qxz_detail
- async listhistorydata(datas) { //上传时间
- const res = await this.$myRequest({
- url: '/api/api_gateway?method=weather.weather.qxz_detail',
- data: {
- device_id: datas,
- begin: parseInt(this.begintime),
- end: parseInt(this.end),
- page: this.page
- }
- })
- this.historydatas = res
- console.log(res)
- this.pagesum = Math.ceil(res.nums / 10) + 1
- if (res.data.length == 0) {
- this.forbidden = true
- } else {
- this.forbidden = false
- }
- },
- async historydata(datas) { //上传时间 //折线图
- const res = await this.$myRequest({
- url: '/api/api_gateway?method=weather.weather.qxz_data_chart',
- data: {
- device_id: datas,
- begin: parseInt(this.begintime),
- end: parseInt(this.end)
- }
- })
- console.log(res)
- if (res.data.length == 0) {
- this.canvastishiTF = false
- } else {
- this.canvastishiTF = true
- var xtitle = []
- var linearr = []
- for (var i = 0; i < res.data.length; i++) {
- var times = new Date(res.data[i].time * 1000)
- xtitle.unshift(times.getMonth() + 1 + "/" + times.getDate() + "-" + times.getHours() + ":" + times.getMinutes())
- }
- for (var key in res.conf) {
- var obj = {}
- if (res.conf[key] != "") {
- obj.name = res.conf[key]
- }
- var arr = []
- for (var i = 0; i < res.data.length; i++) {
- if (parseFloat(res.data[i].dat[key]) != -99.99) {
- arr.push(parseFloat(res.data[i].dat[key]))
- }
- }
- obj.data = arr
- if (obj.name) {
- linearr.push(obj)
- }
- }
- this.canvastishiTF = linearr.some((item) => {
- return item.data.length != 0;
- })
- console.log(this.canvastishiTF)
- this.showColumn("canvasColumnA", xtitle, linearr)
- }
- },
- pickone(e) { //开始时间
- this.begintime = +new Date(e.year, e.month - 1, e.day, e.hour, e.minute) / 1000
- if (this.newtime < this.oldtime) {
- this.tishiTF = true
- } else {
- this.tishiTF = false
- }
- },
- picktwo(e) { //结束时间
- this.end = +new Date(e.year, e.month - 1, e.day, e.hour, e.minute) / 1000
- if (this.newtime < this.oldtime) {
- this.tishiTF = true
- } else {
- this.tishiTF = false
- }
- },
- serter() {
- if (this.tishiTF == false) {
- this.historydata(this.id)
- this.listhistorydata(this.id)
- uni.showToast({
- title: '搜索成功',
- duration: 2000
- });
- }
-
- },
- prev() { //上一页
- if (this.page > 1) {
- this.page--
- this.listhistorydata(this.id)
- }
- },
- next() { //下一页
- this.page++
- this.listhistorydata(this.id)
- },
- clickLeft() {
- uni.navigateBack({
- delta: 1
- })
- },
- showColumn(id, xtitle, xinfo) {
- var _self = this
- canvasColumnA = new uCharts({
- canvasId: id,
- type: 'line',
- legend: {
- position: "top"
- },
- fontSize: 11,
- background: '#FFFFFF',
- pixelRatio: 1,
- animation: true,
- dataLabel: false,
- categories: xtitle,
- series: xinfo,
- enableScroll: true, //开启图表拖拽功能
- xAxis: {
- disableGrid: true,
- type: 'grid',
- gridType: 'dash',
- itemCount: 4, //x轴单屏显示数据的数量,默认为5个
- scrollShow: true, //新增是否显示滚动条,默认false
- // scrollAlign: 'left', //滚动条初始位置
- scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
- scrollColor: '#DEE7F7', //默认为 #A6A6A6
- },
- yAxis: {},
- width: _self.cWidth * 1,
- height: _self.cHeight * 1,
- extra: {
- line: {
- type: 'curve'
- }
- }
- });
- },
- touchLineA(e) {
- canvasColumnA.scrollStart(e);
- },
- moveLineA(e) {
- canvasColumnA.scroll(e);
- },
- touchEndLineA(e) {
- canvasColumnA.scrollEnd(e);
- //下面是toolTip事件,如果滚动后不需要显示,可不填写
- canvasColumnA.showToolTip(e, {
- format: function(item, category) {
- return category + ' ' + item.name + ':' + item.data
- }
- });
- },
- },
- onLoad(option) {
- this.cWidth = uni.upx2px(650);
- this.cHeight = uni.upx2px(500);
- this.id = option.device_id
- this.end = presenttime / 1000
- this.begintime = presenttime / 1000 - 24 * 60 * 60
- console.log(new Date(1616145097 * 1000), new Date(1616231497 * 1000))
- this.historydata(option.device_id)
- this.listhistorydata(option.device_id)
- }
- }
- </script>
- <style lang="scss">
- .graph {
- position: absolute;
- top: 54px;
- width: 90%;
- left: 5%;
- .canvasbox {
- width: 100%;
- height: 550rpx;
- position: relative;
- box-shadow: 0 0 10rpx #bcb9ca;
- .charts{
- }
- .canvastishi {
- font-size: 32rpx;
- position: absolute;
- top: 50%;
- left: 50%;
- margin-left: -64rpx;
- margin-top: -21rpx;
- }
- }
- .none_hint {
- font-size: 32rpx;
- font-weight: 700;
- position: absolute;
- top: 0;
- left: 50%;
- margin-left: -64rpx;
- }
- }
- .shuju_one_title {
- width: 70%;
- margin: 0 auto;
- display: flex;
- .tltle_text {
- width: 25%;
- border: 2rpx solid #B2B2B2;
- color: #B2B2B2;
- text-align: center;
- font-size: 24rpx;
- height: 50rpx;
- line-height: 50rpx;
- }
- .title_text_color {
- width: 25%;
- border: 2rpx solid #28AE4F;
- color: #28AE4F;
- text-align: center;
- font-size: 24rpx;
- height: 50rpx;
- line-height: 50rpx;
- }
- }
- .selecttimes {
- width: 100%;
- box-shadow: 0 0 10rpx #bcb9ca;
- margin-top: 20rpx;
- .tishi {
- width: 90%;
- margin: 0 auto;
- color: #f00000;
- text-align: center;
- font-size: 24rpx;
- }
- .btnser {
- width: 90%;
- margin: 10rpx auto;
- color: #FFFFFF;
- text-align: center;
- font-size: 28rpx;
- background-color: #58BD4D;
- border-radius: 20rpx;
- height: 50rpx;
- line-height: 50rpx;
- }
- .newtimes {
- width: 100%;
- padding: 20rpx 20rpx;
- box-sizing: border-box;
- .newtimes_state,
- .newtimes_end {
- display: flex;
- justify-content: space-between;
- margin-bottom: 20rpx;
- .oldtimes_left {
- position: relative;
- padding-left: 36rpx;
- font-size: 28rpx;
- image {
- width: 30rpx;
- height: 30rpx;
- vertical-align: top;
- position: absolute;
- top: 7rpx;
- left: 0;
- }
- }
- }
- }
- }
- .condition {
- display: flex;
- flex-wrap: wrap;
- width: 100%;
- box-shadow: 0 0 10rpx #bcb9ca;
- margin: 30rpx 0;
- .scroll-X {
- width: 95%;
- margin: 20rpx auto;
- .table{
- width: 1042px;
- }
- .tr {
- display: flex;
- overflow: hidden;
- .th,
- .td {
- display: inline-block;
- padding: 5rpx;
- width: 240rpx;
- text-align: center;
- height: 52rpx;
- line-height: 52rpx;
- border: 2rpx solid #F1F1F1;
- }
- .th:first-child,
- .td:first-child {
- width: 300rpx;
- }
- }
- }
- .pagenumber {
- display: flex;
- margin: 20rpx auto;
- button {
- width: 150rpx;
- height: 50rpx;
- line-height: 50rpx;
- font-size: 26rpx;
- text-align: center;
- background-color: #17BB89;
- color: #FFFFFF;
- }
- .pagenumber_page {
- width: 150rpx;
- height: 50rpx;
- line-height: 50rpx;
- font-size: 26rpx;
- text-align: center;
- }
- }
- }
- </style>
|