xyhistoryile.vue 13 KB

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