Logo.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <div class="sidebar-logo-container" :class="{'collapse':collapse}" style="height: 70px" :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 }">{{ title }} </h1>-->
  7. <!--</router-link>-->
  8. <router-link key="expand" class="sidebar-logo-link" to="/">
  9. <img v-if="logo" :src="logo" style="width: 100%; margin-right: 81px;height: 100%;"/>
  10. <h1 class="sidebar-title" style="margin-left:-40px;" :style="{ color: sideTheme === 'theme-dark' ? variables.logoTitleColor : variables.logoLightTitleColor}"></h1>
  11. </router-link>
  12. </transition>
  13. </div>
  14. </template>
  15. <script>
  16. import logoImg from '@/assets/logo/logo.png'
  17. import Cookies from "js-cookie";
  18. import variables from '@/assets/styles/variables.scss'
  19. import { changeLanguages,systemConfiguration,equipmentMintenance } from "@/api/pdu/pduServer";
  20. export default {
  21. name: 'SidebarLogo',
  22. props: {
  23. collapse: {
  24. type: Boolean,
  25. required: true
  26. }
  27. },
  28. computed: {
  29. variables() {
  30. return variables;
  31. },
  32. sideTheme() {
  33. return this.$store.state.settings.sideTheme
  34. }
  35. },
  36. data() {
  37. return {
  38. title: this.$i18n.t('loginFormTitle'),
  39. logo: "",
  40. language:[
  41. {"key":"zh-CN","value":"简体中文","id":"1"},
  42. // {"key":"zh-TW","value":"繁體中文"},
  43. {"key":"en-US","value":"English","id":"2"},
  44. {"key":"ru-RU","value":"俄语","id":"3"}
  45. ],
  46. }
  47. },
  48. created() {
  49. this.systemConfiguration();
  50. },
  51. methods: {
  52. // 获取系统配置
  53. systemConfiguration(){
  54. systemConfiguration({}).then(response => {
  55. if(response.data!=null){
  56. if(response.data.logo!='' &&response.data.logo!=undefined && response.data.logo!=null ){
  57. this.logo=response.data.logo;
  58. }
  59. var data=response.data;
  60. var webSocket=data.webSocket;
  61. var systemLanguage=data.systemLanguage;
  62. let language = Cookies.get("flowinnIotLanguage");
  63. if(systemLanguage!='' && systemLanguage!=null){
  64. for (var i = 0; i < this.language.length; i++) {
  65. let item = this.language[i]
  66. if (systemLanguage== item.id) {
  67. let cookieslanguage = Cookies.get("flowinnIotLanguage");
  68. if(cookieslanguage!=item.key){
  69. // 用户修改了显示语言,重新设置语言
  70. this.chooseLanguage = item.key;
  71. // 临时保存到cookies中,后面由具体的方法去处理
  72. Cookies.set("flowinnIotLanguage", this.chooseLanguage,{ expires: 3000 });
  73. this.setWebLanguage();
  74. window.location.reload();
  75. }
  76. }
  77. }
  78. }else{
  79. this.setWebLanguage();
  80. }
  81. }
  82. });
  83. },
  84. setWebLanguage(){
  85. // cookies中是刚才用户选择的语言
  86. let language = Cookies.get("flowinnIotLanguage");
  87. if(language != null && language != "" && language != undefined){
  88. this.chooseLanguage = language;
  89. }else{
  90. // 如果cookies中没有,说明用户第一次打开系统,直接获取系统的语言
  91. let systemLanguage = (navigator.language || navigator.userLanguage).substring(0, 2);
  92. if(systemLanguage != null && systemLanguage != "" && systemLanguage != undefined){
  93. // 这里获取到的是zh和es,不是zh-CN需要单独处理
  94. this.chooseLanguage = systemLanguage;
  95. }
  96. }
  97. if(this.chooseLanguage == "zh" || this.chooseLanguage == "zh-CN"){
  98. this.chooseLanguage = "zh-CN";
  99. }else if(this.chooseLanguage == "zh-TW"){
  100. this.chooseLanguage = "zh-TW";
  101. }else if(this.chooseLanguage == "ru-RU"){
  102. this.chooseLanguage = "ru-RU";
  103. }else{
  104. this.chooseLanguage = "en-US";
  105. }
  106. var time = new Date().getTime();
  107. // 设置一个3年的有效期
  108. let timeNum = time + (3 * 365 * 24 * 60 * 60);
  109. Cookies.set("flowinnIotLanguage", this.chooseLanguage,{ expires: timeNum });
  110. // 保存到全局变量中,后面可以使用
  111. localStorage.setItem("language", this.chooseLanguage);
  112. // 页面刷新语言进行显示
  113. this.$i18n.locale = this.chooseLanguage;
  114. // 修改页面标题
  115. document.title = (this.$i18n.t('loginFormTitle')).replace("PDU","");
  116. },
  117. }
  118. }
  119. </script>
  120. <style lang="scss" scoped>
  121. .sidebarLogoFade-enter-active {
  122. transition: opacity 1.5s;
  123. }
  124. .sidebarLogoFade-enter,
  125. .sidebarLogoFade-leave-to {
  126. opacity: 0;
  127. }
  128. .sidebar-logo-container {
  129. position: relative;
  130. width: 100%;
  131. height: 50px;
  132. line-height: 50px;
  133. background: #2b2f3a;
  134. text-align: center;
  135. overflow: hidden;
  136. & .sidebar-logo-link {
  137. height: 100%;
  138. width: 100%;
  139. & .sidebar-logo {
  140. width: 32px;
  141. height: 32px;
  142. vertical-align: middle;
  143. margin-right: 12px;
  144. }
  145. & .sidebar-title {
  146. display: inline-block;
  147. margin: 0;
  148. color: #fff;
  149. font-weight: 600;
  150. line-height: 50px;
  151. font-size: 14px;
  152. font-family: Avenir, Helvetica Neue, Arial, Helvetica, sans-serif;
  153. vertical-align: middle;
  154. }
  155. }
  156. &.collapse {
  157. .sidebar-logo {
  158. margin-right: 0px;
  159. }
  160. }
  161. }
  162. </style>