Files
gaoYuJournal/miniprogram/api/TravelApi.ts
2025-12-13 18:44:37 +08:00

62 lines
1.4 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 { Travel } from "../types/Travel";
import { QueryPage, QueryPageResult } from "../types/Model";
/**
* Travel 旅行计划 API
*
* 按业务模块封装网络请求,使代码更清晰、可维护
*/
export class TravelApi {
/**
* 获取旅行详情
*
* @param id - 旅行 ID
*/
static getDetail(id: number | string): Promise<Travel> {
return Network.get<Travel>(`/journal/travel/${id}`);
}
/**
* 旅行分页列表
*
* @param pageParams - 分页参数
*/
static getList(pageParams: QueryPage): Promise<QueryPageResult<Travel>> {
return Network.page<Travel>("/journal/travel/list", pageParams);
}
/**
* 创建旅行
*
* @param data - 旅行数据
*/
static create(data: Partial<Travel>): Promise<Travel> {
return Network.post<Travel>("/journal/travel/create", data, {
showLoading: true,
loadingText: "正在保存.."
});
}
/**
* 更新旅行
*
* @param data - 旅行数据(必须包含 id
*/
static update(data: Partial<Travel> & { id: number }): Promise<Travel> {
return Network.post<Travel>("/journal/travel/update", data, {
showLoading: true,
loadingText: "正在保存.."
});
}
/**
* 删除旅行
*
* @param id - 旅行 ID
*/
static delete(id: number): Promise<void> {
return Network.post<void>("/journal/travel/delete", { id });
}
}