xyhistoryile.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. <template>
  2. <view>
  3. <view class="status_bar"></view>
  4. <view class="" style="position: relative;top: 44px;">
  5. <view style="position: fixed;z-index: 100;">
  6. <uni-nav-bar @clickLeft="clickLeft" left-icon="back" title="历史数据"></uni-nav-bar>
  7. </view>
  8. <view class="shuju_one">
  9. <view class="shuju_one_title">
  10. <view :class="titleidnex==index?'title_text_color':'tltle_text'" v-for="(item,index) in titletext"
  11. :key="index" @click="changeindex(index)">
  12. {{item}}
  13. </view>
  14. </view>
  15. <view class="canvastishi" v-if="!canvastishiTF && !dataloadingtf">
  16. 暂无数据
  17. </view>
  18. <view class="canvastishi" v-if="dataloadingtf">
  19. <p class="dataloading">加载中</p>
  20. </view>
  21. <canvas v-if="canvastishiTF" canvas-id="canvasColumnA" id="canvasColumnA" class="charts"
  22. @touchstart="touchLineA($event)" @touchmove="moveLineA($event)" @touchend="touchEndLineA($event)"
  23. disable-scroll=true
  24. :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>
  25. </view>
  26. <view class="wind">
  27. <p class="wind_titie">风速、风向</p>
  28. <view class="wind_text">
  29. <view class="wind_speed">
  30. <image
  31. :src="'http://www.hnyfwlw.com:8006/bigdata_app'+'/image/cb/xy/1c24243bb184e84ffd13540367569ba.png'"
  32. mode=""></image>
  33. <p>风速:{{wind_sped}}(m/s)</p>
  34. </view>
  35. <view class="wind_direction">
  36. <image
  37. :src="'http://www.hnyfwlw.com:8006/bigdata_app'+'/image/cb/xy/c44ae038324e1040a1eaa702e6d71a5.png'"
  38. mode=""></image>
  39. <p>风向:{{wind_drec}}</p>
  40. </view>
  41. </view>
  42. </view>
  43. <view class="refresh" @click="refresh">
  44. 刷 新
  45. </view>
  46. <view class="condition">
  47. <scroll-view scroll-top="0" scroll-x="true" class="scroll-X">
  48. <!-- @scrolltoupper="upper" @scrolltolower="lower" @scroll="scroll" -->
  49. <table class="table" v-if="$QueryPermission(268)">
  50. <tr class="tr">
  51. <th class="th" v-for="(item,index) in thdata" :key="'a'+index">{{item}}</th>
  52. </tr>
  53. <tr class="tr" v-for="(items,indexs) in historylistdata" :key="'b'+indexs" v-if="!forbidden">
  54. <td class="td">{{items.d_h_t.addtime|timeFormat()}}</td>
  55. <td class="td">{{items.d_h_t.ds==0?"关":"开"}}</td>
  56. <td class="td">{{items.d_h_t.ws==0?"待机":"工作"}}</td>
  57. <td class="td">{{items.d_h_t.at}}</td>
  58. <td class="td">{{items.d_h_t.ah}}</td>
  59. <td class="td">{{items.d_h_t.cv}}</td>
  60. <td class="td">{{items.d_h_t.bv}}</td>
  61. <td class="td">{{items.d_h_t.bs}}</td>
  62. <td class="td">{{items.d_h_t.cs?"充电":"非充电"}}</td>
  63. <td class="td">{{items.d_h_t.infr_ct}}</td>
  64. <td class="td">{{items.d_h_t.csq}}</td>
  65. </tr>
  66. <tr class="tr" v-if="forbidden">
  67. <td class="td" v-for="item in 11">暂无数据</td>
  68. </tr>
  69. </table>
  70. <table class="table" v-else>
  71. <tr class="tr">
  72. <th class="th" v-for="(item,index) in thdata2" :key="'a'+index">{{item}}</th>
  73. </tr>
  74. <tr class="tr" v-for="(items,indexs) in historylistdata" :key="'b'+indexs" v-if="!forbidden">
  75. <td class="td">{{items.d_h_t.addtime|timeFormat()}}</td>
  76. <td class="td">{{items.d_h_t.ds==0?"关":"开"}}</td>
  77. <td class="td">{{items.d_h_t.ws==0?"待机":"工作"}}</td>
  78. <td class="td">{{items.d_h_t.at}}</td>
  79. <td class="td">{{items.d_h_t.ah}}</td>
  80. <td class="td">{{items.d_h_t.bs}}</td>
  81. <td class="td">{{items.d_h_t.cs?"充电":"非充电"}}</td>
  82. <td class="td">{{items.d_h_t.infr_ct}}</td>
  83. </tr>
  84. <tr class="tr" v-if="forbidden">
  85. <td class="td" v-for="item in 8">暂无数据</td>
  86. </tr>
  87. </table>
  88. </scroll-view>
  89. <view class="pagenumber">
  90. <button @click="prev">上一页</button>
  91. <view class="pagenumber_page">
  92. 第 {{page}} 页
  93. </view>
  94. <view class="pagenumber_page">
  95. 第 {{pagesum}} 页
  96. </view>
  97. <button @click="next" :disabled="forbidden">下一页</button>
  98. </view>
  99. </view>
  100. </view>
  101. </view>
  102. </template>
  103. <script>
  104. import uCharts from '../../../../components/js_sdk/u-charts/u-charts/u-charts.js';
  105. var canvaColumnA = null;
  106. export default {
  107. data() {
  108. return {
  109. cWidth: '400',
  110. cHeight: '400',
  111. pixelRatio: 1,
  112. canvastishiTF: false, //暂无数据提示
  113. dataloadingtf: true, //加载中提示
  114. d_id: '',
  115. start_time: "",
  116. end_time: "",
  117. historydatas: [],
  118. titletext: ["24小时", "近一个月", "近半年", "近一年"],
  119. titleidnex: 0,
  120. device_id: '',
  121. page: 1,
  122. historylistdata: [],
  123. thdata: ["上报时间", "设备开关", "工作状态", "环境温度(°C)", "环境湿度(%)", "充电电压(V)", "电池电压(V)", "电池状态", "充电状态",
  124. "诱虫次数", "信号强度",
  125. ],
  126. thdata2: ["上报时间", "设备开关", "工作状态", "环境温度(°C)", "环境湿度(%)", "电池状态", "充电状态",
  127. "诱虫次数",
  128. ],
  129. forbidden: false,
  130. wind_sped: '', //风速
  131. wind_drec: '',
  132. pagesum: 1
  133. }
  134. },
  135. methods: {
  136. //forecast.worm_lamp.device_polyline_data 历史数据折线图
  137. // device_type_id 必传(string) 设备类型 3虫情测报灯 7孢子仪 4智能性诱 2杀虫灯 9糖醋测报灯 10测报灯rtu
  138. // d_id 必传 设备id
  139. // start_time 非必传(string 时间戳) 开始时间 (用于时间搜索)
  140. // end_time
  141. async history() { //历史数据折线图
  142. this.dataloadingtf = true
  143. const res = await this.$myRequest({
  144. url: '/api/api_gateway?method=forecast.worm_lamp.device_polyline_data',
  145. data: {
  146. device_type_id: 4,
  147. d_id: this.d_id,
  148. start_time: parseInt(this.start_time / 1000),
  149. end_time: parseInt(this.end_time / 1000)
  150. }
  151. })
  152. this.dataloadingtf = false
  153. this.historydatas = res
  154. console.log(this.historydatas)
  155. if (res.length == 0) {
  156. this.wind_sped = "--"
  157. this.wind_drec = "--"
  158. } else {
  159. if(res[res.length-1].others.wind_sped>=66.6){
  160. this.wind_sped = 0
  161. }else{
  162. this.wind_sped = res[res.length-1].others.wind_sped
  163. }
  164. if (22 < res[res.length-1].others.wind_drec && 67 > res[res.length-1].others.wind_drec) {
  165. this.wind_drec = "东北"
  166. } else if (67 < res[res.length-1].others.wind_drec && 112 > res[res.length-1].others.wind_drec) {
  167. this.wind_drec = "东"
  168. } else if (112 < res[res.length-1].others.wind_drec && 157 > res[res.length-1].others.wind_drec) {
  169. this.wind_drec = "东南"
  170. } else if (157 < res[res.length-1].others.wind_drec && 202 > res[res.length-1].others.wind_drec) {
  171. this.wind_drec = "南"
  172. } else if (202 < res[res.length-1].others.wind_drec && 247 > res[res.length-1].others.wind_drec) {
  173. this.wind_drec = "西南"
  174. } else if (247 < res[res.length-1].others.wind_drec && 292 > res[res.length-1].others.wind_drec) {
  175. this.wind_drec = "西"
  176. } else if (292 < res[res.length-1].others.wind_drec && 337 > res[res.length-1].others.wind_drec) {
  177. this.wind_drec = "西北"
  178. } else if (res[res.length-1].others.wind_drec>360){
  179. this.wind_drec = "无"
  180. }else{
  181. this.wind_drec = "北"
  182. }
  183. }
  184. if (this.historydatas.length == 0) {
  185. this.canvastishiTF = false
  186. } else {
  187. this.canvastishiTF = true
  188. var arr1 = []
  189. var arr2 = []
  190. var xtitle = []
  191. for (var i = 0; i < res.length; i++) {
  192. var times = new Date(res[i].addtime * 1000)
  193. xtitle.unshift(times.getMonth() + 1 + "/" + times.getDate() + "-" + times.getHours() + ":" +
  194. times.getMinutes())
  195. arr1.unshift(res[i].temperature == "" ? "0" : res[i].temperature)
  196. arr2.unshift(res[i].humidity == "" ? "0" : res[i].humidity)
  197. }
  198. var obj = [{
  199. name: '温度',
  200. data: arr1,
  201. color: '#00E29D'
  202. }, {
  203. name: '湿度',
  204. data: arr2,
  205. color: '#6CBBFF'
  206. }]
  207. this.showColumn("canvasColumnA", xtitle, obj)
  208. }
  209. },
  210. //forecast.worm_lamp.device_history_data历史数据列表
  211. async historylist() { //历史数据列表
  212. const res = await this.$myRequest({
  213. url: '/api/api_gateway?method=forecast.worm_lamp.device_history_data',
  214. data: {
  215. device_type_id: 4,
  216. device_id: this.device_id,
  217. start_time: parseInt(this.start_time / 1000),
  218. end_time: parseInt(this.end_time / 1000),
  219. page: this.page
  220. }
  221. })
  222. this.historylistdata = res.data
  223. this.pagesum = Math.ceil(res.counts / 10) || 1
  224. if (res.data.length == 0) {
  225. this.forbidden = true
  226. } else {
  227. this.forbidden = false
  228. }
  229. for (var i = 0; i < this.historylistdata.length; i++) {
  230. if (res.data[i].d_h_t.bs == 0) {
  231. this.historylistdata[i].d_h_t.bs = "正常"
  232. } else if (res.data[i].d_h_t.bs == 1) {
  233. this.historylistdata[i].d_h_t.bs = "欠压"
  234. } else if (res.data[i].d_h_t.bs == 2) {
  235. this.historylistdata[i].d_h_t.bs = "过压"
  236. }
  237. }
  238. console.log(this.historylistdata)
  239. },
  240. changeindex(index) {
  241. this.titleidnex = index
  242. var now = new Date()
  243. this.$forceUpdate()
  244. if (index == 0) {
  245. this.start_time = this.end_time - 24 * 60 * 60 * 1000
  246. this.history()
  247. this.historylist()
  248. } else if (index == 1) {
  249. var oldtime = now.setMonth(now.getMonth() - 1)
  250. this.start_time = parseInt(oldtime)
  251. this.history()
  252. this.historylist()
  253. } else if (index == 2) {
  254. var oldtime = now.setMonth(now.getMonth() - 6)
  255. this.start_time = parseInt(oldtime)
  256. this.history()
  257. this.historylist()
  258. } else if (index == 3) {
  259. var oldtime = now.setFullYear(now.getFullYear() - 1)
  260. this.start_time = parseInt(oldtime)
  261. this.history()
  262. this.historylist()
  263. }
  264. },
  265. prev() { //上一页
  266. if (this.page > 1) {
  267. this.page--
  268. this.historylist()
  269. }
  270. },
  271. next() { //下一页
  272. if (this.page < this.pagesum) {
  273. this.page++
  274. this.historylist()
  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. async newdata() {
  335. const res = await this.$myRequest({
  336. url: '/api/api_gateway?method=forecast.send_control.get_device_config',
  337. data: {
  338. device_type_id: 4,
  339. d_id: this.d_id,
  340. control_type: "data"
  341. }
  342. })
  343. if (res) {
  344. uni.showToast({
  345. title: '刷新成功',
  346. duration: 2000,
  347. icon: "none"
  348. });
  349. } else {
  350. uni.showToast({
  351. title: '刷新失败',
  352. duration: 2000,
  353. icon: "none"
  354. });
  355. }
  356. },
  357. refresh() { //获取当前时间的数据
  358. this.newdata()
  359. },
  360. },
  361. onLoad(option) {
  362. this.d_id = option.d_id
  363. this.device_id = option.device_id
  364. this.cWidth = uni.upx2px(650);
  365. this.cHeight = uni.upx2px(500);
  366. },
  367. onShow() {
  368. this.end_time = +new Date() + 1000
  369. this.start_time = this.end_time - 24 * 60 * 60 * 1000
  370. setTimeout(() => {
  371. this.history()
  372. this.historylist()
  373. }, 1000)
  374. },
  375. onPullDownRefresh() {
  376. console.log('refresh');
  377. this.history()
  378. this.historylist()
  379. setTimeout(function() {
  380. uni.stopPullDownRefresh();
  381. }, 1000);
  382. }
  383. }
  384. </script>
  385. <style lang="scss">
  386. .shuju_one,
  387. .shuju_two {
  388. position: absolute;
  389. top: 54px;
  390. width: 90%;
  391. left: 5%;
  392. box-shadow: 0 0 10rpx #bcb9ca;
  393. padding-top: 20rpx;
  394. height: 550rpx;
  395. .canvastishi {
  396. font-size: 32rpx;
  397. position: absolute;
  398. top: 50%;
  399. left: 50%;
  400. margin-left: -64rpx;
  401. margin-top: -21rpx;
  402. .dataloading:after {
  403. overflow: hidden;
  404. display: inline-block;
  405. vertical-align: bottom;
  406. animation: ellipsis 2s infinite;
  407. content: "\2026";
  408. }
  409. @keyframes ellipsis {
  410. from {
  411. width: 2px;
  412. }
  413. to {
  414. width: 15px;
  415. }
  416. }
  417. }
  418. .shuju_one_title {
  419. width: 70%;
  420. margin: 0 auto;
  421. display: flex;
  422. .tltle_text {
  423. width: 25%;
  424. border: 2rpx solid #B2B2B2;
  425. color: #57c878;
  426. text-align: center;
  427. font-size: 24rpx;
  428. height: 50rpx;
  429. line-height: 50rpx;
  430. }
  431. .title_text_color {
  432. width: 25%;
  433. border: 2rpx solid #57c878;
  434. background-color: #57c878;
  435. color: #fff;
  436. text-align: center;
  437. font-size: 24rpx;
  438. height: 50rpx;
  439. line-height: 50rpx;
  440. }
  441. }
  442. }
  443. .wind {
  444. position: absolute;
  445. top: 700rpx;
  446. width: 90%;
  447. left: 5%;
  448. box-shadow: 0 0 10rpx #bcb9ca;
  449. padding: 20rpx;
  450. box-sizing: border-box;
  451. .wind_titie {
  452. border-left: 6rpx solid #57c878;
  453. height: 34rpx;
  454. padding-left: 20rpx;
  455. }
  456. .wind_text {
  457. display: flex;
  458. .wind_speed,
  459. .wind_direction {
  460. width: 50%;
  461. text-align: center;
  462. margin-top: 30rpx;
  463. image {
  464. width: 160rpx;
  465. height: 130rpx;
  466. }
  467. }
  468. }
  469. }
  470. .refresh {
  471. position: absolute;
  472. top: 1000rpx;
  473. left: 5%;
  474. width: 160rpx;
  475. height: 50rpx;
  476. background-color: #57c878;
  477. color: #FFFFFF;
  478. line-height: 50rpx;
  479. text-align: center;
  480. }
  481. .condition {
  482. position: absolute;
  483. top: 1070rpx;
  484. display: flex;
  485. flex-wrap: wrap;
  486. width: 90%;
  487. left: 5%;
  488. box-shadow: 0 0 10rpx #bcb9ca;
  489. margin-bottom: 30rpx;
  490. .scroll-X {
  491. width: 95%;
  492. margin: 20rpx auto;
  493. .table {
  494. width: 1672px;
  495. }
  496. .tr {
  497. display: flex;
  498. overflow: hidden;
  499. .th,
  500. .td {
  501. display: inline-block;
  502. padding: 5rpx;
  503. width: 240rpx;
  504. text-align: center;
  505. height: 52rpx;
  506. line-height: 52rpx;
  507. }
  508. .th:first-child,
  509. .td:first-child {
  510. width: 300rpx;
  511. }
  512. }
  513. .tr:nth-child(2n-1) {
  514. background-color: #f5fff8;
  515. }
  516. .tr:first-child {
  517. background-color: #57c878;
  518. color: #fff;
  519. }
  520. }
  521. .pagenumber {
  522. display: flex;
  523. margin: 20rpx auto;
  524. button {
  525. width: 150rpx;
  526. height: 50rpx;
  527. line-height: 50rpx;
  528. font-size: 26rpx;
  529. text-align: center;
  530. background-color: #57c878;
  531. color: #FFFFFF;
  532. }
  533. .pagenumber_page {
  534. width: 100rpx;
  535. height: 50rpx;
  536. line-height: 50rpx;
  537. font-size: 26rpx;
  538. text-align: center;
  539. }
  540. }
  541. }
  542. </style>