history.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  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. <u-button
  23. type="primary"
  24. shape="circle"
  25. :text="StartTime ? StartTime : '起始时间'"
  26. @click="dataShow = true"
  27. ></u-button>
  28. <u-button
  29. type="primary"
  30. shape="circle"
  31. :text="EndTime ? EndTime : '结束时间'"
  32. @click="dataShow1 = true"
  33. ></u-button>
  34. </div>
  35. <div class="btns" style="margin-top: 10px">
  36. <u-button
  37. type="primary"
  38. shape="circle"
  39. :text="deviceName ? deviceName : '选择设备'"
  40. @click="deviceShow = true"
  41. ></u-button>
  42. <u-button
  43. type="primary"
  44. shape="circle"
  45. :text="lable ? lable : '间隔时间'"
  46. @click="show = true"
  47. ></u-button>
  48. <u-button
  49. type="primary"
  50. shape="circle"
  51. text="查询"
  52. @click="checkHistory"
  53. ></u-button>
  54. </div>
  55. <u-picker
  56. :show="deviceShow"
  57. :columns="[devices]"
  58. @cancel="deviceShow = false"
  59. @confirm="selectDevice"
  60. keyName="strinstallpos"
  61. >
  62. </u-picker>
  63. <u-picker
  64. :show="show"
  65. :columns="timeColumns"
  66. @cancel="show = false"
  67. keyName="label"
  68. @confirm="selectSkipTime"
  69. ></u-picker>
  70. <u-datetime-picker
  71. :show="dataShow"
  72. mode="datetime"
  73. @cancel="dataShow = false"
  74. @confirm="selectStartTime"
  75. v-model="dataTime"
  76. ></u-datetime-picker>
  77. <u-datetime-picker
  78. :show="dataShow1"
  79. mode="datetime"
  80. @cancel="dataShow1 = false"
  81. @confirm="selectEndTime"
  82. v-model="dataTime"
  83. ></u-datetime-picker>
  84. </div>
  85. <u-list class="historycontainer">
  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"></u--text>
  95. </u-col>
  96. </u-row>
  97. <u-row gutter="5" customStyle="margin-bottom: 10px">
  98. <u-col span="2" 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="2"> </u-col>
  117. <u-col span="3"> </u-col>
  118. <u-col span="5">
  119. <u--text class="timetext" :text="item.ttime"></u--text>
  120. </u-col>
  121. </u-row>
  122. <view v-if="colums[TabCur + '_monitor'] != null">
  123. <view
  124. class="datacard"
  125. v-for="(showitem, index) in colums[TabCur + '_monitor']"
  126. :key="index"
  127. v-show="showitem.appShow == 1"
  128. >
  129. <view class="content">
  130. <view>
  131. <view
  132. v-if="
  133. showitem.datatype == 1 &&
  134. item.readData[showitem.monitorcode] !== null &&
  135. item.readData[showitem.monitorcode] !== undefined
  136. "
  137. class="demo-layout bg-purple-light"
  138. style="margin-top: 10rpx; color: #3787fe"
  139. >{{ item[showitem.monitorcode] }}</view
  140. >
  141. <view
  142. v-else-if="
  143. showitem.datatype == 2 &&
  144. item.readData[showitem.monitorcode] !== null &&
  145. item.readData[showitem.monitorcode] !== undefined
  146. "
  147. class="demo-layout bg-purple-light"
  148. style="color: #3787fe"
  149. >{{ item.readData[showitem.monitorcode] }}</view
  150. >
  151. <view
  152. v-else
  153. class="demo-layout bg-purple-light"
  154. style="color: #3787fe"
  155. >--</view
  156. >
  157. <view
  158. class="demo-layout bg-purple-light"
  159. style="margin-top: 10px; color: #677799"
  160. >{{ showitem.des }}</view
  161. >
  162. </view>
  163. </view>
  164. </view>
  165. </view>
  166. </u-list-item>
  167. </template>
  168. <template v-else>
  169. <div class="empty-message">数据为空</div>
  170. </template>
  171. </u-list>
  172. </view>
  173. </view>
  174. </view>
  175. </template>
  176. <script>
  177. import api from "@/api/api";
  178. import dayjs from "dayjs";
  179. import DeviceMenu from "../../pages/device/devicemenu/devicemenu";
  180. export default {
  181. data() {
  182. return {
  183. menushow: false,
  184. TabCur: "gate",
  185. curlist: [],
  186. colums: {},
  187. deviceList: {},
  188. startDate: null,
  189. endDate: null,
  190. show: false,
  191. deviceShow: false,
  192. dataShow: false,
  193. dataShow1: false,
  194. StartTime: "", //起始时间
  195. EndTime: "", //结束时间
  196. devices: [], //设备类型数组
  197. deviceName: "", //设备名称
  198. timeS: "", //间隔时间
  199. lable: "", //间隔时间
  200. timeColumns: [
  201. [
  202. {
  203. label: "1秒",
  204. value: "1",
  205. },
  206. {
  207. label: "5秒",
  208. value: "2",
  209. },
  210. {
  211. label: "10秒",
  212. value: "3",
  213. },
  214. {
  215. label: "30秒",
  216. value: "4",
  217. },
  218. {
  219. label: "1分钟",
  220. value: "5",
  221. },
  222. {
  223. label: "10分钟",
  224. value: "6",
  225. },
  226. {
  227. label: "30分钟",
  228. value: "7",
  229. },
  230. {
  231. label: "1小时",
  232. value: "8",
  233. },
  234. ],
  235. ],
  236. deviceID: "", //设备ID
  237. //deviceType: "", //设备类型
  238. skip: 8, //时间间隔
  239. dataTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
  240. historyData: [], //历史数据
  241. loading: false, // 是否正在加载数据
  242. hasMoreData: true, // 是否还有更多数据可以加载
  243. pageNo: 1, // 当前页码(用于请求数据时分页)
  244. };
  245. },
  246. components: {
  247. DeviceMenu,
  248. },
  249. props: ["showColum", "deviceType"],
  250. watch: {
  251. showColum(data) {
  252. this.colums = data;
  253. },
  254. deviceType: {
  255. async handler(data) {
  256. if (data) {
  257. this.TabCur = data;
  258. console.log(this.TabCur, "设备");
  259. this.curlist = this.deviceList[this.TabCur];
  260. if (this.curlist == null) {
  261. this.curlist = [];
  262. }
  263. // 选择设备分类,重新获取数据
  264. await this.loadData(this.TabCur);
  265. this.$emit("setMenushow", {
  266. menushow: false,
  267. });
  268. }
  269. },
  270. immediate: true,
  271. },
  272. },
  273. created() {
  274. this.colums = this.showColum;
  275. const startTime = new Date().getTime() - 3600 * 1000 * 24 * 30;
  276. const endTime = new Date();
  277. this.StartTime = dayjs(startTime).format("YYYY-MM-DD HH:mm:ss");
  278. this.EndTime = dayjs(endTime).format("YYYY-MM-DD HH:mm:ss");
  279. },
  280. mounted() {
  281. // this.TabCur = this.deviceType;
  282. },
  283. methods: {
  284. loadData(type) {
  285. new Promise((resolve, reject) => {
  286. api
  287. .getDeviceMonitor({
  288. devicetype: type,
  289. pagetype: "normal",
  290. filterParams: {},
  291. })
  292. .then((response) => {
  293. if (response.data.code == 200) {
  294. this.deviceList[type] = response.data.result.msgTxt[0].datalist;
  295. this.curlist = this.deviceList[type];
  296. this.setData(this.curlist);
  297. } else {
  298. resolve(response);
  299. }
  300. })
  301. .catch((error) => {
  302. reject(error);
  303. });
  304. });
  305. },
  306. //选择设备选择器 保存对应的id
  307. setData(data) {
  308. this.devices = [];
  309. data.forEach((element) => {
  310. const deviceObj = {
  311. id: element.deviceID,
  312. strinstallpos: element.strinstallpos,
  313. type: element.deviceType,
  314. };
  315. this.devices.push(deviceObj);
  316. });
  317. },
  318. //选择设备 点击确定按钮 保存id
  319. selectDevice(e) {
  320. this.deviceID = e.value[0].id;
  321. this.TabCur = e.value[0].type;
  322. this.deviceName = e.value[0].strinstallpos;
  323. this.deviceShow = false;
  324. },
  325. //选择起始时间
  326. selectStartTime(e) {
  327. const startTime = e.value;
  328. const formattedTime = dayjs(startTime).format("YYYY-MM-DD HH:mm:ss");
  329. this.StartTime = formattedTime;
  330. this.dataShow = false;
  331. },
  332. //选择起始时间
  333. selectEndTime(e) {
  334. const endTime = e.value;
  335. const formattedTime = dayjs(endTime).format("YYYY-MM-DD HH:mm:ss");
  336. this.EndTime = formattedTime;
  337. this.dataShow1 = false;
  338. },
  339. //选择间隔时间
  340. selectSkipTime(e) {
  341. this.skip = e.value[0].value;
  342. this.lable = e.value[0].label;
  343. this.show = false;
  344. },
  345. //查询历史数据 getDeviceHistory
  346. checkHistory() {
  347. // debugger;
  348. const params = {
  349. ttime_begin: this.StartTime,
  350. ttime_end: this.EndTime,
  351. gdeviceid: this.deviceID,
  352. skip: this.skip,
  353. pageNo: this.pageNo,
  354. pageSize: 10,
  355. strtype: this.TabCur,
  356. };
  357. new Promise((resolve, reject) => {
  358. api
  359. .getDeviceHistory(params)
  360. .then((response) => {
  361. debugger;
  362. if (response.data.code == 200) {
  363. this.historyData = response.data.result.datalist.records;
  364. this.historyData.forEach((item) => {
  365. if (item.readData.frontGateOpen == 1) {
  366. item.readData.frontGateOpen = "打开";
  367. } else {
  368. item.readData.frontGateOpen = "关闭";
  369. }
  370. if (item.readData.rearGateOpen == 1) {
  371. item.readData.rearGateOpen = "打开";
  372. } else {
  373. item.readData.rearGateOpen = "关闭";
  374. }
  375. if (item.readData.midGateOpen == 1) {
  376. item.readData.midGateOpen = "打开";
  377. } else {
  378. item.readData.midGateOpen = "关闭";
  379. }
  380. });
  381. this.pageNo = response.data.result.datalist.current;
  382. // if (infolist.length == 0 && this.pageNo == 1) {
  383. // // console.log('首次加载没数据');
  384. // this.noData = false;
  385. // this.historyData = [];
  386. // } else if (infolist.length < 3 && this.pageNo == 1) {
  387. // // console.log('首次加载有数据,但少于4条');
  388. // this.noData = true;
  389. // this.historyData = infolist;
  390. // } else if (infolist.length !== 0 && this.pageNo == 1) {
  391. // // console.log('首次加载有数据');
  392. // this.noData = false;
  393. // this.historyData = infolist;
  394. // } else if (infolist.length !== 0 && this.pageNo > 1) {
  395. // // console.log('上拉加载更多数据');
  396. // this.noData = false;
  397. // this.historyData = this.historyData.concat(infolist);
  398. // } else if (infolist.length == 0 && this.pageNo > 1) {
  399. // // console.log('上拉加载没有更多数据了');
  400. // this.noData = true;
  401. // }
  402. } else {
  403. resolve(response);
  404. }
  405. })
  406. .catch((error) => {
  407. reject(error);
  408. });
  409. });
  410. },
  411. async loadMoreData() {
  412. if (this.loading || !this.hasMoreData) return;
  413. this.loading = true;
  414. try {
  415. // 如果新数据为空,则表示没有更多数据了
  416. if (this.historyData.length === 0) {
  417. this.hasMoreData = false;
  418. } else {
  419. // 将新数据追加到数据列表中
  420. this.historyData = [...this.historyData, ...newData];
  421. // 更新页码以便下次加载下一页数据
  422. this.pageNo += 1;
  423. }
  424. } catch (error) {
  425. // 处理请求错误
  426. console.error("加载数据失败:", error);
  427. } finally {
  428. // 无论请求成功还是失败,都要将加载状态设置为false
  429. this.loading = false;
  430. }
  431. },
  432. devicemenuShow(e) {
  433. this.menushow = !this.menushow;
  434. console.log(this.menushow, "dainjichengg成都多大事");
  435. },
  436. menuClick(id) {
  437. this.TabCur = id;
  438. console.log(this.TabCur);
  439. // 显示该分类的数据
  440. this.curlist = this.deviceList[this.TabCur];
  441. if (this.curlist == null) {
  442. this.curlist = [];
  443. }
  444. // 选择设备分类,重新获取数据
  445. this.loadData(this.TabCur);
  446. this.menushow = false;
  447. },
  448. },
  449. destroyed() {
  450. // 停止定时器
  451. },
  452. onReachBottom() {
  453. // uni-app提供的页面滚动到底部钩子函数
  454. console.log("上拉加载更多数据");
  455. this.loadMoreData();
  456. },
  457. };
  458. </script>
  459. <style>
  460. .empty-message {
  461. display: flex;
  462. justify-content: center;
  463. align-items: center;
  464. font-size: 16px;
  465. color: #333;
  466. }
  467. .main {
  468. /* margin-top: 100rpx; */
  469. display: flex;
  470. flex-direction: column;
  471. }
  472. .menupage {
  473. position: absolute;
  474. z-index: 2;
  475. top: 40rpx;
  476. height: calc(100% - 40rpx);
  477. width: 100%;
  478. }
  479. .btns {
  480. display: flex;
  481. }
  482. .flcard {
  483. padding: 20rpx;
  484. background-color: #ffffff;
  485. margin-bottom: 5rpx;
  486. }
  487. .itemback {
  488. padding: 20rpx;
  489. background-color: #ffffff;
  490. margin-bottom: 5rpx;
  491. }
  492. .datacard {
  493. width: 30%;
  494. margin: 1%;
  495. float: left;
  496. height: 100rpx;
  497. text-align: center;
  498. background: linear-gradient(
  499. to right,
  500. rgba(55, 135, 254, 0.08),
  501. rgba(4, 184, 255, 0.08),
  502. rgba(60, 161, 237, 0.08)
  503. );
  504. }
  505. .error-tag {
  506. border-radius: 10%;
  507. display: inline-block;
  508. color: #e90000;
  509. line-height: 50rpx;
  510. font-size: 14px;
  511. text-align: center;
  512. width: 120rpx;
  513. height: 50rpx;
  514. background-color: rgba(233, 0, 0, 0.2);
  515. }
  516. .error-tag1 {
  517. border-radius: 10%;
  518. display: inline-block;
  519. color: #696969;
  520. line-height: 50rpx;
  521. font-size: 14px;
  522. text-align: center;
  523. width: 120rpx;
  524. height: 50rpx;
  525. background-color: rgba(105, 105, 105, 0.2);
  526. }
  527. .success-tag {
  528. border-radius: 10%;
  529. color: #42c000;
  530. line-height: 50rpx;
  531. font-size: 14px;
  532. width: 120rpx;
  533. height: 50rpx;
  534. display: inline-block;
  535. background-color: rgba(226, 250, 214);
  536. }
  537. .icon-style {
  538. margin: 15rpx;
  539. width: 14px;
  540. height: 14px;
  541. }
  542. </style>