feat:【mall 商城】商城首页的迁移【antd】30%:shortcut-card、operation-data-card.vue

This commit is contained in:
YunaiV
2025-10-19 10:25:04 +08:00
parent 95fffb8af0
commit 7b8a7efc5b
2 changed files with 31 additions and 30 deletions

View File

@@ -2,10 +2,10 @@
import { onActivated, onMounted, reactive } from 'vue'; import { onActivated, onMounted, reactive } from 'vue';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import { Card } from 'ant-design-vue';
import { CountTo } from '@vben/common-ui'; import { CountTo } from '@vben/common-ui';
import { Card } from 'ant-design-vue';
import * as ProductSpuApi from '#/api/mall/product/spu'; import * as ProductSpuApi from '#/api/mall/product/spu';
import * as PayStatisticsApi from '#/api/mall/statistics/pay'; import * as PayStatisticsApi from '#/api/mall/statistics/pay';
import * as TradeStatisticsApi from '#/api/mall/statistics/trade'; import * as TradeStatisticsApi from '#/api/mall/statistics/trade';
@@ -15,6 +15,15 @@ defineOptions({ name: 'OperationDataCard' });
const router = useRouter(); const router = useRouter();
/** 数据项接口 */
interface DataItem {
name: string;
value: number;
routerName: string;
prefix?: string;
decimals?: number;
}
/** 数据 */ /** 数据 */
const data = reactive({ const data = reactive({
orderUndelivered: { name: '待发货订单', value: 0, routerName: 'TradeOrder' }, orderUndelivered: { name: '待发货订单', value: 0, routerName: 'TradeOrder' },
@@ -34,7 +43,7 @@ const data = reactive({
}, },
rechargePrice: { rechargePrice: {
name: '账户充值', name: '账户充值',
value: 0.0, value: 0,
prefix: '¥', prefix: '¥',
decimals: 2, decimals: 2,
routerName: 'PayWalletRecharge', routerName: 'PayWalletRecharge',
@@ -44,16 +53,16 @@ const data = reactive({
/** 查询订单数据 */ /** 查询订单数据 */
const getOrderData = async () => { const getOrderData = async () => {
const orderCount = await TradeStatisticsApi.getOrderCount(); const orderCount = await TradeStatisticsApi.getOrderCount();
if (orderCount.undelivered != null) { if (orderCount.undelivered) {
data.orderUndelivered.value = orderCount.undelivered; data.orderUndelivered.value = orderCount.undelivered;
} }
if (orderCount.afterSaleApply != null) { if (orderCount.afterSaleApply) {
data.orderAfterSaleApply.value = orderCount.afterSaleApply; data.orderAfterSaleApply.value = orderCount.afterSaleApply;
} }
if (orderCount.pickUp != null) { if (orderCount.pickUp) {
data.orderWaitePickUp.value = orderCount.pickUp; data.orderWaitePickUp.value = orderCount.pickUp;
} }
if (orderCount.auditingWithdraw != null) { if (orderCount.auditingWithdraw) {
data.withdrawAuditing.value = orderCount.auditingWithdraw; data.withdrawAuditing.value = orderCount.auditingWithdraw;
} }
}; };
@@ -61,9 +70,9 @@ const getOrderData = async () => {
/** 查询商品数据 */ /** 查询商品数据 */
const getProductData = async () => { const getProductData = async () => {
const productCount = await ProductSpuApi.getTabsCount(); const productCount = await ProductSpuApi.getTabsCount();
data.productForSale.value = productCount['0']; data.productForSale.value = productCount['0'] || 0;
data.productInWarehouse.value = productCount['1']; data.productInWarehouse.value = productCount['1'] || 0;
data.productAlertStock.value = productCount['3']; data.productAlertStock.value = productCount['3'] || 0;
}; };
/** 查询钱包充值数据 */ /** 查询钱包充值数据 */
@@ -72,11 +81,8 @@ const getWalletRechargeData = async () => {
data.rechargePrice.value = paySummary.rechargePrice; data.rechargePrice.value = paySummary.rechargePrice;
}; };
/** /** 跳转到对应页面 */
* 跳转到对应页面 // TODO @xingyu貌似通过 name 的方式,都无法跳转,找不到路由?
*
* @param routerName 路由页面组件的名称
*/
const handleClick = (routerName: string) => { const handleClick = (routerName: string) => {
router.push({ name: routerName }); router.push({ name: routerName });
}; };
@@ -100,15 +106,15 @@ onMounted(() => {
<Card :bordered="false" title="运营数据"> <Card :bordered="false" title="运营数据">
<div class="flex flex-row flex-wrap items-center gap-8 p-4"> <div class="flex flex-row flex-wrap items-center gap-8 p-4">
<div <div
v-for="item in data" v-for="(item, key) in data"
:key="item.name" :key="key"
class="flex h-20 w-[20%] cursor-pointer flex-col items-center justify-center gap-2" class="flex h-20 w-[20%] cursor-pointer flex-col items-center justify-center gap-2"
@click="handleClick(item.routerName)" @click="handleClick(item.routerName)"
> >
<CountTo <CountTo
:decimals="item.decimals || 0" :decimals="(item as DataItem).decimals ?? 0"
:end-val="item.value" :end-val="item.value"
:prefix="item.prefix || ''" :prefix="(item as DataItem).prefix ?? ''"
class="text-3xl" class="text-3xl"
/> />
<span class="text-center">{{ item.name }}</span> <span class="text-center">{{ item.name }}</span>
@@ -116,4 +122,3 @@ onMounted(() => {
</div> </div>
</Card> </Card>
</template> </template>

View File

@@ -1,10 +1,10 @@
<script lang="ts" setup> <script lang="ts" setup>
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import { Card } from 'ant-design-vue';
import { IconifyIcon } from '@vben/icons'; import { IconifyIcon } from '@vben/icons';
import { Card } from 'ant-design-vue';
/** 快捷入口卡片 */ /** 快捷入口卡片 */
defineOptions({ name: 'ShortcutCard' }); defineOptions({ name: 'ShortcutCard' });
@@ -62,14 +62,11 @@ const menuList = [
}, },
]; ];
/** /** 跳转到菜单对应页面 */
* 跳转到菜单对应页面 // TODO @xingyu貌似通过 name 的方式,都无法跳转,找不到路由?
* function handleMenuClick(routerName: string) {
* @param routerName 路由页面组件的名称
*/
const handleMenuClick = (routerName: string) => {
router.push({ name: routerName }); router.push({ name: routerName });
}; }
</script> </script>
<template> <template>
@@ -92,4 +89,3 @@ const handleMenuClick = (routerName: string) => {
</div> </div>
</Card> </Card>
</template> </template>