history.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  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="
  187. showitem.datatype == 2 && stationType != 'redis'
  188. "
  189. class="demo-layout bg-purple-light"
  190. style="
  191. color: #3787fe;
  192. font-size: 30rpx;
  193. margin-top: 20rpx;
  194. "
  195. >
  196. {{
  197. item.readData[showitem.monitorcode] == null ||
  198. item.readData[showitem.monitorcode] == ""
  199. ? "-"
  200. : item.readData[showitem.monitorcode]
  201. }}
  202. </view>
  203. <view
  204. v-else-if="
  205. showitem.datatype == 2 && stationType == 'redis'
  206. "
  207. class="demo-layout bg-purple-light"
  208. style="
  209. color: #3787fe;
  210. font-size: 30rpx;
  211. margin-top: 20rpx;
  212. "
  213. >
  214. {{
  215. item[showitem.monitorcode] == null ||
  216. item[showitem.monitorcode] == ""
  217. ? "-"
  218. : item[showitem.monitorcode]
  219. }}
  220. </view>
  221. <view
  222. class="demo-layout bg-purple-light"
  223. style="
  224. margin-top: 20rpx;
  225. color: #677799;
  226. margin-top: 20rpx;
  227. "
  228. >
  229. {{ showitem.des }}
  230. </view>
  231. </view>
  232. </view>
  233. </view>
  234. </u-list-item>
  235. </template>
  236. <template v-else>
  237. <div class="empty-message">数据为空</div>
  238. </template>
  239. </u-list>
  240. </view>
  241. </view>
  242. </view>
  243. </template>
  244. <script>
  245. import api from "@/api/api";
  246. import dayjs from "dayjs";
  247. import DeviceMenu from "../../pages/device/devicemenu/devicemenu";
  248. import uniDatetimePicker from "../../uni_modules/uni-datetime-picker/components/uni-datetime-picker/uni-datetime-picker.vue";
  249. export default {
  250. data() {
  251. return {
  252. menushow: false,
  253. TabCur: "gate",
  254. curlist: [],
  255. colums: [],
  256. deviceList: {},
  257. startDate: null,
  258. endDate: null,
  259. show: false,
  260. deviceShow: false,
  261. deviceShow1: false,
  262. dataShow: false,
  263. dataShow1: false,
  264. StartTime: "", //起始时间
  265. EndTime: "", //结束时间
  266. devices: [], //设备类型数组
  267. devices1: [
  268. [
  269. {
  270. label: "1#风机",
  271. value: "fan1",
  272. },
  273. {
  274. label: "2#风机",
  275. value: "fan2",
  276. },
  277. ],
  278. ], //子设备类型数组
  279. deviceName: "", //设备名称
  280. labelName: "", //子设备名称
  281. timeS: "", //间隔时间
  282. lable: "", //间隔时间
  283. timeColumns: [
  284. [
  285. {
  286. label: "1秒",
  287. value: "1",
  288. value1: "1s",
  289. },
  290. {
  291. label: "5秒",
  292. value: "2",
  293. value1: "5s",
  294. },
  295. {
  296. label: "10秒",
  297. value: "3",
  298. value1: "10s",
  299. },
  300. {
  301. label: "30秒",
  302. value: "4",
  303. value1: "30s",
  304. },
  305. {
  306. label: "1分钟",
  307. value: "5",
  308. value1: "1m",
  309. },
  310. {
  311. label: "10分钟",
  312. value: "6",
  313. value1: "10m",
  314. },
  315. {
  316. label: "30分钟",
  317. value: "7",
  318. value1: "30m",
  319. },
  320. {
  321. label: "1小时",
  322. value: "8",
  323. value1: "1h",
  324. },
  325. ],
  326. ],
  327. deviceID: "", //设备ID
  328. //deviceType: "", //设备类型
  329. skip: 8, //时间间隔
  330. interval: "1h", //时间间隔
  331. dataTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
  332. historyData: [], //历史数据
  333. deviceShowList: [],
  334. loading: false, // 是否正在加载数据
  335. hasMoreData: true, // 是否还有更多数据可以加载
  336. pageNo: 1, // 当前页码(用于请求数据时分页)
  337. stationType: "plc1", // 站点类型(用于请求数据时的参数)
  338. strType: "", //设备小类
  339. };
  340. },
  341. components: {
  342. DeviceMenu,
  343. uniDatetimePicker,
  344. },
  345. props: ["showColum", "deviceType"],
  346. watch: {
  347. deviceType: {
  348. async handler(data) {
  349. if (data) {
  350. this.TabCur = data;
  351. console.log(this.TabCur, "设备");
  352. this.curlist = this.deviceList[this.TabCur];
  353. if (this.curlist == null) {
  354. this.curlist = [];
  355. }
  356. // 选择设备分类,重新获取数据
  357. await this.loadData(this.TabCur);
  358. this.$emit("setMenushow", {
  359. menushow: false,
  360. });
  361. }
  362. },
  363. immediate: true,
  364. },
  365. },
  366. created() {
  367. this.colums = this.showColum;
  368. const key = this.TabCur + "_history";
  369. this.deviceShowList = this.colums[key];
  370. const startTime = new Date().getTime() - 3600 * 1000 * 24 * 30;
  371. const endTime = new Date();
  372. this.StartTime = dayjs(startTime).format("YYYY-MM-DD HH:mm:ss");
  373. this.EndTime = dayjs(endTime).format("YYYY-MM-DD HH:mm:ss");
  374. },
  375. mounted() {
  376. // this.TabCur = deviceType;
  377. this.loadData(this.TabCur);
  378. },
  379. computed: {},
  380. methods: {
  381. loadData(type) {
  382. new Promise((resolve, reject) => {
  383. api
  384. .getDeviceMonitor({
  385. devicetype: type,
  386. pagetype: "normal",
  387. filterParams: {},
  388. })
  389. .then((response) => {
  390. if (response.data.code == 200) {
  391. this.deviceList[type] = response.data.result.msgTxt[0].datalist;
  392. this.curlist = this.deviceList[type];
  393. console.log(this.curlist, "设备列表");
  394. this.setData(this.curlist);
  395. } else {
  396. resolve(response);
  397. }
  398. })
  399. .catch((error) => {
  400. reject(error);
  401. });
  402. });
  403. },
  404. //选择设备选择器 保存对应的id
  405. setData(data) {
  406. this.devices = [];
  407. data.forEach((element) => {
  408. const deviceObj = {
  409. id: element.deviceID,
  410. strinstallpos: element.strinstallpos,
  411. type: element.deviceType,
  412. stationType: element.stationType,
  413. strtype: element.strtype,
  414. };
  415. this.devices.push(deviceObj);
  416. });
  417. },
  418. //选择设备 点击确定按钮 保存id
  419. selectDevice(e) {
  420. this.deviceID = e.value[0].id;
  421. this.stationType = e.value[0].stationType;
  422. this.strType = e.value[0].strtype;
  423. // console.log(this.TabCur, "设备类型");
  424. this.deviceName = e.value[0].strinstallpos;
  425. this.deviceShow = false;
  426. },
  427. selectDevice1(e) {
  428. this.deviceNum = e.value[0].value;
  429. this.labelName = e.value[0].label;
  430. this.deviceShow1 = false;
  431. },
  432. //选择起始时间
  433. selectStartTime(e) {
  434. const startTime = e.value;
  435. const formattedTime = dayjs(startTime).format("YYYY-MM-DD HH:mm:ss");
  436. this.StartTime = formattedTime;
  437. this.dataShow = false;
  438. },
  439. //选择结束时间
  440. selectEndTime(e) {
  441. const endTime = e.value;
  442. const formattedTime = dayjs(endTime).format("YYYY-MM-DD HH:mm:ss");
  443. this.EndTime = formattedTime;
  444. this.dataShow1 = false;
  445. },
  446. //选择间隔时间
  447. selectSkipTime(e) {
  448. this.skip = e.value[0].value;
  449. this.interval = e.value[0].value1;
  450. this.lable = e.value[0].label;
  451. this.show = false;
  452. },
  453. //查询历史数据 getDeviceHistory
  454. checkHistory() {
  455. if (this.stationType !== "redis") {
  456. this.getHistoryData();
  457. } else {
  458. this.getHistoryData2();
  459. }
  460. },
  461. // 查询历史数据
  462. getHistoryData() {
  463. const params = {
  464. ttime_begin: this.StartTime,
  465. ttime_end: this.EndTime,
  466. gdeviceid: this.deviceID,
  467. skip: this.skip,
  468. pageNo: this.pageNo,
  469. pageSize: 10,
  470. strtype: this.TabCur,
  471. };
  472. new Promise((resolve, reject) => {
  473. api
  474. .getDeviceHistory(params)
  475. .then((response) => {
  476. if (response.data.code == 200) {
  477. const infolist = response.data.result;
  478. this.historyData = infolist.datalist.records;
  479. // console.log(this.historyData, "111111111111111111");
  480. // this.historyData.forEach((item) => {
  481. // if (item.readData.frontGateOpen == 1) {
  482. // item.readData.frontGateOpen = "打开";
  483. // } else {
  484. // item.readData.frontGateOpen = "关闭";
  485. // }
  486. // if (item.readData.rearGateOpen == 1) {
  487. // item.readData.rearGateOpen = "打开";
  488. // 1;
  489. // } else {
  490. // item.readData.rearGateOpen = "关闭";
  491. // }
  492. // if (item.readData.midGateOpen == 1) {
  493. // item.readData.midGateOpen = "打开";
  494. // } else {
  495. // item.readData.midGateOpen = "关闭";
  496. // }
  497. // });
  498. this.pageNo = response.data.result.datalist.current;
  499. } else {
  500. resolve(response);
  501. }
  502. })
  503. .catch((error) => {
  504. reject(error);
  505. });
  506. });
  507. },
  508. getHistoryData2() {
  509. const params = {
  510. column: "createTime",
  511. startTime: this.StartTime,
  512. endTIme: this.EndTime,
  513. deviceId: this.deviceID,
  514. interval: this.interval,
  515. isEmployee: true,
  516. pageNo: 1,
  517. pageSize: 10,
  518. strtype: this.strType,
  519. };
  520. new Promise((resolve, reject) => {
  521. api
  522. .getDeviceHistory2(params)
  523. .then((response) => {
  524. if (response.data.code == 200) {
  525. const infolist = response.data.result;
  526. this.historyData = infolist.records;
  527. // this.historyData.forEach((item) => {
  528. // if (item.readData.frontGateOpen == 1) {
  529. // item.readData.frontGateOpen = "打开";
  530. // } else {
  531. // item.readData.frontGateOpen = "关闭";
  532. // }
  533. // if (item.readData.rearGateOpen == 1) {
  534. // item.readData.rearGateOpen = "打开";
  535. // } else {
  536. // item.readData.rearGateOpen = "关闭";
  537. // }
  538. // if (item.readData.midGateOpen == 1) {
  539. // item.readData.midGateOpen = "打开";
  540. // } else {
  541. // item.readData.midGateOpen = "关闭";
  542. // }
  543. // });
  544. this.pageNo = response.data.result.datalist.current;
  545. } else {
  546. resolve(response);
  547. }
  548. })
  549. .catch((error) => {
  550. reject(error);
  551. });
  552. });
  553. },
  554. async loadMoreData() {
  555. if (this.loading || !this.hasMoreData) return;
  556. this.loading = true;
  557. try {
  558. // 如果新数据为空,则表示没有更多数据了
  559. if (this.historyData.length === 0) {
  560. this.hasMoreData = false;
  561. } else {
  562. // 将新数据追加到数据列表中
  563. this.historyData = [...this.historyData, ...newData];
  564. // 更新页码以便下次加载下一页数据
  565. this.pageNo += 1;
  566. }
  567. } catch (error) {
  568. // 处理请求错误
  569. console.error("加载数据失败:", error);
  570. } finally {
  571. // 无论请求成功还是失败,都要将加载状态设置为false
  572. this.loading = false;
  573. }
  574. },
  575. devicemenuShow(e) {
  576. this.menushow = !this.menushow;
  577. },
  578. menuClick(id) {
  579. this.TabCur = id;
  580. console.log(this.TabCur);
  581. // 显示该分类的数据
  582. this.curlist = this.deviceList[this.TabCur];
  583. if (this.curlist == null) {
  584. this.curlist = [];
  585. }
  586. // 选择设备分类,重新获取数据
  587. this.loadData(this.TabCur);
  588. this.menushow = false;
  589. },
  590. },
  591. destroyed() {
  592. // 停止定时器
  593. },
  594. onReachBottom() {
  595. // uni-app提供的页面滚动到底部钩子函数
  596. console.log("上拉加载更多数据");
  597. this.loadMoreData();
  598. },
  599. };
  600. </script>
  601. <style lang="scss" scoped>
  602. .emptyhistory {
  603. background: url("/static/empty.png") no-repeat;
  604. background-size: 100% 50%;
  605. }
  606. .empty-message {
  607. display: flex;
  608. justify-content: center;
  609. align-items: center;
  610. font-size: 16px;
  611. line-height: 80vh;
  612. color: #333;
  613. }
  614. .content {
  615. width: 100%;
  616. display: flex;
  617. flex-direction: column;
  618. }
  619. .main {
  620. /* margin-top: 100rpx; */
  621. display: flex;
  622. flex-direction: column;
  623. }
  624. .menupage {
  625. position: absolute;
  626. z-index: 2;
  627. top: 40rpx;
  628. height: calc(100% - 40rpx);
  629. width: 100%;
  630. }
  631. .btns {
  632. display: flex;
  633. }
  634. .btns > * {
  635. margin-right: 10px; /* 根据需要调整间距大小 */
  636. }
  637. /* 去除最后一个按钮的右边距 */
  638. .btns > *:last-child {
  639. margin-right: 0;
  640. }
  641. .flcard {
  642. padding: 20rpx;
  643. background-color: #ffffff;
  644. margin-bottom: 5rpx;
  645. }
  646. .itemback {
  647. padding: 20rpx;
  648. background-color: #ffffff;
  649. margin-bottom: 5rpx;
  650. }
  651. .datacard {
  652. width: 30%;
  653. margin: 1%;
  654. float: left;
  655. height: 190rpx;
  656. text-align: center;
  657. background: linear-gradient(
  658. to right,
  659. rgba(55, 135, 254, 0.08),
  660. rgba(4, 184, 255, 0.08),
  661. rgba(60, 161, 237, 0.08)
  662. );
  663. }
  664. .error-tag {
  665. border-radius: 10%;
  666. display: inline-block;
  667. color: #e90000;
  668. line-height: 50rpx;
  669. font-size: 14px;
  670. text-align: center;
  671. width: 120rpx;
  672. height: 50rpx;
  673. background-color: rgba(233, 0, 0, 0.2);
  674. }
  675. .error-tag1 {
  676. border-radius: 10%;
  677. display: inline-block;
  678. color: #696969;
  679. line-height: 50rpx;
  680. font-size: 14px;
  681. text-align: center;
  682. width: 120rpx;
  683. height: 50rpx;
  684. background-color: rgba(105, 105, 105, 0.2);
  685. }
  686. .success-tag {
  687. border-radius: 10%;
  688. color: #42c000;
  689. line-height: 50rpx;
  690. font-size: 14px;
  691. width: 120rpx;
  692. height: 50rpx;
  693. display: inline-block;
  694. background-color: rgba(226, 250, 214, 0.5);
  695. }
  696. .icon-style {
  697. margin: 15rpx;
  698. width: 14px;
  699. height: 14px;
  700. }
  701. </style>