history.vue 21 KB

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