Bläddra i källkod

首页双语切换功能完成

sys 3 år sedan
förälder
incheckning
1ac2978f21
3 ändrade filer med 98 tillägg och 7 borttagningar
  1. 92 7
      pages/index/index.vue
  2. 4 0
      static/img/index/cn-no.svg
  3. 2 0
      static/img/index/en-no.svg

+ 92 - 7
pages/index/index.vue

@@ -5,8 +5,23 @@
           <view class="logo-img">
             <image src="/static/img/index/index-logo.png" mode="aspectFit"></image>
           </view>
-          <view class="logo-lang">
-            <image src="/static/img/index/en.svg" mode="aspectFit"></image>
+          <view class="logo-lang" @click="setShowLang">
+            <image v-if="applicationLocale==='en'" src="/static/img/index/en.svg" mode="aspectFit"></image>
+            <image v-else src="/static/img/index/cn.svg" mode="aspectFit"></image>
+            <view class="lang-list" @click.stop v-show="showLang">
+              <view class="lang-item" @click.stop="onLocaleChange('en')" :class="{'lang-item-option':applicationLocale==='en'}">
+                <image class="image-ok" src="/static/img/index/en.svg" mode="aspectFit"></image>
+                <image class="image-no" src="/static/img/index/en-no.svg" mode="aspectFit"></image>
+                <view class="item-vertical"></view>
+                <view class="item-str">English</view>
+              </view>
+              <view class="lang-item"  @click.stop="onLocaleChange('zh-Hans')" :class="{'lang-item-option':applicationLocale==='zh-Hans'}">
+                <image class="image-ok" src="/static/img/index/cn.svg" mode="aspectFit"></image>
+                <image  class="image-no" src="/static/img/index/cn-no.svg" mode="aspectFit"></image>
+                <view class="item-vertical"></view>
+                <view class="item-str">简体中文</view>
+              </view>
+            </view>
           </view>
         </view>
         <view class="top-name">
@@ -66,7 +81,7 @@
             <view><image class="title-img" mode="aspectFit" src="/static/img/index/a.png"></image></view>
             <view class="title-str">{{$t('index.index.transaction')}}</view>
           </view>
-          <view class="title-all">{{$t('index.index.affirm')}}>></view>
+          <view class="title-all">{{$t('index.index.all')}}>></view>
         </view>
         <view class="list-tab">
           <view class="tab-items">
@@ -94,8 +109,9 @@
 		},
 		data() {
 			return {
+        applicationLocale:'',
         systemLocale:'',
-        applicationLocale: '',
+        showLang:false,
         optionNum:1,
         listTab:1
       }
@@ -105,14 +121,20 @@
 
 		},
     onLoad(query) {
-
+      this.applicationLocale = uni.getLocale();
     },
     mounted() {
 
 		},
 		methods: {
-      onLocaleChange(){
-
+      setShowLang(){
+        this.showLang=true
+      },
+      onLocaleChange(code){
+        uni.setLocale(code);
+        this.$i18n.locale = code;
+        this.applicationLocale = code;
+        this.showLang=false
       },
       setOptionType(optionNum){
         if(this.optionNum!==optionNum){
@@ -158,11 +180,74 @@
         background: rgba(241,134,134,.04);
         border-radius: 12px;
         border: 1px solid hsla(0,0%,100%,.2);
+        position: relative;
         image{
           margin: 0 5px;
           height: 35px;
           width: 32px;
         }
+        .lang-list{
+          padding: 0 10px;
+          position: absolute;
+          top: 45px;
+          right: 0;
+          height: 100px;
+          word-break: keep-all;
+          background: #f6f9ff;
+          border-radius: 13px;
+          border: 1px solid rgba(39,127,250,.64);
+          z-index: 99;
+          .lang-item{
+            height: 42px;
+            padding: 0 10px;
+            margin: 5px 0;
+            border-radius: 9px;
+            display: flex;
+            justify-content: left;
+            cursor: pointer;
+            font-size: 18px;
+            image{
+              margin-top: 6px;
+              width: 30px;
+              height: 30px;
+            }
+            .image-ok{
+              display: none;
+            }
+            .image-no{
+              display: block;
+            }
+            .item-vertical{
+              height: 20px;
+              width: 1px;
+              margin: 11px 5px 0 5px;
+              background: #277ffa;
+            }
+            .item-str{
+              color: #277ffa;
+              cursor: pointer;
+              font-size: 18px;
+              line-height: 42px;
+              text-align: left;
+              margin-left: 5px;
+            }
+          }
+          .lang-item-option{
+            background: #277ffa;
+            .image-ok{
+              display: block;
+            }
+            .image-no{
+              display: none;
+            }
+            .item-vertical{
+              background: #fff;
+            }
+            .item-str{
+              color: #fff;
+            }
+          }
+        }
       }
     }
     .top-name{

+ 4 - 0
static/img/index/cn-no.svg

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg  viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" width="200" height="200" class="icon">
+    <path  d="M404.0192 686.848l13.44-57.7024h-185.6l21.5808-91.9808 13.44-57.6768 20.992-89.0112h182.1184L483.4048 332.8H224.256L140.8 686.848zM555.1872 686.848l52.5312-221.2864 107.9808 221.2608h65.3824L864.512 332.8h-77.056l-51.9424 221.7728L626.9952 332.8h-65.3824l-83.456 354.048z" fill="#277ffa" ></path>
+</svg>

+ 2 - 0
static/img/index/en-no.svg

@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg data-v-c61c55b0=""  viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"  width="200" height="200" class="icon"><path  d="M404.0192 686.848l13.44-57.7024h-185.6l21.5808-91.9808h157.0048l13.44-57.6768h-157.0048l20.992-89.0112h182.1184L483.4048 332.8H224.256L140.8 686.848zM555.1872 686.848l52.5312-221.2864 107.9808 221.2608h65.3824L864.512 332.8h-77.056l-51.9424 221.7728L626.9952 332.8h-65.3824l-83.456 354.048z" fill="#277ffa" ></path></svg>