historyfile.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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="refresh" @click="refresh">
  22. 刷 新
  23. </view>
  24. <view class="condition">
  25. <scroll-view scroll-top="0" scroll-x="true" class="scroll-X">
  26. <table class="table">
  27. <tr class="tr">
  28. <th class="th" v-for="(item,index) in thdata" :key="'a'+index">{{item}}</th>
  29. </tr>
  30. <tr class="tr" v-for="(items,indexs) in historylistdata" :key="'b'+indexs" v-if="!forbidden">
  31. <td class="td">{{items.d_h_t.addtime|timeFormat()}}</td>
  32. <td class="td">{{items.d_h_t.at==""?"--":items.d_h_t.at}}</td>
  33. <td class="td">{{items.d_h_t.ah==""?"--":items.d_h_t.ah}}</td>
  34. <td class="td">{{items.d_h_t.hrt}}</td>
  35. <td class="td">{{items.d_h_t.rps==0?"正常":"雨控"}}</td>
  36. <td class="td">{{items.d_h_t.tps==0?"正常":"温控"}}</td>
  37. <td class="td">{{items.d_h_t.lps==0?"正常":"光控"}}</td>
  38. <td class="td">{{items.d_h_t.dg}}</td>
  39. <td class="td">{{items.d_h_t.csq}}</td>
  40. <td class="td">{{items.d_h_t.current}}</td>
  41. <td class="td">{{items.d_h_t.vbat}}</td>
  42. <td class="td">{{items.d_h_t.lng}}</td>
  43. <td class="td">{{items.d_h_t.lat}}</td>
  44. </tr>
  45. <tr class="tr" v-if="forbidden">
  46. <td class="td" v-for="item in 13">暂无数据</td>
  47. </tr>
  48. </table>
  49. </scroll-view>
  50. <view class="pagenumber">
  51. <button @click="prev">上一页</button>
  52. <view class="pagenumber_page">
  53. 第 {{page}} 页
  54. </view>
  55. <view class="pagenumber_page">
  56. 共 {{pagesum}} 页
  57. </view>
  58. <button @click="next" :disabled="forbidden">下一页</button>
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. </template>
  64. <script>
  65. import uCharts from '../../../../components/js_sdk/u-charts/u-charts/u-charts.js';
  66. var canvaColumnA = null;
  67. export default {
  68. data() {
  69. return {
  70. styles: {
  71. // width: "650rpx",
  72. height: "400rpx"
  73. },
  74. d_id: '',
  75. start_time: "",
  76. end_time: "",
  77. historydatas: [],
  78. titletext: ["24小时", "近一个月", "近半年", "近一年"],
  79. titleidnex: 0,
  80. device_id: '',
  81. page: 1,
  82. historylistdata: [],
  83. thdata: ["上报时间", "环境温度(°C)", "环境湿度(%)", "加热仓温度(°C)", "雨控状态", "温控状态", "光控状态", "灯管状态", "信号强度", "电流(mA)", "电压(V)",
  84. "经度", "纬度"
  85. ],
  86. forbidden: false,
  87. cWidth: '400',
  88. cHeight: '400',
  89. pixelRatio: 1,
  90. canvastishiTF: false,
  91. pagesum: null
  92. }
  93. },
  94. methods: {
  95. async history() { //历史数据列表折线图
  96. const res = await this.$myRequest({
  97. url: '/api/api_gateway?method=forecast.worm_lamp.device_polyline_data',
  98. data: {
  99. device_type_id: 3,
  100. d_id: this.d_id,
  101. start_time: parseInt(this.start_time / 1000),
  102. end_time: parseInt(this.end_time / 1000)
  103. }
  104. })
  105. this.historydatas = res
  106. console.log(this.historydatas)
  107. if (this.historydatas.length == 0) {
  108. this.canvastishiTF = false
  109. } else {
  110. this.canvastishiTF = true
  111. var arr1 = []
  112. var arr2 = []
  113. var arr3 = []
  114. var xtitle = []
  115. for (var i = 0; i < res.length; i++) {
  116. var times = new Date(res[i].addtime * 1000)
  117. xtitle.unshift(times.getMonth() + 1 + "/" + times.getDate() + "-" + times.getHours() + ":" + times.getMinutes())
  118. arr1.unshift(res[i].temperature == "" ? "0" : res[i].temperature)
  119. arr2.unshift(res[i].humidity == "" ? "0" : res[i].humidity)
  120. arr3.unshift(res[i].others == "" ? "0" : res[i].others)
  121. }
  122. // console.log(arr1)
  123. var obj = [{
  124. name: '温度',
  125. data: arr1,
  126. color: '#00E29D'
  127. }, {
  128. name: '湿度',
  129. data: arr2,
  130. color: '#6CBBFF'
  131. }, {
  132. name: '加热仓温度',
  133. data: arr3,
  134. color: '#FF3F3F'
  135. }]
  136. this.showColumn("canvasColumnA", xtitle, obj)
  137. }
  138. },
  139. //forecast.worm_lamp.device_history_data历史数据列表
  140. async historylist() { //历史数据列表
  141. this.historylistdata=[]
  142. const res = await this.$myRequest({
  143. url: '/api/api_gateway?method=forecast.worm_lamp.device_history_data',
  144. data: {
  145. device_type_id: 3,
  146. device_id: this.device_id,
  147. start_time: parseInt(this.start_time / 1000),
  148. end_time: parseInt(this.end_time / 1000),
  149. page: this.page
  150. }
  151. })
  152. this.historylistdata = res.data
  153. this.pagesum = Math.ceil(res.counts / 10) + 1
  154. if (res.data.length == 0) {
  155. this.forbidden = true
  156. console.log(res.data.length)
  157. } else {
  158. this.forbidden = false
  159. console.log(res.data.length)
  160. }
  161. for (var i = 0; i < this.historylistdata.length; i++) {
  162. if (Number(this.historylistdata[i].d_h_t.ws) == 0) {
  163. this.historylistdata[i].d_h_t.dg = "待机"
  164. } else if (Number(this.historylistdata[i].d_h_t.ws) == 1) {
  165. if (Number(this.historylistdata[i].d_h_t.lamp) == 0) {
  166. this.historylistdata[i].d_h_t.dg = "工作"
  167. } else if (Number(this.historylistdata[i].d_h_t.lamp) == 1) {
  168. this.historylistdata[i].d_h_t.dg = "异常"
  169. }
  170. }
  171. }
  172. console.log(this.historylistdata)
  173. },
  174. // forecast.send_control.get_device_config 获取当前时间的数据
  175. async newdata() {
  176. const res = await this.$myRequest({
  177. url: '/api/api_gateway?method=forecast.send_control.get_device_config',
  178. data: {
  179. device_type_id: 3,
  180. d_id: this.d_id,
  181. control_type: "data"
  182. }
  183. })
  184. if(res){
  185. uni.showToast({
  186. title: '刷新成功',
  187. duration: 2000,
  188. icon: "none"
  189. });
  190. this.historylist()
  191. }else{
  192. uni.showToast({
  193. title: '刷新失败',
  194. duration: 2000,
  195. icon: "none"
  196. });
  197. }
  198. },
  199. refresh() { //获取当前时间的数据
  200. this.newdata()
  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. },
  295. onLoad(option) {
  296. this.d_id = option.d_id
  297. this.device_id = option.device_id
  298. this.cWidth = uni.upx2px(650);
  299. this.cHeight = uni.upx2px(500);
  300. },
  301. onShow(){
  302. this.end_time = +new Date() + 1000
  303. this.start_time = this.end_time - 24 * 60 * 60 * 1000
  304. setTimeout(()=>{
  305. this.history()
  306. this.historylist()
  307. },1000)
  308. },
  309. onPullDownRefresh() {
  310. this.history()
  311. this.historylist()
  312. setTimeout(() => {
  313. uni.stopPullDownRefresh()
  314. }, 1000)
  315. },
  316. }
  317. </script>
  318. <style lang="scss">
  319. .shuju_one,
  320. .shuju_two {
  321. position: absolute;
  322. top: 54px;
  323. width: 90%;
  324. left: 5%;
  325. box-shadow: 0 0 10rpx #bcb9ca;
  326. padding-top: 20rpx;
  327. height: 550rpx;
  328. .canvastishi {
  329. font-size: 32rpx;
  330. position: absolute;
  331. top: 50%;
  332. left: 50%;
  333. margin-left: -64rpx;
  334. margin-top: -21rpx;
  335. }
  336. .shuju_one_title {
  337. width: 70%;
  338. margin: 0 auto;
  339. display: flex;
  340. .tltle_text {
  341. width: 25%;
  342. border: 2rpx solid #B2B2B2;
  343. color: #B2B2B2;
  344. text-align: center;
  345. font-size: 24rpx;
  346. height: 50rpx;
  347. line-height: 50rpx;
  348. }
  349. .title_text_color {
  350. width: 25%;
  351. border: 2rpx solid #28AE4F;
  352. color: #28AE4F;
  353. text-align: center;
  354. font-size: 24rpx;
  355. height: 50rpx;
  356. line-height: 50rpx;
  357. }
  358. }
  359. }
  360. .refresh {
  361. position: absolute;
  362. top: 700rpx;
  363. left: 5%;
  364. width: 160rpx;
  365. height: 50rpx;
  366. background-color: #28AE4F;
  367. color: #FFFFFF;
  368. line-height: 50rpx;
  369. text-align: center;
  370. }
  371. .condition {
  372. position: absolute;
  373. top: 770rpx;
  374. display: flex;
  375. flex-wrap: wrap;
  376. width: 90%;
  377. left: 5%;
  378. box-shadow: 0 0 10rpx #bcb9ca;
  379. margin-bottom: 30rpx;
  380. .scroll-X {
  381. width: 95%;
  382. margin: 20rpx auto;
  383. .table{
  384. width: 1672px;
  385. }
  386. .tr {
  387. display: flex;
  388. overflow: hidden;
  389. .th,
  390. .td {
  391. display: inline-block;
  392. padding: 5rpx;
  393. width: 240rpx;
  394. text-align: center;
  395. height: 52rpx;
  396. line-height: 52rpx;
  397. border: 2rpx solid #F1F1F1;
  398. }
  399. .th:first-child,
  400. .td:first-child {
  401. width: 300rpx;
  402. }
  403. }
  404. }
  405. .pagenumber {
  406. display: flex;
  407. margin: 20rpx auto;
  408. button {
  409. width: 150rpx;
  410. height: 50rpx;
  411. line-height: 50rpx;
  412. font-size: 26rpx;
  413. text-align: center;
  414. background-color: #17BB89;
  415. color: #FFFFFF;
  416. }
  417. .pagenumber_page {
  418. width: 100rpx;
  419. height: 50rpx;
  420. line-height: 50rpx;
  421. font-size: 26rpx;
  422. text-align: center;
  423. }
  424. }
  425. }
  426. </style>