Logo.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <div class="sidebar-logo-container" :class="{ collapse: collapse }" :style="{ backgroundColor: sideTheme === 'theme-dark' ? variables.menuBackground : variables.menuLightBackground }">
  3. <transition name="sidebarLogoFade">
  4. <router-link v-if="collapse" key="collapse" class="sidebar-logo-link" to="/">
  5. <img v-if="logo" :src="logo" class="sidebar-logo" />
  6. <h1 v-else class="sidebar-title" :style="{ color: sideTheme === 'theme-dark' ? variables.logoTitleColor : variables.logoLightTitleColor }" style="padding-left: 10px">{{ title }}</h1>
  7. </router-link>
  8. <router-link v-else key="expand" class="sidebar-logo-link" to="/">
  9. <img v-if="logo" :src="logo" class="sidebar-logo" />
  10. <span class="sidebar-title" :style="{ color: sideTheme === 'theme-dark' ? variables.logoTitleColor : variables.logoLightTitleColor }" style="padding-left: 10px">{{ title }}</span>
  11. </router-link>
  12. </transition>
  13. </div>
  14. </template>
  15. <script>
  16. import logoImg from '@/assets/logo/logo.gif';
  17. import variables from '@/assets/styles/variables.scss';
  18. import { getDept } from '@/api/system/dept';
  19. export default {
  20. name: 'SidebarLogo',
  21. props: {
  22. collapse: {
  23. type: Boolean,
  24. required: true,
  25. },
  26. },
  27. computed: {
  28. variables() {
  29. return variables;
  30. },
  31. sideTheme() {
  32. return this.$store.state.settings.sideTheme;
  33. },
  34. },
  35. data() {
  36. return {
  37. title: '',
  38. logo: '',
  39. baseUrl: process.env.VUE_APP_BASE_API,
  40. };
  41. },
  42. mounted() {
  43. this.getDeptDetail();
  44. },
  45. methods: {
  46. //获取机构详情
  47. getDeptDetail() {
  48. const deptId = this.$store.state.user.dept.deptId;
  49. getDept(deptId).then((response) => {
  50. const data = response.data;
  51. if (data.logoName) {
  52. this.title = data.logoName.length > 8 ? data.logoName.slice(0, 8) : data.logoName;
  53. } else {
  54. this.title = 'FastBee';
  55. }
  56. if (data.deptLogo) {
  57. this.logo = this.baseUrl + data.deptLogo;
  58. } else {
  59. this.logo = logoImg;
  60. }
  61. });
  62. },
  63. },
  64. };
  65. </script>
  66. <style lang="scss" scoped>
  67. .sidebarLogoFade-enter-active {
  68. transition: opacity 1.5s;
  69. }
  70. .sidebarLogoFade-enter,
  71. .sidebarLogoFade-leave-to {
  72. opacity: 0;
  73. }
  74. .sidebar-logo-container {
  75. position: relative;
  76. // width: 100%;
  77. height: 50px;
  78. line-height: 50px;
  79. background: #2b2f3a;
  80. overflow: hidden;
  81. margin-top: 15px;
  82. width: 100%; /* 固定宽度 */
  83. overflow: hidden; /* 隐藏超出部分 */
  84. white-space: nowrap; /* 不换行 */
  85. & .sidebar-logo-link {
  86. height: 100%;
  87. width: 100%;
  88. display: flex !important;
  89. flex-direction: row !important;
  90. justify-content: center;
  91. align-items: center;
  92. & .sidebar-logo {
  93. width: 30px; // 30
  94. height: 30px; // 30
  95. vertical-align: middle;
  96. margin-right: 10px;
  97. }
  98. & .sidebar-title {
  99. display: inline-block;
  100. margin: 0;
  101. color: #fff;
  102. font-weight: 400;
  103. line-height: 50px;
  104. font-size: 18px; // 18
  105. font-family: '微软雅黑';
  106. vertical-align: middle;
  107. position: relative; /* 相对定位以便绝对定位子元素 */
  108. white-space: nowrap; // 防止换行
  109. overflow: hidden; // 隐藏溢出部分
  110. text-align: center;
  111. padding-left: 0 !important;
  112. }
  113. }
  114. &.collapse {
  115. .sidebar-logo {
  116. margin-right: 0px;
  117. }
  118. }
  119. }
  120. </style>