feat(ecom-dmb): 商品卡片UI细节优化

- 瀑布流宽度560→700,breakpoints对应调整
- 规格表格横向滚动,操作列sticky固定右侧
- 规格名称列min-width:180px防止挤压换行
- 成本输入框替换为InputNumber带controls箭头
- 成本同步弹窗UI对标设计稿(警告提示条、选中卡片样式、成本快照列)
- 时间范围默认空值,需用户手动选择
This commit is contained in:
小蟑螂
2026-04-26 22:05:29 +08:00
parent 6ec45a7e0d
commit c8651a7dd1
2 changed files with 322 additions and 76 deletions
@@ -14,11 +14,12 @@ import {
Form,
Image,
Input,
InputNumber,
message,
Popconfirm,
TreeSelect,
} from 'ant-design-vue';
import dayjs from 'dayjs';
import TextArea from 'ant-design-vue/es/input/TextArea';
import { updateProductApi } from '#/api/ecommerce/product';
@@ -59,10 +60,7 @@ async function openSyncModal(costChangedSpecIds: number[]) {
const specs = await getProductSpecsByIdsApi(costChangedSpecIds);
pendingCostChangedSpecs.value = specs ?? [];
selectedSyncSpecIds.value = costChangedSpecIds;
syncFormData.value = [
dayjs().startOf('day').format('YYYY-MM-DD HH:mm:ss'),
dayjs().endOf('day').format('YYYY-MM-DD HH:mm:ss'),
];
syncFormData.value = undefined;
syncModalApi.open();
} catch (error) {
console.error('获取规格详情失败:', error);
@@ -73,8 +71,24 @@ async function openSyncModal(costChangedSpecIds: number[]) {
const pendingCostChangedSpecs = ref<ProductSpecVO.Info[]>([]);
const selectedSyncSpecIds = ref<number[]>([]);
function toggleSpec(specId: number) {
const idx = selectedSyncSpecIds.value.indexOf(specId);
if (idx === -1) {
selectedSyncSpecIds.value.push(specId);
} else {
selectedSyncSpecIds.value.splice(idx, 1);
}
}
async function handleSyncConfirm() {
if (selectedSyncSpecIds.value.length === 0 || !syncFormData.value) return;
if (selectedSyncSpecIds.value.length === 0) {
message.warning('请至少选择一个规格');
return;
}
if (!syncFormData.value || syncFormData.value[0] == null || syncFormData.value[1] == null) {
message.warning('请选择同步时间范围');
return;
}
try {
syncModalApi.setState?.({ confirmLoading: true });
const [startDate, endDate] = syncFormData.value;
@@ -216,12 +230,6 @@ const displaySpecs = computed(() => {
const formatCost = (val?: number) => `¥${(val ?? 0).toFixed(2)}`;
const handleCostInput = (field: 'productCost' | 'shippingCost' | 'otherCost', specIndex: number, e: Event) => {
const raw = (e.target as HTMLInputElement).value;
const num = Number(raw);
draft.value.specs[specIndex]![field] = Number.isFinite(num) && num >= 0 ? num : 0;
};
function addSpec() {
draft.value.specs.push({
id: -Date.now(),
@@ -465,7 +473,7 @@ const saveEdit = async () => {
<span class="cell-head cell-cost">商品成本</span>
<span class="cell-head cell-cost">运费成本</span>
<span class="cell-head cell-cost">其他成本</span>
<span v-if="isEditing" class="op-col" />
<span v-if="isEditing" class="op-col">操作</span>
</div>
<div
v-for="(spec, index) in displaySpecs"
@@ -489,39 +497,42 @@ const saveEdit = async () => {
</span>
<span class="cell cell-cost">
<span v-if="!isEditing" class="cost-text">{{ formatCost(spec.productCost) }}</span>
<span v-else class="cost-input-wrap">
<span class="cost-prefix">¥</span>
<Input
:value="String(spec.productCost ?? 0)"
class="field-input field-input--cost"
placeholder="0"
@input="handleCostInput('productCost', index, $event)"
/>
</span>
<InputNumber
v-else
:value="spec.productCost ?? 0"
:controls="true"
class="cost-number-input"
placeholder="0"
:min="0"
:precision="2"
@update:value="(v) => { draft.specs[index]!.productCost = v ?? 0; }"
/>
</span>
<span class="cell cell-cost">
<span v-if="!isEditing" class="cost-text">{{ formatCost(spec.shippingCost) }}</span>
<span v-else class="cost-input-wrap">
<span class="cost-prefix">¥</span>
<Input
:value="String(spec.shippingCost ?? 0)"
class="field-input field-input--cost"
placeholder="0"
@input="handleCostInput('shippingCost', index, $event)"
/>
</span>
<InputNumber
v-else
:value="spec.shippingCost ?? 0"
:controls="true"
class="cost-number-input"
placeholder="0"
:min="0"
:precision="2"
@update:value="(v) => { draft.specs[index]!.shippingCost = v ?? 0; }"
/>
</span>
<span class="cell cell-cost">
<span v-if="!isEditing" class="cost-text">{{ formatCost(spec.otherCost) }}</span>
<span v-else class="cost-input-wrap">
<span class="cost-prefix">¥</span>
<Input
:value="String(spec.otherCost ?? 0)"
class="field-input field-input--cost"
placeholder="0"
@input="handleCostInput('otherCost', index, $event)"
/>
</span>
<InputNumber
v-else
:value="spec.otherCost ?? 0"
:controls="true"
class="cost-number-input"
placeholder="0"
:min="0"
:precision="2"
@update:value="(v) => { draft.specs[index]!.otherCost = v ?? 0; }"
/>
</span>
<span v-if="isEditing" class="cell op-col">
<Button type="text" danger size="small" class="delete-spec-btn" @click="removeSpec(index)">
@@ -573,44 +584,58 @@ const saveEdit = async () => {
<SyncModal>
<div class="py-4">
<p class="mb-4 text-gray-600">
检测到 <strong>{{ pendingCostChangedSpecs.length }}</strong> 个规格的成本已更新,
请勾选需要同步的规格:
</p>
<div class="mb-4 max-h-48 overflow-y-auto border border-gray-200 rounded">
<!-- 顶部警告提示 -->
<div class="sync-alert">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="8" x2="12" y2="12"></line><line x1="12" y1="16" x2="12.01" y2="16"></line></svg>
检测到 <strong>{{ pendingCostChangedSpecs.length }}</strong> 个规格的成本已更新,请勾选需要同步的规格:
</div>
<!-- 规格选择卡片列表 -->
<div class="spec-list mb-4 max-h-48 overflow-y-auto rounded-lg">
<div
v-for="spec in pendingCostChangedSpecs"
:key="spec.id"
class="flex items-center gap-3 px-3 py-2 border-b border-gray-100 last:border-b-0"
class="spec-item-card"
:class="{ active: selectedSyncSpecIds.includes(spec.id) }"
@click="toggleSpec(spec.id)"
>
<input
type="checkbox"
:value="spec.id"
v-model="selectedSyncSpecIds"
class="w-4 h-4 rounded border-gray-300 text-blue-500 focus:ring-blue-500"
/>
<div class="flex-1 min-w-0">
<div class="text-sm font-medium text-gray-800 truncate">{{ spec.name }}</div>
<div class="text-xs text-gray-400">{{ spec.specCode || '无编码' }}</div>
<div class="checkbox-wrapper">
<div class="custom-checkbox">
<span v-if="selectedSyncSpecIds.includes(spec.id)" class="check-icon">✓</span>
</div>
</div>
<div class="text-xs text-gray-500 text-right shrink-0">
<div>商品成本: <span class="text-orange-500 font-medium">{{ spec.productCost }}</span></div>
<div v-if="spec.shippingCost">运费: {{ spec.shippingCost }}</div>
<div v-if="spec.otherCost">其他: {{ spec.otherCost }}</div>
<div class="spec-info">
<div class="spec-title">{{ spec.name }}</div>
<div class="spec-code">{{ spec.specCode || '无编码' }}</div>
</div>
<div class="cost-snapshot">
<div class="cost-tag changed">
<span>商品成本</span>
<span>¥{{ Number(spec.productCost || 0).toFixed(2) }}</span>
</div>
<div class="cost-tag">
<span>运费</span>
<span>¥{{ Number(spec.shippingCost || 0).toFixed(2) }}</span>
</div>
<div class="cost-tag">
<span>其他</span>
<span>¥{{ Number(spec.otherCost || 0).toFixed(2) }}</span>
</div>
</div>
</div>
</div>
<Form layout="vertical" class="mt-4">
<Form.Item label="同步时间范围">
<DatePicker.RangePicker
v-model:value="syncFormData"
class="w-full"
format="YYYY-MM-DD HH:mm:ss"
value-format="YYYY-MM-DD HH:mm:ss"
show-time
/>
</Form.Item>
</Form>
<!-- 时间范围选择 -->
<div class="time-range-section">
<label class="section-label">同步时间范围</label>
<DatePicker.RangePicker
v-model:value="syncFormData"
class="w-full"
format="YYYY-MM-DD HH:mm:ss"
value-format="YYYY-MM-DD HH:mm:ss"
show-time
/>
</div>
</div>
</SyncModal>
</template>
@@ -846,6 +871,42 @@ const saveEdit = async () => {
box-shadow: none !important;
}
.cost-number-input {
width: 110px;
height: 28px;
border-color: rgba(91, 109, 245, 0.4) !important;
background: rgba(91, 109, 245, 0.04) !important;
}
.cost-number-input:hover {
border-color: #5b6df5 !important;
background: rgba(91, 109, 245, 0.08) !important;
}
.cost-number-input:focus,
.cost-number-input.ant-input-number-focused {
border-color: #5b6df5 !important;
background: #ffffff !important;
box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2) !important;
}
:global(html.dark) .cost-number-input {
border-color: rgba(91, 109, 245, 0.4) !important;
background: rgba(91, 109, 245, 0.08) !important;
color: #e2e8f0 !important;
}
:global(html.dark) .cost-number-input:hover {
border-color: #6366f1 !important;
background: rgba(91, 109, 245, 0.15) !important;
}
:global(html.dark) .cost-number-input:focus,
:global(html.dark) .cost-number-input.ant-input-number-focused {
border-color: #6366f1 !important;
background: #1f2937 !important;
}
.field-textarea {
font-size: inherit;
font-family: inherit;
@@ -942,6 +1003,7 @@ const saveEdit = async () => {
.specs-wrapper {
padding: 0 28px 24px;
min-width: 640px;
}
.specs-header-row {
@@ -971,7 +1033,8 @@ const saveEdit = async () => {
.table-container {
border: 1px solid #f0f0f0;
border-radius: 6px;
overflow: hidden;
overflow-x: auto;
overflow-y: hidden;
}
.spec-head {
@@ -985,8 +1048,10 @@ const saveEdit = async () => {
gap: 8px;
align-items: center;
padding: 14px 16px;
padding-right: 0;
border-bottom: 1px solid #f9f9f9;
font-size: 13px;
background: #fff;
}
.op-col {
@@ -994,6 +1059,10 @@ const saveEdit = async () => {
flex-shrink: 0;
display: flex;
justify-content: center;
align-items: center;
position: sticky;
right: 0;
z-index: 1;
}
.delete-spec-btn {
@@ -1038,7 +1107,7 @@ const saveEdit = async () => {
.cell-name {
flex: 1;
min-width: 0;
min-width: 180px;
}
.cell-cost {
@@ -1293,4 +1362,181 @@ const saveEdit = async () => {
background: #1f2937 !important;
box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2) !important;
}
/* 成本同步弹窗 */
.sync-alert {
display: flex;
align-items: center;
gap: 10px;
background: #fff8f1;
padding: 12px 16px;
border-radius: 8px;
border: 1px solid #ffe8d5;
margin-bottom: 24px;
color: #af6a2b;
font-size: 14px;
}
.spec-list {
display: flex;
flex-direction: column;
gap: 10px;
}
.spec-item-card {
display: flex;
align-items: center;
padding: 16px;
border: 2px solid #eef0f2;
border-radius: 10px;
transition: all 0.2s;
cursor: pointer;
background: #fff;
}
.spec-item-card:hover {
border-color: #d1d9ff;
background: #fafbff;
}
.spec-item-card.active {
border-color: #5b6df5;
background: #f0f2ff;
}
.checkbox-wrapper {
margin-right: 16px;
flex-shrink: 0;
}
.custom-checkbox {
width: 20px;
height: 20px;
border: 2px solid #cbd5e1;
border-radius: 4px;
display: flex;
align-items: center;
justify-content: center;
background: #fff;
transition: all 0.2s;
}
.active .custom-checkbox {
background: #5b6df5;
border-color: #5b6df5;
}
.check-icon {
color: #fff;
font-size: 14px;
font-weight: bold;
line-height: 1;
}
.spec-info {
flex: 1;
min-width: 0;
}
.spec-title {
font-size: 14px;
font-weight: 500;
color: #2d3436;
margin-bottom: 4px;
display: -webkit-box;
-webkit-line-clamp: 1;
-webkit-box-orient: vertical;
overflow: hidden;
}
.spec-code {
font-size: 12px;
color: #636e72;
font-family: monospace;
}
.cost-snapshot {
display: flex;
flex-direction: column;
gap: 4px;
padding-left: 20px;
border-left: 1px solid #e2e8f0;
margin-left: 15px;
min-width: 100px;
}
.cost-tag {
font-size: 12px;
color: #636e72;
display: flex;
justify-content: space-between;
gap: 10px;
}
.cost-tag span:last-child {
font-weight: 600;
color: #2d3436;
}
.cost-tag.changed span:last-child {
color: #f2994a;
}
.time-range-section {
margin-top: 24px;
}
.section-label {
font-size: 14px;
font-weight: 600;
color: #2d3436;
margin-bottom: 12px;
display: block;
}
:global(html.dark) .sync-alert {
background: rgba(242, 153, 74, 0.1);
border-color: rgba(242, 153, 74, 0.3);
color: #f5c080;
}
:global(html.dark) .spec-item-card {
border-color: #2d3748;
background: #1a202c;
}
:global(html.dark) .spec-item-card:hover {
border-color: #4a5568;
background: #1e2533;
}
:global(html.dark) .spec-item-card.active {
border-color: #6366f1;
background: rgba(91, 109, 245, 0.1);
}
:global(html.dark) .custom-checkbox {
background: #1a202c;
border-color: #4a5568;
}
:global(html.dark) .spec-title {
color: #e2e8f0;
}
:global(html.dark) .spec-code {
color: #a0aec0;
}
:global(html.dark) .cost-snapshot {
border-left-color: #2d3748;
}
:global(html.dark) .cost-tag {
color: #a0aec0;
}
:global(html.dark) .cost-tag span:last-child {
color: #e2e8f0;
}
</style>
@@ -295,11 +295,11 @@ onUnmounted(() => {
ref="waterfallRef"
:list="productList"
row-key="id"
:width="560"
:width="700"
:breakpoints="{
2350: { rowPerView: 3 },
1750: { rowPerView: 2 },
1250: { rowPerView: 2 },
2700: { rowPerView: 3 },
2000: { rowPerView: 2 },
1400: { rowPerView: 2 },
900: { rowPerView: 1 },
500: { rowPerView: 1 },
}"