refactor layout
This commit is contained in:
@@ -1,4 +1,49 @@
|
||||
<template>
|
||||
<t-navbar
|
||||
fixed
|
||||
:z-index="20"
|
||||
:title="routeNavBarTitle"
|
||||
left-arrow
|
||||
@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>
|
||||
</template>
|
||||
</t-navbar>
|
||||
<div v-can="savePermissionCode" class="package-config-edit">
|
||||
<t-form class="form" label-align="left" label-width="6rem" v-entrance-transition>
|
||||
<t-form-item label="套餐名称" required-mark>
|
||||
@@ -112,29 +157,74 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { AnimatedAmount, AnimatedNumber, Time } from "timi-web";
|
||||
import { AnimatedAmount, Time } from "timi-web";
|
||||
import { useUserStore } from "timi-web-api";
|
||||
import PackageAPI from "@/api/PackageAPI";
|
||||
import ProductSelectFormItem from "@/components/productSelector/ProductSelectFormItem.vue";
|
||||
import { useCurrentStoreStore } from "@/store/currentStoreStore";
|
||||
import { useNavBarStore } from "@/store/navBarStore";
|
||||
import type { GaoPackageConfig, PackageConfigItem, PackageConfigStatus } from "@/types/Package";
|
||||
import ProductAPI from "@/api/ProductAPI";
|
||||
import type { Product, ProductSelection, ProductSku, ProductSkuUnit } from "@/types/Product";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { formatPackageAmountInput, getPackageConfigStatusText, normalizePackageQuantity, parsePackageAmount } from "@/utils/package";
|
||||
import {
|
||||
formatPackageAmountInput,
|
||||
getPackageConfigStatusText,
|
||||
normalizePackageQuantity,
|
||||
parsePackageAmount
|
||||
} from "@/utils/package";
|
||||
import { Message } from "@/utils/message";
|
||||
import { gaoRoleCodes, permissionCodes } from "@/utils/permission";
|
||||
import { formatProductAmount, getProductQuantityStep } from "@/utils/product";
|
||||
import { getProductQuantityStep } from "@/utils/product";
|
||||
import type { GaoPackageConfig, PackageConfigItem, PackageConfigStatus } from "@/types/Package";
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
type PackageConfigFormItem = Partial<PackageConfigItem> & { clientKey: string };
|
||||
|
||||
defineOptions({ name: "PackageConfigEdit" });
|
||||
|
||||
const route = useRoute();
|
||||
|
||||
const routeNavBarTitle = computed(() => {
|
||||
switch (route.name) {
|
||||
case "PackageConfigCreate":
|
||||
return "新增套餐配置";
|
||||
case "PackageConfigEdit":
|
||||
return "编辑套餐配置";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
});
|
||||
const router = useRouter();
|
||||
const userStore = useUserStore();
|
||||
const navBarStore = useNavBarStore();
|
||||
const currentStoreStore = useCurrentStoreStore();
|
||||
const routeId = computed(() => String(route.params.id || ""));
|
||||
const isCreateMode = computed(() => !routeId.value);
|
||||
@@ -434,7 +524,7 @@ async function loadData(): Promise<void> {
|
||||
|
||||
onMounted(async () => {
|
||||
if (userStore.hasPermissions(savePermissionCode.value)) {
|
||||
navBarStore.setRightText("保存", "var(--td-brand-color)", save);
|
||||
setPageNavBarRightText("保存", "var(--td-brand-color)", save);
|
||||
}
|
||||
try {
|
||||
await loadData();
|
||||
@@ -443,7 +533,7 @@ onMounted(async () => {
|
||||
}
|
||||
});
|
||||
|
||||
onUnmounted(() => navBarStore.clearRight());
|
||||
onUnmounted(() => clearPageNavBarRight());
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
@@ -547,4 +637,45 @@ onUnmounted(() => navBarStore.clearRight());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.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