simple navbar action
This commit is contained in:
@@ -7,41 +7,12 @@
|
||||
@left-click="$router.back()"
|
||||
>
|
||||
<template #right>
|
||||
<div
|
||||
v-if="pageNavBarRight.icon || pageNavBarRight.text"
|
||||
class="nav-right-slot"
|
||||
>
|
||||
<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>
|
||||
<button
|
||||
class="nav-action"
|
||||
type="button"
|
||||
@click="saveNotification"
|
||||
v-text="scheduleAtText ? '提交' : '发送'"
|
||||
></button>
|
||||
</template>
|
||||
</t-navbar>
|
||||
<div v-can="corePermissionCodes.notify.create" class="notify-management-create">
|
||||
@@ -128,36 +99,9 @@ import NotifyRecipientPicker, {
|
||||
} from "@/pages/notify/component/NotifyRecipientPicker.vue";
|
||||
import { corePermissionCodes, coreRoleCodes, gaoRoleCodes, permissionCodes } 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 { useCurrentStoreStore } from "@/store/currentStoreStore";
|
||||
|
||||
@@ -266,11 +210,7 @@ const scheduleAtText = ref("");
|
||||
const scheduleDraftText = ref("");
|
||||
const minimumScheduleText = computed(() => Time.toDateTime(new Date(Time.now() + Time.M)));
|
||||
|
||||
function updateNavActionText(): void {
|
||||
setPageNavBarRightText(scheduleAtText.value ? "提交" : "发送", "var(--td-brand-color)", saveNotification);
|
||||
}
|
||||
|
||||
watch(scheduleAtText, updateNavActionText);
|
||||
|
||||
function getContentText(content: string): string {
|
||||
const parser = new DOMParser();
|
||||
@@ -431,7 +371,6 @@ async function loadRecipients(): Promise<void> {
|
||||
// ---------- 生命周期 ----------
|
||||
|
||||
onMounted(async () => {
|
||||
clearPageNavBarRight();
|
||||
if (!canCreate.value) {
|
||||
return;
|
||||
}
|
||||
@@ -441,11 +380,9 @@ onMounted(async () => {
|
||||
const loginStore = await currentStoreStore.loadLoginStore();
|
||||
recipientStoreId.value = loginStore?.id || currentStoreStore.currentStoreId || "";
|
||||
}
|
||||
updateNavActionText();
|
||||
await loadRecipients();
|
||||
});
|
||||
|
||||
onUnmounted(() => clearPageNavBarRight());
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
@@ -524,44 +461,4 @@ onUnmounted(() => clearPageNavBarRight());
|
||||
}
|
||||
}
|
||||
|
||||
.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>
|
||||
|
||||
@@ -7,41 +7,14 @@
|
||||
@left-click="$router.back()"
|
||||
>
|
||||
<template #right>
|
||||
<div
|
||||
v-if="pageNavBarRight.icon || pageNavBarRight.text"
|
||||
class="nav-right-slot"
|
||||
<button
|
||||
v-if="detail?.id && canDeleteNotify"
|
||||
class="nav-action danger"
|
||||
type="button"
|
||||
@click="confirmDelete"
|
||||
>
|
||||
<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>
|
||||
删除
|
||||
</button>
|
||||
</template>
|
||||
</t-navbar>
|
||||
<div v-can="corePermissionCodes.notify.read" class="notify-detail">
|
||||
@@ -91,36 +64,9 @@ import { getErrorMessage } from "@/utils/error";
|
||||
import { getAttachmentReadURL } from "@/utils/attachment";
|
||||
import NotifyContent from "@/pages/notify/component/NotifyContent.vue";
|
||||
|
||||
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 { corePermissionCodes } from "@/utils/permission";
|
||||
|
||||
@@ -183,7 +129,6 @@ async function loadDetail(): Promise<void> {
|
||||
const requestToken = loadToken + 1;
|
||||
loadToken = requestToken;
|
||||
detail.value = undefined;
|
||||
clearPageNavBarRight();
|
||||
const notifyId = String(route.params.id || "");
|
||||
if (!notifyId) {
|
||||
return;
|
||||
@@ -196,7 +141,6 @@ async function loadDetail(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
detail.value = result;
|
||||
setRightAction();
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "通知详情加载失败"));
|
||||
} finally {
|
||||
@@ -206,11 +150,6 @@ async function loadDetail(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
function setRightAction(): void {
|
||||
if (detail.value?.id && canDeleteNotify.value) {
|
||||
setPageNavBarRightText("删除", "var(--td-error-color)", confirmDelete);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- 通知操作 ----------
|
||||
|
||||
@@ -263,14 +202,12 @@ async function confirmDelete(): Promise<void> {
|
||||
async onConfirm() {
|
||||
dialog.destroy();
|
||||
isDeleting.value = true;
|
||||
clearPageNavBarRight();
|
||||
try {
|
||||
await NotifyAPI.managementDelete(notifyId);
|
||||
Message.success("通知已删除");
|
||||
await router.replace({ name: "NotifyList" });
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "通知删除失败"));
|
||||
setRightAction();
|
||||
} finally {
|
||||
isDeleting.value = false;
|
||||
}
|
||||
@@ -332,8 +269,6 @@ watch(() => route.params.id, async () => {
|
||||
await loadDetail();
|
||||
}, { immediate: true });
|
||||
|
||||
onMounted(() => clearPageNavBarRight());
|
||||
onUnmounted(() => clearPageNavBarRight());
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
@@ -357,44 +292,4 @@ onUnmounted(() => clearPageNavBarRight());
|
||||
}
|
||||
}
|
||||
|
||||
.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>
|
||||
|
||||
@@ -8,41 +8,7 @@
|
||||
@left-click="$router.back()"
|
||||
>
|
||||
<template #right>
|
||||
<div
|
||||
v-if="pageNavBarRight.icon || pageNavBarRight.text"
|
||||
class="nav-right-slot"
|
||||
>
|
||||
<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>
|
||||
<button v-if="canReadNotify && canCreateNotify" class="nav-action" type="button" @click="toCreate">新建</button>
|
||||
</template>
|
||||
</t-navbar>
|
||||
<main v-can="corePermissionCodes.notify.read" class="page-content scroll list">
|
||||
@@ -113,36 +79,9 @@ import { DialogPlugin } from "tdesign-mobile-vue";
|
||||
import { Message } from "@/utils/message";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
|
||||
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 { corePermissionCodes } from "@/utils/permission";
|
||||
|
||||
@@ -333,17 +272,14 @@ async function confirmDelete(item: NotifyManagementItem): Promise<void> {
|
||||
// ---------- 生命周期 ----------
|
||||
|
||||
onMounted(async () => {
|
||||
clearPageNavBarRight();
|
||||
if (!canReadNotify.value) {
|
||||
return;
|
||||
}
|
||||
if (canCreateNotify.value) {
|
||||
setPageNavBarRightText("新建", "var(--td-brand-color)", toCreate);
|
||||
}
|
||||
await reloadList();
|
||||
});
|
||||
|
||||
onUnmounted(() => clearPageNavBarRight());
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
@@ -413,44 +349,4 @@ onUnmounted(() => clearPageNavBarRight());
|
||||
}
|
||||
}
|
||||
|
||||
.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>
|
||||
|
||||
@@ -7,41 +7,14 @@
|
||||
@left-click="$router.back()"
|
||||
>
|
||||
<template #right>
|
||||
<div
|
||||
v-if="pageNavBarRight.icon || pageNavBarRight.text"
|
||||
class="nav-right-slot"
|
||||
<button
|
||||
v-if="detail?.id"
|
||||
class="nav-action danger"
|
||||
type="button"
|
||||
@click="confirmDelete"
|
||||
>
|
||||
<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>
|
||||
删除
|
||||
</button>
|
||||
</template>
|
||||
</t-navbar>
|
||||
<div v-can="corePermissionCodes.notify.read" class="notify-detail">
|
||||
@@ -67,36 +40,9 @@ import { corePermissionCodes } from "@/utils/permission";
|
||||
import { Message } from "@/utils/message.ts";
|
||||
import NotifyContent from "@/pages/notify/component/NotifyContent.vue";
|
||||
|
||||
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";
|
||||
|
||||
@@ -117,7 +63,6 @@ let loadToken = 0;
|
||||
async function loadDetail(): Promise<void> {
|
||||
const requestToken = loadToken + 1;
|
||||
loadToken = requestToken;
|
||||
clearPageNavBarRight();
|
||||
const detailId = String(route.params.id || "");
|
||||
if (!detailId) {
|
||||
detail.value = undefined;
|
||||
@@ -133,7 +78,6 @@ async function loadDetail(): Promise<void> {
|
||||
}
|
||||
|
||||
detail.value = result;
|
||||
setDeleteAction();
|
||||
await markRead(result, requestToken);
|
||||
} catch (error) {
|
||||
console.warn("通知详情加载失败", error);
|
||||
@@ -145,11 +89,6 @@ async function loadDetail(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
function setDeleteAction(): void {
|
||||
if (detail.value?.id) {
|
||||
setPageNavBarRightText("删除", "var(--td-error-color)", confirmDelete);
|
||||
}
|
||||
}
|
||||
|
||||
async function confirmDelete(): Promise<void> {
|
||||
const detailId = detail.value?.id;
|
||||
@@ -178,14 +117,12 @@ async function deleteDetail(detailId: string): Promise<void> {
|
||||
}
|
||||
|
||||
isDeleting.value = true;
|
||||
clearPageNavBarRight();
|
||||
try {
|
||||
await NotifyAPI.deleteInternal(detailId);
|
||||
Message.success("通知已删除");
|
||||
await router.replace({ name: "UserNotifyList" });
|
||||
} catch (error) {
|
||||
Message.error(getErrorMessage(error, "通知删除失败"));
|
||||
setDeleteAction();
|
||||
} finally {
|
||||
isDeleting.value = false;
|
||||
}
|
||||
@@ -224,13 +161,7 @@ watch(() => route.params.id, async () => {
|
||||
await loadDetail();
|
||||
}, { immediate: true });
|
||||
|
||||
onMounted(() => {
|
||||
clearPageNavBarRight();
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
clearPageNavBarRight();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
@@ -238,44 +169,4 @@ onUnmounted(() => {
|
||||
padding: var(--app-nav-height) 0 1rem 0;
|
||||
}
|
||||
|
||||
.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>
|
||||
|
||||
@@ -8,41 +8,14 @@
|
||||
@left-click="$router.back()"
|
||||
>
|
||||
<template #right>
|
||||
<div
|
||||
v-if="pageNavBarRight.icon || pageNavBarRight.text"
|
||||
class="nav-right-slot"
|
||||
<button
|
||||
v-if="canReadNotify && 0 < unreadCount"
|
||||
class="nav-action"
|
||||
type="button"
|
||||
@click="markAllRead"
|
||||
>
|
||||
<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>
|
||||
全部已读
|
||||
</button>
|
||||
</template>
|
||||
</t-navbar>
|
||||
<main v-can="corePermissionCodes.notify.read" class="page-content scroll list">
|
||||
@@ -120,36 +93,9 @@ import { DialogPlugin } from "tdesign-mobile-vue";
|
||||
import { Message } from "@/utils/message";
|
||||
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";
|
||||
|
||||
@@ -189,7 +135,6 @@ const pageResult = reactive<PageResult<NotifyDetail>>({
|
||||
});
|
||||
let loadToken = 0;
|
||||
let loadingPromise: Promise<void> | undefined;
|
||||
let isPageActive = true;
|
||||
|
||||
const loadStateText = computed(() => {
|
||||
if (isLoading.value) {
|
||||
@@ -279,7 +224,6 @@ async function loadUnreadCount(): Promise<void> {
|
||||
unreadCount.value = 0;
|
||||
console.warn("未读通知数量加载失败", error);
|
||||
} finally {
|
||||
updateNavBarAction();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -307,7 +251,6 @@ async function markAllRead(): Promise<void> {
|
||||
Message.error("全部标记已读失败");
|
||||
} finally {
|
||||
isMarkingAllRead.value = false;
|
||||
updateNavBarAction();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -350,15 +293,6 @@ async function deleteNotification(detailId: string): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
function updateNavBarAction(): void {
|
||||
if (!isPageActive) {
|
||||
return;
|
||||
}
|
||||
clearPageNavBarRight();
|
||||
if (0 < unreadCount.value) {
|
||||
setPageNavBarRightText("全部已读", "var(--td-brand-color)", markAllRead);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- 展示和导航 ----------
|
||||
|
||||
@@ -383,7 +317,6 @@ async function toDetail(item: NotifyDetail): Promise<void> {
|
||||
// ---------- 生命周期 ----------
|
||||
|
||||
onMounted(async () => {
|
||||
clearPageNavBarRight();
|
||||
if (!canReadNotify.value) {
|
||||
return;
|
||||
}
|
||||
@@ -396,10 +329,6 @@ onMounted(async () => {
|
||||
}
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
isPageActive = false;
|
||||
clearPageNavBarRight();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
@@ -486,44 +415,4 @@ 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>
|
||||
|
||||
Reference in New Issue
Block a user