// 导入封装的 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 }) }