Historymodel.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. <template>
  2. <view class="container">
  3. <!-- 建议放在外层 -->
  4. <u-navbar
  5. title="历史数据"
  6. @leftClick="devicemenuShow"
  7. :safeAreaInsetTop="false"
  8. style="margin-top: 30px"
  9. >
  10. <view class="u-nav-slot" slot="left">
  11. <u-icon name="list" size="20"> </u-icon>
  12. </view>
  13. </u-navbar>
  14. <!-- 侧边栏 -->
  15. <view v-show="menushow" class="menupage">
  16. <DeviceMenu @menuClick="menuClick"></DeviceMenu>
  17. </view>
  18. <!-- 历史数据列表页 -->
  19. <view v-show="!menushow" class="main">
  20. <view class="u-page">
  21. <div class="flcard">
  22. <div class="btns">
  23. <u-button
  24. type="primary"
  25. shape="circle"
  26. :text="StartTime ? StartTime : '起始时间'"
  27. @click="dataShow = true"
  28. ></u-button>
  29. <u-button
  30. type="primary"
  31. shape="circle"
  32. :text="EndTime ? EndTime : '结束时间'"
  33. @click="dataShow1 = true"
  34. ></u-button>
  35. </div>
  36. <div class="btns" style="margin-top: 10px">
  37. <u-button
  38. type="primary"
  39. shape="circle"
  40. :text="deviceName ? deviceName : '选择设备'"
  41. @click="deviceShow = true"
  42. ></u-button>
  43. <u-button
  44. type="primary"
  45. shape="circle"
  46. :text="lable ? lable : '间隔时间'"
  47. @click="show = true"
  48. ></u-button>
  49. <u-button
  50. type="primary"
  51. shape="circle"
  52. text="查询"
  53. @click="checkHistory"
  54. ></u-button>
  55. </div>
  56. <u-picker
  57. :show="deviceShow"
  58. :columns="[devices]"
  59. @cancel="deviceShow = false"
  60. @confirm="selectDevice"
  61. keyName="strinstallpos"
  62. >
  63. </u-picker>
  64. <u-picker
  65. :show="show"
  66. :columns="timeColumns"
  67. @cancel="show = false"
  68. keyName="label"
  69. @confirm="selectSkipTime"
  70. ></u-picker>
  71. <u-datetime-picker
  72. :show="dataShow"
  73. mode="datetime"
  74. @cancel="dataShow = false"
  75. @confirm="selectStartTime"
  76. v-model="dataTime"
  77. ></u-datetime-picker>
  78. <u-datetime-picker
  79. :show="dataShow1"
  80. mode="datetime"
  81. @cancel="dataShow1 = false"
  82. @confirm="selectEndTime"
  83. v-model="dataTime"
  84. ></u-datetime-picker>
  85. </div>
  86. <u-list>
  87. <u-list-item
  88. class="itemback"
  89. v-for="(item, index) in historyData"
  90. :key="index"
  91. >
  92. <u-row gutter="5" customStyle="margin-bottom: 10px">
  93. <u-col span="24">
  94. <u--text :text="item.ginstallpos"></u--text>
  95. </u-col>
  96. </u-row>
  97. <u-row gutter="5" customStyle="margin-bottom: 10px">
  98. <u-col span="2" style="margin-right: 15rpx">
  99. <div v-if="item.netStatus == 0" class="error-tag1">
  100. <image
  101. src="/static/model/connectFalse.svg"
  102. alt=""
  103. class="icon-style"
  104. />
  105. <span style="float: right">断开</span>
  106. </div>
  107. <div v-else class="success-tag">
  108. <image
  109. src="/static/model/connectTrue.svg"
  110. alt=""
  111. class="icon-style"
  112. />
  113. <span style="float: right">连接</span>
  114. </div>
  115. </u-col>
  116. <u-col span="2">
  117. <div v-if="item.readData[warnFlag] == 0" class="success-tag">
  118. <image
  119. src="/static/model/alarmTrue.svg"
  120. alt=""
  121. class="icon-style"
  122. />
  123. <span style="float: right">{{ item.readData[warndes] }}</span>
  124. </div>
  125. <div v-else class="error-tag">
  126. <image
  127. src="/static/model/alarmFalse.svg"
  128. alt=""
  129. class="icon-style"
  130. />
  131. <span style="float: right">{{ item.readData[warndes] }}</span>
  132. </div>
  133. </u-col>
  134. <u-col span="3"> </u-col>
  135. <u-col span="5">
  136. <u--text class="timetext" :text="item.ttime"></u--text>
  137. </u-col>
  138. </u-row>
  139. <view v-if="colums[TabCur + '_monitor'] != null">
  140. <view
  141. class="datacard"
  142. v-for="(showitem, index) in colums[TabCur + '_monitor']"
  143. :key="index"
  144. v-show="showitem.appShow == 1"
  145. >
  146. <view class="content">
  147. <view>
  148. <view
  149. v-if="
  150. showitem.datatype == 1 &&
  151. item.readData[showitem.monitorcode] !== null &&
  152. item.readData[showitem.monitorcode] !== undefined
  153. "
  154. class="demo-layout bg-purple-light"
  155. style="margin-top: 10rpx; color: #3787fe"
  156. >{{ item[showitem.monitorcode] }}</view
  157. >
  158. <view
  159. v-else-if="
  160. showitem.datatype == 2 &&
  161. item.readData[showitem.monitorcode] !== null &&
  162. item.readData[showitem.monitorcode] !== undefined
  163. "
  164. class="demo-layout bg-purple-light"
  165. style="color: #3787fe"
  166. >{{ item.readData[showitem.monitorcode] }}</view
  167. >
  168. <view
  169. v-else
  170. class="demo-layout bg-purple-light"
  171. style="color: #3787fe"
  172. >--</view
  173. >
  174. <view
  175. class="demo-layout bg-purple-light"
  176. style="margin-top: 10px; color: #677799"
  177. >{{ showitem.des }}</view
  178. >
  179. </view>
  180. </view>
  181. </view>
  182. </view>
  183. </u-list-item>
  184. </u-list>
  185. </view>
  186. </view>
  187. </view>
  188. </template>
  189. <script>
  190. import DeviceMenu from "./devicemenu/devicemenu.vue";
  191. import api from "@/api/api";
  192. import dayjs from "dayjs";
  193. export default {
  194. data() {
  195. return {
  196. menushow: false,
  197. TabCur: "gate",
  198. curlist: [],
  199. colums: {},
  200. deviceList: {},
  201. startDate: null,
  202. endDate: null,
  203. show: false,
  204. deviceShow: false,
  205. dataShow: false,
  206. dataShow1: false,
  207. StartTime: "", //起始时间
  208. EndTime: "", //结束时间
  209. devices: [], //设备类型数组
  210. deviceName: "", //设备名称
  211. timeS: "", //间隔时间
  212. lable: "", //间隔时间
  213. timeColumns: [
  214. [
  215. {
  216. label: "1秒",
  217. value: "1",
  218. },
  219. {
  220. label: "5秒",
  221. value: "2",
  222. },
  223. {
  224. label: "10秒",
  225. value: "3",
  226. },
  227. {
  228. label: "30秒",
  229. value: "4",
  230. },
  231. {
  232. label: "1分钟",
  233. value: "5",
  234. },
  235. {
  236. label: "10分钟",
  237. value: "6",
  238. },
  239. {
  240. label: "30分钟",
  241. value: "7",
  242. },
  243. {
  244. label: "1小时",
  245. value: "8",
  246. },
  247. ],
  248. ],
  249. deviceID: "", //设备ID
  250. deviceType: "", //设备类型
  251. skip: 8, //时间间隔
  252. dataTime: dayjs().toDate(),
  253. historyData: [], //历史数据
  254. };
  255. },
  256. components: {
  257. DeviceMenu,
  258. },
  259. props: ["showColum"],
  260. watch: {
  261. showColum(data) {
  262. this.colums = data;
  263. },
  264. },
  265. created() {
  266. this.colums = this.showColum;
  267. const startTime = new Date(
  268. new Date(
  269. new Date().getTime() - 3600 * 1000 * 24 * 30
  270. ).toLocaleDateString()
  271. );
  272. const endTime = new Date();
  273. this.StartTime = dayjs(startTime).format("YYYY-MM-DD HH:mm:ss");
  274. this.EndTime = dayjs(endTime).format("YYYY-MM-DD HH:mm:ss");
  275. },
  276. mounted() {},
  277. methods: {
  278. loadData(type) {
  279. new Promise((resolve, reject) => {
  280. api
  281. .getDeviceMonitor({
  282. devicetype: type,
  283. pagetype: "normal",
  284. filterParams: {},
  285. })
  286. .then((response) => {
  287. if (response.data.code == 200) {
  288. this.deviceList[type] = response.data.result.msgTxt[0].datalist;
  289. this.curlist = this.deviceList[type];
  290. this.setData(this.curlist);
  291. } else {
  292. resolve(response);
  293. }
  294. })
  295. .catch((error) => {
  296. reject(error);
  297. });
  298. });
  299. },
  300. //选择设备选择器 保存对应的id
  301. setData(data) {
  302. this.devices = [];
  303. data.forEach((element) => {
  304. const deviceObj = {
  305. id: element.deviceID,
  306. strinstallpos: element.strinstallpos,
  307. type: element.deviceType,
  308. };
  309. this.devices.push(deviceObj);
  310. });
  311. },
  312. //选择设备 点击确定按钮 保存id
  313. selectDevice(e) {
  314. this.deviceID = e.value[0].id;
  315. this.deviceType = e.value[0].type;
  316. this.deviceName = e.value[0].strinstallpos;
  317. this.deviceShow = false;
  318. },
  319. //选择起始时间
  320. selectStartTime(e) {
  321. const startTime = e.value;
  322. const formattedTime = dayjs(startTime).format("YYYY-MM-DD HH:mm:ss");
  323. this.StartTime = formattedTime;
  324. this.dataShow = false;
  325. },
  326. //选择起始时间
  327. selectEndTime(e) {
  328. const endTime = e.value;
  329. const formattedTime = dayjs(endTime).format("YYYY-MM-DD HH:mm:ss");
  330. this.EndTime = formattedTime;
  331. this.dataShow1 = false;
  332. },
  333. //选择间隔时间
  334. selectSkipTime(e) {
  335. this.skip = e.value[0].value;
  336. this.lable = e.value[0].label;
  337. this.show = false;
  338. },
  339. //查询历史数据 getDeviceHistory
  340. checkHistory() {
  341. const params = {
  342. ttime_begin: this.StartTime,
  343. ttime_end: this.EndTime,
  344. gdeviceid: this.deviceID,
  345. skip: this.skip,
  346. pageNo: 1,
  347. pageSize: 10000,
  348. strtype: this.deviceType,
  349. };
  350. new Promise((resolve, reject) => {
  351. api
  352. .getDeviceHistory(params)
  353. .then((response) => {
  354. if (response.data.code == 200) {
  355. this.historyData = response.data.result.datalist.records;
  356. this.historyData.forEach((item) => {
  357. if (item.readData.frontGateOpen == 1) {
  358. item.readData.frontGateOpen = "打开";
  359. } else {
  360. item.readData.frontGateOpen = "关闭";
  361. }
  362. if (item.readData.rearGateOpen == 1) {
  363. item.readData.rearGateOpen = "打开";
  364. } else {
  365. item.readData.rearGateOpen = "关闭";
  366. }
  367. if (item.readData.midGateOpen == 1) {
  368. item.readData.midGateOpen = "打开";
  369. } else {
  370. item.readData.midGateOpen = "关闭";
  371. }
  372. });
  373. } else {
  374. resolve(response);
  375. }
  376. })
  377. .catch((error) => {
  378. reject(error);
  379. });
  380. });
  381. },
  382. devicemenuShow(e) {
  383. this.menushow = true;
  384. },
  385. menuClick(id) {
  386. this.TabCur = id;
  387. // 显示该分类的数据
  388. this.curlist = this.deviceList[this.TabCur];
  389. if (this.curlist == null) {
  390. this.curlist = [];
  391. }
  392. // 选择设备分类,重新获取数据
  393. this.loadData(this.TabCur);
  394. this.menushow = false;
  395. },
  396. },
  397. destroyed() {
  398. // 停止定时器
  399. },
  400. };
  401. </script>
  402. <style>
  403. >>> .u-navbar--fixed {
  404. margin-top: 20px;
  405. }
  406. .main {
  407. margin-top: 100rpx;
  408. display: flex;
  409. flex-direction: column;
  410. }
  411. .menupage {
  412. position: absolute;
  413. z-index: 2;
  414. top: 40rpx;
  415. height: calc(100% - 40rpx);
  416. width: 100%;
  417. }
  418. .btns {
  419. display: flex;
  420. }
  421. .flcard {
  422. padding: 20rpx;
  423. background-color: #ffffff;
  424. margin-bottom: 5rpx;
  425. }
  426. .itemback {
  427. padding: 20rpx;
  428. background-color: #ffffff;
  429. margin-bottom: 5rpx;
  430. }
  431. .datacard {
  432. width: 30%;
  433. margin: 1%;
  434. float: left;
  435. height: 100rpx;
  436. text-align: center;
  437. background: linear-gradient(
  438. to right,
  439. rgba(55, 135, 254, 0.08),
  440. rgba(4, 184, 255, 0.08),
  441. rgba(60, 161, 237, 0.08)
  442. );
  443. }
  444. .error-tag {
  445. border-radius: 10%;
  446. display: inline-block;
  447. color: #e90000;
  448. line-height: 50rpx;
  449. font-size: 14px;
  450. text-align: center;
  451. width: 120rpx;
  452. height: 50rpx;
  453. background-color: rgba(233, 0, 0, 0.2);
  454. }
  455. .error-tag1 {
  456. border-radius: 10%;
  457. display: inline-block;
  458. color: #696969;
  459. line-height: 50rpx;
  460. font-size: 14px;
  461. text-align: center;
  462. width: 120rpx;
  463. height: 50rpx;
  464. background-color: rgba(105, 105, 105, 0.2);
  465. }
  466. .success-tag {
  467. border-radius: 10%;
  468. color: #42c000;
  469. line-height: 50rpx;
  470. font-size: 14px;
  471. width: 120rpx;
  472. height: 50rpx;
  473. display: inline-block;
  474. background-color: rgba(226, 250, 214);
  475. }
  476. .icon-style {
  477. margin: 15rpx;
  478. width: 14px;
  479. height: 14px;
  480. }
  481. </style>