history.vue 16 KB

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