gshistory.vue 13 KB

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