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

138 lines
6.6 KiB
Plaintext

<template>
<view class="admin-page-container">
<view class="page-card">
<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;">语言名称</view>
<view class="th" style="flex: 1;">简称</view>
<view class="th" style="flex: 1;">是否启用</view>
<view class="th" style="flex: 1;">排序</view>
<view class="th" style="flex: 2;">操作</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.name }}</view>
<view class="td" style="flex: 1;">{{ item.code }}</view>
<view class="td" style="flex: 1;">
<switch :checked="item.status" color="#1890ff" style="transform: scale(0.7);" />
</view>
<view class="td" style="flex: 1;">{{ item.sort }}</view>
<view class="td" style="flex: 2;">
<text class="action-btn" @click="onEdit(item)">编辑</text>
<text class="action-btn" @click="onTranslate(item)">翻译管理</text>
<text class="action-btn-del" @click="onDel(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'
type LangItem = { id: number; name: string; code: string; status: boolean; sort: number }
// ========== MOCK DATA START ==========
const languageList = ref<LangItem[]>([
{ id: 1, name: '中文简体', code: 'zh-CN', status: true, sort: 1 },
{ id: 2, name: '中文繁体', code: 'zh-TW', status: true, sort: 2 },
{ id: 3, name: '英语', code: 'en-US', status: true, sort: 3 },
{ id: 4, name: '日语', code: 'ja-JP', status: true, sort: 4 },
{ id: 5, name: '韩语', code: 'ko-KR', status: true, sort: 5 },
{ id: 6, name: '法语', code: 'fr-FR', status: false, sort: 6 },
{ id: 7, name: '德语', code: 'de-DE', status: false, sort: 7 },
{ id: 8, name: '西班牙语', code: 'es-ES', status: false, sort: 8 },
{ id: 9, name: '葡萄牙语', code: 'pt-PT', status: false, sort: 9 },
{ id: 10, name: '阿拉伯语', code: 'ar-SA', status: false, sort: 10 },
{ id: 11, name: '俄语', code: 'ru-RU', status: false, sort: 11 },
{ id: 12, name: '意大利语', code: 'it-IT', status: false, sort: 12 },
{ id: 13, name: '泰语', code: 'th-TH', status: true, sort: 13 },
{ id: 14, name: '越南语', code: 'vi-VN', status: true, sort: 14 },
{ id: 15, name: '印尼语', code: 'id-ID', status: false, sort: 15 },
{ id: 16, name: '马来语', code: 'ms-MY', status: false, sort: 16 },
{ id: 17, name: '印地语', code: 'hi-IN', status: false, sort: 17 },
{ id: 18, name: '土耳其语', code: 'tr-TR', status: false, sort: 18 },
{ id: 19, name: '波兰语', code: 'pl-PL', status: false, sort: 19 },
{ id: 20, name: '荷兰语', code: 'nl-NL', status: false, sort: 20 }
])
// ========== 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(() => languageList.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 languageList.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 onAdd() { uni.showToast({ title: '添加语言', icon: 'none' }) }
function onEdit(item: LangItem) { uni.showToast({ title: '编辑: ' + item.name, icon: 'none' }) }
function onTranslate(item: LangItem) { uni.showToast({ title: '翻译管理: ' + item.name, icon: 'none' }) }
function onDel(item: LangItem) {
uni.showModal({ title: '提示', content: '确定删除该语言吗?', success: (res) => {
if (res.confirm) uni.showToast({ title: '已删除', icon: 'success' })
}})
}
</script>
<style scoped>
.admin-page-container { padding: 0; background-color: transparent; min-height: auto; }
.page-card { background-color: #fff; border-radius: 4px; padding: 20px; }
.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; display: flex; flex-direction:row }
.action-btn { font-size: 13px; color: #1890ff; margin-right: 8px; cursor: pointer; }
.action-btn-del { font-size: 13px; color: #ed4014; cursor: pointer; }
</style>