tangning %!s(int64=2) %!d(string=hai) anos
pai
achega
c99751caf3
Modificáronse 4 ficheiros con 21 adicións e 6 borrados
  1. 14 4
      src/components/Toast/Confirm.vue
  2. 1 0
      src/components/mobile/header.vue
  3. 3 1
      src/i18n/en.js
  4. 3 1
      src/i18n/zh.js

+ 14 - 4
src/components/Toast/Confirm.vue

@@ -1,3 +1,4 @@
+
 <template>
   <div class="xtx-confirm">
     <div class="wrapper" ref="target">
@@ -30,16 +31,16 @@
       </div>
       <div class="footer">
         <!-- <button @click="cancelCallback" size="mini" type="gray">取消</button> -->
-        <button @click="confirmCallback" size="mini" type="primary">{{t('confirm')}}</button>
+        <button @click="confirmCallback" size="mini" type="primary">{{confirm}}</button>
       </div>
     </div>
   </div>
 </template>
   
+
   <script lang="ts">
 // 注意:当前组件不是在 #app 下进行渲染,无法使用 #app 下的环境(全局组件,全局指令,原型属性函数)
 import { ref } from 'vue'
-import { useI18n } from 'vue-i18n'
 // import { onClickOutside } from '@vueuse/core'
 export default {
   name: 'showConfirm',
@@ -72,8 +73,17 @@ export default {
   },
   setup(props) {
     // 点击 target 目标元素外部相当于点击了取消
-    const { t } = useI18n()
     const target = ref(null)
+    let current = (localStorage && localStorage.getItem('language'))
+    if (!current) {
+      current = window.navigator.language || window.navigator.userLanguage || null
+        if (current && !/^zh/.test(current)) {
+            console.log('自动获取浏览器语言:' + current)
+            current = 'en'
+        }else{
+          current = 'zh'
+        }
+    }
     // onClickOutside(target, () => {
     //   props.cancelCallback()
     // })
@@ -84,7 +94,7 @@ export default {
       props.options.callback()
       props.close()
     }
-    return { options:props.options,target,confirmCallback,cancelCallback, t }
+    return { options:props.options,target,confirmCallback,cancelCallback,confirm:current=='en'?'confirm':'确认' }
   }
 }
 </script>

+ 1 - 0
src/components/mobile/header.vue

@@ -5,6 +5,7 @@ import logoCn from '@/assets/images/whietlogo.png'
 import logoEn from '@/assets/images/whietlogoEn.png'
 
 const {locale } = useI18n();
+console.log('locale',locale)
 </script>
 
 <template>

+ 3 - 1
src/i18n/en.js

@@ -1,5 +1,7 @@
 export default {
-    confirm: 'confirm',
+    confirm: {
+        text:'confirm'
+    },
     payInfo: {
       payErr: 'Payment Error',
       payfail: 'Payment Failed',

+ 3 - 1
src/i18n/zh.js

@@ -1,5 +1,7 @@
 export default {
-    confirm: '确认',
+    confirm: {
+        text:'确认'
+    },
     payInfo: {
         payErr: '支付异常',
         payfail: '支付失败',