elementdata.vue 15 KB

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