Files
guoxue-admin/src/api/gx/gxRole/index.ts
T
2026-03-25 16:00:47 +08:00

142 lines
3.2 KiB
TypeScript

import request from "@/utils/request";
import type { ApiResult, PageResult } from "@/api";
import type { GxRole, GxRoleParam } from "./model";
import { MODULES_API_URL } from "@/config/setting";
/**
* 分页查询
*/
export async function pageGxRole(params: GxRoleParam) {
const res = await request.get<ApiResult<PageResult<GxRole>>>(
MODULES_API_URL + "/gx/gx-role/page",
{
params
}
);
if (res.data.code === 0) {
return res.data.data;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 查询列表
*/
export async function listGxRole(params?: GxRoleParam) {
const res = await request.get<ApiResult<GxRole[]>>(
MODULES_API_URL + "/gx/gx-role",
{
params
}
);
if (res.data.code === 0 && res.data.data) {
return res.data.data;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 添加
*/
export async function addGxRole(data: GxRole) {
const res = await request.post<ApiResult<unknown>>(
MODULES_API_URL + "/gx/gx-role",
data
);
if (res.data.code === 0) {
return res.data.message;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 修改
*/
export async function updateGxRole(data: GxRole) {
const res = await request.put<ApiResult<unknown>>(
MODULES_API_URL + "/gx/gx-role",
data
);
if (res.data.code === 0) {
return res.data.message;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 删除
*/
export async function removeGxRole(id?: number) {
const res = await request.delete<ApiResult<unknown>>(
MODULES_API_URL + "/gx/gx-role/" + id
);
if (res.data.code === 0) {
return res.data.message;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 批量删除
*/
export async function removeBatchGxRole(data: (number | undefined)[]) {
const res = await request.delete<ApiResult<unknown>>(
MODULES_API_URL + "/gx/gx-role/batch",
{
data
}
);
if (res.data.code === 0) {
return res.data.message;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 根据id查询
*/
export async function getGxRole(id: number) {
const res = await request.get<ApiResult<GxRole>>(
MODULES_API_URL + "/gx/gx-role/" + id
);
if (res.data.code === 0 && res.data.data) {
return res.data.data;
}
return Promise.reject(new Error(res.data.message));
}
export interface VoiceMakeParam {
voice: string;
text: string;
emo?: string;
}
export type VoiceMakeResult =
| string
| {
url?: string;
audioUrl?: string;
src?: string;
path?: string;
};
/**
* 角色音色试听
*/
export async function makeVoice(params: VoiceMakeParam) {
const { voice, text, emo } = params;
const res = await request.post<ApiResult<VoiceMakeResult | undefined>>(
`${MODULES_API_URL}/voice/make`,
{
text,
content: text,
emo,
voice
}
);
if (res.data.code === 0) {
return res.data.data;
}
return Promise.reject(new Error(res.data.message));
}