category.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <div class="menuDiv">
  3. <h3 v-if="showHeader">{{ $t("page.components.category.showHeader") }}</h3>
  4. <ul class="menuUl">
  5. <li
  6. v-for="({ id, title, subList }, index) in items"
  7. :key="`menu-${index}`"
  8. class="menuli"
  9. >
  10. <div
  11. class="dalei"
  12. :class="{ curr: currPid === id }"
  13. @click="() => setCurrIndex(id)"
  14. >
  15. <div />
  16. {{ title }}
  17. <i class="el-icon-arrow-right"></i>
  18. </div>
  19. <div class="menuCon" v-if="subList.length">
  20. <div
  21. v-for="({ id: sid, title: st }, i) in subList"
  22. :key="`menu-item-${i}`"
  23. :class="{ item: true, curr: currSid === sid }"
  24. @click="() => setCurrIndex(sid)"
  25. >
  26. {{ st }}
  27. </div>
  28. </div>
  29. </li>
  30. </ul>
  31. </div>
  32. </template>
  33. <script lang="ts">
  34. import { Component, Vue, Prop, Watch, Emit } from "vue-property-decorator";
  35. import menu from "@/store/modules/menu";
  36. @Component
  37. export default class extends Vue {
  38. @Prop(Number)
  39. private currId!: number;
  40. @Prop(Boolean) private showHeader!: boolean;
  41. get items() {
  42. return menu.pList.map(x => ({
  43. ...x,
  44. subList: menu.subList(x.id)
  45. }));
  46. }
  47. get info() {
  48. return menu.info(this.currId);
  49. }
  50. get currPid() {
  51. if (!this.info) return 0;
  52. return this.info.pId || this.info.id;
  53. }
  54. get currSid() {
  55. if (!this.info) return 0;
  56. return this.info.id;
  57. }
  58. @Emit("change")
  59. setCurrIndex(id: number) {
  60. return id;
  61. }
  62. }
  63. </script>
  64. <style lang="scss" scoped>
  65. .menuDiv {
  66. width: 100%;
  67. height: 39rem;
  68. // overflow: hidden;
  69. position: relative;
  70. display: flex; //因为菜单项不固定 但总高度固定 所以不得不采用flex布局
  71. flex-flow: column nowrap;
  72. h3 {
  73. background: #fd5522;
  74. color: #fff;
  75. height: 35px;
  76. line-height: 35px;
  77. padding-left: 20px;
  78. }
  79. .menuUl {
  80. list-style: none;
  81. width: 100%;
  82. background: #fff;
  83. flex-grow: 1;
  84. display: flex;
  85. flex-flow: column nowrap;
  86. li.menuli {
  87. display: flex;
  88. flex-direction: column;
  89. flex-grow: 1;
  90. // height: 5.6rem;
  91. // line-height: 5.6rem;
  92. font-size: 1.4rem;
  93. color: #333;
  94. border-bottom: 0.1rem solid #e5e5e5;
  95. box-sizing: border-box;
  96. &:hover {
  97. .menuCon {
  98. display: block;
  99. }
  100. }
  101. .dalei {
  102. display: flex;
  103. justify-content: space-between;
  104. align-items: center;
  105. height: 100%;
  106. flex-grow: 1;
  107. cursor: pointer;
  108. padding-right: 1.6rem;
  109. text-align: center;
  110. &.curr,
  111. &:hover {
  112. background: #ffddd3;
  113. color: #fd5522;
  114. div {
  115. background: #fd5522;
  116. }
  117. }
  118. div {
  119. display: inline-block;
  120. height: 1.4rem;
  121. width: 0.2rem;
  122. background: #fff;
  123. // margin-right: 1.6rem;
  124. }
  125. // i {
  126. // float: right;
  127. // margin-top: 2rem;
  128. // }
  129. }
  130. }
  131. }
  132. .menuCon {
  133. overflow: hidden;
  134. // overflow: scroll;
  135. // width: 60rem;
  136. // min-height: 38rem;
  137. background: #fff;
  138. padding: 1.6rem;
  139. box-sizing: border-box;
  140. position: absolute;
  141. top: 0;
  142. bottom: 0;
  143. left: 100%;
  144. z-index: 99;
  145. display: none;
  146. width: 160px;
  147. padding: 0 20px;
  148. border: 1px solid #fd5522;
  149. .item {
  150. font-size: 1.2rem;
  151. color: #333;
  152. margin: 1rem 0;
  153. cursor: pointer;
  154. &.curr,
  155. &:hover {
  156. color: #fd5522;
  157. }
  158. }
  159. }
  160. }
  161. </style>