history.vue 16 KB

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