history.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  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>
  86. <u-list-item
  87. class="itemback"
  88. v-for="(item, index) in historyData"
  89. :key="index"
  90. >
  91. <u-row gutter="5" customStyle="margin-bottom: 10px">
  92. <u-col span="24">
  93. <u--text :text="item.ginstallpos"></u--text>
  94. </u-col>
  95. </u-row>
  96. <u-row gutter="5" customStyle="margin-bottom: 10px">
  97. <u-col span="2" style="margin-right: 15rpx">
  98. <div v-if="item.netStatus == 0" class="error-tag1">
  99. <image
  100. src="/static/model/connectFalse.svg"
  101. alt=""
  102. class="icon-style"
  103. />
  104. <span style="float: right">断开</span>
  105. </div>
  106. <div v-else class="success-tag">
  107. <image
  108. src="/static/model/connectTrue.svg"
  109. alt=""
  110. class="icon-style"
  111. />
  112. <span style="float: right">连接</span>
  113. </div>
  114. </u-col>
  115. <u-col span="2">
  116. </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. </u-list>
  168. </view>
  169. </view>
  170. <view v-if="loading"> 加载中...... </view>
  171. <view v-else-if="!hasMoreData"> 没有更多数据了 </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. this.curlist = this.deviceList[this.TabCur];
  257. if (this.curlist == null) {
  258. this.curlist = [];
  259. }
  260. // 选择设备分类,重新获取数据
  261. await this.loadData(this.TabCur);
  262. this.$emit("setMenushow", {
  263. menushow: false,
  264. });
  265. }
  266. },
  267. immediate: true,
  268. },
  269. },
  270. created() {
  271. this.colums = this.showColum;
  272. const startTime = new Date().getTime() - 3600 * 1000 * 24 * 30;
  273. const endTime = new Date();
  274. this.StartTime = dayjs(startTime).format("YYYY-MM-DD HH:mm:ss");
  275. this.EndTime = dayjs(endTime).format("YYYY-MM-DD HH:mm:ss");
  276. },
  277. mounted() {
  278. this.TabCur = this.deviceType;
  279. },
  280. methods: {
  281. loadData(type) {
  282. new Promise((resolve, reject) => {
  283. api
  284. .getDeviceMonitor({
  285. devicetype: type,
  286. pagetype: "normal",
  287. filterParams: {},
  288. })
  289. .then((response) => {
  290. if (response.data.code == 200) {
  291. this.deviceList[type] = response.data.result.msgTxt[0].datalist;
  292. this.curlist = this.deviceList[type];
  293. this.setData(this.curlist);
  294. } else {
  295. resolve(response);
  296. }
  297. })
  298. .catch((error) => {
  299. reject(error);
  300. });
  301. });
  302. },
  303. //选择设备选择器 保存对应的id
  304. setData(data) {
  305. this.devices = [];
  306. data.forEach((element) => {
  307. const deviceObj = {
  308. id: element.deviceID,
  309. strinstallpos: element.strinstallpos,
  310. type: element.deviceType,
  311. };
  312. this.devices.push(deviceObj);
  313. });
  314. },
  315. //选择设备 点击确定按钮 保存id
  316. selectDevice(e) {
  317. this.deviceID = e.value[0].id;
  318. this.TabCur = e.value[0].type;
  319. this.deviceName = e.value[0].strinstallpos;
  320. this.deviceShow = false;
  321. },
  322. //选择起始时间
  323. selectStartTime(e) {
  324. const startTime = e.value;
  325. const formattedTime = dayjs(startTime).format("YYYY-MM-DD HH:mm:ss");
  326. this.StartTime = formattedTime;
  327. this.dataShow = false;
  328. },
  329. //选择起始时间
  330. selectEndTime(e) {
  331. const endTime = e.value;
  332. const formattedTime = dayjs(endTime).format("YYYY-MM-DD HH:mm:ss");
  333. this.EndTime = formattedTime;
  334. this.dataShow1 = false;
  335. },
  336. //选择间隔时间
  337. selectSkipTime(e) {
  338. this.skip = e.value[0].value;
  339. this.lable = e.value[0].label;
  340. this.show = false;
  341. },
  342. //查询历史数据 getDeviceHistory
  343. checkHistory() {
  344. debugger;
  345. const params = {
  346. ttime_begin: this.StartTime,
  347. ttime_end: this.EndTime,
  348. gdeviceid: this.deviceID,
  349. skip: this.skip,
  350. pageNo: this.pageNo,
  351. pageSize: 10,
  352. strtype: this.TabCur,
  353. };
  354. new Promise((resolve, reject) => {
  355. api
  356. .getDeviceHistory(params)
  357. .then((response) => {
  358. debugger;
  359. if (response.data.code == 200) {
  360. this.historyData = response.data.result.datalist.records;
  361. this.historyData.forEach((item) => {
  362. if (item.readData.frontGateOpen == 1) {
  363. item.readData.frontGateOpen = "打开";
  364. } else {
  365. item.readData.frontGateOpen = "关闭";
  366. }
  367. if (item.readData.rearGateOpen == 1) {
  368. item.readData.rearGateOpen = "打开";
  369. } else {
  370. item.readData.rearGateOpen = "关闭";
  371. }
  372. if (item.readData.midGateOpen == 1) {
  373. item.readData.midGateOpen = "打开";
  374. } else {
  375. item.readData.midGateOpen = "关闭";
  376. }
  377. });
  378. this.pageNo = response.data.result.datalist.current;
  379. // if (infolist.length == 0 && this.pageNo == 1) {
  380. // // console.log('首次加载没数据');
  381. // this.noData = false;
  382. // this.historyData = [];
  383. // } else if (infolist.length < 3 && this.pageNo == 1) {
  384. // // console.log('首次加载有数据,但少于4条');
  385. // this.noData = true;
  386. // this.historyData = infolist;
  387. // } else if (infolist.length !== 0 && this.pageNo == 1) {
  388. // // console.log('首次加载有数据');
  389. // this.noData = false;
  390. // this.historyData = infolist;
  391. // } else if (infolist.length !== 0 && this.pageNo > 1) {
  392. // // console.log('上拉加载更多数据');
  393. // this.noData = false;
  394. // this.historyData = this.historyData.concat(infolist);
  395. // } else if (infolist.length == 0 && this.pageNo > 1) {
  396. // // console.log('上拉加载没有更多数据了');
  397. // this.noData = true;
  398. // }
  399. } else {
  400. resolve(response);
  401. }
  402. })
  403. .catch((error) => {
  404. reject(error);
  405. });
  406. });
  407. },
  408. async loadMoreData() {
  409. if (this.loading || !this.hasMoreData) return;
  410. this.loading = true;
  411. try {
  412. // 如果新数据为空,则表示没有更多数据了
  413. if (this.historyData.length === 0) {
  414. this.hasMoreData = false;
  415. } else {
  416. // 将新数据追加到数据列表中
  417. this.historyData = [...this.historyData, ...newData];
  418. // 更新页码以便下次加载下一页数据
  419. this.pageNo += 1;
  420. }
  421. } catch (error) {
  422. // 处理请求错误
  423. console.error("加载数据失败:", error);
  424. } finally {
  425. // 无论请求成功还是失败,都要将加载状态设置为false
  426. this.loading = false;
  427. }
  428. },
  429. devicemenuShow(e) {
  430. this.menushow = !this.menushow;
  431. console.log(this.menushow, "dainjichengg成都多大事");
  432. },
  433. menuClick(id) {
  434. this.TabCur = id;
  435. console.log(this.TabCur);
  436. // 显示该分类的数据
  437. this.curlist = this.deviceList[this.TabCur];
  438. if (this.curlist == null) {
  439. this.curlist = [];
  440. }
  441. // 选择设备分类,重新获取数据
  442. this.loadData(this.TabCur);
  443. this.menushow = false;
  444. },
  445. },
  446. destroyed() {
  447. // 停止定时器
  448. },
  449. onReachBottom() {
  450. // uni-app提供的页面滚动到底部钩子函数
  451. console.log("上拉加载更多数据");
  452. this.loadMoreData();
  453. },
  454. };
  455. </script>
  456. <style>
  457. .main {
  458. /* margin-top: 100rpx; */
  459. display: flex;
  460. flex-direction: column;
  461. }
  462. .menupage {
  463. position: absolute;
  464. z-index: 2;
  465. top: 40rpx;
  466. height: calc(100% - 40rpx);
  467. width: 100%;
  468. }
  469. .btns {
  470. display: flex;
  471. }
  472. .flcard {
  473. padding: 20rpx;
  474. background-color: #ffffff;
  475. margin-bottom: 5rpx;
  476. }
  477. .itemback {
  478. padding: 20rpx;
  479. background-color: #ffffff;
  480. margin-bottom: 5rpx;
  481. }
  482. .datacard {
  483. width: 30%;
  484. margin: 1%;
  485. float: left;
  486. height: 100rpx;
  487. text-align: center;
  488. background: linear-gradient(
  489. to right,
  490. rgba(55, 135, 254, 0.08),
  491. rgba(4, 184, 255, 0.08),
  492. rgba(60, 161, 237, 0.08)
  493. );
  494. }
  495. .error-tag {
  496. border-radius: 10%;
  497. display: inline-block;
  498. color: #e90000;
  499. line-height: 50rpx;
  500. font-size: 14px;
  501. text-align: center;
  502. width: 120rpx;
  503. height: 50rpx;
  504. background-color: rgba(233, 0, 0, 0.2);
  505. }
  506. .error-tag1 {
  507. border-radius: 10%;
  508. display: inline-block;
  509. color: #696969;
  510. line-height: 50rpx;
  511. font-size: 14px;
  512. text-align: center;
  513. width: 120rpx;
  514. height: 50rpx;
  515. background-color: rgba(105, 105, 105, 0.2);
  516. }
  517. .success-tag {
  518. border-radius: 10%;
  519. color: #42c000;
  520. line-height: 50rpx;
  521. font-size: 14px;
  522. width: 120rpx;
  523. height: 50rpx;
  524. display: inline-block;
  525. background-color: rgba(226, 250, 214);
  526. }
  527. .icon-style {
  528. margin: 15rpx;
  529. width: 14px;
  530. height: 14px;
  531. }
  532. </style>