Files
medical-mall/pages/mall/admin/maintain/i18n/language-detail.uvue

141 lines
7.1 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<view class="admin-page-container">
<view class="page-card">
<view class="search-wrap">
<view class="search-item">
<text class="label">翻译key</text>
<input class="input" placeholder="请输入翻译键" v-model="searchKey" />
</view>
<button class="btn btn-primary" @click="onSearch">查询</button>
</view>
<view class="action-wrap">
<button class="btn btn-primary" @click="onAdd">添加翻译</button>
</view>
<view class="table-wrap">
<view class="table-header">
<view class="th" style="flex: 0 0 60px;">ID</view>
<view class="th" style="flex: 2;">翻译键(key)</view>
<view class="th" style="flex: 3;">中文原文</view>
<view class="th" style="flex: 3;">翻译内容</view>
<view class="th" style="flex: 1.5;">操作</view>
</view>
<view class="table-body">
<view v-for="item in pagedList" :key="item.id" class="tr">
<view class="td" style="flex: 0 0 60px;">{{ item.id }}</view>
<view class="td" style="flex: 2;">{{ item.key }}</view>
<view class="td" style="flex: 3;">{{ item.original }}</view>
<view class="td" style="flex: 3;">{{ item.translation }}</view>
<view class="td" style="flex: 1.5;">
<text class="action-btn" @click="onEdit(item)">编辑</text>
</view>
</view>
</view>
</view>
<CommonPagination
v-if="total > 0"
:total="total"
:loading="false"
:currentPage="currentPage"
:pageSize="pageSize"
:pageSizeOptionLabels="pageSizeOptionLabels"
:pageSizeIndex="pageSizeIndex"
:visiblePages="visiblePages"
:totalPage="totalPage"
:jumpPageInput="jumpPageInput"
@page-size-change="handlePageSizeChange"
@page-change="handlePageChange"
@update:jumpPageInput="(val: string) => { jumpPageInput.value = val }"
@jump-page="handleJumpPage"
/>
</view>
</view>
</template>
<script setup lang="uts">
import { ref, computed } from 'vue'
import CommonPagination from '@/components/CommonPagination/CommonPagination.uvue'
const searchKey = ref('')
type TranslationItem = { id: number; key: string; original: string; translation: string }
// ========== MOCK DATA START ==========
const translationList = ref<TranslationItem[]>([
{ id: 1, key: 'common.confirm', original: '确定', translation: 'Confirm' },
{ id: 2, key: 'common.cancel', original: '取消', translation: 'Cancel' },
{ id: 3, key: 'common.save', original: '保存', translation: 'Save' },
{ id: 4, key: 'common.delete', original: '删除', translation: 'Delete' },
{ id: 5, key: 'common.edit', original: '编辑', translation: 'Edit' },
{ id: 6, key: 'common.add', original: '添加', translation: 'Add' },
{ id: 7, key: 'common.search', original: '搜索', translation: 'Search' },
{ id: 8, key: 'common.reset', original: '重置', translation: 'Reset' },
{ id: 9, key: 'common.loading', original: '加载中...', translation: 'Loading...' },
{ id: 10, key: 'common.no_data', original: '暂无数据', translation: 'No Data' },
{ id: 11, key: 'order.status.pending', original: '待支付', translation: 'Pending' },
{ id: 12, key: 'order.status.paid', original: '已支付', translation: 'Paid' },
{ id: 13, key: 'order.status.shipped', original: '已发货', translation: 'Shipped' },
{ id: 14, key: 'order.status.received', original: '已收货', translation: 'Received' },
{ id: 15, key: 'order.status.cancelled', original: '已取消', translation: 'Cancelled' },
{ id: 16, key: 'product.out_of_stock', original: '已售罄', translation: 'Out of Stock' },
{ id: 17, key: 'user.login', original: '登录', translation: 'Login' },
{ id: 18, key: 'user.logout', original: '登出', translation: 'Logout' },
{ id: 19, key: 'user.register', original: '注册', translation: 'Register' },
{ id: 20, key: 'user.profile', original: '个人中心', translation: 'Profile' }
])
// ========== MOCK DATA END ==========
// ========== PAGINATION STATE ==========
const currentPage = ref(1)
const pageSize = ref(15)
const jumpPageInput = ref('')
const pageSizeOptions = [10, 15, 20, 30, 50]
const pageSizeOptionLabels = computed(() => pageSizeOptions.map((n: number) => `${n}条/页`))
const pageSizeIndex = computed(() => { const idx = pageSizeOptions.indexOf(pageSize.value); return idx >= 0 ? idx : 0 })
const total = computed(() => translationList.value.length)
const totalPage = computed(() => Math.max(1, Math.ceil(total.value / pageSize.value)))
const pagedList = computed(() => {
const start = (currentPage.value - 1) * pageSize.value
return translationList.value.slice(start, start + pageSize.value)
})
const visiblePages = computed((): number[] => {
const t = totalPage.value; const cur = currentPage.value
if (t <= 7) return Array.from({ length: t }, (_: any, i: number) => i + 1)
if (cur <= 4) return [1, 2, 3, 4, 5, -1, t]
if (cur >= t - 3) return [1, -1, t - 4, t - 3, t - 2, t - 1, t]
return [1, -1, cur - 1, cur, cur + 1, -1, t]
})
const handlePageChange = (p: number) => { currentPage.value = p }
const handlePageSizeChange = (e: any) => {
const idx = Number(e.detail.value)
pageSize.value = pageSizeOptions[idx] ?? pageSizeOptions[0]
currentPage.value = 1
}
const handleJumpPage = () => {
const p = parseInt(jumpPageInput.value)
if (!isNaN(p) && p >= 1 && p <= totalPage.value) currentPage.value = p
}
// ========== END PAGINATION STATE ==========
function onSearch() { console.log('Search:', searchKey.value) }
function onAdd() { uni.showToast({ title: '添加翻译', icon: 'none' }) }
function onEdit(item: TranslationItem) { uni.showToast({ title: '编辑: ' + item.key, icon: 'none' }) }
</script>
<style scoped>
.admin-page-container { padding: 0; background-color: transparent; min-height: auto; }
.page-card { background-color: #fff; border-radius: 4px; padding: 20px; }
.search-wrap { display: flex; flex-direction: row; align-items: center; padding-bottom: 20px; border-bottom: 1px solid #f0f0f0; margin-bottom: 20px; }
.search-item { display: flex; flex-direction: row; align-items: center; margin-right: 20px; }
.label { font-size: 14px; color: #606266; margin-right: 8px; }
.input { width: 220px; height: 32px; padding: 0 10px; border: 1px solid #dcdfe6; border-radius: 4px; font-size: 14px; }
.btn { height: 32px; padding: 0 15px; font-size: 14px; border-radius: 4px; border: none; }
.btn-primary { background-color: #1890ff; color: #fff; }
.action-wrap { margin-bottom: 20px; }
.table-wrap { width: 100%; border: 1px solid #f0f0f0; }
.table-header { display: flex; flex-direction: row; background-color: #f8f8f9; }
.th { padding: 12px 10px; font-size: 13px; font-weight: bold; color: #515a6e; border-bottom: 1px solid #f0f0f0; text-align: center; }
.tr { display: flex; flex-direction: row; align-items: center; border-bottom: 1px solid #f0f0f0; min-height: 50px; }
.td { padding: 10px; font-size: 13px; color: #515a6e; text-align: center; }
.action-btn { font-size: 13px; color: #1890ff; margin-right: 8px; cursor: pointer; }
</style>