@liujitcn/kratos-taro-app-system 0.0.20 → 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.
- package/dist/build.mjs +4 -4
- package/package.json +3 -3
- package/src/api/base/ai_message.ts +8 -5
- package/src/index.ts +17 -0
- package/src/locales/README.md +15 -0
- package/src/locales/en-US.json +91 -0
- package/src/locales/es-ES.json +91 -0
- package/src/locales/fr-FR.json +91 -0
- package/src/locales/ja-JP.json +91 -0
- package/src/locales/ko-KR.json +91 -0
- package/src/locales/zh-CN.json +91 -0
- package/src/locales/zh-TW.json +91 -0
- package/src/pages.ts +4 -4
- package/src/views/pages/my/my.tsx +15 -7
- package/src/views/pagesMember/ai/components/SessionDrawer.tsx +8 -6
- package/src/views/pagesMember/ai/components/WelcomePanel.tsx +9 -7
- package/src/views/pagesMember/ai/index.tsx +120 -52
- package/src/views/pagesMember/profile/profile.tsx +21 -15
- package/src/views/pagesMember/settings/settings.scss +10 -0
- package/src/views/pagesMember/settings/settings.tsx +40 -8
|
@@ -1,18 +1,29 @@
|
|
|
1
|
-
import { Button, View } from '@tarojs/components'
|
|
1
|
+
import { Button, Picker, Text, View } from '@tarojs/components'
|
|
2
2
|
import Taro, { useLoad } from '@tarojs/taro'
|
|
3
|
-
import { useState } from 'react'
|
|
3
|
+
import { useEffect, useMemo, useState } from 'react'
|
|
4
4
|
import {
|
|
5
|
+
useLocaleStore,
|
|
5
6
|
navigateToLogin,
|
|
7
|
+
type SupportedLocale,
|
|
8
|
+
useI18n,
|
|
6
9
|
useUserStore,
|
|
7
10
|
} from '@liujitcn/kratos-taro-app-core'
|
|
8
11
|
import './settings.scss'
|
|
9
12
|
|
|
10
13
|
/** 应用设置页。 */
|
|
11
14
|
export default function SettingsPage() {
|
|
15
|
+
const { locale, setLocale, t } = useI18n()
|
|
16
|
+
const languageOptions = useLocaleStore((state) => state.languageOptions)
|
|
12
17
|
const [logoutLoading, setLogoutLoading] = useState(false)
|
|
13
18
|
const authenticated = useUserStore((state) => state.isAuthenticated())
|
|
14
19
|
const ensureAuthenticated = useUserStore((state) => state.ensureAuthenticated)
|
|
15
20
|
const logout = useUserStore((state) => state.logout)
|
|
21
|
+
const localeLabels = useMemo(() => languageOptions.map((item) => item.language_name), [languageOptions])
|
|
22
|
+
const localeIndex = Math.max(0, languageOptions.findIndex((item) => item.language_code === locale))
|
|
23
|
+
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
void Taro.setNavigationBarTitle({ title: t('system.settings.title') })
|
|
26
|
+
}, [locale, t])
|
|
16
27
|
|
|
17
28
|
useLoad(() => {
|
|
18
29
|
if (process.env.TARO_ENV !== 'weapp' && !ensureAuthenticated()) navigateToLogin()
|
|
@@ -20,14 +31,17 @@ export default function SettingsPage() {
|
|
|
20
31
|
|
|
21
32
|
const onLogout = async () => {
|
|
22
33
|
if (logoutLoading) return
|
|
23
|
-
const result = await Taro.showModal({
|
|
34
|
+
const result = await Taro.showModal({
|
|
35
|
+
content: t('system.settings.logoutConfirm'),
|
|
36
|
+
confirmColor: '#27BA9B',
|
|
37
|
+
})
|
|
24
38
|
if (!result.confirm) return
|
|
25
39
|
setLogoutLoading(true)
|
|
26
40
|
try {
|
|
27
41
|
await logout()
|
|
28
42
|
await Taro.navigateBack()
|
|
29
43
|
} catch {
|
|
30
|
-
await Taro.showToast({ icon: 'none', title: '
|
|
44
|
+
await Taro.showToast({ icon: 'none', title: t('system.settings.logoutFailed') })
|
|
31
45
|
} finally {
|
|
32
46
|
setLogoutLoading(false)
|
|
33
47
|
}
|
|
@@ -38,20 +52,38 @@ export default function SettingsPage() {
|
|
|
38
52
|
{process.env.TARO_ENV === 'weapp' ? (
|
|
39
53
|
<View className='settings-list'>
|
|
40
54
|
<Button className='settings-item settings-arrow' hoverClass='none' openType='openSetting'>
|
|
41
|
-
|
|
55
|
+
{t('system.settings.authorization')}
|
|
42
56
|
</Button>
|
|
43
57
|
<Button className='settings-item settings-arrow' hoverClass='none' openType='feedback'>
|
|
44
|
-
|
|
58
|
+
{t('system.settings.feedback')}
|
|
45
59
|
</Button>
|
|
46
60
|
<Button className='settings-item settings-arrow' hoverClass='none' openType='contact'>
|
|
47
|
-
|
|
61
|
+
{t('system.settings.contact')}
|
|
48
62
|
</Button>
|
|
49
63
|
</View>
|
|
50
64
|
) : null}
|
|
65
|
+
<View className='settings-list'>
|
|
66
|
+
<Picker
|
|
67
|
+
mode='selector'
|
|
68
|
+
range={localeLabels}
|
|
69
|
+
value={localeIndex}
|
|
70
|
+
onChange={(event) => {
|
|
71
|
+
const nextLocale = languageOptions[Number(event.detail.value)]?.language_code as
|
|
72
|
+
| SupportedLocale
|
|
73
|
+
| undefined
|
|
74
|
+
if (nextLocale) void setLocale(nextLocale)
|
|
75
|
+
}}
|
|
76
|
+
>
|
|
77
|
+
<View className='settings-item settings-arrow settings-locale'>
|
|
78
|
+
<Text>{t('common.field.language')}</Text>
|
|
79
|
+
<Text className='settings-locale__value'>{localeLabels[localeIndex]}</Text>
|
|
80
|
+
</View>
|
|
81
|
+
</Picker>
|
|
82
|
+
</View>
|
|
51
83
|
{authenticated ? (
|
|
52
84
|
<View className='settings-action'>
|
|
53
85
|
<View className='settings-button' onClick={() => void onLogout()}>
|
|
54
|
-
|
|
86
|
+
{t('common.action.logout')}
|
|
55
87
|
</View>
|
|
56
88
|
</View>
|
|
57
89
|
) : null}
|