Historymodel.vue 13 KB

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