language.vue
3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<template>
<view class="page">
<view class="header-hero" :style="{ paddingTop: statusBarHeight + 'px' }">
<view class="top-bar">
<view class="top-left" @click="goBack">
<AppIcon name="chevronLeft" size="sm" color="white" />
</view>
<view class="top-center">
<text class="page-title">{{ t('language.title') }}</text>
<LocationPicker />
</view>
<view class="top-right" @click="isMenuOpen = true">
<AppIcon name="menu" size="sm" color="white" />
</view>
</view>
</view>
<view class="content">
<view class="intro">
<text class="intro-title">{{ t('language.selectLanguage') }}</text>
<text class="intro-desc">Choose your preferred language for the app</text>
</view>
<view class="lang-list">
<view
v-for="lang in languages"
:key="lang.code"
class="lang-card"
:class="{ active: locale === lang.code }"
@click="handleChange(lang.code)"
>
<text class="lang-flag">{{ lang.flag }}</text>
<text class="lang-name">{{ t(lang.nameKey) }}</text>
<view v-if="locale === lang.code" class="lang-check"><AppIcon name="check" size="sm" color="white" /></view>
</view>
</view>
</view>
<SideMenu v-model="isMenuOpen" />
</view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { setLocale } from '../../utils/i18n'
import AppIcon from '../../components/AppIcon.vue'
import SideMenu from '../../components/SideMenu.vue'
import LocationPicker from '../../components/LocationPicker.vue'
import { getStatusBarHeight } from '../../utils/statusBar'
const { t, locale } = useI18n()
const statusBarHeight = getStatusBarHeight()
const isMenuOpen = ref(false)
const languages = [
{ code: 'en' as const, nameKey: 'language.english', flag: '🇺🇸' },
{ code: 'zh' as const, nameKey: 'language.chinese', flag: '🇨🇳' },
]
const goBack = () => {
const pages = getCurrentPages()
if (pages.length > 1) {
uni.navigateBack()
} else {
uni.redirectTo({ url: '/pages/index/index' })
}
}
const handleChange = (code: 'en' | 'zh') => {
setLocale(code)
uni.showToast({ title: t('language.changed'), icon: 'success' })
}
</script>
<style scoped>
.page {
min-height: 100vh;
background: #f9fafb;
}
.header-hero {
background: linear-gradient(135deg, var(--theme-primary), var(--theme-primary-dark));
padding: 16rpx 32rpx 24rpx;
}
.top-bar {
height: 96rpx;
display: flex;
align-items: center;
justify-content: space-between;
}
.top-left,
.top-right {
width: 64rpx;
height: 64rpx;
border-radius: 999rpx;
background: rgba(255, 255, 255, 0.15);
display: flex;
align-items: center;
justify-content: center;
}
.top-center {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
}
.page-title {
font-size: 34rpx;
font-weight: 600;
color: #fff;
}
.content {
padding: 48rpx;
}
.intro {
margin-bottom: 32rpx;
}
.intro-title {
font-size: 32rpx;
font-weight: 600;
color: #111827;
display: block;
margin-bottom: 8rpx;
}
.intro-desc {
font-size: 28rpx;
color: #6b7280;
}
.lang-card {
background: #fff;
padding: 32rpx;
border-radius: 20rpx;
margin-bottom: 24rpx;
display: flex;
align-items: center;
gap: 32rpx;
border: 3rpx solid #e5e7eb;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
}
.lang-card.active {
border-color: var(--theme-primary);
background: var(--theme-primary-light);
}
.lang-flag {
font-size: 60rpx;
}
.lang-name {
font-size: 34rpx;
font-weight: 600;
color: #111827;
flex: 1;
}
.lang-check {
width: 48rpx;
height: 48rpx;
background: var(--theme-primary);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
}
</style>