xyhistoryile.vue 15 KB

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