history.vue 16 KB

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