feat(i18n): 改造黄历搜索页,替换硬编码中文为 $t() 调用

This commit is contained in:
张翔
2026-04-29 18:28:24 +08:00
parent 96c571d16a
commit 0dee22f5c3
@@ -1,7 +1,7 @@
<template> <template>
<view class="page"> <view class="page">
<view class="page-header"> <view class="page-header">
<Typography variant="h3" weight="bold" class="page-title">黄历搜索</Typography> <Typography variant="h3" weight="bold" class="page-title">{{ $t('almanac.pageTitle') }}</Typography>
</view> </view>
<view class="page-content"> <view class="page-content">
@@ -16,12 +16,12 @@
/> />
<view v-if="loading" class="loading-container"> <view v-if="loading" class="loading-container">
<LoadingIndicator text="搜索中..." /> <LoadingIndicator :text="$t('almanac.searching')" />
</view> </view>
<view v-else-if="error" class="error-container"> <view v-else-if="error" class="error-container">
<Typography variant="body" class="error-text">{{ error }}</Typography> <Typography variant="body" class="error-text">{{ error }}</Typography>
<Button @click="performSearch">重试</Button> <Button @click="performSearch">{{ $t('common.retry') }}</Button>
</view> </view>
<SearchResultList <SearchResultList
@@ -37,7 +37,7 @@
<EmptyState <EmptyState
v-else v-else
:showAction="hasSearched" :showAction="hasSearched"
actionText="重新搜索" :actionText="$t('common.retry')"
@action="performSearch" @action="performSearch"
/> />
</view> </view>
@@ -48,6 +48,8 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, onMounted } from 'vue' import { ref, onMounted } from 'vue'
import { useI18n } from 'vue-i18n'
import { onShow } from '@dcloudio/uni-app'
import type { SearchCondition, SearchRequest, SearchResult } from '../../types/search' import type { SearchCondition, SearchRequest, SearchResult } from '../../types/search'
import BottomNavigation from '../../components/BottomNavigation/BottomNavigation.vue' import BottomNavigation from '../../components/BottomNavigation/BottomNavigation.vue'
import TemplatePanel from '../../components/TemplatePanel/index.vue' import TemplatePanel from '../../components/TemplatePanel/index.vue'
@@ -59,6 +61,12 @@ import Typography from '../../components/Typography/Typography.vue'
import Button from '../../components/Button/Button.vue' import Button from '../../components/Button/Button.vue'
import searchService from '../../services/searchService' import searchService from '../../services/searchService'
const { t } = useI18n()
onShow(() => {
uni.setNavigationBarTitle({ title: t('almanac.pageTitle') })
})
const loading = ref(false) const loading = ref(false)
const error = ref('') const error = ref('')
const hasSearched = ref(false) const hasSearched = ref(false)
@@ -95,7 +103,7 @@ onMounted(() => {
const handleKeywordSearch = async (keyword: string) => { const handleKeywordSearch = async (keyword: string) => {
if (!keyword.trim()) { if (!keyword.trim()) {
error.value = '请输入搜索关键词' error.value = t('almanac.keywordHint')
return return
} }
@@ -108,11 +116,11 @@ const handleKeywordSearch = async (keyword: string) => {
searchResults.value = results searchResults.value = results
if (results.length === 0) { if (results.length === 0) {
error.value = '没有找到符合条件的结果' error.value = t('almanac.noResult')
} }
} catch (err: any) { } catch (err: any) {
console.error('搜索失败:', err) console.error('搜索失败:', err)
error.value = '搜索失败,请稍后重试' error.value = t('almanac.searchFailed')
} finally { } finally {
loading.value = false loading.value = false
} }
@@ -154,7 +162,7 @@ const sortResults = () => {
const performSearch = async () => { const performSearch = async () => {
if (searchRequest.value.conditions.length === 0) { if (searchRequest.value.conditions.length === 0) {
error.value = '请至少添加一个搜索条件' error.value = t('search.addConditionHint')
return return
} }
@@ -167,11 +175,11 @@ const performSearch = async () => {
searchResults.value = results searchResults.value = results
if (results.length === 0) { if (results.length === 0) {
error.value = '没有找到符合条件的结果' error.value = t('almanac.noResult')
} }
} catch (err: any) { } catch (err: any) {
console.error('搜索失败:', err) console.error('搜索失败:', err)
error.value = '搜索失败,请稍后重试' error.value = t('almanac.searchFailed')
} finally { } finally {
loading.value = false loading.value = false
} }