duoyuyan.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <view class="contentV">
  3. <customNav :shownav="true" title="Ngôn ngữ/语言" titledetl=""></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 api from "@/pages/api/api.js"
  20. export default {
  21. data() {
  22. return {
  23. index:0,
  24. systemLocale: '',
  25. applicationLocale: '',
  26. isAndroid:false
  27. }
  28. },
  29. onLoad() {
  30. let systemInfo = uni.getSystemInfoSync();
  31. this.systemLocale = systemInfo.language;
  32. this.applicationLocale = uni.getLocale();
  33. this.isAndroid = systemInfo.platform.toLowerCase() === 'android';
  34. uni.onLocaleChange((e) => {
  35. this.applicationLocale = e.locale;
  36. })
  37. },
  38. methods: {
  39. yuyanxuanze(index){
  40. var code='zh-Hans';
  41. var note=this.$t('index.language-change-confirm');
  42. var okbt='';
  43. var cancl='';
  44. switch(index){
  45. case 0:
  46. code='zh-Hans';
  47. break;
  48. case 1:
  49. code='zh-Hans';
  50. note='应用此设置将重启App';
  51. okbt='确定';
  52. cancl='取消';
  53. break;
  54. case 2:
  55. code='zh-Hant';
  56. note='應用此設置將重啟App';
  57. okbt='確定';
  58. cancl='取消';
  59. break;
  60. case 3:
  61. code='yuenan';
  62. note='Áp dụng cài đặt này sẽ khởi động lại Ứng dụng';
  63. okbt='Chắc chắn';
  64. cancl='Hủy bỏ';
  65. break;
  66. case 4:
  67. code='en';
  68. break;
  69. case 5:
  70. code='zh-Hans';
  71. break;
  72. }
  73. if (this.isAndroid) {
  74. uni.showModal({
  75. content: note,
  76. confirmText:okbt,
  77. cancelText:cancl,
  78. success: (res) => {
  79. if (res.confirm) {
  80. uni.setStorageSync('language',code);
  81. uni.setLocale(code);
  82. }
  83. }
  84. })
  85. } else {
  86. uni.setStorageSync('language',code);
  87. uni.setLocale(code);
  88. this.$i18n.locale = code;
  89. if(code=='yuenan'){
  90. code='vi';
  91. }
  92. if(code=='zh-Hans'){
  93. code='zh-CN';
  94. }
  95. if(code=='zh-Hant'){
  96. code='zh-TW';
  97. }
  98. var userId = uni.getStorageSync('userId');
  99. if(!userId){
  100. userId=0
  101. }
  102. api('changeLanguages',{
  103. lang:code,
  104. id:userId
  105. },res=>{
  106. console.log('changeLanguages',res)
  107. },failc=>{
  108. //console.log('getadvertis----',failc)
  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>