history.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  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. <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="deviceName ? deviceName : '选择设备'"
  40. @click="deviceShow = true"
  41. ></u-button>
  42. <u-button
  43. type="primary"
  44. shape="circle"
  45. :text="lable ? lable : '间隔时间'"
  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. @cancel="deviceShow = false"
  59. @confirm="selectDevice"
  60. keyName="strinstallpos"
  61. >
  62. </u-picker>
  63. <u-picker
  64. :show="show"
  65. :columns="timeColumns"
  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. <image
  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. <image
  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. <image
  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. <image
  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 api from "@/api/api";
  190. import dayjs from "dayjs";
  191. export default {
  192. data() {
  193. return {
  194. menushow: false,
  195. TabCur: "gate",
  196. curlist: [],
  197. colums: {},
  198. deviceList: {},
  199. startDate: null,
  200. endDate: null,
  201. show: false,
  202. deviceShow: false,
  203. dataShow: false,
  204. dataShow1: false,
  205. StartTime: "", //起始时间
  206. EndTime: "", //结束时间
  207. devices: [], //设备类型数组
  208. deviceName: "", //设备名称
  209. timeS: "", //间隔时间
  210. lable: "", //间隔时间
  211. timeColumns: [
  212. [
  213. {
  214. label: "1秒",
  215. value: "1",
  216. },
  217. {
  218. label: "5秒",
  219. value: "2",
  220. },
  221. {
  222. label: "10秒",
  223. value: "3",
  224. },
  225. {
  226. label: "30秒",
  227. value: "4",
  228. },
  229. {
  230. label: "1分钟",
  231. value: "5",
  232. },
  233. {
  234. label: "10分钟",
  235. value: "6",
  236. },
  237. {
  238. label: "30分钟",
  239. value: "7",
  240. },
  241. {
  242. label: "1小时",
  243. value: "8",
  244. },
  245. ],
  246. ],
  247. deviceID: "", //设备ID
  248. // deviceType: "", //设备类型
  249. skip: 8, //时间间隔
  250. dataTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
  251. historyData: [], //历史数据
  252. };
  253. },
  254. props: ["showColum", 'deviceType'],
  255. watch: {
  256. showColum(data) {
  257. this.colums = data;
  258. },
  259. deviceType: {
  260. async handler (data) {
  261. if(data){
  262. this.TabCur = data;
  263. this.curlist = this.deviceList[this.TabCur];
  264. if (this.curlist == null) {
  265. this.curlist = [];
  266. }
  267. // 选择设备分类,重新获取数据
  268. await this.loadData(this.TabCur);
  269. this.$emit('setMenushow', {
  270. menushow: false
  271. });
  272. }
  273. },
  274. immediate: true
  275. }
  276. },
  277. created() {
  278. this.colums = this.showColum;
  279. const startTime =new Date().getTime() - 3600 * 1000 * 24 * 30;
  280. const endTime = new Date();
  281. this.StartTime = dayjs(startTime).format("YYYY-MM-DD HH:mm:ss");
  282. this.EndTime = dayjs(endTime).format("YYYY-MM-DD HH:mm:ss");
  283. },
  284. mounted() {
  285. this.TabCur = this.deviceType;
  286. },
  287. methods: {
  288. loadData(type) {
  289. new Promise((resolve, reject) => {
  290. api
  291. .getDeviceMonitor({
  292. devicetype: type,
  293. pagetype: "normal",
  294. filterParams: {},
  295. })
  296. .then((response) => {
  297. if (response.data.code == 200) {
  298. this.deviceList[type] = response.data.result.msgTxt[0].datalist;
  299. this.curlist = this.deviceList[type];
  300. this.setData(this.curlist);
  301. } else {
  302. resolve(response);
  303. }
  304. })
  305. .catch((error) => {
  306. reject(error);
  307. });
  308. });
  309. },
  310. //选择设备选择器 保存对应的id
  311. setData(data) {
  312. this.devices = [];
  313. data.forEach((element) => {
  314. const deviceObj = {
  315. id: element.deviceID,
  316. strinstallpos: element.strinstallpos,
  317. type: element.deviceType,
  318. };
  319. this.devices.push(deviceObj);
  320. });
  321. },
  322. //选择设备 点击确定按钮 保存id
  323. selectDevice(e) {
  324. this.deviceID = e.value[0].id;
  325. this.TabCur = e.value[0].type;
  326. this.deviceName = e.value[0].strinstallpos;
  327. this.deviceShow = false;
  328. },
  329. //选择起始时间
  330. selectStartTime(e) {
  331. const startTime = e.value;
  332. const formattedTime = dayjs(startTime).format("YYYY-MM-DD HH:mm:ss");
  333. this.StartTime = formattedTime;
  334. this.dataShow = false;
  335. },
  336. //选择起始时间
  337. selectEndTime(e) {
  338. const endTime = e.value;
  339. const formattedTime = dayjs(endTime).format("YYYY-MM-DD HH:mm:ss");
  340. this.EndTime = formattedTime;
  341. this.dataShow1 = false;
  342. },
  343. //选择间隔时间
  344. selectSkipTime(e) {
  345. this.skip = e.value[0].value;
  346. this.lable = e.value[0].label;
  347. this.show = false;
  348. },
  349. //查询历史数据 getDeviceHistory
  350. checkHistory() {
  351. const params = {
  352. ttime_begin: this.StartTime,
  353. ttime_end: this.EndTime,
  354. gdeviceid: this.deviceID,
  355. skip: this.skip,
  356. pageNo: 1,
  357. pageSize: 10000,
  358. strtype: this.TabCur,
  359. };
  360. new Promise((resolve, reject) => {
  361. api
  362. .getDeviceHistory(params)
  363. .then((response) => {
  364. if (response.data.code == 200) {
  365. this.historyData = response.data.result.datalist.records;
  366. this.historyData.forEach((item) => {
  367. if (item.readData.frontGateOpen == 1) {
  368. item.readData.frontGateOpen = "打开";
  369. } else {
  370. item.readData.frontGateOpen = "关闭";
  371. }
  372. if (item.readData.rearGateOpen == 1) {
  373. item.readData.rearGateOpen = "打开";
  374. } else {
  375. item.readData.rearGateOpen = "关闭";
  376. }
  377. if (item.readData.midGateOpen == 1) {
  378. item.readData.midGateOpen = "打开";
  379. } else {
  380. item.readData.midGateOpen = "关闭";
  381. }
  382. });
  383. } else {
  384. resolve(response);
  385. }
  386. })
  387. .catch((error) => {
  388. reject(error);
  389. });
  390. });
  391. },
  392. devicemenuShow(e) {
  393. this.menushow = !this.menushow;
  394. console.log( this.menushow,'dainjichengg成都多大事');
  395. },
  396. menuClick(id) {
  397. this.TabCur = id;
  398. // 显示该分类的数据
  399. this.curlist = this.deviceList[this.TabCur];
  400. if (this.curlist == null) {
  401. this.curlist = [];
  402. }
  403. // 选择设备分类,重新获取数据
  404. this.loadData(this.TabCur);
  405. this.menushow = false;
  406. },
  407. },
  408. destroyed() {
  409. // 停止定时器
  410. },
  411. };
  412. </script>
  413. <style>
  414. .main {
  415. /* margin-top: 100rpx; */
  416. display: flex;
  417. flex-direction: column;
  418. }
  419. .menupage {
  420. position: absolute;
  421. z-index: 2;
  422. top: 40rpx;
  423. height: calc(100% - 40rpx);
  424. width: 100%;
  425. }
  426. .btns {
  427. display: flex;
  428. }
  429. .flcard {
  430. padding: 20rpx;
  431. background-color: #ffffff;
  432. margin-bottom: 5rpx;
  433. }
  434. .itemback {
  435. padding: 20rpx;
  436. background-color: #ffffff;
  437. margin-bottom: 5rpx;
  438. }
  439. .datacard {
  440. width: 30%;
  441. margin: 1%;
  442. float: left;
  443. height: 100rpx;
  444. text-align: center;
  445. background: linear-gradient(
  446. to right,
  447. rgba(55, 135, 254, 0.08),
  448. rgba(4, 184, 255, 0.08),
  449. rgba(60, 161, 237, 0.08)
  450. );
  451. }
  452. .error-tag {
  453. border-radius: 10%;
  454. display: inline-block;
  455. color: #e90000;
  456. line-height: 50rpx;
  457. font-size: 14px;
  458. text-align: center;
  459. width: 120rpx;
  460. height: 50rpx;
  461. background-color: rgba(233, 0, 0, 0.2);
  462. }
  463. .error-tag1 {
  464. border-radius: 10%;
  465. display: inline-block;
  466. color: #696969;
  467. line-height: 50rpx;
  468. font-size: 14px;
  469. text-align: center;
  470. width: 120rpx;
  471. height: 50rpx;
  472. background-color: rgba(105, 105, 105, 0.2);
  473. }
  474. .success-tag {
  475. border-radius: 10%;
  476. color: #42c000;
  477. line-height: 50rpx;
  478. font-size: 14px;
  479. width: 120rpx;
  480. height: 50rpx;
  481. display: inline-block;
  482. background-color: rgba(226, 250, 214);
  483. }
  484. .icon-style {
  485. margin: 15rpx;
  486. width: 14px;
  487. height: 14px;
  488. }
  489. </style>