history.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. <template>
  2. <view class="container">
  3. <!-- 建议放在外层 -->
  4. <!-- <u-navbar
  5. title="历史数据"
  6. @leftClick="devicemenuShow"
  7. :safeAreaInsetTop="true"
  8. >
  9. <view class="u-nav-slot" slot="left">
  10. <u-icon name="list" size="20"> </u-icon>
  11. </view>
  12. </u-navbar> -->
  13. <!-- 侧边栏 -->
  14. <view v-show="menushow" class="menupage">
  15. <DeviceMenu @menuClick="menuClick"></DeviceMenu>
  16. </view>
  17. <!-- 历史数据列表页 -->
  18. <view v-if="!menushow" class="main">
  19. <view class="u-page">
  20. <div class="flcard">
  21. <div class="btns">
  22. <uni-datetime-picker
  23. :show="dataShow"
  24. mode="datetime"
  25. @cancel="dataShow = false"
  26. @confirm="selectStartTime"
  27. v-model="StartTime"
  28. ></uni-datetime-picker>
  29. <uni-datetime-picker
  30. :show="dataShow1"
  31. mode="datetime"
  32. @cancel="dataShow1 = false"
  33. @confirm="selectEndTime"
  34. v-model="EndTime"
  35. ></uni-datetime-picker>
  36. </div>
  37. <div class="btns" style="margin-top: 10px">
  38. <u-button
  39. type="primary"
  40. :text="deviceName ? deviceName : '选择设备'"
  41. @click="deviceShow = true"
  42. ></u-button>
  43. <!-- <u-button
  44. v-show="TabCur == 'fanmain' || TabCur == 'fanlocal'"
  45. type="primary"
  46. :text="labelName ? labelName : '子设备'"
  47. @click="deviceShow1 = true"
  48. ></u-button> -->
  49. <u-button
  50. type="primary"
  51. :text="lable ? lable : '间隔时间'"
  52. @click="show = true"
  53. ></u-button>
  54. <u-button
  55. type="primary"
  56. text="查询"
  57. @click="checkHistory"
  58. ></u-button>
  59. </div>
  60. <u-picker
  61. :show="deviceShow"
  62. :columns="[devices]"
  63. @cancel="deviceShow = false"
  64. @confirm="selectDevice"
  65. keyName="strinstallpos"
  66. >
  67. </u-picker>
  68. <u-picker
  69. :show="deviceShow1"
  70. :columns="devices1"
  71. @cancel="deviceShow1 = false"
  72. @confirm="selectDevice1"
  73. keyName="label"
  74. ></u-picker>
  75. <u-picker
  76. :show="show"
  77. :columns="timeColumns"
  78. @cancel="show = false"
  79. keyName="label"
  80. @confirm="selectSkipTime"
  81. ></u-picker>
  82. </div>
  83. <u-list
  84. :class="{ emptyhistory: historyData.length === 0 }"
  85. class="historycontainer"
  86. >
  87. <template v-if="historyData.length > 0">
  88. <u-list-item
  89. class="itemback"
  90. v-for="(item, index) in historyData"
  91. :key="index"
  92. >
  93. <u-row gutter="5" customStyle="margin-bottom: 10px">
  94. <u-col span="24">
  95. <u--text :text="item.ginstallpos"></u--text>
  96. </u-col>
  97. </u-row>
  98. <u-row gutter="5" customStyle="margin-bottom: 10px">
  99. <u-col span="2" style="margin-right: 15rpx">
  100. <div v-if="item.netStatus == 0" class="error-tag1">
  101. <image
  102. src="/static/model/connectFalse.svg"
  103. alt=""
  104. class="icon-style"
  105. />
  106. <span style="float: right">断开</span>
  107. </div>
  108. <div v-else class="success-tag">
  109. <image
  110. src="/static/model/connectTrue.svg"
  111. alt=""
  112. class="icon-style"
  113. />
  114. <span style="float: right">连接</span>
  115. </div>
  116. </u-col>
  117. <u-col span="2"> </u-col>
  118. <u-col span="3"> </u-col>
  119. <u-col span="5">
  120. <u--text class="timetext" :text="item.ttime"></u--text>
  121. </u-col>
  122. </u-row>
  123. <view
  124. style="
  125. display: flex;
  126. flex-wrap: wrap;
  127. justify-content: space-between;
  128. "
  129. >
  130. <view
  131. class="datacard"
  132. v-for="(showitem, index) in deviceShowList"
  133. :key="index"
  134. v-show="showitem.appShow == 1"
  135. >
  136. <view
  137. :class="TabCur"
  138. style="
  139. padding-top: 10rpx;
  140. padding-bottom: 10rpx;
  141. display: flex;
  142. flex-direction: column;
  143. align-items: center;
  144. height: 100%;
  145. "
  146. >
  147. <view
  148. v-if="
  149. showitem.datatype == 1 &&
  150. showitem.monitorcode == 'doorUse'
  151. "
  152. class="demo-layout bg-purple-light"
  153. style="
  154. margin-top: 10rpx;
  155. color: #3787fe;
  156. font-size: 30rpx;
  157. margin-top: 20rpx;
  158. "
  159. >
  160. {{
  161. item[showitem.monitorcode] == "2"
  162. ? "行人"
  163. : item[showitem.monitorcode] == "1"
  164. ? "行车"
  165. : "-"
  166. }}
  167. </view>
  168. <view
  169. v-else-if="showitem.datatype == 1"
  170. class="demo-layout bg-purple-light"
  171. style="
  172. margin-top: 10rpx;
  173. color: #3787fe;
  174. font-size: 30rpx;
  175. margin-top: 20rpx;
  176. "
  177. >
  178. {{
  179. item[showitem.monitorcode] == null ||
  180. item[showitem.monitorcode] == ""
  181. ? "-"
  182. : item[showitem.monitorcode]
  183. }}
  184. </view>
  185. <view
  186. v-else-if="showitem.datatype == 2"
  187. class="demo-layout bg-purple-light"
  188. style="
  189. color: #3787fe;
  190. font-size: 30rpx;
  191. margin-top: 20rpx;
  192. "
  193. >
  194. {{
  195. item[showitem.monitorcode] == null ||
  196. item[showitem.monitorcode] == ""
  197. ? "-"
  198. : item[showitem.monitorcode]
  199. }}
  200. </view>
  201. <view
  202. class="demo-layout bg-purple-light"
  203. style="
  204. margin-top: 20rpx;
  205. color: #677799;
  206. margin-top: 20rpx;
  207. "
  208. >
  209. {{ showitem.des }}
  210. </view>
  211. </view>
  212. </view>
  213. </view>
  214. </u-list-item>
  215. </template>
  216. <template v-else>
  217. <div class="empty-message">数据为空</div>
  218. </template>
  219. </u-list>
  220. </view>
  221. </view>
  222. </view>
  223. </template>
  224. <script>
  225. import api from "@/api/api";
  226. import dayjs from "dayjs";
  227. import DeviceMenu from "../../pages/device/devicemenu/devicemenu";
  228. import uniDatetimePicker from "../../uni_modules/uni-datetime-picker/components/uni-datetime-picker/uni-datetime-picker.vue";
  229. export default {
  230. data() {
  231. return {
  232. menushow: false,
  233. TabCur: "gate",
  234. curlist: [],
  235. colums: [],
  236. deviceList: {},
  237. startDate: null,
  238. endDate: null,
  239. show: false,
  240. deviceShow: false,
  241. deviceShow1: false,
  242. dataShow: false,
  243. dataShow1: false,
  244. StartTime: "", //起始时间
  245. EndTime: "", //结束时间
  246. devices: [], //设备类型数组
  247. devices1: [
  248. [
  249. {
  250. label: "1#风机",
  251. value: "fan1",
  252. },
  253. {
  254. label: "2#风机",
  255. value: "fan2",
  256. },
  257. ],
  258. ], //子设备类型数组
  259. deviceName: "", //设备名称
  260. labelName: "", //子设备名称
  261. timeS: "", //间隔时间
  262. lable: "", //间隔时间
  263. timeColumns: [
  264. [
  265. {
  266. label: "1秒",
  267. value: "1",
  268. value1: "1s",
  269. },
  270. {
  271. label: "5秒",
  272. value: "2",
  273. value1: "5s",
  274. },
  275. {
  276. label: "10秒",
  277. value: "3",
  278. value1: "10s",
  279. },
  280. {
  281. label: "30秒",
  282. value: "4",
  283. value1: "30s",
  284. },
  285. {
  286. label: "1分钟",
  287. value: "5",
  288. value1: "1m",
  289. },
  290. {
  291. label: "10分钟",
  292. value: "6",
  293. value1: "10m",
  294. },
  295. {
  296. label: "30分钟",
  297. value: "7",
  298. value1: "30m",
  299. },
  300. {
  301. label: "1小时",
  302. value: "8",
  303. value1: "1h",
  304. },
  305. ],
  306. ],
  307. deviceID: "", //设备ID
  308. //deviceType: "", //设备类型
  309. skip: 8, //时间间隔
  310. interval: "1h", //时间间隔
  311. dataTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
  312. historyData: [], //历史数据
  313. deviceShowList: [],
  314. loading: false, // 是否正在加载数据
  315. hasMoreData: true, // 是否还有更多数据可以加载
  316. pageNo: 1, // 当前页码(用于请求数据时分页)
  317. stationType: "plc1", // 站点类型(用于请求数据时的参数)
  318. };
  319. },
  320. components: {
  321. DeviceMenu,
  322. uniDatetimePicker,
  323. },
  324. props: ["showColum", "deviceType"],
  325. watch: {
  326. deviceType: {
  327. async handler(data) {
  328. if (data) {
  329. this.TabCur = data;
  330. console.log(this.TabCur, "设备");
  331. this.curlist = this.deviceList[this.TabCur];
  332. if (this.curlist == null) {
  333. this.curlist = [];
  334. }
  335. // 选择设备分类,重新获取数据
  336. await this.loadData(this.TabCur);
  337. this.$emit("setMenushow", {
  338. menushow: false,
  339. });
  340. }
  341. },
  342. immediate: true,
  343. },
  344. },
  345. created() {
  346. this.colums = this.showColum;
  347. const key = this.TabCur + "_history";
  348. this.deviceShowList = this.colums[key];
  349. const startTime = new Date().getTime() - 3600 * 1000 * 24 * 30;
  350. const endTime = new Date();
  351. this.StartTime = dayjs(startTime).format("YYYY-MM-DD HH:mm:ss");
  352. this.EndTime = dayjs(endTime).format("YYYY-MM-DD HH:mm:ss");
  353. },
  354. mounted() {
  355. // this.TabCur = deviceType;
  356. this.loadData(this.TabCur);
  357. },
  358. computed: {},
  359. methods: {
  360. loadData(type) {
  361. new Promise((resolve, reject) => {
  362. api
  363. .getDeviceMonitor({
  364. devicetype: type,
  365. pagetype: "normal",
  366. filterParams: {},
  367. })
  368. .then((response) => {
  369. if (response.data.code == 200) {
  370. this.deviceList[type] = response.data.result.msgTxt[0].datalist;
  371. this.curlist = this.deviceList[type];
  372. this.setData(this.curlist);
  373. } else {
  374. resolve(response);
  375. }
  376. })
  377. .catch((error) => {
  378. reject(error);
  379. });
  380. });
  381. },
  382. //选择设备选择器 保存对应的id
  383. setData(data) {
  384. this.devices = [];
  385. data.forEach((element) => {
  386. const deviceObj = {
  387. id: element.deviceID,
  388. strinstallpos: element.strinstallpos,
  389. type: element.deviceType,
  390. stationType: element.stationType,
  391. };
  392. this.devices.push(deviceObj);
  393. });
  394. },
  395. //选择设备 点击确定按钮 保存id
  396. selectDevice(e) {
  397. this.deviceID = e.value[0].id;
  398. this.stationType = e.value[0].stationType;
  399. // console.log(this.TabCur, "设备类型");
  400. this.deviceName = e.value[0].strinstallpos;
  401. this.deviceShow = false;
  402. },
  403. selectDevice1(e) {
  404. this.deviceNum = e.value[0].value;
  405. this.labelName = e.value[0].label;
  406. this.deviceShow1 = false;
  407. },
  408. //选择起始时间
  409. selectStartTime(e) {
  410. const startTime = e.value;
  411. const formattedTime = dayjs(startTime).format("YYYY-MM-DD HH:mm:ss");
  412. this.StartTime = formattedTime;
  413. this.dataShow = false;
  414. },
  415. //选择结束时间
  416. selectEndTime(e) {
  417. const endTime = e.value;
  418. const formattedTime = dayjs(endTime).format("YYYY-MM-DD HH:mm:ss");
  419. this.EndTime = formattedTime;
  420. this.dataShow1 = false;
  421. },
  422. //选择间隔时间
  423. selectSkipTime(e) {
  424. this.skip = e.value[0].value;
  425. this.interval = e.value[0].value1;
  426. this.lable = e.value[0].label;
  427. this.show = false;
  428. },
  429. //查询历史数据 getDeviceHistory
  430. checkHistory() {
  431. if (this.stationType !== "redis") {
  432. console.log(this.stationType, "stationType");
  433. this.getHistoryData();
  434. } else {
  435. this.getHistoryData2();
  436. }
  437. },
  438. // 查询历史数据
  439. getHistoryData() {
  440. const params = {
  441. ttime_begin: this.StartTime,
  442. ttime_end: this.EndTime,
  443. gdeviceid: this.deviceID,
  444. skip: this.skip,
  445. pageNo: this.pageNo,
  446. pageSize: 10,
  447. strtype: this.TabCur,
  448. };
  449. new Promise((resolve, reject) => {
  450. api
  451. .getDeviceHistory(params)
  452. .then((response) => {
  453. if (response.data.code == 200) {
  454. const infolist = response.data.result;
  455. this.historyData = infolist.datalist.records;
  456. this.historyData.forEach((item) => {
  457. if (item.readData.frontGateOpen == 1) {
  458. item.readData.frontGateOpen = "打开";
  459. } else {
  460. item.readData.frontGateOpen = "关闭";
  461. }
  462. if (item.readData.rearGateOpen == 1) {
  463. item.readData.rearGateOpen = "打开";
  464. } else {
  465. item.readData.rearGateOpen = "关闭";
  466. }
  467. if (item.readData.midGateOpen == 1) {
  468. item.readData.midGateOpen = "打开";
  469. } else {
  470. item.readData.midGateOpen = "关闭";
  471. }
  472. });
  473. this.pageNo = response.data.result.datalist.current;
  474. } else {
  475. resolve(response);
  476. }
  477. })
  478. .catch((error) => {
  479. reject(error);
  480. });
  481. });
  482. },
  483. getHistoryData2() {
  484. const params = {
  485. startTime: this.StartTime,
  486. endTIme: this.EndTime,
  487. deviceId: this.deviceID,
  488. interval: this.interval,
  489. isEmployee: true,
  490. pageSize: 10,
  491. strtype: this.TabCur,
  492. };
  493. new Promise((resolve, reject) => {
  494. api
  495. .getDeviceHistory2(params)
  496. .then((response) => {
  497. if (response.data.code == 200) {
  498. const infolist = response.data.result;
  499. this.historyData = infolist.records;
  500. this.historyData.forEach((item) => {
  501. if (item.readData.frontGateOpen == 1) {
  502. item.readData.frontGateOpen = "打开";
  503. } else {
  504. item.readData.frontGateOpen = "关闭";
  505. }
  506. if (item.readData.rearGateOpen == 1) {
  507. item.readData.rearGateOpen = "打开";
  508. } else {
  509. item.readData.rearGateOpen = "关闭";
  510. }
  511. if (item.readData.midGateOpen == 1) {
  512. item.readData.midGateOpen = "打开";
  513. } else {
  514. item.readData.midGateOpen = "关闭";
  515. }
  516. });
  517. this.pageNo = response.data.result.datalist.current;
  518. } else {
  519. resolve(response);
  520. }
  521. })
  522. .catch((error) => {
  523. reject(error);
  524. });
  525. });
  526. },
  527. async loadMoreData() {
  528. if (this.loading || !this.hasMoreData) return;
  529. this.loading = true;
  530. try {
  531. // 如果新数据为空,则表示没有更多数据了
  532. if (this.historyData.length === 0) {
  533. this.hasMoreData = false;
  534. } else {
  535. // 将新数据追加到数据列表中
  536. this.historyData = [...this.historyData, ...newData];
  537. // 更新页码以便下次加载下一页数据
  538. this.pageNo += 1;
  539. }
  540. } catch (error) {
  541. // 处理请求错误
  542. console.error("加载数据失败:", error);
  543. } finally {
  544. // 无论请求成功还是失败,都要将加载状态设置为false
  545. this.loading = false;
  546. }
  547. },
  548. devicemenuShow(e) {
  549. this.menushow = !this.menushow;
  550. },
  551. menuClick(id) {
  552. this.TabCur = id;
  553. console.log(this.TabCur);
  554. // 显示该分类的数据
  555. this.curlist = this.deviceList[this.TabCur];
  556. if (this.curlist == null) {
  557. this.curlist = [];
  558. }
  559. // 选择设备分类,重新获取数据
  560. this.loadData(this.TabCur);
  561. this.menushow = false;
  562. },
  563. },
  564. destroyed() {
  565. // 停止定时器
  566. },
  567. onReachBottom() {
  568. // uni-app提供的页面滚动到底部钩子函数
  569. console.log("上拉加载更多数据");
  570. this.loadMoreData();
  571. },
  572. };
  573. </script>
  574. <style lang="scss" scoped>
  575. .emptyhistory {
  576. background: url("/static/empty.png") no-repeat;
  577. background-size: 100% 50%;
  578. }
  579. .empty-message {
  580. display: flex;
  581. justify-content: center;
  582. align-items: center;
  583. font-size: 16px;
  584. line-height: 80vh;
  585. color: #333;
  586. }
  587. .content {
  588. width: 100%;
  589. display: flex;
  590. flex-direction: column;
  591. }
  592. .main {
  593. /* margin-top: 100rpx; */
  594. display: flex;
  595. flex-direction: column;
  596. }
  597. .menupage {
  598. position: absolute;
  599. z-index: 2;
  600. top: 40rpx;
  601. height: calc(100% - 40rpx);
  602. width: 100%;
  603. }
  604. .btns {
  605. display: flex;
  606. }
  607. .btns > * {
  608. margin-right: 10px; /* 根据需要调整间距大小 */
  609. }
  610. /* 去除最后一个按钮的右边距 */
  611. .btns > *:last-child {
  612. margin-right: 0;
  613. }
  614. .flcard {
  615. padding: 20rpx;
  616. background-color: #ffffff;
  617. margin-bottom: 5rpx;
  618. }
  619. .itemback {
  620. padding: 20rpx;
  621. background-color: #ffffff;
  622. margin-bottom: 5rpx;
  623. }
  624. .datacard {
  625. width: 30%;
  626. margin: 1%;
  627. float: left;
  628. height: 190rpx;
  629. text-align: center;
  630. background: linear-gradient(
  631. to right,
  632. rgba(55, 135, 254, 0.08),
  633. rgba(4, 184, 255, 0.08),
  634. rgba(60, 161, 237, 0.08)
  635. );
  636. }
  637. .error-tag {
  638. border-radius: 10%;
  639. display: inline-block;
  640. color: #e90000;
  641. line-height: 50rpx;
  642. font-size: 14px;
  643. text-align: center;
  644. width: 120rpx;
  645. height: 50rpx;
  646. background-color: rgba(233, 0, 0, 0.2);
  647. }
  648. .error-tag1 {
  649. border-radius: 10%;
  650. display: inline-block;
  651. color: #696969;
  652. line-height: 50rpx;
  653. font-size: 14px;
  654. text-align: center;
  655. width: 120rpx;
  656. height: 50rpx;
  657. background-color: rgba(105, 105, 105, 0.2);
  658. }
  659. .success-tag {
  660. border-radius: 10%;
  661. color: #42c000;
  662. line-height: 50rpx;
  663. font-size: 14px;
  664. width: 120rpx;
  665. height: 50rpx;
  666. display: inline-block;
  667. background-color: rgba(226, 250, 214, 0.5);
  668. }
  669. .icon-style {
  670. margin: 15rpx;
  671. width: 14px;
  672. height: 14px;
  673. }
  674. </style>