historyfile.vue 9.6 KB

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