history.vue 16 KB

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