history.vue 21 KB

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