index.vue
8.35 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
<template>
<view class="min-h-screen bg-white flex flex-col">
<view class="flex-1 px-4 py-6 overflow-auto">
<!-- Feedback Section -->
<view class="mb-6">
<view class="text-lg font-medium mb-2">您的反馈</view>
<view class="bg-white rounded-lg border border-gray-200 p-4">
<textarea
v-model="feedbackText"
class="w-full text-gray-600 focus:outline-none resize-none"
placeholder="请描述您遇到的问题或建议..."
:rows="4"
/>
</view>
</view>
<!-- Upload Screenshot Section -->
<view class="mb-6">
<view class="text-lg font-medium mb-2">上传截图 (可选)</view>
<!-- 已上传图片显示 -->
<view class="flex flex-wrap gap-2 mb-4">
<view
v-for="(item, index) in screenshots"
:key="index"
class="relative"
>
<image
:src="item.url"
class="w-24 h-24 rounded-lg object-cover"
mode="widthFix"
@tap="() => previewImage(index)"
/>
<view
@click="() => deleteImage(index)"
class="absolute -top-2 -right-2 w-4 h-4 bg-red-500 rounded-full flex items-center justify-center"
>
<view class="text-white text-xs">×</view>
</view>
</view>
<!-- 上传按钮 -->
<view
v-if="screenshots.length < maxImages"
class="w-24 h-24 border border-dashed border-gray-300 rounded-lg flex flex-col items-center justify-center"
@click="chooseImage"
>
<view class="text-gray-400 mb-2">
<Photograph size="24" />
</view>
<view class="text-center text-gray-400 text-xs">添加图片</view>
</view>
</view>
<!-- 提示信息 -->
<view class="text-xs text-gray-500 mt-2">
<view>• 图片大小不能超过10MB</view>
<view>• 最多只能上传3张图片</view>
<view>• 当前已上传 {{ screenshots.length }}/{{ maxImages }} 张</view>
</view>
</view>
<!-- Name Section -->
<view class="mb-6">
<view class="text-lg font-medium mb-2">您的姓名</view>
<view class="bg-white rounded-lg border border-gray-200 p-4">
<input
type="text"
v-model="name"
class="w-full text-gray-600 focus:outline-none"
placeholder="请输入您的姓名"
:cursorSpacing="100"
/>
</view>
</view>
<!-- Contact Section -->
<view class="mb-10">
<view class="text-lg font-medium mb-2">联系方式</view>
<view class="bg-white rounded-lg border border-gray-200 p-4">
<input
type="text"
v-model="contact"
class="w-full text-gray-600 focus:outline-none"
placeholder="请输入您的手机号或微信号"
:cursorSpacing="100"
/>
</view>
</view>
<!-- Submit Button -->
<view
@click="submitFeedback"
class="w-full py-2 bg-blue-500 text-white text-lg font-medium rounded-lg flex items-center justify-center"
>
提交反馈
</view>
</view>
<!-- Image Preview -->
<nut-image-preview
v-model:show="previewVisible"
:images="previewImages"
:init-no="0"
@close="closePreview"
/>
</view>
</template>
<script setup>
import { ref } from 'vue';
import Taro from '@tarojs/taro';
import { Photograph } from '@nutui/icons-vue-taro';
import BASE_URL from '@/utils/config';
import { submitFeedbackAPI } from '@/api/feedback';
const feedbackText = ref('');
const screenshots = ref([]);
const name = ref('');
const contact = ref('');
const previewVisible = ref(false);
const previewImages = ref([]);
const maxImages = 3;
/**
* 显示提示信息
*/
const showToast = (message, type = 'success') => {
Taro.showToast({
title: message,
icon: type,
duration: 2000
});
};
/**
* 选择图片
*/
const chooseImage = () => {
if (screenshots.value.length >= maxImages) {
showToast(`最多只能上传${maxImages}张图片`, 'error');
return;
}
const remainingCount = maxImages - screenshots.value.length;
Taro.chooseImage({
count: remainingCount,
sizeType: ['compressed'],
sourceType: ['album', 'camera'],
success: function (res) {
res.tempFilePaths.forEach(tempFilePath => {
// 检查文件大小(10MB = 10 * 1024 * 1024 bytes)
Taro.getFileInfo({
filePath: tempFilePath,
success: function (fileInfo) {
if (fileInfo.size > 10 * 1024 * 1024) {
showToast('图片大小不能超过10MB', 'error');
return;
}
uploadImage(tempFilePath);
},
fail: function () {
// 如果获取文件信息失败,直接上传
uploadImage(tempFilePath);
}
});
});
},
fail: function () {
showToast('选择图片失败', 'error');
}
});
};
/**
* 上传图片到服务器
*/
const uploadImage = (filePath) => {
// 显示上传中提示
Taro.showLoading({
title: '上传中',
mask: true
});
wx.uploadFile({
url: BASE_URL + '/admin/?m=srv&a=upload&image_audit=1',
filePath,
name: 'file',
header: {
'content-type': 'multipart/form-data',
},
success: function (res) {
let upload_data = JSON.parse(res.data);
Taro.hideLoading({
success: () => {
if (upload_data.code === 0 && upload_data.data) {
screenshots.value.push({
url: upload_data.data.src,
localPath: filePath
});
showToast('上传成功', 'success');
} else {
// 检查是否为审核不通过
if (upload_data.code === 0 && !upload_data.data && upload_data.msg && upload_data.msg.includes('审核不通过')) {
Taro.showModal({
title: '温馨提示',
content: '您上传的内容未通过审核',
showCancel: false
}).then(res => {
if (res.confirm) {
// 点击了确认按钮
}
});
} else {
showToast('服务器错误,稍后重试!', 'error');
}
}
},
});
},
fail: function (res) {
Taro.hideLoading({
success: () => {
showToast('上传失败,稍后重试!', 'error');
}
});
}
});
};
/**
* 预览图片
*/
const previewImage = (index) => {
previewImages.value = screenshots.value.map(item => ({ src: item.url }));
previewVisible.value = true;
};
/**
* 关闭预览
*/
const closePreview = () => {
previewVisible.value = false;
};
/**
* 删除图片
*/
const deleteImage = (index) => {
screenshots.value.splice(index, 1);
showToast('图片已删除', 'success');
};
/**
* 提交反馈
*/
const submitFeedback = async () => {
if (!feedbackText.value) {
showToast('请描述您遇到的问题或建议', 'none');
return;
}
if (!name.value) {
showToast('请输入您的姓名', 'none');
return;
}
if (!contact.value) {
showToast('请输入您的手机号或微信号', 'none');
return;
}
try {
// 显示提交中提示
Taro.showLoading({
title: '提交中...',
mask: true
});
// 准备提交数据
const submitData = {
note: feedbackText.value,
name: name.value,
contact: contact.value,
images: screenshots.value.map(item => item.url)
};
// 调用提交API
const response = await submitFeedbackAPI(submitData);
Taro.hideLoading();
if (response.code === 1) {
showToast('提交成功');
// 提交成功后清空表单
feedbackText.value = '';
screenshots.value = [];
name.value = '';
contact.value = '';
// 延迟返回上一页
setTimeout(() => {
Taro.navigateBack();
}, 1500);
} else {
showToast(response.msg || '提交失败,请重试', 'none');
}
} catch (error) {
Taro.hideLoading();
console.error('提交反馈失败:', error);
showToast('提交失败,请重试', 'none');
}
};
</script>
<style lang="less">
// 你可以在这里添加自定义样式
</style>