Logo.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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="@/assets/images/logo.png" 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="@/assets/images/logo.png" 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. this.title = "LT云组态"
  54. } else {
  55. this.title = 'LT云组态';
  56. }
  57. if (data.deptLogo) {
  58. this.logo = this.baseUrl + data.deptLogo;
  59. } else {
  60. this.logo = logoImg;
  61. }
  62. });
  63. },
  64. },
  65. };
  66. </script>
  67. <style lang="scss" scoped>
  68. .sidebarLogoFade-enter-active {
  69. transition: opacity 1.5s;
  70. }
  71. .sidebarLogoFade-enter,
  72. .sidebarLogoFade-leave-to {
  73. opacity: 0;
  74. }
  75. .sidebar-logo-container {
  76. position: relative;
  77. // width: 100%;
  78. height: 50px;
  79. line-height: 50px;
  80. background: #2b2f3a;
  81. overflow: hidden;
  82. margin-top: 15px;
  83. width: 100%; /* 固定宽度 */
  84. overflow: hidden; /* 隐藏超出部分 */
  85. white-space: nowrap; /* 不换行 */
  86. & .sidebar-logo-link {
  87. height: 100%;
  88. width: 100%;
  89. display: flex !important;
  90. flex-direction: row !important;
  91. justify-content: center;
  92. align-items: center;
  93. & .sidebar-logo {
  94. width: 30px; // 30
  95. height: 30px; // 30
  96. vertical-align: middle;
  97. margin-right: 10px;
  98. }
  99. & .sidebar-title {
  100. display: inline-block;
  101. margin: 0;
  102. color: #fff;
  103. font-weight: 400;
  104. line-height: 50px;
  105. font-size: 18px; // 18
  106. font-family: '微软雅黑';
  107. vertical-align: middle;
  108. position: relative; /* 相对定位以便绝对定位子元素 */
  109. white-space: nowrap; // 防止换行
  110. overflow: hidden; // 隐藏溢出部分
  111. text-align: center;
  112. padding-left: 0 !important;
  113. }
  114. }
  115. &.collapse {
  116. .sidebar-logo {
  117. margin-right: 0px;
  118. width: 30px; // 30
  119. height: 30px; // 30
  120. }
  121. }
  122. }
  123. </style>