index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <template>
  2. <div class="index">
  3. <!-- 头部 -->
  4. <div class="head">
  5. <div class="menu">
  6. <span v-for="item in menu" :key="item.name" :class="item.name == currentMenu ? 'current' : ''" @click="menuClick(item)">
  7. <i :class="item.icon"></i> {{item.name}}
  8. </span>
  9. </div>
  10. <div class="user">
  11. <img :src="user.avatar" alt="">
  12. <p>{{hi}}</p>
  13. <span @click="logout"><i class="designer- designer-tuichu"></i> {{lang.logout}}</span>
  14. </div>
  15. </div>
  16. <!-- 内容区 -->
  17. <div class="content">
  18. <router-view />
  19. </div>
  20. </div>
  21. </template>
  22. <script>
  23. import global from '@/tools/global';
  24. export default {
  25. name: 'index',
  26. data (){
  27. return {
  28. lang: {},
  29. user: {},
  30. hi: '',
  31. menu: [],
  32. currentMenu: ''
  33. }
  34. },
  35. created (){
  36. // 多语言支持
  37. this.lang = this.$lang('index');
  38. this.menu = [
  39. {
  40. name: this.lang.menu.list,
  41. route: 'group',
  42. icon: 'el-icon-pie-chart'
  43. },
  44. {
  45. name: this.lang.menu.user,
  46. route: 'user',
  47. icon: 'el-icon-user'
  48. }
  49. ];
  50. this.currentMenu = this.lang.menu.default;
  51. },
  52. mounted (){
  53. // 获取用户信息
  54. this.user = JSON.parse(localStorage.getItem('designer_user'));
  55. this.user.avatar = global.host + this.user.avatar;
  56. if(this.user.role == 0){
  57. this.menu.push({
  58. name: this.lang.menu.team,
  59. route: 'team',
  60. icon: 'designer- designer-qunchengyuan-02'
  61. })
  62. }
  63. // 欢迎语
  64. if(this.user.role == 0){
  65. this.hi = `${this.lang.role.admin} ${this.user.user_name} ${this.lang.role.hi}`;
  66. }
  67. if(this.user.role == 1){
  68. this.hi = `${this.lang.role.designer} ${this.user.user_name} ${this.lang.role.hi}`;
  69. }
  70. if(this.user.role == 2){
  71. this.hi = `${this.lang.role.custom} ${this.user.user_name} ${this.lang.role.hi}`;
  72. }
  73. // 默认进入 group 路由
  74. if(this.$route.name == 'index'){
  75. this.$router.push('/group');
  76. }
  77. // 刷新时菜单高亮
  78. switch (this.$route.name){
  79. case 'list':
  80. this.currentMenu = this.lang.menu.list;
  81. break;
  82. case 'user':
  83. this.currentMenu = this.lang.menu.user;
  84. break;
  85. case 'team':
  86. this.currentMenu = this.lang.menu.team;
  87. break;
  88. }
  89. },
  90. methods: {
  91. // 切换菜单
  92. menuClick (item){
  93. this.currentMenu = item.name;
  94. this.$router.push(item.route);
  95. },
  96. // 退出登录
  97. logout (){
  98. let that = this;
  99. this.$confirm(this.lang.tips.logout.title, this.lang.tips.logout.t, {
  100. type: 'warning',
  101. cancelButtonText: this.lang.tips.logout.cancel,
  102. confirmButtonText: this.lang.tips.logout.confirm,
  103. beforeClose (action, instance, done){
  104. if(action == 'confirm'){
  105. that.$router.push('/login');
  106. localStorage.removeItem('designer_user');
  107. done();
  108. }else{
  109. done();
  110. }
  111. }
  112. }).catch(() => {});
  113. }
  114. }
  115. }
  116. </script>
  117. <style lang="less" scoped>
  118. @import url('../tools/common.less');
  119. .index{
  120. width: 100%;
  121. height: 100%;
  122. /* 头部 */
  123. .head{
  124. width: calc(100% - 60px);
  125. height: 60px;
  126. border-bottom: 1px solid rgb(236, 236, 236);
  127. padding: 0 30px;
  128. background: #ffffff;
  129. position: absolute;
  130. top: 0;
  131. left: 0;
  132. z-index: 3;
  133. display: flex;
  134. justify-content: space-between;
  135. align-items: center;
  136. .user{
  137. display: flex;
  138. justify-content: flex-start;
  139. align-items: center;
  140. img{
  141. width: 45px;
  142. height: 45px;
  143. border-radius: 50%;
  144. }
  145. p{
  146. margin-left: 20px;
  147. }
  148. span{
  149. margin-left: 30px;
  150. cursor: pointer;
  151. }
  152. }
  153. .menu{
  154. display: flex;
  155. justify-content: flex-end;
  156. align-items: center;
  157. span{
  158. display: block;
  159. padding: 0 15px;
  160. height: 58px;
  161. line-height: 60px;
  162. margin: 0 10px;
  163. cursor: pointer;
  164. user-select: none;
  165. border-bottom: 2px solid transparent;
  166. }
  167. span.current{
  168. color: @color;
  169. border-bottom: 2px solid rgb(126, 172, 250);
  170. }
  171. }
  172. }
  173. /* 内容区 */
  174. .content{
  175. width: 100%;
  176. height: calc(100% - 61px);
  177. position: absolute;
  178. top: 60px;
  179. left: 0;
  180. z-index: 1;
  181. }
  182. }
  183. </style>