simple navbar action
This commit is contained in:
+13
-112
@@ -5,41 +5,17 @@
|
||||
title="客户"
|
||||
>
|
||||
<template #right>
|
||||
<div
|
||||
v-if="pageNavBarRight.icon || pageNavBarRight.text"
|
||||
class="nav-right-slot"
|
||||
<t-badge
|
||||
v-if="canReadNotify"
|
||||
class="notification-badge"
|
||||
:count="unreadNotifyCount"
|
||||
:max-count="99"
|
||||
:show-zero="false"
|
||||
>
|
||||
<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 class="nav-action nav-action-icon" type="button" aria-label="通知" @click="router.push('/notify')">
|
||||
<t-icon name="notification" 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>
|
||||
</t-badge>
|
||||
</template>
|
||||
</t-navbar>
|
||||
<main class="page-content scroll column home-tab">
|
||||
@@ -101,40 +77,10 @@
|
||||
<script setup lang="ts">
|
||||
import { NotifyAPI, useUserStore } from "timi-web-api";
|
||||
|
||||
const pageNavBarRight = reactive({
|
||||
icon: "",
|
||||
badge: undefined as number | undefined,
|
||||
text: "",
|
||||
textColor: "",
|
||||
disabled: false,
|
||||
action: undefined as (() => void | Promise<void>) | undefined
|
||||
});
|
||||
|
||||
function setPageNavBarRightIcon(value?: string, action?: () => void | Promise<void>): void {
|
||||
pageNavBarRight.icon = value || "";
|
||||
pageNavBarRight.badge = undefined;
|
||||
pageNavBarRight.disabled = false;
|
||||
pageNavBarRight.action = action;
|
||||
if (value) {
|
||||
pageNavBarRight.text = "";
|
||||
pageNavBarRight.textColor = "";
|
||||
}
|
||||
}
|
||||
|
||||
function setPageNavBarRightBadge(value?: number): void {
|
||||
pageNavBarRight.badge = value === undefined ? undefined : Math.max(0, value);
|
||||
}
|
||||
|
||||
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 { corePermissionCodes, gaoRoleCodes, permissionCodes } from "@/utils/permission";
|
||||
|
||||
@@ -145,7 +91,6 @@ defineOptions({
|
||||
const router = useRouter();
|
||||
const userStore = useUserStore();
|
||||
const unreadNotifyCount = ref(0);
|
||||
let isPageActive = true;
|
||||
|
||||
interface HomeEntry {
|
||||
path: string;
|
||||
@@ -242,26 +187,15 @@ async function loadUnreadNotifyCount(): Promise<void> {
|
||||
unreadNotifyCount.value = 0;
|
||||
console.warn("未读通知数量加载失败", error);
|
||||
}
|
||||
if (isPageActive) {
|
||||
setPageNavBarRightBadge(unreadNotifyCount.value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
clearPageNavBarRight();
|
||||
if (canReadNotify.value) {
|
||||
setPageNavBarRightIcon("notification", async () => {
|
||||
await router.push("/notify");
|
||||
});
|
||||
setPageNavBarRightBadge(0);
|
||||
await loadUnreadNotifyCount();
|
||||
}
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
isPageActive = false;
|
||||
clearPageNavBarRight();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
@@ -368,44 +302,11 @@ 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;
|
||||
.notification-badge {
|
||||
:deep(.t-badge__content) {
|
||||
display: flex;
|
||||
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>
|
||||
|
||||
Reference in New Issue
Block a user