You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.0 KiB

10 months ago
  1. <template>
  2. <view class="language" :style="{color: color}"
  3. >
  4. <u-action-sheet :actions="list"
  5. @close="languageShow = false"
  6. @select="selectLnaguage"
  7. :safeAreaInsetBottom="true"
  8. :show="languageShow"></u-action-sheet>
  9. <text @click="languageShow = true">{{ $t('language') }}</text>
  10. <view class="icon" @click="languageShow = true">
  11. <u-icon name="arrow-up" style="margin-bottom: -5px;" :color="color" size="12"></u-icon>
  12. <u-icon name="arrow-down" style="margin-bottom: -5px;" :color="color" size="12"></u-icon>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. export default {
  18. name:"languageUpdate",
  19. props : {
  20. color : {
  21. default : '#000'
  22. }
  23. },
  24. data() {
  25. return {
  26. languageShow : false,
  27. list: [
  28. // {
  29. // name:'中文简体',
  30. // key : "zh-Hans"
  31. // },
  32. // {
  33. // name:'中文繁體',
  34. // key : "zh-hk"
  35. // },
  36. {
  37. name:'English',
  38. key : "en"
  39. },
  40. {
  41. name:'Indonesian',
  42. key : "vi-ydnxy"
  43. },
  44. // {
  45. // name : 'Tiếng Việt',
  46. // key : "vi-VN"
  47. // },
  48. {
  49. name: this.$t('language.cancel')
  50. }
  51. ],
  52. };
  53. },
  54. methods : {
  55. selectLnaguage(res){
  56. //#ifdef H5
  57. this.$router.go(0); //刷新页面,不然validate.js不好国际化
  58. //#endif
  59. //#ifdef APP-PLUS
  60. uni.navigateTo({
  61. url: '/pages/home/home' // 要刷新的页面路径
  62. });
  63. //#endif
  64. if(!res.key){
  65. return
  66. }
  67. this.curLanguage = res.key;
  68. // this.$store.commit('changeLanguage', res.key.code);
  69. uni.setStorage({
  70. key: 'language',
  71. data: res.key
  72. })
  73. this.$i18n.locale = res.key
  74. uni.setLocale(res.key) //切换语言环境必须在this.$i18n.locale之后,否则app端会有意想不到的bug
  75. }
  76. }
  77. }
  78. </script>
  79. <style lang="scss" scoped>
  80. .language{
  81. display: flex;
  82. justify-content: center;
  83. align-items: center;
  84. font-size: 28rpx;
  85. height: 100%;
  86. .icon{
  87. display: flex;
  88. flex-direction: column;
  89. // justify-content: center;
  90. // align-items: center;
  91. }
  92. }
  93. </style>