gshistory.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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="'https://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. this.historylistdata[i].ecs = this.historylistdata[i].ecs.split(",");
  123. }
  124. var arr1 = []
  125. var arr2 = []
  126. var xtitle = []
  127. var obj = [{
  128. name: '空气温度',
  129. data: [],
  130. color: '#00E29D'
  131. }, {
  132. name: '空气湿度',
  133. data: [],
  134. color: '#6CBBFF'
  135. }]
  136. var arr3 = []
  137. var k = 0
  138. for (var i = 0; i < res.dat_char.length; i++) {
  139. var times = new Date(res.dat_char[i].uptime * 1000)
  140. xtitle.unshift(times.getMonth() + 1 + "/" + times.getDate() + "-" + times.getHours() + ":" + times
  141. .getMinutes())
  142. arr1.unshift(res.dat_char[i].at == "" ? "0" : res.dat_char[i].at) //空气温度
  143. arr2.unshift(res.dat_char[i].ats == "" ? "0" : res.dat_char[i].ats) //空气湿度
  144. res.dat_char[i].temp = res.dat_char[i].temp.split(",")
  145. res.dat_char[i].swc = res.dat_char[i].swc.split(",")
  146. res.dat_char[i].ecs = res.dat_char[i].ecs.split(",")
  147. for (var j = 0; j < res.dat_char[i].temp.length; j++) {
  148. arr3.unshift(res.dat_char[i].temp[j] == "" ? "0" : res.dat_char[i].temp[j]) //10cm土壤温度
  149. }
  150. this.thdata.length = 1;
  151. res.depth.split(',').forEach((dep, index) => {
  152. this.thdata.push(`${dep}cm土壤温度(℃)`)
  153. res.dat_char[i].temp.forEach((items, indexs) => {
  154. var tempdata = [];
  155. var tempdatas = [];
  156. var ecsarr = [];
  157. tempdata.push(Number(items));
  158. tempdatas.push(Number(res.dat_char[i].swc[indexs]));
  159. if((res.dat_char[i]).ecs[indexs]) {
  160. ecsarr.push(Number(res.dat_char[i].ecs[indexs]));
  161. }
  162. var temparrs = {
  163. name: dep + "cm土壤温度(℃)",
  164. data: tempdata,
  165. };
  166. var temparr = {
  167. name: dep + "cm土壤湿度(%RH)",
  168. data: tempdatas,
  169. };
  170. var ecsparr = {
  171. name: dep + "cm电导率(ms/cm)",
  172. data: ecsarr,
  173. };
  174. obj.push(temparr);
  175. obj.push(temparrs);
  176. if(ecsarr.length > 0) {
  177. obj.push(ecsparr);
  178. }
  179. });
  180. })
  181. res.depth.split(',').forEach((dep, index) => {
  182. this.thdata.push(`${dep}cm土壤湿度(%RH)`)
  183. })
  184. res.depth.split(',').forEach((dep, index) => {
  185. this.thdata.push(`${dep}cm电导率(ms/cm)`)
  186. })
  187. }
  188. obj[0].data = arr1
  189. obj[1].data = arr2
  190. var listArr = [];
  191. obj.forEach(function(el, index) {
  192. for (var i = 0; i < listArr.length; i++) {
  193. // 对比相同的字段key,相同放入对应的数组中
  194. if (listArr[i].name == el.name && el.data !== undefined) {
  195. listArr[i].data.unshift(el.data[0]);
  196. return;
  197. }
  198. }
  199. // 第一次对比没有参照,放入参照
  200. listArr.push({
  201. name: el.name,
  202. data: el.data,
  203. });
  204. });
  205. console.log(listArr)
  206. if(listArr.length==0){
  207. this.canvastishiTF = false
  208. }else{
  209. this.canvastishiTF = true
  210. }
  211. this.showColumn("canvasColumnA", xtitle, listArr)
  212. // console.log(this.historylistdata)
  213. },
  214. prev() { //上一页
  215. if (this.page > 1) {
  216. this.page--
  217. this.histprydatas()
  218. }
  219. },
  220. next() { //下一页
  221. if (this.page < this.pagesum) {
  222. this.page++
  223. this.histprydatas()
  224. }
  225. },
  226. clickLeft() {
  227. uni.navigateBack({
  228. delta: 1
  229. })
  230. },
  231. showColumn(id, xtitle, xinfo) {
  232. var _self = this
  233. canvaColumnA = new uCharts({
  234. canvasId: id,
  235. type: 'line',
  236. legend: {
  237. position: "top"
  238. },
  239. fontSize: 11,
  240. background: '#FFFFFF',
  241. pixelRatio: 1,
  242. animation: true,
  243. dataLabel: false,
  244. categories: xtitle,
  245. series: xinfo,
  246. enableScroll: true, //开启图表拖拽功能
  247. xAxis: {
  248. disableGrid: true,
  249. type: 'grid',
  250. gridType: 'dash',
  251. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  252. scrollShow: true, //新增是否显示滚动条,默认false
  253. // scrollAlign: 'left', //滚动条初始位置
  254. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  255. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  256. },
  257. yAxis: {},
  258. width: _self.cWidth * 1,
  259. height: _self.cHeight * 1,
  260. extra: {
  261. line: {
  262. type: 'curve'
  263. }
  264. }
  265. });
  266. },
  267. touchLineA(e) {
  268. console.log(e)
  269. canvaColumnA.scrollStart(e);
  270. },
  271. moveLineA(e) {
  272. canvaColumnA.scroll(e);
  273. },
  274. touchEndLineA(e) {
  275. canvaColumnA.scrollEnd(e);
  276. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  277. canvaColumnA.showToolTip(e, {
  278. format: function(item, category) {
  279. return category + ' ' + item.name + ':' + item.data
  280. }
  281. });
  282. },
  283. },
  284. onLoad(option) {
  285. this.cWidth = uni.upx2px(650);
  286. this.cHeight = uni.upx2px(500);
  287. this.device_id = option.id
  288. this.end = parseInt(+new Date() / 1000)
  289. this.begintime = parseInt(this.end - 24 * 60 * 60)
  290. this.histprydatas()
  291. }
  292. }
  293. </script>
  294. <style lang="scss">
  295. .selecttimes {
  296. width: 90%;
  297. box-shadow: 0 0 10rpx #bcb9ca;
  298. padding: 10rpx 20rpx;
  299. box-sizing: border-box;
  300. margin: 0 auto;
  301. font-size: 28rpx;
  302. .timesbox {
  303. display: flex;
  304. justify-content: space-around;
  305. image {
  306. width: 30rpx;
  307. height: 30rpx;
  308. margin-top: 6rpx;
  309. }
  310. .icon {
  311. color: #949494;
  312. text-align: right;
  313. margin-left: 30rpx;
  314. }
  315. }
  316. /deep/.u-calendar__action {
  317. display: flex;
  318. justify-content: space-around;
  319. .u-calendar__action__text {
  320. line-height: 25px;
  321. }
  322. }
  323. }
  324. .shuju_one {
  325. width: 90%;
  326. left: 5%;
  327. box-shadow: 0 0 10rpx #bcb9ca;
  328. padding-top: 20rpx;
  329. height: 550rpx;
  330. margin: 20rpx auto;
  331. .canvastishi {
  332. font-size: 32rpx;
  333. position: absolute;
  334. top: 50%;
  335. left: 50%;
  336. margin-left: -64rpx;
  337. margin-top: -21rpx;
  338. .dataloading:after {
  339. overflow: hidden;
  340. display: inline-block;
  341. vertical-align: bottom;
  342. animation: ellipsis 2s infinite;
  343. content: "\2026";
  344. }
  345. @keyframes ellipsis {
  346. from {
  347. width: 2px;
  348. }
  349. to {
  350. width: 15px;
  351. }
  352. }
  353. }
  354. }
  355. .condition {
  356. display: flex;
  357. flex-wrap: wrap;
  358. width: 90%;
  359. left: 5%;
  360. box-shadow: 0 0 10rpx #bcb9ca;
  361. margin-bottom: 30rpx;
  362. margin: 20rpx auto;
  363. .scroll-X {
  364. width: 95%;
  365. margin: 20rpx auto;
  366. .tr {
  367. display: flex;
  368. overflow: hidden;
  369. .th,
  370. .td {
  371. display: inline-block;
  372. padding: 5rpx;
  373. width: 300rpx;
  374. text-align: center;
  375. height: 52rpx;
  376. line-height: 52rpx;
  377. border: 2rpx solid #F1F1F1;
  378. }
  379. }
  380. .tr:nth-child(2n-1) {
  381. background-color: #f5fff8;
  382. }
  383. .tr:first-child {
  384. background-color: #57c878;
  385. color: #fff;
  386. }
  387. }
  388. .pagenumber {
  389. display: flex;
  390. margin: 20rpx auto;
  391. button {
  392. width: 150rpx;
  393. height: 50rpx;
  394. line-height: 50rpx;
  395. font-size: 26rpx;
  396. text-align: center;
  397. background-color: #57c878;
  398. color: #FFFFFF;
  399. }
  400. .pagenumber_page {
  401. width: 100rpx;
  402. height: 50rpx;
  403. line-height: 50rpx;
  404. font-size: 26rpx;
  405. text-align: center;
  406. }
  407. }
  408. }
  409. </style>