index.vue 7.8 KB

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