feat(shop): 新增首页专区管理功能

- 在商品模型中添加所属专区字段 sectionIds,支持逗号分隔字符串
- 商品编辑界面增加所属专区多选下拉框,联动专区数据
- 新增首页专区相关接口,包括分页查询、增删改查及权限校验等
- 实现首页专区列表页面,支持专区的增删改查及状态切换
- 新增专区白名单用户管理弹窗,支持多选用户设置白名单
- 实现专区商品列表抽屉,支持分页查看专区内商品
- 首页专区编辑弹窗支持标题、副标题、banner等多字段编辑及上传功能
- 完善专区管理界面交互和表格展示,支持搜索和状态筛选功能
This commit is contained in:
2026-08-15 03:30:48 +08:00
parent 053b776d9a
commit b5c67988a6
7 changed files with 1076 additions and 0 deletions
+156
View File
@@ -0,0 +1,156 @@
import request from '@/utils/request';
import type { ApiResult, PageResult } from '@/api';
import type {
HomeSection,
HomeSectionParam,
SectionPermission,
SectionGoods,
SectionUser
} from './model';
import { MODULES_API_URL } from '@/config/setting';
/**
* 分页查询首页专区
*/
export async function pageHomeSections(params: HomeSectionParam) {
const res = await request.get<ApiResult<PageResult<HomeSection>>>(
MODULES_API_URL + '/shop/shop-home-section/page',
{
params
}
);
if (res.data.code === 0) {
return res.data.data;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 查询首页专区列表
*/
export async function listHomeSections(params?: HomeSectionParam) {
const res = await request.get<ApiResult<HomeSection[]>>(
MODULES_API_URL + '/shop/shop-home-section',
{
params
}
);
if (res.data.code === 0 && res.data.data) {
return res.data.data;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 根据id查询首页专区
*/
export async function getHomeSection(id: number) {
const res = await request.get<ApiResult<HomeSection>>(
MODULES_API_URL + '/shop/shop-home-section/' + id
);
if (res.data.code === 0 && res.data.data) {
return res.data.data;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 添加首页专区
*/
export async function addHomeSection(data: HomeSection) {
const res = await request.post<ApiResult<unknown>>(
MODULES_API_URL + '/shop/shop-home-section',
data
);
if (res.data.code === 0) {
return res.data.message;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 修改首页专区
*/
export async function updateHomeSection(data: HomeSection) {
const res = await request.put<ApiResult<unknown>>(
MODULES_API_URL + '/shop/shop-home-section',
data
);
if (res.data.code === 0) {
return res.data.message;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 删除首页专区
*/
export async function removeHomeSection(id?: number) {
const res = await request.delete<ApiResult<unknown>>(
MODULES_API_URL + '/shop/shop-home-section/' + id
);
if (res.data.code === 0) {
return res.data.message;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 查询专区白名单用户
*/
export async function listSectionUsers(id: number) {
const res = await request.get<ApiResult<SectionUser[]>>(
MODULES_API_URL + '/shop/shop-home-section/' + id + '/users'
);
if (res.data.code === 0 && res.data.data) {
return res.data.data;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 保存专区白名单用户(覆盖式)
*/
export async function setSectionUsers(id: number, userIds: number[]) {
const res = await request.put<ApiResult<unknown>>(
MODULES_API_URL + '/shop/shop-home-section/' + id + '/users',
userIds
);
if (res.data.code === 0) {
return res.data.message;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 查询专区商品分页
*/
export async function listSectionGoods(
id: number,
params?: { page?: number; limit?: number }
) {
const res = await request.get<ApiResult<PageResult<SectionGoods>>>(
MODULES_API_URL + '/shop/shop-home-section/' + id + '/goods',
{
params: { page: 1, limit: 10, ...params }
}
);
if (res.data.code === 0) {
return res.data.data;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 校验专区访问权限
*/
export async function checkSectionPermission(sectionIds: number[]) {
const res = await request.post<ApiResult<SectionPermission[]>>(
MODULES_API_URL + '/shop/shop-home-section/check-permission',
{ sectionIds }
);
if (res.data.code === 0 && res.data.data) {
return res.data.data;
}
return Promise.reject(new Error(res.data.message));
}
+88
View File
@@ -0,0 +1,88 @@
import type { PageParam } from '@/api';
/**
* 首页专区
*/
export interface HomeSection {
// 专区ID
sectionId?: number;
// 租户id
tenantId?: number;
// 专区标题
title?: string;
// 专区副标题
subtitle?: string;
// banner 图片URL
banner?: string;
// 关联分类ID(逗号分隔字符串,可选)
categoryIds?: string;
// 样式类型 0默认
styleType?: number;
// 是否受限专区 0否 1是
restricted?: number;
// 排序号(数字越小越靠前)
sortNumber?: number;
// 状态 0正常 1禁用
status?: number;
// 生效开始时间
startTime?: string;
// 生效结束时间
endTime?: string;
// 用户ID
userId?: number;
// 是否删除 0否 1是
deleted?: number;
// 创建时间
createTime?: string;
// 修改时间
updateTime?: string;
}
/**
* 首页专区搜索条件
*/
export interface HomeSectionParam extends PageParam {
// 专区标题(模糊)
title?: string;
// 状态 0正常 1禁用
status?: number;
// 是否受限专区 0/1
restricted?: number;
// 排序号
sortNumber?: number;
}
/**
* 专区权限校验结果
*/
export interface SectionPermission {
// 专区ID
sectionId?: number;
// 是否受限专区
restricted?: boolean;
// 当前用户是否允许访问
allowed?: boolean;
}
/**
* 专区商品(只读展示,字段按需取用)
*/
export interface SectionGoods {
goodsId?: number;
name?: string;
image?: string;
price?: string;
salePrice?: string;
stock?: number;
status?: number;
[key: string]: any;
}
/**
* 专区白名单用户
*/
export interface SectionUser {
id?: number;
sectionId?: number;
userId?: number;
}