gshistory.vue 12 KB

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