bzyhistoryile.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. <template>
  2. <view>
  3. <view class="status_bar"></view>
  4. <view class="" style="position: relative;top: 40px;">
  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 && !dataloadingtf">
  16. 暂无数据
  17. </view>
  18. <view class="canvastishi" v-if="dataloadingtf">
  19. <p class="dataloading">加载中</p>
  20. </view>
  21. <canvas v-if="canvastishiTF" canvas-id="canvasColumnA" id="canvasColumnA" class="charts" @touchstart="touchLineA($event)"
  22. @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>
  23. </view>
  24. <view class="refresh" @click="refresh">
  25. 刷 新
  26. </view>
  27. <view class="condition">
  28. <scroll-view scroll-x="true" class="scroll-X" scroll-top="0">
  29. <table class="table" v-if="$QueryPermission(265)">
  30. <tr class="tr">
  31. <th class="th" v-for="(item,index) in thdata" :key="index">{{item}}</th>
  32. </tr>
  33. <tr class="tr" v-for="(items,indexs) in historylistdata" :key="indexs" v-if="!forbidden">
  34. <td class="td">{{items.d_h_t.addtime|timeFormat()}}</td>
  35. <td class="td">{{items.d_h_t.ds==0?"关":"开"}}</td>
  36. <td class="td">{{items.d_h_t.at}}</td>
  37. <td class="td">{{items.d_h_t.ah}}</td>
  38. <td class="td">{{items.d_h_t.set_temp}}</td>
  39. <td class="td">{{items.d_h_t.pre_temp}}</td>
  40. <td class="td">{{items.d_h_t.batStatus==0?"正常":"欠压"}}</td>
  41. <td class="td">{{items.d_h_t.rps==0?"正常":"雨控"}}</td>
  42. <td class="td">{{Circulation.work_sta.value[items.d_h_t.work_sta]}}</td>
  43. <td class="td">{{items.d_h_t.csq}}</td>
  44. <td class="td">{{items.d_h_t.current}}</td>
  45. <td class="td">{{items.d_h_t.vbat}}</td>
  46. <td class="td">{{items.d_h_t.dver}}</td>
  47. </tr>
  48. <tr class="tr" v-if="forbidden">
  49. <td class="td" v-for="item in 13" :key="item">暂无数据</td>
  50. </tr>
  51. </table>
  52. <table class="table" v-else>
  53. <tr class="tr">
  54. <th class="th" v-for="(item,index) in thdata2" :key="index">{{item}}</th>
  55. </tr>
  56. <tr class="tr" v-for="(items,indexs) in historylistdata" :key="indexs" v-if="!forbidden">
  57. <td class="td">{{items.d_h_t.addtime|timeFormat()}}</td>
  58. <td class="td">{{items.d_h_t.ds==0?"关":"开"}}</td>
  59. <td class="td">{{items.d_h_t.at}}</td>
  60. <td class="td">{{items.d_h_t.ah}}</td>
  61. <td class="td">{{items.d_h_t.set_temp}}</td>
  62. <td class="td">{{items.d_h_t.pre_temp}}</td>
  63. <td class="td">{{items.d_h_t.batStatus==0?"正常":"欠压"}}</td>
  64. <td class="td">{{items.d_h_t.rps==0?"正常":"雨控"}}</td>
  65. <td class="td">{{Circulation.work_sta.value[items.d_h_t.work_sta]}}</td>
  66. <td class="td">{{items.d_h_t.dver}}</td>
  67. </tr>
  68. <tr class="tr" v-if="forbidden">
  69. <td class="td" v-for="item in 10" :key="item">暂无数据</td>
  70. </tr>
  71. </table>
  72. </scroll-view>
  73. <view class="pagenumber">
  74. <button @click="prev">上一页</button>
  75. <view class="pagenumber_page">
  76. 第 {{page}} 页
  77. </view>
  78. <view class="pagenumber_page">
  79. 共 {{pagesum}} 页
  80. </view>
  81. <button @click="next" :disabled="forbidden">下一页</button>
  82. </view>
  83. </view>
  84. </view>
  85. </view>
  86. </template>
  87. <script>
  88. import uCharts from '../../../../components/js_sdk/u-charts/u-charts/u-charts.js';
  89. import Circulation from "../../../../static/js/equipState_dict.json"
  90. var canvaColumnA = null;
  91. export default {
  92. data() {
  93. return {
  94. styles: {
  95. // width: "650rpx",
  96. height: "400rpx"
  97. },
  98. d_id: '',
  99. start_time: "",
  100. end_time: "",
  101. historydatas: [],
  102. titletext: ["24小时", "近一个月", "近半年", "近一年"],
  103. titleidnex: 0,
  104. device_id: '',
  105. page: 1,
  106. pagesum: 1,
  107. historylistdata: [],
  108. thdata: ["上报时间", "设备开关", "环境温度(°C)", "环境湿度(%)", "保温仓设定温度(°C)", "保温仓当前温度(°C)", "电池状态", "雨控状态", "工作状态",
  109. "信号强度", "电流(mA)", "电压(V)", "设备版本"
  110. ],
  111. thdata2: ["上报时间", "设备开关", "环境温度(°C)", "环境湿度(%)", "保温仓设定温度(°C)", "保温仓当前温度(°C)", "电池状态", "雨控状态", "工作状态",
  112. "设备版本"
  113. ],
  114. forbidden: false,
  115. canvastishiTF: false,//暂无数据提示
  116. dataloadingtf:true,//加载中提示
  117. cWidth: '400',
  118. cHeight: '400',
  119. pixelRatio: 1,
  120. Circulation:Circulation
  121. }
  122. },
  123. methods: {
  124. //forecast.worm_lamp.device_polyline_data 历史数据折线图
  125. // device_type_id 必传(string) 设备类型 3虫情测报灯 7孢子仪 4智能性诱 2杀虫灯 9糖醋测报灯 10测报灯rtu
  126. // d_id 必传 设备id
  127. // start_time 非必传(string 时间戳) 开始时间 (用于时间搜索)
  128. // end_time
  129. async history() {
  130. this.dataloadingtf = true
  131. const res = await this.$myRequest({
  132. url: '/api/api_gateway?method=forecast.worm_lamp.device_polyline_data',
  133. data: {
  134. device_type_id: 7,
  135. d_id: this.d_id,
  136. start_time: parseInt(this.start_time / 1000),
  137. end_time: parseInt(this.end_time / 1000)
  138. }
  139. })
  140. this.dataloadingtf = false
  141. console.log(res)
  142. this.historydatas = res
  143. console.log(this.historydatas)
  144. if (this.historydatas.length == 0) {
  145. this.canvastishiTF = false
  146. } else {
  147. this.canvastishiTF = true
  148. var arr1 = []
  149. var arr2 = []
  150. var arr3 = []
  151. var xtitle = []
  152. for (var i = 0; i < res.length; i++) {
  153. var times = new Date(res[i].addtime * 1000)
  154. xtitle.push(times.getMonth() + 1 + "/" + times.getDate() + "-" + times.getHours() + ":" + times.getMinutes())
  155. arr1.push(res[i].temperature == "" ? "0" : res[i].temperature)
  156. arr2.push(res[i].humidity == "" ? "0" : res[i].humidity)
  157. arr3.push(res[i].others == "" ? "0" : res[i].others)
  158. }
  159. var obj = [{
  160. name: '温度',
  161. data: arr1,
  162. color: '#00E29D'
  163. }, {
  164. name: '湿度',
  165. data: arr2,
  166. color: '#6CBBFF'
  167. }, {
  168. name: '保温仓温度',
  169. data: arr3,
  170. color: '#FF3F3F'
  171. }]
  172. this.showColumn("canvasColumnA", xtitle, obj)
  173. }
  174. },
  175. //forecast.worm_lamp.device_history_data历史数据列表
  176. async historylist() {
  177. const res = await this.$myRequest({
  178. url: '/api/api_gateway?method=forecast.worm_lamp.device_history_data',
  179. data: {
  180. device_type_id: 7,
  181. device_id: this.device_id,
  182. start_time: parseInt(this.start_time / 1000),
  183. end_time: parseInt(this.end_time / 1000),
  184. page: this.page
  185. }
  186. })
  187. this.historylistdata = res.data
  188. this.pagesum = Math.ceil(res.counts / 10) || 1
  189. if (res.data.length == 0) {
  190. this.forbidden = true
  191. console.log(res.data.length)
  192. } else {
  193. this.forbidden = false
  194. console.log(res.data.length)
  195. }
  196. // console.log(this.historylistdata)
  197. },
  198. changeindex(index) {
  199. this.titleidnex = index
  200. var now = new Date()
  201. this.$forceUpdate()
  202. if (index == 0) {
  203. this.start_time = this.end_time - 24 * 60 * 60 * 1000
  204. this.history()
  205. this.historylist()
  206. } else if (index == 1) {
  207. var oldtime = now.setMonth(now.getMonth() - 1)
  208. this.start_time = parseInt(oldtime)
  209. this.history()
  210. this.historylist()
  211. } else if (index == 2) {
  212. var oldtime = now.setMonth(now.getMonth() - 6)
  213. this.start_time = parseInt(oldtime)
  214. this.history()
  215. this.historylist()
  216. } else if (index == 3) {
  217. var oldtime = now.setFullYear(now.getFullYear() - 1)
  218. this.start_time = parseInt(oldtime)
  219. this.history()
  220. this.historylist()
  221. }
  222. },
  223. prev() { //上一页
  224. if (this.page > 1) {
  225. this.page--
  226. this.historylist()
  227. }
  228. },
  229. next() { //下一页
  230. this.page++
  231. this.historylist()
  232. },
  233. clickLeft() {
  234. uni.navigateBack({
  235. delta: 1
  236. })
  237. },
  238. showColumn(id, xtitle, xinfo) {
  239. var _self = this
  240. canvaColumnA = new uCharts({
  241. canvasId: id,
  242. type: 'line',
  243. legend: {
  244. position: "top"
  245. },
  246. fontSize: 11,
  247. background: '#FFFFFF',
  248. pixelRatio: 1,
  249. animation: true,
  250. dataLabel: false,
  251. categories: xtitle,
  252. series: xinfo,
  253. enableScroll: true, //开启图表拖拽功能
  254. xAxis: {
  255. disableGrid: true,
  256. type: 'grid',
  257. gridType: 'dash',
  258. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  259. scrollShow: true, //新增是否显示滚动条,默认false
  260. // scrollAlign: 'left', //滚动条初始位置
  261. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  262. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  263. },
  264. yAxis: {},
  265. width: _self.cWidth * 1,
  266. height: _self.cHeight * 1,
  267. extra: {
  268. line: {
  269. type: 'curve'
  270. }
  271. }
  272. });
  273. },
  274. touchLineA(e) {
  275. console.log(e)
  276. canvaColumnA.scrollStart(e);
  277. },
  278. moveLineA(e) {
  279. canvaColumnA.scroll(e);
  280. },
  281. touchEndLineA(e) {
  282. canvaColumnA.scrollEnd(e);
  283. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  284. canvaColumnA.showToolTip(e, {
  285. format: function(item, category) {
  286. return category + ' ' + item.name + ':' + item.data
  287. }
  288. });
  289. },
  290. async newdata() {
  291. const res = await this.$myRequest({
  292. url: '/api/api_gateway?method=forecast.send_control.get_device_config',
  293. data: {
  294. device_type_id: 7,
  295. d_id: this.d_id,
  296. control_type: "data"
  297. }
  298. })
  299. if(res){
  300. uni.showToast({
  301. title: '刷新成功',
  302. duration: 2000,
  303. icon: "none"
  304. });
  305. }else{
  306. uni.showToast({
  307. title: '刷新失败',
  308. duration: 2000,
  309. icon: "none"
  310. });
  311. }
  312. },
  313. refresh() { //获取当前时间的数据
  314. this.newdata()
  315. },
  316. },
  317. onLoad(option) {
  318. this.d_id = option.d_id
  319. this.device_id = option.device_id
  320. this.cWidth = uni.upx2px(650);
  321. this.cHeight = uni.upx2px(500);
  322. },
  323. onShow() {
  324. this.end_time = +new Date()
  325. this.start_time = this.end_time - 24 * 60 * 60 * 1000
  326. setTimeout(()=>{
  327. this.history()
  328. this.historylist()
  329. },1000)
  330. }
  331. }
  332. </script>
  333. <style lang="scss">
  334. .shuju_one,
  335. .shuju_two {
  336. position: absolute;
  337. top: 54px;
  338. width: 90%;
  339. left: 5%;
  340. box-shadow: 0 0 10rpx #bcb9ca;
  341. padding-top: 20rpx;
  342. height: 550rpx;
  343. .canvastishi {
  344. font-size: 32rpx;
  345. position: absolute;
  346. top: 50%;
  347. left: 50%;
  348. margin-left: -64rpx;
  349. margin-top: -21rpx;
  350. .dataloading:after {
  351. overflow: hidden;
  352. display: inline-block;
  353. vertical-align: bottom;
  354. animation: ellipsis 2s infinite;
  355. content: "\2026";
  356. }
  357. @keyframes ellipsis {
  358. from {
  359. width: 2px;
  360. }
  361. to {
  362. width: 15px;
  363. }
  364. }
  365. }
  366. .shuju_one_title {
  367. width: 70%;
  368. margin: 0 auto;
  369. display: flex;
  370. .tltle_text {
  371. width: 25%;
  372. border: 2rpx solid #B2B2B2;
  373. color: #B2B2B2;
  374. text-align: center;
  375. font-size: 24rpx;
  376. height: 50rpx;
  377. line-height: 50rpx;
  378. }
  379. .title_text_color {
  380. width: 25%;
  381. border: 2rpx solid #28AE4F;
  382. color: #28AE4F;
  383. text-align: center;
  384. font-size: 24rpx;
  385. height: 50rpx;
  386. line-height: 50rpx;
  387. }
  388. }
  389. }
  390. .refresh {
  391. position: absolute;
  392. top: 700rpx;
  393. left: 5%;
  394. width: 160rpx;
  395. height: 50rpx;
  396. background-color: #28AE4F;
  397. color: #FFFFFF;
  398. line-height: 50rpx;
  399. text-align: center;
  400. }
  401. .condition {
  402. position: absolute;
  403. top: 770rpx;
  404. display: flex;
  405. flex-wrap: wrap;
  406. width: 90%;
  407. left: 5%;
  408. box-shadow: 0 0 10rpx #bcb9ca;
  409. margin-bottom: 30rpx;
  410. .scroll-X {
  411. width: 95%;
  412. margin: 20rpx auto;
  413. .table{
  414. width: 1672px;
  415. }
  416. .tr {
  417. display: flex;
  418. overflow: hidden;
  419. .th,
  420. .td {
  421. display: inline-block;
  422. padding: 5rpx;
  423. width: 300rpx;
  424. text-align: center;
  425. height: 52rpx;
  426. line-height: 52rpx;
  427. border: 2rpx solid #F1F1F1;
  428. }
  429. .th:first-child,
  430. .td:first-child {
  431. width: 300rpx;
  432. }
  433. }
  434. .tr:nth-child(2n-1){
  435. background-color: #f5fff8;
  436. }
  437. .tr:first-child{
  438. background-color: #57c878;
  439. color: #fff;
  440. }
  441. }
  442. .pagenumber {
  443. display: flex;
  444. margin: 20rpx auto;
  445. button {
  446. width: 150rpx;
  447. height: 50rpx;
  448. line-height: 50rpx;
  449. font-size: 26rpx;
  450. text-align: center;
  451. background-color: #17BB89;
  452. color: #FFFFFF;
  453. margin: 0 10rpx;
  454. }
  455. .pagenumber_page {
  456. width: 100rpx;
  457. height: 50rpx;
  458. line-height: 50rpx;
  459. font-size: 26rpx;
  460. text-align: center;
  461. }
  462. }
  463. }
  464. </style>