elementdata.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. <template>
  2. <view>
  3. <view class="">
  4. <view class="selecttimes" @click="tiemshow=!tiemshow">
  5. <view class="timesbox">
  6. <image
  7. :src="'http://www.hnyfwlw.com:8006/bigdata_app'+'/image/prevention/1acfe2751c01d3786cdc49b83d7e505.png'"
  8. mode=""></image>
  9. <p>{{timetab(oldtime)}}</p>
  10. <p class="or">~</p>
  11. <p>{{timetab(newtime)}}</p>
  12. <u-icon name="rili" custom-prefix="custom-icon" class="icon"></u-icon>
  13. </view>
  14. <u-calendar v-model="tiemshow" mode="range" @change="tiemchange"></u-calendar>
  15. </view>
  16. <view class="shuju_one">
  17. <view class="canvastishi" v-if="!canvastishiTF && !dataloadingtf">
  18. 暂无数据
  19. </view>
  20. <view class="canvastishi" v-if="dataloadingtf">
  21. <p class="dataloading">加载中</p>
  22. </view>
  23. <canvas v-if="canvastishiTF" v-show="!tiemshow" canvas-id="canvasColumnA" id="canvasColumnA" class="charts"
  24. @touchstart="touchLineA($event)" @touchmove="moveLineA($event)" @touchend="touchEndLineA($event)"
  25. disable-scroll=true
  26. :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>
  27. </view>
  28. <view class="refresh" @click="refresh">
  29. 刷 新
  30. </view>
  31. <view class="condition">
  32. <scroll-view scroll-top="0" scroll-x="true" class="scroll-X">
  33. <table class="table">
  34. <tr class="tr">
  35. <th class="th" v-for="(item,index) in thdata" :key="'a'+index">{{item}}</th>
  36. </tr>
  37. <tr class="tr" v-for="(items,indexs) in eqlistdata[0].length" :key="'b'+indexs">
  38. <td class="td" v-for="(item,index) in eqlistdata" :key="'c'+index">{{item[indexs]}}</td>
  39. <!-- |timeFormat() -->
  40. </tr>
  41. <tr class="tr" v-if="!forbidden">
  42. <td class="td" v-for="item in 12">暂无数据</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. <style lang="scss">
  61. </style>
  62. <script>
  63. import uCharts from '../../components/js_sdk/u-charts/u-charts/u-charts.js';
  64. var canvaColumnA = null;
  65. var presenttime = null
  66. // var oldpresenttime = presenttime - 24*60*60*1000
  67. export default {
  68. data() {
  69. return {
  70. thdata: ["上报时间"],
  71. eqlistdata: [[]],
  72. cWidth: '400',
  73. cHeight: '400',
  74. pixelRatio: 1,
  75. oldtime: '',
  76. newtime: '',
  77. page: 1,
  78. forbidden: false, //暂无数据
  79. times: {
  80. d_id: null,
  81. start_time: null,
  82. end_time: null,
  83. device_id: null
  84. },
  85. canvastishiTF: false, //折线图暂无数据提示
  86. dataloadingtf: true, //加载中提示
  87. pagesum: 1,
  88. tiemshow: false, //日历选择器
  89. }
  90. },
  91. // 页面加载执行的函数
  92. onLoad(option) {
  93. this.times.device_id = option.device_id
  94. // this.times.imei = option.imei
  95. this.cWidth = uni.upx2px(650);
  96. this.cHeight = uni.upx2px(500);
  97. presenttime = +new Date();
  98. this.oldtime = parseInt((presenttime - 30 * 24 * 60 * 60 * 1000) / 1000)
  99. this.newtime = parseInt(presenttime / 1000)
  100. setTimeout(() => {
  101. this.getServerData(parseInt(presenttime / 1000), parseInt((presenttime - 30 * 24 * 60 * 60 *
  102. 1000) /
  103. 1000))
  104. this.historydata(parseInt(presenttime / 1000), parseInt((presenttime - 30 * 24 * 60 * 60 * 1000) /
  105. 1000))
  106. }, 1000)
  107. },
  108. onShow() {
  109. },
  110. onPullDownRefresh() {
  111. console.log('refresh');
  112. this.getServerData(parseInt(presenttime / 1000), parseInt((presenttime - 24 * 60 * 60 * 1000) /
  113. 1000))
  114. this.historydata(parseInt(presenttime / 1000), parseInt((presenttime - 24 * 60 * 60 * 1000) /
  115. 1000))
  116. setTimeout(function() {
  117. uni.stopPullDownRefresh();
  118. }, 1000);
  119. },
  120. methods: { //
  121. //forecast.worm_lamp.device_polyline_data
  122. // 获取数据,发请求
  123. async getServerData(newtime, oldtimes) { //设备折线图
  124. this.dataloadingtf = true
  125. const res = await this.$myRequest({
  126. url: '/api/api_gateway?method=weather.weather.sf_data_chart',
  127. data: {
  128. device_id: this.times.device_id,
  129. end: newtime,
  130. begin: oldtimes,
  131. }
  132. })
  133. this.dataloadingtf = false
  134. if (res.length == 0) {
  135. this.canvastishiTF = false
  136. } else {
  137. this.canvastishiTF = true
  138. var dataarr = res.conf.eleName.split("/")
  139. var elearr = res.conf.eleNum.split("/")
  140. var xtitle = []
  141. var arr = []
  142. var color = ['#F97000', '#00E29D', '#FF3F3F', '#6CBBFF', '#00E29D']
  143. for (var i = 0; i < dataarr.length; i++) {
  144. if (dataarr[i] != "-") {
  145. var valuearr = []
  146. for (var j = 0; j < res.dat.length; j++) {
  147. var numarr = JSON.stringify(res.dat[j].device_status).slice(2, -2)
  148. numarr = numarr.split(",")
  149. var numobj = {}
  150. for (var k = 0; k < numarr.length; k++) {
  151. numarr[k] = numarr[k].split(":")
  152. var index = numarr[k][0].indexOf("e") == -1 ? numarr[k][0].indexOf("j") : numarr[k]
  153. [0].indexOf("e")
  154. numobj[numarr[k][0].slice(index, -1)] = Number(numarr[k][1])
  155. }
  156. valuearr.unshift(numobj['e' + (i + 1)]) // + elelist[elearr[i]].unit
  157. var times = new Date(res.dat[j].uptime * 1000)
  158. xtitle.unshift(times.getMonth() + 1 + "/" + times.getDate() + "-" + times.getHours() +
  159. ":" +
  160. times.getMinutes())
  161. }
  162. var obj = {
  163. name: dataarr[i],
  164. data: valuearr,
  165. color: color[i]
  166. }
  167. arr.push(obj)
  168. }
  169. }
  170. console.log(arr)
  171. this.showColumn("canvasColumnA", xtitle, arr)
  172. }
  173. },
  174. async historydata(newtime, oldtimes) { //设备表格数据
  175. const res = await this.$myRequest({
  176. url: '/api/api_gateway?method=weather.weather.sf_data',
  177. data: {
  178. device_id: this.times.device_id,
  179. page: this.page,
  180. page_size: 10,
  181. begin: oldtimes,
  182. end: newtime,
  183. }
  184. })
  185. console.log(res)
  186. if (res.length == 0) {
  187. this.forbidden = false
  188. } else {
  189. this.pagesum = Math.floor(res.nums / 10) + 1
  190. this.forbidden = true
  191. this.eqlistdata = []
  192. var dataarr = res.conf.eleName.split("/")
  193. var elearr = res.conf.eleNum.split("/")
  194. this.thdata = ["上报时间"]
  195. var timearr = []
  196. for (var i = 0; i < dataarr.length; i++) {
  197. if (dataarr[i] != "-") {
  198. this.thdata.push(dataarr[i])
  199. var valuearr = []
  200. for (var j = 0; j < res.dat.length; j++) {
  201. var numarr = JSON.stringify(res.dat[j].device_status).slice(2, -2)
  202. numarr = numarr.split(",")
  203. var numobj = {}
  204. for (var k = 0; k < numarr.length; k++) {
  205. numarr[k] = numarr[k].split(":")
  206. var index = numarr[k][0].indexOf("e")
  207. numobj[numarr[k][0].slice(index, -1)] = Number(numarr[k][1])
  208. }
  209. valuearr.push(numobj['e' + (i + 1)]) // + elelist[elearr[i]].unit
  210. }
  211. console.log(valuearr)
  212. this.eqlistdata.push(valuearr)
  213. // console.log(valuearr)
  214. }
  215. }
  216. for (var j = 0; j < res.dat.length; j++) {
  217. // valuearr.unshift(numobj['e' + (i + 1)]) // + elelist[elearr[i]].unit
  218. timearr.push(this.tiemtag(res.dat[j].uptime))
  219. }
  220. this.eqlistdata.unshift(timearr)
  221. console.log(this.eqlistdata)
  222. }
  223. },
  224. prev() { //上一页
  225. if (this.page != 1) {
  226. this.page--
  227. this.historydata(this.newtime, this.oldtime)
  228. }
  229. },
  230. next() { //下一页
  231. if (this.page < this.pagesum) {
  232. this.page++
  233. this.historydata(this.newtime, this.oldtime)
  234. }
  235. },
  236. tiemchange(e) {
  237. console.log(e)
  238. this.oldtime = +new Date(e.startDate) / 1000
  239. this.newtime = +new Date(e.endDate) / 1000 + 16 * 60 * 60
  240. this.getServerData(this.newtime, this.oldtime)
  241. this.historydata(this.newtime, this.oldtime)
  242. },
  243. timetab(e) {
  244. e = new Date(e * 1000)
  245. var year = e.getFullYear()
  246. var month = e.getMonth() + 1 < 10 ? "0" + (e.getMonth() + 1) : e.getMonth() + 1
  247. var day = e.getDate() < 10 ? "0" + e.getDate() : e.getDate()
  248. var time = year + "/" + month + "/" + day
  249. return time
  250. },
  251. clickLeft() {
  252. uni.navigateBack({
  253. delta: 1
  254. })
  255. },
  256. showColumn(id, xtitle, xinfo) {
  257. var _self = this
  258. canvaColumnA = new uCharts({
  259. canvasId: id,
  260. type: 'line',
  261. legend: {
  262. position: "top"
  263. },
  264. fontSize: 11,
  265. background: '#FFFFFF',
  266. pixelRatio: 1,
  267. animation: true,
  268. dataLabel: false,
  269. categories: xtitle,
  270. series: xinfo,
  271. enableScroll: true, //开启图表拖拽功能
  272. xAxis: {
  273. disableGrid: true,
  274. type: 'grid',
  275. gridType: 'dash',
  276. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  277. scrollShow: true, //新增是否显示滚动条,默认false
  278. // scrollAlign: 'left', //滚动条初始位置
  279. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  280. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  281. },
  282. yAxis: {},
  283. width: _self.cWidth * 1,
  284. height: _self.cHeight * 1,
  285. extra: {
  286. line: {
  287. type: 'curve'
  288. }
  289. }
  290. });
  291. },
  292. showColumnb(id, xtitle, xinfo) {
  293. var _self = this
  294. canvaColumnB = new uCharts({
  295. canvasId: id,
  296. type: 'line',
  297. legend: {
  298. position: "top"
  299. },
  300. fontSize: 11,
  301. background: '#FFFFFF',
  302. pixelRatio: 1,
  303. animation: true,
  304. dataLabel: false,
  305. categories: xtitle,
  306. series: xinfo,
  307. enableScroll: true, //开启图表拖拽功能
  308. xAxis: {
  309. disableGrid: true,
  310. type: 'grid',
  311. gridType: 'dash',
  312. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  313. scrollShow: true, //新增是否显示滚动条,默认false
  314. // scrollAlign: 'left', //滚动条初始位置
  315. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  316. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  317. },
  318. yAxis: {},
  319. width: _self.cWidth * 1,
  320. height: _self.cHeight * 1,
  321. extra: {
  322. line: {
  323. type: 'curve'
  324. }
  325. }
  326. });
  327. },
  328. touchLineA(e) {
  329. console.log(e)
  330. canvaColumnA.scrollStart(e);
  331. },
  332. moveLineA(e) {
  333. canvaColumnA.scroll(e);
  334. },
  335. touchEndLineA(e) {
  336. canvaColumnA.scrollEnd(e);
  337. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  338. canvaColumnA.showToolTip(e, {
  339. format: function(item, category) {
  340. return category + ' ' + item.name + ':' + Number(item.data).toFixed(3)
  341. }
  342. });
  343. },
  344. touchLineBb(e) {
  345. console.log(e)
  346. canvaColumnB.scrollStart(e);
  347. },
  348. moveLineBb(e) {
  349. canvaColumnB.scroll(e);
  350. },
  351. touchEndLineBb(e) {
  352. canvaColumnB.scrollEnd(e);
  353. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  354. canvaColumnB.showToolTip(e, {
  355. format: function(item, category) {
  356. return category + ' ' + item.name + ':' + item.data
  357. }
  358. });
  359. },
  360. async newdata() {
  361. const res = await this.$myRequest({
  362. url: '/api/api_gateway?method=forecast.send_control.get_device_config',
  363. data: {
  364. device_type_id: 2,
  365. d_id: this.times.d_id,
  366. control_type: "data"
  367. }
  368. })
  369. if (res) {
  370. uni.showToast({
  371. title: '刷新成功',
  372. duration: 2000,
  373. icon: "none"
  374. });
  375. } else {
  376. uni.showToast({
  377. title: '刷新失败',
  378. duration: 2000,
  379. icon: "none"
  380. });
  381. }
  382. },
  383. refresh() { //获取当前时间的数据
  384. this.newdata()
  385. },
  386. tiemtag(time) {
  387. var date = new Date(time * 1000)
  388. var year = date.getFullYear()
  389. var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1
  390. var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate()
  391. var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours()
  392. var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()
  393. var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds()
  394. return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds
  395. }
  396. }
  397. }
  398. </script>
  399. <style lang="scss">
  400. /*样式的width和height一定要与定义的cWidth和cHeight相对应*/
  401. .shuju_one {
  402. position: relative;
  403. width: 90%;
  404. box-shadow: 0 0 10rpx #bcb9ca;
  405. padding-top: 20rpx;
  406. height: 550rpx;
  407. margin: 30rpx auto;
  408. .canvastishi {
  409. font-size: 32rpx;
  410. position: absolute;
  411. top: 50%;
  412. left: 50%;
  413. margin-left: -64rpx;
  414. margin-top: -21rpx;
  415. .dataloading:after {
  416. overflow: hidden;
  417. display: inline-block;
  418. vertical-align: bottom;
  419. animation: ellipsis 2s infinite;
  420. content: "\2026";
  421. }
  422. @keyframes ellipsis {
  423. from {
  424. width: 2px;
  425. }
  426. to {
  427. width: 15px;
  428. }
  429. }
  430. }
  431. .shuju_one_title {
  432. width: 70%;
  433. margin: 0 auto;
  434. display: flex;
  435. .tltle_text {
  436. width: 25%;
  437. border: 2rpx solid #B2B2B2;
  438. color: #57c878;
  439. text-align: center;
  440. font-size: 24rpx;
  441. height: 50rpx;
  442. line-height: 50rpx;
  443. }
  444. .title_text_color {
  445. width: 25%;
  446. border: 2rpx solid #57c878;
  447. background-color: #57c878;
  448. color: #fff;
  449. text-align: center;
  450. font-size: 24rpx;
  451. height: 50rpx;
  452. line-height: 50rpx;
  453. }
  454. }
  455. .qiun-columns {
  456. .qiun-charts {
  457. width: 650upx;
  458. height: 400upx;
  459. background-color: #FFFFFF;
  460. }
  461. .charts {
  462. width: 650upx;
  463. height: 400upx;
  464. background-color: #FFFFFF;
  465. }
  466. }
  467. }
  468. .shuju_two {
  469. top: 790rpx;
  470. }
  471. .selecttimes {
  472. width: 90%;
  473. box-shadow: 0 0 10rpx #bcb9ca;
  474. padding: 10rpx 20rpx;
  475. box-sizing: border-box;
  476. margin: 30rpx auto;
  477. .timesbox {
  478. display: flex;
  479. justify-content: space-around;
  480. image {
  481. width: 30rpx;
  482. height: 30rpx;
  483. margin-top: 6rpx;
  484. }
  485. .icon {
  486. color: #949494;
  487. text-align: right;
  488. margin-left: 30rpx;
  489. }
  490. }
  491. }
  492. .refresh {
  493. width: 160rpx;
  494. height: 50rpx;
  495. background-color: #57c878;
  496. color: #FFFFFF;
  497. line-height: 50rpx;
  498. text-align: center;
  499. box-shadow: 0 0 10rpx #bcb9ca;
  500. margin: 30rpx 5%;
  501. }
  502. .condition {
  503. display: flex;
  504. flex-wrap: wrap;
  505. width: 90%;
  506. box-shadow: 0 0 10rpx #bcb9ca;
  507. margin-bottom: 30rpx;
  508. margin: 30rpx auto;
  509. .scroll-X {
  510. width: 95%;
  511. margin: 20rpx auto;
  512. .tr {
  513. display: flex;
  514. overflow: hidden;
  515. .th,
  516. .td {
  517. display: inline-block;
  518. padding: 5rpx;
  519. width: 140rpx;
  520. text-align: center;
  521. height: 52rpx;
  522. line-height: 52rpx;
  523. // border: 2rpx solid #F1F1F1;
  524. }
  525. .th:first-child,
  526. .td:first-child {
  527. width: 300rpx;
  528. }
  529. .th:nth-last-child(1),
  530. .th:nth-last-child(2),
  531. .td:nth-last-child(1),
  532. .td:nth-last-child(2) {
  533. width: 200rpx;
  534. }
  535. }
  536. .tr:nth-child(2n-1) {
  537. background-color: #f5fff8;
  538. }
  539. .tr:first-child {
  540. background-color: #57c878;
  541. color: #fff;
  542. }
  543. }
  544. .pagenumber {
  545. display: flex;
  546. margin: 20rpx auto;
  547. button {
  548. width: 150rpx;
  549. height: 50rpx;
  550. line-height: 50rpx;
  551. font-size: 26rpx;
  552. text-align: center;
  553. background-color: #57c878;
  554. color: #FFFFFF;
  555. }
  556. .pagenumber_page {
  557. width: 150rpx;
  558. height: 50rpx;
  559. line-height: 50rpx;
  560. font-size: 26rpx;
  561. text-align: center;
  562. }
  563. }
  564. }
  565. /deep/.u-calendar__action {
  566. display: flex;
  567. justify-content: space-around;
  568. .u-calendar__action__text {
  569. line-height: 25px;
  570. }
  571. }
  572. </style>