index.vue
8.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
<!--
* @Date: 2022-09-19 14:11:06
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-07-07 16:48:19
* @FilePath: /jgdl/src/pages/feedBack/index.vue
* @Description: 意见反馈页面
-->
<template>
<view class="feedback-page">
<view class="content">
<!-- 提示文字 -->
<view class="tip-text">
感谢您的宝贵意见,我们将不断完善产品和服务
</view>
<!-- 反馈分类 -->
<view class="category-section">
<view class="category-grid">
<view
v-for="category in categories"
:key="category.id"
class="category-item"
:class="{ active: selectedCategory === category.id }"
@click="selectCategory(category.id)"
>
<view class="category-icon" :class="{ active: selectedCategory === category.id }">
<text class="icon-text">{{ category.icon }}</text>
</view>
<text class="category-name">{{ category.name }}</text>
</view>
</view>
</view>
<!-- 反馈内容 -->
<view class="feedback-section">
<textarea
v-model="feedbackText"
placeholder="请详细描述您遇到的问题或建议..."
class="feedback-textarea"
maxlength="200"
/>
<view class="char-count">
{{ feedbackText.length }}/200
</view>
</view>
<!-- 图片上传 -->
<view class="image-section">
<view class="section-label">上传图片(选填)</view>
<view class="image-upload-grid">
<!-- 已上传的图片 -->
<view
v-for="(image, index) in uploadedImages"
:key="index"
class="image-item"
>
<view class="image-preview" @click="previewImage(image)">
<image :src="image" class="preview-image" mode="aspectFill" />
<view class="delete-btn" @click.stop="deleteImage(index)">
<Close class="delete-icon" />
</view>
</view>
</view>
<!-- 上传按钮 -->
<view
v-if="uploadedImages.length < 3"
class="upload-button"
@click="triggerUpload"
>
<Plus class="upload-icon" />
</view>
</view>
<view class="upload-tip">最多上传3张</view>
</view>
<!-- 联系方式 -->
<view class="contact-section">
<view class="section-label">联系方式(选填)</view>
<nut-input
v-model="contactInfo"
placeholder="请留下您的手机号或微信号"
/>
</view>
<!-- 提交按钮 -->
<view class="submit-section">
<button
class="submit-btn"
:class="{ disabled: !canSubmit }"
:disabled="!canSubmit"
@click="handleSubmit"
>
提交反馈
</button>
</view>
</view>
<!-- 图片预览组件 -->
<nut-image-preview
v-model:show="previewVisible"
:images="previewImages"
:init-no="previewIndex"
@close="closePreview"
/>
<!-- 成功提示弹窗 -->
<nut-overlay v-model:visible="showSuccessModal" @click="closeSuccessModal">
<view class="success-modal">
<view class="success-content">
<view class="success-icon">
<text class="check-icon">✓</text>
</view>
<view class="success-title">反馈成功</view>
<view class="success-desc">感谢您的反馈</view>
</view>
</view>
</nut-overlay>
</view>
</template>
<script setup>
import { ref, computed } from 'vue'
import Taro from '@tarojs/taro'
import { Plus, Close } from '@nutui/icons-vue-taro'
import { Toast } from '@nutui/nutui-taro'
import BASE_URL from '@/utils/config'
import './index.less'
// 反馈分类
const categories = ref([
{ id: 'feature', name: '功能建议', icon: '💡' },
{ id: 'ui', name: '界面设计', icon: '✖️' },
{ id: 'vehicle', name: '车辆信息', icon: '🚲' },
{ id: 'other', name: '其他问题', icon: '❓' }
])
// 表单数据
const selectedCategory = ref(null)
const feedbackText = ref('')
const contactInfo = ref('')
const uploadedImages = ref([])
// 图片预览相关
const previewVisible = ref(false)
const previewImages = ref([])
const previewIndex = ref(0)
// 成功弹窗
const showSuccessModal = ref(false)
// 计算属性:是否可以提交
const canSubmit = computed(() => {
return selectedCategory.value && feedbackText.value.trim()
})
/**
* 选择反馈分类
*/
const selectCategory = (categoryId) => {
selectedCategory.value = categoryId
}
/**
* 触发图片上传
*/
const triggerUpload = () => {
if (uploadedImages.value.length >= 3) {
Toast.fail('最多只能上传3张图片')
return
}
Taro.chooseImage({
count: 1,
sizeType: ['compressed'],
sourceType: ['album', 'camera'],
success: function (res) {
const tempFilePath = res.tempFilePaths[0]
uploadImage(tempFilePath)
},
fail: function () {
Toast.fail('选择图片失败')
}
})
}
/**
* 上传图片到服务器
* @param {String} filePath - 图片文件路径
*/
const uploadImage = (filePath) => {
// 显示上传中提示
Taro.showLoading({
title: '上传中',
mask: true
})
// 使用wx.uploadFile进行真实上传
wx.uploadFile({
url: BASE_URL + '/admin/?m=srv&a=upload',
filePath,
name: 'file',
header: {
'content-type': 'multipart/form-data',
},
success: function (res) {
let upload_data = JSON.parse(res.data);
Taro.hideLoading({
success: () => {
if (res.statusCode === 200) {
// 添加到已上传图片列表
uploadedImages.value.push(upload_data.data.src);
Taro.showToast({
title: '上传成功',
icon: 'success'
})
} else {
Taro.showToast({
icon: 'error',
title: '服务器错误,稍后重试!',
mask: true
})
}
}
});
},
fail: function (res) {
Taro.hideLoading({
success: () => {
Taro.showToast({
icon: 'error',
title: '上传失败,稍后重试!',
mask: true
})
}
})
}
});
}
/**
* 预览图片
*/
const previewImage = (imageUrl) => {
previewImages.value = [{ src: imageUrl }]
previewIndex.value = 0
previewVisible.value = true
}
/**
* 删除图片
*/
const deleteImage = (index) => {
uploadedImages.value.splice(index, 1)
Taro.showToast({
title: '删除成功',
icon: 'success',
duration: 2000
})
}
/**
* 关闭图片预览
*/
const closePreview = () => {
previewVisible.value = false
}
/**
* 提交反馈
*/
const handleSubmit = () => {
if (!canSubmit.value) return
Taro.showLoading({ title: '提交中...', mask: true })
// 构建提交数据
const submitData = {
category: selectedCategory.value,
content: feedbackText.value.trim(),
contact: contactInfo.value.trim(),
images: uploadedImages.value
}
// TODO: 调用实际的API接口提交数据
// submitFeedback(submitData)
// 模拟提交
setTimeout(() => {
Taro.hideLoading()
showSuccessModal.value = true
// 2秒后自动关闭并重置表单
setTimeout(() => {
closeSuccessModal()
}, 2000)
}, 1500)
}
/**
* 关闭成功弹窗并重置表单
*/
const closeSuccessModal = () => {
showSuccessModal.value = false
// 重置表单
selectedCategory.value = null
feedbackText.value = ''
contactInfo.value = ''
uploadedImages.value = []
}
</script>
<script>
export default {
name: 'FeedbackPage'
}
</script>