mls.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. <template>
  2. <view>
  3. <!-- <view class="status_bar"></view> -->
  4. <view class="" style="position: relative">
  5. <!-- <view style="position: fixed; z-index: 100; width: 100%">
  6. <uni-nav-bar @clickLeft="clickLeft" left-icon="back" left-text="返回" title="设备详情"></uni-nav-bar>
  7. </view> -->
  8. <view class="info">
  9. <view class="info_item">
  10. <image
  11. :src="$imageURL+'/bigdata_app/image/cb/onBg.png'"
  12. mode=""
  13. class="bgi"
  14. ></image>
  15. <p style="font-size: 32rpx" @click="copy(eqinfo.device_id)">
  16. 设备 ID:{{ eqinfo.device_id }}
  17. <image
  18. :src="$imageURL+'/bigdata_app/image/environment/fuzhi.png'"
  19. mode=""
  20. class="tishi"
  21. ></image>
  22. </p>
  23. <p>设备名称:{{ eqinfo.device_name || '无' }}</p>
  24. <p>
  25. 最近上报时间:<span v-if="eqinfo.uptime">{{
  26. eqinfo.uptime == 0 ? '无' : eqinfo.uptime | timeFormat()
  27. }}</span
  28. ><span v-else>{{
  29. eqinfo.uptime == 0 ? '无' : eqinfo.uptime | timeFormat()
  30. }}</span>
  31. </p>
  32. <p>地址:{{ eqinfo.location || '暂无地址' }}</p>
  33. </view>
  34. </view>
  35. <view class="control">
  36. <view class="control_item" v-if="kongtf" @click="control">
  37. <image
  38. :src="
  39. $imageURL+ '/bigdata_app' +
  40. '/image/environment/forecastResult.png'
  41. "
  42. mode=""
  43. ></image>
  44. <p>防控决策</p>
  45. </view>
  46. </view>
  47. <view class="his_box" v-if="datatf">
  48. <view class="selecttimes" @click="tiemshow = !tiemshow">
  49. <view class="timesbox">
  50. <image
  51. :src="$imageURL+'/bigdata_app/image/prevention/1acfe2751c01d3786cdc49b83d7e505.png'"
  52. mode=""
  53. ></image>
  54. <p>{{ timetab(begintime) }}</p>
  55. <p class="or">~</p>
  56. <p>{{ timetab(end) }}</p>
  57. <u-icon
  58. name="rili"
  59. custom-prefix="custom-icon"
  60. class="icon"
  61. ></u-icon>
  62. </view>
  63. <u-calendar
  64. v-model="tiemshow"
  65. mode="range"
  66. @change="tiemchange"
  67. range-color="#999"
  68. btn-type="success"
  69. active-bg-color="#0BBC58"
  70. range-bg-color="rgba(11,188,88,0.13)"
  71. ></u-calendar>
  72. </view>
  73. <view class="shuju_one">
  74. <view class="canvastishi" v-if="!canvastishiTF && !dataloadingtf">
  75. 暂无数据
  76. </view>
  77. <view class="canvastishi" v-if="dataloadingtf">
  78. <p class="dataloading">加载中</p>
  79. </view>
  80. <canvas
  81. v-show="!tiemshow"
  82. canvas-id="canvasColumnA"
  83. id="canvasColumnA"
  84. class="charts"
  85. @touchstart="touchLineA($event)"
  86. @touchmove="moveLineA($event)"
  87. @touchend="touchEndLineA($event)"
  88. disable-scroll="true"
  89. :style="{
  90. width: cWidth * pixelRatio + 'px',
  91. height: cHeight * pixelRatio + 'px',
  92. transform: 'scale(' + 1 / pixelRatio + ')',
  93. 'margin-left': (-cWidth * (pixelRatio - 1)) / 2 + 'px',
  94. 'margin-top': (-cHeight * (pixelRatio - 1)) / 2 + 'px',
  95. }"
  96. ></canvas>
  97. <canvas
  98. v-show="!tiemshow"
  99. canvas-id="canvasColumnB"
  100. id="canvasColumnB"
  101. class="charts"
  102. @touchstart="touchLineB($event)"
  103. @touchmove="moveLineB($event)"
  104. @touchend="touchEndLineB($event)"
  105. disable-scroll="true"
  106. :style="{
  107. width: cWidth * pixelRatio + 'px',
  108. height: cHeight * pixelRatio + 'px',
  109. transform: 'scale(' + 1 / pixelRatio + ')',
  110. 'margin-left': (-cWidth * (pixelRatio - 1)) / 2 + 'px',
  111. 'margin-top': (-cHeight * (pixelRatio - 1)) / 2 + 'px',
  112. }"
  113. ></canvas>
  114. </view>
  115. <view class="condition">
  116. <scroll-view scroll-top="0" scroll-x="true" class="scroll-X">
  117. <table class="table">
  118. <tr class="tr">
  119. <th class="th" v-for="(value, key) in param" :key="'a' + key">
  120. {{ value }}
  121. </th>
  122. </tr>
  123. <tr
  124. class="tr"
  125. v-for="(items, indexs) in historylistdata"
  126. :key="'b' + indexs"
  127. v-if="!forbidden"
  128. >
  129. <td class="td" v-for="(value, key) in param">
  130. {{ items[key] }}
  131. </td>
  132. </tr>
  133. <tr class="tr" v-if="forbidden">
  134. <td class="td" v-for="item in 13">暂无数据</td>
  135. </tr>
  136. </table>
  137. </scroll-view>
  138. <view class="pagenumber">
  139. <button @click="prev">上一页</button>
  140. <view class="pagenumber_page"> 第 {{ page }} 页 </view>
  141. <view class="pagenumber_page"> 共 {{ pagesum }} 页 </view>
  142. <button @click="next">下一页</button>
  143. </view>
  144. </view>
  145. </view>
  146. </view>
  147. </view>
  148. </template>
  149. <script>
  150. import uCharts from '../../../components/js_sdk/u-charts/u-charts/u-charts.js';
  151. var canvaColumnA = null;
  152. var canvaColumnB = null;
  153. export default {
  154. data() {
  155. return {
  156. basetype: '',
  157. kongtf: false,
  158. datatf: false,
  159. eqinfo: {},
  160. city: '河南省',
  161. tiemshow: false, //时间筛选弹框
  162. begintime: '', //开始时间
  163. end: '', //结束时间
  164. dataloadingtf: true,
  165. canvastishiTF: false,
  166. device_id: '', //设备ID
  167. forbidden: false,
  168. historylistdata: [], //历史数据
  169. pagesum: 1,
  170. page: 1,
  171. cWidth: '',
  172. cHeight: '',
  173. pixelRatio: 1,
  174. param: {},
  175. color: [
  176. '#ff7b30',
  177. '#f93948',
  178. '#fb2ea4',
  179. '#bc59db',
  180. '#7457ec',
  181. '#307dfd',
  182. '#31bfff',
  183. '#46e9b1',
  184. '#19cd48',
  185. '#b2e409',
  186. '#f0f254',
  187. '#fed000',
  188. '#f06f14',
  189. '#a74040',
  190. '#90bb71',
  191. '#a07635',
  192. '#6502bd',
  193. '#048bbb',
  194. '#9ebb01',
  195. '#cc9202',
  196. '#ff8fa0',
  197. '#a3d55f',
  198. '#d9bedd',
  199. '#00a6b6',
  200. '#236093',
  201. '#009fff',
  202. '#ddc0a6',
  203. '#c4a6dd',
  204. '#dda6a6',
  205. '#779e33',
  206. '#a6ddb0',
  207. ],
  208. };
  209. },
  210. methods: {
  211. copy(item) {
  212. uni.setClipboardData({
  213. data: item,
  214. success: function () {
  215. console.log('success');
  216. },
  217. });
  218. },
  219. control() {
  220. //设备控制
  221. uni.navigateTo({
  222. url: './forecastResult?id=' + this.eqinfo.device_id,
  223. });
  224. },
  225. tiemchange(e) {
  226. console.log(e);
  227. //切换时间
  228. // this.begintime = parseInt(+new Date(e.startDate) / 1000);
  229. this.begintime = parseInt(+new Date(`${e.startDate} 00:00:00`) / 1000);
  230. this.end = parseInt(+new Date(`${e.endDate} 00:00:00`) / 1000);
  231. this.histprydatas();
  232. this.getChartLine();
  233. },
  234. timetab(e) {
  235. //时间转换
  236. e = new Date(e * 1000);
  237. var year = e.getFullYear();
  238. var month =
  239. e.getMonth() + 1 < 10 ? '0' + (e.getMonth() + 1) : e.getMonth() + 1;
  240. var day = e.getDate() < 10 ? '0' + e.getDate() : e.getDate();
  241. var time = year + '/' + month + '/' + day;
  242. return time;
  243. },
  244. // 表格数据
  245. async histprydatas() {
  246. //表格历史数据
  247. const res = await this.$myRequest({
  248. url: '/api/api_gateway?method=wheat.potato.potato_data_list',
  249. data: {
  250. device_id: this.eqinfo.device_id,
  251. page: this.page,
  252. begin: this.begintime,
  253. end: this.end,
  254. },
  255. });
  256. console.log(res);
  257. this.param = res.ele;
  258. this.pagesum = Math.ceil(res.nums / 10) || 1;
  259. if (this.pagesum > 0) {
  260. var dat = res.sta;
  261. this.historylistdata = [];
  262. for (var i = 0; i < dat.length; i++) {
  263. var item = eval('(' + dat[i] + ')');
  264. var obj = {};
  265. for (var i1 in item) {
  266. // if (i1 == "uploadTime") {
  267. // obj[i1] = this.formatTime(item[i1] * 1000);
  268. // } else {
  269. obj[i1] = item[i1];
  270. // }
  271. }
  272. this.historylistdata.push(obj);
  273. }
  274. } else {
  275. this.historylistdata = [];
  276. }
  277. },
  278. //获取折线图数据
  279. async getChartLine() {
  280. const res = await this.$myRequest({
  281. method: 'POST',
  282. url: '/api/api_gateway?method=wheat.potato.potato_data',
  283. data: {
  284. device_id: this.eqinfo.device_id,
  285. begin: this.begintime,
  286. end: this.end,
  287. },
  288. });
  289. this.dataloadingtf = false;
  290. var dat = res.data;
  291. this.param = res.ele;
  292. if (dat.length) {
  293. var regroupData = []; //重组数据
  294. var kindArr = []; //通道数组
  295. var time = [];
  296. var xtitle = [];
  297. for (var i = 0; i < dat.length; i++) {
  298. var item = eval('(' + dat[i] + ')');
  299. console.log(item);
  300. var tim = new Date(item['dataTime']).getTime();
  301. var times = new Date(tim);
  302. xtitle.unshift(
  303. times.getMonth() +
  304. 1 +
  305. '/' +
  306. times.getDate() +
  307. '-' +
  308. times.getHours() +
  309. ':' +
  310. times.getMinutes()
  311. );
  312. time.unshift(tim);
  313. for (var j in item) {
  314. var arr = '';
  315. if (j == 'id' || j == 'dataTime' || j == 'windDir') {
  316. continue;
  317. } else if (kindArr.indexOf(j) == '-1') {
  318. kindArr.push(j);
  319. regroupData.push({
  320. name: this.param[j],
  321. color: this.color[kindArr.length - 1],
  322. data: [],
  323. });
  324. // arr.push(tim);
  325. arr = parseFloat(item[j]);
  326. regroupData[kindArr.indexOf(j)].data.unshift(arr);
  327. } else {
  328. // arr.push(tim);
  329. // arr.push(parseFloat(item[j]));
  330. arr = parseFloat(item[j]);
  331. regroupData[kindArr.indexOf(j)].data.unshift(arr);
  332. }
  333. }
  334. }
  335. console.log(regroupData);
  336. // 分割折线图
  337. const regroupDataNum = Math.ceil(regroupData.length / 2);
  338. const options1 = regroupData.filter((v, i) => {
  339. return i < regroupDataNum;
  340. });
  341. const options2 = regroupData.filter((v, i) => {
  342. return i >= regroupDataNum;
  343. });
  344. console.log(options1, options2);
  345. this.showColumn('canvasColumnA', xtitle, options1);
  346. this.showColumn('canvasColumnB', xtitle, options2);
  347. this.canvastishiTF = true;
  348. } else {
  349. this.canvastishiTF = false;
  350. this.showColumn('canvasColumnA', xtitle, []);
  351. this.showColumn('canvasColumnB', xtitle, []);
  352. }
  353. },
  354. prev() {
  355. //上一页
  356. if (this.page > 1) {
  357. this.page--;
  358. this.histprydatas();
  359. }
  360. },
  361. next() {
  362. //下一页
  363. if (this.page < this.pagesum) {
  364. this.page++;
  365. this.histprydatas();
  366. }
  367. },
  368. clickLeft() {
  369. uni.navigateBack({
  370. delta: 1,
  371. });
  372. },
  373. showColumn(id, xtitle, xinfo) {
  374. console.log(id);
  375. var _self = this;
  376. const ctx = uni.createCanvasContext(id, this);
  377. if (id === 'canvasColumnA') {
  378. canvaColumnA = new uCharts({
  379. context: ctx,
  380. type: 'line',
  381. legend: {
  382. position: 'top',
  383. },
  384. fontSize: 11,
  385. background: '#FFFFFF',
  386. pixelRatio: 1,
  387. animation: true,
  388. dataLabel: false,
  389. categories: xtitle,
  390. series: xinfo,
  391. enableScroll: true, //开启图表拖拽功能
  392. xAxis: {
  393. disableGrid: true,
  394. type: 'grid',
  395. gridType: 'dash',
  396. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  397. scrollShow: true, //新增是否显示滚动条,默认false
  398. // scrollAlign: 'left', //滚动条初始位置
  399. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  400. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  401. },
  402. yAxis: {},
  403. width: _self.cWidth * 1,
  404. height: _self.cHeight * 1,
  405. extra: {
  406. line: {
  407. type: 'curve',
  408. },
  409. },
  410. });
  411. } else if (id === 'canvasColumnB') {
  412. canvaColumnB = new uCharts({
  413. context: ctx,
  414. type: 'line',
  415. legend: {
  416. position: 'top',
  417. },
  418. fontSize: 11,
  419. background: '#FFFFFF',
  420. pixelRatio: 1,
  421. animation: true,
  422. dataLabel: false,
  423. categories: xtitle,
  424. series: xinfo,
  425. enableScroll: true, //开启图表拖拽功能
  426. xAxis: {
  427. disableGrid: true,
  428. type: 'grid',
  429. gridType: 'dash',
  430. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  431. scrollShow: true, //新增是否显示滚动条,默认false
  432. // scrollAlign: 'left', //滚动条初始位置
  433. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  434. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  435. },
  436. yAxis: {},
  437. width: _self.cWidth * 1,
  438. height: _self.cHeight * 1,
  439. extra: {
  440. line: {
  441. type: 'curve',
  442. },
  443. },
  444. });
  445. }
  446. },
  447. touchLineA(e) {
  448. console.log(e);
  449. canvaColumnA.scrollStart(e);
  450. },
  451. moveLineA(e) {
  452. canvaColumnA.scroll(e);
  453. },
  454. touchEndLineA(e) {
  455. canvaColumnA.scrollEnd(e);
  456. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  457. canvaColumnA.showToolTip(e, {
  458. format: function (item, category) {
  459. return category + ' ' + item.name + ':' + item.data;
  460. },
  461. });
  462. },
  463. touchLineB(e) {
  464. console.log(e);
  465. canvaColumnB.scrollStart(e);
  466. },
  467. moveLineB(e) {
  468. canvaColumnB.scroll(e);
  469. },
  470. touchEndLineB(e) {
  471. canvaColumnB.scrollEnd(e);
  472. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  473. canvaColumnB.showToolTip(e, {
  474. format: function (item, category) {
  475. return category + ' ' + item.name + ':' + item.data;
  476. },
  477. });
  478. },
  479. },
  480. onLoad(option) {
  481. this.eqinfo = JSON.parse(option.shebei);
  482. this.basetype = this.eqinfo.type;
  483. this.cWidth = uni.upx2px(650);
  484. this.cHeight = uni.upx2px(500);
  485. this.device_id = option.id;
  486. this.end = parseInt(+new Date() / 1000);
  487. this.begintime = parseInt(this.end - 24 * 60 * 60);
  488. this.histprydatas();
  489. this.getChartLine();
  490. this.kongtf = this.$QueryPermission(347);
  491. this.datatf = this.$QueryPermission(348);
  492. },
  493. };
  494. </script>
  495. <style lang="scss">
  496. .info {
  497. width: 100%;
  498. .info_item {
  499. width: 90%;
  500. margin: 0 auto;
  501. height: 240rpx;
  502. padding: 40rpx 50rpx;
  503. position: relative;
  504. box-sizing: border-box;
  505. .bgi {
  506. width: 100%;
  507. height: 100%;
  508. position: absolute;
  509. top: 0;
  510. left: 0;
  511. z-index: -1;
  512. }
  513. p {
  514. font-size: 24rpx;
  515. color: #ffffff;
  516. margin-bottom: 10rpx;
  517. .tishi {
  518. width: 30rpx;
  519. height: 30rpx;
  520. margin: 0rpx 0 0 20rpx;
  521. }
  522. }
  523. }
  524. }
  525. .control {
  526. width: 90%;
  527. margin-top: 30rpx;
  528. display: flex;
  529. text-align: center;
  530. // padding: 0 30rpx;
  531. box-sizing: border-box;
  532. .control_item {
  533. width: 128rpx;
  534. height: 120rpx;
  535. width: 20%;
  536. image {
  537. width: 70rpx;
  538. height: 70rpx;
  539. }
  540. p {
  541. font-size: 24rpx;
  542. }
  543. }
  544. }
  545. .his_box {
  546. width: 100%;
  547. margin-top: 30rpx;
  548. position: relative;
  549. }
  550. .selecttimes {
  551. width: 90%;
  552. box-shadow: 0 0 10rpx #bcb9ca;
  553. padding: 10rpx 20rpx;
  554. box-sizing: border-box;
  555. margin: 0 auto;
  556. font-size: 28rpx;
  557. .timesbox {
  558. display: flex;
  559. justify-content: space-around;
  560. image {
  561. width: 30rpx;
  562. height: 30rpx;
  563. margin-top: 6rpx;
  564. }
  565. .icon {
  566. color: #949494;
  567. text-align: right;
  568. margin-left: 30rpx;
  569. }
  570. }
  571. ::v-deep .u-calendar__action {
  572. display: flex;
  573. justify-content: space-around;
  574. .u-calendar__action__text {
  575. line-height: 25px;
  576. }
  577. }
  578. }
  579. .shuju_one {
  580. width: 90%;
  581. margin: 20px auto;
  582. box-shadow: 0 0 10rpx #bcb9ca;
  583. padding-top: 20rpx;
  584. height: 1000rpx;
  585. .canvastishi {
  586. font-size: 32rpx;
  587. position: absolute;
  588. top: 50%;
  589. left: 50%;
  590. margin-left: -64rpx;
  591. margin-top: -21rpx;
  592. .dataloading:after {
  593. overflow: hidden;
  594. display: inline-block;
  595. vertical-align: bottom;
  596. animation: ellipsis 2s infinite;
  597. content: '\2026';
  598. }
  599. @keyframes ellipsis {
  600. from {
  601. width: 2px;
  602. }
  603. to {
  604. width: 15px;
  605. }
  606. }
  607. }
  608. }
  609. .condition {
  610. display: flex;
  611. flex-wrap: wrap;
  612. width: 90%;
  613. box-shadow: 0 0 10rpx #bcb9ca;
  614. margin: 0 auto 30rpx;
  615. .scroll-X {
  616. width: 95%;
  617. margin: 20rpx auto;
  618. .tr {
  619. display: flex;
  620. overflow: hidden;
  621. .th,
  622. .td {
  623. display: inline-block;
  624. padding: 5rpx;
  625. width: 300rpx;
  626. text-align: center;
  627. height: 52rpx;
  628. line-height: 52rpx;
  629. border: 2rpx solid #f1f1f1;
  630. }
  631. }
  632. .tr:nth-child(2n-1) {
  633. background-color: #f5fff8;
  634. }
  635. .tr:first-child {
  636. background-color: #57c878;
  637. color: #fff;
  638. }
  639. }
  640. .pagenumber {
  641. display: flex;
  642. margin: 20rpx auto;
  643. button {
  644. width: 150rpx;
  645. height: 50rpx;
  646. line-height: 50rpx;
  647. font-size: 26rpx;
  648. text-align: center;
  649. background-color: #57c878;
  650. color: #ffffff;
  651. }
  652. .pagenumber_page {
  653. width: 100rpx;
  654. height: 50rpx;
  655. line-height: 50rpx;
  656. font-size: 26rpx;
  657. text-align: center;
  658. }
  659. }
  660. }
  661. </style>