diff --git a/src/App.vue b/src/App.vue index fc2aa58..fdfb453 100644 --- a/src/App.vue +++ b/src/App.vue @@ -19,6 +19,7 @@ import headers from './views/header/index' import MobileHerder from './views/header/mobile_herder' import footers from './views/footer/index' +import {setAppLanguage} from "@/utils/sist"; export default { name: 'App', @@ -31,9 +32,13 @@ export default { return { iftop: false, timer : true, + lang:'cn', width: document.documentElement.clientWidth >= 992 } }, + created() { + setAppLanguage(this) + }, mounted() { //监听scroll方法 window.addEventListener('scroll', this.handleScroll) diff --git a/src/assets/index/bottom/sy_icon_sjzx.png b/src/assets/index/bottom/sy_icon_sjzx.png index c0ea28b..e03d074 100644 Binary files a/src/assets/index/bottom/sy_icon_sjzx.png and b/src/assets/index/bottom/sy_icon_sjzx.png differ diff --git a/src/assets/index/bottom/sy_icon_sjzx@2x.png b/src/assets/index/bottom/sy_icon_sjzx@2x.png index c8919e5..2f35a34 100644 Binary files a/src/assets/index/bottom/sy_icon_sjzx@2x.png and b/src/assets/index/bottom/sy_icon_sjzx@2x.png differ diff --git a/src/i18n/i18n.js b/src/i18n/i18n.js index b54c9d4..9934760 100644 --- a/src/i18n/i18n.js +++ b/src/i18n/i18n.js @@ -5,10 +5,12 @@ import VueI18n from 'vue-i18n' import messages from './langs' Vue.use(VueI18n) + const i18n = new VueI18n({ locale: localStorage.lang || 'cn', messages }) + locale.i18n((key, value) => i18n.t(key, value)) //重点:为了实现element插件的多语言切换 export default i18n diff --git a/src/main.js b/src/main.js index 39bc577..2fe8f66 100644 --- a/src/main.js +++ b/src/main.js @@ -6,7 +6,11 @@ import i18n from './i18n/i18n' import ElementUI from 'element-ui'; import 'element-ui/lib/theme-chalk/index.css'; import 'element-ui/lib/theme-chalk/display.css'; +import en from 'element-ui/lib/locale/lang/en' +import cn from 'element-ui/lib/locale/lang/zh-CN' +i18n.mergeLocaleMessage('en', en) +i18n.mergeLocaleMessage('zh', cn) Vue.config.productionTip = false Vue.use(ElementUI) @@ -32,6 +36,9 @@ const store = new Vuex.Store({ } } }) + + + new Vue({ i18n, router, diff --git a/src/utils/request.js b/src/utils/request.js index 13c4e49..cc91795 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -1,6 +1,7 @@ import axios from 'axios' import {Notification, Message} from 'element-ui' import errorCode from '@/utils/errorCode' +import {setAppLanguage} from "@/utils/sist"; //todo 显示消息处理 @@ -16,6 +17,8 @@ const service = axios.create({ service.interceptors.request.use(config => { if (config.method == 'post') { config.data['sitetype'] = 'NEd5n92EMIpyyBslaNqsRgE'; + let lang = sessionStorage.getItem("lang"); + config.data['lang'] = lang; } return config }, error => { diff --git a/src/utils/sist.js b/src/utils/sist.js index f4cff90..c8ed759 100644 --- a/src/utils/sist.js +++ b/src/utils/sist.js @@ -39,3 +39,30 @@ export function getParentNode(id) { } } +export function setAppLanguage(that){ + let lang = sessionStorage.getItem("lang"); + if (lang != null){ + that.$i18n.locale = lang + return + } + var language = window.navigator.userLanguage || window.navigator.language; + if (language == 'zh-CN'){ + lang = 'cn' + }else { + lang = 'en' + } + that.$i18n.locale = lang + sessionStorage.setItem("lang",lang) +} +export function setLanguage(that){ + let lang = that.$route.query && that.$route.query.lang + if (lang != undefined){ + that.$i18n.locale = lang + sessionStorage.setItem("lang",lang) + } +} + + + + + diff --git a/src/views/Test.vue b/src/views/Test.vue index e4c81cf..fca69e7 100644 --- a/src/views/Test.vue +++ b/src/views/Test.vue @@ -1,13 +1,9 @@ - diff --git a/src/views/anchor.vue b/src/views/anchor.vue index b5d58f4..165a207 100644 --- a/src/views/anchor.vue +++ b/src/views/anchor.vue @@ -70,7 +70,7 @@ export default { // mousewheel事件中的 “event.wheelDelta” 属性值:返回的如果是正值说明滚轮是向上滚动 // DOMMouseScroll事件中的 “event.detail” 属性值:返回的如果是负值说明滚轮是向上滚动 let delta = event.detail || (-event.wheelDelta); - console.log(delta) + //console.log(delta) // 如果当前滚动开始时间和上次滚动结束时间的差值小于1.5s,则不执行翻页动作,这样做是为了实现类似节流的效果 if ((this.startTime - this.endTime) > 1) { if (delta > 0 && window.pageYOffset < window.innerHeight) { diff --git a/src/views/content/components/list.vue b/src/views/content/components/list.vue index 525ea13..1e3e8ed 100644 --- a/src/views/content/components/list.vue +++ b/src/views/content/components/list.vue @@ -103,9 +103,9 @@ export default { router="/" +this.value.navId+"?id="+context.id } if (this.width <=992){ - this.$router.push("/mobile/" + this.value.secondId +router); + this.$router.push("/mobile/" + this.value.secondId +router+"?lang="+sessionStorage.getItem("lang")); }else { - this.$router.push("/pc/" + this.value.secondId +router); + this.$router.push("/pc/" + this.value.secondId +router+"?lang="+sessionStorage.getItem("lang")); } }, handleSizeChange(val) { diff --git a/src/views/content/index.vue b/src/views/content/index.vue index a2fc92d..5d2c952 100644 --- a/src/views/content/index.vue +++ b/src/views/content/index.vue @@ -49,7 +49,7 @@
- {{ $t('message.home') }} + {{ $t('message.home') }} > {{ crumbs.one.title }} @@ -128,7 +128,7 @@ import DireData from './components/dire_data.vue' import Details from './components/details.vue' import FileList from './components/file_list.vue' import {handleTree} from "@/utils/ebts"; -import {getParentNode} from "@/utils/sist"; +import {getParentNode, setLanguage} from "@/utils/sist"; export default { name: "index", @@ -166,7 +166,6 @@ export default { this.navId = this.$route.params && this.$route.params.navId; let id = this.$route.params && this.$route.params.secondId this.type = this.$route.query && this.$route.query.type - console.log("触发了 $route") if (this.type == 3 || this.type == 1 || this.type == 2) { this.secondId = id this.showSecond = false @@ -203,6 +202,7 @@ export default { } }, created() { + setLanguage(this) this.secondId = this.$route.params && this.$route.params.secondId; this.navId = this.$route.params && this.$route.params.navId; this.type = this.$route.query && this.$route.query.type @@ -312,7 +312,7 @@ export default { //if (index != this.showIndex) { this.showIndex = index this.type = nav.type - this.$router.push("/pc/" + this.secondId + "/" + nav.encodeId); + this.$router.push("/pc/" + this.secondId + "/" + nav.encodeId+"?lang="+sessionStorage.getItem("lang")); //this.getContent(nav) //} } diff --git a/src/views/header/index.vue b/src/views/header/index.vue index 7bef319..05b239c 100644 --- a/src/views/header/index.vue +++ b/src/views/header/index.vue @@ -47,10 +47,10 @@