duoyuyan.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <view class="contentV">
  3. <customNav :shownav="true" title="Ngôn ngữ/语言" tinColor="#40AE36" jiantou="0"></customNav>
  4. <view class="itemView" @click="yuyanxuanze(3)">
  5. <text class="textstye">Tiếng Việt</text>
  6. </view>
  7. <view class="itemView" @click="yuyanxuanze(2)">
  8. <text class="textstye">繁體中文</text>
  9. </view>
  10. <view class="itemView" @click="yuyanxuanze(1)">
  11. <text class="textstye">简体中文</text>
  12. </view>
  13. <!-- <view class="itemView" @click="yuyanxuanze(4)">
  14. <text class="textstye">{{$t('locale.en')}}</text>
  15. </view> -->
  16. </view>
  17. </template>
  18. <script>
  19. import {
  20. changeLanguages,
  21. } from '@/pages/api/basic';
  22. export default {
  23. data() {
  24. return {
  25. index:0,
  26. systemLocale: '',
  27. applicationLocale: '',
  28. isAndroid:false
  29. }
  30. },
  31. onLoad() {
  32. let systemInfo = uni.getSystemInfoSync();
  33. this.systemLocale = systemInfo.language;
  34. this.applicationLocale = uni.getLocale();
  35. this.isAndroid = systemInfo.platform.toLowerCase() === 'android';
  36. uni.onLocaleChange((e) => {
  37. this.applicationLocale = e.locale;
  38. })
  39. },
  40. methods: {
  41. yuyanxuanze(index){
  42. var code='zh-Hans';
  43. var note=this.$t('index.language-change-confirm');
  44. var okbt='';
  45. var cancl='';
  46. switch(index){
  47. case 0:
  48. code='zh-Hans';
  49. break;
  50. case 1:
  51. code='zh-Hans';
  52. note='应用此设置将重启App';
  53. okbt='确定';
  54. cancl='取消';
  55. break;
  56. case 2:
  57. code='zh-Hant';
  58. note='應用此設置將重啟App';
  59. okbt='確定';
  60. cancl='取消';
  61. break;
  62. case 3:
  63. code='yuenan';
  64. note='Áp dụng cài đặt này sẽ khởi động lại Ứng dụng';
  65. okbt='Chắc chắn';
  66. cancl='Hủy bỏ';
  67. break;
  68. case 4:
  69. code='en';
  70. break;
  71. case 5:
  72. code='zh-Hans';
  73. break;
  74. }
  75. if (this.isAndroid) {
  76. uni.showModal({
  77. content: note,
  78. confirmText:okbt,
  79. cancelText:cancl,
  80. success: (res) => {
  81. if (res.confirm) {
  82. uni.setStorageSync('language',code);
  83. uni.setLocale(code);
  84. }
  85. }
  86. })
  87. } else {
  88. uni.setStorageSync('language',code);
  89. uni.setLocale(code);
  90. this.$i18n.locale = code;
  91. if(code=='yuenan'){
  92. code='vi';
  93. }
  94. if(code=='zh-Hans'){
  95. code='zh-CN';
  96. }
  97. if(code=='zh-Hant'){
  98. code='zh-TW';
  99. }
  100. //console.log("changeLanguages");
  101. this.$http.get(`${changeLanguages}`, {
  102. lang:code
  103. },false)
  104. .then( r => {
  105. //console.log(r)
  106. })
  107. .catch(err => {
  108. console.log(err)
  109. })
  110. setTimeout(() => {
  111. uni.navigateBack();
  112. }, 600);
  113. }
  114. },
  115. }
  116. }
  117. </script>
  118. <style>
  119. .contentV{
  120. display:flex;
  121. flex-direction: column;
  122. justify-content: center;
  123. align-items: center;
  124. }
  125. .itemView{
  126. display:flex;
  127. justify-content: flex-start;
  128. margin-top: 30rpx;
  129. height: 130rpx;
  130. width: 90%;
  131. border: 2rpx dotted darkgray;
  132. background-color: aliceblue;
  133. }
  134. .textstye{
  135. font-size: 40rpx;
  136. margin-left: 30rpx;
  137. height: 130rpx;
  138. line-height:130rpx;
  139. }
  140. </style>