xyhistoryile.vue 12 KB

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