elementdata.vue 15 KB

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