index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <template>
  2. <view class="devic-box">
  3. <!-- 建议放在外层 -->
  4. <u-navbar
  5. :bgStatusImage="backPic0"
  6. :bgImage="backPic"
  7. title="设备监测"
  8. @leftClick="onLeftClick"
  9. :safeAreaInsetTop="true"
  10. :fixed="true"
  11. height="50px"
  12. bgColor="transparent"
  13. titleStyle="fw600 fs-18"
  14. leftIconColor="#303133"
  15. >
  16. <view class="u-nav-slot" slot="left">
  17. <!-- 菜单选择页显示三横线,选完设备类型进入列表后显示返回键 -->
  18. <view v-if="menushow" class="menu-icon">
  19. <view class="menu-line"></view>
  20. <view class="menu-line"></view>
  21. <view class="menu-line"></view>
  22. </view>
  23. <u-icon v-else name="arrow-left" size="20" color="#303133"></u-icon>
  24. </view>
  25. </u-navbar>
  26. <!-- 左上角三横线展开的菜单 -->
  27. <view
  28. v-if="navMenuShow"
  29. class="nav-menu-mask"
  30. @tap="navMenuShow = false"
  31. ></view>
  32. <view v-if="navMenuShow" class="nav-menu-panel">
  33. <view
  34. class="nav-menu-item"
  35. v-for="(item, index) in navMenuList"
  36. :key="index"
  37. @tap="navMenuClick(item)"
  38. >
  39. {{ item.name }}
  40. </view>
  41. </view>
  42. <view class="devic-box-content">
  43. <view v-if="menushow" class="menupage">
  44. <DeviceMenu @menuClick="menuClick"></DeviceMenu>
  45. </view>
  46. <!-- <u-tabs v-if="!menushow" class="devic-box-tab" :current="PageCur" :list="tabList" @click="NavChange"></u-tabs> -->
  47. <u-tabs
  48. v-if="!menushow"
  49. class="devic-box-tab"
  50. :current="pageCurNew"
  51. :list="tabListNew"
  52. @click="NavChange"
  53. ></u-tabs>
  54. <view class="">
  55. <!-- <home cur="home" :showColum="showColum" v-if="pageCurNew == '0' && !menushow" :key="0" :deviceType="deviceType"
  56. @setMenushow="setMenushow"></home> -->
  57. <home
  58. ref="homeRef"
  59. cur="home"
  60. :showColum="showColum"
  61. v-if="!menushow"
  62. :key="0"
  63. :deviceType="deviceType"
  64. @setMenushow="setMenushow"
  65. ></home>
  66. <!-- <history :key="1" cur="history" :showColum="showColum" :deviceType="deviceType"
  67. v-if="PageCur == '1' && !menushow" @setMenushow="setMenushow"></history>
  68. <operation :key="2" :showColum="showColum" :deviceType="deviceType" cur="operation"
  69. v-if="PageCur == '2' && !menushow" @setMenushow="setMenushow"></operation> -->
  70. </view>
  71. </view>
  72. </view>
  73. </template>
  74. <script>
  75. import api from "@/api/api";
  76. import DeviceMenu from "./devicemenu/devicemenu.vue";
  77. export default {
  78. components: {
  79. DeviceMenu,
  80. },
  81. data() {
  82. return {
  83. // backPic0: "url(/static/topnavbar0.png)",
  84. // backPic: "url(../../static/topnavbar.png)",
  85. backPic0: "",
  86. backPic: "",
  87. // PageCur: "0",
  88. pageCurNew: "",
  89. showColum: {},
  90. menushow: true,
  91. deviceType: "",
  92. //左上角三横线菜单
  93. navMenuShow: false,
  94. navMenuList: [
  95. // component:切换到外层 index.vue 的 tab 组件;url:跳转独立页面
  96. { name: "瓦斯日报", component: "gasreport" },
  97. ],
  98. // tabList: [
  99. // {
  100. // name: "设备监测",
  101. // },
  102. // {
  103. // name: "历史数据",
  104. // },
  105. // {
  106. // name: "操作记录",
  107. // },
  108. // ],
  109. tabListNew: [],
  110. };
  111. },
  112. created() {
  113. this.getShowColum();
  114. },
  115. onLoad: function () {
  116. // this.PageCur = "0";
  117. },
  118. onShow() {
  119. // 从设备详情页返回时,恢复子组件的轮询并立即刷新数据
  120. this.$nextTick(() => {
  121. const homeRef = this.$refs.homeRef;
  122. if (homeRef && typeof homeRef.restartTimer === "function") {
  123. homeRef.restartTimer();
  124. }
  125. });
  126. },
  127. methods: {
  128. NavChange: function (item) {
  129. console.log("item", item);
  130. // this.PageCur = item.index;
  131. this.navMenuShow = false;
  132. this.deviceType = item.id;
  133. this.menushow = false;
  134. },
  135. devicemenuShow(e) {
  136. this.menushow = !this.menushow;
  137. },
  138. //左上角图标:菜单选择页展开三横线菜单,已进入列表页则返回菜单选择
  139. onLeftClick() {
  140. if (this.menushow) {
  141. this.toggleNavMenu();
  142. } else {
  143. this.navMenuShow = false;
  144. this.menushow = true;
  145. }
  146. },
  147. //左上角三横线菜单:展开/收起
  148. toggleNavMenu() {
  149. this.navMenuShow = !this.navMenuShow;
  150. },
  151. //点击菜单项:优先切换外层 tab 组件,否则跳转独立页面
  152. navMenuClick(item) {
  153. this.navMenuShow = false;
  154. if (!item) {
  155. return;
  156. }
  157. if (item.component) {
  158. this.$emit("changePage", item.component);
  159. return;
  160. }
  161. if (!item.url) {
  162. return;
  163. }
  164. uni.navigateTo({
  165. url: item.url,
  166. fail: () => {
  167. uni.showToast({ title: "页面不存在", icon: "none" });
  168. },
  169. });
  170. },
  171. menuClick(params) {
  172. debugger;
  173. this.navMenuShow = false;
  174. let data = params.menu
  175. .map((item) => item.children)
  176. .flatMap((i) => i)
  177. .map((v, index) => {
  178. return {
  179. name: v.itemText,
  180. id: v.itemValue,
  181. index: index,
  182. };
  183. });
  184. this.deviceType = params.id;
  185. this.tabListNew = data;
  186. this.pageCurNew = this.tabListNew.find(
  187. (item) => item.id == params.id
  188. ).index;
  189. console.log("data", data);
  190. this.menushow = false;
  191. },
  192. getShowColum() {
  193. new Promise((resolve, reject) => {
  194. api
  195. .getShowColum({})
  196. .then((response) => {
  197. if (response.data.code == 200) {
  198. var showlist = response.data.result;
  199. this.$store.commit("SET_SHOWCOLUM", showlist);
  200. this.showColum = showlist;
  201. console.log("showColum", this.showColum);
  202. } else {
  203. resolve(response);
  204. }
  205. })
  206. .catch((error) => {
  207. console.log("catch===>response", response);
  208. reject(error);
  209. });
  210. });
  211. },
  212. setMenushow(params) {
  213. if (params) {
  214. this.menushow = params.menushow;
  215. }
  216. },
  217. },
  218. };
  219. </script>
  220. <style lang="scss" scoped>
  221. // .devic-box {
  222. // // background: #f4f7fd;
  223. // }
  224. .devic-box-content {
  225. height: calc(100vh - 101px);
  226. margin-top: 50px;
  227. overflow-y: auto;
  228. // background: #f4f7fd;
  229. }
  230. .menupage {
  231. min-height: 100%;
  232. // background: #f4f7fd;
  233. }
  234. ::v-deep .u-tabs__wrapper {
  235. margin: 0px 15px !important;
  236. }
  237. //左上角三横线图标
  238. .menu-icon {
  239. width: 18px;
  240. height: 14px;
  241. display: flex;
  242. flex-direction: column;
  243. justify-content: space-between;
  244. .menu-line {
  245. width: 18px;
  246. height: 2px;
  247. border-radius: 1px;
  248. background-color: #303133;
  249. }
  250. }
  251. //三横线展开的下拉菜单
  252. .nav-menu-mask {
  253. position: fixed;
  254. left: 0;
  255. top: 0;
  256. right: 0;
  257. bottom: 0;
  258. background-color: rgba(0, 0, 0, 0.15);
  259. z-index: 998;
  260. }
  261. .nav-menu-panel {
  262. position: fixed;
  263. left: 10px;
  264. top: calc(var(--status-bar-height) + 54px);
  265. width: 140px;
  266. padding: 4px 0px;
  267. box-sizing: border-box;
  268. border-radius: 8px;
  269. background-color: #fff;
  270. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  271. z-index: 999;
  272. .nav-menu-item {
  273. height: 44px;
  274. padding: 0px 16px;
  275. display: flex;
  276. align-items: center;
  277. font-size: 14px;
  278. color: #303133;
  279. &:active {
  280. background-color: #f2f6ff;
  281. }
  282. & + .nav-menu-item {
  283. border-top: 1px solid #f0f2f5;
  284. }
  285. }
  286. }
  287. </style>