xyhistoryile.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  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="$imageURL+ '/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="$imageURL+ '/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 != 0 ?"充电":"非充电"}}</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 != 0 ?"充电":"非充电"}}</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. const ctx = uni.createCanvasContext(id, this);
  285. canvaColumnA = new uCharts({
  286. context: ctx,
  287. type: 'line',
  288. legend: {
  289. position: "top"
  290. },
  291. fontSize: 11,
  292. background: '#FFFFFF',
  293. pixelRatio: 1,
  294. animation: true,
  295. dataLabel: false,
  296. categories: xtitle,
  297. series: xinfo,
  298. enableScroll: true, //开启图表拖拽功能
  299. xAxis: {
  300. disableGrid: true,
  301. type: 'grid',
  302. gridType: 'dash',
  303. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  304. scrollShow: true, //新增是否显示滚动条,默认false
  305. // scrollAlign: 'left', //滚动条初始位置
  306. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  307. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  308. },
  309. yAxis: {},
  310. width: _self.cWidth * 1,
  311. height: _self.cHeight * 1,
  312. extra: {
  313. line: {
  314. type: 'curve'
  315. }
  316. }
  317. });
  318. },
  319. touchLineA(e) {
  320. console.log(e)
  321. canvaColumnA.scrollStart(e);
  322. },
  323. moveLineA(e) {
  324. canvaColumnA.scroll(e);
  325. },
  326. touchEndLineA(e) {
  327. canvaColumnA.scrollEnd(e);
  328. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  329. canvaColumnA.showToolTip(e, {
  330. format: function(item, category) {
  331. return category + ' ' + item.name + ':' + item.data
  332. }
  333. });
  334. },
  335. async newdata() {
  336. const res = await this.$myRequest({
  337. url: '/api/api_gateway?method=forecast.send_control.get_device_config',
  338. data: {
  339. device_type_id: 4,
  340. d_id: this.d_id,
  341. control_type: "data"
  342. }
  343. })
  344. if (res) {
  345. uni.showToast({
  346. title: '刷新成功',
  347. duration: 2000,
  348. icon: "none"
  349. });
  350. } else {
  351. uni.showToast({
  352. title: '刷新失败',
  353. duration: 2000,
  354. icon: "none"
  355. });
  356. }
  357. },
  358. refresh() { //获取当前时间的数据
  359. this.newdata()
  360. },
  361. },
  362. onLoad(option) {
  363. this.d_id = option.d_id
  364. this.device_id = option.device_id
  365. this.cWidth = uni.upx2px(650);
  366. this.cHeight = uni.upx2px(500);
  367. },
  368. onShow() {
  369. this.end_time = +new Date() + 1000
  370. this.start_time = this.end_time - 24 * 60 * 60 * 1000
  371. setTimeout(() => {
  372. this.history()
  373. this.historylist()
  374. }, 1000)
  375. },
  376. onPullDownRefresh() {
  377. console.log('refresh');
  378. this.history()
  379. this.historylist()
  380. setTimeout(function() {
  381. uni.stopPullDownRefresh();
  382. }, 1000);
  383. }
  384. }
  385. </script>
  386. <style lang="scss">
  387. .shuju_one,
  388. .shuju_two {
  389. position: absolute;
  390. top: 54px;
  391. width: 90%;
  392. left: 5%;
  393. box-shadow: 0 0 10rpx #bcb9ca;
  394. padding-top: 20rpx;
  395. height: 550rpx;
  396. .canvastishi {
  397. font-size: 32rpx;
  398. position: absolute;
  399. top: 50%;
  400. left: 50%;
  401. margin-left: -64rpx;
  402. margin-top: -21rpx;
  403. .dataloading:after {
  404. overflow: hidden;
  405. display: inline-block;
  406. vertical-align: bottom;
  407. animation: ellipsis 2s infinite;
  408. content: "\2026";
  409. }
  410. @keyframes ellipsis {
  411. from {
  412. width: 2px;
  413. }
  414. to {
  415. width: 15px;
  416. }
  417. }
  418. }
  419. .shuju_one_title {
  420. width: 70%;
  421. margin: 0 auto;
  422. display: flex;
  423. .tltle_text {
  424. width: 25%;
  425. border: 2rpx solid #B2B2B2;
  426. color: #57c878;
  427. text-align: center;
  428. font-size: 24rpx;
  429. height: 50rpx;
  430. line-height: 50rpx;
  431. }
  432. .title_text_color {
  433. width: 25%;
  434. border: 2rpx solid #57c878;
  435. background-color: #57c878;
  436. color: #fff;
  437. text-align: center;
  438. font-size: 24rpx;
  439. height: 50rpx;
  440. line-height: 50rpx;
  441. }
  442. }
  443. }
  444. .wind {
  445. position: absolute;
  446. top: 700rpx;
  447. width: 90%;
  448. left: 5%;
  449. box-shadow: 0 0 10rpx #bcb9ca;
  450. padding: 20rpx;
  451. box-sizing: border-box;
  452. .wind_titie {
  453. border-left: 6rpx solid #57c878;
  454. height: 34rpx;
  455. padding-left: 20rpx;
  456. }
  457. .wind_text {
  458. display: flex;
  459. .wind_speed,
  460. .wind_direction {
  461. width: 50%;
  462. text-align: center;
  463. margin-top: 30rpx;
  464. image {
  465. width: 160rpx;
  466. height: 130rpx;
  467. }
  468. }
  469. }
  470. }
  471. .refresh {
  472. position: absolute;
  473. top: 1000rpx;
  474. left: 5%;
  475. width: 160rpx;
  476. height: 50rpx;
  477. background-color: #57c878;
  478. color: #FFFFFF;
  479. line-height: 50rpx;
  480. text-align: center;
  481. }
  482. .condition {
  483. position: absolute;
  484. top: 1070rpx;
  485. display: flex;
  486. flex-wrap: wrap;
  487. width: 90%;
  488. left: 5%;
  489. box-shadow: 0 0 10rpx #bcb9ca;
  490. margin-bottom: 30rpx;
  491. .scroll-X {
  492. width: 95%;
  493. margin: 20rpx auto;
  494. .table {
  495. width: 1400px;
  496. }
  497. .tr {
  498. display: flex;
  499. overflow: hidden;
  500. .th,
  501. .td {
  502. display: inline-block;
  503. padding: 5rpx;
  504. width: 240rpx;
  505. text-align: center;
  506. height: 52rpx;
  507. line-height: 52rpx;
  508. }
  509. .th:first-child,
  510. .td:first-child {
  511. width: 300rpx;
  512. }
  513. }
  514. .tr:nth-child(2n-1) {
  515. background-color: #f5fff8;
  516. }
  517. .tr:first-child {
  518. background-color: #57c878;
  519. color: #fff;
  520. }
  521. }
  522. .pagenumber {
  523. display: flex;
  524. margin: 20rpx auto;
  525. button {
  526. width: 150rpx;
  527. height: 50rpx;
  528. line-height: 50rpx;
  529. font-size: 26rpx;
  530. text-align: center;
  531. background-color: #57c878;
  532. color: #FFFFFF;
  533. }
  534. .pagenumber_page {
  535. width: 100rpx;
  536. height: 50rpx;
  537. line-height: 50rpx;
  538. font-size: 26rpx;
  539. text-align: center;
  540. }
  541. }
  542. }
  543. </style>