feat: 优化店铺相关

This commit is contained in:
2026-08-14 11:44:22 +08:00
parent 3322b0542b
commit 8921c6b122
37 changed files with 558 additions and 241 deletions
@@ -0,0 +1,10 @@
import type { PddShopInfo } from '#/api/ecommerce/shop/types';
import { requestClient } from '#/api/request';
/**
* 拼多多渠道店铺详情(含授权信息,不含 token)
*/
export async function getPddShopDetailApi(id: number) {
return requestClient.get<PddShopInfo>(`/channel/pdd/shop/detail/${id}`);
}
@@ -0,0 +1 @@
export * from './apis';
@@ -37,6 +37,13 @@ export async function deleteShopApi(id: number) {
return requestClient.delete(`/ec/shop/delete/${id}`);
}
/**
* 店铺详情(含平台店铺及授权信息)
*/
export async function getShopDetailApi(id: number) {
return requestClient.get<ShopVO.Info>(`/ec/shop/detail/${id}`);
}
/**
* 上传店铺Logo
*/
@@ -2,31 +2,55 @@
* 店铺相关VO类型定义
*/
/** 拼多多外部店铺信息(列表关联返回) */
/** 拼多多授权信息(不含 token) */
export interface PddAuthInfo {
/** 授权主键ID */
id: number;
/** 公司ID */
companyId: number;
/** 拼多多授权主体ID(owner_id) */
ownerId?: string;
/** access_token 过期时间 */
expiresAt?: string;
/** refresh_token 过期时间 */
refreshTokenExpiresAt?: string;
/** 授权 scope(JSON 数组字符串) */
scope?: string;
/** 状态:0=失效 1=正常 2=已撤销 */
status?: number;
/** 创建时间 */
createTime?: string;
/** 更新时间 */
updateTime?: string;
}
/** 拼多多外部店铺信息 */
export interface PddShopInfo {
/** 主键ID */
id: number;
/** 公司ID */
companyId: number;
/** 拼多多授权ID */
companyId?: number;
/** 拼多多授权ID(列表简要也会带,用于判断是否已授权) */
pddAuthId?: null | number;
/** 关联授权信息(仅详情接口返回) */
auth?: null | PddAuthInfo;
/** 拼多多店铺ID(mall_id) */
mallId: number;
mallId?: number;
/** 店铺名称 */
mallName?: string;
/** 店铺logo */
logo?: string;
/** 店铺描述 */
/** 店铺描述(详情) */
mallDesc?: string;
/** 店铺类型:1个人 2企业 3旗舰店 4专卖店 5专营店 6普通店 */
/** 店铺类型(详情) */
merchantType?: number;
/** 店铺身份:0厂商 1分销商 2都不是 3都是 */
/** 店铺身份(详情) */
mallCharacter?: number;
/** 最近一次同步时间 */
/** 最近一次同步时间(详情) */
lastSyncTime?: string;
/** 创建时间 */
/** 创建时间(详情) */
createTime?: string;
/** 更新时间 */
/** 更新时间(详情) */
updateTime?: string;
}
@@ -47,8 +71,8 @@ export namespace ShopVO {
platformCode?: string;
/** 平台名称(后端回填) */
platformName?: string;
/** 外部店铺ID(如拼多多 mall_id) */
externalShopId?: null | string;
/** 外部/平台店铺表主键 ID(如 channel_pdd_shop.id) */
externalShopId?: null | number;
/** 关联的拼多多外部店铺(已授权绑定时返回) */
pddShop?: null | PddShopInfo;
/** 创建时间 */
@@ -1,25 +1,136 @@
<script lang="ts" setup>
import { computed } from 'vue';
import type { ShopVO } from '#/api/ecommerce/shop/types';
import { computed, onMounted, ref, watch } from 'vue';
import { useRoute } from 'vue-router';
import { Page } from '@vben/common-ui';
import { Descriptions, Spin, Tag, message } from 'ant-design-vue';
import { getShopDetailApi } from '#/api/ecommerce/shop';
import {
getPlatformLabel,
getPlatformTagColor,
} from '#/utils/platform-display';
import PddShopDetailModal from '../list/components/PddShopDetailModal.vue';
defineOptions({ name: 'ShopDetails' });
const route = useRoute();
const loading = ref(false);
const shop = ref<null | ShopVO.Info>(null);
const pddShopDetailModalRef = ref<InstanceType<typeof PddShopDetailModal> | null>(
null,
);
const shopId = computed(() => {
const id = route.params.id;
return id ? Number(id) : 0;
});
async function loadDetail() {
if (!shopId.value) {
shop.value = null;
return;
}
try {
loading.value = true;
shop.value = await getShopDetailApi(shopId.value);
} catch (error) {
console.error('获取店铺详情失败:', error);
message.error('获取店铺详情失败');
shop.value = null;
} finally {
loading.value = false;
}
}
function openPddShopDetail() {
const pddShopId = shop.value?.pddShop?.id ?? shop.value?.externalShopId;
if (!pddShopId) {
message.warning('暂无平台店铺信息');
return;
}
pddShopDetailModalRef.value?.open(Number(pddShopId), shop.value?.name);
}
onMounted(loadDetail);
watch(shopId, loadDetail);
</script>
<template>
<Page
:title="shopId ? `店铺详情(#${shopId})` : '店铺详情'"
:title="shop ? shop.name : shopId ? `店铺详情(#${shopId})` : '店铺详情'"
auto-content-height
content-class="flex min-h-0 flex-1 flex-col bg-[#f8fafc] dark:bg-[hsl(222.34deg_10.43%_12.27%)]"
content-class="flex min-h-0 flex-1 flex-col bg-[#f8fafc] p-4 dark:bg-[hsl(222.34deg_10.43%_12.27%)]"
>
<div class="text-slate-500">店铺详情看板接口已下线。</div>
<Spin :spinning="loading">
<div v-if="shop" class="space-y-4 rounded-lg bg-white p-5 dark:bg-[hsl(222.34deg_10.43%_14%)]">
<div class="flex items-start gap-4">
<img
v-if="shop.logo"
:src="shop.logo"
:alt="shop.name"
class="h-20 w-20 rounded-md border border-slate-200 object-cover"
/>
<div class="min-w-0 flex-1 space-y-2">
<div class="text-lg font-semibold">{{ shop.name }}</div>
<div class="flex flex-wrap items-center gap-2">
<Tag
v-if="shop.platformCode"
:color="getPlatformTagColor(shop.platformCode)"
>
{{ getPlatformLabel(shop.platformCode, shop.platformName) }}
</Tag>
<Tag v-else color="default">未设置平台</Tag>
</div>
</div>
</div>
<Descriptions :column="2" bordered size="small" title="基础信息">
<Descriptions.Item label="店铺ID">{{ shop.id }}</Descriptions.Item>
<Descriptions.Item label="平台店铺主键">
{{ shop.externalShopId ?? '-' }}
</Descriptions.Item>
<Descriptions.Item label="创建时间">
{{ shop.createTime || '-' }}
</Descriptions.Item>
<Descriptions.Item label="更新时间">
{{ shop.updateTime || '-' }}
</Descriptions.Item>
</Descriptions>
<div v-if="shop.platformCode === 'pdd'">
<Descriptions :column="2" bordered size="small" title="拼多多平台店铺">
<template v-if="shop.pddShop">
<Descriptions.Item label="店铺名称">
<a class="text-primary" @click="openPddShopDetail">
{{ shop.pddShop.mallName || '-' }}
</a>
</Descriptions.Item>
<Descriptions.Item label="mall_id">
{{ shop.pddShop.mallId }}
</Descriptions.Item>
<Descriptions.Item label="授权">
<Tag :color="shop.pddShop.pddAuthId ? 'success' : 'default'">
{{ shop.pddShop.pddAuthId ? '已绑定' : '未绑定' }}
</Tag>
</Descriptions.Item>
<Descriptions.Item label="详情">
<a class="text-primary" @click="openPddShopDetail">查看完整信息</a>
</Descriptions.Item>
</template>
<Descriptions.Item v-else label="绑定状态" :span="2">
未绑定拼多多平台店铺
</Descriptions.Item>
</Descriptions>
</div>
</div>
<div v-else-if="!loading" class="text-slate-500">店铺不存在或暂无数据</div>
</Spin>
<PddShopDetailModal ref="pddShopDetailModalRef" />
</Page>
</template>
@@ -5,7 +5,9 @@ import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { Descriptions, Tag } from 'ant-design-vue';
import { Descriptions, Spin, Tag, message } from 'ant-design-vue';
import { getPddShopDetailApi } from '#/api/ecommerce/pdd/shop';
const MERCHANT_TYPE_MAP: Record<number, string> = {
1: '个人',
@@ -23,6 +25,13 @@ const MALL_CHARACTER_MAP: Record<number, string> = {
3: '都是',
};
const AUTH_STATUS_MAP: Record<number, { color: string; label: string }> = {
0: { color: 'error', label: '失效' },
1: { color: 'success', label: '正常' },
2: { color: 'default', label: '已撤销' },
};
const loading = ref(false);
const pddShop = ref<null | PddShopInfo>(null);
const internalShopName = ref('');
@@ -45,10 +54,34 @@ const mallCharacterLabel = computed(() => {
return MALL_CHARACTER_MAP[character] ?? String(character);
});
function open(shop: PddShopInfo, shopName?: string) {
pddShop.value = shop;
const authStatus = computed(() => {
const status = pddShop.value?.auth?.status;
if (status == null) {
return pddShop.value?.pddAuthId
? { color: 'success', label: '已绑定' }
: { color: 'default', label: '未绑定' };
}
return AUTH_STATUS_MAP[status] ?? { color: 'default', label: String(status) };
});
async function open(pddShopId: number, shopName?: string) {
if (!pddShopId) {
message.warning('暂无外部店铺详情,请先完成授权同步');
return;
}
internalShopName.value = shopName || '';
pddShop.value = null;
modalApi.open();
try {
loading.value = true;
pddShop.value = await getPddShopDetailApi(pddShopId);
} catch (error) {
console.error('获取拼多多店铺详情失败:', error);
message.error('获取拼多多店铺详情失败');
modalApi.close();
} finally {
loading.value = false;
}
}
defineExpose({ open });
@@ -56,52 +89,84 @@ defineExpose({ open });
<template>
<Modal title="拼多多外部店铺" content-class="px-5 py-4">
<div v-if="pddShop" class="space-y-4">
<div class="flex items-center gap-3">
<img
v-if="pddShop.logo"
:src="pddShop.logo"
:alt="pddShop.mallName"
class="h-14 w-14 rounded-md border border-slate-200 object-cover"
/>
<div>
<div class="text-base font-medium">
{{ pddShop.mallName || '-' }}
</div>
<div v-if="internalShopName" class="mt-1 text-xs text-slate-500">
内部店铺:{{ internalShopName }}
<Spin :spinning="loading">
<div v-if="pddShop" class="space-y-4">
<div class="flex items-center gap-3">
<img
v-if="pddShop.logo"
:src="pddShop.logo"
:alt="pddShop.mallName"
class="h-14 w-14 rounded-md border border-slate-200 object-cover"
/>
<div>
<div class="text-base font-medium">
{{ pddShop.mallName || '-' }}
</div>
<div v-if="internalShopName" class="mt-1 text-xs text-slate-500">
内部店铺:{{ internalShopName }}
</div>
</div>
</div>
</div>
<Descriptions :column="1" bordered size="small">
<Descriptions.Item label="mall_id">
{{ pddShop.mallId }}
</Descriptions.Item>
<Descriptions.Item label="授权状态">
<Tag :color="pddShop.pddAuthId ? 'success' : 'default'">
{{ pddShop.pddAuthId ? '已绑定授权' : '未绑定授权' }}
</Tag>
</Descriptions.Item>
<Descriptions.Item label="店铺类型">
{{ merchantTypeLabel }}
</Descriptions.Item>
<Descriptions.Item label="店铺身份">
{{ mallCharacterLabel }}
</Descriptions.Item>
<Descriptions.Item label="店铺描述">
{{ pddShop.mallDesc || '-' }}
</Descriptions.Item>
<Descriptions.Item label="最近同步">
{{ pddShop.lastSyncTime || '-' }}
</Descriptions.Item>
<Descriptions.Item label="创建时间">
{{ pddShop.createTime || '-' }}
</Descriptions.Item>
<Descriptions.Item label="更新时间">
{{ pddShop.updateTime || '-' }}
</Descriptions.Item>
</Descriptions>
</div>
<Descriptions :column="1" bordered size="small" title="店铺信息">
<Descriptions.Item label="平台店铺主键">
{{ pddShop.id }}
</Descriptions.Item>
<Descriptions.Item label="mall_id">
{{ pddShop.mallId }}
</Descriptions.Item>
<Descriptions.Item label="店铺类型">
{{ merchantTypeLabel }}
</Descriptions.Item>
<Descriptions.Item label="店铺身份">
{{ mallCharacterLabel }}
</Descriptions.Item>
<Descriptions.Item label="店铺描述">
{{ pddShop.mallDesc || '-' }}
</Descriptions.Item>
<Descriptions.Item label="最近同步">
{{ pddShop.lastSyncTime || '-' }}
</Descriptions.Item>
<Descriptions.Item label="创建时间">
{{ pddShop.createTime || '-' }}
</Descriptions.Item>
<Descriptions.Item label="更新时间">
{{ pddShop.updateTime || '-' }}
</Descriptions.Item>
</Descriptions>
<Descriptions :column="1" bordered size="small" title="授权信息">
<Descriptions.Item label="授权状态">
<Tag :color="authStatus.color">{{ authStatus.label }}</Tag>
</Descriptions.Item>
<template v-if="pddShop.auth">
<Descriptions.Item label="授权ID">
{{ pddShop.auth.id }}
</Descriptions.Item>
<Descriptions.Item label="owner_id">
{{ pddShop.auth.ownerId || '-' }}
</Descriptions.Item>
<Descriptions.Item label="Token 过期">
{{ pddShop.auth.expiresAt || '-' }}
</Descriptions.Item>
<Descriptions.Item label="Refresh 过期">
{{ pddShop.auth.refreshTokenExpiresAt || '-' }}
</Descriptions.Item>
<Descriptions.Item label="授权时间">
{{ pddShop.auth.createTime || '-' }}
</Descriptions.Item>
<Descriptions.Item label="更新时间">
{{ pddShop.auth.updateTime || '-' }}
</Descriptions.Item>
</template>
<Descriptions.Item v-else label="授权详情">
未绑定授权
</Descriptions.Item>
</Descriptions>
</div>
<div v-else-if="!loading" class="py-8 text-center text-slate-400">
暂无数据
</div>
</Spin>
</Modal>
</template>
@@ -362,11 +362,12 @@ function handleModalSuccess() {
}
function handleViewExternalShop(record: ShopVO.Info) {
if (!record.pddShop) {
const pddShopId = record.pddShop?.id ?? record.externalShopId;
if (!pddShopId) {
message.warning('暂无外部店铺详情,请先完成授权同步');
return;
}
pddShopDetailModalRef.value?.open(record.pddShop, record.name);
pddShopDetailModalRef.value?.open(Number(pddShopId), record.name);
}
function handleSyncPddOrders(record: ShopVO.Info) {
@@ -477,7 +478,7 @@ onUnmounted(() => {
v-else-if="row.externalShopId"
class="text-center text-xs text-slate-500"
>
mall_id: {{ row.externalShopId }}
平台店#{{ row.externalShopId }}
</span>
</div>
<span v-else class="text-slate-400">-</span>