feat(api): generate and update API client modules
Add new API client modules for various endpoints including authentication, orders, events, and configuration management. Update existing modules to use the standardized request utility. Add post-generation script to restore request.ts after openapi-ts generation to prevent file deletion issues. The API client generation now includes comprehensive TypeScript types and proper request handling for all endpoints. The request utility has been enhanced to handle query parameters and response parsing consistently across all API calls.
This commit is contained in:
@@ -34,7 +34,7 @@
|
|||||||
"release": "pnpm run package && electron-builder --publish always",
|
"release": "pnpm run package && electron-builder --publish always",
|
||||||
"lint": "eslint --ext .ts,.tsx .",
|
"lint": "eslint --ext .ts,.tsx .",
|
||||||
"typecheck": "tsc --noEmit",
|
"typecheck": "tsc --noEmit",
|
||||||
"openapi": "dotenv -e .env -- openapi-ts",
|
"openapi": "dotenv -e .env -- openapi-ts && node scripts/restore-api-request.mjs",
|
||||||
"generate-prod-entry": "node build/scripts/generateProdEntry.js",
|
"generate-prod-entry": "node build/scripts/generateProdEntry.js",
|
||||||
"clean": "node build/scripts/clean.js",
|
"clean": "node build/scripts/clean.js",
|
||||||
"build:encrypt": "pnpm run clean && pnpm run build:vite && pnpm run package",
|
"build:encrypt": "pnpm run clean && pnpm run build:vite && pnpm run package",
|
||||||
|
|||||||
36
scripts/restore-api-request.mjs
Normal file
36
scripts/restore-api-request.mjs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在 openapi-ts 生成后恢复 request.ts 文件
|
||||||
|
* 解决 openapi-ts-request 的 full 模式会删除整个 serversPath 目录的问题
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { copyFileSync, existsSync, mkdirSync } from 'fs';
|
||||||
|
import { dirname, resolve } from 'path';
|
||||||
|
import { fileURLToPath } from 'url';
|
||||||
|
|
||||||
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
|
const rootDir = resolve(__dirname, '..');
|
||||||
|
|
||||||
|
const templatePath = resolve(rootDir, 'src/utils/api-request.ts');
|
||||||
|
const targetPath = resolve(rootDir, 'src/api/request.ts');
|
||||||
|
|
||||||
|
console.log('🔄 Restoring request.ts after openapi generation...');
|
||||||
|
|
||||||
|
// 确保目标目录存在
|
||||||
|
const targetDir = dirname(targetPath);
|
||||||
|
if (!existsSync(targetDir)) {
|
||||||
|
mkdirSync(targetDir, { recursive: true });
|
||||||
|
console.log('📁 Created directory:', targetDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 复制模板文件
|
||||||
|
if (existsSync(templatePath)) {
|
||||||
|
copyFileSync(templatePath, targetPath);
|
||||||
|
console.log('✅ Restored:', targetPath);
|
||||||
|
} else {
|
||||||
|
console.error('❌ Template not found:', templatePath);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('🎉 Request file restoration complete!');
|
||||||
23
src/api/code.ts
Normal file
23
src/api/code.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
// @ts-ignore
|
||||||
|
import request from './request';
|
||||||
|
|
||||||
|
import * as API from './types';
|
||||||
|
|
||||||
|
/** 创建图形验证码 GET /auth/code/image */
|
||||||
|
export function authCodeImageUsingGet({
|
||||||
|
params,
|
||||||
|
options,
|
||||||
|
}: {
|
||||||
|
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
|
||||||
|
params: API.AuthCodeImageUsingGetParams;
|
||||||
|
options?: { [key: string]: unknown };
|
||||||
|
}) {
|
||||||
|
return request<API.AuthCodeImageUsingGetResponse>('/auth/code/image', {
|
||||||
|
method: 'GET',
|
||||||
|
params: {
|
||||||
|
...params,
|
||||||
|
},
|
||||||
|
...(options || {}),
|
||||||
|
});
|
||||||
|
}
|
||||||
23
src/api/commodityOrderList.ts
Normal file
23
src/api/commodityOrderList.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
// @ts-ignore
|
||||||
|
import request from './request';
|
||||||
|
|
||||||
|
import * as API from './types';
|
||||||
|
|
||||||
|
/** 商品订单列表 商品订单列表 POST /order/commodityOrderList */
|
||||||
|
export function orderCommodityOrderListUsingPost({
|
||||||
|
body,
|
||||||
|
options,
|
||||||
|
}: {
|
||||||
|
body: API.CommodityOrderListSearchForm;
|
||||||
|
options?: { [key: string]: unknown };
|
||||||
|
}) {
|
||||||
|
return request<API.RPageCommodityOrderDTO>('/order/commodityOrderList', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
data: body,
|
||||||
|
...(options || {}),
|
||||||
|
});
|
||||||
|
}
|
||||||
71
src/api/configChannel.ts
Normal file
71
src/api/configChannel.ts
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
// @ts-ignore
|
||||||
|
import request from './request';
|
||||||
|
|
||||||
|
import * as API from './types';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 绑定渠道账号 绑定渠道账号
|
||||||
|
* 绑定渠道账号
|
||||||
|
* POST /hotelStaff/configChannel/binding
|
||||||
|
*/
|
||||||
|
export function hotelStaffConfigChannelBindingUsingPost({
|
||||||
|
body,
|
||||||
|
options,
|
||||||
|
}: {
|
||||||
|
body: API.PcConfigChannel;
|
||||||
|
options?: { [key: string]: unknown };
|
||||||
|
}) {
|
||||||
|
return request<API.RBoolean>('/hotelStaff/configChannel/binding', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
data: body,
|
||||||
|
...(options || {}),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建账号渠道 创建账号渠道
|
||||||
|
* 创建账号渠道
|
||||||
|
* POST /hotelStaff/configChannel/createPcConfigChannel
|
||||||
|
*/
|
||||||
|
export function hotelStaffConfigChannelCreatePcConfigChannelUsingPost({
|
||||||
|
body,
|
||||||
|
options,
|
||||||
|
}: {
|
||||||
|
body: API.PcConfig;
|
||||||
|
options?: { [key: string]: unknown };
|
||||||
|
}) {
|
||||||
|
return request<API.RBoolean>(
|
||||||
|
'/hotelStaff/configChannel/createPcConfigChannel',
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
data: body,
|
||||||
|
...(options || {}),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询配置与渠道关系列表 查询配置与渠道关系列表
|
||||||
|
* 查询配置与渠道关系列表
|
||||||
|
* POST /hotelStaff/configChannel/pageList
|
||||||
|
*/
|
||||||
|
export function hotelStaffConfigChannelPageListUsingPost({
|
||||||
|
options,
|
||||||
|
}: {
|
||||||
|
options?: { [key: string]: unknown };
|
||||||
|
}) {
|
||||||
|
return request<API.RListPcConfigChannel>(
|
||||||
|
'/hotelStaff/configChannel/pageList',
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
...(options || {}),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
23
src/api/createEvent.ts
Normal file
23
src/api/createEvent.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
// @ts-ignore
|
||||||
|
import request from './request';
|
||||||
|
|
||||||
|
import * as API from './types';
|
||||||
|
|
||||||
|
/** 创建事件 创建事件 POST /event/createEvent */
|
||||||
|
export function eventCreateEventUsingPost({
|
||||||
|
body,
|
||||||
|
options,
|
||||||
|
}: {
|
||||||
|
body: API.CreateEventForm;
|
||||||
|
options?: { [key: string]: unknown };
|
||||||
|
}) {
|
||||||
|
return request<API.RBoolean>('/event/createEvent', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
data: body,
|
||||||
|
...(options || {}),
|
||||||
|
});
|
||||||
|
}
|
||||||
23
src/api/eventList.ts
Normal file
23
src/api/eventList.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
// @ts-ignore
|
||||||
|
import request from './request';
|
||||||
|
|
||||||
|
import * as API from './types';
|
||||||
|
|
||||||
|
/** 事件列表 事件列表 POST /event/eventList */
|
||||||
|
export function eventEventListUsingPost({
|
||||||
|
body,
|
||||||
|
options,
|
||||||
|
}: {
|
||||||
|
body: API.EventListSearchForm;
|
||||||
|
options?: { [key: string]: unknown };
|
||||||
|
}) {
|
||||||
|
return request<API.RPageEventDataDTO>('/event/eventList', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
data: body,
|
||||||
|
...(options || {}),
|
||||||
|
});
|
||||||
|
}
|
||||||
14
src/api/index.ts
Normal file
14
src/api/index.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
// @ts-ignore
|
||||||
|
export * from './types';
|
||||||
|
|
||||||
|
export * from './code';
|
||||||
|
export * from './oauth2';
|
||||||
|
export * from './pcUser';
|
||||||
|
export * from './configChannel';
|
||||||
|
export * from './typeMapping';
|
||||||
|
export * from './writeOff';
|
||||||
|
export * from './commodityOrderList';
|
||||||
|
export * from './userOrderDetail';
|
||||||
|
export * from './createEvent';
|
||||||
|
export * from './eventList';
|
||||||
23
src/api/oauth2.ts
Normal file
23
src/api/oauth2.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
// @ts-ignore
|
||||||
|
import request from './request';
|
||||||
|
|
||||||
|
import * as API from './types';
|
||||||
|
|
||||||
|
/** 登录 POST /auth/oauth2/token */
|
||||||
|
export function authOauth2TokenUsingPost({
|
||||||
|
body,
|
||||||
|
options,
|
||||||
|
}: {
|
||||||
|
body: API.AuthOauth2TokenUsingPostBody;
|
||||||
|
options?: { [key: string]: unknown };
|
||||||
|
}) {
|
||||||
|
return request<API.AuthOauth2TokenUsingPostResponse>('/auth/oauth2/token', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
|
},
|
||||||
|
data: body,
|
||||||
|
...(options || {}),
|
||||||
|
});
|
||||||
|
}
|
||||||
23
src/api/pcUser.ts
Normal file
23
src/api/pcUser.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
// @ts-ignore
|
||||||
|
import request from './request';
|
||||||
|
|
||||||
|
import * as API from './types';
|
||||||
|
|
||||||
|
/** 修改pc桌面端平台用户密码 修改pc桌面端平台用户密码 POST /hotelStaff/pcUser/updatePassword */
|
||||||
|
export function hotelStaffPcUserUpdatePasswordUsingPost({
|
||||||
|
body,
|
||||||
|
options,
|
||||||
|
}: {
|
||||||
|
body: API.UpdatePasswordForm;
|
||||||
|
options?: { [key: string]: unknown };
|
||||||
|
}) {
|
||||||
|
return request<API.RBoolean>('/hotelStaff/pcUser/updatePassword', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
data: body,
|
||||||
|
...(options || {}),
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -1,19 +1,54 @@
|
|||||||
import { hostApiFetch } from '../lib/host-api';
|
import { hostApiFetch } from '@/lib/host-api';
|
||||||
|
|
||||||
type RequestOptions = {
|
interface RequestOptions {
|
||||||
|
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
||||||
|
headers?: Record<string, string>;
|
||||||
data?: unknown;
|
data?: unknown;
|
||||||
headers?: HeadersInit;
|
params?: Record<string, string | number | boolean>;
|
||||||
method?: string;
|
|
||||||
[key: string]: unknown;
|
[key: string]: unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ApiResponse<T> {
|
||||||
|
code: number;
|
||||||
|
data: T;
|
||||||
|
message?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function request<T>(url: string, options: RequestOptions = {}): Promise<T> {
|
||||||
|
const { method = 'GET', headers = {}, data, params, ...rest } = options;
|
||||||
|
|
||||||
|
let finalUrl = url;
|
||||||
|
if (params && Object.keys(params).length > 0) {
|
||||||
|
const searchParams = new URLSearchParams();
|
||||||
|
Object.entries(params).forEach(([key, value]) => {
|
||||||
|
searchParams.append(key, String(value));
|
||||||
|
});
|
||||||
|
finalUrl = `${url}?${searchParams.toString()}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const init: RequestInit = {
|
||||||
|
method,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
...headers,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function request<T>(url: string, options: RequestOptions = {}): Promise<T> {
|
if (data && method !== 'GET') {
|
||||||
const { data, method = 'GET', headers, ...rest } = options;
|
init.body = JSON.stringify(data);
|
||||||
|
|
||||||
return hostApiFetch<T>(url, {
|
|
||||||
...rest,
|
|
||||||
method,
|
|
||||||
headers,
|
|
||||||
body: data == null ? undefined : data,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const response = await hostApiFetch<ApiResponse<T>>(finalUrl, {
|
||||||
|
...init,
|
||||||
|
...rest,
|
||||||
|
body: init.body,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response && typeof response === 'object' && 'data' in response) {
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
return response as T;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default request;
|
||||||
|
|||||||
@@ -1,55 +1,71 @@
|
|||||||
import { hostApiFetch } from '../lib/host-api';
|
/* eslint-disable */
|
||||||
import type * as API from './types';
|
// @ts-ignore
|
||||||
|
import request from './request';
|
||||||
|
|
||||||
type RequestOptions = { [key: string]: unknown };
|
import * as API from './types';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询房型映射列表 查询房型映射列表
|
||||||
|
* 查询房型映射列表
|
||||||
|
* POST /hotelStaff/typeMapping/list
|
||||||
|
*/
|
||||||
export function hotelStaffTypeMappingListUsingPost({
|
export function hotelStaffTypeMappingListUsingPost({
|
||||||
body,
|
body,
|
||||||
options,
|
options,
|
||||||
}: {
|
}: {
|
||||||
body: API.RoomTypeMapping;
|
body: API.RoomTypeMapping;
|
||||||
options?: RequestOptions;
|
options?: { [key: string]: unknown };
|
||||||
}) {
|
}) {
|
||||||
return hostApiFetch<API.RListRoomTypeMapping>('/hotelStaff/typeMapping/list', {
|
return request<API.RListRoomTypeMapping>('/hotelStaff/typeMapping/list', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
...((options?.headers as Record<string, string> | undefined) ?? {}),
|
|
||||||
},
|
},
|
||||||
body: JSON.stringify(body),
|
data: body,
|
||||||
|
...(options || {}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询房型映射列表 查询房型映射列表
|
||||||
|
* 查询房型映射列表
|
||||||
|
* POST /hotelStaff/typeMapping/pageList
|
||||||
|
*/
|
||||||
export function hotelStaffTypeMappingPageListUsingPost({
|
export function hotelStaffTypeMappingPageListUsingPost({
|
||||||
body,
|
body,
|
||||||
options,
|
options,
|
||||||
}: {
|
}: {
|
||||||
body: API.RoomTypeMapping;
|
body: API.RoomTypeMapping;
|
||||||
options?: RequestOptions;
|
options?: { [key: string]: unknown };
|
||||||
}) {
|
}) {
|
||||||
return hostApiFetch<API.RPageRoomTypeMapping>('/hotelStaff/typeMapping/pageList', {
|
return request<API.RPageRoomTypeMapping>('/hotelStaff/typeMapping/pageList', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
...((options?.headers as Record<string, string> | undefined) ?? {}),
|
|
||||||
},
|
},
|
||||||
body: JSON.stringify(body),
|
data: body,
|
||||||
|
...(options || {}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改房型映射 修改房型映射
|
||||||
|
* 修改房型映射
|
||||||
|
* POST /hotelStaff/typeMapping/update
|
||||||
|
*/
|
||||||
export function hotelStaffTypeMappingUpdateUsingPost({
|
export function hotelStaffTypeMappingUpdateUsingPost({
|
||||||
body,
|
body,
|
||||||
options,
|
options,
|
||||||
}: {
|
}: {
|
||||||
body: API.RoomTypeMapping;
|
body: API.RoomTypeMapping;
|
||||||
options?: RequestOptions;
|
options?: { [key: string]: unknown };
|
||||||
}) {
|
}) {
|
||||||
return hostApiFetch<API.RBoolean>('/hotelStaff/typeMapping/update', {
|
return request<API.RBoolean>('/hotelStaff/typeMapping/update', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
...((options?.headers as Record<string, string> | undefined) ?? {}),
|
|
||||||
},
|
},
|
||||||
body: JSON.stringify(body),
|
data: body,
|
||||||
|
...(options || {}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
563
src/api/types.ts
563
src/api/types.ts
@@ -1,8 +1,319 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
// @ts-ignore
|
||||||
|
|
||||||
|
export type AuthCodeImageUsingGetParams = {
|
||||||
|
randomStr?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type AuthCodeImageUsingGetResponse = Record<string, unknown>;
|
||||||
|
|
||||||
|
export type AuthCodeImageUsingGetResponses = {
|
||||||
|
200: AuthCodeImageUsingGetResponse;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type AuthOauth2TokenUsingPostBody = {
|
||||||
|
openIdCode?: unknown[];
|
||||||
|
grant_type?: string;
|
||||||
|
scope?: string;
|
||||||
|
clientId: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type AuthOauth2TokenUsingPostResponse = Record<string, unknown>;
|
||||||
|
|
||||||
|
export type AuthOauth2TokenUsingPostResponses = {
|
||||||
|
200: AuthOauth2TokenUsingPostResponse;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type CommodityEquipmentDTO = {
|
||||||
|
/** 设施图标 */
|
||||||
|
icon?: string;
|
||||||
|
/** 设施标题 */
|
||||||
|
title?: string;
|
||||||
|
/** 设施描述 */
|
||||||
|
desc?: string[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type CommodityOrderDTO = {
|
||||||
|
/** 订单号 */
|
||||||
|
id?: string;
|
||||||
|
/** 订单金额 */
|
||||||
|
orderAmt?: string;
|
||||||
|
/** 游客姓名 */
|
||||||
|
visitorName?: string;
|
||||||
|
/** 联系电话 */
|
||||||
|
contactPhone?: string;
|
||||||
|
/** 入住时间(yyyy-MM-dd) */
|
||||||
|
checkInData?: string;
|
||||||
|
/** 离店时间(yyyy-MM-dd) */
|
||||||
|
checkOutData?: string;
|
||||||
|
/**
|
||||||
|
* 订单状态
|
||||||
|
* 0-待支付
|
||||||
|
* 1-待确认
|
||||||
|
* 2-待使用
|
||||||
|
* 3-已取消
|
||||||
|
* 4-退款中
|
||||||
|
* 5-已关闭
|
||||||
|
* 6-已完成
|
||||||
|
* 订单状态 0-待支付 1-待确认 2-待使用 3-已取消 4-退款中 5-已关闭 6-已完成
|
||||||
|
*/
|
||||||
|
orderStatus?: string;
|
||||||
|
/** 用户id */
|
||||||
|
userId?: string;
|
||||||
|
/** 组织id */
|
||||||
|
organizationId?: string;
|
||||||
|
/**
|
||||||
|
* 支付状态
|
||||||
|
* 0-未支付
|
||||||
|
* 1-已支付
|
||||||
|
* 支付状态 0-未支付 1-已支付
|
||||||
|
*/
|
||||||
|
payStatus?: string;
|
||||||
|
/** 支付金额 */
|
||||||
|
payAmt?: string;
|
||||||
|
/** 优惠金额 */
|
||||||
|
discountAmt?: string;
|
||||||
|
/** 支付时间 */
|
||||||
|
payTime?: string;
|
||||||
|
/**
|
||||||
|
* 订单类型
|
||||||
|
* 0-酒店
|
||||||
|
* 1-门票
|
||||||
|
* 2-餐饮
|
||||||
|
*/
|
||||||
|
orderType?: string;
|
||||||
|
/** 创建时间 */
|
||||||
|
createTime?: string;
|
||||||
|
/** 房间确认后的房间号 */
|
||||||
|
roomId?: string;
|
||||||
|
/** 商品信息 */
|
||||||
|
commodityName?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type CommodityOrderInfoWriteOffForm = {
|
||||||
|
/** 订单号 */
|
||||||
|
orderId?: string;
|
||||||
|
/** 套餐名称 */
|
||||||
|
packageName?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type CommodityOrderListSearchForm = {
|
||||||
|
/** 页码 */
|
||||||
|
pageNum: number;
|
||||||
|
/** 页面数量 */
|
||||||
|
pageSize: number;
|
||||||
|
/**
|
||||||
|
* 商品类型编码0-酒店
|
||||||
|
* 1-门票
|
||||||
|
* 2-餐饮
|
||||||
|
*/
|
||||||
|
commodityTypeCode?: string;
|
||||||
|
/** 订单状态 */
|
||||||
|
orderStatus?: string;
|
||||||
|
/** 创建时间的开始时间(yyyy-MM-dd) */
|
||||||
|
orderCreateTimeStartDate?: string;
|
||||||
|
/** 创建时间的结束时间(yyyy-MM-dd) */
|
||||||
|
orderCreateTimeEndDate?: string;
|
||||||
|
/** 房间号 */
|
||||||
|
roomId?: string;
|
||||||
|
/** 订单号 */
|
||||||
|
orderId?: string;
|
||||||
|
/** 联系电话 */
|
||||||
|
contactPhone?: string;
|
||||||
|
/** 组织id */
|
||||||
|
organizationId: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type CommodityPackageConfigDTO = {
|
||||||
|
/** 套餐商品名称 */
|
||||||
|
name?: string;
|
||||||
|
/** 商品数量 */
|
||||||
|
count?: number;
|
||||||
|
/** 商品颜色 */
|
||||||
|
color?: string;
|
||||||
|
/** 套餐状态 0 未核销 1 已核销 */
|
||||||
|
packageStatus?: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type CommodityPurchaseInstructionModuleEntity = {
|
||||||
|
/** 模块标题 */
|
||||||
|
moduleTitle?: string;
|
||||||
|
/** 模块图标 */
|
||||||
|
moduleIcon?: string;
|
||||||
|
/** 模块内容 */
|
||||||
|
moduleContent?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type CommodityPurchaseInstructionTemplateDTO = {
|
||||||
|
/** 模板id */
|
||||||
|
templateId?: string;
|
||||||
|
/** 模板名称 */
|
||||||
|
templateName?: string;
|
||||||
|
/** 一级标题 */
|
||||||
|
templateTitle?: string;
|
||||||
|
/** 退款标题 */
|
||||||
|
refundTitle?: string;
|
||||||
|
/** 退款logo */
|
||||||
|
refundLogo?: string;
|
||||||
|
/** 退款内容(退款政策) */
|
||||||
|
refundContent?: string;
|
||||||
|
/** 购买须知的内容 */
|
||||||
|
commodityPurchaseInstructionModuleEntityList?: CommodityPurchaseInstructionModuleEntity[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type CommodityServiceEntity = {
|
||||||
|
/** 服务项名称 */
|
||||||
|
serviceTitle?: string;
|
||||||
|
/** 分组名称 */
|
||||||
|
groupName?: string;
|
||||||
|
/** 服务份数 */
|
||||||
|
serviceAmount?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ConsumerInfoEntity = {
|
||||||
|
/** 游客姓名 */
|
||||||
|
visitorName?: string;
|
||||||
|
/** 联系电话 */
|
||||||
|
contactPhone?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type CreateEventForm = {
|
||||||
|
/** 实体名称 */
|
||||||
|
entityName?: string;
|
||||||
|
/** 事件描述 */
|
||||||
|
eventDescription?: string;
|
||||||
|
/** 发布员工名称 */
|
||||||
|
createByName?: string;
|
||||||
|
/** 弹窗提醒 0-否 1-是 */
|
||||||
|
popUpReminder?: number;
|
||||||
|
/** 发布时间(yyyy-MM-dd HH:mm:ss) */
|
||||||
|
publicTime?: string;
|
||||||
|
/** 事件生效开始时间(yyyy-MM-dd HH:mm:ss) */
|
||||||
|
effectiveStartTime?: string;
|
||||||
|
/** 事件生效结束时间(yyyy-MM-dd HH:mm:ss) */
|
||||||
|
effectiveEndTime?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type EventCreateEventUsingPostResponses = {
|
||||||
|
200: RBoolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type EventDataDTO = {
|
||||||
|
/** 主键id */
|
||||||
|
id?: string;
|
||||||
|
/** 实体名称 */
|
||||||
|
entityName?: string;
|
||||||
|
/** 事件描述 */
|
||||||
|
eventDescription?: string;
|
||||||
|
/** 事件状态 0-开启 1-关闭 */
|
||||||
|
eventStatus?: number;
|
||||||
|
/** 事件生效开始时间 */
|
||||||
|
effectiveStartTime?: string;
|
||||||
|
/** 事件生效结束时间 */
|
||||||
|
effectiveEndTime?: string;
|
||||||
|
/** 发布员工名称 */
|
||||||
|
createByName?: string;
|
||||||
|
/** 弹窗提醒 0-否 1-是 */
|
||||||
|
popUpReminder?: number;
|
||||||
|
/** 发布时间 */
|
||||||
|
publicTime?: string;
|
||||||
|
/** 显示状态 待生效 生效中 已过期 */
|
||||||
|
showStatusDesc?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type EventEventListUsingPostResponses = {
|
||||||
|
200: RPageEventDataDTO;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type EventListSearchForm = {
|
||||||
|
/** 页码 */
|
||||||
|
pageNum: number;
|
||||||
|
/** 页面数量 */
|
||||||
|
pageSize: number;
|
||||||
|
/** 实体名称 */
|
||||||
|
entityName?: string;
|
||||||
|
/** 事件状态 0-开启 1-关闭 */
|
||||||
|
eventStatus?: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type HotelStaffConfigChannelBindingUsingPostResponses = {
|
||||||
|
200: RBoolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type HotelStaffConfigChannelCreatePcConfigChannelUsingPostResponses = {
|
||||||
|
200: RBoolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type HotelStaffConfigChannelPageListUsingPostResponses = {
|
||||||
|
200: RListPcConfigChannel;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type HotelStaffPcUserUpdatePasswordUsingPostResponses = {
|
||||||
|
200: RBoolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type HotelStaffTypeMappingListUsingPostResponses = {
|
||||||
|
200: RListRoomTypeMapping;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type HotelStaffTypeMappingPageListUsingPostResponses = {
|
||||||
|
200: RPageRoomTypeMapping;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type HotelStaffTypeMappingUpdateUsingPostResponses = {
|
||||||
|
200: RBoolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type OpenDateRangeDTO = {
|
||||||
|
/** 起始时间 */
|
||||||
|
begin?: string;
|
||||||
|
/** 结束时间 */
|
||||||
|
end?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type OrderCommodityOrderListUsingPostResponses = {
|
||||||
|
200: RPageCommodityOrderDTO;
|
||||||
|
};
|
||||||
|
|
||||||
export type OrderItem = {
|
export type OrderItem = {
|
||||||
column?: string;
|
column?: string;
|
||||||
asc?: boolean;
|
asc?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type OrderUserOrderDetailUsingPostResponses = {
|
||||||
|
200: RUserOrderDetailDTO;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type OrderWriteOffUsingPostResponses = {
|
||||||
|
200: RBoolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type PageCommodityOrderDTO = {
|
||||||
|
records?: CommodityOrderDTO[];
|
||||||
|
total?: number;
|
||||||
|
size?: number;
|
||||||
|
current?: number;
|
||||||
|
orders?: OrderItem[];
|
||||||
|
optimizeCountSql?: boolean;
|
||||||
|
searchCount?: boolean;
|
||||||
|
optimizeJoinOfCountSql?: boolean;
|
||||||
|
maxLimit?: number;
|
||||||
|
countId?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type PageEventDataDTO = {
|
||||||
|
records?: EventDataDTO[];
|
||||||
|
total?: number;
|
||||||
|
size?: number;
|
||||||
|
current?: number;
|
||||||
|
orders?: OrderItem[];
|
||||||
|
optimizeCountSql?: boolean;
|
||||||
|
searchCount?: boolean;
|
||||||
|
optimizeJoinOfCountSql?: boolean;
|
||||||
|
maxLimit?: number;
|
||||||
|
countId?: string;
|
||||||
|
};
|
||||||
|
|
||||||
export type PageRoomTypeMapping = {
|
export type PageRoomTypeMapping = {
|
||||||
records?: RoomTypeMapping[];
|
records?: RoomTypeMapping[];
|
||||||
total?: number;
|
total?: number;
|
||||||
@@ -16,22 +327,73 @@ export type PageRoomTypeMapping = {
|
|||||||
countId?: string;
|
countId?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type RoomTypeMapping = {
|
export type PcConfig = {
|
||||||
|
/**
|
||||||
|
* 创建者
|
||||||
|
* 创建人
|
||||||
|
*/
|
||||||
createBy?: string;
|
createBy?: string;
|
||||||
|
/** 创建时间 */
|
||||||
createTime?: string;
|
createTime?: string;
|
||||||
|
/**
|
||||||
|
* 更新者
|
||||||
|
* 更新人
|
||||||
|
*/
|
||||||
updateBy?: string;
|
updateBy?: string;
|
||||||
|
/** 更新时间 */
|
||||||
updateTime?: string;
|
updateTime?: string;
|
||||||
|
/** 主键 */
|
||||||
id?: string;
|
id?: string;
|
||||||
pmsName?: string;
|
/** 配置信息id */
|
||||||
xcName?: string;
|
|
||||||
fzName?: string;
|
|
||||||
mtName?: string;
|
|
||||||
dyHotelName?: string;
|
|
||||||
dyHotSrpingName?: string;
|
|
||||||
dyHotSpringName?: string;
|
|
||||||
pcConfigId?: string;
|
pcConfigId?: string;
|
||||||
|
/** 账号id */
|
||||||
|
platformUserId?: string;
|
||||||
|
/** 租户id */
|
||||||
|
tenantId?: number;
|
||||||
|
/** 组织id */
|
||||||
|
organizationId?: string;
|
||||||
|
/** 删除标志 true/false 删除/未删除 */
|
||||||
delFlag?: number;
|
delFlag?: number;
|
||||||
|
/** 分页数量 */
|
||||||
size?: number;
|
size?: number;
|
||||||
|
/** 分页标识 从1开始 */
|
||||||
|
current?: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type PcConfigChannel = {
|
||||||
|
/**
|
||||||
|
* 创建者
|
||||||
|
* 创建人
|
||||||
|
*/
|
||||||
|
createBy?: string;
|
||||||
|
/** 创建时间 */
|
||||||
|
createTime?: string;
|
||||||
|
/**
|
||||||
|
* 更新者
|
||||||
|
* 更新人
|
||||||
|
*/
|
||||||
|
updateBy?: string;
|
||||||
|
/** 更新时间 */
|
||||||
|
updateTime?: string;
|
||||||
|
/** 主键 */
|
||||||
|
id?: string;
|
||||||
|
/** 配置信息id */
|
||||||
|
pcConfigId?: string;
|
||||||
|
/** 系统渠道id */
|
||||||
|
systemChannelId?: string;
|
||||||
|
/** 是否绑定 0未绑定 1已绑定 */
|
||||||
|
bindingFlag?: number;
|
||||||
|
/** 绑定账号 */
|
||||||
|
bindingUsername?: string;
|
||||||
|
/** 绑定密码 */
|
||||||
|
bindingPassword?: string;
|
||||||
|
/** 当前登录token信息 */
|
||||||
|
loginToken?: string;
|
||||||
|
/** 删除标志 true/false 删除/未删除 */
|
||||||
|
delFlag?: number;
|
||||||
|
/** 分页数量 */
|
||||||
|
size?: number;
|
||||||
|
/** 分页标识 从1开始 */
|
||||||
current?: number;
|
current?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -41,14 +403,199 @@ export type RBoolean = {
|
|||||||
data?: boolean;
|
data?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type RListPcConfigChannel = {
|
||||||
|
code?: number;
|
||||||
|
msg?: string;
|
||||||
|
data?: PcConfigChannel[];
|
||||||
|
};
|
||||||
|
|
||||||
export type RListRoomTypeMapping = {
|
export type RListRoomTypeMapping = {
|
||||||
code?: number;
|
code?: number;
|
||||||
msg?: string;
|
msg?: string;
|
||||||
data?: RoomTypeMapping[];
|
data?: RoomTypeMapping[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type RoomTypeMapping = {
|
||||||
|
/**
|
||||||
|
* 创建者
|
||||||
|
* 创建人
|
||||||
|
*/
|
||||||
|
createBy?: string;
|
||||||
|
/** 创建时间 */
|
||||||
|
createTime?: string;
|
||||||
|
/**
|
||||||
|
* 更新者
|
||||||
|
* 更新人
|
||||||
|
*/
|
||||||
|
updateBy?: string;
|
||||||
|
/** 更新时间 */
|
||||||
|
updateTime?: string;
|
||||||
|
/** 主键 */
|
||||||
|
id?: string;
|
||||||
|
/** pms名称 */
|
||||||
|
pmsName?: string;
|
||||||
|
/** 携程渠道名称 */
|
||||||
|
xcName?: string;
|
||||||
|
/** 飞猪渠道名称 */
|
||||||
|
fzName?: string;
|
||||||
|
/** 美团渠道名称 */
|
||||||
|
mtName?: string;
|
||||||
|
/** 抖音酒店渠道名称 */
|
||||||
|
dyHotelName?: string;
|
||||||
|
/** 抖音温泉渠道名称 */
|
||||||
|
dyHotSrpingName?: string;
|
||||||
|
/** 配置信息id */
|
||||||
|
pcConfigId?: string;
|
||||||
|
/** 删除标志 true/false 删除/未删除 */
|
||||||
|
delFlag?: number;
|
||||||
|
/** 分页数量 */
|
||||||
|
size?: number;
|
||||||
|
/** 分页标识 从1开始 */
|
||||||
|
current?: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type RPageCommodityOrderDTO = {
|
||||||
|
code?: number;
|
||||||
|
msg?: string;
|
||||||
|
data?: PageCommodityOrderDTO;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type RPageEventDataDTO = {
|
||||||
|
code?: number;
|
||||||
|
msg?: string;
|
||||||
|
data?: PageEventDataDTO;
|
||||||
|
};
|
||||||
|
|
||||||
export type RPageRoomTypeMapping = {
|
export type RPageRoomTypeMapping = {
|
||||||
code?: number;
|
code?: number;
|
||||||
msg?: string;
|
msg?: string;
|
||||||
data?: PageRoomTypeMapping;
|
data?: PageRoomTypeMapping;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type RUserOrderDetailDTO = {
|
||||||
|
code?: number;
|
||||||
|
msg?: string;
|
||||||
|
data?: UserOrderDetailDTO;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type UpdatePasswordForm = {
|
||||||
|
/** 旧密码 */
|
||||||
|
oldPassword?: string;
|
||||||
|
/** 新密码 */
|
||||||
|
newPassword?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type UserOrderDetailDTO = {
|
||||||
|
/** 订单id */
|
||||||
|
orderId?: string;
|
||||||
|
/** 订单金额 */
|
||||||
|
orderAmt?: string;
|
||||||
|
/** 消费者信息 */
|
||||||
|
consumerInfoList?: ConsumerInfoEntity[];
|
||||||
|
/** 入住时间(yyyy-MM-dd) */
|
||||||
|
checkInData?: string;
|
||||||
|
/** 离店时间(yyyy-MM-dd) */
|
||||||
|
checkOutData?: string;
|
||||||
|
/**
|
||||||
|
* 订单状态
|
||||||
|
* 0-待支付
|
||||||
|
* 1-待确认
|
||||||
|
* 2-待使用
|
||||||
|
* 3-已取消
|
||||||
|
* 4-退款中
|
||||||
|
* 5-已关闭
|
||||||
|
* 6-已完成
|
||||||
|
* 订单状态 0-待支付 1-待确认 2-待使用 3-已取消 4-退款中 5-已关闭 6-已完成
|
||||||
|
*/
|
||||||
|
orderStatus?: string;
|
||||||
|
/** 用户id */
|
||||||
|
userId?: string;
|
||||||
|
/** 组织id */
|
||||||
|
organizationId?: string;
|
||||||
|
/**
|
||||||
|
* 支付状态
|
||||||
|
* 0-未支付
|
||||||
|
* 1-已支付
|
||||||
|
* 支付状态 0-未支付 1-已支付
|
||||||
|
*/
|
||||||
|
payStatus?: string;
|
||||||
|
/** 支付金额 */
|
||||||
|
payAmt?: string;
|
||||||
|
/** 优惠金额 */
|
||||||
|
discountAmt?: string;
|
||||||
|
/**
|
||||||
|
* 支付时间
|
||||||
|
* 支付时间(yyyy-MM-dd HH:mm:ss)
|
||||||
|
*/
|
||||||
|
payTime?: string;
|
||||||
|
/** 创建时间 */
|
||||||
|
createTime?: string;
|
||||||
|
/** 商品封面图片 */
|
||||||
|
commodityCoverPhoto?: string;
|
||||||
|
/** 商品核销地址 */
|
||||||
|
writeOffUrl?: string;
|
||||||
|
/** 商品名称 */
|
||||||
|
commodityName?: string;
|
||||||
|
/** 商品地址 */
|
||||||
|
commodityAddress?: string;
|
||||||
|
/** 商品纬度 */
|
||||||
|
commodityLatitude?: string;
|
||||||
|
/** 商品经度 */
|
||||||
|
commodityLongitude?: string;
|
||||||
|
/** 商品服务项列表 */
|
||||||
|
commodityServiceList?: CommodityServiceEntity[];
|
||||||
|
/** 商品购买须知 */
|
||||||
|
commodityTip?: string;
|
||||||
|
/** 支付方式 0-微信 1-支付宝 2-云闪付 */
|
||||||
|
payWay?: string;
|
||||||
|
/** 支付流水号 */
|
||||||
|
paySerialNumber?: string;
|
||||||
|
/** 支付渠道 0-app 1-小程序 2-h5 */
|
||||||
|
paySource?: string;
|
||||||
|
/**
|
||||||
|
* 订单类型
|
||||||
|
* 0-酒店
|
||||||
|
* 1-门票
|
||||||
|
* 2-餐饮
|
||||||
|
*/
|
||||||
|
orderType?: string;
|
||||||
|
/** 购买数量 */
|
||||||
|
commodityAmount?: string;
|
||||||
|
/** 退款单号 */
|
||||||
|
refundOrderNo?: string;
|
||||||
|
/** 门店名称 */
|
||||||
|
storeName?: string;
|
||||||
|
/** 投诉电话 */
|
||||||
|
complaintHotline?: string;
|
||||||
|
/** 一级地址 */
|
||||||
|
oneLevelAddress?: string;
|
||||||
|
/** 二级地址 */
|
||||||
|
twoLevelAddress?: string;
|
||||||
|
/** 是否可退款 */
|
||||||
|
refundable?: boolean;
|
||||||
|
/** 商品购买须知的内容 */
|
||||||
|
commodityPurchaseInstruction?: CommodityPurchaseInstructionTemplateDTO;
|
||||||
|
/** 商品id */
|
||||||
|
commodityId?: string;
|
||||||
|
/** 商品分类的编码 */
|
||||||
|
commodityTypeCode?: string;
|
||||||
|
/** 商品权益列表 */
|
||||||
|
commodityFacilityList?: string[];
|
||||||
|
/** 设施列表 */
|
||||||
|
commodityEquipment?: CommodityEquipmentDTO[];
|
||||||
|
/** 商品描述 */
|
||||||
|
commodityDescription?: string;
|
||||||
|
/** 套餐内容配置 */
|
||||||
|
commodityPackageConfig?: CommodityPackageConfigDTO[];
|
||||||
|
/** 是否启用预约(0-否 1-是) */
|
||||||
|
reservationEnabled?: number;
|
||||||
|
/** 开放日期范围 */
|
||||||
|
openDateRange?: OpenDateRangeDTO[];
|
||||||
|
/** 预约规则说明 */
|
||||||
|
reservationRuleDesc?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type UserOrderDetailSearchForm = {
|
||||||
|
/** 订单id */
|
||||||
|
orderId?: string;
|
||||||
|
};
|
||||||
|
|||||||
23
src/api/userOrderDetail.ts
Normal file
23
src/api/userOrderDetail.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
// @ts-ignore
|
||||||
|
import request from './request';
|
||||||
|
|
||||||
|
import * as API from './types';
|
||||||
|
|
||||||
|
/** 获取订单详情 获取订单详情 POST /order/userOrderDetail */
|
||||||
|
export function orderUserOrderDetailUsingPost({
|
||||||
|
body,
|
||||||
|
options,
|
||||||
|
}: {
|
||||||
|
body: API.UserOrderDetailSearchForm;
|
||||||
|
options?: { [key: string]: unknown };
|
||||||
|
}) {
|
||||||
|
return request<API.RUserOrderDetailDTO>('/order/userOrderDetail', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
data: body,
|
||||||
|
...(options || {}),
|
||||||
|
});
|
||||||
|
}
|
||||||
23
src/api/writeOff.ts
Normal file
23
src/api/writeOff.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
// @ts-ignore
|
||||||
|
import request from './request';
|
||||||
|
|
||||||
|
import * as API from './types';
|
||||||
|
|
||||||
|
/** 核销订单 核销订单 POST /order/writeOff */
|
||||||
|
export function orderWriteOffUsingPost({
|
||||||
|
body,
|
||||||
|
options,
|
||||||
|
}: {
|
||||||
|
body: API.CommodityOrderInfoWriteOffForm;
|
||||||
|
options?: { [key: string]: unknown };
|
||||||
|
}) {
|
||||||
|
return request<API.RBoolean>('/order/writeOff', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
data: body,
|
||||||
|
...(options || {}),
|
||||||
|
});
|
||||||
|
}
|
||||||
54
src/utils/api-request.ts
Normal file
54
src/utils/api-request.ts
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
import { hostApiFetch } from '@/lib/host-api';
|
||||||
|
|
||||||
|
interface RequestOptions {
|
||||||
|
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
||||||
|
headers?: Record<string, string>;
|
||||||
|
data?: unknown;
|
||||||
|
params?: Record<string, string | number | boolean>;
|
||||||
|
[key: string]: unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ApiResponse<T> {
|
||||||
|
code: number;
|
||||||
|
data: T;
|
||||||
|
message?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function request<T>(url: string, options: RequestOptions = {}): Promise<T> {
|
||||||
|
const { method = 'GET', headers = {}, data, params, ...rest } = options;
|
||||||
|
|
||||||
|
let finalUrl = url;
|
||||||
|
if (params && Object.keys(params).length > 0) {
|
||||||
|
const searchParams = new URLSearchParams();
|
||||||
|
Object.entries(params).forEach(([key, value]) => {
|
||||||
|
searchParams.append(key, String(value));
|
||||||
|
});
|
||||||
|
finalUrl = `${url}?${searchParams.toString()}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const init: RequestInit = {
|
||||||
|
method,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
...headers,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
if (data && method !== 'GET') {
|
||||||
|
init.body = JSON.stringify(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await hostApiFetch<ApiResponse<T>>(finalUrl, {
|
||||||
|
...init,
|
||||||
|
...rest,
|
||||||
|
body: init.body,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response && typeof response === 'object' && 'data' in response) {
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
return response as T;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default request;
|
||||||
Reference in New Issue
Block a user