mls.vue 16 KB

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