Browse Source

首页语言包功能完成

sys 3 years ago
parent
commit
982295f2c9
6 changed files with 79 additions and 45 deletions
  1. 17 0
      locale/en.json
  2. 6 0
      locale/index.js
  3. 17 0
      locale/zh-Hans.json
  4. 15 1
      main.js
  5. 4 34
      pages.json
  6. 20 10
      pages/index/index.vue

+ 17 - 0
locale/en.json

@@ -0,0 +1,17 @@
+{
+  "locale.auto": "System",
+  "locale.en": "English",
+  "locale.zh-hans": "简体中文",
+  "title.index": "Home",
+  "title.login.index": "Login",
+  "title.login.register": "Register",
+  "title.index.error": "Error...",
+  "index.index.investment": "Investment",
+  "index.index.after": "After voting",
+  "index.index.money": "balance",
+  "index.index.affirm": "affirm",
+  "index.index.all": "all",
+  "index.index.transaction": "trading record",
+  "index.index.team": "team",
+  "index.index.code": "code"
+}

+ 6 - 0
locale/index.js

@@ -0,0 +1,6 @@
+import en from './en.json'
+import zhHans from './zh-Hans.json'
+export default {
+	en,
+	'zh-Hans': zhHans
+}

+ 17 - 0
locale/zh-Hans.json

@@ -0,0 +1,17 @@
+{
+	"locale.auto": "系统",
+	"locale.en": "English",
+	"locale.zh-hans": "简体中文",
+	"title.index": "首页",
+	"title.login.index": "登陆",
+	"title.login.register": "注册",
+	"title.index.error": "出错啦...",
+	"index.index.investment": "投资",
+	"index.index.after": "复投",
+	"index.index.money": "余额",
+	"index.index.affirm": "确认",
+	"index.index.all": "更多",
+	"index.index.transaction": "交易记录",
+	"index.index.team": "我的团队",
+	"index.index.code": "推荐码"
+}

+ 15 - 1
main.js

@@ -1,5 +1,13 @@
 import '.env.js'
 import App from './App'
+//引入语言包
+import messages from './locale/index'
+
+console.log(messages)
+let i18nConfig = {
+	locale: uni.getLocale(),
+	messages
+}
 //引入前置路由颜值
 import {
 	router,
@@ -10,11 +18,14 @@ Vue.use(router)
 import Vue from 'vue'
 import store from './store'
 import Nav from './components/en-utils/en-nav/en-nav.vue'
-
+import VueI18n from 'vue-i18n'
+Vue.use(VueI18n)
+const i18n = new VueI18n(i18nConfig)
 Vue.component('Nav', Nav)
 Vue.config.productionTip = false
 App.mpType = 'app'
 const app = new Vue({
+	i18n,
 	...App,
 	store
 })
@@ -35,8 +46,11 @@ app.$mount(); //为了兼容小程序及app端必须这样写才有效果
 import {
 	createSSRApp
 } from 'vue'
+import { createI18n } from 'vue-i18n'
+const i18n = createI18n(i18nConfig)
 export function createApp() {
 	const app = createSSRApp(App)
+	app.use(i18n)
 	return {
 		app,
 	}

+ 4 - 34
pages.json

@@ -4,55 +4,25 @@
 		{
 			"path": "pages/login/index",
 			"style": {
-				"navigationBarTitleText": "首页"
+				"navigationBarTitleText": "%title.login.index"
 			}
 		},
 		{
 			"path": "pages/index/index",
 			"style": {
-				"navigationBarTitleText": "首页"
-			}
-		},
-		{
-			"path": "pages/contract/add",
-			"style": {
-				"navigationBarTitleText": "投资"
-			}
-		},
-		{
-			"path": "pages/icon/index",
-			"style": {
-				"navigationBarTitleText": "资产"
-			}
-		},
-		{
-			"path": "pages/msg/index",
-			"style": {
-				"navigationBarTitleText": "留言"
-			}
-		},
-		{
-			"path": "pages/my/index",
-			"style": {
-				"navigationBarTitleText": "我的"
+				"navigationBarTitleText": "%title.index"
 			}
 		},
 		{
 			"path": "pages/login/register",
 			"style": {
-				"navigationBarTitleText": "注册"
+				"navigationBarTitleText": "%title.login.register"
 			}
 		},
 		{
 			"path": "pages/index/error",
 			"style": {
-				"navigationBarTitleText": "出错啦..."
-			}
-		},
-		{
-			"path": "pages/text/index",
-			"style": {
-				"navigationBarTitleText": "列表演示"
+				"navigationBarTitleText": "%title.index.error"
 			}
 		}
 	],

+ 20 - 10
pages/index/index.vue

@@ -17,14 +17,14 @@
       <view class="index-from">
         <view class="from-data">
           <view class="from-tab">
-            <view class="tab-item" :class="{'option-tab':optionNum===1}" >
-              <view class="item-content">投资</view>
+            <view class="tab-item" @click="setOptionType(1)" :class="{'option-tab':optionNum===1}" >
+              <view class="item-content">{{$t('index.index.investment')}}</view>
               <view class="item-img img-left">
                 <image src="/static/img/index/left.png" mode="heightFix"></image>
               </view>
             </view>
-            <view class="tab-item" :class="{'option-tab':optionNum===2}" >
-              <view class="item-content">复投</view>
+            <view class="tab-item" @click="setOptionType(2)" :class="{'option-tab':optionNum===2}" >
+              <view class="item-content">{{$t('index.index.after')}}</view>
               <view class="item-img img-right">
                 <image src="/static/img/index/right.png" mode="heightFix"></image>
               </view>
@@ -43,7 +43,7 @@
               <view class="from-between"></view>
             <view class="from-input">
               <view class="input-data">
-                <view class="data-money">余额:0</view>
+                <view class="data-money">{{$t('index.index.money')}}:0</view>
                 <view class="data-input">
                   <view>
                     <input type="number">
@@ -54,7 +54,7 @@
               </view>
             </view>
             <view class="from-but">
-              <button>确认</button>
+              <button>{{$t('index.index.affirm')}}</button>
             </view>
           </view>
 
@@ -64,15 +64,15 @@
         <view class="list-title">
           <view class="title-data">
             <view><image class="title-img" mode="aspectFit" src="/static/img/index/a.png"></image></view>
-            <view class="title-str">交易记录</view>
+            <view class="title-str">{{$t('index.index.transaction')}}</view>
           </view>
-          <view class="title-all">更多>></view>
+          <view class="title-all">{{$t('index.index.affirm')}}>></view>
         </view>
         <view class="list-tab">
           <view class="tab-items">
             <view class="tab-item" @click="setListTab(1)"  :class="{'option-tab':listTab===1}">NFT</view>
-            <view class="tab-item" @click="setListTab(2)" :class="{'option-tab':listTab===2}">我的团队</view>
-            <view class="tab-item" @click="setListTab(3)" :class="{'option-tab':listTab===3}">推荐码</view>
+            <view class="tab-item" @click="setListTab(2)" :class="{'option-tab':listTab===2}">{{$t('index.index.team')}}</view>
+            <view class="tab-item" @click="setListTab(3)" :class="{'option-tab':listTab===3}">{{$t('index.index.code')}}</view>
           </view>
           <view class="tab-item-bg" :class="{'bg-location-1':listTab===1,'bg-location-2':listTab===2,'bg-location-3':listTab===3}"></view>
         </view>
@@ -94,6 +94,8 @@
 		},
 		data() {
 			return {
+        systemLocale:'',
+        applicationLocale: '',
         optionNum:1,
         listTab:1
       }
@@ -109,6 +111,14 @@
 
 		},
 		methods: {
+      onLocaleChange(){
+
+      },
+      setOptionType(optionNum){
+        if(this.optionNum!==optionNum){
+          this.optionNum=optionNum
+        }
+      },
       setListTab(listTab){
         if(this.listTab!==listTab){
           this.listTab=listTab