mls.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  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 src="http://www.hnyfwlw.com:8006/bigdata_app/image/cb/onBg.png" mode="" class="bgi"></image>
  11. <p style="font-size: 32rpx" @click="copy(eqinfo.device_id)">
  12. 设备 ID:{{ eqinfo.device_id }}
  13. <image src="http://www.hnyfwlw.com:8006/bigdata_app/image/environment/fuzhi.png" mode=""
  14. class="tishi"></image>
  15. </p>
  16. <p>设备名称:{{ eqinfo.device_name || "无" }}</p>
  17. <p>
  18. 最近上报时间:<span v-if="eqinfo.uptime">{{ eqinfo.uptime == 0 ? '无' : eqinfo.uptime | timeFormat()
  19. }}</span><span v-else>{{eqinfo.uptime == 0 ? '无' : eqinfo.uptime | timeFormat() }}</span>
  20. </p>
  21. <p>地址:{{ eqinfo.location || "暂无地址" }}</p>
  22. </view>
  23. </view>
  24. <view class="control">
  25. <view class="control_item" v-if="kongtf" @click="control">
  26. <image :src="
  27. 'http://www.hnyfwlw.com:8006/bigdata_app' +
  28. '/image/environment/forecastResult.png'
  29. " mode=""></image>
  30. <p>防控决策</p>
  31. </view>
  32. </view>
  33. <view class="his_box" v-if="datatf">
  34. <view class="selecttimes" @click="tiemshow = !tiemshow">
  35. <view class="timesbox">
  36. <image
  37. :src="'http://www.hnyfwlw.com:8006/bigdata_app/image/prevention/1acfe2751c01d3786cdc49b83d7e505.png'"
  38. mode=""></image>
  39. <p>{{ timetab(begintime) }}</p>
  40. <p class="or">~</p>
  41. <p>{{ timetab(end) }}</p>
  42. <u-icon name="rili" custom-prefix="custom-icon" class="icon"></u-icon>
  43. </view>
  44. <u-calendar v-model="tiemshow" mode="range" @change="tiemchange"></u-calendar>
  45. </view>
  46. <view class="shuju_one">
  47. <view class="canvastishi" v-if="!canvastishiTF && !dataloadingtf">
  48. 暂无数据
  49. </view>
  50. <view class="canvastishi" v-if="dataloadingtf">
  51. <p class="dataloading">加载中</p>
  52. </view>
  53. <canvas v-show="!tiemshow" canvas-id="canvasColumnA" id="canvasColumnA" class="charts"
  54. @touchstart="touchLineA($event)" @touchmove="moveLineA($event)"
  55. @touchend="touchEndLineA($event)" disable-scroll="true" :style="{
  56. width: cWidth * pixelRatio + 'px',
  57. height: cHeight * pixelRatio + 'px',
  58. transform: 'scale(' + 1 / pixelRatio + ')',
  59. 'margin-left': (-cWidth * (pixelRatio - 1)) / 2 + 'px',
  60. 'margin-top': (-cHeight * (pixelRatio - 1)) / 2 + 'px',
  61. }"></canvas>
  62. <canvas v-show="!tiemshow" canvas-id="canvasColumnB" id="canvasColumnB" class="charts"
  63. @touchstart="touchLineB($event)" @touchmove="moveLineB($event)"
  64. @touchend="touchEndLineB($event)" disable-scroll="true" :style="{
  65. width: cWidth * pixelRatio + 'px',
  66. height: cHeight * pixelRatio + 'px',
  67. transform: 'scale(' + 1 / pixelRatio + ')',
  68. 'margin-left': (-cWidth * (pixelRatio - 1)) / 2 + 'px',
  69. 'margin-top': (-cHeight * (pixelRatio - 1)) / 2 + 'px',
  70. }"></canvas>
  71. </view>
  72. <view class="condition">
  73. <scroll-view scroll-top="0" scroll-x="true" class="scroll-X">
  74. <table class="table">
  75. <tr class="tr">
  76. <th class="th" v-for="(value, key) in param" :key="'a' + key">
  77. {{ value }}
  78. </th>
  79. </tr>
  80. <tr class="tr" v-for="(items, indexs) in historylistdata" :key="'b' + indexs"
  81. v-if="!forbidden">
  82. <td class="td" v-for="(value, key) in param">{{ items[key]}}</td>
  83. </tr>
  84. <tr class="tr" v-if="forbidden">
  85. <td class="td" v-for="item in 13">暂无数据</td>
  86. </tr>
  87. </table>
  88. </scroll-view>
  89. <view class="pagenumber">
  90. <button @click="prev">上一页</button>
  91. <view class="pagenumber_page"> 第 {{ page }} 页 </view>
  92. <view class="pagenumber_page"> 共 {{ pagesum }} 页 </view>
  93. <button @click="next">下一页</button>
  94. </view>
  95. </view>
  96. </view>
  97. </view>
  98. </view>
  99. </template>
  100. <script>
  101. import uCharts from "../../../components/js_sdk/u-charts/u-charts/u-charts.js";
  102. var canvaColumnA = null;
  103. var canvaColumnB = null;
  104. export default {
  105. data() {
  106. return {
  107. basetype: "",
  108. kongtf: false,
  109. datatf: false,
  110. eqinfo: {},
  111. city: "河南省",
  112. tiemshow: false, //时间筛选弹框
  113. begintime: "", //开始时间
  114. end: "", //结束时间
  115. dataloadingtf: true,
  116. canvastishiTF: false,
  117. device_id: "", //设备ID
  118. forbidden: false,
  119. historylistdata: [], //历史数据
  120. pagesum: 1,
  121. page: 1,
  122. cWidth: "",
  123. cHeight: "",
  124. pixelRatio: 1,
  125. param: {
  126. },
  127. color: [
  128. "#ff7b30",
  129. "#f93948",
  130. "#fb2ea4",
  131. "#bc59db",
  132. "#7457ec",
  133. "#307dfd",
  134. "#31bfff",
  135. "#46e9b1",
  136. "#19cd48",
  137. "#b2e409",
  138. "#f0f254",
  139. "#fed000",
  140. "#f06f14",
  141. "#a74040",
  142. "#90bb71",
  143. "#a07635",
  144. "#6502bd",
  145. "#048bbb",
  146. "#9ebb01",
  147. "#cc9202",
  148. "#ff8fa0",
  149. "#a3d55f",
  150. "#d9bedd",
  151. "#00a6b6",
  152. "#236093",
  153. "#009fff",
  154. "#ddc0a6",
  155. "#c4a6dd",
  156. "#dda6a6",
  157. "#779e33",
  158. "#a6ddb0",
  159. ],
  160. };
  161. },
  162. methods: {
  163. copy(item) {
  164. uni.setClipboardData({
  165. data: item,
  166. success: function() {
  167. console.log("success");
  168. },
  169. });
  170. },
  171. control() {
  172. //设备控制
  173. uni.navigateTo({
  174. url: "./forecastResult?id=" + this.eqinfo.device_id,
  175. });
  176. },
  177. tiemchange(e) {
  178. console.log(e);
  179. //切换时间
  180. // this.begintime = parseInt(+new Date(e.startDate) / 1000);
  181. this.begintime = parseInt(+new Date(`${e.startDate} 00:00:00`) / 1000);
  182. this.end = parseInt(+new Date(`${e.endDate} 00:00:00`) / 1000);
  183. this.histprydatas();
  184. this.getChartLine();
  185. },
  186. timetab(e) {
  187. //时间转换
  188. e = new Date(e * 1000);
  189. var year = e.getFullYear();
  190. var month =
  191. e.getMonth() + 1 < 10 ? "0" + (e.getMonth() + 1) : e.getMonth() + 1;
  192. var day = e.getDate() < 10 ? "0" + e.getDate() : e.getDate();
  193. var time = year + "/" + month + "/" + day;
  194. return time;
  195. },
  196. // 表格数据
  197. async histprydatas() {
  198. //表格历史数据
  199. const res = await this.$myRequest({
  200. url: "/api/api_gateway?method=wheat.potato.potato_data_list",
  201. data: {
  202. device_id: this.eqinfo.device_id,
  203. page: this.page,
  204. begin: this.begintime,
  205. end: this.end,
  206. },
  207. });
  208. console.log(res);
  209. this.param = res.ele
  210. this.pagesum = Math.ceil(res.nums / 10) || 1;
  211. if (this.pagesum > 0) {
  212. var dat = res.sta;
  213. this.historylistdata = [];
  214. for (var i = 0; i < dat.length; i++) {
  215. var item = eval("(" + dat[i] + ")");
  216. var obj = {};
  217. for (var i1 in item) {
  218. // if (i1 == "uploadTime") {
  219. // obj[i1] = this.formatTime(item[i1] * 1000);
  220. // } else {
  221. obj[i1] = item[i1];
  222. // }
  223. }
  224. this.historylistdata.push(obj);
  225. }
  226. } else {
  227. this.historylistdata = [];
  228. }
  229. },
  230. //获取折线图数据
  231. async getChartLine() {
  232. const res = await this.$myRequest({
  233. method: "POST",
  234. url: "/api/api_gateway?method=wheat.potato.potato_data",
  235. data: {
  236. device_id: this.eqinfo.device_id,
  237. begin: this.begintime,
  238. end: this.end,
  239. },
  240. });
  241. this.dataloadingtf = false;
  242. var dat = res.data;
  243. this.param = res.ele;
  244. if (dat.length) {
  245. var regroupData = []; //重组数据
  246. var kindArr = []; //通道数组
  247. var time = [];
  248. var xtitle = [];
  249. for (var i = 0; i < dat.length; i++) {
  250. var item = eval("(" + dat[i] + ")");
  251. console.log(item)
  252. var tim = new Date(item["dataTime"]).getTime();
  253. var times = new Date(tim);
  254. xtitle.unshift(
  255. times.getMonth() +
  256. 1 +
  257. "/" +
  258. times.getDate() +
  259. "-" +
  260. times.getHours() +
  261. ":" +
  262. times.getMinutes()
  263. );
  264. time.unshift(tim);
  265. for (var j in item) {
  266. var arr = "";
  267. if (j == "id" || j == "dataTime" || j=='windDir') {
  268. continue;
  269. } else if (kindArr.indexOf(j) == "-1") {
  270. kindArr.push(j);
  271. regroupData.push({
  272. name: this.param[j],
  273. color: this.color[kindArr.length - 1],
  274. data: [],
  275. });
  276. // arr.push(tim);
  277. arr = parseFloat(item[j]);
  278. regroupData[kindArr.indexOf(j)].data.unshift(arr);
  279. } else {
  280. // arr.push(tim);
  281. // arr.push(parseFloat(item[j]));
  282. arr = parseFloat(item[j]);
  283. regroupData[kindArr.indexOf(j)].data.unshift(arr);
  284. }
  285. }
  286. }
  287. console.log(regroupData);
  288. // 分割折线图
  289. const regroupDataNum = Math.ceil(regroupData.length / 2);
  290. const options1 = regroupData.filter((v, i) => {
  291. return i < regroupDataNum;
  292. });
  293. const options2 = regroupData.filter((v, i) => {
  294. return i >= regroupDataNum;
  295. });
  296. console.log(options1, options2);
  297. this.showColumn("canvasColumnA", xtitle, options1);
  298. this.showColumn("canvasColumnB", xtitle, options2);
  299. this.canvastishiTF = true;
  300. } else {
  301. this.canvastishiTF = false;
  302. this.showColumn("canvasColumnA", xtitle, []);
  303. this.showColumn("canvasColumnB", xtitle, []);
  304. }
  305. },
  306. prev() {
  307. //上一页
  308. if (this.page > 1) {
  309. this.page--;
  310. this.histprydatas();
  311. }
  312. },
  313. next() {
  314. //下一页
  315. if (this.page < this.pagesum) {
  316. this.page++;
  317. this.histprydatas();
  318. }
  319. },
  320. clickLeft() {
  321. uni.navigateBack({
  322. delta: 1,
  323. });
  324. },
  325. showColumn(id, xtitle, xinfo) {
  326. console.log(id);
  327. var _self = this;
  328. if (id === "canvasColumnA") {
  329. canvaColumnA = new uCharts({
  330. canvasId: id,
  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. canvasId: id,
  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. margin-top: 30rpx;
  479. display: flex;
  480. text-align: center;
  481. // padding: 0 30rpx;
  482. box-sizing: border-box;
  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. margin-top: 30rpx;
  499. position: relative;
  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>