history.vue 16 KB

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