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.
mall-admin/src/api/coupon.js

107 lines
3.2 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.

// 导入封装的 HTTP 请求工具,用于与后端接口通信
import request from '@/utils/request'
/**
* fetchList - 获取优惠券列表
*
* 该函数通过 GET 请求获取优惠券列表,并支持通过参数进行查询筛选。
*
* @param {Object} params - 查询参数,例如分页、筛选条件等。
* @returns {Promise} - 返回一个Promise对象包含接口返回的数据
*
* 用法示例:
* fetchList({ pageNum: 1, pageSize: 10 }).then(response => {
* console.log(response);
* });
*/
export function fetchList(params) {
return request({
url: '/coupon/list', // 接口URL路径获取优惠券列表
method: 'get', // 请求方法GET
params: params // 查询参数通过URL参数传递
})
}
/**
* createCoupon - 创建新的优惠券
*
* 该函数通过 POST 请求向后端提交新优惠券的数据。
*
* @param {Object} data - 优惠券的详细数据,包含名称、折扣等字段。
* @returns {Promise} - 返回一个Promise对象包含接口返回的数据
*
* 用法示例:
* createCoupon({ name: 'Spring Sale', discount: 20 }).then(response => {
* console.log(response);
* });
*/
export function createCoupon(data) {
return request({
url: '/coupon/create', // 接口URL路径创建优惠券
method: 'post', // 请求方法POST
data: data // 请求体,包含优惠券数据
})
}
/**
* getCoupon - 获取单个优惠券的详情
*
* 该函数通过 GET 请求获取指定ID的优惠券详细信息。
*
* @param {number|string} id - 优惠券的唯一标识ID。
* @returns {Promise} - 返回一个Promise对象包含优惠券的详细数据
*
* 用法示例:
* getCoupon(1).then(response => {
* console.log(response);
* });
*/
export function getCoupon(id) {
return request({
url: '/coupon/' + id, // 接口URL路径根据ID获取优惠券详情
method: 'get' // 请求方法GET
})
}
/**
* updateCoupon - 更新指定优惠券的信息
*
* 该函数通过 POST 请求提交修改后的优惠券数据更新指定ID的优惠券。
*
* @param {number|string} id - 优惠券的唯一标识ID。
* @param {Object} data - 修改后的优惠券数据。
* @returns {Promise} - 返回一个Promise对象包含操作结果
*
* 用法示例:
* updateCoupon(1, { name: 'Updated Sale', discount: 25 }).then(response => {
* console.log(response);
* });
*/
export function updateCoupon(id, data) {
return request({
url: '/coupon/update/' + id, // 接口URL路径更新指定ID的优惠券
method: 'post', // 请求方法POST
data: data // 请求体,包含修改后的数据
})
}
/**
* deleteCoupon - 删除指定优惠券
*
* 该函数通过 POST 请求删除指定ID的优惠券。
*
* @param {number|string} id - 优惠券的唯一标识ID。
* @returns {Promise} - 返回一个Promise对象包含操作结果
*
* 用法示例:
* deleteCoupon(1).then(response => {
* console.log(response);
* });
*/
export function deleteCoupon(id) {
return request({
url: '/coupon/delete/' + id, // 接口URL路径删除指定ID的优惠券
method: 'post' // 请求方法POST
})
}