refactor layout

This commit is contained in:
Timi
2026-10-17 12:01:28 +08:00
parent fe467e8781
commit 469c595a7c
134 changed files with 11493 additions and 4437 deletions
+133 -6
View File
@@ -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="product-edit">
<t-form class="form" label-align="left" label-width="6rem" v-entrance-transition>
<t-form-item label="产品编码" required-mark help="使用英语、拼音或唯一数字">
@@ -216,8 +261,6 @@ import ProductSkuEditor from "@/pages/product/component/ProductSkuEditor.vue";
import ProductSkuUnitEditor from "@/pages/product/component/ProductSkuUnitEditor.vue";
import ProductSkuUnitBatchEditor from "@/pages/product/component/ProductSkuUnitBatchEditor.vue";
import type { MediaSelectorAddAction } from "@/components/mediaSelector/types";
import { useNavBarStore } from "@/store/navBarStore";
import type { PhotoItem } from "@/types/Photo";
import type { Product, ProductAttachmentType, ProductCategory, ProductSku, ProductSkuUnit, ProductSpec, ProductType } from "@/types/Product";
import type { ProductAttachmentItem, ProductForm, ProductSkuForm as SkuForm, ProductSkuUnitForm as UnitForm, ProductSpecForm as SpecForm, ProductSpecValueForm as SpecValueForm } from "@/types/ProductEditor";
import { compressUploadImage } from "@/utils/imageCompression";
@@ -229,6 +272,39 @@ import { Message } from "@/utils/message";
import { permissionCodes } from "@/utils/permission";
import { saveCapturedFilesFromInput } from "@/utils/twaBridge";
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 { PhotoItem } from "@/types/Photo";
type PickerValue = string | number;
const SOLID_COLOR_COVER_PURPOSE = "PRODUCT_SOLID_COLOR_COVER";
@@ -237,8 +313,18 @@ const DEFAULT_COVER_COLOR = "#2F88FF";
defineOptions({ name: "ProductEdit" });
const route = useRoute();
const routeNavBarTitle = computed(() => {
switch (route.name) {
case "ProductCreate":
return "新增产品";
case "ProductEdit":
return "编辑产品";
default:
return "";
}
});
const router = useRouter();
const navBarStore = useNavBarStore();
const userStore = useUserStore();
const routeId = computed(() => String(route.params.id || ""));
const isCreateMode = computed(() => !routeId.value);
@@ -1131,9 +1217,9 @@ async function load(): Promise<void> {
}
onMounted(async () => {
navBarStore.clearRight();
clearPageNavBarRight();
if (userStore.hasPermissions(savePermissionCode.value)) {
navBarStore.setRightText("保存", "var(--td-brand-color)", save);
setPageNavBarRightText("保存", "var(--td-brand-color)", save);
}
try {
await load();
@@ -1142,7 +1228,7 @@ onMounted(async () => {
}
});
onUnmounted(() => navBarStore.clearRight());
onUnmounted(() => clearPageNavBarRight());
</script>
<style scoped lang="less">
@@ -1256,4 +1342,45 @@ onUnmounted(() => navBarStore.clearRight());
border-color: rgba(148, 163, 184, .3);
}
}
.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>