Historymodel.vue 13 KB

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