feedback.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <view class="page">
  3. <view class="feedback-title">
  4. <text>问题和意见</text>
  5. <text class="feedback-quick" @tap="chooseMsg">快速键入</text>
  6. </view>
  7. <view class="feedback-body"><textarea placeholder="请详细描述你的问题和意见..." v-model="sendDate.content" class="feedback-textare"></textarea></view>
  8. <view class="feedback-title"><text>图片(选填,提供问题截图,总大小10M以下)</text></view>
  9. <view class="feedback-body feedback-uploader">
  10. <view class="uni-uploader">
  11. <view class="uni-uploader-head">
  12. <view class="uni-uploader-title">点击预览图片</view>
  13. <view class="uni-uploader-info">{{ imageList.length }}/5</view>
  14. </view>
  15. <view class="uni-uploader-body">
  16. <view class="uni-uploader__files">
  17. <block v-for="(image, index) in imageList" :key="index">
  18. <view class="uni-uploader__file" style="position: relative;">
  19. <image class="uni-uploader__img" :src="image" @tap="previewImage(index)"></image>
  20. <view class="close-view" @click="close(index)">x</view>
  21. </view>
  22. </block>
  23. <view class="uni-uploader__input-box" v-show="imageList.length < 5"><view class="uni-uploader__input" @tap="chooseImg"></view></view>
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. <view class="feedback-title"><text>QQ/邮箱</text></view>
  29. <view class="feedback-body"><input class="feedback-input" v-model="sendDate.contact" placeholder="(选填,方便我们联系你 )" /></view>
  30. <view class="feedback-title feedback-star-view">
  31. <text>应用评分</text>
  32. <view class="feedback-star-view"><uni-rate v-model="sendDate.score" color="#bbb"></uni-rate></view>
  33. </view>
  34. <button type="default" class="feedback-submit" @tap="send">提交</button>
  35. <view class="feedback-title"><text>用户反馈的结果可在app打包后于DCloud开发者中心查看</text></view>
  36. </view>
  37. </template>
  38. <script>
  39. import uniRate from '@/components/uni-rate/uni-rate.vue';
  40. export default {
  41. components: { uniRate },
  42. data() {
  43. return {
  44. msgContents: ['界面显示错乱', '启动缓慢,卡出翔了', 'UI无法直视,丑哭了', '偶发性崩溃'],
  45. stars: [1, 2, 3, 4, 5],
  46. imageList: [],
  47. sendDate: {
  48. score: 0,
  49. content: '',
  50. contact: ''
  51. }
  52. };
  53. },
  54. onLoad() {
  55. this.deviceInfo = {
  56. // appid: plus.runtime.appid,
  57. appid: '__UNI__5D0B0CA',
  58. imei: plus.device.imei, //设备标识
  59. p: plus.os.name === 'Android' ? 'a' : 'i', //平台类型,i表示iOS平台,a表示Android平台。
  60. md: plus.device.model, //设备型号
  61. app_version: plus.runtime.version,
  62. plus_version: plus.runtime.innerVersion, //基座版本号
  63. os: plus.os.version,
  64. net: '' + plus.networkinfo.getCurrentType()
  65. };
  66. this.sendDate = Object.assign(this.deviceInfo, this.sendDate);
  67. },
  68. methods: {
  69. /**
  70. * 关闭图片
  71. * @param {Object} e
  72. */
  73. close(e) {
  74. this.imageList.splice(e, 1);
  75. },
  76. /**
  77. * 快速输入
  78. */
  79. chooseMsg() {
  80. uni.showActionSheet({
  81. itemList: this.msgContents,
  82. success: res => {
  83. this.sendDate.content = this.msgContents[res.tapIndex];
  84. }
  85. });
  86. },
  87. /**
  88. * 选择图片
  89. */
  90. chooseImg() {
  91. //选择图片
  92. uni.chooseImage({
  93. sourceType: ['camera', 'album'],
  94. sizeType: 'compressed',
  95. count: 5 - this.imageList.length,
  96. success: res => {
  97. this.imageList = this.imageList.concat(res.tempFilePaths);
  98. }
  99. });
  100. },
  101. /**
  102. * 评分
  103. * @param {Object} e
  104. */
  105. chooseStar(e) {
  106. //点击评星
  107. this.sendDate.score = e;
  108. },
  109. /**
  110. * 预览图片
  111. * @param {Object} index
  112. */
  113. previewImage(index) {
  114. uni.previewImage({
  115. urls: this.imageList,
  116. current: this.imageList[index]
  117. });
  118. },
  119. /**
  120. * 提交
  121. */
  122. send() {
  123. //发送反馈
  124. if (this.sendDate.content.length === 0) {
  125. uni.showModal({
  126. content: '请输入问题和意见',
  127. showCancel: false
  128. });
  129. return;
  130. }
  131. uni.showLoading({
  132. title: '上传中...'
  133. });
  134. let imgs = this.imageList.map((value, index) => {
  135. return {
  136. name: 'images' + index,
  137. uri: value
  138. };
  139. });
  140. // TODO 服务端限制上传文件一次最大不超过 2M, 图片一次最多不超过5张
  141. this.request(this.sendDate, imgs)
  142. .then(res => {
  143. if (typeof res.data === 'string') {
  144. res.data = JSON.parse(res.data);
  145. }
  146. if (res.statusCode === 200 && res.data && res.data.ret === 0) {
  147. uni.showModal({
  148. content: '反馈成功',
  149. showCancel: false
  150. });
  151. this.imageList = [];
  152. this.sendDate = Object.assign(this.deviceInfo, {
  153. score: 0,
  154. content: '',
  155. contact: ''
  156. });
  157. } else if (res.statusCode !== 200) {
  158. uni.showModal({
  159. content: '反馈失败,错误码为:' + res.statusCode,
  160. showCancel: false
  161. });
  162. } else {
  163. uni.showModal({
  164. content: '反馈失败',
  165. showCancel: false
  166. });
  167. }
  168. })
  169. .catch(err => {
  170. console.log(err);
  171. });
  172. },
  173. /**
  174. * 发送请求到后台
  175. */
  176. request(sendDate, imgs) {
  177. return new Promise((resolve, reject) => {
  178. let fromData = {
  179. url: 'https://service.dcloud.net.cn/feedback',
  180. success: res => {
  181. resolve(res);
  182. },
  183. fail: res => {
  184. reject(res);
  185. },
  186. complete() {
  187. uni.hideLoading();
  188. }
  189. };
  190. if (imgs.length > 0) {
  191. fromData.files = imgs;
  192. fromData.formData = sendDate;
  193. uni.uploadFile(fromData);
  194. } else {
  195. fromData.data = sendDate;
  196. fromData.method = 'POST';
  197. uni.request(fromData);
  198. }
  199. });
  200. }
  201. }
  202. };
  203. </script>
  204. <style>
  205. page {
  206. background-color: #efeff4;
  207. }
  208. .input-view {
  209. font-size: 28rpx;
  210. }
  211. .close-view {
  212. text-align: center;
  213. line-height: 14px;
  214. height: 16px;
  215. width: 16px;
  216. border-radius: 50%;
  217. background: #ff5053;
  218. color: #ffffff;
  219. position: absolute;
  220. top: -6px;
  221. right: -4px;
  222. font-size: 12px;
  223. }
  224. </style>