mls.vue 16 KB

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