historyfile.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. <template>
  2. <view>
  3. <view class="status_bar"></view>
  4. <view class="" style="position: relative;top: 64px;">
  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. const res = await this.$myRequest({
  142. url: '/api/api_gateway?method=forecast.worm_lamp.device_history_data',
  143. data: {
  144. device_type_id: 3,
  145. device_id: this.device_id,
  146. start_time: parseInt(this.start_time / 1000),
  147. end_time: parseInt(this.end_time / 1000),
  148. page: this.page
  149. }
  150. })
  151. this.historylistdata = res.data
  152. this.pagesum = Math.ceil(res.counts / 10) + 1
  153. if (res.data.length == 0) {
  154. this.forbidden = true
  155. console.log(res.data.length)
  156. } else {
  157. this.forbidden = false
  158. console.log(res.data.length)
  159. }
  160. for (var i = 0; i < this.historylistdata.length; i++) {
  161. if (Number(this.historylistdata[i].d_h_t.ws) == 0) {
  162. this.historylistdata[i].d_h_t.dg = "待机"
  163. } else if (Number(this.historylistdata[i].d_h_t.ws) == 1) {
  164. if (Number(this.historylistdata[i].d_h_t.lamp) == 0) {
  165. this.historylistdata[i].d_h_t.dg = "工作"
  166. } else if (Number(this.historylistdata[i].d_h_t.lamp) == 1) {
  167. this.historylistdata[i].d_h_t.dg = "异常"
  168. }
  169. }
  170. }
  171. console.log(this.historylistdata)
  172. },
  173. // forecast.send_control.get_device_config 获取当前时间的数据
  174. async newdata() {
  175. const res = await this.$myRequest({
  176. url: '/api/api_gateway?method=forecast.send_control.get_device_config',
  177. data: {
  178. device_type_id: 3,
  179. d_id: this.d_id,
  180. control_type: "data"
  181. }
  182. })
  183. if(res){
  184. uni.showToast({
  185. title: '刷新成功',
  186. duration: 2000,
  187. icon: "none"
  188. });
  189. uni.navigateBack({
  190. delta: 1
  191. })
  192. }else{
  193. uni.showToast({
  194. title: '刷新失败',
  195. duration: 2000,
  196. icon: "none"
  197. });
  198. }
  199. },
  200. refresh() { //获取当前时间的数据
  201. this.newdata()
  202. },
  203. changeindex(index) {
  204. this.titleidnex = index
  205. var now = new Date()
  206. this.$forceUpdate()
  207. if (index == 0) {
  208. this.start_time = this.end_time - 24 * 60 * 60 * 1000
  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: 4, //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. },
  302. onShow(){
  303. this.end_time = +new Date() + 1000
  304. this.start_time = this.end_time - 24 * 60 * 60 * 1000
  305. setTimeout(()=>{
  306. this.history()
  307. this.historylist()
  308. },1000)
  309. }
  310. }
  311. </script>
  312. <style lang="scss">
  313. .shuju_one,
  314. .shuju_two {
  315. position: absolute;
  316. top: 54px;
  317. width: 90%;
  318. left: 5%;
  319. box-shadow: 0 0 10rpx #bcb9ca;
  320. padding-top: 20rpx;
  321. height: 550rpx;
  322. .canvastishi {
  323. font-size: 32rpx;
  324. position: absolute;
  325. top: 50%;
  326. left: 50%;
  327. margin-left: -64rpx;
  328. margin-top: -21rpx;
  329. }
  330. .shuju_one_title {
  331. width: 70%;
  332. margin: 0 auto;
  333. display: flex;
  334. .tltle_text {
  335. width: 25%;
  336. border: 2rpx solid #B2B2B2;
  337. color: #B2B2B2;
  338. text-align: center;
  339. font-size: 24rpx;
  340. height: 50rpx;
  341. line-height: 50rpx;
  342. }
  343. .title_text_color {
  344. width: 25%;
  345. border: 2rpx solid #28AE4F;
  346. color: #28AE4F;
  347. text-align: center;
  348. font-size: 24rpx;
  349. height: 50rpx;
  350. line-height: 50rpx;
  351. }
  352. }
  353. }
  354. .refresh {
  355. position: absolute;
  356. top: 700rpx;
  357. left: 5%;
  358. width: 160rpx;
  359. height: 50rpx;
  360. background-color: #28AE4F;
  361. color: #FFFFFF;
  362. line-height: 50rpx;
  363. text-align: center;
  364. }
  365. .condition {
  366. position: absolute;
  367. top: 770rpx;
  368. display: flex;
  369. flex-wrap: wrap;
  370. width: 90%;
  371. left: 5%;
  372. box-shadow: 0 0 10rpx #bcb9ca;
  373. margin-bottom: 30rpx;
  374. .scroll-X {
  375. width: 95%;
  376. margin: 20rpx auto;
  377. .table{
  378. width: 1672px;
  379. }
  380. .tr {
  381. display: flex;
  382. overflow: hidden;
  383. .th,
  384. .td {
  385. display: inline-block;
  386. padding: 5rpx;
  387. width: 240rpx;
  388. text-align: center;
  389. height: 52rpx;
  390. line-height: 52rpx;
  391. border: 2rpx solid #F1F1F1;
  392. }
  393. .th:first-child,
  394. .td:first-child {
  395. width: 300rpx;
  396. }
  397. }
  398. }
  399. .pagenumber {
  400. display: flex;
  401. margin: 20rpx auto;
  402. button {
  403. width: 150rpx;
  404. height: 50rpx;
  405. line-height: 50rpx;
  406. font-size: 26rpx;
  407. text-align: center;
  408. background-color: #17BB89;
  409. color: #FFFFFF;
  410. }
  411. .pagenumber_page {
  412. width: 100rpx;
  413. height: 50rpx;
  414. line-height: 50rpx;
  415. font-size: 26rpx;
  416. text-align: center;
  417. }
  418. }
  419. }
  420. </style>