Files
gaoYuJournal/miniprogram/api/JournalApi.ts
2025-12-17 16:56:33 +08:00

90 lines
1.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Network } from "../utils/Network";
import { Journal, JournalPage } from "../types/Journal";
import { QueryPageResult } from "../types/Model";
/**
* Journal 日记 API
*
* 按业务模块封装网络请求,使代码更清晰、可维护
*/
export class JournalApi {
/**
* 获取日记详情
*
* @param id - 日记 ID
*/
static getDetail(id: number | string): Promise<Journal> {
return Network.post<Journal>(`/journal/${id}`);
}
/**
* 日记分页列表
*
* @param pageParams - 分页参数
*/
static getList(pageParams: JournalPage): Promise<QueryPageResult<Journal>> {
return Network.post<QueryPageResult<Journal>>("/journal/list", pageParams);
}
/**
* 创建日记
*
* @param data - 日记数据
*/
static create(data: Partial<Journal> & {
pusher?: string;
tempFileIds?: string[];
}): Promise<Journal> {
return Network.post<Journal>("/journal/create", data, {
showLoading: true,
loadingText: "正在保存.."
});
}
/**
* 更新日记
*
* @param data - 日记数据(必须包含 id
*/
static update(data: Partial<Journal> & {
id: number;
attachmentIds?: number[];
tempFileIds?: string[];
}): Promise<Journal> {
return Network.post<Journal>("/journal/update", data, {
showLoading: true,
loadingText: "正在保存.."
});
}
/**
* 删除日记
*
* @param id - 日记 ID
*/
static delete(id: number): Promise<void> {
return Network.post<void>("/journal/delete", { id }, {
showLoading: true,
loadingText: "删除中..."
});
}
/**
* 获取 openId用于推送
*
* @param code - 微信登录 code
*/
static getOpenId(code: string): Promise<string> {
return Network.post<string>("/journal/openid", { code });
}
/**
* 根据 ID 列表获取日记
*
* @param ids - 日记 ID 列表
*/
static getListByIds(ids: number[]): Promise<Journal[]> {
return Network.post<Journal[]>("/journal/list/ids", ids);
}
}