AppSidebar.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <div class="index-nav" :class="{'index-nav-top':isActive}">
  3. <nav class="side-navigator-wrap">
  4. <div v-for="(item,index) in sideBarList" :key="index" class="nav-item-wrap">
  5. <div @click="removeTab" class="nav-item-content" :class="{ active: item.checked }">
  6. <router-link :to="item.path" class="nav-item">
  7. <i :class="item.icon"></i>
  8. <span class="nav-item-text">{{ item.name }}</span>
  9. </router-link>
  10. </div>
  11. </div>
  12. </nav>
  13. </div>
  14. </template>
  15. <script>
  16. import { removeTab } from '@/utils/auth'
  17. export default {
  18. name: 'AppSidebar',
  19. data() {
  20. return {
  21. sideBarList:[
  22. {
  23. value:'pointsMall',
  24. name:'积分商城',
  25. path:'/home/pointsMall',
  26. icon:'icon-mall-jifenshangcheng',
  27. checked:false,
  28. },
  29. {
  30. value:'index',
  31. name:'最新通知',
  32. path:'/home/index',
  33. icon:'icon-mall-tongzhi',
  34. checked:false,
  35. },
  36. {
  37. value:'signIn',
  38. name:'每日签到',
  39. path:'/home/signIn',
  40. icon:'icon-mall-qiandao',
  41. checked:false,
  42. },
  43. {
  44. value:'festiveEvents',
  45. name:'节日活动',
  46. path:'/home/festiveEvents',
  47. icon:'icon-mall-huodong',
  48. checked:false,
  49. },
  50. // {
  51. // value:'myMedal',
  52. // name:'我的勋章',
  53. // path:'/home/myMedal',
  54. // icon:'icon-mall-xunzhang',
  55. // checked:false,
  56. // },
  57. {
  58. value:'commend',
  59. name:'员工表彰',
  60. path:'/home/commend',
  61. icon:'icon-mall-xunzhang',
  62. checked:false,
  63. },
  64. {
  65. value:'welfareList',
  66. name:'福利领取',
  67. path:'/home/welfareList',
  68. icon:'icon-mall-hongbao',
  69. checked:false,
  70. },
  71. {
  72. value:'myCenter',
  73. name:'个人中心',
  74. path:'/home/myCenter',
  75. icon:'icon-mall-gerenzhongxin',
  76. checked:false,
  77. },
  78. {
  79. value:'earnPoints',
  80. name:'积分获取',
  81. path:'/home/earnPoints',
  82. icon:'icon-mall-zuorenwuzhuanjifen',
  83. checked:false,
  84. },
  85. ],
  86. employeeDynamics: false,
  87. pointsMall: false,
  88. welfareList: false,
  89. festiveEvents: false,
  90. isActive:false,
  91. };
  92. },
  93. methods:{
  94. removeTab(){
  95. removeTab();
  96. },
  97. getRoute(){
  98. var path = this.$route.path;
  99. this.sideBarList.forEach(item => {
  100. if(path.indexOf(item.value) != -1){
  101. item.checked = true;
  102. } else{
  103. item.checked = false;
  104. }
  105. });
  106. },
  107. // 保存滚动值,这是兼容的写法
  108. handleScroll () {
  109. var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
  110. if(scrollTop >= 80){
  111. this.isActive = true
  112. }else{
  113. this.isActive = false
  114. }
  115. },
  116. },
  117. watch: {
  118. $route:'getRoute'
  119. },
  120. created() {
  121. this.getRoute();
  122. },
  123. mounted () {
  124. window.addEventListener('scroll', this.handleScroll)
  125. },
  126. destroyed () {
  127. // 离开该页面需要移除这个监听的事件,不然会报错
  128. window.removeEventListener('scroll', this.handleScroll)
  129. }
  130. }
  131. </script>
  132. <style scoped>
  133. .index-nav{
  134. width: 180px;
  135. position: -webkit-sticky;
  136. position: sticky;
  137. top: 80px;
  138. margin-right: 20px;
  139. height: -webkit-fit-content;
  140. height: -moz-fit-content;
  141. height: fit-content;
  142. border-radius: 4px;
  143. background-color: #fff;
  144. max-height: calc(100vh - 101px);
  145. /* overflow-x: hidden; */
  146. }
  147. .index-nav-top{
  148. top: 20px;
  149. max-height: calc(100vh - 40px);
  150. }
  151. li a {
  152. font-weight: bold;
  153. color: #515767;
  154. }
  155. li a.router-link-active {
  156. color: #1e80ff;
  157. }
  158. .side-navigator-wrap{
  159. min-width: 180px;
  160. box-sizing: border-box;
  161. padding: 8px;
  162. font-size: 16px;
  163. color: #515767;
  164. }
  165. .nav-item-wrap{
  166. display: flex;
  167. flex-direction: column;
  168. }
  169. .nav-item-content{
  170. line-height: 24px;
  171. border-radius: 4px;
  172. cursor: pointer;
  173. display: flex;
  174. flex-direction: row;
  175. align-items: center;
  176. justify-content: space-between;
  177. }
  178. .active{
  179. background-color: #eaf2ff;
  180. color: #1e80ff;
  181. font-weight: 500
  182. }
  183. .nav-item{
  184. display: inline-block;
  185. width: 100%;
  186. box-sizing: border-box;
  187. position: relative;
  188. padding: 10px 17px;
  189. }
  190. .nav-item i{
  191. vertical-align: middle;
  192. margin-right: 12px;
  193. }
  194. .nav-item-text{
  195. vertical-align: middle;
  196. position: relative;
  197. }
  198. </style>