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
+122 -7
View File
@@ -1,4 +1,49 @@
<template>
<t-navbar
fixed
:z-index="20"
title="产品分类排序"
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="permissionCodes.productCategory.update" class="product-category-rank">
<div class="tip" v-text="'按住右侧拖动手柄调整分类顺序,保存后生效'" />
<div class="items">
@@ -44,16 +89,45 @@
import type { TagProps } from "tdesign-mobile-vue";
import { VueDraggableNext } from "vue-draggable-next";
import ProductAPI from "@/api/ProductAPI";
import { useNavBarStore } from "@/store/navBarStore";
import type { ProductCategory, ProductCategoryStatus } from "@/types/Product";
import { getErrorMessage } from "@/utils/error";
import { Message } from "@/utils/message";
import { permissionCodes } from "@/utils/permission";
import { useUserStore } from "timi-web-api";
defineOptions({ name: "ProductCategoryRank" });
const pageNavBarRight = reactive({
icon: "",
badge: undefined as number | undefined,
text: "",
textColor: "",
disabled: false,
action: undefined as (() => void | Promise<void>) | undefined
});
const navBarStore = useNavBarStore();
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 { ProductCategory, ProductCategoryStatus } from "@/types/Product";
defineOptions({ name: "ProductCategoryRank" });
const userStore = useUserStore();
const router = useRouter();
@@ -109,9 +183,9 @@ async function loadData(): Promise<void> {
}
onMounted(async () => {
navBarStore.clearRight();
clearPageNavBarRight();
if (userStore.hasPermissions(permissionCodes.productCategory.update)) {
navBarStore.setRightText("保存", "var(--td-brand-color)", saveSort);
setPageNavBarRightText("保存", "var(--td-brand-color)", saveSort);
}
try {
await loadData();
@@ -121,7 +195,7 @@ onMounted(async () => {
});
onUnmounted(() => {
navBarStore.clearRight();
clearPageNavBarRight();
});
</script>
@@ -186,4 +260,45 @@ 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>