29 lines
927 B
TypeScript
29 lines
927 B
TypeScript
import { SYSTEM_SERVICE_PREFIX } from '@/constants/service';
|
||
import { request } from '../request';
|
||
import { type ServiceRequestResult, mapServiceResult, normalizeStringId, safeJsonRequestConfig } from './shared';
|
||
|
||
const NOTICE_PREFIX = `${SYSTEM_SERVICE_PREFIX}/notice`;
|
||
|
||
type NoticeResponse = Omit<Api.Notice.Notice, 'id'> & {
|
||
id: string | number;
|
||
};
|
||
|
||
function normalizeNotice(data: NoticeResponse): Api.Notice.Notice {
|
||
return {
|
||
...data,
|
||
id: normalizeStringId(data.id)
|
||
};
|
||
}
|
||
|
||
/** 获取最近公告(status=0,按 id 倒序;登录即可,工作台公告卡片用) */
|
||
export async function fetchGetRecentNotices(size?: number) {
|
||
const result = await request<NoticeResponse[]>({
|
||
url: `${NOTICE_PREFIX}/recent`,
|
||
method: 'get',
|
||
params: { size },
|
||
...safeJsonRequestConfig
|
||
});
|
||
|
||
return mapServiceResult(result as ServiceRequestResult<NoticeResponse[]>, data => data.map(normalizeNotice));
|
||
}
|