- 添加Docker相关配置文件(.dockerignore, .env.example, .gitignore) - 实现服务端API代理功能,支持文件、模块和服务器API转发 - 创建文章详情页、栏目文章列表页和单页内容展示页面 - 集成Ant Design Vue组件库并实现SSR样式提取功能 - 定义API响应数据结构类型和应用布局组件 - 开发开发者应用中心和文章管理页面 - 实现CMS导航菜单获取和多租户切换功能
179 lines
4.2 KiB
TypeScript
179 lines
4.2 KiB
TypeScript
import request from '@/utils/request';
|
|
import type { ApiResult, PageResult } from '@/api';
|
|
import type { Payment, PaymentParam } from './model';
|
|
import { SERVER_API_URL } from '@/config/setting';
|
|
import type { Order } from '@/api/system/order/model';
|
|
|
|
export type PaymentCreatePayload = Record<string, unknown>;
|
|
|
|
export type PaymentCreateResult = {
|
|
codeUrl?: string;
|
|
url?: string;
|
|
payUrl?: string;
|
|
paymentUrl?: string;
|
|
qrcode?: string;
|
|
orderId?: number;
|
|
orderNo?: string;
|
|
paymentNo?: string;
|
|
tradeNo?: string;
|
|
order?: Order;
|
|
} & Record<string, unknown>;
|
|
|
|
/**
|
|
* 分页查询支付方式
|
|
*/
|
|
export async function pagePayment(params: PaymentParam) {
|
|
const res = await request.get<ApiResult<PageResult<Payment>>>(
|
|
SERVER_API_URL + '/system/payment/page',
|
|
{
|
|
params
|
|
}
|
|
);
|
|
if (res.data.code === 0) {
|
|
return res.data.data;
|
|
}
|
|
return Promise.reject(new Error(res.data.message));
|
|
}
|
|
|
|
/**
|
|
* 查询支付方式列表
|
|
*/
|
|
export async function listPayment(params?: PaymentParam) {
|
|
const res = await request.get<ApiResult<Payment[]>>(
|
|
SERVER_API_URL + '/system/payment',
|
|
{
|
|
params
|
|
}
|
|
);
|
|
if (res.data.code === 0 && res.data.data) {
|
|
return res.data.data;
|
|
}
|
|
return Promise.reject(new Error(res.data.message));
|
|
}
|
|
|
|
/**
|
|
* 添加支付方式
|
|
*/
|
|
export async function addPayment(data: Payment) {
|
|
const res = await request.post<ApiResult<unknown>>(
|
|
SERVER_API_URL + '/system/payment',
|
|
data
|
|
);
|
|
if (res.data.code === 0) {
|
|
return res.data.message;
|
|
}
|
|
return Promise.reject(new Error(res.data.message));
|
|
}
|
|
|
|
/**
|
|
* 统一下单订单接口
|
|
*/
|
|
export async function create(data: PaymentCreatePayload) {
|
|
const res = await request.post<ApiResult<PaymentCreateResult>>(
|
|
SERVER_API_URL + '/system/payment/create',
|
|
data
|
|
);
|
|
if (res.data.code === 0) {
|
|
return res.data.data;
|
|
}
|
|
return Promise.reject(new Error(res.data.message));
|
|
}
|
|
|
|
/**
|
|
* 统一下单订单接口(包含订单信息)
|
|
*/
|
|
export async function createWithOrder(data: PaymentCreatePayload) {
|
|
try {
|
|
const res = await request.post<ApiResult<PaymentCreateResult>>(
|
|
SERVER_API_URL + '/system/payment/createWithOrder',
|
|
data
|
|
);
|
|
if (res.data.code === 0) {
|
|
return res.data.data;
|
|
}
|
|
return Promise.reject(new Error(res.data.message));
|
|
} catch (e: any) {
|
|
const status = e?.statusCode ?? e?.response?.status;
|
|
if (String(status) !== '404') throw e;
|
|
|
|
const res = await request.post<ApiResult<PaymentCreateResult>>(
|
|
SERVER_API_URL + '/system/payment/create-with-order',
|
|
data
|
|
);
|
|
if (res.data.code === 0) {
|
|
return res.data.data;
|
|
}
|
|
return Promise.reject(new Error(res.data.message));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 修改支付方式
|
|
*/
|
|
export async function updatePayment(data: Payment) {
|
|
const res = await request.put<ApiResult<unknown>>(
|
|
SERVER_API_URL + '/system/payment',
|
|
data
|
|
);
|
|
if (res.data.code === 0) {
|
|
return res.data.message;
|
|
}
|
|
return Promise.reject(new Error(res.data.message));
|
|
}
|
|
|
|
/**
|
|
* 删除支付方式
|
|
*/
|
|
export async function removePayment(id?: number) {
|
|
const res = await request.delete<ApiResult<unknown>>(
|
|
SERVER_API_URL + '/system/payment/' + id
|
|
);
|
|
if (res.data.code === 0) {
|
|
return res.data.message;
|
|
}
|
|
return Promise.reject(new Error(res.data.message));
|
|
}
|
|
|
|
/**
|
|
* 批量删除支付方式
|
|
*/
|
|
export async function removeBatchPayment(data: (number | undefined)[]) {
|
|
const res = await request.delete<ApiResult<unknown>>(
|
|
SERVER_API_URL + '/system/payment/batch',
|
|
{
|
|
data
|
|
}
|
|
);
|
|
if (res.data.code === 0) {
|
|
return res.data.message;
|
|
}
|
|
return Promise.reject(new Error(res.data.message));
|
|
}
|
|
|
|
/**
|
|
* 根据id查询支付方式
|
|
*/
|
|
export async function getPayment(id: number) {
|
|
const res = await request.get<ApiResult<Payment>>(
|
|
SERVER_API_URL + '/system/payment/' + id
|
|
);
|
|
if (res.data.code === 0 && res.data.data) {
|
|
return res.data.data;
|
|
}
|
|
return Promise.reject(new Error(res.data.message));
|
|
}
|
|
|
|
/**
|
|
* 生成支付二维码(微信native)
|
|
*/
|
|
export async function getNativeCode(data: Order) {
|
|
const res = await request.post<ApiResult<unknown>>(
|
|
SERVER_API_URL + '/system/wx-native-pay/codeUrl',
|
|
data
|
|
);
|
|
if (res.data.code === 0) {
|
|
return res.data.data;
|
|
}
|
|
return Promise.reject(new Error(res.data.message));
|
|
}
|