history.vue 21 KB

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