HomePage.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <template>
  2. <el-container :class="getRole">
  3. <el-aside>
  4. <div class="logo">
  5. <p v-if="userLoginDTO&&userLoginDTO.type=='1'"><b>朗通后台管理系统</b></p>
  6. <p v-if="userLoginDTO&&userLoginDTO.type=='0'"><b>DiagbotCloud</b></p>
  7. <p v-if="userLoginDTO&&userLoginDTO.type=='0'"><b>后台管理系统</b></p>
  8. </div>
  9. <lt-menu v-if="menuWrappers&&menuWrappers.length" v-bind:role="getRole"
  10. v-bind:data="menuWrappers"></lt-menu>
  11. </el-aside>
  12. <el-container>
  13. <el-header class="clearfix">
  14. <div class="title fl">
  15. <h2>{{organization&&organization.name}}</h2>
  16. </div>
  17. <div class="userInfo fr">
  18. <span class="username" @click="goCenter">{{userLoginDTO&&userLoginDTO.linkman}}</span>
  19. <lt-badge v-if="getRole=='user'" class="green" :authStatus="authStatus">
  20. {{authStatusName}}
  21. </lt-badge>
  22. <el-button type="info" size="small" plain @click="logout">退出</el-button>
  23. </div>
  24. </el-header>
  25. <el-main>
  26. <router-view v-if="ok" v-on:status-change="changeStatus"></router-view>
  27. </el-main>
  28. </el-container>
  29. </el-container>
  30. </template>
  31. <script>
  32. import LtMenu from '../common/Menu.vue';
  33. import LtBadge from '@base/LtBadge.vue';
  34. import api from '@api/index.js';
  35. import userApi from '@api/user.js';
  36. import Console from '@components/user/Console.vue';
  37. export default {
  38. name: 'homepage',
  39. components: {
  40. 'lt-badge': LtBadge,
  41. 'lt-menu': LtMenu,
  42. 'console': Console
  43. },
  44. data: function () {
  45. return {
  46. menuWrappers: null,
  47. organization: null,
  48. userLoginDTO: null,
  49. authStatus: null,
  50. authStatusName:'',
  51. ok:false, //是否已获取到菜单
  52. }
  53. },
  54. computed: {
  55. getRole: function () {
  56. return this.userLoginDTO && this.userLoginDTO.type == '0' ? 'user' : 'admin';
  57. }
  58. },
  59. created () {
  60. //获取菜单
  61. this.getMenuList();
  62. },
  63. watch:{
  64. '$route': function(to,from){
  65. if(from.name=='login'){
  66. this.getMenuList();
  67. }
  68. if(to.path=='/'){ // 退出时清空菜单
  69. this.menuWrappers=[];
  70. }
  71. }
  72. },
  73. methods: {
  74. getMenuList(){
  75. api.getAccessdMenu().then((res) => {
  76. if (res.data.code == '0') {
  77. const data = res.data.data;
  78. this.ok = true;
  79. const hasConcole=data.menuWrappers.find((it)=>{
  80. return it.code.indexOf('-KZT')>-1;
  81. });
  82. //this.hasConcole = hasConcole!=-1;
  83. this.menuWrappers = data.menuWrappers;
  84. this.organization = data.organization;
  85. this.userLoginDTO = data.userLoginDTO;
  86. this.getRole=='user' && this.getAuthStatus();
  87. if(hasConcole){
  88. const url = this.getRole=='user'?'/user/YH-KZT':'/admin/LT-KZT';
  89. this.$router.push({path:url});
  90. }
  91. }
  92. }).catch((error) => {
  93. console.log(error);
  94. });
  95. },
  96. /*redirectPage(){
  97. const url = this.getRole=='user'?'/user':'/admin';
  98. this.$router.push({path:url});
  99. },*/
  100. changeStatus(text){ //账号信息中提交认证后修改状态
  101. this.authStatus = 2;
  102. this.authStatusName = text;
  103. },
  104. goCenter(){
  105. const url = this.getRole=='user'?'':'/admin/LT-GRZX';
  106. this.$router.push({path:url});
  107. },
  108. getAuthStatus() {
  109. //获取用户认证状态
  110. userApi.getUserAuthStatus().then((res) => {
  111. if (res.data.code == '0') {
  112. const data = res.data.data;
  113. // this.authStatus = data[0];
  114. this.authStatusName = data.authStatusName;
  115. this.authStatus = data.authStatus;
  116. }
  117. }).catch((error) => {
  118. console.log(error)
  119. });
  120. },
  121. logout(){//退出
  122. localStorage.removeItem('token');
  123. this.$router.push({path:'/'});
  124. }
  125. }
  126. }
  127. </script>
  128. <style lang="less">
  129. @import '../../less/common.less';
  130. .user .el-menu-item.is-active {
  131. color: @userBase;
  132. }
  133. .admin .el-menu-item.is-active {
  134. color: @adminBase;
  135. }
  136. .admin .username{
  137. cursor: pointer;
  138. }
  139. </style>
  140. <style lang="less" scoped>
  141. @import '../../less/common.less';
  142. .user .logo {
  143. background: @userBase;
  144. p {
  145. font-size: 16px;
  146. line-height: normal
  147. }
  148. }
  149. .admin .logo {
  150. background: @adminBase;
  151. p {
  152. font-size: 18px;
  153. line-height: 40px;
  154. }
  155. }
  156. .title {
  157. h2 {
  158. display: inline-block;
  159. line-height: 60px;
  160. font-size: 18px;
  161. }
  162. }
  163. .block {
  164. height: 40px;
  165. width: 100%;
  166. background: #fff;
  167. box-shadow: 0px 1px 2px #c9c9c9;
  168. }
  169. .el-main{
  170. padding: 0;
  171. }
  172. .el-button{
  173. margin-left: 15px;
  174. }
  175. </style>