gshistory.vue 14 KB

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