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>
|
||||
|
||||
Reference in New Issue
Block a user