Files
novel_frontend_RcKtFezyRAZX/wechat/pages/feedback/feedback.js
mzltMpfqGS e4a087e67e init
2026-04-15 19:45:16 +08:00

110 lines
2.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// pages/feedback/feedback.js
// 意见反馈逻辑处理
const app = getApp()
const api = require('../../services/api')
Page({
data: {
typeIndex: 0,
typeList: ['功能建议', 'Bug反馈', '体验问题', '其他'],
type: '功能建议',
content: '',
contact: '',
images: [],
loading: false
},
onLoad(options) {
if (options.type) {
const index = this.data.typeList.findIndex(item => item === options.type)
if (index !== -1) {
this.setData({ typeIndex: index, type: options.type })
}
}
},
onTypeChange(e) {
const index = e.detail.value
this.setData({
typeIndex: index,
type: this.data.typeList[index]
})
},
onContentInput(e) {
this.setData({ content: e.detail.value })
},
onContactInput(e) {
this.setData({ contact: e.detail.value })
},
onChooseImage() {
const count = 3 - this.data.images.length
if (count <= 0) {
wx.showToast({ title: '最多上传3张图片', icon: 'none' })
return
}
wx.chooseImage({
count: count,
sizeType: ['compressed'],
sourceType: ['album', 'camera'],
success: res => {
const images = this.data.images.concat(res.tempFilePaths)
this.setData({ images })
}
})
},
onRemoveImage(e) {
const index = e.currentTarget.dataset.index
const images = this.data.images
images.splice(index, 1)
this.setData({ images })
},
submitFeedback() {
const { type, content, contact, images } = this.data
if (!content.trim()) {
wx.showToast({ title: '请输入反馈内容', icon: 'none' })
return
}
if (content.trim().length < 10) {
wx.showToast({ title: '反馈内容至少10个字', icon: 'none' })
return
}
this.setData({ loading: true })
api.submitFeedback({
type,
content: content.trim(),
contact: contact.trim(),
images: images.join(',')
}).then(res => {
this.setData({ loading: false })
if (res.code === 200) {
wx.showToast({ title: '提交成功', icon: 'success' })
setTimeout(() => {
wx.navigateBack()
}, 1500)
} else {
wx.showToast({ title: res.message || '提交失败', icon: 'none' })
}
}).catch(() => {
this.setData({ loading: false })
wx.showToast({ title: '提交失败', icon: 'none' })
})
}
})
/**
* @联系作者16768118056
* @描述:(此项目非免费分享)源码百分百可用,搞定毕设不发愁,支持远程调试安装、二次开发、定制、讲解、文档类。
* @访问https://www.notmaker.com/detail/8326a897119d4542896c863a69d7bbe7/gtt20260415查看完整运行演示。
*/