IntroductionHeader.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template>
  2. <div >
  3. <div class="header1">
  4. <div class="header2">
  5. <div class="language">
  6. <span class="active" style="margin-left: 30px;">
  7. <span class="cursor" @click="locale('zh')">{{ $t('common.CN')}}</span>
  8. <span style="margin: 0 12px; display: inline-block; width: 2px; height: 12px; background: #ccc;vertical-align: middle;"></span>
  9. <span class="cursor" @click="locale('en')">EN</span>
  10. </span>
  11. <span class="active" style="float: right;">
  12. <span style="margin-right: 9px;" @click="toView('Register',{})" v-if="i==1">
  13. <img src="@/assets/注册.png" style="height: 12px;width: 12px;margin-right: 0px;vertical-align: middle;">
  14. {{ $t('common.register')}}
  15. </span>
  16. <span style="margin-right: 9px;" @click="toView('login',{})" v-if="i==1">
  17. <img src="@/assets/登录.png" style="height: 12px;width: 12px;margin-right: 0px;vertical-align: middle;">
  18. {{ $t('common.login')}}
  19. </span>
  20. <!-- <span style="margin-right: 9px;" v-if="i==2 || i==3">{{ $t('common.OngoingProject')}}(<span style="color: #ff0000;">0</span>)</span> -->
  21. <!-- <span style="margin-right: 9px;" v-if="i==2 || i==3">{{ $t('common.MyAttention')}}(<span style="color: #ff0000;">0</span>)</span>
  22. <span style="margin-right: 9px;" v-if="i==2 || i==3">{{ $t('common.MyCollection')}}</span> -->
  23. <i class="el-icon-s-custom" style="color: #fff;margin-right: 5px;" v-if="i==2 || i==3"></i>
  24. <el-dropdown trigger="click" @command="handleCommand" >
  25. <span style="margin-right: 9px; cursor:pointer" v-if="i==2 || i==3">
  26. {{ $t('common.Usercenter')}}
  27. <i class="el-icon-arrow-down"></i>
  28. <el-dropdown-menu slot="dropdown">
  29. <el-dropdown-item
  30. v-for="(item,index) in options"
  31. :command="item"
  32. >{{$t(item.label)}}</el-dropdown-item>
  33. </el-dropdown-menu>
  34. </span>
  35. </el-dropdown>
  36. <i class="el-icon-message-solid" style="margin-left: 15px;color: #fff;" v-if="i==2 || i==3"></i>
  37. <span v-if="i==2 || i==3" style="margin-left: 5px;">{{ $t('common.MessageNotification')}}(<span style="color: #ff0000;">0</span>)</span>
  38. <!-- <span style="margin-right: 9px;">{{ $t('common.CustomerService')}}</span> -->
  39. <!-- <span style="margin-right: 9px;">{{ $t('common.HelpCenter')}}</span> -->
  40. </span>
  41. </div>
  42. </div>
  43. </div>
  44. </div>
  45. </template>
  46. <script>
  47. import Bus from "@/api/bus"; //注意引入
  48. export default {
  49. name: 'IntroductionHeader',
  50. data () {
  51. return {
  52. i:'1',
  53. options: [{
  54. value: 'userCenterView',
  55. label: 'common.Usercenter',
  56. json:''
  57. }, {
  58. value: 'information',
  59. label: 'common.BasicInformation',
  60. json:'information'
  61. }, {
  62. value: 'authentication',
  63. label: 'common.Auth',
  64. json:'/authentication'
  65. }, {
  66. value: 'securitySetting',
  67. label: 'common.SecuritySettings',
  68. json:'/securitySetting'
  69. }, {
  70. value: 'loginOut',
  71. label: 'common.Logout',
  72. json:''
  73. }],
  74. }
  75. },
  76. watch:{
  77. '$i18n.locale'(){
  78. if(this.$i18n.locale=='en'&& this.$Cookies.get('token')){
  79. this.i=3
  80. }else if(this.$i18n.locale=='zh'&& this.$Cookies.get('token')){
  81. this.i=2
  82. }else {
  83. this.i=1
  84. }
  85. }
  86. },
  87. mounted(){
  88. let locale=window.localStorage.getItem('locale')
  89. if(!locale){
  90. window.localStorage.setItem('locale','en')
  91. }
  92. document.title = this.$t('common.GEIDcpTitleSeptember');
  93. let locales=window.localStorage.getItem('locale')
  94. this.$i18n.locale = locales
  95. console.log(window.localStorage.getItem('locale'),window.localStorage.getItem('userLogin'))
  96. //if (window.localStorage.getItem('userLogin')) {
  97. if (this.$Cookies.get('token') && this.$i18n.locale=='zh') {
  98. return this.i=2
  99. }else if(this.$i18n.locale=='en'&& this.$Cookies.get('token')){
  100. return this.i=3
  101. }else {
  102. return this.i=1
  103. }
  104. },
  105. methods:{
  106. locale(lang){
  107. this.$i18n.locale = lang
  108. let locale=window.localStorage.getItem('locale')
  109. if(locale){
  110. window.localStorage.setItem('locale',lang)
  111. }else {
  112. window.localStorage['locale'] = lang;
  113. }
  114. console.log(window.localStorage.getItem('locale'))
  115. },
  116. handleCommand(command){
  117. if(command.value=='loginOut'){
  118. this.loginOut()
  119. }else {
  120. this.toView(0,command.value,command.json)
  121. }
  122. },
  123. // 退出登录
  124. loginOut(){
  125. this.$confirm('此操作将退出登录, 是否继续?', '提示', {
  126. confirmButtonText: '确定',
  127. cancelButtonText: '取消',
  128. type: 'warning'
  129. }).then(() => {
  130. // 退出的逻辑代码
  131. this.$store
  132. .dispatch("user/LOGOUT")
  133. .then(() => {
  134. // location.href = "/";
  135. this.$router.push({
  136. path: "/login",
  137. });
  138. })
  139. .catch((error) => {
  140. location.href = "/";
  141. });
  142. // this.toView(2,'login','')// 返回登录
  143. // window.localStorage.removeItem('token')
  144. window.sessionStorage.removeItem("token");
  145. this.getInitData();
  146. })
  147. .catch(() => {
  148. this.$message({
  149. type: "info",
  150. message: "已取消",
  151. });
  152. });
  153. },
  154. toView(num, router, json) {
  155. this.$router.push({ name: router, query: { key: json } });
  156. // this.$store.state.router=router
  157. this.$store.commit("modify", router);
  158. // this.$router.push({name:'userCenterView'})
  159. // this.$store.state.router=router
  160. // this.$store.commit('modify', router)
  161. window.localStorage.setItem("router", router);
  162. if (num == 1) {
  163. let i = {
  164. label: "用户中心",
  165. value: "userCenterView",
  166. };
  167. if (this.$Cookies.get('token')) {
  168. return (this.i = 2);
  169. } else if (this.$i18n.locale == "en") {
  170. return (this.i = 3);
  171. } else {
  172. return (this.i = 1);
  173. }
  174. this.$nextTick(() => {
  175. Bus.$emit("title", i);
  176. });
  177. // this.BusChange(i)
  178. }
  179. }
  180. }
  181. }
  182. </script>
  183. <!-- Add "scoped" attribute to limit CSS to this component only -->
  184. <style scoped>
  185. body {
  186. margin: 0;
  187. padding: 0;
  188. }
  189. .header1 {
  190. width:100%;
  191. margin: auto;
  192. height: 70px;
  193. /* background: transparent; */
  194. background: rgba(50,75,116,.8);
  195. }
  196. .header2 {
  197. width:1200px;
  198. height: 70px;
  199. margin: auto;
  200. position: relative;
  201. /* background: url("../assets/img/home/banner.png") no-repeat; */
  202. }
  203. .language {
  204. line-height: 70px;
  205. color: #ccc;
  206. font-weight: 400;
  207. font-size: 14px;
  208. width:100%;
  209. /* background: rgba(50,75,116,.8); */
  210. }
  211. .logo {
  212. position: absolute;
  213. top: 50px;
  214. left: 80px;
  215. width: 260px;
  216. height: 55px;
  217. /* background-image: url(@/assets/logo.png); */
  218. }
  219. .title {
  220. position: absolute;
  221. top: 60px;
  222. left: 450px;
  223. font-size: 30px;
  224. font-weight: 700;
  225. color: #fff;
  226. }
  227. .active span:hover{
  228. color:#ff0000;
  229. cursor:pointer
  230. }
  231. .el-dropdown {
  232. color: #ccc;
  233. font-size: 12px;
  234. }
  235. </style>