AppSidebar.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. // value:'citeList',
  87. // name:'表彰上传',
  88. // path:'/home/citeList',
  89. // icon:'icon-mall-zuorenwuzhuanjifen',
  90. // checked:false,
  91. // },
  92. ],
  93. employeeDynamics: false,
  94. pointsMall: false,
  95. welfareList: false,
  96. festiveEvents: false,
  97. isActive:false,
  98. };
  99. },
  100. methods:{
  101. removeTab(){
  102. removeTab();
  103. },
  104. getRoute(){
  105. var path = this.$route.path;
  106. this.sideBarList.forEach(item => {
  107. if(path.indexOf(item.value) != -1){
  108. item.checked = true;
  109. } else{
  110. item.checked = false;
  111. }
  112. });
  113. },
  114. // 保存滚动值,这是兼容的写法
  115. handleScroll () {
  116. var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
  117. if(scrollTop >= 80){
  118. this.isActive = true
  119. }else{
  120. this.isActive = false
  121. }
  122. },
  123. },
  124. watch: {
  125. $route:'getRoute'
  126. },
  127. created() {
  128. this.getRoute();
  129. },
  130. mounted () {
  131. window.addEventListener('scroll', this.handleScroll)
  132. },
  133. destroyed () {
  134. // 离开该页面需要移除这个监听的事件,不然会报错
  135. window.removeEventListener('scroll', this.handleScroll)
  136. }
  137. }
  138. </script>
  139. <style scoped>
  140. .index-nav{
  141. width: 180px;
  142. position: -webkit-sticky;
  143. position: sticky;
  144. top: 80px;
  145. margin-right: 20px;
  146. height: -webkit-fit-content;
  147. height: -moz-fit-content;
  148. height: fit-content;
  149. border-radius: 4px;
  150. background-color: #fff;
  151. max-height: calc(100vh - 101px);
  152. /* overflow-x: hidden; */
  153. }
  154. .index-nav-top{
  155. top: 20px;
  156. max-height: calc(100vh - 40px);
  157. }
  158. li a {
  159. font-weight: bold;
  160. color: #515767;
  161. }
  162. li a.router-link-active {
  163. color: #1e80ff;
  164. }
  165. .side-navigator-wrap{
  166. min-width: 180px;
  167. box-sizing: border-box;
  168. padding: 8px;
  169. font-size: 16px;
  170. color: #515767;
  171. }
  172. .nav-item-wrap{
  173. display: flex;
  174. flex-direction: column;
  175. }
  176. .nav-item-content{
  177. line-height: 24px;
  178. border-radius: 4px;
  179. cursor: pointer;
  180. display: flex;
  181. flex-direction: row;
  182. align-items: center;
  183. justify-content: space-between;
  184. }
  185. .active{
  186. background-color: #eaf2ff;
  187. color: #1e80ff;
  188. font-weight: 500
  189. }
  190. .nav-item{
  191. display: inline-block;
  192. width: 100%;
  193. box-sizing: border-box;
  194. position: relative;
  195. padding: 10px 17px;
  196. }
  197. .nav-item i{
  198. vertical-align: middle;
  199. margin-right: 12px;
  200. }
  201. .nav-item-text{
  202. vertical-align: middle;
  203. position: relative;
  204. }
  205. </style>