bzyhistoryile.vue 10 KB

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