history.vue 18 KB

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