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> </span>
<button <template v-for="page in visiblePages" :key="page">
v-for="page in visiblePages" <button
v-if="page !== 1 && page !== pagination.total" v-if="page !== 1 && page !== pagination.total"
:key="page" class="pagination-button"
class="pagination-button" :class="{ 'pagination-button-active': page === pagination.page }"
:class="{ 'pagination-button-active': page === pagination.page }" :disabled="page === pagination.page"
:disabled="page === pagination.page" @click="goPage(page)"
@click="goPage(page)" >
> {{ page }}
{{ page }} </button>
</button> </template>
<span <span
v-if=" v-if="
visiblePages.length && visiblePages.length &&
@@ -186,6 +186,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, ref, computed } from "vue"; import { onMounted, ref, computed } from "vue";
import { useRoute, useRouter } from "vue-router";
import { import {
CommentItem, CommentItem,
CommentListResponse, CommentListResponse,
@@ -196,6 +197,9 @@ import {
blockEmail, blockEmail,
} from "../api/admin"; } from "../api/admin";
const route = useRoute();
const router = useRouter();
const comments = ref<CommentItem[]>([]); const comments = ref<CommentItem[]>([]);
const pagination = ref<{ page: number; total: number }>({ page: 1, total: 1 }); const pagination = ref<{ page: number; total: number }>({ page: 1, total: 1 });
const loading = ref(false); 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) { async function goPage(page: number) {
if (page < 1 || page > pagination.value.total) { if (page < 1 || page > pagination.value.total) {
return; return;
} }
updateRoutePage(page);
await loadComments(page); await loadComments(page);
} }
@@ -286,6 +296,7 @@ function handleJumpPage() {
return; return;
} }
jumpPageInput.value = ""; jumpPageInput.value = "";
updateRoutePage(page);
loadComments(page); loadComments(page);
} }
@@ -341,7 +352,21 @@ async function handleBlockEmail(item: CommentItem) {
} }
onMounted(() => { 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> </script>

View File

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

View File

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

View File

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