Historymodel.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  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. <img
  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. <img
  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. <img
  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. <img
  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: "", //时间间隔
  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. },
  268. mounted() {},
  269. methods: {
  270. loadData(type) {
  271. new Promise((resolve, reject) => {
  272. api
  273. .getDeviceMonitor({
  274. devicetype: type,
  275. pagetype: "normal",
  276. filterParams: {},
  277. })
  278. .then((response) => {
  279. if (response.data.code == 200) {
  280. this.deviceList[type] = response.data.result.msgTxt[0].datalist;
  281. this.curlist = this.deviceList[type];
  282. this.setData(this.curlist);
  283. } else {
  284. resolve(response);
  285. }
  286. })
  287. .catch((error) => {
  288. reject(error);
  289. });
  290. });
  291. },
  292. //选择设备选择器 保存对应的id
  293. setData(data) {
  294. this.devices = [];
  295. data.forEach((element) => {
  296. const deviceObj = {
  297. id: element.deviceID,
  298. strinstallpos: element.strinstallpos,
  299. type: element.deviceType,
  300. };
  301. this.devices.push(deviceObj);
  302. });
  303. },
  304. //选择设备 点击确定按钮 保存id
  305. selectDevice(e) {
  306. this.deviceID = e.value[0].id;
  307. this.deviceType = e.value[0].type;
  308. this.deviceName = e.value[0].strinstallpos;
  309. this.deviceShow = false;
  310. },
  311. //选择起始时间
  312. selectStartTime(e) {
  313. const startTime = e.value;
  314. const formattedTime = dayjs(startTime).format("YYYY-MM-DD HH:mm:ss");
  315. this.StartTime = formattedTime;
  316. this.dataShow = false;
  317. },
  318. //选择起始时间
  319. selectEndTime(e) {
  320. const endTime = e.value;
  321. const formattedTime = dayjs(endTime).format("YYYY-MM-DD HH:mm:ss");
  322. this.EndTime = formattedTime;
  323. this.dataShow1 = false;
  324. },
  325. //选择间隔时间
  326. selectSkipTime(e) {
  327. this.skip = e.value[0].value;
  328. this.lable = e.value[0].label;
  329. this.show = false;
  330. },
  331. //查询历史数据 getDeviceHistory
  332. checkHistory() {
  333. const params = {
  334. ttime_begin: this.StartTime,
  335. ttime_end: this.EndTime,
  336. gdeviceid: this.deviceID,
  337. skip: this.skip,
  338. pageNo: 1,
  339. pageSize: 10000,
  340. strtype: this.deviceType,
  341. };
  342. new Promise((resolve, reject) => {
  343. api
  344. .getDeviceHistory(params)
  345. .then((response) => {
  346. if (response.data.code == 200) {
  347. this.historyData = response.data.result.datalist.records;
  348. this.historyData.forEach((item) => {
  349. if (item.readData.frontGateOpen == 1) {
  350. item.readData.frontGateOpen = "打开";
  351. } else {
  352. item.readData.frontGateOpen = "关闭";
  353. }
  354. if (item.readData.rearGateOpen == 1) {
  355. item.readData.rearGateOpen = "打开";
  356. } else {
  357. item.readData.rearGateOpen = "关闭";
  358. }
  359. if (item.readData.midGateOpen == 1) {
  360. item.readData.midGateOpen = "打开";
  361. } else {
  362. item.readData.midGateOpen = "关闭";
  363. }
  364. });
  365. } else {
  366. resolve(response);
  367. }
  368. })
  369. .catch((error) => {
  370. reject(error);
  371. });
  372. });
  373. },
  374. devicemenuShow(e) {
  375. this.menushow = true;
  376. },
  377. menuClick(id) {
  378. this.TabCur = id;
  379. // 显示该分类的数据
  380. this.curlist = this.deviceList[this.TabCur];
  381. if (this.curlist == null) {
  382. this.curlist = [];
  383. }
  384. // 选择设备分类,重新获取数据
  385. this.loadData(this.TabCur);
  386. this.menushow = false;
  387. },
  388. },
  389. destroyed() {
  390. // 停止定时器
  391. },
  392. };
  393. </script>
  394. <style>
  395. >>> .u-navbar--fixed {
  396. margin-top: 20px;
  397. }
  398. .main {
  399. margin-top: 100rpx;
  400. display: flex;
  401. flex-direction: column;
  402. }
  403. .menupage {
  404. position: absolute;
  405. z-index: 2;
  406. top: 40rpx;
  407. height: calc(100% - 40rpx);
  408. width: 100%;
  409. }
  410. .btns {
  411. display: flex;
  412. }
  413. .flcard {
  414. padding: 20rpx;
  415. background-color: #ffffff;
  416. margin-bottom: 5rpx;
  417. }
  418. .itemback {
  419. padding: 20rpx;
  420. background-color: #ffffff;
  421. margin-bottom: 5rpx;
  422. }
  423. .datacard {
  424. width: 30%;
  425. margin: 1%;
  426. float: left;
  427. height: 100rpx;
  428. text-align: center;
  429. background: linear-gradient(
  430. to right,
  431. rgba(55, 135, 254, 0.08),
  432. rgba(4, 184, 255, 0.08),
  433. rgba(60, 161, 237, 0.08)
  434. );
  435. }
  436. .error-tag {
  437. border-radius: 10%;
  438. display: inline-block;
  439. color: #e90000;
  440. line-height: 50rpx;
  441. font-size: 14px;
  442. text-align: center;
  443. width: 120rpx;
  444. height: 50rpx;
  445. background-color: rgba(233, 0, 0, 0.2);
  446. }
  447. .error-tag1 {
  448. border-radius: 10%;
  449. display: inline-block;
  450. color: #696969;
  451. line-height: 50rpx;
  452. font-size: 14px;
  453. text-align: center;
  454. width: 120rpx;
  455. height: 50rpx;
  456. background-color: rgba(105, 105, 105, 0.2);
  457. }
  458. .success-tag {
  459. border-radius: 10%;
  460. color: #42c000;
  461. line-height: 50rpx;
  462. font-size: 14px;
  463. width: 120rpx;
  464. height: 50rpx;
  465. display: inline-block;
  466. background-color: rgba(226, 250, 214);
  467. }
  468. .icon-style {
  469. margin: 15rpx;
  470. width: 14px;
  471. height: 14px;
  472. }
  473. </style>