From 944bdd52943181a725b11570dd0daa6473a6fbb7 Mon Sep 17 00:00:00 2001 From: huangzhenbao <17818024429@163.com> Date: Fri, 20 Mar 2026 17:51:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=85=A5=E5=BA=97=E9=93=BA=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- layouts/admin/router/adminComponentMap.uts | 2 + layouts/admin/router/adminRoutes.uts | 13 +- pages.json | 7 + pages/mall/admin/shop/shop-manage.uvue | 506 +++++++++++++++++++++ services/admin/shopManageService.uts | 114 +++++ 5 files changed, 640 insertions(+), 2 deletions(-) create mode 100644 pages/mall/admin/shop/shop-manage.uvue create mode 100644 services/admin/shopManageService.uts diff --git a/layouts/admin/router/adminComponentMap.uts b/layouts/admin/router/adminComponentMap.uts index 92e0d3b3..6776e4fe 100644 --- a/layouts/admin/router/adminComponentMap.uts +++ b/layouts/admin/router/adminComponentMap.uts @@ -21,6 +21,7 @@ import UserCenter from '@/pages/mall/admin/userCenter/index.uvue' // --- 店铺模块 --- import ShopManage from '@/pages/mall/admin/shop/manage.uvue' import ShopCreate from '@/pages/mall/admin/shop/create.uvue' +import ShopAdminList from '@/pages/mall/admin/shop/shop-manage.uvue' // --- 用户模块 --- import UserStatistic from '@/pages/mall/admin/user/statistics/index.uvue' @@ -192,6 +193,7 @@ export const componentMap: Map = new Map([ // 店铺模块 ['ShopManage', ShopManage], ['ShopCreate', ShopCreate], + ['ShopAdminList', ShopAdminList], // 用户模块 ['UserStatistic', UserStatistic], diff --git a/layouts/admin/router/adminRoutes.uts b/layouts/admin/router/adminRoutes.uts index e87b05c6..e46e6a15 100644 --- a/layouts/admin/router/adminRoutes.uts +++ b/layouts/admin/router/adminRoutes.uts @@ -244,6 +244,15 @@ export const routes: RouteRecord[] = [ }, // ========== 店铺模块 ========== + { + id: 'shop_admin_list', + title: '店铺列表', + path: '/pages/mall/admin/shop/shop-manage', + componentKey: 'ShopAdminList', + parentId: 'shop', + groupId: 'shop-manage', + order: 1 + }, { id: 'shop_manage', title: '我的店铺', @@ -251,7 +260,7 @@ export const routes: RouteRecord[] = [ componentKey: 'ShopManage', parentId: 'shop', groupId: 'shop-manage', - order: 1 + order: 2 }, { id: 'shop_create', @@ -261,7 +270,7 @@ export const routes: RouteRecord[] = [ parentId: 'shop', groupId: 'shop-manage', hidden: true, - order: 2 + order: 3 }, // ========== 用户模块 ========== diff --git a/pages.json b/pages.json index 7605a7ae..be65d498 100644 --- a/pages.json +++ b/pages.json @@ -1604,6 +1604,13 @@ { "root": "pages/mall/admin/shop", "pages": [ + { + "path": "shop-manage", + "style": { + "navigationBarTitleText": "店铺列表", + "navigationStyle": "custom" + } + }, { "path": "manage", "style": { diff --git a/pages/mall/admin/shop/shop-manage.uvue b/pages/mall/admin/shop/shop-manage.uvue new file mode 100644 index 00000000..82df998d --- /dev/null +++ b/pages/mall/admin/shop/shop-manage.uvue @@ -0,0 +1,506 @@ + + + + + + diff --git a/services/admin/shopManageService.uts b/services/admin/shopManageService.uts new file mode 100644 index 00000000..366cd6fa --- /dev/null +++ b/services/admin/shopManageService.uts @@ -0,0 +1,114 @@ +import supa from '@/components/supadb/aksupainstance.uts' + +/** + * Admin 店铺列表项(对应 ml_shops 列表页所需字段) + */ +export type AdminShopItem = { + id: string + cid: number + merchant_id: string + shop_name: string + shop_logo: string | null + contact_name: string | null + contact_phone: string | null + status: number + product_count: number + order_count: number + rating_avg: number + rating_count: number + verified_at: string | null + created_at: string +} + +/** + * Admin 店铺查询参数 + */ +export type AdminShopQuery = { + searchName?: string | null + status?: number | null + startTime?: string | null + endTime?: string | null + page?: number + pageSize?: number +} + +// 精确选取列表页需要字段,禁止 SELECT * +const LIST_COLUMNS = 'id,cid,merchant_id,shop_name,shop_logo,contact_name,contact_phone,status,product_count,order_count,rating_avg,rating_count,verified_at,created_at' + +/** + * 分页查询 ml_shops(服务端分页,按需按页请求) + */ +export async function fetchAdminShops(query?: AdminShopQuery): Promise<{ total: number; items: Array }> { + const page = query?.page ?? 1 + const pageSize = query?.pageSize ?? 20 + + const builder = supa + .from('ml_shops') + .select(LIST_COLUMNS) + .order('created_at', { ascending: false }) + .limit(pageSize) + .page(page) + + // 条件过滤(仅非空时才附加,避免无效 filter) + if (query?.status != null) { + builder.eq('status', query.status) + } + if (query?.searchName != null && query.searchName !== '') { + builder.ilike('shop_name', `%${query.searchName}%`) + } + if (query?.startTime != null && query.startTime !== '') { + builder.gte('created_at', query.startTime) + } + if (query?.endTime != null && query.endTime !== '') { + builder.lte('created_at', query.endTime) + } + + const result = await builder.execute() + + if (result.error != null) { + console.error('[shopManageService] fetchAdminShops 失败:', result.error) + return { total: 0, items: [] as Array } + } + + const rawRows = (result.data ?? []) as any[] + const items: Array = [] + + for (let i = 0; i < rawRows.length; i++) { + const row = rawRows[i] as UTSJSONObject + items.push({ + id: row.getString('id') ?? '', + cid: row.getNumber('cid') ?? 0, + merchant_id: row.getString('merchant_id') ?? '', + shop_name: row.getString('shop_name') ?? '', + shop_logo: row.getString('shop_logo') ?? null, + contact_name: row.getString('contact_name') ?? null, + contact_phone: row.getString('contact_phone') ?? null, + status: row.getNumber('status') ?? 1, + product_count: row.getNumber('product_count') ?? 0, + order_count: row.getNumber('order_count') ?? 0, + rating_avg: row.getNumber('rating_avg') ?? 0, + rating_count: row.getNumber('rating_count') ?? 0, + verified_at: row.getString('verified_at') ?? null, + created_at: row.getString('created_at') ?? '' + } as AdminShopItem) + } + + return { total: result.total ?? 0, items } +} + +/** + * 更新指定店铺的状态(1=正常 2=暂停 3=关闭) + */ +export async function updateAdminShopStatus(shopId: string, status: number): Promise { + const result = await supa + .from('ml_shops') + .update({ status: status, updated_at: new Date().toISOString() } as UTSJSONObject) + .eq('id', shopId) + .execute() + + if (result.error != null) { + console.error('[shopManageService] updateAdminShopStatus 失败:', result.error) + return false + } + return true +}