123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309 |
- <template>
- <div>
- <div class="header1">
- <div class="header2">
- <div class="language">
- <span class="active">
- <span style="margin-left: 30px;" class="cursor" @click="locale('zh')">{{ $t('common.CN')}}</span>
- <span style="margin: 0 14px; display: inline-block; width: 2px; height: 14px; background: #F9F9F9"></span>
- <span style="margin-left: 9px;" class="cursor" @click="locale('en')">EN</span>
- </span>
- <span class="active" style="float: right;">
- <span
- style="margin-right: 9px;"
- @click="toView(2,'Register','')"
- v-if="i==1"
- >{{ $t('common.register')}}</span>
- <span
- style="margin-right: 9px;"
- @click="toView(2,'login','')"
- v-if="i==1"
- >{{ $t('common.login')}}</span>
- <!-- <span style="margin-right: 9px;" v-if="i==2 || i==3">
- {{ $t('common.OngoingProject')}}(
- <span style="color: #ff0000;">0</span>)
- </span> -->
- <el-dropdown trigger="click" @command="handleCommand">
- <span style="margin-right: 9px; cursor:pointer;color: #ccc;" v-if="i==2 || i==3">
- {{ $t('common.Usercenter')}}
- <i class="el-icon-arrow-down"></i>
- <el-dropdown-menu slot="dropdown">
- <el-dropdown-item
- v-for="(item,index) in options"
- :command="item"
- >{{$t(item.label)}}</el-dropdown-item>
- </el-dropdown-menu>
- </span>
- </el-dropdown>
- <span @click="toView(0,'SystemMessage','/SystemMessage')" style="margin-right: 9px;" v-if="i==2 || i==3">
- {{ $t('common.MessageNotification')}}(
- <span style="color: #ff0000;">{{systemMessageNum}}</span>)
- </span>
- <!-- <span style="margin-right: 9px;" v-if="i==2 || i==3">
- {{ $t('common.MyAttention')}}(
- <span style="color: #ff0000;">0</span>)
- </span> -->
- <!-- <span style="margin-right: 9px;" v-if="i==2 || i==3">{{ $t('common.MyCollection')}}</span> -->
- <!-- <span style="margin-right: 9px;" @click="toView(2,'customerService')">{{ $t('common.CustomerService')}}</span> -->
- <span
- style="margin-right: 9px;"
- @click="toView(2,'helpCenter')"
- >{{ $t('common.HelpCenter')}}</span>
- </span>
- </div>
- <div class="logo">
- <img
- :src="$i18n.locale=='zh'?require('@/assets/img/home/LOGO.png'):require('@/assets/img/home/GlobalEnergyInter.png')"
- alt
- :style="$i18n.locale=='zh'?'width: 836px;':'width:640px;transform:translateY(1px)'"
- />
- </div>
- <!-- <div class="title">
- GEIDCP 全球能源互联网发展合作平台
- </div>-->
- </div>
- </div>
- </div>
- </template>
- <script>
- import Bus from "@/api/bus"; //注意引入
- import {selectPushMsgNum} from '@/api/userCenter'
- // import Cookies from 'js-cookie'; //引入cookie操作依赖
- export default {
- name: 'Headers',
- data () {
- return {
- i:'1',
- systemMessageNum:0,
- options: [{
- value: 'userCenterView',
- label: 'common.Usercenter',
- json:''
- }, {
- value: 'information',
- label: 'common.BasicInformation',
- json:'information'
- }, {
- value: 'authentication',
- label: 'common.RealAuthentication',
- json:'/authentication'
- }, {
- value: 'securitySetting',
- label: 'common.SecuritySettings',
- json:'/securitySetting'
- }, {
- value: 'loginOut',
- label: 'common.Logout',
- json:''
- }],
- }
- },
- mounted() {
- this.getInitData();
- this.getMessageNum();
- },
- methods: {
- getMessageNum(){
- if(this.i !=1){
- let readStatus='unread'
- selectPushMsgNum(readStatus).then(res=>{
- if(res.data.page.totalCount>0){
- this.systemMessageNum = res.data.page.totalCount;
- }else{
- this.systemMessageNum = 0;
- }
- })
- }
- },
- getInitData() {
- let locale = window.localStorage.getItem("locale");
- if (!locale) {
- window.localStorage.setItem("locale", "en");
- }
- document.title = this.$t('common.GEIDcpTitleSeptember');
- this.$i18n.locale = locale;
- console.log(
- window.localStorage.getItem("locale"),
- window.localStorage.getItem("userLogin")
- );
- //if (window.localStorage.getItem('userLogin')) {
- if (this.$Cookies.get("token") && this.$i18n.locale == "zh") {
- return (this.i = 2);
- } else if (
- this.$i18n.locale == "en" && this.$Cookies.get("token")
- ) {
- return (this.i = 3);
- } else {
- return (this.i = 1);
- }
- },
- locale(lang) {
- this.$i18n.locale = lang;
- let locale = window.localStorage.getItem("locale");
- if (locale) {
- window.localStorage.setItem("locale", lang);
- } else {
- window.localStorage["locale"] = lang;
- }
- },
- getInitData(){
- let locale=window.localStorage.getItem('locale');
- let langdefaultLanguage = navigator.language||navigator.userLanguage;//常规浏览器语言和IE浏览器
- langdefaultLanguage = langdefaultLanguage.substr(0, 2);//截取lang前2位字符
- if(langdefaultLanguage !== 'zh'){
- langdefaultLanguage = 'en';
- }
- if(!locale){
- window.localStorage.setItem('locale',langdefaultLanguage)
- }
- this.$i18n.locale = locale
- console.log(window.localStorage.getItem('locale'),window.localStorage.getItem('userLogin'))
- //if (window.localStorage.getItem('userLogin')) {
- if (this.$Cookies.get('token') && this.$i18n.locale=='zh') {
- return this.i=2
- }else if(this.$i18n.locale=='en'&& this.$Cookies.get('token')){
- return this.i=3
- }else {
- return this.i=1
- }
- },
- locale(lang){
- this.$i18n.locale = lang
- let locale=window.localStorage.getItem('locale')
- if(locale){
- window.localStorage.setItem('locale',lang)
- }else {
- window.localStorage['locale'] = lang;
- }
- console.log(window.localStorage.getItem('locale'))
- },
- handleCommand(command){
- if(command.value=='loginOut'){
- this.loginOut()
- }else {
- this.toView(0,command.value,command.json)
- }
- },
- // 退出登录
- loginOut(){
- this.$confirm(this.$t('common.Thisoperationwilllogout')+'?', this.$t('common.Tips'), {
- confirmButtonText: this.$t('common.OK'),
- cancelButtonText: this.$t('common.cancel'),
- type: 'warning'
- }).then(() => {
- // 退出的逻辑代码
- this.$store
- .dispatch("user/LOGOUT")
- .then(() => {
- // location.href = "/";
- this.$router.push({
- path: "/login",
- });
- })
- .catch((error) => {
- location.href = "/";
- });
- // this.toView(2,'login','')// 返回登录
- // window.localStorage.removeItem('token')
- window.sessionStorage.removeItem("token");
- // Cookies.remove('login');
- this.getInitData();
- })
- .catch(() => {
- this.$message({
- type: "info",
- message: this.$t('common.Cancelled'),
- });
- });
- },
- toView(num, router, json) {
- this.$router.push({ name: router, query: { key: json } });
- // this.$store.state.router=router
- this.$store.commit("modify", router);
- // this.$router.push({name:'userCenterView'})
- // this.$store.state.router=router
- // this.$store.commit('modify', router)
- window.localStorage.setItem("router", router);
- if (num == 1) {
- let i = {
- label: "用户中心",
- value: "userCenterView",
- };
- if (window.sessionStorage.getItem("token")) {
- return (this.i = 2);
- } else if (this.$i18n.locale == "en") {
- return (this.i = 3);
- } else {
- return (this.i = 1);
- }
- this.$nextTick(() => {
- Bus.$emit("title", i);
- });
- // this.BusChange(i)
- }
- }
- },
- };
- </script>
- <!-- Add "scoped" attribute to limit CSS to this component only -->
- <style scoped>
- body {
- margin: 0;
- padding: 0;
- }
- .header1 {
- width: 100%;
- height: 120px;
- margin: auto;
- background: #2c558a;
- /* border-bottom: 2px solid #c2c2c2; */
- }
- .header2 {
- width: 1200px;
- height: 120px;
- margin: auto;
- position: relative;
- border-bottom: 1px solid #fff;
- background: url("../assets/img/home/banner.png") no-repeat;
- }
- .language {
- line-height: 12px;
- color: #F9F9F9;
- font-weight: 400;
- font-size: 16px;
- padding-top: 15px;
- }
- .logo {
- position: absolute;
- top: 50px;
- left: 80px;
- width: 260px;
- height: 55px;
- /* background-image: url(@/assets/logo.png); */
- }
- .title {
- position: absolute;
- top: 60px;
- left: 450px;
- font-size: 30px;
- font-weight: 700;
- color: #fff;
- }
- .active span:hover {
- color: #ff0000;
- cursor: pointer;
- }
- .el-dropdown {
- color:#F9F9F9;
- font-size: 16px;
- }
- </style>
|