history.vue 18 KB

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