refactor layout

This commit is contained in:
Timi
2026-10-17 12:01:28 +08:00
parent fe467e8781
commit 469c595a7c
134 changed files with 11493 additions and 4437 deletions
+185 -66
View File
@@ -1,67 +1,115 @@
<template>
<div v-can="corePermissionCodes.notify.read" class="notify-list">
<t-segmented
v-model="filterMode"
class="filter"
block
:options="filterOptions"
@change="switchFilter"
v-entrance-transition
/>
<t-pull-down-refresh
v-model="isRefreshing"
:refresh-timeout="30000"
@refresh="refresh"
@scrolltolower="loadMore"
<div class="page-layout navbar notify-list">
<t-navbar
fixed
:z-index="20"
title="站内通知"
left-arrow
@left-click="$router.back()"
>
<t-cell-group v-if="pageResult.list.length" class="items fix-last-cell-line" theme="card">
<t-swipe-cell
v-for="item in pageResult.list"
:key="item.id"
class="item"
v-entrance-transition="{ step: 30 }"
<template #right>
<div
v-if="pageNavBarRight.icon || pageNavBarRight.text"
class="nav-right-slot"
>
<t-cell arrow hover @click="toDetail(item)">
<template #leftIcon>
<div class="icon" :class="{ unread: isUnread(item) }">
<t-icon name="notification" size="1.25rem" />
</div>
</template>
<template #title>
<div class="title">
<span v-text="getSubject(item)" />
</div>
</template>
<template #description>
<pass-time-label :timestamp="item.sendAt" underline />
</template>
<template #note>
<t-tag
v-if="filterMode === 'all' && isUnread(item)"
class="unread-label"
<t-badge
v-if="pageNavBarRight.icon && pageNavBarRight.badge !== undefined"
class="badge"
:count="pageNavBarRight.badge"
:max-count="99"
:show-zero="false"
>
<button class="button" type="button" :disabled="pageNavBarRight.disabled" @click="handlePageNavBarRightAction">
<t-icon :name="pageNavBarRight.icon" size="1.25rem" />
</button>
</t-badge>
<button
v-else-if="pageNavBarRight.icon"
class="button"
type="button"
:disabled="pageNavBarRight.disabled"
@click="handlePageNavBarRightAction"
>
<t-icon :name="pageNavBarRight.icon" size="1.25rem" />
</button>
<button
v-else
class="nav-text"
type="button"
:disabled="pageNavBarRight.disabled"
:style="{ color: pageNavBarRight.disabled ? 'var(--td-text-color-disabled)' : pageNavBarRight.textColor || 'var(--td-text-color-primary, #333)' }"
:class="{ clickable: !!pageNavBarRight.action, disabled: pageNavBarRight.disabled }"
@click="handlePageNavBarRightAction"
v-text="pageNavBarRight.text"
/>
</div>
</template>
</t-navbar>
<main v-can="corePermissionCodes.notify.read" class="page-content scroll list">
<t-pull-down-refresh
class="pull-refresh"
v-model="isRefreshing"
:refresh-timeout="30000"
@refresh="refresh"
@scrolltolower="loadMore"
>
<t-segmented
v-model="filterMode"
class="filter"
block
:options="filterOptions"
@change="switchFilter"
v-entrance-transition
/>
<t-cell-group v-if="pageResult.list.length" class="items fix-last-cell-line" theme="card">
<t-swipe-cell
v-for="item in pageResult.list"
:key="item.id"
class="item"
v-entrance-transition="{ step: 30 }"
>
<t-cell arrow hover @click="toDetail(item)">
<template #leftIcon>
<div class="icon" :class="{ unread: isUnread(item) }">
<t-icon name="notification" size="1.25rem" />
</div>
</template>
<template #title>
<div class="title">
<span v-text="getSubject(item)" />
</div>
</template>
<template #description>
<pass-time-label :timestamp="item.sendAt" underline />
</template>
<template #note>
<t-tag
v-if="filterMode === 'all' && isUnread(item)"
class="unread-label"
theme="danger"
size="small"
>未读</t-tag>
</template>
</t-cell>
<template #right>
<t-button
class="delete"
theme="danger"
size="small"
>未读</t-tag>
:loading="deletingId === item.id"
@click.stop="confirmDelete(item)"
>
删除
</t-button>
</template>
</t-cell>
<template #right>
<t-button
class="delete"
theme="danger"
:loading="deletingId === item.id"
@click.stop="confirmDelete(item)"
>
删除
</t-button>
</template>
</t-swipe-cell>
</t-cell-group>
<t-empty
v-else-if="!isLoading"
description="暂无站内通知"
/>
<div class="center-tips" v-text="loadStateText" />
</t-pull-down-refresh>
</t-swipe-cell>
</t-cell-group>
<t-empty
v-else-if="!isLoading"
description="暂无站内通知"
/>
<div class="center-tips" v-text="loadStateText" />
</t-pull-down-refresh>
</main>
</div>
</template>
@@ -70,10 +118,41 @@ import { PassTimeLabel } from "timi-web";
import { NotifyAPI, type NotifyDetail, type Page, type PageResult, useUserStore } from "timi-web-api";
import { DialogPlugin } from "tdesign-mobile-vue";
import { Message } from "@/utils/message";
import { useNavBarStore } from "@/store/navBarStore";
import { getErrorMessage } from "@/utils/error";
import { corePermissionCodes } from "@/utils/permission";
const pageNavBarRight = reactive({
icon: "",
badge: undefined as number | undefined,
text: "",
textColor: "",
disabled: false,
action: undefined as (() => void | Promise<void>) | undefined
});
function setPageNavBarRightText(value?: string, color?: string, action?: () => void | Promise<void>): void {
pageNavBarRight.text = value || "";
pageNavBarRight.textColor = color || "";
pageNavBarRight.disabled = false;
pageNavBarRight.action = action;
if (value) {
pageNavBarRight.badge = undefined;
pageNavBarRight.icon = "";
}
}
function clearPageNavBarRight(): void {
Object.assign(pageNavBarRight, { icon: "", badge: undefined, text: "", textColor: "", disabled: false, action: undefined });
}
async function handlePageNavBarRightAction(): Promise<void> {
if (pageNavBarRight.disabled || !pageNavBarRight.action) {
return;
}
await pageNavBarRight.action();
}
import { getErrorMessage } from "@/utils/error";
type NotifyFilter = "all" | "unread";
defineOptions({
@@ -82,7 +161,6 @@ defineOptions({
const pageSize = 20;
const router = useRouter();
const navBarStore = useNavBarStore();
const userStore = useUserStore();
const canReadNotify = computed(() => userStore.hasPermissions(corePermissionCodes.notify.read));
@@ -276,9 +354,9 @@ function updateNavBarAction(): void {
if (!isPageActive) {
return;
}
navBarStore.clearRight();
clearPageNavBarRight();
if (0 < unreadCount.value) {
navBarStore.setRightText("全部已读", "var(--td-brand-color)", markAllRead);
setPageNavBarRightText("全部已读", "var(--td-brand-color)", markAllRead);
}
}
@@ -305,7 +383,7 @@ async function toDetail(item: NotifyDetail): Promise<void> {
// ---------- 生命周期 ----------
onMounted(async () => {
navBarStore.clearRight();
clearPageNavBarRight();
if (!canReadNotify.value) {
return;
}
@@ -320,7 +398,7 @@ onMounted(async () => {
onUnmounted(() => {
isPageActive = false;
navBarStore.clearRight();
clearPageNavBarRight();
});
</script>
@@ -407,4 +485,45 @@ onUnmounted(() => {
}
}
}
.nav-right-slot {
width: 6rem;
height: 100%;
display: flex;
align-items: center;
justify-content: flex-end;
.badge {
:deep(.t-badge__content) {
display: flex;
align-items: center;
}
}
.button,
.nav-text {
color: var(--td-text-color-primary, #333);
border: none;
padding: 0;
display: inline-flex;
background: transparent;
align-items: center;
justify-content: center;
}
.button {
&:disabled {
color: var(--td-text-color-disabled);
cursor: not-allowed;
}
}
.nav-text {
font: inherit;
cursor: default;
&.clickable { cursor: pointer; }
&.disabled { cursor: not-allowed; }
}
}
</style>