| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- /**
- * 商品评价 API(与 miniprogram `src/api/reviewApi.ts` 路径与语义一致)
- */
- import { API_URL } from '@/config/api'
- import { request, parseResponseJson } from '@/utils/request'
- /**
- * 获取商品评价列表
- */
- export function fetchProductReviews(productId, params) {
- return new Promise((resolve, reject) => {
- if (!productId) {
- reject(new Error('missing productId'))
- return
- }
- request({
- url: `${API_URL.PRODUCT_REVIEWS}/${productId}`,
- method: 'GET',
- data: params || {}
- })
- .then((res) => {
- const body = parseResponseJson(res)
- if (body && body.code === 200) {
- resolve(body.data)
- } else {
- uni.showToast({ title: (body && body.message) || '获取评价列表失败', icon: 'none' })
- reject(body)
- }
- })
- .catch((err) => {
- uni.showToast({ title: (err && err.message) || '网络请求失败', icon: 'none' })
- reject(err)
- })
- })
- }
- /**
- * 提交评价
- */
- export function fetchCreateReview(data) {
- return new Promise((resolve, reject) => {
- request({
- url: API_URL.CREATE_REVIEW,
- method: 'POST',
- data
- })
- .then((res) => {
- const body = parseResponseJson(res)
- if (body && body.code === 200) {
- uni.showToast({ title: '评价提交成功', icon: 'success' })
- resolve(body.data)
- } else {
- uni.showToast({ title: (body && body.message) || '评价提交失败', icon: 'none' })
- reject(body)
- }
- })
- .catch((err) => {
- uni.showToast({ title: (err && err.message) || '网络请求失败', icon: 'none' })
- reject(err)
- })
- })
- }
- /**
- * 点赞评价
- */
- export function fetchLikeReview(reviewId) {
- return new Promise((resolve, reject) => {
- request({
- url: API_URL.REVIEW_LIKE(reviewId),
- method: 'POST'
- })
- .then((res) => {
- const body = parseResponseJson(res)
- if (body && body.code === 200) {
- resolve(body.data)
- } else {
- uni.showToast({ title: (body && body.message) || '点赞失败', icon: 'none' })
- reject(body)
- }
- })
- .catch((err) => {
- uni.showToast({ title: (err && err.message) || '网络请求失败', icon: 'none' })
- reject(err)
- })
- })
- }
- /**
- * 获取商品评价统计
- */
- export function fetchReviewStatistics(productId) {
- return new Promise((resolve, reject) => {
- request({
- url: API_URL.REVIEW_STATISTICS(productId),
- method: 'GET'
- })
- .then((res) => {
- const body = parseResponseJson(res)
- if (body && body.code === 200) {
- resolve(body.data)
- } else {
- uni.showToast({ title: (body && body.message) || '获取评价统计失败', icon: 'none' })
- reject(body)
- }
- })
- .catch((err) => {
- uni.showToast({ title: (err && err.message) || '网络请求失败', icon: 'none' })
- reject(err)
- })
- })
- }
|