feat: 新增公告管理
This commit is contained in:
@@ -1,5 +1,14 @@
|
||||
import type { AnnouncementLogDto } from './types';
|
||||
import { get } from '@/utils/request';
|
||||
import type {
|
||||
AnnouncementLogDto,
|
||||
AnnouncementDto,
|
||||
AnnouncementCreateInput,
|
||||
AnnouncementUpdateInput,
|
||||
AnnouncementGetListInput,
|
||||
PagedResultDto,
|
||||
} from './types';
|
||||
import { del, get, post, put } from '@/utils/request';
|
||||
|
||||
// ==================== 前端首页用 ====================
|
||||
|
||||
/**
|
||||
* 获取系统公告和活动数据
|
||||
@@ -9,4 +18,49 @@ import { get } from '@/utils/request';
|
||||
export function getSystemAnnouncements() {
|
||||
return get<AnnouncementLogDto[]>('/announcement').json();
|
||||
}
|
||||
|
||||
// ==================== 后台管理用 ====================
|
||||
|
||||
// 获取公告列表
|
||||
export function getList(params?: AnnouncementGetListInput) {
|
||||
const queryParams = new URLSearchParams();
|
||||
if (params?.searchKey) {
|
||||
queryParams.append('SearchKey', params.searchKey);
|
||||
}
|
||||
if (params?.skipCount !== undefined) {
|
||||
queryParams.append('SkipCount', params.skipCount.toString());
|
||||
}
|
||||
if (params?.maxResultCount !== undefined) {
|
||||
queryParams.append('MaxResultCount', params.maxResultCount.toString());
|
||||
}
|
||||
if (params?.type !== undefined) {
|
||||
queryParams.append('Type', params.type.toString());
|
||||
}
|
||||
|
||||
const queryString = queryParams.toString();
|
||||
const url = queryString ? `/announcement/list?${queryString}` : '/announcement/list';
|
||||
|
||||
return get<PagedResultDto<AnnouncementDto>>(url).json();
|
||||
}
|
||||
|
||||
// 根据ID获取公告
|
||||
export function getById(id: string) {
|
||||
return get<AnnouncementDto>(`/announcement/${id}`).json();
|
||||
}
|
||||
|
||||
// 创建公告
|
||||
export function create(data: AnnouncementCreateInput) {
|
||||
return post<AnnouncementDto>('/announcement', data).json();
|
||||
}
|
||||
|
||||
// 更新公告
|
||||
export function update(data: AnnouncementUpdateInput) {
|
||||
return put<AnnouncementDto>('/announcement', data).json();
|
||||
}
|
||||
|
||||
// 删除公告
|
||||
export function deleteById(id: string) {
|
||||
return del(`/announcement/${id}`).json();
|
||||
}
|
||||
|
||||
export * from './types';
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
// 公告类型(对应后端 AnnouncementTypeEnum)
|
||||
// 公告类型枚举(对应后端 AnnouncementTypeEnum)
|
||||
export enum AnnouncementTypeEnum {
|
||||
Activity = 1,
|
||||
System = 2,
|
||||
}
|
||||
|
||||
// 公告类型(兼容旧代码)
|
||||
export type AnnouncementType = 'Activity' | 'System'
|
||||
|
||||
// 公告DTO(对应后端 AnnouncementLogDto)
|
||||
@@ -16,3 +22,58 @@ export interface AnnouncementLogDto {
|
||||
/** 公告类型(系统、活动) */
|
||||
type: AnnouncementType
|
||||
}
|
||||
|
||||
// ==================== 后台管理用 DTO ====================
|
||||
|
||||
// 公告 DTO(后台管理列表)
|
||||
export interface AnnouncementDto {
|
||||
id: string;
|
||||
title: string;
|
||||
content: string[];
|
||||
remark?: string;
|
||||
imageUrl?: string;
|
||||
startTime: string;
|
||||
endTime?: string;
|
||||
type: AnnouncementTypeEnum;
|
||||
url?: string;
|
||||
creationTime: string;
|
||||
}
|
||||
|
||||
// 创建公告输入
|
||||
export interface AnnouncementCreateInput {
|
||||
title: string;
|
||||
content: string[];
|
||||
remark?: string;
|
||||
imageUrl?: string;
|
||||
startTime: string;
|
||||
endTime?: string;
|
||||
type: AnnouncementTypeEnum;
|
||||
url?: string;
|
||||
}
|
||||
|
||||
// 更新公告输入
|
||||
export interface AnnouncementUpdateInput {
|
||||
id: string;
|
||||
title: string;
|
||||
content: string[];
|
||||
remark?: string;
|
||||
imageUrl?: string;
|
||||
startTime: string;
|
||||
endTime?: string;
|
||||
type: AnnouncementTypeEnum;
|
||||
url?: string;
|
||||
}
|
||||
|
||||
// 获取公告列表输入
|
||||
export interface AnnouncementGetListInput {
|
||||
searchKey?: string;
|
||||
skipCount?: number;
|
||||
maxResultCount?: number;
|
||||
type?: AnnouncementTypeEnum;
|
||||
}
|
||||
|
||||
// 分页结果
|
||||
export interface PagedResultDto<T> {
|
||||
items: T[];
|
||||
totalCount: number;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user