gshistory.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. <template>
  2. <view>
  3. <view class="status_bar"></view>
  4. <view class="" style="position: relative;top: 40px;">
  5. <view style="position: fixed;z-index: 10000000;width: 100%;background-color: #000000;">
  6. <uni-nav-bar @clickLeft="clickLeft" left-icon="back" left-text="返回" title="历史数据"></uni-nav-bar>
  7. </view>
  8. </view>
  9. <view class="" style="position: relative;top: 100px;">
  10. <view class="selecttimes" @click="tiemshow=!tiemshow">
  11. <view class="timesbox">
  12. <image
  13. :src="'http://www.hnyfwlw.com:8006/bigdata_app/image/prevention/1acfe2751c01d3786cdc49b83d7e505.png'"
  14. mode=""></image>
  15. <p>{{timetab(begintime)}}</p>
  16. <p class="or">~</p>
  17. <p>{{timetab(end)}}</p>
  18. <u-icon name="rili" custom-prefix="custom-icon" class="icon"></u-icon>
  19. </view>
  20. <u-calendar v-model="tiemshow" mode="range" @change="tiemchange"></u-calendar>
  21. </view>
  22. <view class="shuju_one">
  23. <view class="canvastishi" v-if="!canvastishiTF && !dataloadingtf">
  24. 暂无数据
  25. </view>
  26. <view class="canvastishi" v-if="dataloadingtf">
  27. <p class="dataloading">加载中</p>
  28. </view>
  29. <canvas v-show="!tiemshow" canvas-id="canvasColumnA" id="canvasColumnA" class="charts" @touchstart="touchLineA($event)"
  30. @touchmove="moveLineA($event)" @touchend="touchEndLineA($event)" disable-scroll=true
  31. :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>
  32. </view>
  33. <view class="condition">
  34. <scroll-view scroll-top="0" scroll-x="true" class="scroll-X">
  35. <table class="table" :style="{width:300*thdata.length+'rpx'}">
  36. <tr class="tr">
  37. <th class="th" v-for="(item,index) in thdata" :key="'a'+index">{{item}}</th>
  38. </tr>
  39. <tr class="tr" v-for="(items,indexs) in historylistdata" :key="'b'+indexs" v-if="!forbidden">
  40. <td class="td">{{items.uptime|timeFormat()}}</td>
  41. <td class="td">{{items.ats}}</td>
  42. <td class="td">{{items.at}}</td>
  43. <td class="td" v-for="(item,index) in items.temp" :key="'c'+index">{{item}}</td>
  44. <td class="td" v-for="(item,index) in items.swc" :key="'d'+index">{{item}}</td>
  45. <td class="td">{{items.atm}}</td>
  46. </tr>
  47. <tr class="tr" v-if="forbidden">
  48. <td class="td" v-for="item in 13">暂无数据</td>
  49. </tr>
  50. </table>
  51. </scroll-view>
  52. <view class="pagenumber">
  53. <button @click="prev">上一页</button>
  54. <view class="pagenumber_page">
  55. 第 {{page}} 页
  56. </view>
  57. <view class="pagenumber_page">
  58. 共 {{pagesum}} 页
  59. </view>
  60. <button @click="next">下一页</button>
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. </template>
  66. <script>
  67. import uCharts from '../../components/js_sdk/u-charts/u-charts/u-charts.js';
  68. var canvaColumnA = null;
  69. export default {
  70. data() {
  71. return {
  72. tiemshow: false, //时间筛选弹框
  73. begintime: "", //开始时间
  74. end: "", //结束时间
  75. dataloadingtf: true,
  76. canvastishiTF: false,
  77. device_id: '', //设备ID
  78. thdata: ["上传时间", "空气湿度(%RH)", "空气温度(℃)", "10cm土壤温度(%RH)", "20cm土壤温度(%RH)", "30cm土壤温度(%RH)", "10cm土壤湿度(%RH)", "20cm土壤湿度(%RH)", "30cm土壤湿度(%RH)",
  79. "大气压强(Pa)"
  80. ], //表格抬头
  81. forbidden: false,
  82. historylistdata: [], //历史数据
  83. pagesum: 1,
  84. page: 1,
  85. cWidth: '',
  86. cHeight: '',
  87. pixelRatio: 1,
  88. }
  89. },
  90. methods: {
  91. tiemchange(e) { //切换时间
  92. this.begintime = parseInt(+new Date(e.startDate) / 1000)
  93. this.end = parseInt(+new Date(e.endDate) / 1000)
  94. this.histprydatas()
  95. },
  96. timetab(e) { //时间转换
  97. e = new Date(e * 1000)
  98. var year = e.getFullYear()
  99. var month = e.getMonth() + 1 < 10 ? "0" + (e.getMonth() + 1) : e.getMonth() + 1
  100. var day = e.getDate() < 10 ? "0" + e.getDate() : e.getDate()
  101. var time = year + "/" + month + "/" + day
  102. return time
  103. },
  104. async histprydatas() { //历史数据
  105. this.dataloadingtf = true
  106. const res = await this.$myRequest({
  107. url: '/api/api_gateway?method=weather.weather.nd_data',
  108. data: {
  109. device_id: this.device_id,
  110. page: this.page,
  111. begin: this.begintime,
  112. end: this.end
  113. }
  114. })
  115. this.dataloadingtf = false
  116. console.log(res.nums)
  117. this.pagesum = Math.ceil(res.nums / 10) || 1
  118. this.historylistdata = res.dat_list
  119. for (var i = 0; i < this.historylistdata.length; i++) {
  120. this.historylistdata[i].temp = this.historylistdata[i].temp.split(",")
  121. this.historylistdata[i].swc = this.historylistdata[i].swc.split(",")
  122. }
  123. var arr1 = []
  124. var arr2 = []
  125. var xtitle = []
  126. var obj = [{
  127. name: '空气温度',
  128. data: [],
  129. color: '#00E29D'
  130. }, {
  131. name: '空气湿度',
  132. data: [],
  133. color: '#6CBBFF'
  134. }]
  135. var arr3 = []
  136. var k = 0
  137. for (var i = 0; i < res.dat_char.length; i++) {
  138. var times = new Date(res.dat_char[i].uptime * 1000)
  139. xtitle.unshift(times.getMonth() + 1 + "/" + times.getDate() + "-" + times.getHours() + ":" + times
  140. .getMinutes())
  141. arr1.unshift(res.dat_char[i].at == "" ? "0" : res.dat_char[i].at) //空气温度
  142. arr2.unshift(res.dat_char[i].ats == "" ? "0" : res.dat_char[i].ats) //空气湿度
  143. res.dat_char[i].temp = res.dat_char[i].temp.split(",")
  144. res.dat_char[i].swc = res.dat_char[i].swc.split(",")
  145. for (var j = 0; j < res.dat_char[i].temp.length; j++) {
  146. arr3.unshift(res.dat_char[i].temp[j] == "" ? "0" : res.dat_char[i].temp[j]) //10cm土壤温度
  147. }
  148. res.dat_char[i].temp.forEach((items, indexs) => {
  149. var tempdata = [];
  150. var tempdatas = [];
  151. tempdata.push(Number(items));
  152. tempdatas.push(Number(res.dat_char[i].swc[indexs]));
  153. var temparrs = {
  154. name: 10 + indexs * res.topic + "cm土壤温度",
  155. data: tempdata,
  156. };
  157. var temparr = {
  158. name: 10 + indexs * res.topic + "cm土壤湿度",
  159. data: tempdatas,
  160. };
  161. obj.push(temparr);
  162. obj.push(temparrs);
  163. })
  164. }
  165. obj[0].data = arr1
  166. obj[1].data = arr2
  167. var listArr = [];
  168. obj.forEach(function(el, index) {
  169. for (var i = 0; i < listArr.length; i++) {
  170. // 对比相同的字段key,相同放入对应的数组中
  171. if (listArr[i].name == el.name && el.data !== undefined) {
  172. listArr[i].data.unshift(el.data[0]);
  173. return;
  174. }
  175. }
  176. // 第一次对比没有参照,放入参照
  177. listArr.push({
  178. name: el.name,
  179. data: el.data,
  180. });
  181. });
  182. console.log(listArr)
  183. if(listArr.length==0){
  184. this.canvastishiTF = false
  185. }else{
  186. this.canvastishiTF = true
  187. }
  188. this.showColumn("canvasColumnA", xtitle, listArr)
  189. // console.log(this.historylistdata)
  190. },
  191. prev() { //上一页
  192. if (this.page > 1) {
  193. this.page--
  194. this.histprydatas()
  195. }
  196. },
  197. next() { //下一页
  198. if (this.page < this.pagesum) {
  199. this.page++
  200. this.histprydatas()
  201. }
  202. },
  203. clickLeft() {
  204. uni.navigateBack({
  205. delta: 1
  206. })
  207. },
  208. showColumn(id, xtitle, xinfo) {
  209. var _self = this
  210. canvaColumnA = new uCharts({
  211. canvasId: id,
  212. type: 'line',
  213. legend: {
  214. position: "top"
  215. },
  216. fontSize: 11,
  217. background: '#FFFFFF',
  218. pixelRatio: 1,
  219. animation: true,
  220. dataLabel: false,
  221. categories: xtitle,
  222. series: xinfo,
  223. enableScroll: true, //开启图表拖拽功能
  224. xAxis: {
  225. disableGrid: true,
  226. type: 'grid',
  227. gridType: 'dash',
  228. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  229. scrollShow: true, //新增是否显示滚动条,默认false
  230. // scrollAlign: 'left', //滚动条初始位置
  231. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  232. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  233. },
  234. yAxis: {},
  235. width: _self.cWidth * 1,
  236. height: _self.cHeight * 1,
  237. extra: {
  238. line: {
  239. type: 'curve'
  240. }
  241. }
  242. });
  243. },
  244. touchLineA(e) {
  245. console.log(e)
  246. canvaColumnA.scrollStart(e);
  247. },
  248. moveLineA(e) {
  249. canvaColumnA.scroll(e);
  250. },
  251. touchEndLineA(e) {
  252. canvaColumnA.scrollEnd(e);
  253. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  254. canvaColumnA.showToolTip(e, {
  255. format: function(item, category) {
  256. return category + ' ' + item.name + ':' + item.data
  257. }
  258. });
  259. },
  260. },
  261. onLoad(option) {
  262. this.cWidth = uni.upx2px(650);
  263. this.cHeight = uni.upx2px(500);
  264. this.device_id = option.id
  265. this.end = parseInt(+new Date() / 1000)
  266. this.begintime = parseInt(this.end - 24 * 60 * 60)
  267. this.histprydatas()
  268. }
  269. }
  270. </script>
  271. <style lang="scss">
  272. .selecttimes {
  273. width: 90%;
  274. box-shadow: 0 0 10rpx #bcb9ca;
  275. padding: 10rpx 20rpx;
  276. box-sizing: border-box;
  277. margin: 0 auto;
  278. font-size: 28rpx;
  279. .timesbox {
  280. display: flex;
  281. justify-content: space-around;
  282. image {
  283. width: 30rpx;
  284. height: 30rpx;
  285. margin-top: 6rpx;
  286. }
  287. .icon {
  288. color: #949494;
  289. text-align: right;
  290. margin-left: 30rpx;
  291. }
  292. }
  293. /deep/.u-calendar__action {
  294. display: flex;
  295. justify-content: space-around;
  296. .u-calendar__action__text {
  297. line-height: 25px;
  298. }
  299. }
  300. }
  301. .shuju_one {
  302. width: 90%;
  303. left: 5%;
  304. box-shadow: 0 0 10rpx #bcb9ca;
  305. padding-top: 20rpx;
  306. height: 550rpx;
  307. margin: 20rpx auto;
  308. .canvastishi {
  309. font-size: 32rpx;
  310. position: absolute;
  311. top: 50%;
  312. left: 50%;
  313. margin-left: -64rpx;
  314. margin-top: -21rpx;
  315. .dataloading:after {
  316. overflow: hidden;
  317. display: inline-block;
  318. vertical-align: bottom;
  319. animation: ellipsis 2s infinite;
  320. content: "\2026";
  321. }
  322. @keyframes ellipsis {
  323. from {
  324. width: 2px;
  325. }
  326. to {
  327. width: 15px;
  328. }
  329. }
  330. }
  331. }
  332. .condition {
  333. display: flex;
  334. flex-wrap: wrap;
  335. width: 90%;
  336. left: 5%;
  337. box-shadow: 0 0 10rpx #bcb9ca;
  338. margin-bottom: 30rpx;
  339. margin: 20rpx auto;
  340. .scroll-X {
  341. width: 95%;
  342. margin: 20rpx auto;
  343. .tr {
  344. display: flex;
  345. overflow: hidden;
  346. .th,
  347. .td {
  348. display: inline-block;
  349. padding: 5rpx;
  350. width: 300rpx;
  351. text-align: center;
  352. height: 52rpx;
  353. line-height: 52rpx;
  354. border: 2rpx solid #F1F1F1;
  355. }
  356. }
  357. .tr:nth-child(2n-1) {
  358. background-color: #f5fff8;
  359. }
  360. .tr:first-child {
  361. background-color: #57c878;
  362. color: #fff;
  363. }
  364. }
  365. .pagenumber {
  366. display: flex;
  367. margin: 20rpx auto;
  368. button {
  369. width: 150rpx;
  370. height: 50rpx;
  371. line-height: 50rpx;
  372. font-size: 26rpx;
  373. text-align: center;
  374. background-color: #57c878;
  375. color: #FFFFFF;
  376. }
  377. .pagenumber_page {
  378. width: 100rpx;
  379. height: 50rpx;
  380. line-height: 50rpx;
  381. font-size: 26rpx;
  382. text-align: center;
  383. }
  384. }
  385. }
  386. </style>