historyfile.vue 9.4 KB

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