feedback.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. <template>
  2. <view class="container">
  3. <!-- 顶部导航栏 -->
  4. <view class="header">
  5. <view class="back-btn" @click="goBack">
  6. <text class="back-icon">←</text>
  7. </view>
  8. <text class="header-title">意见反馈</text>
  9. <view class="header-right"></view>
  10. </view>
  11. <scroll-view class="scroll-content" scroll-y>
  12. <!-- 反馈类型 -->
  13. <view class="section">
  14. <view class="section-title">
  15. <view class="title-indicator"></view>
  16. <text class="title-text">反馈类型</text>
  17. </view>
  18. <view class="type-buttons">
  19. <view
  20. class="type-btn"
  21. :class="{ active: feedbackType === 'bug' }"
  22. @click="selectType('bug')"
  23. >
  24. <text class="type-btn-text">产品bug</text>
  25. </view>
  26. <view
  27. class="type-btn"
  28. :class="{ active: feedbackType === 'suggestion' }"
  29. @click="selectType('suggestion')"
  30. >
  31. <text class="type-btn-text">功能建议</text>
  32. </view>
  33. <view
  34. class="type-btn"
  35. :class="{ active: feedbackType === 'other' }"
  36. @click="selectType('other')"
  37. >
  38. <text class="type-btn-text">其他</text>
  39. </view>
  40. </view>
  41. </view>
  42. <!-- 详细描述 -->
  43. <view class="section">
  44. <view class="section-title">
  45. <view class="title-indicator"></view>
  46. <text class="title-text">详细描述</text>
  47. </view>
  48. <textarea
  49. class="description-input"
  50. v-model="description"
  51. placeholder="请输入您的问题"
  52. :maxlength="500"
  53. :auto-height="true"
  54. ></textarea>
  55. </view>
  56. <!-- 上传图片 -->
  57. <view class="section">
  58. <view class="section-title">
  59. <view class="title-indicator"></view>
  60. <text class="title-text">上传图片</text>
  61. </view>
  62. <view class="upload-area">
  63. <view class="image-list">
  64. <view
  65. class="image-item"
  66. v-for="(image, index) in imageList"
  67. :key="index"
  68. >
  69. <image class="uploaded-image" :src="image" mode="aspectFill"></image>
  70. <view class="delete-btn" @click="deleteImage(index)">
  71. <text class="delete-icon">×</text>
  72. </view>
  73. </view>
  74. <view
  75. class="upload-btn"
  76. v-if="imageList.length < 3"
  77. @click="chooseImage"
  78. >
  79. <text class="upload-icon">+</text>
  80. </view>
  81. </view>
  82. </view>
  83. </view>
  84. </scroll-view>
  85. <!-- 提交按钮 -->
  86. <view class="submit-section">
  87. <button class="submit-btn" @click="submitFeedback">提交</button>
  88. </view>
  89. </view>
  90. </template>
  91. <script>
  92. import { submitFeedback } from '@/utils/api.js'
  93. export default {
  94. data() {
  95. return {
  96. feedbackType: 'bug', // bug, suggestion, other
  97. description: '',
  98. imageList: [],
  99. isSubmitting: false
  100. }
  101. },
  102. onLoad() {
  103. // 获取用户信息(从本地存储)
  104. const userInfo = uni.getStorageSync('userInfo')
  105. if (!userInfo || !userInfo.id) {
  106. uni.showToast({
  107. title: '请先登录',
  108. icon: 'none'
  109. })
  110. setTimeout(() => {
  111. uni.navigateTo({
  112. url: '/pages/login/login'
  113. })
  114. }, 1500)
  115. }
  116. },
  117. methods: {
  118. goBack() {
  119. uni.navigateBack()
  120. },
  121. selectType(type) {
  122. this.feedbackType = type
  123. },
  124. chooseImage() {
  125. uni.chooseImage({
  126. count: 3 - this.imageList.length,
  127. sizeType: ['compressed'],
  128. sourceType: ['album', 'camera'],
  129. success: (res) => {
  130. // 将临时文件路径添加到列表
  131. // 注意:如果是真实项目,需要先将图片上传到服务器获取URL
  132. this.imageList = this.imageList.concat(res.tempFilePaths)
  133. },
  134. fail: (err) => {
  135. console.error('选择图片失败:', err)
  136. uni.showToast({
  137. title: '选择图片失败',
  138. icon: 'none'
  139. })
  140. }
  141. })
  142. },
  143. deleteImage(index) {
  144. this.imageList.splice(index, 1)
  145. },
  146. async submitFeedback() {
  147. // 获取用户信息
  148. const userInfo = uni.getStorageSync('userInfo')
  149. if (!userInfo || !userInfo.id) {
  150. uni.showToast({
  151. title: '请先登录',
  152. icon: 'none'
  153. })
  154. setTimeout(() => {
  155. uni.navigateTo({
  156. url: '/pages/login/login'
  157. })
  158. }, 1500)
  159. return
  160. }
  161. // 验证描述
  162. if (!this.description.trim()) {
  163. uni.showToast({
  164. title: '请输入详细描述',
  165. icon: 'none'
  166. })
  167. return
  168. }
  169. // 防止重复提交
  170. if (this.isSubmitting) {
  171. return
  172. }
  173. this.isSubmitting = true
  174. uni.showLoading({
  175. title: '提交中...',
  176. mask: true
  177. })
  178. try {
  179. // 准备提交数据
  180. const feedbackData = {
  181. userId: userInfo.id,
  182. type: this.feedbackType,
  183. description: this.description.trim(),
  184. images: this.imageList // 图片列表,暂时使用临时路径
  185. // 注意:在生产环境中,需要先将图片上传到服务器获取URL
  186. // images: uploadedImageUrls
  187. }
  188. // 调用API提交反馈
  189. const res = await submitFeedback(feedbackData)
  190. uni.hideLoading()
  191. this.isSubmitting = false
  192. if (res && res.code === 200) {
  193. uni.showToast({
  194. title: '提交成功',
  195. icon: 'success'
  196. })
  197. // 清空表单
  198. this.description = ''
  199. this.imageList = []
  200. this.feedbackType = 'bug'
  201. // 延迟返回上一页
  202. setTimeout(() => {
  203. uni.navigateBack()
  204. }, 1500)
  205. } else {
  206. uni.showToast({
  207. title: res.message || '提交失败,请重试',
  208. icon: 'none'
  209. })
  210. }
  211. } catch (error) {
  212. uni.hideLoading()
  213. this.isSubmitting = false
  214. console.error('提交反馈失败:', error)
  215. uni.showToast({
  216. title: error.message || '网络错误,请稍后再试',
  217. icon: 'none'
  218. })
  219. }
  220. }
  221. }
  222. }
  223. </script>
  224. <style scoped>
  225. .container {
  226. width: 100%;
  227. height: 100vh;
  228. background-color: #FFFFFF;
  229. display: flex;
  230. flex-direction: column;
  231. padding-top: 30px;
  232. box-sizing: border-box;
  233. }
  234. .header {
  235. display: flex;
  236. align-items: center;
  237. justify-content: space-between;
  238. padding: 20rpx 30rpx;
  239. background-color: #FFFFFF;
  240. border-bottom: 1rpx solid #F0F0F0;
  241. position: relative;
  242. }
  243. .back-btn {
  244. width: 60rpx;
  245. height: 60rpx;
  246. display: flex;
  247. align-items: center;
  248. justify-content: center;
  249. z-index: 10;
  250. }
  251. .back-icon {
  252. font-size: 40rpx;
  253. color: #333333;
  254. font-weight: bold;
  255. }
  256. .header-title {
  257. position: absolute;
  258. left: 50%;
  259. transform: translateX(-50%);
  260. font-size: 36rpx;
  261. font-weight: bold;
  262. color: #333333;
  263. }
  264. .header-right {
  265. width: 60rpx;
  266. }
  267. .scroll-content {
  268. flex: 1;
  269. width: 100%;
  270. padding-bottom: env(safe-area-inset-bottom);
  271. }
  272. .section {
  273. padding: 40rpx 30rpx;
  274. background-color: #FFFFFF;
  275. }
  276. .section-title {
  277. display: flex;
  278. align-items: center;
  279. margin-bottom: 30rpx;
  280. }
  281. .title-indicator {
  282. width: 6rpx;
  283. height: 32rpx;
  284. background-color: #81C784;
  285. border-radius: 3rpx;
  286. margin-right: 15rpx;
  287. }
  288. .title-text {
  289. font-size: 32rpx;
  290. font-weight: bold;
  291. color: #333333;
  292. }
  293. .type-buttons {
  294. display: flex;
  295. gap: 20rpx;
  296. }
  297. .type-btn {
  298. flex: 1;
  299. height: 80rpx;
  300. background-color: #F5F5F5;
  301. border-radius: 40rpx;
  302. display: flex;
  303. align-items: center;
  304. justify-content: center;
  305. border: 2rpx solid transparent;
  306. transition: all 0.3s;
  307. }
  308. .type-btn.active {
  309. background-color: #E8F5E9;
  310. border-color: #81C784;
  311. }
  312. .type-btn-text {
  313. font-size: 28rpx;
  314. color: #999999;
  315. }
  316. .type-btn.active .type-btn-text {
  317. color: #4CAF50;
  318. font-weight: bold;
  319. }
  320. .description-input {
  321. width: 100%;
  322. min-height: 300rpx;
  323. background-color: #F5F5F5;
  324. border-radius: 16rpx;
  325. padding: 30rpx;
  326. font-size: 28rpx;
  327. color: #333333;
  328. line-height: 1.6;
  329. box-sizing: border-box;
  330. }
  331. .description-input::placeholder {
  332. color: #CCCCCC;
  333. }
  334. .upload-area {
  335. width: 100%;
  336. }
  337. .image-list {
  338. display: flex;
  339. flex-wrap: wrap;
  340. gap: 20rpx;
  341. }
  342. .image-item {
  343. position: relative;
  344. width: 200rpx;
  345. height: 200rpx;
  346. border-radius: 12rpx;
  347. overflow: hidden;
  348. }
  349. .uploaded-image {
  350. width: 100%;
  351. height: 100%;
  352. }
  353. .delete-btn {
  354. position: absolute;
  355. top: 0;
  356. right: 0;
  357. width: 50rpx;
  358. height: 50rpx;
  359. background-color: rgba(0, 0, 0, 0.5);
  360. border-radius: 0 0 0 50rpx;
  361. display: flex;
  362. align-items: center;
  363. justify-content: center;
  364. }
  365. .delete-icon {
  366. font-size: 40rpx;
  367. color: #FFFFFF;
  368. line-height: 1;
  369. }
  370. .upload-btn {
  371. width: 200rpx;
  372. height: 200rpx;
  373. border: 2rpx dashed #CCCCCC;
  374. border-radius: 12rpx;
  375. display: flex;
  376. align-items: center;
  377. justify-content: center;
  378. background-color: #FAFAFA;
  379. }
  380. .upload-icon {
  381. font-size: 80rpx;
  382. color: #CCCCCC;
  383. line-height: 1;
  384. }
  385. .submit-section {
  386. padding: 30rpx;
  387. background-color: #FFFFFF;
  388. border-top: 1rpx solid #F0F0F0;
  389. padding-bottom: calc(30rpx + env(safe-area-inset-bottom));
  390. }
  391. .submit-btn {
  392. width: 100%;
  393. height: 88rpx;
  394. background-color: #4FC3F7;
  395. color: #FFFFFF;
  396. font-size: 32rpx;
  397. font-weight: bold;
  398. border: none;
  399. border-radius: 44rpx;
  400. display: flex;
  401. align-items: center;
  402. justify-content: center;
  403. }
  404. .submit-btn::after {
  405. border: none;
  406. }
  407. </style>