feedback.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <template>
  2. <view class="page">
  3. <PageHeader title="意见与反馈" class="PageHeader">
  4. <template slot="center"> </template>
  5. </PageHeader>
  6. <view class="feedback-container">
  7. <!-- 问题描述区域 -->
  8. <view class="description-area">
  9. <view class="title">问题描述</view>
  10. <textarea class="input-area"
  11. v-model="content"
  12. placeholder="请尽可能详细地描述您的反馈或问题"
  13. :maxlength="200"
  14. show-count
  15. ></textarea>
  16. <view class="word-count">{{content.length}}/200</view>
  17. </view>
  18. <!-- 图片上传区域 -->
  19. <view class="upload-area">
  20. <view class="title">上传图片 <text class="subtitle">(最多5张,可选)</text></view>
  21. <view class="tips">* 上传问题截图更好的帮助我们快速定位您反馈的问题</view>
  22. <view class="tips" style="margin-bottom: 20rpx;">* 需要您授权相册权限</view>
  23. <view class="image-list">
  24. <view class="image-item" v-for="(item, index) in imgList" :key="index">
  25. <image class="preview" :src="item" mode="aspectFill"></image>
  26. <view class="delete-btn" @tap="deleteImage(index)">
  27. <text class="fa fa-times"></text>
  28. </view>
  29. </view>
  30. <view class="upload-btn" @tap="upload" v-if="imgList.length < 5">
  31. <text class="fa fa-plus"></text>
  32. </view>
  33. </view>
  34. </view>
  35. <!-- 提交按钮 -->
  36. <view class="submit-btn" @tap="submitFeedback">
  37. 确认提交
  38. </view>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. export default {
  44. data() {
  45. return {
  46. content: '',
  47. imgList: [],
  48. skey: getApp().globalData.skey || ''
  49. }
  50. },
  51. methods: {
  52. // 上传图片
  53. upload() {
  54. if (this.imgList.length >= 5) {
  55. uni.showToast({
  56. title: '最多只能上传5张图片',
  57. icon: 'none'
  58. });
  59. return;
  60. }
  61. let that = this;
  62. uni.chooseImage({
  63. count: 5 - this.imgList.length,
  64. sizeType: ['compressed'],
  65. sourceType: ['album', 'camera'],
  66. success: function(res) {
  67. let tempFilePaths = [];
  68. // #ifdef H5
  69. res.tempFiles.forEach(file => {
  70. tempFilePaths.push(file.path);
  71. });
  72. // #endif
  73. // #ifdef APP-PLUS || MP
  74. tempFilePaths = res.tempFilePaths;
  75. // #endif
  76. for (let i = 0; i < tempFilePaths.length; i++) {
  77. const uploadTask = uni.uploadFile({
  78. url: that.$apiHost + '/Xweb/upload_img?skey=' + that.skey,
  79. filePath: tempFilePaths[i],
  80. name: 'file',
  81. success: function(uploadFileRes) {
  82. let resdata = JSON.parse(uploadFileRes.data);
  83. if (resdata.success == 'yes') {
  84. that.imgList.push(resdata.url);
  85. } else {
  86. uni.showToast({
  87. title: resdata.str || '上传失败',
  88. icon: 'none'
  89. });
  90. }
  91. },
  92. fail: function(err) {
  93. console.error('上传失败:', err);
  94. uni.showToast({
  95. title: '图片上传失败',
  96. icon: 'none'
  97. });
  98. }
  99. });
  100. }
  101. }
  102. });
  103. },
  104. // 删除图片
  105. deleteImage(index) {
  106. this.imgList.splice(index, 1);
  107. },
  108. // 提交反馈
  109. submitFeedback() {
  110. if (!this.content.trim()) {
  111. uni.showToast({
  112. title: '请输入问题描述',
  113. icon: 'none'
  114. });
  115. return;
  116. }
  117. let imgStr = this.imgList.join('|');
  118. uni.request({
  119. url: this.$apiHost + '/Feedback/submit',
  120. method: 'POST',
  121. data: {
  122. uuid: getApp().globalData.uuid,
  123. content: this.content,
  124. images: imgStr
  125. },
  126. header: {
  127. 'Content-Type': 'application/x-www-form-urlencoded',
  128. 'sign': getApp().globalData.headerSign
  129. },
  130. success: (res) => {
  131. if (res.data.success === 'yes') {
  132. uni.showToast({
  133. title: '提交成功',
  134. icon: 'success'
  135. });
  136. setTimeout(() => {
  137. uni.navigateBack();
  138. }, 1500);
  139. } else {
  140. uni.showToast({
  141. title: res.data.str || '提交失败',
  142. icon: 'none'
  143. });
  144. }
  145. },
  146. fail: (err) => {
  147. console.error('提交失败:', err);
  148. uni.showToast({
  149. title: '网络错误,请稍后重试',
  150. icon: 'none'
  151. });
  152. }
  153. });
  154. }
  155. }
  156. }
  157. </script>
  158. <style lang="scss">
  159. // 导入FontAwesome
  160. @import url("https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css");
  161. .page {
  162. min-height: 100vh;
  163. background-color: #f8f8f8;
  164. padding-bottom: env(safe-area-inset-bottom);
  165. }
  166. .feedback-container {
  167. padding: 30rpx;
  168. .description-area {
  169. background: #fff;
  170. border-radius: 16rpx;
  171. padding: 24rpx;
  172. margin-bottom: 30rpx;
  173. position: relative;
  174. .title {
  175. font-size: 32rpx;
  176. color: #333;
  177. margin-bottom: 20rpx;
  178. }
  179. .input-area {
  180. width: 100%;
  181. height: 300rpx;
  182. font-size: 28rpx;
  183. line-height: 1.6;
  184. padding: 20rpx;
  185. background: #f8f8f8;
  186. border-radius: 12rpx;
  187. }
  188. .word-count {
  189. position: absolute;
  190. right: 44rpx;
  191. bottom: 44rpx;
  192. font-size: 24rpx;
  193. color: #999;
  194. }
  195. }
  196. .upload-area {
  197. background: #fff;
  198. border-radius: 16rpx;
  199. padding: 24rpx;
  200. margin-bottom: 30rpx;
  201. .title {
  202. font-size: 32rpx;
  203. color: #333;
  204. margin-bottom: 20rpx;
  205. .subtitle {
  206. font-size: 24rpx;
  207. color: #999;
  208. }
  209. }
  210. .image-list {
  211. display: flex;
  212. flex-wrap: wrap;
  213. gap: 16rpx;
  214. margin-bottom: 20rpx;
  215. .image-item {
  216. width: 200rpx;
  217. height: 200rpx;
  218. position: relative;
  219. .preview {
  220. width: 100%;
  221. height: 100%;
  222. border-radius: 12rpx;
  223. }
  224. .delete-btn {
  225. position: absolute;
  226. top: -16rpx;
  227. right: -16rpx;
  228. width: 40rpx;
  229. height: 40rpx;
  230. background: rgba(0,0,0,0.5);
  231. border-radius: 50%;
  232. display: flex;
  233. align-items: center;
  234. justify-content: center;
  235. .fa {
  236. color: #fff;
  237. font-size: 24rpx;
  238. }
  239. }
  240. }
  241. .upload-btn {
  242. width: 200rpx;
  243. height: 200rpx;
  244. background: #f8f8f8;
  245. border-radius: 12rpx;
  246. display: flex;
  247. align-items: center;
  248. justify-content: center;
  249. .fa {
  250. font-size: 48rpx;
  251. color: #999;
  252. }
  253. }
  254. }
  255. .tips {
  256. font-size: 24rpx;
  257. color: #999;
  258. line-height: 1.6;
  259. }
  260. }
  261. .submit-btn {
  262. width: 100%;
  263. height: 88rpx;
  264. background: #000;
  265. border-radius: 44rpx;
  266. color: #fff;
  267. font-size: 32rpx;
  268. display: flex;
  269. align-items: center;
  270. justify-content: center;
  271. margin-top: 60rpx;
  272. &:active {
  273. opacity: 0.9;
  274. }
  275. }
  276. }
  277. </style>