feat(i18n): 改造10个组件为i18n国际化,同步更新9种语言翻译文件
- 组件改造:EmptyState、ExportPanel、SearchConditionItem、SearchHistoryPanel、 SearchResultCard、SearchResultList、Select、SortSwitcher、TemplatePanel、 BottomNavigation、SearchConditionPanel - 替换硬编码中文为 $t() 调用和 computed 响应式翻译 - 新增翻译键:search(搜索历史/模板/条件)、export(导出选项)、 common.pleaseSelect 等 - 同步更新 zh-CN、en、zh-TW、ja、ko、es、fr、de、pt 共9种语言文件 - 重构 errorHandler:从 API 错误处理改为本地应用错误处理 - 移除 search.ts 中未使用的 SearchService 接口
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
<template>
|
||||
<Card class="search-history-panel">
|
||||
<view class="panel-header">
|
||||
<Typography variant="h4" weight="semibold">搜索历史</Typography>
|
||||
<Typography variant="h4" weight="semibold">{{ $t('search.searchHistory') }}</Typography>
|
||||
<Button size="small" type="text" @click="handleClearHistory">
|
||||
<Typography variant="caption" color="rgba(196, 30, 58, 255)">清除历史</Typography>
|
||||
<Typography variant="caption" color="rgba(196, 30, 58, 255)">{{ $t('search.clearHistory') }}</Typography>
|
||||
</Button>
|
||||
</view>
|
||||
|
||||
<view v-if="history.length === 0" class="empty-history">
|
||||
<EmptyState
|
||||
icon="empty"
|
||||
title="暂无搜索历史"
|
||||
description="执行搜索后,搜索条件将显示在这里"
|
||||
:title="$t('search.noHistoryTitle')"
|
||||
:description="$t('search.noHistoryDesc')"
|
||||
size="small"
|
||||
/>
|
||||
</view>
|
||||
@@ -39,6 +39,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import type { SearchRequest } from '../../types/search'
|
||||
import searchService from '../../services/searchService'
|
||||
import Card from '../Card/Card.vue'
|
||||
@@ -53,6 +54,8 @@ interface HistoryItem {
|
||||
createdAt: string
|
||||
}
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const emit = defineEmits<{
|
||||
select: [condition: SearchRequest]
|
||||
}>()
|
||||
@@ -73,8 +76,8 @@ function handleSelectHistory(item: HistoryItem) {
|
||||
|
||||
function handleClearHistory() {
|
||||
uni.showModal({
|
||||
title: '确认清除',
|
||||
content: '确定要清除所有搜索历史吗?',
|
||||
title: t('search.confirmClear'),
|
||||
content: t('search.confirmClearContent'),
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
searchService.clearSearchHistory()
|
||||
@@ -88,11 +91,11 @@ function formatHistoryTitle(condition: SearchRequest): string {
|
||||
const conditionCount = condition.conditions.length
|
||||
const days = condition.days
|
||||
|
||||
let title = `${conditionCount}个条件,${days}天范围`
|
||||
let title = t('search.historyConditionDays', { count: conditionCount, days })
|
||||
|
||||
if (conditionCount > 0) {
|
||||
const firstCondition = condition.conditions[0]
|
||||
const type = firstCondition.type === 'suitable' ? '宜' : '忌'
|
||||
const type = firstCondition.type === 'suitable' ? t('search.suitable') : t('search.unsuitable')
|
||||
const items = firstCondition.items.slice(0, 2).join('、')
|
||||
|
||||
title += `(${type}${items}${firstCondition.items.length > 2 ? '...' : ''})`
|
||||
@@ -108,13 +111,13 @@ function formatTime(timeStr: string): string {
|
||||
const diffHours = Math.floor(diffMs / (1000 * 60 * 60))
|
||||
|
||||
if (diffHours < 1) {
|
||||
return '刚刚'
|
||||
return t('search.justNow')
|
||||
} else if (diffHours < 24) {
|
||||
return `${diffHours}小时前`
|
||||
return t('search.hoursAgo', { count: diffHours })
|
||||
} else {
|
||||
const diffDays = Math.floor(diffHours / 24)
|
||||
if (diffDays < 7) {
|
||||
return `${diffDays}天前`
|
||||
return t('search.daysAgo', { count: diffDays })
|
||||
} else {
|
||||
return date.toLocaleDateString()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user