elementdata.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. <template>
  2. <view>
  3. <view class="">
  4. <view class="selecttimes" @click="tiemshow=!tiemshow">
  5. <view class="timesbox">
  6. <image
  7. :src="$imageURL+'/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. const ctx = uni.createCanvasContext(id, this);
  259. canvaColumnA = new uCharts({
  260. context: ctx,
  261. type: 'line',
  262. legend: {
  263. position: "top"
  264. },
  265. fontSize: 11,
  266. background: '#FFFFFF',
  267. pixelRatio: 1,
  268. animation: true,
  269. dataLabel: false,
  270. categories: xtitle,
  271. series: xinfo,
  272. enableScroll: true, //开启图表拖拽功能
  273. xAxis: {
  274. disableGrid: true,
  275. type: 'grid',
  276. gridType: 'dash',
  277. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  278. scrollShow: true, //新增是否显示滚动条,默认false
  279. // scrollAlign: 'left', //滚动条初始位置
  280. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  281. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  282. },
  283. yAxis: {},
  284. width: _self.cWidth * 1,
  285. height: _self.cHeight * 1,
  286. extra: {
  287. line: {
  288. type: 'curve'
  289. }
  290. }
  291. });
  292. },
  293. showColumnb(id, xtitle, xinfo) {
  294. var _self = this
  295. const ctx = uni.createCanvasContext(id, this);
  296. canvaColumnB = new uCharts({
  297. context: ctx,
  298. type: 'line',
  299. legend: {
  300. position: "top"
  301. },
  302. fontSize: 11,
  303. background: '#FFFFFF',
  304. pixelRatio: 1,
  305. animation: true,
  306. dataLabel: false,
  307. categories: xtitle,
  308. series: xinfo,
  309. enableScroll: true, //开启图表拖拽功能
  310. xAxis: {
  311. disableGrid: true,
  312. type: 'grid',
  313. gridType: 'dash',
  314. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  315. scrollShow: true, //新增是否显示滚动条,默认false
  316. // scrollAlign: 'left', //滚动条初始位置
  317. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  318. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  319. },
  320. yAxis: {},
  321. width: _self.cWidth * 1,
  322. height: _self.cHeight * 1,
  323. extra: {
  324. line: {
  325. type: 'curve'
  326. }
  327. }
  328. });
  329. },
  330. touchLineA(e) {
  331. console.log(e)
  332. canvaColumnA.scrollStart(e);
  333. },
  334. moveLineA(e) {
  335. canvaColumnA.scroll(e);
  336. },
  337. touchEndLineA(e) {
  338. canvaColumnA.scrollEnd(e);
  339. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  340. canvaColumnA.showToolTip(e, {
  341. format: function(item, category) {
  342. return category + ' ' + item.name + ':' + Number(item.data).toFixed(3)
  343. }
  344. });
  345. },
  346. touchLineBb(e) {
  347. console.log(e)
  348. canvaColumnB.scrollStart(e);
  349. },
  350. moveLineBb(e) {
  351. canvaColumnB.scroll(e);
  352. },
  353. touchEndLineBb(e) {
  354. canvaColumnB.scrollEnd(e);
  355. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  356. canvaColumnB.showToolTip(e, {
  357. format: function(item, category) {
  358. return category + ' ' + item.name + ':' + item.data
  359. }
  360. });
  361. },
  362. async newdata() {
  363. const res = await this.$myRequest({
  364. url: '/api/api_gateway?method=forecast.send_control.get_device_config',
  365. data: {
  366. device_type_id: 2,
  367. d_id: this.times.d_id,
  368. control_type: "data"
  369. }
  370. })
  371. if (res) {
  372. uni.showToast({
  373. title: '刷新成功',
  374. duration: 2000,
  375. icon: "none"
  376. });
  377. } else {
  378. uni.showToast({
  379. title: '刷新失败',
  380. duration: 2000,
  381. icon: "none"
  382. });
  383. }
  384. },
  385. refresh() { //获取当前时间的数据
  386. this.newdata()
  387. },
  388. tiemtag(time) {
  389. var date = new Date(time * 1000)
  390. var year = date.getFullYear()
  391. var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1
  392. var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate()
  393. var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours()
  394. var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()
  395. var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds()
  396. return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds
  397. }
  398. }
  399. }
  400. </script>
  401. <style lang="scss">
  402. /*样式的width和height一定要与定义的cWidth和cHeight相对应*/
  403. .shuju_one {
  404. position: relative;
  405. width: 90%;
  406. box-shadow: 0 0 10rpx #bcb9ca;
  407. padding-top: 20rpx;
  408. height: 550rpx;
  409. margin: 30rpx auto;
  410. .canvastishi {
  411. font-size: 32rpx;
  412. position: absolute;
  413. top: 50%;
  414. left: 50%;
  415. margin-left: -64rpx;
  416. margin-top: -21rpx;
  417. .dataloading:after {
  418. overflow: hidden;
  419. display: inline-block;
  420. vertical-align: bottom;
  421. animation: ellipsis 2s infinite;
  422. content: "\2026";
  423. }
  424. @keyframes ellipsis {
  425. from {
  426. width: 2px;
  427. }
  428. to {
  429. width: 15px;
  430. }
  431. }
  432. }
  433. .shuju_one_title {
  434. width: 70%;
  435. margin: 0 auto;
  436. display: flex;
  437. .tltle_text {
  438. width: 25%;
  439. border: 2rpx solid #B2B2B2;
  440. color: #57c878;
  441. text-align: center;
  442. font-size: 24rpx;
  443. height: 50rpx;
  444. line-height: 50rpx;
  445. }
  446. .title_text_color {
  447. width: 25%;
  448. border: 2rpx solid #57c878;
  449. background-color: #57c878;
  450. color: #fff;
  451. text-align: center;
  452. font-size: 24rpx;
  453. height: 50rpx;
  454. line-height: 50rpx;
  455. }
  456. }
  457. .qiun-columns {
  458. .qiun-charts {
  459. width: 650upx;
  460. height: 400upx;
  461. background-color: #FFFFFF;
  462. }
  463. .charts {
  464. width: 650upx;
  465. height: 400upx;
  466. background-color: #FFFFFF;
  467. }
  468. }
  469. }
  470. .shuju_two {
  471. top: 790rpx;
  472. }
  473. .selecttimes {
  474. width: 90%;
  475. box-shadow: 0 0 10rpx #bcb9ca;
  476. padding: 10rpx 20rpx;
  477. box-sizing: border-box;
  478. margin: 30rpx auto;
  479. .timesbox {
  480. display: flex;
  481. justify-content: space-around;
  482. image {
  483. width: 30rpx;
  484. height: 30rpx;
  485. margin-top: 6rpx;
  486. }
  487. .icon {
  488. color: #949494;
  489. text-align: right;
  490. margin-left: 30rpx;
  491. }
  492. }
  493. }
  494. .refresh {
  495. width: 160rpx;
  496. height: 50rpx;
  497. background-color: #57c878;
  498. color: #FFFFFF;
  499. line-height: 50rpx;
  500. text-align: center;
  501. box-shadow: 0 0 10rpx #bcb9ca;
  502. margin: 30rpx 5%;
  503. }
  504. .condition {
  505. display: flex;
  506. flex-wrap: wrap;
  507. width: 90%;
  508. box-shadow: 0 0 10rpx #bcb9ca;
  509. margin-bottom: 30rpx;
  510. margin: 30rpx auto;
  511. .scroll-X {
  512. width: 95%;
  513. margin: 20rpx auto;
  514. .tr {
  515. display: flex;
  516. overflow: hidden;
  517. .th,
  518. .td {
  519. display: inline-block;
  520. padding: 5rpx;
  521. width: 140rpx;
  522. text-align: center;
  523. height: 52rpx;
  524. line-height: 52rpx;
  525. // border: 2rpx solid #F1F1F1;
  526. }
  527. .th:first-child,
  528. .td:first-child {
  529. width: 300rpx;
  530. }
  531. .th:nth-last-child(1),
  532. .th:nth-last-child(2),
  533. .td:nth-last-child(1),
  534. .td:nth-last-child(2) {
  535. width: 200rpx;
  536. }
  537. }
  538. .tr:nth-child(2n-1) {
  539. background-color: #f5fff8;
  540. }
  541. .tr:first-child {
  542. background-color: #57c878;
  543. color: #fff;
  544. }
  545. }
  546. .pagenumber {
  547. display: flex;
  548. margin: 20rpx auto;
  549. button {
  550. width: 150rpx;
  551. height: 50rpx;
  552. line-height: 50rpx;
  553. font-size: 26rpx;
  554. text-align: center;
  555. background-color: #57c878;
  556. color: #FFFFFF;
  557. }
  558. .pagenumber_page {
  559. width: 150rpx;
  560. height: 50rpx;
  561. line-height: 50rpx;
  562. font-size: 26rpx;
  563. text-align: center;
  564. }
  565. }
  566. }
  567. /deep/.u-calendar__action {
  568. display: flex;
  569. justify-content: space-around;
  570. .u-calendar__action__text {
  571. line-height: 25px;
  572. }
  573. }
  574. </style>