fix(ui): 修复按钮最小宽度和分页路由同步问题

- 为按钮添加最小宽度100px防止内容截断
- 修改模态框背景透明度提升视觉层次
- 统一错误日志中的冒号为中文全角
- 重构分页组件,同步当前页码到路由参数
- 初始化时从路由参数读取页码
This commit is contained in:
anghunk
2026-01-21 11:19:35 +08:00
parent ec9c658e44
commit c95ca722bc
4 changed files with 44 additions and 17 deletions

View File

@@ -130,17 +130,17 @@
>
...
</span>
<button
v-for="page in visiblePages"
v-if="page !== 1 && page !== pagination.total"
:key="page"
class="pagination-button"
:class="{ 'pagination-button-active': page === pagination.page }"
:disabled="page === pagination.page"
@click="goPage(page)"
>
{{ page }}
</button>
<template v-for="page in visiblePages" :key="page">
<button
v-if="page !== 1 && page !== pagination.total"
class="pagination-button"
:class="{ 'pagination-button-active': page === pagination.page }"
:disabled="page === pagination.page"
@click="goPage(page)"
>
{{ page }}
</button>
</template>
<span
v-if="
visiblePages.length &&
@@ -186,6 +186,7 @@
<script setup lang="ts">
import { onMounted, ref, computed } from "vue";
import { useRoute, useRouter } from "vue-router";
import {
CommentItem,
CommentListResponse,
@@ -196,6 +197,9 @@ import {
blockEmail,
} from "../api/admin";
const route = useRoute();
const router = useRouter();
const comments = ref<CommentItem[]>([]);
const pagination = ref<{ page: number; total: number }>({ page: 1, total: 1 });
const loading = ref(false);
@@ -269,10 +273,16 @@ async function loadComments(page?: number) {
}
}
function updateRoutePage(page: number) {
const query = { ...route.query, p: String(page) };
router.replace({ query });
}
async function goPage(page: number) {
if (page < 1 || page > pagination.value.total) {
return;
}
updateRoutePage(page);
await loadComments(page);
}
@@ -286,6 +296,7 @@ function handleJumpPage() {
return;
}
jumpPageInput.value = "";
updateRoutePage(page);
loadComments(page);
}
@@ -341,7 +352,21 @@ async function handleBlockEmail(item: CommentItem) {
}
onMounted(() => {
loadComments();
const p = route.query.p;
let initialPage = 1;
if (typeof p === "string") {
const value = Number(p);
if (Number.isFinite(value) && value >= 1) {
initialPage = Math.floor(value);
}
} else if (Array.isArray(p) && typeof p[0] === "string") {
const value = Number(p[0]);
if (Number.isFinite(value) && value >= 1) {
initialPage = Math.floor(value);
}
}
updateRoutePage(initialPage);
loadComments(initialPage);
});
</script>

View File

@@ -76,7 +76,7 @@
</div>
<div class="modal-actions">
<button class="modal-btn secondary" @click="cancelPrefix">
直接导入(不添加)
直接导入 (不添加)
</button>
<button class="modal-btn primary" @click="confirmPrefix">添加并导入</button>
</div>
@@ -210,7 +210,7 @@ async function handleFileChange(event: Event) {
}
} catch (err: any) {
console.error(err);
addLog(`导入失败: ${err.message || "未知错误"}`);
addLog(`导入失败${err.message || "未知错误"}`);
showToast(err.message || "导入失败,文件格式错误", "error");
importing.value = false;
}
@@ -299,11 +299,11 @@ async function executeImport(comments: any[]) {
addLog("正在上传并导入数据库...");
try {
const res = await importComments(comments);
addLog(`导入完成: ${res.message || "成功"}`);
addLog(`导入完成${res.message || "成功"}`);
showToast(res.message || "导入成功", "success");
} catch (err: any) {
console.error(err);
addLog(`导入失败: ${err.message || "未知错误"}`);
addLog(`导入失败${err.message || "未知错误"}`);
showToast(err.message || "导入失败", "error");
} finally {
importing.value = false;
@@ -444,6 +444,7 @@ async function executeImport(comments: any[]) {
color: #ffffff;
font-size: 14px;
cursor: pointer;
min-width: 100px;
}
.card-button:disabled {

View File

@@ -327,7 +327,7 @@ function handleLogoutFromActions() {
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.3);
background-color: rgba(0, 0, 0, 0.6);
z-index: 900;
display: block;
}

View File

@@ -701,6 +701,7 @@ onMounted(() => {
color: #ffffff;
font-size: 14px;
cursor: pointer;
min-width: 100px;
}
.card-button.secondary {