simple navbar action

This commit is contained in:
Timi
2026-10-22 16:17:22 +08:00
parent de8374db0b
commit 1eef8c6ea1
52 changed files with 358 additions and 5516 deletions
+6 -108
View File
@@ -7,41 +7,13 @@
@left-click="$router.back()"
>
<template #right>
<div
v-if="pageNavBarRight.icon || pageNavBarRight.text"
class="nav-right-slot"
<button
class="nav-action"
type="button"
@click="save"
>
<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="permissionCodes.pointRedeemSku.manage" class="redeem-sku-edit">
@@ -109,37 +81,6 @@ import { Message } from "@/utils/message";
import { normalizePackageQuantity } from "@/utils/package";
import { 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 type { PointRedeemSku, PointRedeemSkuStatus } from "@/types/Point";
defineOptions({ name: "PointRedeemSkuEdit" });
@@ -274,15 +215,12 @@ async function remove(): Promise<void> {
}
onMounted(async () => {
setPageNavBarRightText("保存", "var(--td-brand-color)", save);
try {
await load();
} catch (error) {
Message.error(getErrorMessage(error, "兑换配置加载失败"));
}
});
onUnmounted(() => clearPageNavBarRight());
</script>
<style scoped lang="less">
@@ -297,44 +235,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>
+6 -103
View File
@@ -7,41 +7,13 @@
@left-click="$router.back()"
>
<template #right>
<div
v-if="pageNavBarRight.icon || pageNavBarRight.text"
class="nav-right-slot"
<button
class="nav-action"
type="button"
@click="save"
>
<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="permissionCodes.pointRedemption.create" class="redemption-create">
@@ -189,36 +161,9 @@ import { getProductPhotoURL, getProductQuantityStep } from "@/utils/product";
import { uploadPhotoList } from "@/utils/photo";
import { 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 { useSettingStore } from "@/store/settingStore";
@@ -404,7 +349,6 @@ function formatPoint(value?: number): string {
}
onMounted(async () => {
setPageNavBarRightText("兑换", "var(--td-brand-color)", save);
try {
await loadSkuList();
} catch (error) {
@@ -412,7 +356,6 @@ onMounted(async () => {
}
});
onUnmounted(() => clearPageNavBarRight());
</script>
<style scoped lang="less">
@@ -485,44 +428,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 -115
View File
@@ -7,41 +7,14 @@
@left-click="$router.back()"
>
<template #right>
<div
v-if="pageNavBarRight.icon || pageNavBarRight.text"
class="nav-right-slot"
<button
v-if="rule?.id && canUpdate"
class="nav-action"
type="button"
@click="toEdit"
>
<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="permissionCodes.pointRule.read" class="point-rule-detail">
@@ -147,36 +120,9 @@ import { Message } from "@/utils/message";
import { formatWanInteger } from "@/utils/money";
import { 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 type { EventItem } from "@/types/EventItem";
@@ -332,14 +278,12 @@ async function removeRule(): Promise<void> {
}
isDeleting.value = true;
clearPageNavBarRight();
try {
await PointAPI.ruleRemove(ruleId);
Message.success("积分规则已删除");
await router.replace("/management/points/rules");
} catch (error) {
Message.error(getErrorMessage(error, "积分规则删除失败"));
setEditAction();
} finally {
isDeleting.value = false;
}
@@ -347,11 +291,6 @@ async function removeRule(): Promise<void> {
// ---------- 导航 ----------
function setEditAction(): void {
if (canUpdate.value) {
setPageNavBarRightText("编辑", "var(--td-brand-color)", toEdit);
}
}
async function toEdit(): Promise<void> {
const ruleId = String(route.params.id || "");
@@ -380,14 +319,7 @@ watch(() => route.params.id, async () => {
await loadRule();
}, { immediate: true });
onMounted(() => {
clearPageNavBarRight();
setEditAction();
});
onUnmounted(() => {
clearPageNavBarRight();
});
</script>
<style scoped lang="less">
@@ -467,44 +399,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>
+7 -110
View File
@@ -7,41 +7,14 @@
@left-click="$router.back()"
>
<template #right>
<div
v-if="pageNavBarRight.icon || pageNavBarRight.text"
class="nav-right-slot"
<button
v-if="userStore.hasPermissions(savePermissionCode)"
class="nav-action"
type="button"
@click="saveRule"
>
<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="pageAccess" class="point-rule-edit">
@@ -202,37 +175,6 @@ import { getErrorMessage } from "@/utils/error";
import { gaoRoleCodes, permissionCodes } from "@/utils/permission";
import { Message } from "@/utils/message";
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 type { EventItem } from "@/types/EventItem";
type PickerValue = string | number;
@@ -622,17 +564,12 @@ async function fillForm(): Promise<void> {
}
onMounted(async () => {
if (userStore.hasPermissions(savePermissionCode.value)) {
setPageNavBarRightText("保存", "var(--td-brand-color)", saveRule);
}
try {
await fillForm();
} catch (error) {
Message.error(getErrorMessage(error, "积分规则加载失败"));
}
});
onUnmounted(() => clearPageNavBarRight());
</script>
<style scoped lang="less">
@@ -689,44 +626,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>
+2 -112
View File
@@ -7,41 +7,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 class="nav-action" type="button" @click="saveSort">保存</button>
</template>
</t-navbar>
<div v-can="permissionCodes.pointRule.update" class="point-rule-sort">
@@ -95,42 +61,10 @@ import { VueDraggableNext } from "vue-draggable-next";
import EventAPI from "@/api/EventAPI";
import PointAPI from "@/api/PointAPI";
import type { PointRule } from "@/types/Point";
import type { EventItem } from "@/types/EventItem";
import { formatWanInteger } from "@/utils/money";
import { 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 type { EventItem } from "@/types/EventItem";
defineOptions({ name: "PointRuleSort" });
const router = useRouter();
const ruleList = ref<PointRule[]>([]);
@@ -185,16 +119,12 @@ async function saveSort(): Promise<void> {
}
onMounted(async () => {
clearPageNavBarRight();
setPageNavBarRightText("保存", "var(--td-brand-color)", saveSort);
try {
await loadData();
} catch {
Message.error("启用积分规则加载失败");
}
});
onUnmounted(() => clearPageNavBarRight());
</script>
<style scoped lang="less">
@@ -232,44 +162,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>