home.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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. <view v-if="menushow" class="menupage">
  14. <DeviceMenu @menuClick="menuClick"></DeviceMenu>
  15. </view> -->
  16. <view v-if="!menushow" class="main">
  17. <view class="u-page">
  18. <u-list>
  19. <u-list-item
  20. class="itemback"
  21. v-for="(item, index) in curlist"
  22. :key="index"
  23. >
  24. <div @tap="openNewPage(item)">
  25. <u-row gutter="5" customStyle="margin-bottom: 10px">
  26. <u-col span="24">
  27. <image
  28. style="position: absolute; width: 18px; height: 18px"
  29. class="icon"
  30. :src="getIcon(TabCur)"
  31. alt="Icon"
  32. />
  33. <span class="title">{{ item.strinstallpos }}</span>
  34. </u-col>
  35. </u-row>
  36. <u-row gutter="5" customStyle="margin-bottom: 10px">
  37. <u-col span="3" style="margin-right: 5rpx">
  38. <div v-if="item.netStatus == 0" class="error-tag1">
  39. <image
  40. src="/static/model/connectFalse.svg"
  41. alt=""
  42. class="icon-style"
  43. />
  44. <span style="float: right">断开</span>
  45. </div>
  46. <div v-else class="success-tag">
  47. <image
  48. src="/static/model/connectTrue.svg"
  49. alt=""
  50. class="icon-style"
  51. />
  52. <span style="float: right">连接</span>
  53. </div>
  54. </u-col>
  55. <u-col span="4">
  56. <div v-if="item.warnFlag == 0" class="success-tag">
  57. <image
  58. src="/static/model/alarmTrue.svg"
  59. alt=""
  60. class="icon-style"
  61. />
  62. <span style="float: right">{{ item.warnLevel_str }}</span>
  63. </div>
  64. <div v-else class="error-tag">
  65. <image
  66. src="/static/model/alarmFalse.svg"
  67. alt=""
  68. class="icon-style"
  69. />
  70. <span style="float: right">{{ item.warnDes }}</span>
  71. </div>
  72. </u-col>
  73. <u-col span="5">
  74. <u--text class="timetext" :text="item.readTime"></u--text>
  75. </u-col>
  76. </u-row>
  77. <view v-if="colums[TabCur + '_monitor'] != null">
  78. <view
  79. class="datacard"
  80. v-for="(showitem, index) in colums[TabCur + '_monitor']"
  81. :key="index"
  82. v-show="
  83. showitem.appShow == 1 &&
  84. showitem.monitorcode != 'strinstallpos' &&
  85. showitem.monitorcode != 'netStatus' &&
  86. showitem.monitorcode != 'warnFlag' &&
  87. showitem.monitorcode != 'readTime' &&
  88. showitem.monitorcode != ''
  89. "
  90. >
  91. <view
  92. :class="TabCur"
  93. style="padding-top: 10rpx; padding-bottom: 10rpx"
  94. >
  95. <view
  96. v-if="
  97. showitem.datatype == 1 &&
  98. showitem.monitorcode == 'doorUse'
  99. "
  100. class="demo-layout bg-purple-light"
  101. style="
  102. margin-top: 10rpx;
  103. color: #3787fe;
  104. font-size: 30rpx;
  105. margin-top: 5rpx;
  106. "
  107. >
  108. {{
  109. item[showitem.monitorcode] == "2"
  110. ? "行人"
  111. : item[showitem.monitorcode] == "1"
  112. ? "行车"
  113. : "-"
  114. }}
  115. </view>
  116. <view
  117. v-else-if="showitem.datatype == 1"
  118. class="demo-layout bg-purple-light"
  119. style="
  120. margin-top: 10rpx;
  121. color: #3787fe;
  122. font-size: 30rpx;
  123. margin-top: 5rpx;
  124. "
  125. >
  126. {{
  127. item[showitem.monitorcode] == null ||
  128. item[showitem.monitorcode] == ""
  129. ? "-"
  130. : item[showitem.monitorcode]
  131. }}
  132. </view>
  133. <view
  134. v-else-if="showitem.datatype == 2"
  135. class="demo-layout bg-purple-light"
  136. style="color: #3787fe; font-size: 30rpx; margin-top: 5rpx"
  137. >
  138. {{
  139. item.readData[showitem.monitorcode] == null ||
  140. item.readData[showitem.monitorcode] == ""
  141. ? "-"
  142. : item.readData[showitem.monitorcode]
  143. }}
  144. </view>
  145. <view
  146. class="demo-layout bg-purple-light"
  147. style="
  148. margin-top: 6rpx;
  149. color: #677799;
  150. margin-bottom: 5rpx;
  151. "
  152. >
  153. {{ showitem.des }}
  154. </view>
  155. </view>
  156. </view>
  157. </view>
  158. </div>
  159. </u-list-item>
  160. </u-list>
  161. </view>
  162. </view>
  163. </view>
  164. </template>
  165. <script>
  166. import DeviceMenu from "./devicemenu/devicemenu.vue";
  167. import api from "@/api/api";
  168. import { nextTick } from "vue";
  169. export default {
  170. data() {
  171. return {
  172. menushow: false,
  173. TabCur: "gate",
  174. curlist: [],
  175. deviceList: {},
  176. colums: {},
  177. };
  178. },
  179. components: {
  180. DeviceMenu,
  181. },
  182. props: ["showColum", 'deviceType'],
  183. watch: {
  184. showColum(data) {
  185. this.colums = data;
  186. },
  187. deviceType: {
  188. async handler (data) {
  189. if(data){
  190. this.TabCur = data;
  191. this.curlist = this.deviceList[this.TabCur];
  192. if (this.curlist == null) {
  193. this.curlist = [];
  194. }
  195. // 选择设备分类,重新获取数据
  196. await this.loadData(this.TabCur);
  197. this.$emit('setMenushow', {
  198. menushow: false
  199. });
  200. }
  201. },
  202. immediate: true
  203. }
  204. },
  205. created() {
  206. this.colums = this.showColum;
  207. },
  208. async mounted() {
  209. await this.loadData(this.TabCur);
  210. this.startTimer();
  211. },
  212. methods: {
  213. startTimer() {
  214. // 每隔一段时间执行某个操作
  215. this.timer = setInterval(async() => {
  216. // 执行定时任务
  217. await this.loadData(this.deviceType);
  218. console.log("定时任务执行中...");
  219. }, 5000);
  220. },
  221. stopTimer() {
  222. // 停止定时器
  223. clearInterval(this.timer);
  224. },
  225. getIcon(itemValue) {
  226. // 根据itemValue获取对应的图标路径,如果找不到对应关系则返回默认图标
  227. return "/static/sidebar/" + itemValue + ".svg";
  228. },
  229. getValueIcon(itemValue) {
  230. // 根据itemValue获取对应的图标路径,如果找不到对应关系则返回默认图标
  231. return "/static/sidebar/" + itemValue + ".svg";
  232. },
  233. loadData(type) {
  234. return new Promise((resolve, reject) => {
  235. api
  236. .getDeviceMonitor({
  237. devicetype: type,
  238. pagetype: "normal",
  239. filterParams: {},
  240. })
  241. .then((response) => {
  242. if (response.data.code == 200) {
  243. this.deviceList[type] = response.data.result.msgTxt[0].datalist;
  244. this.curlist = this.deviceList[type];
  245. this.curlist.forEach((item) => {
  246. if (item.readData.frontGateOpen == 1) {
  247. item.readData.frontGateOpen = "打开";
  248. } else {
  249. item.readData.frontGateOpen = "关闭";
  250. }
  251. if (item.readData.midGateOpen == 1) {
  252. item.readData.midGateOpen = "打开";
  253. } else {
  254. item.readData.midGateOpen = "关闭";
  255. }
  256. if (item.readData.rearGateOpen == 1) {
  257. item.readData.rearGateOpen = "打开";
  258. } else {
  259. item.readData.rearGateOpen = "关闭";
  260. }
  261. if (item.readData.midGateOpen == 1) {
  262. item.readData.midGateOpen = "打开";
  263. } else {
  264. item.readData.midGateOpen = "关闭";
  265. }
  266. });
  267. } else {
  268. resolve(response);
  269. }
  270. })
  271. .catch((error) => {
  272. console.log("catch===>response", response);
  273. reject(error);
  274. });
  275. });
  276. },
  277. devicemenuShow(e) {
  278. this.menushow = !this.menushow;
  279. },
  280. // menuClick(id) {
  281. // this.TabCur = id;
  282. // // 显示该分类的数据
  283. // this.curlist = this.deviceList[this.TabCur];
  284. // if (this.curlist == null) {
  285. // this.curlist = [];
  286. // }
  287. // // 选择设备分类,重新获取数据
  288. // this.loadData(this.TabCur);
  289. // this.menushow = false;
  290. // },
  291. openNewPage(params) {
  292. this.$destroy();
  293. uni.navigateTo({
  294. url: `/pages/home/detail/autodoor/autodoor?id=${params.deviceID}&name=${params.strinstallpos}&type=${this.TabCur}`,
  295. });
  296. },
  297. },
  298. destroyed() {
  299. // 停止定时器
  300. this.stopTimer();
  301. },
  302. };
  303. </script>
  304. <style>
  305. >>> .u-navbar--fixed {
  306. /* margin-top: 20px; */
  307. }
  308. .main {
  309. /* margin-top: 100rpx; */
  310. display: flex;
  311. flex-direction: column;
  312. }
  313. .card {
  314. background-color: #ffffff;
  315. margin: auto;
  316. margin-top: 20rpx;
  317. width: 10%;
  318. height: 280rpx;
  319. border: 1rpx solid #000000;
  320. border-radius: 20rpx;
  321. }
  322. .menupage {
  323. position: absolute;
  324. z-index: 2;
  325. width: 100%;
  326. }
  327. .timetext {
  328. text-align: right;
  329. float: right;
  330. }
  331. .itemback {
  332. padding: 20rpx;
  333. background-color: #ffffff;
  334. margin-bottom: 5rpx;
  335. }
  336. .datacard .content {
  337. width: 30rpx;
  338. height: 30rpx;
  339. left: 0rpx;
  340. top: 0rpx;
  341. position: absolute;
  342. }
  343. .datacard {
  344. border-radius: 10rpx;
  345. border: rgba(55, 135, 254, 0.28);
  346. width: 30%;
  347. margin: 1%;
  348. float: left;
  349. height: 105rpx;
  350. text-align: center;
  351. background: linear-gradient(
  352. to right,
  353. rgba(55, 135, 254, 0.08),
  354. rgba(4, 184, 255, 0.08),
  355. rgba(60, 161, 237, 0.08)
  356. );
  357. }
  358. .datacard .gate {
  359. background: linear-gradient(
  360. to right,
  361. rgba(75, 135, 254, 0.08),
  362. rgba(24, 184, 255, 0.08),
  363. rgba(80, 161, 237, 0.08)
  364. );
  365. }
  366. .datacard .window {
  367. background: linear-gradient(
  368. to right,
  369. rgba(55, 125, 254, 0.08),
  370. rgba(4, 164, 255, 0.08),
  371. rgba(60, 131, 237, 0.08)
  372. );
  373. }
  374. .datacard .windrect {
  375. background: linear-gradient(
  376. to right,
  377. rgba(85, 125, 254, 0.08),
  378. rgba(34, 164, 255, 0.08),
  379. rgba(90, 131, 237, 0.08)
  380. );
  381. }
  382. .error-tag {
  383. border-radius: 10%;
  384. display: inline-block;
  385. color: #e90000;
  386. line-height: 50rpx;
  387. font-size: 14px;
  388. text-align: center;
  389. float: left;
  390. width: 180rpx;
  391. height: 50rpx;
  392. padding-right: 30rpx;
  393. background-color: rgba(233, 0, 0, 0.2);
  394. }
  395. .error-tag1 {
  396. border-radius: 10%;
  397. display: inline-block;
  398. color: #696969;
  399. line-height: 50rpx;
  400. font-size: 14px;
  401. text-align: center;
  402. margin-top: 10rpx;
  403. float: left;
  404. width: 120rpx;
  405. height: 50rpx;
  406. background-color: rgba(105, 105, 105, 0.2);
  407. }
  408. .success-tag {
  409. border-radius: 10%;
  410. color: #42c000;
  411. line-height: 25px;
  412. font-size: 14px;
  413. width: 60px;
  414. height: 26px;
  415. padding-right: 15px;
  416. background-color: rgba(226, 250, 214);
  417. }
  418. .icon-style {
  419. margin: 7px;
  420. width: 14px;
  421. height: 14px;
  422. }
  423. .title {
  424. margin-left: 40rpx;
  425. float: left;
  426. font-size: 28rpx;
  427. font-weight: 400;
  428. }
  429. </style>