historydatas.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. <template>
  2. <view>
  3. <view class="">
  4. <view class="shuju_one">
  5. <view class="shuju_one_title">
  6. <view :class="titleidnex==index?'title_text_color':'tltle_text'" v-for="(item,index) in titletext" :key="index"
  7. @click="changeindex(index)">
  8. {{item}}
  9. </view>
  10. </view>
  11. <view class="canvastishi" v-if="!canvastishiTF">
  12. 暂无数据
  13. </view>
  14. <canvas v-if="canvastishiTF" canvas-id="canvasColumnA" id="canvasColumnA" class="charts" @touchstart="touchLineA($event)"
  15. @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>
  16. </view>
  17. <view class="refresh" @click="refresh">
  18. 刷 新
  19. </view>
  20. <view class="condition">
  21. <scroll-view scroll-top="0" scroll-x="true" class="scroll-X">
  22. <table class="table">
  23. <tr class="tr">
  24. <th class="th" v-for="(item,index) in thdata" :key="'a'+index">{{item}}</th>
  25. </tr>
  26. <tr class="tr" v-for="(items,indexs) in historylistdata" :key="'b'+indexs" v-if="!forbidden">
  27. <td class="td">{{items.xy_addtime|timeFormat()}}</td>
  28. <td class="td">{{items.at==""?"--":items.at}}</td>
  29. <td class="td">{{items.ah==""?"--":items.ah}}</td>
  30. <td class="td">{{items.warn==""?"--":items.warn}}</td>
  31. <td class="td">{{items.b_V==""?"--":items.b_V}}</td>
  32. <td class="td">{{items.b_c==""?"--":items.b_c}}</td>
  33. <td class="td">{{items.p_v==""?"--":items.p_v}}</td>
  34. <td class="td">{{items.p_c==""?"--":items.p_c}}</td>
  35. </tr>
  36. <tr class="tr" v-if="forbidden">
  37. <td class="td" v-for="item in 8">暂无数据</td>
  38. </tr>
  39. </table>
  40. </scroll-view>
  41. <view class="pagenumber">
  42. <button @click="prev">上一页</button>
  43. <view class="pagenumber_page">
  44. 第 {{page}} 页
  45. </view>
  46. <view class="pagenumber_page">
  47. 共 {{pagesum}} 页
  48. </view>
  49. <button @click="next" :disabled="forbidden">下一页</button>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. </template>
  55. <script>
  56. import uCharts from '../../../components/js_sdk/u-charts/u-charts/u-charts.js';
  57. var canvaColumnA = null;
  58. export default {
  59. data() {
  60. return {
  61. styles: {
  62. // width: "650rpx",
  63. height: "400rpx"
  64. },
  65. d_id: '',
  66. start_time: "",
  67. end_time: "",
  68. historydatas: [],
  69. titletext: ["24小时", "近一个月", "近半年", "近一年"],
  70. titleidnex: 0,
  71. device_id: '',
  72. page: 1,
  73. historylistdata: [],
  74. thdata: ["上报时间", "环境温度(°C)", "环境湿度(%)", "虫害预警", "电池电压", "电池电流", "太阳能板电压", "太阳能板电流"],
  75. forbidden: false,
  76. cWidth: '400',
  77. cHeight: '400',
  78. pixelRatio: 1,
  79. canvastishiTF: false,
  80. pagesum: null,
  81. worms:[]
  82. }
  83. },
  84. methods: {
  85. async history() { //历史数据列表折线图
  86. this.Chistory()
  87. const res = await this.$myRequest({
  88. url: '/api/api_gateway?method=sex_lure_nl.sex_lure.nl_device_line_chart',
  89. data: {
  90. device_id: this.device_id,
  91. strat_time: parseInt(this.start_time / 1000),
  92. end_time: parseInt(this.end_time / 1000),
  93. status: "at_ah"
  94. }
  95. })
  96. this.historydatas = res
  97. console.log(this.historydatas)
  98. if (this.historydatas.length == 0) {
  99. this.canvastishiTF = false
  100. } else {
  101. this.canvastishiTF = true
  102. var arr1 = []
  103. var arr2 = []
  104. var arr3 = []
  105. var xtitle = []
  106. for (var i = 0; i < res.length; i++) {
  107. var times = new Date(res[i].xy_addtime)
  108. xtitle.unshift(times.getMonth() + 1 + "/" + times.getDate() + "-" + times.getHours() + ":" + times.getMinutes())
  109. arr1.unshift(res[i].ah == "" ? "0" : res[i].ah)
  110. arr2.unshift(res[i].at == "" ? "0" : res[i].at)
  111. }
  112. for(var j = 0; j < this.worms.length; j++){
  113. var times = new Date(res[i].xy_addtime)
  114. arr3.unshift(res[i].pest_num == "" ? "0" : res[i].pest_num)
  115. }
  116. this.$nextTick(()=>{
  117. var obj = [{
  118. name: '温度',
  119. data: arr1,
  120. color: '#00E29D'
  121. }, {
  122. name: '湿度',
  123. data: arr2,
  124. color: '#6CBBFF'
  125. },{
  126. name: '诱虫次数',
  127. data: arr3,
  128. color: '#ff0000'
  129. }]
  130. this.showColumn("canvasColumnA", xtitle, obj)
  131. })
  132. }
  133. },
  134. async Chistory() { //历史数据列表折线图
  135. const res = await this.$myRequest({
  136. url: '/api/api_gateway?method=sex_lure_nl.sex_lure.nl_device_line_chart',
  137. data: {
  138. device_id: this.device_id,
  139. strat_time: parseInt(this.start_time / 1000),
  140. end_time: parseInt(this.end_time / 1000),
  141. status: "pest"
  142. }
  143. })
  144. this.worms = res
  145. },
  146. //forecast.worm_lamp.device_history_data历史数据列表
  147. async historylist() { //历史数据列表
  148. const res = await this.$myRequest({
  149. url: '/api/api_gateway?method=sex_lure_nl.sex_lure.nl_device_history',
  150. data: {
  151. device_type_id: 3,
  152. device_id: this.device_id,
  153. strat_time: parseInt(this.start_time / 1000),
  154. end_time: parseInt(this.end_time / 1000),
  155. page: this.page
  156. }
  157. })
  158. this.historylistdata = res.data
  159. console.log(res.data)
  160. this.pagesum = Math.ceil(res.nums / 10) + 1
  161. if (res.data.length == 0) {
  162. this.forbidden = true
  163. } else {
  164. this.forbidden = false
  165. }
  166. console.log(this.historylistdata)
  167. },
  168. // forecast.send_control.get_device_config 获取当前时间的数据
  169. async newdata() {
  170. const res = await this.$myRequest({
  171. url: '/api/api_gateway?method=sex_lure_nl.sex_lure.nl_device_mqtt',
  172. data: {
  173. d_id: this.d_id
  174. }
  175. })
  176. if(res){
  177. uni.showToast({
  178. title: '刷新成功',
  179. duration: 2000,
  180. icon: "none"
  181. });
  182. uni.navigateBack({
  183. delta: 1
  184. })
  185. }else{
  186. uni.showToast({
  187. title: '刷新失败',
  188. duration: 2000,
  189. icon: "none"
  190. });
  191. }
  192. },
  193. refresh() { //获取当前时间的数据
  194. this.newdata()
  195. },
  196. changeindex(index) {
  197. this.titleidnex = index
  198. var now = new Date()
  199. this.$forceUpdate()
  200. if (index == 0) {
  201. this.start_time = this.end_time - 24 * 60 * 60 * 1000
  202. this.history()
  203. this.historylist()
  204. } else if (index == 1) {
  205. var oldtime = now.setMonth(now.getMonth() - 1)
  206. this.start_time = parseInt(oldtime)
  207. this.history()
  208. this.historylist()
  209. } else if (index == 2) {
  210. var oldtime = now.setMonth(now.getMonth() - 6)
  211. this.start_time = parseInt(oldtime)
  212. this.history()
  213. this.historylist()
  214. } else if (index == 3) {
  215. var oldtime = now.setFullYear(now.getFullYear() - 1)
  216. this.start_time = parseInt(oldtime)
  217. this.history()
  218. this.historylist()
  219. }
  220. },
  221. prev() { //上一页
  222. if (this.page > 1) {
  223. this.page--
  224. this.historylist()
  225. }
  226. },
  227. next() { //下一页
  228. this.page++
  229. this.historylist()
  230. },
  231. clickLeft() {
  232. uni.navigateBack({
  233. delta: 1
  234. })
  235. },
  236. showColumn(id, xtitle, xinfo) {
  237. var _self = this
  238. canvaColumnA = new uCharts({
  239. canvasId: id,
  240. type: 'line',
  241. legend: {
  242. position: "top"
  243. },
  244. fontSize: 11,
  245. background: '#FFFFFF',
  246. pixelRatio: 1,
  247. animation: true,
  248. dataLabel: false,
  249. categories: xtitle,
  250. series: xinfo,
  251. enableScroll: true, //开启图表拖拽功能
  252. xAxis: {
  253. disableGrid: true,
  254. type: 'grid',
  255. gridType: 'dash',
  256. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  257. scrollShow: true, //新增是否显示滚动条,默认false
  258. // scrollAlign: 'left', //滚动条初始位置
  259. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  260. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  261. },
  262. yAxis: {},
  263. width: _self.cWidth * 1,
  264. height: _self.cHeight * 1,
  265. extra: {
  266. line: {
  267. type: 'curve'
  268. }
  269. }
  270. });
  271. },
  272. touchLineA(e) {
  273. console.log(e)
  274. canvaColumnA.scrollStart(e);
  275. },
  276. moveLineA(e) {
  277. canvaColumnA.scroll(e);
  278. },
  279. touchEndLineA(e) {
  280. canvaColumnA.scrollEnd(e);
  281. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  282. canvaColumnA.showToolTip(e, {
  283. format: function(item, category) {
  284. return category + ' ' + item.name + ':' + item.data
  285. }
  286. });
  287. },
  288. },
  289. onLoad(option) {
  290. console.log(option)
  291. this.d_id = option.d_id
  292. this.device_id = option.device_id
  293. this.cWidth = uni.upx2px(650);
  294. this.cHeight = uni.upx2px(500);
  295. },
  296. onShow(){
  297. this.end_time = +new Date() + 1000
  298. this.start_time = this.end_time - 24 * 60 * 60 * 1000
  299. setTimeout(()=>{
  300. this.history()
  301. this.historylist()
  302. },1000)
  303. }
  304. }
  305. </script>
  306. <style lang="scss">
  307. .shuju_one,
  308. .shuju_two {
  309. position: absolute;
  310. top: 10px;
  311. width: 90%;
  312. left: 5%;
  313. box-shadow: 0 0 10rpx #bcb9ca;
  314. padding-top: 20rpx;
  315. height: 550rpx;
  316. .canvastishi {
  317. font-size: 32rpx;
  318. position: absolute;
  319. top: 50%;
  320. left: 50%;
  321. margin-left: -64rpx;
  322. margin-top: -21rpx;
  323. }
  324. .shuju_one_title {
  325. width: 70%;
  326. margin: 0 auto;
  327. display: flex;
  328. .tltle_text {
  329. width: 25%;
  330. border: 2rpx solid #B2B2B2;
  331. color: #B2B2B2;
  332. text-align: center;
  333. font-size: 24rpx;
  334. height: 50rpx;
  335. line-height: 50rpx;
  336. }
  337. .title_text_color {
  338. width: 25%;
  339. border: 2rpx solid #28AE4F;
  340. color: #28AE4F;
  341. text-align: center;
  342. font-size: 24rpx;
  343. height: 50rpx;
  344. line-height: 50rpx;
  345. }
  346. }
  347. }
  348. .refresh {
  349. position: absolute;
  350. top: 630rpx;
  351. left: 5%;
  352. width: 160rpx;
  353. height: 50rpx;
  354. background-color: #28AE4F;
  355. color: #FFFFFF;
  356. line-height: 50rpx;
  357. text-align: center;
  358. }
  359. .condition {
  360. position: absolute;
  361. top: 720rpx;
  362. display: flex;
  363. flex-wrap: wrap;
  364. width: 90%;
  365. left: 5%;
  366. box-shadow: 0 0 10rpx #bcb9ca;
  367. margin-bottom: 30rpx;
  368. .scroll-X {
  369. width: 95%;
  370. margin: 20rpx auto;
  371. .table{
  372. width: 1042px;
  373. }
  374. .tr {
  375. display: flex;
  376. overflow: hidden;
  377. .th,
  378. .td {
  379. display: inline-block;
  380. padding: 5rpx;
  381. width: 240rpx;
  382. text-align: center;
  383. height: 52rpx;
  384. line-height: 52rpx;
  385. border: 2rpx solid #F1F1F1;
  386. }
  387. .th:first-child,
  388. .td:first-child {
  389. width: 300rpx;
  390. }
  391. }
  392. }
  393. .pagenumber {
  394. display: flex;
  395. margin: 20rpx auto;
  396. button {
  397. width: 150rpx;
  398. height: 50rpx;
  399. line-height: 50rpx;
  400. font-size: 26rpx;
  401. text-align: center;
  402. background-color: #17BB89;
  403. color: #FFFFFF;
  404. }
  405. .pagenumber_page {
  406. width: 100rpx;
  407. height: 50rpx;
  408. line-height: 50rpx;
  409. font-size: 26rpx;
  410. text-align: center;
  411. }
  412. }
  413. }
  414. </style>