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="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. if (id === "canvasColumnA") {
  328. canvaColumnA = new uCharts({
  329. canvasId: id,
  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. canvasId: id,
  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>