zhb 2 주 전
부모
커밋
5b99c34583
5개의 변경된 파일32개의 추가작업 그리고 27개의 파일을 삭제
  1. 4 10
      components/cwg-language.vue
  2. 2 6
      components/cwg-submenu.vue
  3. 3 2
      composables/useMenuSplit.ts
  4. 15 1
      locale/index.js
  5. 8 8
      manifest.json

+ 4 - 10
components/cwg-language.vue

@@ -1,6 +1,6 @@
 <template>
   <view class="cwg-language">
-    <cwg-dropdown :menu-list="customMenuList" @menuClick="handleMenuClick" showActive :activeKey="curLange">
+    <cwg-dropdown :menu-list="customMenuList" @menuClick="handleMenuClick" showActive :activeKey="lang">
       <view class="pc-header-btn">
         <cwg-icon name="cwg-lang" :color="iconColor " :size="20" />
       </view>
@@ -10,9 +10,9 @@
 </template>
 
 <script setup lang="ts">
-import { computed,ref } from 'vue'
+import { computed } from 'vue'
 import { useI18n } from 'vue-i18n'
-import { localesList, LANG_MAP } from '@/locale/index'
+import { localesList, switchAppLanguage } from '@/locale/index'
 import { lang } from '@/composables/config'
 
 const props = defineProps({
@@ -22,7 +22,6 @@ const props = defineProps({
   },
 })
 
-const curLange = ref(lang)
 const { t, locale } = useI18n()
 const customMenuList = computed(() =>
   localesList.map((code) => ({
@@ -33,12 +32,7 @@ const customMenuList = computed(() =>
 
 function handleMenuClick({ value }: { value: any }) {
   const type = value?.type ?? value
-  if (!type) return
-  locale.value = type
-  lang.value = type
-  curLange.value = type
-  const localeValue = LANG_MAP[type] || 'zh-Hans'
-  uni.setLocale(localeValue)
+  switchAppLanguage(type, { locale, lang })
 }
 
 function getFlagSrc(code: string) {

+ 2 - 6
components/cwg-submenu.vue

@@ -15,7 +15,7 @@ import { computed, watch, nextTick } from 'vue';
 import { openExternalUrl } from '@/utils/openExternalUrl'
 import { useI18n } from 'vue-i18n'
 import { lang } from '@/composables/config'
-import { LANG_MAP } from '@/locale/index'
+import { switchAppLanguage } from '@/locale/index'
 const { locale } = useI18n()
 import useRouter from "@/hooks/useRouter";
 const router = useRouter();
@@ -56,11 +56,7 @@ function handleClick(item: MenuItem) {
 }
 
 function handleMenuClick(a: string) {
-    if (!a) return
-    locale.value = a
-    lang.value = a
-    const localeValue = LANG_MAP[a] || 'zh-Hans'
-    uni.setLocale(localeValue)
+    switchAppLanguage(a, { locale, lang })
 }
 </script>
 

+ 3 - 2
composables/useMenuSplit.ts

@@ -1,7 +1,8 @@
 import { ref, computed, watch, nextTick, onMounted } from 'vue'
 import { useI18n } from 'vue-i18n'
 import Config from '@/config/index'
-import { localesList } from '@/locale/index'
+import { localesList, switchAppLanguage } from '@/locale/index'
+import { lang } from '@/composables/config'
 import { useWindowWidth } from '@/composables/useWindowWidth'
 import useGlobalStore from '@/stores/use-global-store'
 import useRouter from '@/hooks/useRouter'
@@ -99,7 +100,7 @@ export function useMenuSplit(handleClick1: (item: MenuItem) => void) {
 
     function handleSubmenuClick(subItem: any) {
         if (subItem.type === 'lang') {
-            locale.value = subItem.lang
+            switchAppLanguage(subItem.lang, { locale, lang })
             return
         }
         if (subItem.isExternal) {

+ 15 - 1
locale/index.js

@@ -52,4 +52,18 @@ const LANG_MAP = {
   ug: 'ug',
 };
 
-export { messages, localesList, LANG_MAP };
+/**
+ * 切换应用语言(vue-i18n + 本地存储)
+ * App 端勿调用 uni.setLocale,否则会触发原生重启
+ */
+function switchAppLanguage(type, { locale, lang }) {
+  if (!type || !locale || !lang) return
+  locale.value = type
+  lang.value = type
+  // #ifdef H5
+  const localeValue = LANG_MAP[type] || 'zh-Hans'
+  uni.setLocale(localeValue)
+  // #endif
+}
+
+export { messages, localesList, LANG_MAP, switchAppLanguage };

+ 8 - 8
manifest.json

@@ -50,14 +50,14 @@
                 "UIBackgroundModes" : [ "audio" ],
                 "urlschemewhitelist" : [ "baidumap", "iosamap" ],
                 "privacyDescription" : {
-                    "NSLocalNetworkUsageDescription" : "true",
-                    "NSPhotoLibraryUsageDescription" : "true",
-                    "NSCameraUsageDescription" : "true",
-                    "NSMicrophoneUsageDescription" : "true",
-                    "NSLocationAlwaysAndWhenInUseUsageDescription" : "true",
-                    "NSCalendarsUsageDescription" : "true",
-                    "NSSpeechRecognitionUsageDescription" : "true",
-                    "NSFaceIDUsageDescription" : "true"
+                    "NSLocalNetworkUsageDescription" : "CWG Center uses the local network to connect to services and improve app performance on your device.",
+                    "NSPhotoLibraryUsageDescription" : "CWG Center needs access to your photo library so you can upload identity documents, payment proofs, and other files required for account verification and transactions.",
+                    "NSCameraUsageDescription" : "CWG Center needs camera access so you can take photos of identity documents and other materials required for KYC verification and account services.",
+                    "NSMicrophoneUsageDescription" : "CWG Center needs microphone access for voice communication during customer support or related in-app services.",
+                    "NSLocationAlwaysAndWhenInUseUsageDescription" : "CWG Center may use your location to meet regulatory requirements and provide location-related account services when you choose to enable this feature.",
+                    "NSCalendarsUsageDescription" : "CWG Center needs calendar access to add reminders for account activities and scheduled events you choose to save.",
+                    "NSSpeechRecognitionUsageDescription" : "CWG Center needs speech recognition to convert your voice input into text when you use voice-related features in the app.",
+                    "NSFaceIDUsageDescription" : "CWG Center uses Face ID to securely verify your identity and protect access to your account."
                 },
                 "NSAppTransportSecurity" : {
                     "NSAllowsArbitraryLoads" : true