refactor(frontend): 优化订单状态卡片和产品卡片的交互和样式

- OrderStatusCard 重构布局,按钮移到右上角,新增悬停阴影和圆角设计
- ProductCard 大幅重构 UI 样式,增强视觉层次和交互反馈
- 修复 TabBar / use-tabbar hooks 在特定场景下的状态同步问题
- CategoryFormModal / ProductFormModal 同步样式适配
This commit is contained in:
小蟑螂
2026-05-05 21:53:29 +08:00
parent c6025a7c2c
commit 0a02207dfd
9 changed files with 724 additions and 383 deletions
@@ -1,7 +1,7 @@
<script lang="ts" setup>
import type { CategoryDTO, CategoryVO } from '#/api/ecommerce/category';
import { computed, ref, watch } from 'vue';
import { ref, watch } from 'vue';
import { useVbenModal } from '@vben/common-ui';
@@ -13,12 +13,12 @@ const props = defineProps<{
const emit = defineEmits<{
delete: [OrderStatusVO.Info];
edit: [OrderStatusVO.Info];
/** 成功时携带 PATCH 返回的最新 VO;失败时不传,由父级决定是否重新拉列表 */
patched: [vo?: OrderStatusVO.Info];
}>();
const EditIcon = createIconifyIcon('lucide:pencil');
const TrashIcon = createIconifyIcon('lucide:trash-2');
const RefundIcon = createIconifyIcon('lucide:rotate-ccw');
type StatKey = keyof Pick<
OrderStatusVO.Info,
@@ -29,7 +29,6 @@ type StatKey = keyof Pick<
| 'includeRefund'
>;
/** 后端 / JSON 可能为 0、1、'0'、'1';Switch 在 checkedValue=1 时须用 0|1 绑定 :checked,不能绑 boolean */
function dim01(v: unknown): 0 | 1 {
if (v === 1 || v === '1' || v === true) return 1;
return 0;
@@ -55,121 +54,178 @@ async function handleDimChange(key: StatKey, next: unknown) {
<template>
<Card
hoverable
:body-style="{ padding: 0 }"
class="order-status-card group h-full"
class="order-status-card group h-full overflow-hidden rounded-3xl border border-slate-200 bg-white shadow-[0_4px_14px_-2px_rgba(15,23,42,0.08),0_2px_6px_-2px_rgba(15,23,42,0.06)] transition-transform duration-200 hover:-translate-y-0.5 hover:border-slate-300 hover:shadow-[0_20px_28px_-8px_rgba(15,23,42,0.14),0_8px_16px_-6px_rgba(15,23,42,0.08)] dark:border-neutral-600 dark:bg-[hsl(222.34deg_10.43%_12.27%)] dark:shadow-[0_1px_0_0_rgb(255_255_255/0.06)_inset] dark:hover:border-neutral-500 dark:hover:shadow-[0_12px_40px_-12px_rgb(0_0_0/0.45)]"
>
<div class="card-head">
<div class="flex min-w-0 flex-1 items-center gap-2">
<span
class="max-w-[70%] truncate text-base font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]"
<!-- 操作:单独一行,状态名称区域占满宽 -->
<div class="flex justify-end gap-0.5 px-8 pt-3 pb-0.5">
<Button
type="text"
class="!flex !h-11 !w-11 !items-center !justify-center !rounded-xl !text-slate-600 hover:!bg-blue-50 hover:!text-blue-600 dark:!text-neutral-300 dark:hover:!bg-blue-950/40 dark:hover:!text-blue-400"
@click="emit('edit', status)"
>
<EditIcon class="h-6 w-6" />
</Button>
<Popconfirm title="确定删除该订单状态?" @confirm="emit('delete', status)">
<Button
type="text"
class="!flex !h-11 !w-11 !items-center !justify-center !rounded-xl !text-slate-600 hover:!bg-red-50 hover:!text-red-600 dark:!text-neutral-300 dark:hover:!bg-red-950/30 dark:hover:!text-red-400"
>
{{ status.statusName }}
</span>
<span
v-if="status.sortOrder != null"
class="shrink-0 rounded-md bg-slate-100 px-2 py-0.5 text-xs text-slate-500 dark:bg-[hsl(240deg_3.7%_22%)] dark:text-[hsl(240deg_5%_64.9%)]"
>
排序 {{ status.sortOrder }}
</span>
</div>
<div class="flex shrink-0 items-center gap-1 opacity-80 transition-opacity group-hover:opacity-100">
<Button type="text" size="small" @click="emit('edit', status)">
<EditIcon class="h-4 w-4" />
<TrashIcon class="h-6 w-6" />
</Button>
<Popconfirm title="确定删除该订单状态?" @confirm="emit('delete', status)">
<Button type="text" size="small" danger>
<TrashIcon class="h-4 w-4" />
</Button>
</Popconfirm>
</div>
</Popconfirm>
</div>
<!-- 布局与 OrderStatusFormModal 中 Form 区块对齐(只读展示 + 维度开关) -->
<div class="card-body">
<div class="grid grid-cols-1 gap-4 sm:grid-cols-2">
<div class="min-w-0">
<div class="mb-1 text-sm text-muted-foreground">状态名称</div>
<div class="text-sm font-medium text-foreground">
<!-- 状态名称 + 描述:整行留给标题 -->
<div
class="order-status-card-hero border-b border-slate-200 bg-slate-50/60 px-8 pb-6 pt-1 dark:border-neutral-700 dark:bg-neutral-900/35"
>
<div class="flex min-w-0 items-start gap-4">
<div
class="mt-1 h-12 w-1.5 shrink-0 rounded-full bg-blue-600 dark:bg-blue-500"
/>
<div class="min-w-0 flex-1">
<h1
class="break-words text-4xl font-black leading-tight tracking-tight text-gray-950 dark:text-neutral-50"
>
{{ status.statusName }}
</div>
</div>
<div class="min-w-0">
<div class="mb-1 text-sm text-muted-foreground">状态描述</div>
</h1>
<p
class="desc-preview whitespace-pre-wrap text-sm text-foreground/90"
class="desc-under-title mt-2 text-sm font-medium italic leading-relaxed text-gray-600 dark:text-neutral-400"
>
{{ status.description || '—' }}
</p>
</div>
</div>
</div>
<div class="mb-2 mt-4 text-sm font-medium text-foreground">
统计维度
<div class="bg-white px-8 pb-8 pt-1 dark:bg-transparent">
<div class="mb-6 mt-5 flex items-center gap-2">
<span
class="text-xs font-bold uppercase tracking-widest text-slate-600 dark:text-neutral-400"
>
统计维度设置
</span>
<div class="h-px flex-1 bg-slate-200 dark:bg-neutral-600" />
</div>
<div class="grid grid-cols-1 gap-x-4 gap-y-2 sm:grid-cols-2">
<div class="grid grid-cols-1 gap-4 sm:grid-cols-2">
<!-- 销售额 -->
<div
class="stat-dim-row stat-dim--sales flex items-center justify-between gap-2 rounded-lg border border-slate-100 border-l-[3px] border-l-blue-500 bg-blue-50/70 px-3 py-2 dark:border-[hsl(240deg_3.7%_22%)] dark:border-l-sky-400 dark:bg-sky-950/25"
class="stat-tile stat-tile--sales group flex cursor-default flex-col justify-between rounded-2xl border border-slate-200 bg-slate-50 p-4 shadow-sm transition-all hover:border-blue-300 hover:bg-blue-50/80 hover:shadow-md dark:border-neutral-600 dark:bg-neutral-800 dark:shadow-none dark:hover:border-blue-600 dark:hover:bg-blue-950/35"
>
<span class="text-sm text-muted-foreground">计入销售额 / 单量</span>
<Switch
:checked="dim01(status.includeSalesAmount)"
:checked-value="1"
:un-checked-value="0"
checked-children="计入"
un-checked-children="不计入"
@update:checked="(v: unknown) => handleDimChange('includeSalesAmount', v)"
/>
<span
class="text-sm font-bold text-gray-800 transition-colors group-hover:text-blue-800 dark:text-neutral-100 dark:group-hover:text-blue-300"
>销售额/单量</span
>
<div class="mt-4 flex items-center justify-between">
<span
class="text-[10px] font-bold uppercase text-slate-600 dark:text-neutral-400"
>计入统计</span
>
<Switch
size="small"
class="stat-tile-switch"
:checked="dim01(status.includeSalesAmount)"
:checked-value="1"
:un-checked-value="0"
@update:checked="(v: unknown) => handleDimChange('includeSalesAmount', v)"
/>
</div>
</div>
<!-- 商品成本 -->
<div
class="stat-dim-row stat-dim--product flex items-center justify-between gap-2 rounded-lg border border-slate-100 border-l-[3px] border-l-emerald-500 bg-emerald-50/70 px-3 py-2 dark:border-[hsl(240deg_3.7%_22%)] dark:border-l-emerald-400 dark:bg-emerald-950/25"
class="stat-tile stat-tile--product group flex cursor-default flex-col justify-between rounded-2xl border border-slate-200 bg-slate-50 p-4 shadow-sm transition-all hover:border-emerald-300 hover:bg-emerald-50/80 hover:shadow-md dark:border-neutral-600 dark:bg-neutral-800 dark:shadow-none dark:hover:border-emerald-600 dark:hover:bg-emerald-950/35"
>
<span class="text-sm text-muted-foreground">计入商品成本</span>
<Switch
:checked="dim01(status.includeProductCost)"
:checked-value="1"
:un-checked-value="0"
checked-children="计入"
un-checked-children="不计入"
@update:checked="(v: unknown) => handleDimChange('includeProductCost', v)"
/>
<span
class="text-sm font-bold text-gray-800 transition-colors group-hover:text-emerald-800 dark:text-neutral-100 dark:group-hover:text-emerald-300"
>商品成本</span
>
<div class="mt-4 flex items-center justify-between">
<span
class="text-[10px] font-bold uppercase text-slate-600 dark:text-neutral-400"
>计入统计</span
>
<Switch
size="small"
class="stat-tile-switch"
:checked="dim01(status.includeProductCost)"
:checked-value="1"
:un-checked-value="0"
@update:checked="(v: unknown) => handleDimChange('includeProductCost', v)"
/>
</div>
</div>
<!-- 运费成本 -->
<div
class="stat-dim-row stat-dim--freight flex items-center justify-between gap-2 rounded-lg border border-slate-100 border-l-[3px] border-l-amber-500 bg-amber-50/70 px-3 py-2 dark:border-[hsl(240deg_3.7%_22%)] dark:border-l-amber-400 dark:bg-amber-950/25"
class="stat-tile stat-tile--freight group flex cursor-default flex-col justify-between rounded-2xl border border-slate-200 bg-slate-50 p-4 shadow-sm transition-all hover:border-amber-300 hover:bg-amber-50/80 hover:shadow-md dark:border-neutral-600 dark:bg-neutral-800 dark:shadow-none dark:hover:border-amber-600 dark:hover:bg-amber-950/35"
>
<span class="text-sm text-muted-foreground">计入运费成本</span>
<Switch
:checked="dim01(status.includeFreightCost)"
:checked-value="1"
:un-checked-value="0"
checked-children="计入"
un-checked-children="不计入"
@update:checked="(v: unknown) => handleDimChange('includeFreightCost', v)"
/>
<span
class="text-sm font-bold text-gray-800 transition-colors group-hover:text-amber-800 dark:text-neutral-100 dark:group-hover:text-amber-300"
>运费成本</span
>
<div class="mt-4 flex items-center justify-between">
<span
class="text-[10px] font-bold uppercase text-slate-600 dark:text-neutral-400"
>计入统计</span
>
<Switch
size="small"
class="stat-tile-switch"
:checked="dim01(status.includeFreightCost)"
:checked-value="1"
:un-checked-value="0"
@update:checked="(v: unknown) => handleDimChange('includeFreightCost', v)"
/>
</div>
</div>
<!-- 其他成本 -->
<div
class="stat-dim-row stat-dim--other flex items-center justify-between gap-2 rounded-lg border border-slate-100 border-l-[3px] border-l-violet-500 bg-violet-50/70 px-3 py-2 dark:border-[hsl(240deg_3.7%_22%)] dark:border-l-violet-400 dark:bg-violet-950/25"
class="stat-tile stat-tile--other group flex cursor-default flex-col justify-between rounded-2xl border border-slate-200 bg-slate-50 p-4 shadow-sm transition-all hover:border-purple-300 hover:bg-purple-50/80 hover:shadow-md dark:border-neutral-600 dark:bg-neutral-800 dark:shadow-none dark:hover:border-purple-600 dark:hover:bg-purple-950/35"
>
<span class="text-sm text-muted-foreground">计入其他成本</span>
<Switch
:checked="dim01(status.includeOtherCost)"
:checked-value="1"
:un-checked-value="0"
checked-children="计入"
un-checked-children="不计入"
@update:checked="(v: unknown) => handleDimChange('includeOtherCost', v)"
/>
<span
class="text-sm font-bold text-gray-800 transition-colors group-hover:text-purple-800 dark:text-neutral-100 dark:group-hover:text-purple-300"
>其他成本</span
>
<div class="mt-4 flex items-center justify-between">
<span
class="text-[10px] font-bold uppercase text-slate-600 dark:text-neutral-400"
>计入统计</span
>
<Switch
size="small"
class="stat-tile-switch"
:checked="dim01(status.includeOtherCost)"
:checked-value="1"
:un-checked-value="0"
@update:checked="(v: unknown) => handleDimChange('includeOtherCost', v)"
/>
</div>
</div>
<!-- 退款:全宽、虚线、弱化 -->
<div
class="stat-dim-row stat-dim--refund flex items-center justify-between gap-2 rounded-lg border border-slate-100 border-l-[3px] border-l-rose-500 bg-rose-50/70 px-3 py-2 sm:col-span-2 dark:border-[hsl(240deg_3.7%_22%)] dark:border-l-rose-400 dark:bg-rose-950/25"
class="stat-tile stat-tile--refund group col-span-1 flex cursor-default items-center justify-between rounded-2xl border border-dashed border-slate-300 bg-slate-100 p-4 shadow-sm transition-all hover:border-orange-300 hover:bg-orange-50/50 hover:shadow-md sm:col-span-2 dark:border-neutral-500 dark:bg-neutral-800/90 dark:shadow-none dark:hover:border-orange-700/80 dark:hover:bg-orange-950/25"
>
<span class="text-sm text-muted-foreground">计入退款金额</span>
<div class="flex min-w-0 items-center gap-3">
<RefundIcon
class="h-4 w-4 shrink-0 text-slate-600 transition-colors group-hover:text-orange-700 dark:text-neutral-300 dark:group-hover:text-orange-400"
/>
<span
class="text-sm font-bold text-gray-800 transition-colors group-hover:text-gray-950 dark:text-neutral-100 dark:group-hover:text-neutral-50"
>
退款金额{{ dim01(status.includeRefund) ? '计入' : '不计入' }}
</span>
</div>
<Switch
size="small"
class="stat-tile-switch"
:checked="dim01(status.includeRefund)"
:checked-value="1"
:un-checked-value="0"
checked-children="计入"
un-checked-children="不计入"
@update:checked="(v: unknown) => handleDimChange('includeRefund', v)"
/>
</div>
@@ -179,63 +235,65 @@ async function handleDimChange(key: StatKey, next: unknown) {
</template>
<style scoped lang="scss">
.order-status-card {
border-radius: 12px;
overflow: hidden;
border: 1px solid #d7e1ee;
background: linear-gradient(180deg, #ffffff 0%, #f7fbff 100%);
box-shadow:
0 14px 34px rgb(15 23 42 / 9%),
0 2px 10px rgb(15 23 42 / 5%);
transition: all 0.2s ease;
&:hover {
transform: translateY(-2px);
border-color: #b8c8de;
box-shadow:
0 20px 38px rgb(15 23 42 / 14%),
0 6px 14px rgb(15 23 42 / 9%);
}
.card-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 14px 16px;
border-bottom: 1px solid #dde6f2;
background: linear-gradient(180deg, rgb(237 245 255 / 95%) 0%, #ffffff 100%);
}
.card-body {
padding: 16px 18px 18px;
}
/* 各维度 Switch 开启态与行主题色一致 */
.stat-dim--sales :deep(.ant-switch-checked) {
background: #1677ff !important;
}
.stat-dim--product :deep(.ant-switch-checked) {
background: #16a34a !important;
}
.stat-dim--freight :deep(.ant-switch-checked) {
background: #d97706 !important;
}
.stat-dim--other :deep(.ant-switch-checked) {
background: #7c3aed !important;
}
.stat-dim--refund :deep(.ant-switch-checked) {
background: #e11d48 !important;
}
}
/* 右侧描述区:多行截断,避免把卡片撑得过高 */
.desc-preview {
.desc-under-title {
display: -webkit-box;
-webkit-line-clamp: 5;
line-clamp: 5;
-webkit-line-clamp: 3;
line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
word-break: break-word;
}
.order-status-card {
.stat-tile-switch:deep(.ant-switch) {
min-width: 48px;
}
/* 非退款 tile:关态轨道略深,与白底区分 */
.stat-tile:not(.stat-tile--refund) :deep(.ant-switch:not(.ant-switch-checked)) {
background: #cbd5e1 !important;
box-shadow: inset 0 0 0 1px rgb(15 23 42 / 0.06);
}
.stat-tile--sales :deep(.ant-switch-checked) {
background: #3b82f6 !important;
}
.stat-tile--product :deep(.ant-switch-checked) {
background: #10b981 !important;
}
.stat-tile--freight :deep(.ant-switch-checked) {
background: #f59e0b !important;
}
.stat-tile--other :deep(.ant-switch-checked) {
background: #8b5cf6 !important;
}
/* 退款:关态浅灰轨 + 开态亮橙,与灰底卡片强对比 */
.stat-tile--refund :deep(.ant-switch:not(.ant-switch-checked)) {
background: #e5e7eb !important;
box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.08);
}
.stat-tile--refund :deep(.ant-switch-checked) {
background: #ea580c !important;
box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.06);
}
.stat-tile--refund :deep(.ant-switch-checked .ant-switch-handle::before) {
background: #fff !important;
}
}
html.dark .order-status-card {
.stat-tile:not(.stat-tile--refund) :deep(.ant-switch:not(.ant-switch-checked)) {
background: #3f3f46 !important;
box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.08);
}
.stat-tile--refund :deep(.ant-switch:not(.ant-switch-checked)) {
background: #52525b !important;
box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.12);
}
.stat-tile--refund :deep(.ant-switch-checked) {
background: #f97316 !important;
box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.2);
}
}
</style>
@@ -357,23 +357,4 @@ html.dark .order-status-scroll .ant-empty-description {
color: hsl(var(--muted-foreground));
}
/* 订单状态卡片深色(与商品卡同思路) */
html.dark .order-status-card {
border-color: hsl(240deg 3.7% 22%) !important;
background: linear-gradient(
180deg,
hsl(222.34deg 10.43% 14%) 0%,
hsl(222.34deg 10.43% 12.27%) 100%
) !important;
box-shadow: 0 8px 24px rgb(0 0 0 / 35%) !important;
}
html.dark .order-status-card .card-head {
border-bottom-color: hsl(240deg 3.7% 22%) !important;
background: linear-gradient(
180deg,
hsl(222deg 14% 16%) 0%,
hsl(222.34deg 10.43% 12.27%) 100%
) !important;
}
</style>
@@ -1,7 +1,9 @@
<script lang="ts" setup>
import type { ProductDTO, ProductVO } from '#/api/ecommerce/product/types';
import { computed, ref, watch } from 'vue';
import { computed, h, ref, watch } from 'vue';
import type { DropdownRender } from 'ant-design-vue/es/vc-select/BaseSelect';
import { useRouter } from 'vue-router';
import { useVbenModal } from '@vben/common-ui';
@@ -16,6 +18,7 @@ import {
InputNumber,
message,
Popconfirm,
Tooltip,
TreeSelect,
} from 'ant-design-vue';
@@ -30,16 +33,19 @@ import {
import type { ProductSpecVO } from '#/api/ecommerce/product-spec/types';
import { getCategoryTreeApi } from '#/api/ecommerce/category';
import { uploadFileToOss } from '#/utils/oss-upload';
import CategoryFormModal from '#/views/ecommerce/config/category-config/components/CategoryFormModal.vue';
const props = defineProps<Props>();
const emit = defineEmits<Emits>();
const router = useRouter();
const EditIcon = createIconifyIcon('lucide:edit');
const EditIcon = createIconifyIcon('lucide:square-pen');
const TrashIcon = createIconifyIcon('lucide:trash-2');
const ChartIcon = createIconifyIcon('lucide:bar-chart-2');
const ImageOffIcon = createIconifyIcon('lucide:image-off');
const ChartIcon = createIconifyIcon('lucide:line-chart');
const ImageIcon = createIconifyIcon('lucide:image');
const PlusIcon = createIconifyIcon('lucide:plus');
const CheckIcon = createIconifyIcon('lucide:check');
const XIcon = createIconifyIcon('lucide:x');
// 成本同步弹窗
const [SyncModal, syncModalApi] = useVbenModal({
@@ -209,6 +215,7 @@ const isEditing = ref(false);
const isSaving = ref(false);
const originalSnapshot = ref('');
const categoryOptions = ref<any[]>([]);
const categoryFormModalRef = ref<InstanceType<typeof CategoryFormModal> | null>(null);
const newImageFile = ref<File | null>(null);
const originalImageUrl = ref('');
const imageLoadError = ref(false);
@@ -245,12 +252,62 @@ const normalizeDraft = () => ({
const loadCategoryOptions = async () => {
if (categoryOptions.value.length > 0) return;
await reloadCategoryTree();
};
/** 重新拉取类目树(新建类目后调用) */
async function reloadCategoryTree() {
try {
const list = await getCategoryTreeApi();
categoryOptions.value = list ?? [];
categoryOptions.value = (await getCategoryTreeApi()) ?? [];
} catch {
categoryOptions.value = [];
}
}
function openAddCategoryModal() {
categoryFormModalRef.value?.open(false);
}
/** 类目下拉底部「添加类目」(TreeSelect 无输入框侧插槽,用 dropdownRender) */
const categoryTreeDropdownRender: DropdownRender = (opt) => {
return h('div', {}, [
opt?.menuNode,
h(
'div',
{
style: {
borderTop: '1px solid #f1f5f9',
padding: '6px 8px',
background: '#f8fafc',
},
},
[
h(
Button,
{
type: 'link',
size: 'small',
block: true,
style: { height: 'auto', padding: '4px 8px', textAlign: 'left' as const },
onMousedown: (e: MouseEvent) => {
e.preventDefault();
},
onClick: (e: MouseEvent) => {
e.preventDefault();
e.stopPropagation();
openAddCategoryModal();
},
},
{
default: () => [
h(PlusIcon, { class: 'mr-1 inline-block h-4 w-4 align-middle' }),
h('span', null, '添加类目'),
],
},
),
],
),
]);
};
const initDraftFromProps = () => {
@@ -468,9 +525,9 @@ const saveEdit = async () => {
class="product-image"
:preview="true"
/>
<div v-else class="no-image">
<ImageOffIcon class="no-image-icon mb-1 text-base" />
<span>暂无图片</span>
<div v-else class="no-image no-image--proto">
<ImageIcon class="no-image-icon mb-2 text-4xl text-slate-300" />
<span class="text-xs text-slate-400">暂无图片</span>
</div>
</template>
<template v-else>
@@ -482,12 +539,12 @@ const saveEdit = async () => {
class="product-image"
@error="handleImageError"
/>
<div v-else class="no-image">
<ImageOffIcon class="no-image-icon mb-1 text-base" />
<span>点击上传</span>
<div v-else class="no-image no-image--proto">
<ImageIcon class="no-image-icon mb-2 text-4xl text-slate-300 transition-transform group-hover:scale-110" />
<span class="text-xs text-slate-400">点击上传图片</span>
</div>
<div class="image-overlay dark:bg-black/60">
<ImageOffIcon class="text-base mb-1" />
<ImageIcon class="mb-1 text-2xl" />
<span class="text-xs">{{ currentImageUrl && !imageLoadError ? '更换图片' : '上传图片' }}</span>
</div>
</div>
@@ -497,46 +554,52 @@ const saveEdit = async () => {
</template>
</div>
<div class="info-main">
<div class="field-row">
<span class="field-label">商品名称</span>
<span v-if="!isEditing" class="field-text field-text--title">{{ product.name }}</span>
<div class="info-main min-w-0 flex-1">
<div class="title-block mb-6">
<span class="mb-1 block text-xs font-bold uppercase tracking-widest text-blue-500">
商品名称
</span>
<h1 v-if="!isEditing" class="proto-product-title">
{{ product.name }}
</h1>
<TextArea
v-else
v-model:value="draft.name"
class="field-textarea"
class="field-textarea proto-title-input"
placeholder="请输入商品名称"
:auto-size="{ minRows: 1, maxRows: 4 }"
/>
</div>
<div class="meta-grid">
<div class="meta-box">
<span class="label">类目</span>
<span v-if="!isEditing" class="value">{{ product.categoryName || '未设置' }}</span>
<div class="meta-grid-proto">
<div class="meta-cell">
<p class="info-label">所属类目</p>
<p v-if="!isEditing" class="info-value" :class="{ 'value-empty': !product.categoryName }">
{{ product.categoryName || '未设置类目' }}
</p>
<TreeSelect
v-else
v-model:value="draft.categoryId"
class="field-tree-select"
class="field-tree-select w-full"
placeholder="请选择类目"
:tree-data="categoryOptions"
:field-names="{ label: 'name', value: 'id', children: 'children' }"
:dropdown-render="categoryTreeDropdownRender"
allow-clear
tree-default-expand-all
/>
</div>
<div class="meta-box">
<span class="label">商品编码</span>
<span v-if="!isEditing" class="value">{{ product.productCode || '未填写' }}</span>
<Input v-else v-model:value="draft.productCode" class="field-input field-input--meta" placeholder="请输入编码" />
</div>
<div class="meta-box">
<span class="label">创建时间</span>
<span class="value">{{ product.createTime || '-' }}</span>
</div>
<div class="meta-box">
<span class="label">更新时间</span>
<span class="value">{{ product.updateTime || '-' }}</span>
<div class="meta-cell">
<p class="info-label">商品编码</p>
<p v-if="!isEditing" class="info-value" :class="{ 'value-empty': !product.productCode }">
{{ product.productCode || '无编码' }}
</p>
<Input
v-else
v-model:value="draft.productCode"
class="field-input field-input--meta w-full"
placeholder="请输入编码"
/>
</div>
</div>
</div>
@@ -544,26 +607,33 @@ const saveEdit = async () => {
<div class="specs-wrapper">
<div class="specs-header-row">
<div class="specs-header">规格</div>
<Button v-if="isEditing" type="dashed" size="small" @click="addSpec">
<template #icon><PlusIcon class="h-3 w-3" /></template>
添加规格
</Button>
<div class="specs-header-bar" />
<h2 class="specs-header-title min-w-0 flex-1">规格明细</h2>
<span class="spec-count-badge shrink-0">共 {{ displaySpecs.length }} 条规格</span>
<Tooltip v-if="isEditing" title="添加规格">
<Button type="dashed" shape="circle" class="add-spec-icon-btn" @click="addSpec">
<PlusIcon class="h-4 w-4" />
</Button>
</Tooltip>
</div>
<div v-if="displaySpecs.length > 0" class="table-container">
<div class="spec-row spec-head">
<span class="cell-head cell-code">规格编码</span>
<span class="cell-head cell-name">规格名称</span>
<span class="cell-head cell-cost">商品成本</span>
<span class="cell-head cell-cost">运费成本</span>
<span class="cell-head cell-cost">其他成本</span>
<span class="cell-head cell-cost cell-cost--product">商品成本</span>
<span class="cell-head cell-cost cell-cost--freight">运费成本</span>
<span class="cell-head cell-cost cell-cost--other">其他成本</span>
<span v-if="isEditing" class="op-col">操作</span>
</div>
<div
v-for="(spec, index) in displaySpecs"
:key="isEditing ? spec.id ?? spec._clientKey ?? `idx-${index}` : spec.id"
class="spec-row"
:key="
isEditing
? (spec as EditableSpec).id ?? (spec as EditableSpec)._clientKey ?? `idx-${index}`
: spec.id
"
class="spec-row spec-row--body group"
:class="{ 'editing-row': isEditing }"
>
<span class="cell cell-code">
@@ -571,7 +641,7 @@ const saveEdit = async () => {
<Input v-else v-model:value="draft.specs[index]!.specCode" class="field-input" placeholder="编码" />
</span>
<span class="cell cell-name">
<span v-if="!isEditing" class="field-text">{{ spec.name || '-' }}</span>
<span v-if="!isEditing" class="field-text spec-name-text">{{ spec.name || '-' }}</span>
<TextArea
v-else
v-model:value="draft.specs[index]!.name"
@@ -581,7 +651,9 @@ const saveEdit = async () => {
/>
</span>
<span class="cell cell-cost">
<span v-if="!isEditing" class="cost-text">{{ formatCost(spec.productCost) }}</span>
<span v-if="!isEditing" class="cost-text cost-mono transition-colors group-hover:text-emerald-600">
{{ formatCost(spec.productCost) }}
</span>
<InputNumber
v-else
:value="spec.productCost ?? 0"
@@ -594,7 +666,9 @@ const saveEdit = async () => {
/>
</span>
<span class="cell cell-cost">
<span v-if="!isEditing" class="cost-text">{{ formatCost(spec.shippingCost) }}</span>
<span v-if="!isEditing" class="cost-text cost-mono transition-colors group-hover:text-amber-600">
{{ formatCost(spec.shippingCost) }}
</span>
<InputNumber
v-else
:value="spec.shippingCost ?? 0"
@@ -607,7 +681,9 @@ const saveEdit = async () => {
/>
</span>
<span class="cell cell-cost">
<span v-if="!isEditing" class="cost-text">{{ formatCost(spec.otherCost) }}</span>
<span v-if="!isEditing" class="cost-text cost-mono transition-colors group-hover:text-purple-600">
{{ formatCost(spec.otherCost) }}
</span>
<InputNumber
v-else
:value="spec.otherCost ?? 0"
@@ -620,53 +696,68 @@ const saveEdit = async () => {
/>
</span>
<span v-if="isEditing" class="cell op-col">
<Button type="text" danger size="small" class="delete-spec-btn" @click="removeSpec(index)">
<template #icon><TrashIcon class="h-4 w-4" /></template>
</Button>
<Tooltip title="删除此规格">
<Button type="text" danger size="small" class="delete-spec-btn" @click="removeSpec(index)">
<template #icon><TrashIcon class="h-4 w-4" /></template>
</Button>
</Tooltip>
</span>
</div>
<div
v-if="!isEditing && (product.specs?.length || 0) > visibleSpecs.length"
class="more-tip"
>
仅展示前 {{ visibleSpecs.length }} 条规格,点击"统计"查看全部
仅展示前 {{ visibleSpecs.length }} 条规格,点击「经营统计」查看全部
</div>
</div>
<div v-else-if="!isEditing" class="empty-text">暂无规格数据</div>
</div>
<div class="card-footer">
<template v-if="!isEditing">
<Button class="btn btn-edit" @click="startEdit" title="编辑">
<template #icon><EditIcon class="h-4 w-4" /></template>
<span class="hidden sm:inline">编辑</span>
</Button>
<Button class="btn btn-stats" title="查看统计" @click="goToDetails(product)">
<template #icon><ChartIcon class="h-4 w-4" /></template>
经营统计
</Button>
</template>
<template v-else>
<Button class="btn btn-cancel" @click="cancelEdit">取消</Button>
<Button
class="btn btn-save"
:type="hasChanges ? 'primary' : 'default'"
:disabled="!hasChanges"
:loading="isSaving"
@click="saveEdit"
>
保存
</Button>
</template>
<Popconfirm title="确定要删除这个商品吗?" @confirm="handleDelete(product)">
<Button class="btn btn-delete" title="删除">
<template #icon><TrashIcon class="h-4 w-4" /></template>
删除商品
</Button>
</Popconfirm>
<div class="footer-left flex flex-wrap items-center gap-3">
<template v-if="!isEditing">
<Tooltip title="编辑商品">
<Button type="primary" class="footer-icon-btn footer-icon-btn--primary" @click="startEdit">
<EditIcon class="h-5 w-5" />
</Button>
</Tooltip>
<Tooltip title="经营统计">
<Button class="footer-icon-btn footer-icon-btn--stats" @click="goToDetails(product)">
<ChartIcon class="h-5 w-5" />
</Button>
</Tooltip>
</template>
<template v-else>
<Tooltip title="取消编辑">
<Button class="footer-icon-btn footer-icon-btn--cancel" @click="cancelEdit">
<XIcon class="h-5 w-5" />
</Button>
</Tooltip>
<Tooltip title="保存">
<Button
type="primary"
class="footer-icon-btn footer-icon-btn--primary"
:disabled="!hasChanges"
:loading="isSaving"
@click="saveEdit"
>
<CheckIcon v-if="!isSaving" class="h-5 w-5" />
</Button>
</Tooltip>
</template>
</div>
<div class="footer-right">
<Popconfirm title="确定要删除这个商品吗?" @confirm="handleDelete(product)">
<Button class="footer-icon-btn footer-icon-btn--danger" title="删除商品">
<TrashIcon class="h-5 w-5" />
</Button>
</Popconfirm>
</div>
</div>
</Card>
<CategoryFormModal ref="categoryFormModalRef" @success="reloadCategoryTree" />
<SyncModal>
<div class="product-cost-sync py-4">
<!-- 顶部警告提示 -->
@@ -744,21 +835,22 @@ const saveEdit = async () => {
</template>
<style scoped lang="scss">
.management-card {
border-radius: 12px;
border-radius: 2rem;
overflow: hidden;
border: 1px solid #d7e1ee;
background: linear-gradient(180deg, #ffffff 0%, #f7fbff 100%);
border: 1px solid rgb(255 255 255 / 0.65);
background: rgb(255 255 255 / 0.95);
backdrop-filter: blur(10px);
box-shadow:
0 14px 34px rgb(15 23 42 / 9%),
0 2px 10px rgb(15 23 42 / 5%);
0 25px 50px -12px rgb(30 58 138 / 5%),
0 12px 24px -8px rgb(15 23 42 / 6%);
transition: all 0.2s ease;
&:hover {
transform: translateY(-2px);
border-color: #b8c8de;
border-color: rgb(226 232 240 / 0.95);
box-shadow:
0 20px 38px rgb(15 23 42 / 14%),
0 6px 14px rgb(15 23 42 / 9%);
0 28px 55px -12px rgb(30 58 138 / 8%),
0 14px 28px -10px rgb(15 23 42 / 8%);
}
&.editing {
@@ -768,10 +860,14 @@ const saveEdit = async () => {
.card-top {
display: flex;
gap: 24px;
padding: 28px;
border-bottom: 1px solid #dde6f2;
background: linear-gradient(180deg, rgb(237 245 255 / 95%) 0%, #ffffff 100%);
flex-direction: column;
gap: 2rem;
padding: 2rem;
background: transparent;
@media (min-width: 768px) {
flex-direction: row;
}
}
.info-main {
@@ -779,47 +875,35 @@ const saveEdit = async () => {
min-width: 0;
}
.field-row {
display: flex;
align-items: flex-start;
gap: 8px;
margin-bottom: 12px;
min-height: 32px;
}
.field-label {
font-size: 13px;
color: #8c8c8c;
font-weight: 400;
width: 70px;
flex-shrink: 0;
padding-top: 4px;
}
.img-preview {
width: 140px;
height: 140px;
width: 10rem;
height: 10rem;
flex-shrink: 0;
border: 1px solid #eeeeee;
border-radius: 6px;
border: 2px dashed #e2e8f0;
border-radius: 1.5rem;
overflow: hidden;
background: #fbfbfb;
background: #f8fafc;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
position: relative;
transition:
border-color 0.2s,
color 0.2s;
&:hover {
border-color: #93c5fd;
}
}
.editing-img.img-preview {
cursor: pointer;
border-color: rgba(91, 109, 245, 0.4);
border-style: dashed;
transition: all 0.15s;
border-color: #cbd5e1;
&:hover {
border-color: #5b6df5;
background: rgba(91, 109, 245, 0.04);
border-color: #3b82f6;
background: rgb(239 246 255 / 80%);
}
}
@@ -851,7 +935,7 @@ const saveEdit = async () => {
color: #ffffff;
opacity: 0;
transition: opacity 0.2s;
border-radius: 5px;
border-radius: 1.25rem;
}
.img-reset-btn {
@@ -866,6 +950,64 @@ const saveEdit = async () => {
}
}
.proto-product-title {
margin: 0;
font-size: 1.875rem;
line-height: 2.25rem;
font-weight: 900;
color: #1e293b;
letter-spacing: -0.025em;
display: -webkit-box;
-webkit-line-clamp: 3;
line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
word-break: break-word;
}
.proto-title-input {
font-size: 1.25rem !important;
font-weight: 700 !important;
line-height: 1.4 !important;
}
.meta-grid-proto {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 1.5rem;
}
.meta-cell {
min-width: 0;
}
.info-label {
margin: 0 0 0.25rem;
font-size: 0.75rem;
font-weight: 500;
color: #94a3b8;
}
.info-value {
margin: 0;
font-size: 0.875rem;
font-weight: 600;
color: #334155;
word-break: break-word;
}
.info-value.value-empty {
color: #cbd5e1;
font-weight: 400;
font-style: italic;
}
.spec-name-text {
font-size: 0.875rem;
font-weight: 500;
color: #334155;
}
.product-image {
width: 100%;
height: 100%;
@@ -1117,48 +1259,79 @@ const saveEdit = async () => {
}
.specs-wrapper {
padding: 0 28px 24px;
min-width: 640px;
padding: 0 2rem 1.5rem;
min-width: 0;
background: #fff;
}
.specs-header-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
gap: 0.75rem;
margin-bottom: 1rem;
}
.specs-header {
font-size: 14px;
font-weight: 600;
color: #1a1a1a;
display: flex;
.specs-header-bar {
width: 0.375rem;
height: 1.25rem;
flex-shrink: 0;
border-radius: 9999px;
background: #2563eb;
}
.specs-header-title {
margin: 0;
font-size: 1.125rem;
font-weight: 700;
color: #1e293b;
}
.spec-count-badge {
font-size: 0.75rem;
font-weight: 400;
color: #94a3b8;
background: #f1f5f9;
padding: 0.125rem 0.5rem;
border-radius: 0.375rem;
}
.add-spec-icon-btn {
display: inline-flex !important;
align-items: center;
gap: 8px;
}
.specs-header::before {
content: '';
width: 3px;
height: 14px;
border-radius: 2px;
background: #5b6df5;
justify-content: center;
width: 2rem !important;
height: 2rem !important;
min-width: 2rem !important;
padding: 0 !important;
}
.table-container {
border: 1px solid #e2eaf5;
border-radius: 6px;
border: 1px solid #f1f5f9;
border-radius: 1rem;
overflow-x: auto;
overflow-y: hidden;
background: #fcfeff;
background: rgb(248 250 252 / 0.45);
}
.spec-head {
background: linear-gradient(180deg, #f5f9ff 0%, #edf4ff 100%);
color: #6b7280;
font-weight: 600;
border-bottom: 1px solid #e2eaf5;
color: #64748b;
font-weight: 700;
font-size: 0.75rem;
text-transform: uppercase;
letter-spacing: 0.05em;
border-bottom: 1px solid #f1f5f9;
}
.cell-head.cell-cost--product {
color: #059669;
}
.cell-head.cell-cost--freight {
color: #d97706;
}
.cell-head.cell-cost--other {
color: #9333ea;
}
.spec-row {
@@ -1167,11 +1340,19 @@ const saveEdit = async () => {
align-items: center;
padding: 14px 16px;
padding-right: 0;
border-bottom: 1px solid #f9f9f9;
border-bottom: 1px solid #f1f5f9;
font-size: 13px;
background: #fff;
}
.spec-row.spec-head {
background: rgb(241 245 249 / 0.65);
}
.spec-row--body:hover {
background: rgb(239 246 255 / 0.55);
}
.op-col {
width: 36px;
flex-shrink: 0;
@@ -1244,19 +1425,28 @@ const saveEdit = async () => {
}
.code-tag {
font-family: Consolas, Menlo, Monaco, monospace;
background: #f0f2ff;
color: #5b6df5;
border-radius: 4px;
padding: 2px 6px;
font-size: 12px;
font-weight: 600;
display: inline-block;
width: fit-content;
padding: 0.25rem 0.5rem;
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New',
monospace;
font-size: 0.75rem;
font-weight: 700;
color: #2563eb;
background: #eff6ff;
border: 1px solid #dbeafe;
border-radius: 0.5rem;
}
.cost-text {
font-weight: 600;
color: #333333;
font-weight: 700;
color: #475569;
}
.cost-mono {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New',
monospace;
font-size: 0.875rem;
}
.more-tip {
@@ -1275,66 +1465,73 @@ const saveEdit = async () => {
.card-footer {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: flex-start;
gap: 12px;
padding: 12px 28px;
border-top: 1px solid #dde6f2;
background: linear-gradient(180deg, #ffffff 0%, #eef5ff 100%);
justify-content: space-between;
gap: 1rem;
padding: 2rem;
border-top: 1px solid #f1f5f9;
background: rgb(248 250 252 / 0.85);
}
.btn {
height: 34px;
border-radius: 6px;
padding: 0 16px;
font-size: 13px;
font-weight: 500;
.footer-icon-btn {
display: inline-flex !important;
align-items: center;
justify-content: center;
width: 2.75rem !important;
height: 2.75rem !important;
min-width: 2.75rem !important;
padding: 0 !important;
border-radius: 0.75rem !important;
transition:
transform 0.15s ease,
box-shadow 0.2s ease,
background 0.2s ease,
border-color 0.2s ease;
}
.btn-edit {
background: #ffffff;
color: #5b6df5;
border: 1px solid #d6e4ff;
.footer-icon-btn:active {
transform: scale(0.96);
}
.btn-edit:hover {
background: #f0f2ff !important;
border-color: #d6e4ff !important;
color: #5b6df5 !important;
.footer-icon-btn--primary.ant-btn-primary {
box-shadow: 0 10px 15px -3px rgb(37 99 235 / 25%);
}
.btn-save {
min-width: 72px;
.footer-icon-btn--stats {
background: #fff !important;
border: 1px solid #a7f3d0 !important;
color: #059669 !important;
}
.btn-cancel {
background: #ffffff;
border-color: #d0d8e2;
color: #64748b;
.footer-icon-btn--stats:hover {
background: #ecfdf5 !important;
border-color: #6ee7b7 !important;
color: #047857 !important;
}
.btn-delete {
border: 1px solid #ffccc7;
background: #ffffff;
color: #ff4d4f;
.footer-icon-btn--cancel {
background: #fff !important;
border: 1px solid #e2e8f0 !important;
color: #64748b !important;
}
.btn-delete:hover {
border-color: #ffccc7 !important;
background: #fff1f0 !important;
color: #ff4d4f !important;
.footer-icon-btn--cancel:hover {
background: #f8fafc !important;
border-color: #cbd5e1 !important;
color: #334155 !important;
}
.btn-stats {
border: 1px solid #d9f7be;
background: #ffffff;
color: #00b578;
.footer-icon-btn--danger {
background: #fff !important;
border: 1px solid #fecaca !important;
color: #ef4444 !important;
}
.btn-stats:hover {
border-color: #d9f7be !important;
background: #e6fffb !important;
color: #00b578 !important;
.footer-icon-btn--danger:hover {
background: #fef2f2 !important;
border-color: #fca5a5 !important;
color: #dc2626 !important;
}
/* 成本同步弹窗 */
@@ -1536,7 +1733,6 @@ html.dark {
.card-top {
background: linear-gradient(180deg, hsl(var(--accent-lighter) / 80%) 0%, #{$card-bg} 100%);
border-bottom-color: hsl(var(--primary) / 28%);
}
.field-label,
@@ -1562,7 +1758,7 @@ html.dark {
background: $card-bg;
}
.specs-header-row .ant-btn-dashed {
.specs-header-row .add-spec-icon-btn.ant-btn-dashed {
@include outline-btn($primary-soft, $primary, $accent-bg, hsl(var(--primary-foreground)));
}
@@ -1579,6 +1775,10 @@ html.dark {
}
}
.spec-row--body:hover {
background: hsl(var(--primary) / 10%);
}
.card-footer {
background: linear-gradient(180deg, #{$card-bg} 0%, hsl(var(--accent-lighter) / 85%) 100%);
border-top-color: hsl(var(--primary) / 28%);
@@ -1587,8 +1787,21 @@ html.dark {
.spec-head {
background: $accent-bg !important;
color: $muted-text;
border-bottom-color: $border-base;
.cell-head {
.cell-head.cell-cost--product {
color: hsl(var(--success));
}
.cell-head.cell-cost--freight {
color: hsl(var(--warning));
}
.cell-head.cell-cost--other {
color: hsl(var(--primary));
}
.cell-head:not(.cell-cost--product):not(.cell-cost--freight):not(.cell-cost--other) {
color: $muted-text;
}
}
@@ -1598,33 +1811,46 @@ html.dark {
border-color: hsl(var(--primary) / 22%);
}
.btn-edit {
@include outline-btn($primary, $primary, hsl(var(--accent-hover)), hsl(var(--primary-foreground)));
.footer-icon-btn--primary.ant-btn-primary:not(:disabled) {
box-shadow: 0 8px 20px hsl(var(--primary) / 32%);
}
.btn-stats {
.footer-icon-btn--stats {
@include outline-btn(hsl(var(--success)), hsl(var(--success)), $accent-bg, hsl(var(--success-foreground)));
}
.btn-cancel {
.footer-icon-btn--cancel {
@include outline-btn($border-base, $muted-text, $secondary-bg);
}
.btn-delete {
.footer-icon-btn--danger {
@include outline-btn(hsl(var(--destructive)), hsl(var(--destructive)), hsl(var(--destructive) / 18%));
}
.btn-save.ant-btn-default {
&:not(:disabled) {
background: $secondary-bg !important;
border-color: $border-base !important;
color: $card-text !important;
}
.proto-product-title,
.specs-header-title {
color: $card-text;
}
&:hover:not(:disabled) {
border-color: $primary !important;
color: $primary !important;
}
.info-label {
color: $muted-text;
}
.info-value {
color: $card-text;
}
.info-value.value-empty {
color: hsl(var(--muted-foreground) / 72%);
}
.spec-count-badge {
background: hsl(var(--muted));
color: $muted-text;
}
.spec-name-text {
color: $card-text;
}
.field-text--title,
@@ -1665,8 +1891,8 @@ html.dark {
color: $primary;
}
.specs-header {
color: $card-text;
.specs-header-bar {
background: hsl(var(--primary));
}
.field-input,
@@ -1,6 +1,7 @@
<script lang="ts" setup>
import type { ProductDTO, ProductVO } from '#/api/ecommerce/product/types';
import type { DropdownRender } from 'ant-design-vue/es/vc-select/BaseSelect';
import { computed, h, onUnmounted, ref, watch } from 'vue';
import { useVbenModal } from '@vben/common-ui';
@@ -28,6 +29,7 @@ import {
import type { ProductSpecVO } from '#/api/ecommerce/product-spec/types';
import { getCategoryTreeApi } from '#/api/ecommerce/category';
import { uploadFileToOss } from '#/utils/oss-upload';
import CategoryFormModal from '#/views/ecommerce/config/category-config/components/CategoryFormModal.vue';
interface Emits {
(e: 'success'): void;
@@ -196,6 +198,60 @@ const formData = ref({
// 类目选项列表
const categoryOptions = ref<any[]>([]);
const categoryFormModalRef = ref<InstanceType<typeof CategoryFormModal> | null>(null);
async function reloadCategoryTree() {
try {
categoryOptions.value = (await getCategoryTreeApi()) ?? [];
} catch {
categoryOptions.value = [];
}
}
function openAddCategoryModal() {
categoryFormModalRef.value?.open(false);
}
const categoryTreeDropdownRender: DropdownRender = (opt) => {
return h('div', {}, [
opt?.menuNode,
h(
'div',
{
style: {
borderTop: '1px solid #f1f5f9',
padding: '6px 8px',
background: '#f8fafc',
},
},
[
h(
Button,
{
type: 'link',
size: 'small',
block: true,
style: { height: 'auto', padding: '4px 8px', textAlign: 'left' as const },
onMousedown: (e: MouseEvent) => {
e.preventDefault();
},
onClick: (e: MouseEvent) => {
e.preventDefault();
e.stopPropagation();
openAddCategoryModal();
},
},
{
default: () => [
h(PlusIcon, { class: 'mr-1 inline-block h-4 w-4 align-middle' }),
h('span', null, '添加类目'),
],
},
),
],
),
]);
};
/** 表格行稳定 key(新增行无 id) */
type SpecFormRow = (ProductDTO.Spec | ProductDTO.UpdateSpec) & {
@@ -429,13 +485,7 @@ async function open(
resetForm(); // 先重置表单
initFormData(); // 再初始化数据
// 加载类目选项
try {
const list = await getCategoryTreeApi();
categoryOptions.value = list ?? [];
} catch (error) {
console.error('加载类目列表失败:', error);
}
await reloadCategoryTree();
modalApi.open();
}
@@ -814,6 +864,7 @@ onUnmounted(() => {
placeholder="请选择商品类目"
:tree-data="categoryOptions"
:field-names="{ label: 'name', value: 'id', children: 'children' }"
:dropdown-render="categoryTreeDropdownRender"
allow-clear
tree-default-expand-all
style="width: 100%"
@@ -925,4 +976,6 @@ onUnmounted(() => {
</Form>
</div>
</SyncModal>
<CategoryFormModal ref="categoryFormModalRef" @success="reloadCategoryTree" />
</template>
@@ -50,7 +50,12 @@ const delegatedProps = computed(() => {
const forwarded = useForwardPropsEmits(delegatedProps, emits);
const menusView = computed(() => {
return props.menus?.(props.handlerData);
try {
const list = props.menus?.(props.handlerData);
return Array.isArray(list) ? list : [];
} catch {
return [];
}
});
function handleClick(menu: IContextMenuItem) {
@@ -86,6 +86,17 @@ export function useTabs() {
* @param tab
*/
function getTabDisableState(tab: RouteLocationNormalized = route) {
if (!tab || typeof tab.path !== 'string') {
return {
disabledCloseAll: true,
disabledCloseCurrent: true,
disabledCloseLeft: true,
disabledCloseOther: true,
disabledCloseRight: true,
disabledRefresh: true,
};
}
const tabs = tabbarStore.getTabs;
const affixTabs = tabbarStore.affixTabs;
const index = tabs.findIndex((item) => item.path === tab.path);
@@ -31,6 +31,9 @@ const {
const menus = computed(() => {
const tab = tabbarStore.getTabByKey(currentActive.value);
if (!tab || typeof tab.path !== 'string') {
return [];
}
const menus = createContextMenus(tab);
return menus.map((item) => {
return {
@@ -133,6 +133,10 @@ export function useTabbar() {
);
const createContextMenus = (tab: TabDefinition) => {
if (!tab || typeof tab.path !== 'string') {
return [];
}
const {
disabledCloseAll,
disabledCloseCurrent,