feat:【代码优化】减少部分模块的 import * 的 API

This commit is contained in:
YunaiV
2025-10-27 09:34:45 +08:00
parent d2db16c8c6
commit 86c68b5466
35 changed files with 185 additions and 164 deletions

View File

@@ -10,7 +10,7 @@ import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
import { Card, Radio, RadioGroup, Spin } from 'ant-design-vue';
import dayjs from 'dayjs';
import * as MemberStatisticsApi from '#/api/mall/statistics/member';
import { getMemberRegisterCountList } from '#/api/mall/statistics/member';
import {
getMemberStatisticsChartOptions,
@@ -71,13 +71,13 @@ async function handleTimeRangeTypeChange() {
}
}
// 发送时间范围选中事件
await getMemberRegisterCountList(beginTime, endTime);
await loadMemberRegisterCountList(beginTime, endTime);
}
async function getMemberRegisterCountList(beginTime: Dayjs, endTime: Dayjs) {
async function loadMemberRegisterCountList(beginTime: Dayjs, endTime: Dayjs) {
loading.value = true;
try {
const list = await MemberStatisticsApi.getMemberRegisterCountList(
const list = await getMemberRegisterCountList(
beginTime.toDate(),
endTime.toDate(),
);

View File

@@ -6,9 +6,9 @@ import { CountTo } from '@vben/common-ui';
import { Card } from 'ant-design-vue';
import * as ProductSpuApi from '#/api/mall/product/spu';
import * as PayStatisticsApi from '#/api/mall/statistics/pay';
import * as TradeStatisticsApi from '#/api/mall/statistics/trade';
import { getTabsCount } from '#/api/mall/product/spu';
import { getWalletRechargePrice } from '#/api/mall/statistics/pay';
import { getOrderCount } from '#/api/mall/statistics/trade';
/** 运营数据卡片 */
defineOptions({ name: 'OperationDataCard' });
@@ -51,8 +51,8 @@ const data = reactive({
});
/** 查询订单数据 */
async function getOrderData() {
const orderCount = await TradeStatisticsApi.getOrderCount();
async function loadOrderData() {
const orderCount = await getOrderCount();
if (orderCount.undelivered) {
data.orderUndelivered.value = orderCount.undelivered;
}
@@ -68,16 +68,16 @@ async function getOrderData() {
}
/** 查询商品数据 */
async function getProductData() {
const productCount = await ProductSpuApi.getTabsCount();
async function loadProductData() {
const productCount = await getTabsCount();
data.productForSale.value = productCount['0'] || 0;
data.productInWarehouse.value = productCount['1'] || 0;
data.productAlertStock.value = productCount['3'] || 0;
}
/** 查询钱包充值数据 */
async function getWalletRechargeData() {
const paySummary = await PayStatisticsApi.getWalletRechargePrice();
async function loadWalletRechargeData() {
const paySummary = await getWalletRechargePrice();
data.rechargePrice.value = paySummary.rechargePrice;
}
@@ -88,16 +88,16 @@ function handleClick(routerName: string) {
/** 激活时 */
onActivated(() => {
getOrderData();
getProductData();
getWalletRechargeData();
loadOrderData();
loadProductData();
loadWalletRechargeData();
});
/** 初始化 */
onMounted(() => {
getOrderData();
getProductData();
getWalletRechargeData();
loadOrderData();
loadProductData();
loadWalletRechargeData();
});
</script>

View File

@@ -11,7 +11,7 @@ import { fenToYuan } from '@vben/utils';
import { Card, Radio, RadioGroup, Spin } from 'ant-design-vue';
import dayjs from 'dayjs';
import * as TradeStatisticsApi from '#/api/mall/statistics/trade';
import { getOrderCountTrendComparison } from '#/api/mall/statistics/trade';
import {
getTradeTrendChartOptions,
@@ -76,15 +76,15 @@ async function handleTimeRangeTypeChange() {
}
}
// 发送时间范围选中事件
await getOrderCountTrendComparison(beginTime, endTime);
await loadOrderCountTrendComparison(beginTime, endTime);
}
/** 查询订单数量趋势对照数据 */
async function getOrderCountTrendComparison(beginTime: Dayjs, endTime: Dayjs) {
async function loadOrderCountTrendComparison(beginTime: Dayjs, endTime: Dayjs) {
loading.value = true;
try {
// 1. 查询数据
const list = await TradeStatisticsApi.getOrderCountTrendComparison(
const list = await getOrderCountTrendComparison(
timeRangeType.value,
beginTime.toDate(),
endTime.toDate(),

View File

@@ -42,7 +42,6 @@ const selectCategoryId = computed({
/** 初始化 */
const categoryList = ref<any[]>([]); // 分类树
onMounted(async () => {
// 获得分类树
const data = await getCategoryList({
parentId: props.parentId,
});

View File

@@ -5,7 +5,7 @@ import type { MallCouponTemplateApi } from '#/api/mall/promotion/coupon/couponTe
import { onMounted, ref, watch } from 'vue';
import * as CouponTemplateApi from '#/api/mall/promotion/coupon/couponTemplate';
import {
CouponDiscount,
@@ -23,7 +23,7 @@ watch(
() => props.property.couponIds,
async () => {
if (props.property.couponIds?.length > 0) {
couponList.value = await CouponTemplateApi.getCouponTemplateList(
couponList.value = await getCouponTemplateList(
props.property.couponIds,
);
}

View File

@@ -9,7 +9,7 @@ import { fenToYuan } from '@vben/utils';
import { Image } from 'ant-design-vue';
import * as ProductSpuApi from '#/api/mall/product/spu';
import { getSpuDetailList } from '#/api/mall/product/spu';
/** 商品卡片 */
defineOptions({ name: 'ProductCard' });
@@ -20,7 +20,7 @@ const spuList = ref<MallSpuApi.Spu[]>([]);
watch(
() => props.property.spuIds,
async () => {
spuList.value = await ProductSpuApi.getSpuDetailList(props.property.spuIds);
spuList.value = await getSpuDetailList(props.property.spuIds);
},
{
immediate: true,

View File

@@ -7,7 +7,7 @@ import { onMounted, ref, watch } from 'vue';
import { fenToYuan } from '@vben/utils';
import * as ProductSpuApi from '#/api/mall/product/spu';
import { getSpuDetailList } from '#/api/mall/product/spu';
/** 商品栏 */
defineOptions({ name: 'ProductList' });
@@ -18,7 +18,7 @@ const spuList = ref<MallSpuApi.Spu[]>([]);
watch(
() => props.property.spuIds,
async () => {
spuList.value = await ProductSpuApi.getSpuDetailList(props.property.spuIds);
spuList.value = await getSpuDetailList(props.property.spuIds);
},
{
immediate: true,

View File

@@ -5,7 +5,7 @@ import type { MallArticleApi } from '#/api/mall/promotion/article';
import { ref, watch } from 'vue';
import * as ArticleApi from '#/api/mall/promotion/article/index';
/** 营销文章 */
defineOptions({ name: 'PromotionArticle' });
@@ -18,7 +18,7 @@ watch(
() => props.property.id,
async () => {
if (props.property.id) {
article.value = await ArticleApi.getArticle(props.property.id);
article.value = await getArticle(props.property.id);
}
},
{

View File

@@ -9,7 +9,7 @@ import { useVModel } from '@vueuse/core';
import { Form, FormItem, Select } from 'ant-design-vue';
import * as ArticleApi from '#/api/mall/promotion/article/index';
import ComponentContainerProperty from '../../component-container-property.vue';
@@ -27,7 +27,7 @@ const loading = ref(false);
// 查询文章列表
const queryArticleList = async (title?: string) => {
loading.value = true;
const { list } = await ArticleApi.getArticlePage({
const { list } = await getArticlePage({
title,
pageNo: 1,
pageSize: 10,

View File

@@ -10,8 +10,8 @@ import { fenToYuan } from '@vben/utils';
import { Image } from 'ant-design-vue';
import * as ProductSpuApi from '#/api/mall/product/spu';
import * as CombinationActivityApi from '#/api/mall/promotion/combination/combinationActivity';
import { getSpuDetailList } from '#/api/mall/product/spu';
import { getCombinationActivityListByIds, getCombinationActivityPage } from '#/api/mall/promotion/combination/combinationActivity';
/** 拼团卡片 */
defineOptions({ name: 'PromotionCombination' });
@@ -34,7 +34,7 @@ watch(
if (Array.isArray(activityIds) && activityIds.length > 0) {
// 获取拼团活动详情列表
combinationActivityList.value =
await CombinationActivityApi.getCombinationActivityListByIds(
await getCombinationActivityListByIds(
activityIds,
);
@@ -44,7 +44,7 @@ watch(
.map((activity) => activity.spuId)
.filter((spuId): spuId is number => typeof spuId === 'number');
if (spuIdList.value.length > 0) {
spuList.value = await ProductSpuApi.getSpuDetailList(spuIdList.value);
spuList.value = await getSpuDetailList(spuIdList.value);
}
// 更新 SPU 的最低价格

View File

@@ -24,7 +24,7 @@ import {
Tooltip,
} from 'ant-design-vue';
import * as CombinationActivityApi from '#/api/mall/promotion/combination/combinationActivity';
import { getCombinationActivityListByIds, getCombinationActivityPage } from '#/api/mall/promotion/combination/combinationActivity';
import UploadImg from '#/components/upload/image-upload.vue';
import CombinationShowcase from '#/views/mall/promotion/combination/components/combination-showcase.vue';
import { ColorInput } from '#/views/mall/promotion/components';
@@ -38,7 +38,7 @@ const formData = useVModel(props, 'modelValue', emit);
// 活动列表
const activityList = ref<MallCombinationActivityApi.CombinationActivity[]>([]);
onMounted(async () => {
const { list } = await CombinationActivityApi.getCombinationActivityPage({
const { list } = await getCombinationActivityPage({
pageNo: 1,
pageSize: 10,
status: CommonStatusEnum.ENABLE,

View File

@@ -9,8 +9,8 @@ import { fenToYuan } from '@vben/utils';
import { Image } from 'ant-design-vue';
import * as ProductSpuApi from '#/api/mall/product/spu';
import * as PointActivityApi from '#/api/mall/promotion/point';
import { getSpuDetailList } from '#/api/mall/product/spu';
/** 积分商城卡片 */
defineOptions({ name: 'PromotionPoint' });
@@ -31,7 +31,7 @@ watch(
if (Array.isArray(activityIds) && activityIds.length > 0) {
// 获取积分商城活动详情列表
pointActivityList.value =
await PointActivityApi.getPointActivityListByIds(activityIds);
await getPointActivityListByIds(activityIds);
// 获取积分商城活动的 SPU 详情列表
spuList.value = [];
@@ -39,7 +39,7 @@ watch(
(activity) => activity.spuId,
);
if (spuIdList.value.length > 0) {
spuList.value = (await ProductSpuApi.getSpuDetailList(
spuList.value = (await getSpuDetailList(
spuIdList.value,
)) as MallPointActivityApi.SpuExtensionWithPoint[];
}

View File

@@ -10,8 +10,8 @@ import { fenToYuan } from '@vben/utils';
import { Image } from 'ant-design-vue';
import * as ProductSpuApi from '#/api/mall/product/spu';
import * as SeckillActivityApi from '#/api/mall/promotion/seckill/seckillActivity';
import { getSpuDetailList } from '#/api/mall/product/spu';
import { getSeckillActivityListByIds } from '#/api/mall/promotion/seckill/seckillActivity';
/** 秒杀卡片 */
defineOptions({ name: 'PromotionSeckill' });
@@ -32,7 +32,7 @@ watch(
if (Array.isArray(activityIds) && activityIds.length > 0) {
// 获取秒杀活动详情列表
seckillActivityList.value =
await SeckillActivityApi.getSeckillActivityListByIds(activityIds);
await getSeckillActivityListByIds(activityIds);
// 获取秒杀活动的 SPU 详情列表
spuList.value = [];
@@ -40,7 +40,7 @@ watch(
.map((activity) => activity.spuId)
.filter((spuId): spuId is number => typeof spuId === 'number');
if (spuIdList.value.length > 0) {
spuList.value = await ProductSpuApi.getSpuDetailList(spuIdList.value);
spuList.value = await getSpuDetailList(spuIdList.value);
}
// 更新 SPU 的最低价格

View File

@@ -55,7 +55,7 @@ async function initGiveCouponList() {
// return;
// }
// const tempLateIds = Object.keys(rewardRule.value.giveCouponTemplateCounts);
// const data = await CouponTemplateApi.getCouponTemplateList(tempLateIds);
// const data = await getCouponTemplateList(tempLateIds);
// if (!data) {
// return;
// }

View File

@@ -8,7 +8,7 @@ import { fenToYuan } from '@vben/utils';
import { Col, Row } from 'ant-design-vue';
import * as MemberStatisticsApi from '#/api/mall/statistics/member';
import { getMemberSummary } from '#/api/mall/statistics/member';
import MemberAreaCard from './modules/area-card.vue';
import MemberFunnelCard from './modules/funnel-card.vue';
@@ -22,15 +22,15 @@ const loading = ref(true); // 加载中
const summary = ref<MallMemberStatisticsApi.Summary>(); // 会员统计数据
/** 查询会员统计 */
async function getMemberSummary() {
summary.value = await MemberStatisticsApi.getMemberSummary();
async function loadMemberSummary() {
summary.value = await getMemberSummary();
}
/** 初始化 */
onMounted(async () => {
loading.value = true;
try {
await getMemberSummary();
await loadMemberSummary();
} finally {
loading.value = false;
}

View File

@@ -10,7 +10,7 @@ import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
import { Card, Spin } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import * as MemberStatisticsApi from '#/api/mall/statistics/member';
import { getMemberAreaStatisticsList } from '#/api/mall/statistics/member';
import { getAreaChartOptions, getAreaTableColumns } from './area-chart-options';
@@ -44,10 +44,10 @@ const [Grid, gridApi] = useVbenVxeGrid({
});
/** 按照省份,查询会员统计列表 */
async function getMemberAreaStatisticsList() {
async function loadMemberAreaStatisticsList() {
loading.value = true;
try {
const list = await MemberStatisticsApi.getMemberAreaStatisticsList();
const list = await getMemberAreaStatisticsList();
areaStatisticsList.value = list.map(
(item: MallMemberStatisticsApi.AreaStatistics) => ({
...item,
@@ -80,7 +80,7 @@ function areaReplace(areaName: string): string {
/** 初始化 */
onMounted(() => {
getMemberAreaStatisticsList();
loadMemberAreaStatisticsList();
});
</script>

View File

@@ -7,7 +7,7 @@ import { fenToYuan } from '@vben/utils';
import { Card } from 'ant-design-vue';
import * as MemberStatisticsApi from '#/api/mall/statistics/member';
import { getMemberAnalyse } from '#/api/mall/statistics/member';
import { ShortcutDateRangePicker } from '#/components/shortcut-date-range-picker';
/** 会员概览卡片 */
@@ -23,7 +23,7 @@ async function loadData(times: [Dayjs, Dayjs]) {
}
loading.value = true;
try {
analyseData.value = await MemberStatisticsApi.getMemberAnalyse({
analyseData.value = await getMemberAnalyse({
times,
});
} finally {

View File

@@ -11,7 +11,7 @@ import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
import { Card, Spin } from 'ant-design-vue';
import * as MemberStatisticsApi from '#/api/mall/statistics/member';
import { getMemberSexStatisticsList } from '#/api/mall/statistics/member';
import { getSexChartOptions } from './sex-chart-options';
@@ -23,10 +23,10 @@ const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
/** 按照性别,查询会员统计列表 */
async function getMemberSexStatisticsList() {
async function loadMemberSexStatisticsList() {
loading.value = true;
try {
const list = await MemberStatisticsApi.getMemberSexStatisticsList();
const list = await getMemberSexStatisticsList();
const dictDataList = getDictOptions(DICT_TYPE.SYSTEM_USER_SEX, 'number');
dictDataList.push({ label: '未知', value: null } as any);
const chartData = dictDataList.map((dictData: any) => {
@@ -49,7 +49,7 @@ async function getMemberSexStatisticsList() {
/** 初始化 */
onMounted(() => {
getMemberSexStatisticsList();
loadMemberSexStatisticsList();
});
</script>

View File

@@ -8,7 +8,7 @@ import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
import { Card, Spin } from 'ant-design-vue';
import * as MemberStatisticsApi from '#/api/mall/statistics/member';
import { getMemberTerminalStatisticsList } from '#/api/mall/statistics/member';
import { getTerminalChartOptions } from './terminal-chart-options';
@@ -20,10 +20,10 @@ const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
/** 按照终端,查询会员统计列表 */
const getMemberTerminalStatisticsList = async () => {
const loadMemberTerminalStatisticsList = async () => {
loading.value = true;
try {
const list = await MemberStatisticsApi.getMemberTerminalStatisticsList();
const list = await getMemberTerminalStatisticsList();
const dictDataList = getDictOptions('terminal', 'number');
const chartData = dictDataList.map((dictData: any) => {
const userCount = list.find(
@@ -43,7 +43,7 @@ const getMemberTerminalStatisticsList = async () => {
/** 初始化 */
onMounted(() => {
getMemberTerminalStatisticsList();
loadMemberTerminalStatisticsList();
});
</script>

View File

@@ -21,8 +21,13 @@ import {
import { Button, Card, Col, Row, Spin } from 'ant-design-vue';
import dayjs from 'dayjs';
import * as ProductStatisticsApi from '#/api/mall/statistics/product';
import {
exportProductStatisticsExcel,
getProductStatisticsAnalyse,
getProductStatisticsList,
} from '#/api/mall/statistics/product';
import ShortcutDateRangePicker from '#/components/shortcut-date-range-picker/shortcut-date-range-picker.vue';
import { $t } from '#/locales';
import { getProductSummaryChartOptions } from './summary-chart-options';
@@ -51,7 +56,7 @@ const calculateRelativeRate = (value?: number, reference?: number): string => {
/** 处理日期范围变化 */
const handleDateRangeChange = (times?: [Dayjs, Dayjs]) => {
if (times?.length !== 2) {
getProductTrendData();
loadProductTrendData();
return;
}
// 处理时间: 开始与截止在同一天的, 折线图出不来, 需要延长一天
@@ -65,29 +70,29 @@ const handleDateRangeChange = (times?: [Dayjs, Dayjs]) => {
];
// 查询数据
getProductTrendData();
loadProductTrendData();
};
/** 处理商品状况查询 */
const getProductTrendData = async () => {
const loadProductTrendData = async () => {
trendLoading.value = true;
try {
await Promise.all([getProductTrendSummary(), getProductStatisticsList()]);
await Promise.all([loadProductTrendSummary(), loadProductStatisticsList()]);
} finally {
trendLoading.value = false;
}
};
/** 查询商品状况数据统计 */
async function getProductTrendSummary() {
trendSummary.value = await ProductStatisticsApi.getProductStatisticsAnalyse({
async function loadProductTrendSummary() {
trendSummary.value = await getProductStatisticsAnalyse({
times: searchTimes.value.length > 0 ? searchTimes.value : undefined,
});
}
/** 查询商品状况数据列表 */
async function getProductStatisticsList() {
const list = await ProductStatisticsApi.getProductStatisticsList({
async function loadProductStatisticsList() {
const list = await getProductStatisticsList({
times: searchTimes.value.length > 0 ? searchTimes.value : undefined,
});
@@ -104,7 +109,7 @@ async function handleExport() {
});
// 发起导出
exportLoading.value = true;
const data = await ProductStatisticsApi.exportProductStatisticsExcel({
const data = await exportProductStatisticsExcel({
times: searchTimes.value.length > 0 ? searchTimes.value : undefined,
});
// 处理下载
@@ -125,7 +130,7 @@ async function handleExport() {
<template #icon>
<IconifyIcon icon="lucide:download" />
</template>
导出
{{ $t('page.action.export') }}
</Button>
</ShortcutDateRangePicker>
</div>

View File

@@ -9,7 +9,7 @@ import { fenToYuan } from '@vben/utils';
import { Col, Row } from 'ant-design-vue';
import * as TradeStatisticsApi from '#/api/mall/statistics/trade';
import { getTradeStatisticsSummary } from '#/api/mall/statistics/trade';
import TradeTrendCard from './modules/trend-card.vue';
@@ -31,14 +31,14 @@ function calculateRelativeRate(value?: number, reference?: number): string {
}
/** 查询交易统计 */
async function getTradeStatisticsSummary() {
summary.value = await TradeStatisticsApi.getTradeStatisticsSummary();
async function loadTradeStatisticsSummary() {
summary.value = await getTradeStatisticsSummary();
}
/** 初始化 */
onMounted(async () => {
loading.value = true;
await getTradeStatisticsSummary();
await loadTradeStatisticsSummary();
loading.value = false;
});
</script>

View File

@@ -21,8 +21,13 @@ import {
import { Button, Card, Col, Row, Spin } from 'ant-design-vue';
import dayjs from 'dayjs';
import * as TradeStatisticsApi from '#/api/mall/statistics/trade';
import {
exportTradeStatisticsExcel,
getTradeStatisticsAnalyse,
getTradeStatisticsList,
} from '#/api/mall/statistics/trade';
import ShortcutDateRangePicker from '#/components/shortcut-date-range-picker/shortcut-date-range-picker.vue';
import { $t } from '#/locales';
import { getTradeTrendChartOptions } from './trend-chart-options';
@@ -51,7 +56,7 @@ const calculateRelativeRate = (value?: number, reference?: number): string => {
/** 处理日期范围变化 */
const handleDateRangeChange = (times?: [Dayjs, Dayjs]) => {
if (times?.length !== 2) {
getTradeTrendData();
loadTradeTrendData();
return;
}
// 处理时间: 开始与截止在同一天的, 折线图出不来, 需要延长一天
@@ -65,29 +70,32 @@ const handleDateRangeChange = (times?: [Dayjs, Dayjs]) => {
];
// 查询数据
getTradeTrendData();
loadTradeTrendData();
};
/** 处理交易状况查询 */
async function getTradeTrendData() {
async function loadTradeTrendData() {
trendLoading.value = true;
try {
await Promise.all([getTradeStatisticsAnalyse(), getTradeStatisticsList()]);
await Promise.all([
loadTradeStatisticsAnalyse(),
loadTradeStatisticsList(),
]);
} finally {
trendLoading.value = false;
}
}
/** 查询交易状况数据统计 */
async function getTradeStatisticsAnalyse() {
trendSummary.value = await TradeStatisticsApi.getTradeStatisticsAnalyse({
async function loadTradeStatisticsAnalyse() {
trendSummary.value = await getTradeStatisticsAnalyse({
times: searchTimes.value.length > 0 ? searchTimes.value : undefined,
});
}
/** 查询交易状况数据列表 */
async function getTradeStatisticsList() {
const list = await TradeStatisticsApi.getTradeStatisticsList({
async function loadTradeStatisticsList() {
const list = await getTradeStatisticsList({
times: searchTimes.value.length > 0 ? searchTimes.value : undefined,
});
@@ -104,7 +112,7 @@ async function handleExport() {
});
// 发起导出
exportLoading.value = true;
const data = await TradeStatisticsApi.exportTradeStatisticsExcel({
const data = await exportTradeStatisticsExcel({
times: searchTimes.value.length > 0 ? searchTimes.value : undefined,
});
// 处理下载