mls.vue 15 KB

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