mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 18:29:19 +08:00
feat: 新增拼多多店铺授权
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
import type { PddAuthVO } from './types';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
/**
|
||||
* 获取拼多多店铺授权跳转 URL(绑定指定内部店铺)
|
||||
*/
|
||||
export async function getPddAuthorizeUrlApi(shopId: number) {
|
||||
return requestClient.get<PddAuthVO.AuthorizeUrl>('/ec/pdd/auth/authorize-url', {
|
||||
params: { shopId },
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './apis';
|
||||
export * from './types';
|
||||
@@ -0,0 +1 @@
|
||||
export * from './types.vo';
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* 拼多多授权相关 VO
|
||||
*/
|
||||
export namespace PddAuthVO {
|
||||
/** 授权跳转信息 */
|
||||
export interface AuthorizeUrl {
|
||||
/** 拼多多授权页完整 URL */
|
||||
authorizeUrl: string;
|
||||
/** 本次授权 state */
|
||||
state: string;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,34 @@
|
||||
* 店铺相关VO类型定义
|
||||
*/
|
||||
|
||||
/** 拼多多外部店铺信息(列表关联返回) */
|
||||
export interface PddShopInfo {
|
||||
/** 主键ID */
|
||||
id: number;
|
||||
/** 公司ID */
|
||||
companyId: number;
|
||||
/** 拼多多授权ID */
|
||||
pddAuthId?: null | number;
|
||||
/** 拼多多店铺ID(mall_id) */
|
||||
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;
|
||||
}
|
||||
|
||||
export namespace ShopVO {
|
||||
/** 店铺信息 */
|
||||
export interface Info {
|
||||
@@ -19,6 +47,10 @@ export namespace ShopVO {
|
||||
platformId?: number;
|
||||
/** 平台名称 */
|
||||
platformName?: string;
|
||||
/** 外部店铺ID(如拼多多 mall_id) */
|
||||
externalShopId?: null | string;
|
||||
/** 关联的拼多多外部店铺(已授权绑定时返回) */
|
||||
pddShop?: null | PddShopInfo;
|
||||
/** 创建时间 */
|
||||
createTime: string;
|
||||
/** 更新时间 */
|
||||
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
<script lang="ts" setup>
|
||||
import type { PddShopInfo } from '#/api/ecommerce/shop/types';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { Descriptions, Tag } from 'ant-design-vue';
|
||||
|
||||
const MERCHANT_TYPE_MAP: Record<number, string> = {
|
||||
1: '个人',
|
||||
2: '企业',
|
||||
3: '旗舰店',
|
||||
4: '专卖店',
|
||||
5: '专营店',
|
||||
6: '普通店',
|
||||
};
|
||||
|
||||
const MALL_CHARACTER_MAP: Record<number, string> = {
|
||||
0: '厂商',
|
||||
1: '分销商',
|
||||
2: '都不是',
|
||||
3: '都是',
|
||||
};
|
||||
|
||||
const pddShop = ref<null | PddShopInfo>(null);
|
||||
const internalShopName = ref('');
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
draggable: true,
|
||||
class: 'w-[640px]',
|
||||
showConfirmButton: false,
|
||||
cancelText: '关闭',
|
||||
});
|
||||
|
||||
const merchantTypeLabel = computed(() => {
|
||||
const type = pddShop.value?.merchantType;
|
||||
if (type == null) return '-';
|
||||
return MERCHANT_TYPE_MAP[type] ?? String(type);
|
||||
});
|
||||
|
||||
const mallCharacterLabel = computed(() => {
|
||||
const character = pddShop.value?.mallCharacter;
|
||||
if (character == null) return '-';
|
||||
return MALL_CHARACTER_MAP[character] ?? String(character);
|
||||
});
|
||||
|
||||
function open(shop: PddShopInfo, shopName?: string) {
|
||||
pddShop.value = shop;
|
||||
internalShopName.value = shopName || '';
|
||||
modalApi.open();
|
||||
}
|
||||
|
||||
defineExpose({ open });
|
||||
</script>
|
||||
|
||||
<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 }}
|
||||
</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>
|
||||
</Modal>
|
||||
</template>
|
||||
@@ -1,44 +1,48 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { PlatformVO } from '#/api/ecommerce/platform/types';
|
||||
import type { ShopDTO, ShopVO } from '#/api/ecommerce/shop/types';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
import { computed, onMounted, onUnmounted, ref } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Button, message, Popconfirm, Space } from 'ant-design-vue';
|
||||
import { Button, message, Popconfirm, Space, Tag } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getPddAuthorizeUrlApi } from '#/api/ecommerce/pdd/auth';
|
||||
import { getActivePlatformsApi } from '#/api/ecommerce/platform';
|
||||
import { deleteShopApi, getShopPageApi } from '#/api/ecommerce/shop';
|
||||
|
||||
import PddShopDetailModal from './components/PddShopDetailModal.vue';
|
||||
import ShopFormModal from './components/ShopFormModal.vue';
|
||||
|
||||
defineOptions({ name: 'ShopManagement' });
|
||||
|
||||
const PLATFORM_CODE_PDD = 'pdd';
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
// 创建图标组件
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const authorizing = ref(false);
|
||||
const shopFormModalRef = ref();
|
||||
const pddShopDetailModalRef = ref();
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref({
|
||||
name: '',
|
||||
platformId: undefined as number | undefined,
|
||||
});
|
||||
|
||||
// 表单数据(已移至ShopFormModal组件)
|
||||
|
||||
// 平台选项(动态加载)
|
||||
const platformOptions = ref<{ label: string; value: number }[]>([]);
|
||||
const platformCodeById = ref<Record<number, string>>({});
|
||||
|
||||
let authPollTimer: null | ReturnType<typeof setInterval> = null;
|
||||
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: [
|
||||
{
|
||||
@@ -66,6 +70,12 @@ const gridOptions: VxeGridProps<any> = {
|
||||
minWidth: 120,
|
||||
showOverflow: true,
|
||||
},
|
||||
{
|
||||
title: '外部店铺',
|
||||
minWidth: 180,
|
||||
showOverflow: false,
|
||||
slots: { default: 'externalShop' },
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
@@ -78,7 +88,7 @@ const gridOptions: VxeGridProps<any> = {
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
minWidth: 'auto',
|
||||
minWidth: 360,
|
||||
fixed: 'right' as const,
|
||||
slots: { default: 'action' },
|
||||
},
|
||||
@@ -86,7 +96,6 @@ const gridOptions: VxeGridProps<any> = {
|
||||
height: 'auto',
|
||||
border: true,
|
||||
stripe: true,
|
||||
// 行高需容纳店铺 Logo(与商品表一致)
|
||||
rowConfig: {
|
||||
isHover: true,
|
||||
height: 88,
|
||||
@@ -122,7 +131,6 @@ const gridOptions: VxeGridProps<any> = {
|
||||
| 'Total'
|
||||
)[],
|
||||
},
|
||||
// 配置远程加载
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }) => {
|
||||
@@ -156,7 +164,6 @@ const gridOptions: VxeGridProps<any> = {
|
||||
},
|
||||
};
|
||||
|
||||
// 搜索表单配置
|
||||
const gridReloadRef = ref<(() => void) | null>(null);
|
||||
const formOptions = computed(() => ({
|
||||
schema: [
|
||||
@@ -173,7 +180,7 @@ const formOptions = computed(() => ({
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择平台',
|
||||
options: platformOptions,
|
||||
options: platformOptions.value,
|
||||
allowClear: true,
|
||||
onChange: (val: any) => {
|
||||
searchForm.value.platformId = val;
|
||||
@@ -189,7 +196,6 @@ const formOptions = computed(() => ({
|
||||
collapsedRows: 1,
|
||||
}));
|
||||
|
||||
// 创建 VbenVxeGrid 实例
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
formOptions: formOptions.value,
|
||||
@@ -198,24 +204,53 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
});
|
||||
gridReloadRef.value = () => gridApi.reload();
|
||||
|
||||
// 刷新表格数据
|
||||
function refreshTable() {
|
||||
if (gridApi) {
|
||||
gridApi.reload();
|
||||
async function fetchPlatformOptions() {
|
||||
try {
|
||||
const data = await getActivePlatformsApi();
|
||||
platformOptions.value = data.map((p: PlatformVO.Info) => ({
|
||||
label: p.platformName,
|
||||
value: p.id,
|
||||
}));
|
||||
const codeMap: Record<number, string> = {};
|
||||
data.forEach((p: PlatformVO.Info) => {
|
||||
codeMap[p.id] = p.platformCode;
|
||||
});
|
||||
platformCodeById.value = codeMap;
|
||||
|
||||
await gridApi.formApi?.updateSchema([
|
||||
{
|
||||
fieldName: 'platformId',
|
||||
componentProps: {
|
||||
options: platformOptions.value,
|
||||
},
|
||||
},
|
||||
]);
|
||||
} catch (error) {
|
||||
console.error('获取平台列表失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 处理添加店铺
|
||||
function refreshTable() {
|
||||
gridApi?.reload();
|
||||
}
|
||||
|
||||
function isPddShop(row: ShopVO.Info) {
|
||||
if (!row.platformId) return false;
|
||||
return platformCodeById.value[row.platformId] === PLATFORM_CODE_PDD;
|
||||
}
|
||||
|
||||
function hasExternalShop(row: ShopVO.Info) {
|
||||
return Boolean(row.pddShop || row.externalShopId);
|
||||
}
|
||||
|
||||
function handleAdd() {
|
||||
shopFormModalRef.value?.open(false);
|
||||
}
|
||||
|
||||
// 处理编辑店铺
|
||||
function handleEdit(record: ShopVO.Info) {
|
||||
shopFormModalRef.value?.open(true, record);
|
||||
}
|
||||
|
||||
// 处理删除店铺
|
||||
async function handleDelete(record: ShopVO.Info) {
|
||||
try {
|
||||
await deleteShopApi(record.id);
|
||||
@@ -227,22 +262,71 @@ async function handleDelete(record: ShopVO.Info) {
|
||||
}
|
||||
}
|
||||
|
||||
// 处理模态框成功
|
||||
function handleModalSuccess() {
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
// 处理查看概览
|
||||
function handleViewOverview(record: ShopVO.Info) {
|
||||
router.push(`/ecom/shop/overview/${record.id}`);
|
||||
}
|
||||
|
||||
function handleViewExternalShop(record: ShopVO.Info) {
|
||||
if (!record.pddShop) {
|
||||
message.warning('暂无外部店铺详情,请先完成授权同步');
|
||||
return;
|
||||
}
|
||||
pddShopDetailModalRef.value?.open(record.pddShop, record.name);
|
||||
}
|
||||
|
||||
function clearAuthPoll() {
|
||||
if (authPollTimer) {
|
||||
clearInterval(authPollTimer);
|
||||
authPollTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleAuthorizePdd(record: ShopVO.Info) {
|
||||
if (authorizing.value) return;
|
||||
try {
|
||||
authorizing.value = true;
|
||||
const data = await getPddAuthorizeUrlApi(record.id);
|
||||
if (!data?.authorizeUrl) {
|
||||
message.error('未获取到授权链接');
|
||||
return;
|
||||
}
|
||||
const win = window.open(data.authorizeUrl, '_blank');
|
||||
if (!win) {
|
||||
message.warning('浏览器拦截了弹窗,请允许后重试');
|
||||
return;
|
||||
}
|
||||
message.info('请在新窗口完成拼多多授权,完成后将自动刷新列表');
|
||||
clearAuthPoll();
|
||||
authPollTimer = setInterval(() => {
|
||||
if (win.closed) {
|
||||
clearAuthPoll();
|
||||
refreshTable();
|
||||
}
|
||||
}, 1000);
|
||||
} catch (error) {
|
||||
console.error('获取拼多多授权链接失败:', error);
|
||||
message.error('获取拼多多授权链接失败');
|
||||
} finally {
|
||||
authorizing.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchPlatformOptions();
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
clearAuthPoll();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height>
|
||||
<!-- VbenVxeGrid 表格 -->
|
||||
<Grid :loading="loading" class="shop-grid">
|
||||
<!-- 工具栏工具 -->
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
@@ -252,7 +336,6 @@ function handleViewOverview(record: ShopVO.Info) {
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
<!-- Logo 列:64px 图标,需配合更高行高 -->
|
||||
<template #logo="{ row }: { row: ShopVO.Info }">
|
||||
<div class="shop-logo-cell flex items-center justify-center">
|
||||
<img
|
||||
@@ -270,7 +353,6 @@ function handleViewOverview(record: ShopVO.Info) {
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 店铺名称列 -->
|
||||
<template #name="{ row }: { row: ShopVO.Info }">
|
||||
<a
|
||||
class="text-primary cursor-pointer hover:underline"
|
||||
@@ -280,33 +362,74 @@ function handleViewOverview(record: ShopVO.Info) {
|
||||
</a>
|
||||
</template>
|
||||
|
||||
<!-- 操作列 -->
|
||||
<template #action="{ row }: { row: any }">
|
||||
<Space>
|
||||
<template #externalShop="{ row }: { row: ShopVO.Info }">
|
||||
<div v-if="isPddShop(row)" class="flex flex-col gap-1">
|
||||
<Tag v-if="hasExternalShop(row)" color="success" class="!mr-0 w-fit">
|
||||
已绑定
|
||||
</Tag>
|
||||
<Tag v-else color="default" class="!mr-0 w-fit">未授权</Tag>
|
||||
<span
|
||||
v-if="row.pddShop?.mallName"
|
||||
class="text-primary cursor-pointer text-xs hover:underline"
|
||||
@click="handleViewExternalShop(row)"
|
||||
>
|
||||
{{ row.pddShop.mallName }}
|
||||
</span>
|
||||
<span
|
||||
v-else-if="row.externalShopId"
|
||||
class="text-xs text-slate-500"
|
||||
>
|
||||
mall_id: {{ row.externalShopId }}
|
||||
</span>
|
||||
</div>
|
||||
<span v-else class="text-slate-400">-</span>
|
||||
</template>
|
||||
|
||||
<template #action="{ row }: { row: ShopVO.Info }">
|
||||
<Space wrap>
|
||||
<Button size="small" type="primary" @click="handleViewOverview(row)">
|
||||
查看概览
|
||||
</Button>
|
||||
<Button size="small" @click="router.push(`/ecom/shop/details/${row.id}`)">
|
||||
<Button
|
||||
size="small"
|
||||
@click="router.push(`/ecom/shop/details/${row.id}`)"
|
||||
>
|
||||
查看详情
|
||||
</Button>
|
||||
<Button size="small" @click="handleEdit(row)"> 编辑 </Button>
|
||||
<Button
|
||||
v-if="isPddShop(row) && row.pddShop"
|
||||
size="small"
|
||||
@click="handleViewExternalShop(row)"
|
||||
>
|
||||
外部店铺
|
||||
</Button>
|
||||
<Button
|
||||
v-if="isPddShop(row)"
|
||||
size="small"
|
||||
type="primary"
|
||||
ghost
|
||||
:loading="authorizing"
|
||||
@click="handleAuthorizePdd(row)"
|
||||
>
|
||||
{{ hasExternalShop(row) ? '重新授权' : '授权拼多多' }}
|
||||
</Button>
|
||||
<Button size="small" @click="handleEdit(row)">编辑</Button>
|
||||
<Popconfirm
|
||||
title="确定要删除这个店铺吗?"
|
||||
@confirm="handleDelete(row)"
|
||||
>
|
||||
<Button size="small" danger> 删除 </Button>
|
||||
<Button size="small" danger>删除</Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
|
||||
<!-- 店铺表单模态框 -->
|
||||
<ShopFormModal ref="shopFormModalRef" @success="handleModalSuccess" />
|
||||
<PddShopDetailModal ref="pddShopDetailModalRef" />
|
||||
</Page>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* 店铺表行高与 Logo 垂直居中 */
|
||||
:deep(.shop-grid .vxe-body--column) {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user