gshistory.vue 12 KB

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