index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <template>
  2. <div style="height: 60px; flex-shrink: 0" ref="pronbit">
  3. <div class="navbar" :class="fix ? 'navbar_fix' : ''">
  4. <!--导航栏-->
  5. <div class="nav_box center_1200">
  6. <el-menu
  7. :default-active="activeIndex"
  8. class="el-menu-demo"
  9. mode="horizontal"
  10. @select="handleSelect"
  11. background-color="#3975C6"
  12. text-color="#fff"
  13. active-text-color="#fff"
  14. router
  15. >
  16. <template v-for="(item, index) in $store.state.asyncRouter">
  17. <el-menu-item
  18. v-if="!item.ChildList || item.ChildList.length <= 0"
  19. :index="
  20. item.MenuId === 1
  21. ? 'home'
  22. : item.WebUrl
  23. ? null
  24. : `menuList?ParentId=${item.ParentId}&MenuId=${item.MenuId}`
  25. "
  26. ><a
  27. v-if="item.WebUrl && item.MenuId !== 1"
  28. :href="item.WebUrl"
  29. target="_blank"
  30. style="color: #fff; display: block"
  31. >{{ item.Name }}</a
  32. ><span v-else>{{ item.Name }}</span></el-menu-item
  33. >
  34. <el-submenu
  35. v-else
  36. :index="`menuList?ParentId=${item.ParentId}&MenuId=${item.MenuId}`"
  37. >
  38. <template slot="title">{{ item.Name }}</template>
  39. <template v-for="(items, indexs) in item.ChildList">
  40. <el-menu-item
  41. v-if="items.Type === 2"
  42. :key="indexs"
  43. :index="
  44. items.WebUrl
  45. ? null
  46. : `menuList?ParentId=${items.ParentId}&MenuId=${items.MenuId}`
  47. "
  48. ><a
  49. v-if="items.WebUrl"
  50. :href="items.WebUrl"
  51. target="_blank"
  52. style="color: #fff; display: block"
  53. >{{ items.Name }}</a
  54. ><span v-else>{{ items.Name }}</span></el-menu-item
  55. ><el-submenu
  56. v-else
  57. :index="`menuList?ParentId=${items.ParentId}&MenuId=${items.MenuId}`"
  58. >
  59. <template slot="title">{{ items.Name }}</template>
  60. <template v-for="(itemsxt, indexsxt) in items.ChildList">
  61. <el-menu-item
  62. :index="
  63. itemsxt.WebUrl
  64. ? null
  65. : `menuList?ParentId=${itemsxt.ParentId}&MenuId=${itemsxt.MenuId}`
  66. "
  67. ><a
  68. v-if="itemsxt.WebUrl"
  69. :href="itemsxt.WebUrl"
  70. target="_blank"
  71. style="color: #fff; display: block"
  72. >{{ itemsxt.Name }}</a
  73. ><span v-else>{{ itemsxt.Name }}</span></el-menu-item
  74. >
  75. </template>
  76. </el-submenu>
  77. </template>
  78. </el-submenu>
  79. </template>
  80. </el-menu>
  81. <!-- <div>
  82. <el-button size="medium" v-if="$store.state.token" @click="userInfo"
  83. >个人中心</el-button
  84. >
  85. <el-button size="medium" v-else @click="login">登录</el-button>
  86. </div> -->
  87. </div>
  88. </div>
  89. <div class="backTopBtn" v-if="fix" @click="scollTop">
  90. <img src="@/assets/images/backTopimg.png" alt="" />
  91. </div>
  92. <login-dialog ref="login"></login-dialog>
  93. <user-info ref="userInfo"></user-info>
  94. </div>
  95. </template>
  96. <script>
  97. import loginDialog from "@/components/login-dialog/index.vue";
  98. import userInfo from "@/components/userInfo/index.vue";
  99. export default {
  100. components: { loginDialog, userInfo },
  101. data() {
  102. return {
  103. activeIndex: "home",
  104. fix: false,
  105. scrollTimer: null,
  106. };
  107. },
  108. watch: {
  109. $route: {
  110. handler: function (val, oldVal) {
  111. this.activeIndex = val.fullPath.substring(1);
  112. },
  113. // 深度观察监听
  114. deep: true,
  115. immediate: true,
  116. },
  117. },
  118. mounted() {
  119. window.addEventListener("scroll", this.handleScroll); // 监听页面滚动
  120. console.log("$store.state.asyncRouter", this.$store.state.asyncRouter);
  121. },
  122. methods: {
  123. userInfo() {
  124. this.$refs.userInfo.showInit();
  125. },
  126. login() {
  127. this.$refs.login.showInit();
  128. },
  129. scollTop() {
  130. clearInterval(this.scrollTimer);
  131. this.scrollTimer = setInterval(() => {
  132. const top = document.documentElement.scrollTop;
  133. const speed = top / 10;
  134. if (document.documentElement.scrollTop !== 0) {
  135. document.documentElement.scrollTop -= speed;
  136. } else {
  137. clearInterval(this.scrollTimer);
  138. }
  139. }, 16);
  140. },
  141. handleScroll() {
  142. if (this.$refs.pronbit.getBoundingClientRect().top <= 0) {
  143. this.fix = true;
  144. } else {
  145. this.fix = false;
  146. }
  147. },
  148. handleSelect(key, keyPath) {
  149. console.log(key, keyPath);
  150. },
  151. },
  152. };
  153. </script>
  154. <style lang="scss" scoped>
  155. // ::v-deep .el-menu-item,
  156. // ::v-deep .el-submenu__title {
  157. // font-size: 20px;
  158. // }
  159. ::v-deep .el-menu-item * {
  160. vertical-align: unset;
  161. }
  162. ::v-deep .el-submenu > .el-submenu__title {
  163. font-size: 20px;
  164. }
  165. .el-menu--horizontal > .el-menu-item {
  166. font-size: 20px;
  167. }
  168. ::v-deep .el-menu.el-menu--horizontal {
  169. flex-shrink: 0;
  170. }
  171. .backTopBtn {
  172. position: fixed;
  173. bottom: 20px;
  174. right: 20px;
  175. width: 40px;
  176. height: 40px;
  177. border-radius: 8px;
  178. overflow: hidden;
  179. transition: all 0.3s;
  180. cursor: pointer;
  181. user-select: none;
  182. background-color: #fff !important;
  183. box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.4);
  184. z-index: 9999;
  185. & > img {
  186. padding: 10px;
  187. width: 100%;
  188. height: 100%;
  189. }
  190. &:hover {
  191. transform: scale(1.2);
  192. }
  193. }
  194. ::v-deep .el-submenu__title i {
  195. color: #fff;
  196. }
  197. .navbar {
  198. height: 60px;
  199. font-size: 20px;
  200. background-color: #3975c6;
  201. & > .nav_box {
  202. display: flex;
  203. align-items: center;
  204. justify-content: space-between;
  205. }
  206. }
  207. .navbar_fix {
  208. position: fixed;
  209. top: 0;
  210. left: 0;
  211. right: 0;
  212. z-index: 333;
  213. }
  214. ::v-deep .el-menu.el-menu--horizontal {
  215. border-bottom: none;
  216. }
  217. </style>