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>
<view class="page">
<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 class="page-content">
@@ -16,12 +16,12 @@
/>
<view v-if="loading" class="loading-container">
<LoadingIndicator text="搜索中..." />
<LoadingIndicator :text="$t('almanac.searching')" />
</view>
<view v-else-if="error" class="error-container">
<Typography variant="body" class="error-text">{{ error }}</Typography>
<Button @click="performSearch">重试</Button>
<Button @click="performSearch">{{ $t('common.retry') }}</Button>
</view>
<SearchResultList
@@ -37,7 +37,7 @@
<EmptyState
v-else
:showAction="hasSearched"
actionText="重新搜索"
:actionText="$t('common.retry')"
@action="performSearch"
/>
</view>
@@ -48,6 +48,8 @@
<script setup lang="ts">
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 BottomNavigation from '../../components/BottomNavigation/BottomNavigation.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 searchService from '../../services/searchService'
const { t } = useI18n()
onShow(() => {
uni.setNavigationBarTitle({ title: t('almanac.pageTitle') })
})
const loading = ref(false)
const error = ref('')
const hasSearched = ref(false)
@@ -95,7 +103,7 @@ onMounted(() => {
const handleKeywordSearch = async (keyword: string) => {
if (!keyword.trim()) {
error.value = '请输入搜索关键词'
error.value = t('almanac.keywordHint')
return
}
@@ -108,11 +116,11 @@ const handleKeywordSearch = async (keyword: string) => {
searchResults.value = results
if (results.length === 0) {
error.value = '没有找到符合条件的结果'
error.value = t('almanac.noResult')
}
} catch (err: any) {
console.error('搜索失败:', err)
error.value = '搜索失败,请稍后重试'
error.value = t('almanac.searchFailed')
} finally {
loading.value = false
}
@@ -154,7 +162,7 @@ const sortResults = () => {
const performSearch = async () => {
if (searchRequest.value.conditions.length === 0) {
error.value = '请至少添加一个搜索条件'
error.value = t('search.addConditionHint')
return
}
@@ -167,11 +175,11 @@ const performSearch = async () => {
searchResults.value = results
if (results.length === 0) {
error.value = '没有找到符合条件的结果'
error.value = t('almanac.noResult')
}
} catch (err: any) {
console.error('搜索失败:', err)
error.value = '搜索失败,请稍后重试'
error.value = t('almanac.searchFailed')
} finally {
loading.value = false
}