gshistory.vue 10 KB

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