feat: 忘了干啥了

This commit is contained in:
ah--desktop
2026-03-09 20:40:13 +08:00
parent 79109202d3
commit 60d34e2a47
37 changed files with 751 additions and 2673 deletions
@@ -1,98 +0,0 @@
<script lang="ts" setup>
import type { EchartsUIType } from '@vben/plugins/echarts';
import { onMounted, ref } from 'vue';
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
onMounted(() => {
renderEcharts({
grid: {
bottom: 0,
containLabel: true,
left: '1%',
right: '1%',
top: '2 %',
},
series: [
{
areaStyle: {},
data: [
111, 2000, 6000, 16_000, 33_333, 55_555, 64_000, 33_333, 18_000,
36_000, 70_000, 42_444, 23_222, 13_000, 8000, 4000, 1200, 333, 222,
111,
],
itemStyle: {
color: '#5ab1ef',
},
smooth: true,
type: 'line',
},
{
areaStyle: {},
data: [
33, 66, 88, 333, 3333, 6200, 20_000, 3000, 1200, 13_000, 22_000,
11_000, 2221, 1201, 390, 198, 60, 30, 22, 11,
],
itemStyle: {
color: '#019680',
},
smooth: true,
type: 'line',
},
],
tooltip: {
axisPointer: {
lineStyle: {
color: '#019680',
width: 1,
},
},
trigger: 'axis',
},
// xAxis: {
// axisTick: {
// show: false,
// },
// boundaryGap: false,
// data: Array.from({ length: 18 }).map((_item, index) => `${index + 6}:00`),
// type: 'category',
// },
xAxis: {
axisTick: {
show: false,
},
boundaryGap: false,
data: Array.from({ length: 18 }).map((_item, index) => `${index + 6}:00`),
splitLine: {
lineStyle: {
type: 'solid',
width: 1,
},
show: true,
},
type: 'category',
},
yAxis: [
{
axisTick: {
show: false,
},
max: 80_000,
splitArea: {
show: true,
},
splitNumber: 4,
type: 'value',
},
],
});
});
</script>
<template>
<EchartsUI ref="chartRef" />
</template>
@@ -1,82 +0,0 @@
<script lang="ts" setup>
import type { EchartsUIType } from '@vben/plugins/echarts';
import { onMounted, ref } from 'vue';
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
onMounted(() => {
renderEcharts({
legend: {
bottom: 0,
data: ['访问', '趋势'],
},
radar: {
indicator: [
{
name: '网页',
},
{
name: '移动端',
},
{
name: 'Ipad',
},
{
name: '客户端',
},
{
name: '第三方',
},
{
name: '其它',
},
],
radius: '60%',
splitNumber: 8,
},
series: [
{
areaStyle: {
opacity: 1,
shadowBlur: 0,
shadowColor: 'rgba(0,0,0,.2)',
shadowOffsetX: 0,
shadowOffsetY: 10,
},
data: [
{
itemStyle: {
color: '#b6a2de',
},
name: '访问',
value: [90, 50, 86, 40, 50, 20],
},
{
itemStyle: {
color: '#5ab1ef',
},
name: '趋势',
value: [70, 75, 70, 76, 20, 85],
},
],
itemStyle: {
// borderColor: '#fff',
borderRadius: 10,
borderWidth: 2,
},
symbolSize: 0,
type: 'radar',
},
],
tooltip: {},
});
});
</script>
<template>
<EchartsUI ref="chartRef" />
</template>
@@ -1,46 +0,0 @@
<script lang="ts" setup>
import type { EchartsUIType } from '@vben/plugins/echarts';
import { onMounted, ref } from 'vue';
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
onMounted(() => {
renderEcharts({
series: [
{
animationDelay() {
return Math.random() * 400;
},
animationEasing: 'exponentialInOut',
animationType: 'scale',
center: ['50%', '50%'],
color: ['#5ab1ef', '#b6a2de', '#67e0e3', '#2ec7c9'],
data: [
{ name: '外包', value: 500 },
{ name: '定制', value: 310 },
{ name: '技术支持', value: 274 },
{ name: '远程', value: 400 },
].sort((a, b) => {
return a.value - b.value;
}),
name: '商业占比',
radius: '80%',
roseType: 'radius',
type: 'pie',
},
],
tooltip: {
trigger: 'item',
},
});
});
</script>
<template>
<EchartsUI ref="chartRef" />
</template>
@@ -1,65 +0,0 @@
<script lang="ts" setup>
import type { EchartsUIType } from '@vben/plugins/echarts';
import { onMounted, ref } from 'vue';
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
onMounted(() => {
renderEcharts({
legend: {
bottom: '2%',
left: 'center',
},
series: [
{
animationDelay() {
return Math.random() * 100;
},
animationEasing: 'exponentialInOut',
animationType: 'scale',
avoidLabelOverlap: false,
color: ['#5ab1ef', '#b6a2de', '#67e0e3', '#2ec7c9'],
data: [
{ name: '搜索引擎', value: 1048 },
{ name: '直接访问', value: 735 },
{ name: '邮件营销', value: 580 },
{ name: '联盟广告', value: 484 },
],
emphasis: {
label: {
fontSize: '12',
fontWeight: 'bold',
show: true,
},
},
itemStyle: {
// borderColor: '#fff',
borderRadius: 10,
borderWidth: 2,
},
label: {
position: 'center',
show: false,
},
labelLine: {
show: false,
},
name: '访问来源',
radius: ['40%', '65%'],
type: 'pie',
},
],
tooltip: {
trigger: 'item',
},
});
});
</script>
<template>
<EchartsUI ref="chartRef" />
</template>
@@ -1,55 +0,0 @@
<script lang="ts" setup>
import type { EchartsUIType } from '@vben/plugins/echarts';
import { onMounted, ref } from 'vue';
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
onMounted(() => {
renderEcharts({
grid: {
bottom: 0,
containLabel: true,
left: '1%',
right: '1%',
top: '2 %',
},
series: [
{
barMaxWidth: 80,
// color: '#4f69fd',
data: [
3000, 2000, 3333, 5000, 3200, 4200, 3200, 2100, 3000, 5100, 6000,
3200, 4800,
],
type: 'bar',
},
],
tooltip: {
axisPointer: {
lineStyle: {
// color: '#4f69fd',
width: 1,
},
},
trigger: 'axis',
},
xAxis: {
data: Array.from({ length: 12 }).map((_item, index) => `${index + 1}月`),
type: 'category',
},
yAxis: {
max: 8000,
splitNumber: 4,
type: 'value',
},
});
});
</script>
<template>
<EchartsUI ref="chartRef" />
</template>
@@ -1,90 +0,0 @@
<script lang="ts" setup>
import type { AnalysisOverviewItem } from '@vben/common-ui';
import type { TabOption } from '@vben/types';
import {
AnalysisChartCard,
AnalysisChartsTabs,
AnalysisOverview,
} from '@vben/common-ui';
import {
SvgBellIcon,
SvgCakeIcon,
SvgCardIcon,
SvgDownloadIcon,
} from '@vben/icons';
import AnalyticsTrends from './analytics-trends.vue';
import AnalyticsVisitsData from './analytics-visits-data.vue';
import AnalyticsVisitsSales from './analytics-visits-sales.vue';
import AnalyticsVisitsSource from './analytics-visits-source.vue';
import AnalyticsVisits from './analytics-visits.vue';
const overviewItems: AnalysisOverviewItem[] = [
{
icon: SvgCardIcon,
title: '用户量',
totalTitle: '总用户量',
totalValue: 120_000,
value: 2000,
},
{
icon: SvgCakeIcon,
title: '访问量',
totalTitle: '总访问量',
totalValue: 500_000,
value: 20_000,
},
{
icon: SvgDownloadIcon,
title: '下载量',
totalTitle: '总下载量',
totalValue: 120_000,
value: 8000,
},
{
icon: SvgBellIcon,
title: '使用量',
totalTitle: '总使用量',
totalValue: 50_000,
value: 5000,
},
];
const chartTabs: TabOption[] = [
{
label: '流量趋势',
value: 'trends',
},
{
label: '月访问量',
value: 'visits',
},
];
</script>
<template>
<div class="p-5">
<AnalysisOverview :items="overviewItems" />
<AnalysisChartsTabs :tabs="chartTabs" class="mt-5">
<template #trends>
<AnalyticsTrends />
</template>
<template #visits>
<AnalyticsVisits />
</template>
</AnalysisChartsTabs>
<div class="mt-5 w-full md:flex">
<AnalysisChartCard class="mt-5 md:mr-4 md:mt-0 md:w-1/3" title="访问数量">
<AnalyticsVisitsData />
</AnalysisChartCard>
<AnalysisChartCard class="mt-5 md:mr-4 md:mt-0 md:w-1/3" title="访问来源">
<AnalyticsVisitsSource />
</AnalysisChartCard>
<AnalysisChartCard class="mt-5 md:mt-0 md:w-1/3" title="访问来源">
<AnalyticsVisitsSales />
</AnalysisChartCard>
</div>
</div>
</template>
@@ -7,6 +7,7 @@ import type {
} from '#/api/ecommerce/company-overview';
import { onMounted, ref, watch } from 'vue';
import { useRouter } from 'vue-router';
import { Page } from '@vben/common-ui';
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
@@ -19,6 +20,9 @@ import { getShopPageApi } from '#/api/ecommerce/shop';
defineOptions({ name: 'CompanyOverview' });
// 路由
const router = useRouter();
// 响应式数据
const loading = ref(false);
const overviewData = ref<CompanyOverviewVO.Info | null>(null);
@@ -116,6 +120,17 @@ const formatPercentPlain = (value: number | undefined) => {
return `${value.toFixed(1)}%`;
};
// 跳转到店铺详情页
const navigateToShopOverview = (shopId: number) => {
router.push({
path: `/ecom/shop/overview/${shopId}`,
query: {
startDate: dateRange.value[0].format('YYYY-MM-DD'),
endDate: dateRange.value[1].format('YYYY-MM-DD'),
},
});
};
// 加载店铺数量
const loadShopCount = async () => {
try {
@@ -406,7 +421,7 @@ onMounted(async () => {
</template>
<Spin :spinning="loading">
<div class="mx-auto w-full space-y-6 p-4 md:p-8">
<div class="mx-auto w-full space-y-6">
<!-- 第一层:核心汇总指标 -->
<div class="grid grid-cols-1 gap-6 sm:grid-cols-2 xl:grid-cols-4">
<!-- 销售额 -->
@@ -673,9 +688,14 @@ onMounted(async () => {
class="transition-colors hover:bg-blue-50/50"
>
<td
class="sticky-col border-r-2 border-slate-100 bg-white p-6 font-bold text-slate-900 shadow-sm"
class="sticky-col border-r-2 border-slate-100 bg-white p-6 font-bold shadow-sm"
>
{{ shop.shopName }}
<span
class="cursor-pointer text-blue-600 transition-colors hover:text-blue-800 hover:underline"
@click="navigateToShopOverview(shop.shopId)"
>
{{ shop.shopName }}
</span>
</td>
<!-- 目标 -->
<td class="p-6 font-medium">
@@ -1,266 +0,0 @@
<script lang="ts" setup>
import type {
WorkbenchProjectItem,
WorkbenchQuickNavItem,
WorkbenchTodoItem,
WorkbenchTrendItem,
} from '@vben/common-ui';
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import {
AnalysisChartCard,
WorkbenchHeader,
WorkbenchProject,
WorkbenchQuickNav,
WorkbenchTodo,
WorkbenchTrends,
} from '@vben/common-ui';
import { preferences } from '@vben/preferences';
import { useUserStore } from '@vben/stores';
import { openWindow } from '@vben/utils';
import AnalyticsVisitsSource from '../analytics/analytics-visits-source.vue';
const userStore = useUserStore();
// 这是一个示例数据,实际项目中需要根据实际情况进行调整
// url 也可以是内部路由,在 navTo 方法中识别处理,进行内部跳转
// 例如:url: /dashboard/workspace
const projectItems: WorkbenchProjectItem[] = [
{
color: '',
content: '不要等待机会,而要创造机会。',
date: '2021-04-01',
group: '开源组',
icon: 'carbon:logo-github',
title: 'Github',
url: 'https://github.com',
},
{
color: '#3fb27f',
content: '现在的你决定将来的你。',
date: '2021-04-01',
group: '算法组',
icon: 'ion:logo-vue',
title: 'Vue',
url: 'https://vuejs.org',
},
{
color: '#e18525',
content: '没有什么才能比努力更重要。',
date: '2021-04-01',
group: '上班摸鱼',
icon: 'ion:logo-html5',
title: 'Html5',
url: 'https://developer.mozilla.org/zh-CN/docs/Web/HTML',
},
{
color: '#bf0c2c',
content: '热情和欲望可以突破一切难关。',
date: '2021-04-01',
group: 'UI',
icon: 'ion:logo-angular',
title: 'Angular',
url: 'https://angular.io',
},
{
color: '#00d8ff',
content: '健康的身体是实现目标的基石。',
date: '2021-04-01',
group: '技术牛',
icon: 'bx:bxl-react',
title: 'React',
url: 'https://reactjs.org',
},
{
color: '#EBD94E',
content: '路是走出来的,而不是空想出来的。',
date: '2021-04-01',
group: '架构组',
icon: 'ion:logo-javascript',
title: 'Js',
url: 'https://developer.mozilla.org/zh-CN/docs/Web/JavaScript',
},
];
// 同样,这里的 url 也可以使用以 http 开头的外部链接
const quickNavItems: WorkbenchQuickNavItem[] = [
{
color: '#1fdaca',
icon: 'ion:home-outline',
title: '首页',
url: '/',
},
{
color: '#bf0c2c',
icon: 'ion:grid-outline',
title: '仪表盘',
url: '/dashboard',
},
{
color: '#e18525',
icon: 'ion:layers-outline',
title: '组件',
url: '/demos/features/icons',
},
{
color: '#3fb27f',
icon: 'ion:settings-outline',
title: '系统管理',
url: '/demos/features/login-expired', // 这里的 URL 是示例,实际项目中需要根据实际情况进行调整
},
{
color: '#4daf1bc9',
icon: 'ion:key-outline',
title: '权限管理',
url: '/demos/access/page-control',
},
{
color: '#00d8ff',
icon: 'ion:bar-chart-outline',
title: '图表',
url: '/analytics',
},
];
const todoItems = ref<WorkbenchTodoItem[]>([
{
completed: false,
content: `审查最近提交到Git仓库的前端代码,确保代码质量和规范。`,
date: '2024-07-30 11:00:00',
title: '审查前端代码提交',
},
{
completed: true,
content: `检查并优化系统性能,降低CPU使用率。`,
date: '2024-07-30 11:00:00',
title: '系统性能优化',
},
{
completed: false,
content: `进行系统安全检查,确保没有安全漏洞或未授权的访问。 `,
date: '2024-07-30 11:00:00',
title: '安全检查',
},
{
completed: false,
content: `更新项目中的所有npm依赖包,确保使用最新版本。`,
date: '2024-07-30 11:00:00',
title: '更新项目依赖',
},
{
completed: false,
content: `修复用户报告的页面UI显示问题,确保在不同浏览器中显示一致。 `,
date: '2024-07-30 11:00:00',
title: '修复UI显示问题',
},
]);
const trendItems: WorkbenchTrendItem[] = [
{
avatar: 'svg:avatar-1',
content: `在 <a>开源组</a> 创建了项目 <a>Vue</a>`,
date: '刚刚',
title: '威廉',
},
{
avatar: 'svg:avatar-2',
content: `关注了 <a>威廉</a> `,
date: '1个小时前',
title: '艾文',
},
{
avatar: 'svg:avatar-3',
content: `发布了 <a>个人动态</a> `,
date: '1天前',
title: '克里斯',
},
{
avatar: 'svg:avatar-4',
content: `发表文章 <a>如何编写一个Vite插件</a> `,
date: '2天前',
title: 'Vben',
},
{
avatar: 'svg:avatar-1',
content: `回复了 <a>杰克</a> 的问题 <a>如何进行项目优化?</a>`,
date: '3天前',
title: '皮特',
},
{
avatar: 'svg:avatar-2',
content: `关闭了问题 <a>如何运行项目</a> `,
date: '1周前',
title: '杰克',
},
{
avatar: 'svg:avatar-3',
content: `发布了 <a>个人动态</a> `,
date: '1周前',
title: '威廉',
},
{
avatar: 'svg:avatar-4',
content: `推送了代码到 <a>Github</a>`,
date: '2021-04-01 20:00',
title: '威廉',
},
{
avatar: 'svg:avatar-4',
content: `发表文章 <a>如何编写使用 Admin Vben</a> `,
date: '2021-03-01 20:00',
title: 'Vben',
},
];
const router = useRouter();
// 这是一个示例方法,实际项目中需要根据实际情况进行调整
// This is a sample method, adjust according to the actual project requirements
function navTo(nav: WorkbenchProjectItem | WorkbenchQuickNavItem) {
if (nav.url?.startsWith('http')) {
openWindow(nav.url);
return;
}
if (nav.url?.startsWith('/')) {
router.push(nav.url).catch((error) => {
console.error('Navigation failed:', error);
});
} else {
console.warn(`Unknown URL for navigation item: ${nav.title} -> ${nav.url}`);
}
}
</script>
<template>
<div class="p-5">
<WorkbenchHeader
:avatar="userStore.userInfo?.avatar || preferences.app.defaultAvatar"
>
<template #title>
早安, {{ userStore.userInfo?.realName }}, 开始您一天的工作吧!
</template>
<template #description> 今日晴,20℃ - 32℃! </template>
</WorkbenchHeader>
<div class="mt-5 flex flex-col lg:flex-row">
<div class="mr-4 w-full lg:w-3/5">
<WorkbenchProject :items="projectItems" title="项目" @click="navTo" />
<WorkbenchTrends :items="trendItems" class="mt-5" title="最新动态" />
</div>
<div class="w-full lg:w-2/5">
<WorkbenchQuickNav
:items="quickNavItems"
class="mt-5 lg:mt-0"
title="快捷导航"
@click="navTo"
/>
<WorkbenchTodo :items="todoItems" class="mt-5" title="待办事项" />
<AnalysisChartCard class="mt-5" title="访问来源">
<AnalyticsVisitsSource />
</AnalysisChartCard>
</div>
</div>
</div>
</template>
@@ -235,9 +235,7 @@ onUnmounted(() => {
</script>
<template>
<div
class="h-full overflow-hidden bg-gradient-to-br from-indigo-100 via-pink-100 to-slate-100 p-8"
>
<div class="h-full overflow-hidden bg-slate-100 p-8">
<div class="mx-auto flex h-full w-[60%] flex-col overflow-hidden">
<!-- 头部标题 -->
<div class="mb-12 shrink-0 text-center">
@@ -254,10 +252,8 @@ onUnmounted(() => {
v-if="csvData.length === 0"
class="flex min-h-0 flex-1 flex-col overflow-hidden"
>
<div
class="mb-8 grid shrink-0 grid-cols-1 gap-6 lg:grid-cols-[2fr_1fr]"
>
<!-- 左侧:导入区域 -->
<div class="mb-8 shrink-0">
<!-- 导入区域 -->
<div
class="relative flex min-h-[400px] flex-col items-center justify-center overflow-hidden rounded-[2rem] border border-white/50 bg-white/45 p-8 shadow-[0_25px_50px_-12px_rgba(0,0,0,0.1)] backdrop-blur-2xl"
>
@@ -273,68 +269,6 @@ onUnmounted(() => {
/>
</div>
</div>
<!-- 右侧:指引与历史 -->
<div class="flex flex-col gap-6">
<!-- 操作指南卡片 -->
<div
class="relative flex flex-col gap-4 overflow-hidden rounded-[2rem] border border-white/50 bg-white/45 p-6 shadow-[0_25px_50px_-12px_rgba(0,0,0,0.1)] backdrop-blur-2xl"
>
<h3 class="m-0 text-base font-bold text-slate-800">操作指南</h3>
<div class="flex flex-col gap-4">
<div class="flex items-start gap-3">
<div
class="flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-indigo-600 text-xs font-bold text-white"
>
1
</div>
<p
class="m-0 text-xs font-medium leading-relaxed text-slate-500"
>
从电商后台导出【订单详情】CSV文件
</p>
</div>
<div class="flex items-start gap-3">
<div
class="flex h-6 w-6 shrink-0 items-center justify-center rounded-full border border-indigo-100 bg-white text-xs font-bold text-indigo-600"
>
2
</div>
<p
class="m-0 text-xs font-medium leading-relaxed text-slate-500"
>
检查文件是否包含【订单号】与【金额】列
</p>
</div>
<div class="flex items-start gap-3">
<div
class="flex h-6 w-6 shrink-0 items-center justify-center rounded-full border border-indigo-100 bg-white text-xs font-bold text-indigo-600"
>
3
</div>
<p
class="m-0 text-xs font-medium leading-relaxed text-slate-500"
>
上传成功后,系统将自动解析并显示数据
</p>
</div>
</div>
</div>
</div>
</div>
<!-- 底部全局按钮 -->
<div class="flex justify-center gap-4 pt-4">
<Button :disabled="csvData.length === 0" @click="handleClearData">
清空当前选择
</Button>
<Button
type="primary"
:disabled="csvHeaders.length === 0"
@click="handleCreateImportTask"
>
创建导入任务
</Button>
</div>
</div>
@@ -342,7 +276,7 @@ onUnmounted(() => {
<div v-else class="flex min-h-0 w-full flex-1 flex-col overflow-hidden">
<div
class="mb-6 flex shrink-0 flex-wrap items-start justify-between gap-4"
>
>
<div class="flex-1">
<h2 class="mb-1 text-2xl font-bold text-slate-800">数据预览</h2>
<p class="m-0 text-sm text-slate-500">
@@ -102,7 +102,7 @@ const handleDelete = (product: ProductVO.Info) => {
</span>
</div>
<span class="ml-4 font-semibold text-red-500 dark:text-red-400">
¥{{ spec.costPrice.toFixed(2) }}
¥{{ spec.productCost.toFixed(2) }}
</span>
</div>
</div>
@@ -17,7 +17,7 @@ import {
} from 'ant-design-vue';
import { createProductApi, updateProductApi } from '#/api/ecommerce/product';
import { uploadImageApi } from '#/api/media/image';
import { uploadFileToOss } from '#/utils/oss-upload';
interface Emits {
(e: 'success'): void;
@@ -30,9 +30,9 @@ const emit = defineEmits<Emits>();
// 创建Vben Modal实例
const [Modal, modalApi] = useVbenModal({
title: '添加商品',
class: 'w-[800px]',
class: 'w-[1000px]',
draggable: true, // 开启拖拽
contentClass: 'px-6 py-4',
contentClass: 'px-5 py-4',
onConfirm: handleSubmit,
onCancel: close,
onOpenChange: (isOpen: boolean) => {
@@ -67,10 +67,7 @@ const imageLoadError = ref(false); // 图片加载错误状态
const formData = ref({
name: '',
productCode: '',
specCode: '',
skuCode: '',
mainImageId: undefined as number | undefined,
costPrice: 0,
});
// 规格数据 - 支持创建和更新
@@ -88,30 +85,17 @@ const currentImageUrl = computed(() => {
// 初始化表单数据
function initFormData() {
if (isEdit.value && currentProductData.value) {
// 编辑模式
// 注意:ProductVO.Info 中可能没有 specCode、skuCode、costPrice 字段
// 这些字段可能需要在编辑时从其他地方获取或设置为空
const productData = currentProductData.value as any;
formData.value = {
name: currentProductData.value.name || '',
productCode: currentProductData.value.productCode || '',
specCode: productData.specCode || '',
skuCode: productData.skuCode || '',
mainImageId: undefined,
costPrice: productData.costPrice ?? 0,
};
// 设置原始图片 URL
originalImageUrl.value = currentProductData.value.mainImage || '';
} else {
// 创建模式 - 如果有传入的productData,则使用它来初始化表单
formData.value = {
name: currentProductData.value?.name || '',
productCode: currentProductData.value?.productCode || '',
specCode: '',
skuCode: '',
mainImageId: undefined,
costPrice: 0,
};
originalImageUrl.value = currentProductData.value?.mainImage || '';
}
@@ -130,25 +114,25 @@ function initFormData() {
'specs' in currentProductData.value &&
currentProductData.value.specs
) {
if (isEdit.value) {
// 编辑模式:使用 UpdateSpec 格式,包含 id
specs.value = currentProductData.value.specs.map(
(spec) =>
({
id: (spec as ProductVO.SpecInfo).id,
name: (spec as ProductVO.SpecInfo).name || spec.specCode || '',
specCode: spec.specCode || '',
costPrice: spec.costPrice || 0,
}) as ProductDTO.UpdateSpec,
);
} else {
// 创建模式:使用 Spec 格式
specs.value = currentProductData.value.specs.map((spec) => ({
name: (spec as ProductVO.SpecInfo).name || spec.specCode || '',
specCode: spec.specCode || '',
costPrice: spec.costPrice || 0,
}));
}
const mapSpec = (spec: ProductVO.SpecInfo) => ({
name: spec.name || spec.specCode || '',
specCode: spec.specCode || '',
productCost: spec.productCost ?? 0,
shippingCost: spec.shippingCost ?? 0,
otherCost: spec.otherCost ?? 0,
remark: spec.remark || '',
});
specs.value = isEdit.value
? currentProductData.value.specs.map(
(spec) =>
({
id: (spec as ProductVO.SpecInfo).id,
...mapSpec(spec as ProductVO.SpecInfo),
}) as ProductDTO.UpdateSpec,
)
: currentProductData.value.specs.map((spec) =>
mapSpec(spec as ProductVO.SpecInfo),
);
showSpecs.value = specs.value.length > 0;
}
}
@@ -305,22 +289,21 @@ function removeNewImage() {
message.success('已重置图片');
}
const defaultSpec = (): ProductDTO.Spec => ({
name: '',
specCode: '',
productCost: 0,
shippingCost: 0,
otherCost: 0,
remark: '',
});
// 添加规格
function addSpec() {
if (isEdit.value) {
// 编辑模式:新增的规格暂时不包含id,服务器端会识别并创建新规格
specs.value.push({
name: '',
specCode: '',
costPrice: 0,
} as ProductDTO.Spec);
specs.value.push(defaultSpec() as ProductDTO.Spec);
} else {
// 创建模式
specs.value.push({
name: '',
specCode: '',
costPrice: 0,
});
specs.value.push(defaultSpec());
}
}
@@ -335,7 +318,7 @@ const specColumns = [
title: '规格名称',
dataIndex: 'name',
key: 'name',
width: '30%',
width: 300,
customRender: ({
record,
}: {
@@ -354,7 +337,7 @@ const specColumns = [
title: '规格编码',
dataIndex: 'specCode',
key: 'specCode',
width: '30%',
width: 140,
customRender: ({
record,
}: {
@@ -370,23 +353,86 @@ const specColumns = [
},
},
{
title: '成本价',
dataIndex: 'costPrice',
key: 'costPrice',
width: '25%',
title: '商品成本',
dataIndex: 'productCost',
key: 'productCost',
width: 100,
customRender: ({
record,
}: {
record: ProductDTO.Spec | ProductDTO.UpdateSpec;
}) => {
return h(InputNumber, {
value: record.costPrice,
placeholder: '请输入成本价',
value: record.productCost,
placeholder: '商品成本',
min: 0,
precision: 2,
style: { width: '100%' },
'onUpdate:value': (value: null | number) => {
record.costPrice = value ?? 0;
record.productCost = value ?? 0;
},
} as any);
},
},
{
title: '运费成本',
dataIndex: 'shippingCost',
key: 'shippingCost',
width: 90,
customRender: ({
record,
}: {
record: ProductDTO.Spec | ProductDTO.UpdateSpec;
}) => {
return h(InputNumber, {
value: record.shippingCost ?? 0,
placeholder: '运费',
min: 0,
precision: 2,
style: { width: '100%' },
'onUpdate:value': (value: null | number) => {
record.shippingCost = value ?? 0;
},
} as any);
},
},
{
title: '其他成本',
dataIndex: 'otherCost',
key: 'otherCost',
width: 90,
customRender: ({
record,
}: {
record: ProductDTO.Spec | ProductDTO.UpdateSpec;
}) => {
return h(InputNumber, {
value: record.otherCost ?? 0,
placeholder: '其他',
min: 0,
precision: 2,
style: { width: '100%' },
'onUpdate:value': (value: null | number) => {
record.otherCost = value ?? 0;
},
} as any);
},
},
{
title: '备注',
dataIndex: 'remark',
key: 'remark',
width: 100,
customRender: ({
record,
}: {
record: ProductDTO.Spec | ProductDTO.UpdateSpec;
}) => {
return h(Input, {
value: record.remark ?? '',
placeholder: '备注',
'onUpdate:value': (value: string) => {
record.remark = value ?? '';
},
});
},
@@ -394,7 +440,7 @@ const specColumns = [
{
title: '操作',
key: 'action',
width: '15%',
width: 80,
align: 'center' as const,
customRender: ({ index }: { index: number }) => {
return h(
@@ -421,11 +467,13 @@ async function uploadImageAndGetId(): Promise<number | undefined> {
}
try {
const response = await uploadImageApi(newImageFile.value);
return response.id;
const fileInfo = await uploadFileToOss(newImageFile.value, {
category: 'product-main-image',
errorMessage: '主图上传失败',
});
return fileInfo.id;
} catch (error) {
console.error('图片上传失败:', error);
message.error('图片上传失败');
throw error;
}
}
@@ -448,12 +496,7 @@ onUnmounted(() => {
<template>
<Modal>
<Form
ref="formRef"
:model="formData"
:label-col="{ span: 6 }"
:wrapper-col="{ span: 18 }"
>
<Form ref="formRef" :model="formData">
<Form.Item label="商品主图" name="mainImageId">
<div style="display: flex; align-items: center; gap: 16px">
<!-- 主图预览区域 -->
@@ -335,7 +335,7 @@ defineExpose({
white-space: nowrap;
"
>
¥{{ spec.costPrice.toFixed(2) }}
¥{{ spec.productCost.toFixed(2) }}
</span>
</div>
</div>
@@ -8,11 +8,8 @@ import { createIconifyIcon } from '@vben/icons';
import { Button, Form, Input, message, Select } from 'ant-design-vue';
import {
createShopApi,
updateShopApi,
uploadShopLogoApi,
} from '#/api/ecommerce/shop';
import { createShopApi, updateShopApi } from '#/api/ecommerce/shop';
import { uploadFileToOss } from '#/utils/oss-upload';
interface Emits {
(e: 'success'): void;
@@ -230,11 +227,13 @@ async function uploadLogoAndGetId(): Promise<number | undefined> {
}
try {
const response = await uploadShopLogoApi(newLogoFile.value);
return response.id;
const fileInfo = await uploadFileToOss(newLogoFile.value, {
category: 'shop-logo',
errorMessage: 'Logo上传失败',
});
return fileInfo.id;
} catch (error) {
console.error('Logo上传失败:', error);
message.error('Logo上传失败');
throw error;
}
}
@@ -256,13 +255,12 @@ onUnmounted(() => {
</script>
<template>
<Modal :title="modalTitle" :confirm-loading="loading">
<Form
ref="formRef"
:model="formData"
:label-col="{ span: 6 }"
:wrapper-col="{ span: 18 }"
>
<Modal
:title="modalTitle"
:confirm-loading="loading"
content-class="px-5 py-4"
>
<Form ref="formRef" :model="formData">
<Form.Item label="店铺Logo" name="logoImageId">
<div style="display: flex; align-items: center; gap: 16px">
<!-- Logo预览区域 -->
@@ -227,7 +227,7 @@ function handleModalSuccess() {
// 处理查看详情
function handleViewDetails(record: ShopVO.Info) {
router.push(`/ecom/shop/details/${record.id}`);
router.push(`/ecom/shop/overview/${record.id}`);
}
</script>
@@ -267,6 +267,48 @@ watch(
// 初始化
onMounted(() => {
// 检查查询参数,如果有则设置时间范围
const query = route.query;
if (query.startDate && query.endDate) {
const startDate = dayjs(query.startDate as string);
const endDate = dayjs(query.endDate as string);
const today = dayjs();
if (startDate.isValid() && endDate.isValid()) {
dateRange.value = [startDate, endDate];
// 判断时间范围类型
const daysDiff = endDate.diff(startDate, 'day');
const isEndDateToday = endDate.isSame(today, 'day');
const isStartDate7DaysAgo = startDate.isSame(
dayjs().subtract(7, 'day'),
'day',
);
const isStartDate30DaysAgo = startDate.isSame(
dayjs().subtract(30, 'day'),
'day',
);
if (daysDiff === 0 && startDate.isSame(today, 'day')) {
activeTimeRange.value = 'today';
} else if (
daysDiff === 0 &&
startDate.isSame(dayjs().subtract(1, 'day'), 'day')
) {
activeTimeRange.value = 'yesterday';
} else if (isEndDateToday && isStartDate7DaysAgo) {
// 近7天:从7天前到今天
activeTimeRange.value = '7days';
} else if (isEndDateToday && isStartDate30DaysAgo) {
// 近30天:从30天前到今天
activeTimeRange.value = '30days';
} else {
activeTimeRange.value = 'custom';
customDateRange.value = [startDate, endDate];
}
}
}
// 设置完时间范围后再加载数据
if (shopId.value) {
loadOverviewData();
}
@@ -274,7 +316,11 @@ onMounted(() => {
</script>
<template>
<Page title="店铺经营概览" auto-content-height class="bg-[#f8fafc]">
<Page
:title="overviewData?.shopName || '店铺经营概览'"
auto-content-height
class="bg-[#f8fafc]"
>
<template #description>
<div class="mt-1 text-sm font-bold italic text-slate-500">
数据更新于:{{ dayjs().format('今日 HH:mm:ss') }}