You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Nursing-home-management-system/client/src/apis/source.ts

96 lines
3.9 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// 从 "@/utils" 模块导入名为 http 的对象,推测该对象是用于发起 HTTP 请求的工具,可能是对 axios 等请求库的封装
import { http } from "@/utils";
// 定义一个接口 IPageSourceByKey用于描述分页查询来源渠道时的请求参数结构
interface IPageSourceByKey {
// 名称,用于筛选来源渠道,类型为字符串
name: string;
// 来源渠道名称,用于筛选来源渠道,类型为字符串
sourceName: string;
}
// 定义一个接口 IAddSource用于描述新增来源渠道时的数据结构
interface IAddSource {
// 来源渠道的 ID类型为字符串
id: string;
// 来源渠道的名称,类型为字符串
name: string;
}
// 定义一个接口 IGetSourceById用于描述根据编号查询来源渠道时的请求参数结构
interface IGetSourceById {
// 来源渠道 ID类型为字符串
sourceId: string;
}
/**
* 定义一个异步函数 pageSourceByKey用于分页查询来源渠道
* @param data - 一个符合 IPageSourceByKey 接口的对象,包含分页查询所需的参数
* @returns 一个 Promise 对象,解析后得到的是分页查询来源渠道的响应结果
*/
export async function pageSourceByKey(data: IPageSourceByKey) {
// 因为后台返回的字段与前端表单数据的 prop 不一样,
// 但是组件封装需要一样,所以请求前增加一些这两个字段
// 如果 data 对象中有 "name" 字段,则将其值赋给 "sourceName" 字段
Reflect.has(data, "name")? (data.sourceName = data.name) : "";
// 使用导入的 http 对象发起 GET 请求,请求地址为 "/api/source/pageSourceByKey"
// 将处理后的 data 对象展开作为请求的参数
return http.get("/api/source/pageSourceByKey", {
params: {
...data
}
});
}
/**
* 定义一个函数 addSource用于新增来源渠道
* @param data - 一个符合 IAddSource 接口的对象,包含新增来源渠道所需的数据
* @returns 一个 Promise 对象,解析后得到的是新增来源渠道操作的响应结果
*/
export function addSource(data: IAddSource) {
// 使用导入的 http 对象发起 POST 请求,请求地址为 "/api/source/addSource"
// 将 data 对象作为请求的主体
return http.post("/api/source/addSource", data);
}
/**
* 定义一个异步函数 getSourceById用于根据编号查询来源渠道
* @param data - 一个符合 IGetSourceById 接口的对象,包含根据编号查询来源渠道所需的参数
* @returns 一个 Promise 对象,解析后得到的是根据编号查询来源渠道的响应结果
*/
export async function getSourceById(data: IGetSourceById) {
// 使用导入的 http 对象发起 GET 请求,请求地址为 "/api/source/getSourceById"
// 将 data 对象展开作为请求的参数
return http.get("/api/source/getSourceById", {
params: {
...data
}
});
}
/**
* 定义一个函数 editSource用于编辑来源渠道
* @param data - 一个符合 IAddSource 接口的对象,包含编辑来源渠道所需的数据
* @returns 一个 Promise 对象,解析后得到的是编辑来源渠道操作的响应结果
*/
export function editSource(data: IAddSource) {
// 使用导入的 http 对象发起 PUT 请求,请求地址为 "/api/source/editSource"
// 将 data 对象作为请求的主体
return http.put("/api/source/editSource", data);
}
/**
* 定义一个异步函数 deleteSource用于删除来源渠道
* @param data - 一个符合 IGetSourceById 接口的对象,包含删除来源渠道所需的参数
* @returns 一个 Promise 对象,解析后得到的是删除来源渠道操作的响应结果
*/
export async function deleteSource(data: IGetSourceById) {
// 使用导入的 http 对象发起 DELETE 请求,请求地址为 "/api/source/deleteSource"
// 将 data 对象展开作为请求的参数
return http.delete("/api/source/deleteSource", {
params: {
...data
}
});
}