feat(反馈): 添加提交反馈的API接口和实现
- 在other.js中添加SUBMIT_FEEDBACK API接口 - 实现反馈页面的表单提交逻辑,包括分类映射和错误处理 - 移除模拟提交代码,改为调用真实API接口
Showing
2 changed files
with
44 additions
and
11 deletions
| 1 | /* | 1 | /* |
| 2 | * @Date: 2025-07-10 16:13:08 | 2 | * @Date: 2025-07-10 16:13:08 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2025-07-11 09:40:22 | 4 | + * @LastEditTime: 2025-07-14 15:19:19 |
| 5 | * @FilePath: /jgdl/src/api/other.js | 5 | * @FilePath: /jgdl/src/api/other.js |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | */ | 7 | */ |
| ... | @@ -11,6 +11,7 @@ const Api = { | ... | @@ -11,6 +11,7 @@ const Api = { |
| 11 | GET_SCHOOLS: '/srv/?a=common&t=get_schools', | 11 | GET_SCHOOLS: '/srv/?a=common&t=get_schools', |
| 12 | GET_BRANDS_MODELS: '/srv/?a=common&t=get_brands_models', | 12 | GET_BRANDS_MODELS: '/srv/?a=common&t=get_brands_models', |
| 13 | GET_VEHICLE_BRANDS: '/srv/?a=common&t=get_vehicle_brands', | 13 | GET_VEHICLE_BRANDS: '/srv/?a=common&t=get_vehicle_brands', |
| 14 | + SUBMIT_FEEDBACK: '/srv/?a=common&t=submit_feedback', | ||
| 14 | GET_FAVORITE_LIST: '/srv/?a=favorite&t=list', | 15 | GET_FAVORITE_LIST: '/srv/?a=favorite&t=list', |
| 15 | TOGGLE_FAVORITE_ADD: '/srv/?a=favorite&t=add', | 16 | TOGGLE_FAVORITE_ADD: '/srv/?a=favorite&t=add', |
| 16 | TOGGLE_FAVORITE_DEL: '/srv/?a=favorite&t=del', | 17 | TOGGLE_FAVORITE_DEL: '/srv/?a=favorite&t=del', |
| ... | @@ -53,3 +54,14 @@ export const getFavoriteListAPI = (params) => fn(fetch.get(Api.GET_FAVORITE_LIST | ... | @@ -53,3 +54,14 @@ export const getFavoriteListAPI = (params) => fn(fetch.get(Api.GET_FAVORITE_LIST |
| 53 | */ | 54 | */ |
| 54 | export const toggleFavoriteAddAPI = (params) => fn(fetch.post(Api.TOGGLE_FAVORITE_ADD, params)); | 55 | export const toggleFavoriteAddAPI = (params) => fn(fetch.post(Api.TOGGLE_FAVORITE_ADD, params)); |
| 55 | export const toggleFavoriteDelAPI = (params) => fn(fetch.post(Api.TOGGLE_FAVORITE_DEL, params)); | 56 | export const toggleFavoriteDelAPI = (params) => fn(fetch.post(Api.TOGGLE_FAVORITE_DEL, params)); |
| 57 | + | ||
| 58 | +/** | ||
| 59 | + * @description: 提交反馈 | ||
| 60 | + * @param {*} params | ||
| 61 | + * @param {string} params.category - 反馈类型(1=功能建议,2=界面设计,3=车辆信息, 4=其他) | ||
| 62 | + * @param {string} params.content - 反馈内容 | ||
| 63 | + * @param {string} params.images - 上传图片(选填) 最多3张 | ||
| 64 | + * @param {string} params.contact_info - 联系方式(选填) 手机号或微信号 | ||
| 65 | + * @returns | ||
| 66 | + */ | ||
| 67 | +export const submitFeedbackAPI = (params) => fn(fetch.post(Api.SUBMIT_FEEDBACK, params)); | ... | ... |
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2022-09-19 14:11:06 | 2 | * @Date: 2022-09-19 14:11:06 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2025-07-08 11:02:56 | 4 | + * @LastEditTime: 2025-07-14 15:20:15 |
| 5 | * @FilePath: /jgdl/src/pages/feedBack/index.vue | 5 | * @FilePath: /jgdl/src/pages/feedBack/index.vue |
| 6 | * @Description: 意见反馈页面 | 6 | * @Description: 意见反馈页面 |
| 7 | --> | 7 | --> |
| ... | @@ -126,6 +126,8 @@ import { Plus, Close } from '@nutui/icons-vue-taro' | ... | @@ -126,6 +126,8 @@ import { Plus, Close } from '@nutui/icons-vue-taro' |
| 126 | import { Toast } from '@nutui/nutui-taro' | 126 | import { Toast } from '@nutui/nutui-taro' |
| 127 | import BASE_URL from '@/utils/config' | 127 | import BASE_URL from '@/utils/config' |
| 128 | import './index.less' | 128 | import './index.less' |
| 129 | +// 导入接口 | ||
| 130 | +import { submitFeedbackAPI } from '@/api/other' | ||
| 129 | 131 | ||
| 130 | // 反馈分类 | 132 | // 反馈分类 |
| 131 | const categories = ref([ | 133 | const categories = ref([ |
| ... | @@ -269,32 +271,51 @@ const closePreview = () => { | ... | @@ -269,32 +271,51 @@ const closePreview = () => { |
| 269 | /** | 271 | /** |
| 270 | * 提交反馈 | 272 | * 提交反馈 |
| 271 | */ | 273 | */ |
| 272 | -const handleSubmit = () => { | 274 | +const handleSubmit = async () => { |
| 273 | if (!canSubmit.value) return | 275 | if (!canSubmit.value) return |
| 274 | 276 | ||
| 275 | Taro.showLoading({ title: '提交中...', mask: true }) | 277 | Taro.showLoading({ title: '提交中...', mask: true }) |
| 276 | 278 | ||
| 279 | + try { | ||
| 280 | + // 将分类ID转换为数字格式 | ||
| 281 | + const categoryMap = { | ||
| 282 | + 'feature': '1', | ||
| 283 | + 'ui': '2', | ||
| 284 | + 'vehicle': '3', | ||
| 285 | + 'other': '4' | ||
| 286 | + } | ||
| 287 | + | ||
| 277 | // 构建提交数据 | 288 | // 构建提交数据 |
| 278 | const submitData = { | 289 | const submitData = { |
| 279 | - category: selectedCategory.value, | 290 | + category: categoryMap[selectedCategory.value], |
| 280 | content: feedbackText.value.trim(), | 291 | content: feedbackText.value.trim(), |
| 281 | - contact: contactInfo.value.trim(), | 292 | + contact_info: contactInfo.value.trim(), |
| 282 | - images: uploadedImages.value | 293 | + images: uploadedImages.value.join(',') |
| 283 | } | 294 | } |
| 284 | 295 | ||
| 285 | - // TODO: 调用实际的API接口提交数据 | 296 | + // 调用真实的API接口提交数据 |
| 286 | - // submitFeedback(submitData) | 297 | + const response = await submitFeedbackAPI(submitData) |
| 287 | 298 | ||
| 288 | - // 模拟提交 | ||
| 289 | - setTimeout(() => { | ||
| 290 | Taro.hideLoading() | 299 | Taro.hideLoading() |
| 300 | + | ||
| 301 | + if (response.code) { | ||
| 291 | showSuccessModal.value = true | 302 | showSuccessModal.value = true |
| 292 | 303 | ||
| 293 | // 2秒后自动关闭并重置表单 | 304 | // 2秒后自动关闭并重置表单 |
| 294 | setTimeout(() => { | 305 | setTimeout(() => { |
| 295 | closeSuccessModal() | 306 | closeSuccessModal() |
| 296 | }, 2000) | 307 | }, 2000) |
| 297 | - }, 1500) | 308 | + } else { |
| 309 | + throw new Error(response.message || '提交失败') | ||
| 310 | + } | ||
| 311 | + } catch (error) { | ||
| 312 | + Taro.hideLoading() | ||
| 313 | + Taro.showToast({ | ||
| 314 | + title: error.message || '提交失败,请重试', | ||
| 315 | + icon: 'error', | ||
| 316 | + duration: 2000 | ||
| 317 | + }) | ||
| 318 | + } | ||
| 298 | } | 319 | } |
| 299 | 320 | ||
| 300 | /** | 321 | /** | ... | ... |
-
Please register or login to post a comment