@liujitcn/kratos-uni-app-system 0.0.19 → 0.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,9 +3,32 @@ import { useUserStore } from '@liujitcn/kratos-uni-app-core/stores'
3
3
  import { onLoad } from '@dcloudio/uni-app'
4
4
  import { ref } from 'vue'
5
5
  import { navigateToLogin } from '@liujitcn/kratos-uni-app-core/utils/navigation'
6
+ import { getLanguageOptions, useI18n, type SupportedLocale } from '@liujitcn/kratos-uni-app-core'
7
+ import { computed, watch } from 'vue'
6
8
 
7
9
  const userStore = useUserStore()
10
+ const { locale, setLocale, t } = useI18n()
8
11
  const logoutLoading = ref(false)
12
+ const localeOptions = computed(() => getLanguageOptions())
13
+ const localeLabels = computed(() => localeOptions.value.map((item) => item.language_name))
14
+ const localeIndex = computed(() =>
15
+ Math.max(
16
+ 0,
17
+ localeOptions.value.findIndex((item) => item.language_code === locale.value),
18
+ ),
19
+ )
20
+
21
+ watch(locale, () => void uni.setNavigationBarTitle({ title: t('system.settings.title') }), {
22
+ immediate: true,
23
+ })
24
+
25
+ /** 处理语言选择并刷新动态本地化数据。 */
26
+ const onLocaleChange = (event: { detail: { value: string | number } }) => {
27
+ const nextLocale = localeOptions.value[Number(event.detail.value)]?.language_code as
28
+ | SupportedLocale
29
+ | undefined
30
+ if (nextLocale) void setLocale(nextLocale)
31
+ }
9
32
 
10
33
  // #ifndef MP-WEIXIN
11
34
  // 非微信小程序端未登录时没有可用设置项,直接引导登录以避免显示空白页面。
@@ -23,7 +46,7 @@ const onLogout = () => {
23
46
  }
24
47
  // 模态弹窗
25
48
  uni.showModal({
26
- content: '是否退出登录?',
49
+ content: t('system.settings.logoutConfirm'),
27
50
  confirmColor: '#27BA9B',
28
51
  success: async (res) => {
29
52
  if (!res.confirm) {
@@ -38,7 +61,7 @@ const onLogout = () => {
38
61
  } catch (error) {
39
62
  await uni.showToast({
40
63
  icon: 'none',
41
- title: '退出登录失败',
64
+ title: t('system.settings.logoutFailed'),
42
65
  })
43
66
  } finally {
44
67
  logoutLoading.value = false
@@ -53,14 +76,28 @@ const onLogout = () => {
53
76
  <!-- #ifdef MP-WEIXIN -->
54
77
  <!-- 列表2 -->
55
78
  <view class="list">
56
- <button hover-class="none" class="item arrow" open-type="openSetting">授权管理</button>
57
- <button hover-class="none" class="item arrow" open-type="feedback">问题反馈</button>
58
- <button hover-class="none" class="item arrow" open-type="contact">联系我们</button>
79
+ <button hover-class="none" class="item arrow" open-type="openSetting">
80
+ {{ t('system.settings.authorization') }}
81
+ </button>
82
+ <button hover-class="none" class="item arrow" open-type="feedback">
83
+ {{ t('system.settings.feedback') }}
84
+ </button>
85
+ <button hover-class="none" class="item arrow" open-type="contact">
86
+ {{ t('system.settings.contact') }}
87
+ </button>
59
88
  </view>
60
89
  <!-- #endif -->
90
+ <view class="list">
91
+ <picker :range="localeLabels" :value="localeIndex" @change="onLocaleChange">
92
+ <view class="item arrow locale-item">
93
+ <text>{{ t('common.field.language') }}</text>
94
+ <text class="locale-value">{{ localeLabels[localeIndex] }}</text>
95
+ </view>
96
+ </picker>
97
+ </view>
61
98
  <!-- 操作按钮 -->
62
99
  <view class="action" v-if="userStore.isAuthenticated()">
63
- <view @tap="onLogout" class="button">退出登录</view>
100
+ <view @tap="onLogout" class="button">{{ t('common.action.logout') }}</view>
64
101
  </view>
65
102
  </view>
66
103
  </template>
@@ -113,6 +150,16 @@ page {
113
150
  }
114
151
  }
115
152
 
153
+ .locale-item {
154
+ display: flex;
155
+ justify-content: space-between;
156
+ padding-right: 42rpx;
157
+ }
158
+
159
+ .locale-value {
160
+ color: #888;
161
+ }
162
+
116
163
  /* 操作按钮 */
117
164
  .action {
118
165
  text-align: center;