feedback.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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"
  8. class="feedback-textare"></textarea></view>
  9. <view class="feedback-title"><text>图片(选填,提供问题截图,总大小10M以下)</text></view>
  10. <view class="feedback-body feedback-uploader">
  11. <view class="uni-uploader">
  12. <view class="uni-uploader-head">
  13. <view class="uni-uploader-title">点击预览图片</view>
  14. <view class="uni-uploader-info">{{ imageList.length }}/5</view>
  15. </view>
  16. <view class="uni-uploader-body">
  17. <view class="uni-uploader__files">
  18. <block v-for="(image, index) in imageList" :key="index">
  19. <view class="uni-uploader__file" style="position: relative;">
  20. <image class="uni-uploader__img" :src="image" @tap="previewImage(index)"></image>
  21. <view class="close-view" @click="close(index)">x</view>
  22. </view>
  23. </block>
  24. <view class="uni-uploader__input-box" v-show="imageList.length < 5">
  25. <view class="uni-uploader__input" @tap="chooseImg"></view>
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="feedback-title"><text>联系方式(手机或者邮箱)</text></view>
  32. <view class="feedback-body"><input class="feedback-input" v-model="sendDate.contact"
  33. placeholder="(选填,方便我们联系你 )" /></view>
  34. <view class="feedback-title feedback-star-view">
  35. <text>应用评分</text>
  36. <view class="feedback-star-view">
  37. <uni-rate v-model="sendDate.score" color="#bbb"></uni-rate>
  38. </view>
  39. </view>
  40. <button type="default" class="feedback-submit" @tap="send">提交</button>
  41. </view>
  42. </template>
  43. <script>
  44. export default {
  45. components: {},
  46. data() {
  47. return {
  48. msgContents: ['界面显示错乱,不兼容', '启动缓慢,运行卡顿', 'UI不好看', '偶发性崩溃','等待loading时间过长'],
  49. stars: [1, 2, 3, 4, 5],
  50. imageList: [],
  51. sendDate: {
  52. score: 0,
  53. content: '',
  54. contact: ''
  55. }
  56. };
  57. },
  58. onLoad() {
  59. this.deviceInfo = {
  60. // appid: plus.runtime.appid,
  61. appid: '__UNI__EEA6732',
  62. imei: plus.device.imei, //设备标识
  63. p: plus.os.name === 'Android' ? 'a' : 'i', //平台类型,i表示iOS平台,a表示Android平台。
  64. md: plus.device.model, //设备型号
  65. app_version: plus.runtime.version,
  66. plus_version: plus.runtime.innerVersion, //基座版本号
  67. os: plus.os.version,
  68. net: '' + plus.networkinfo.getCurrentType()
  69. };
  70. this.sendDate = Object.assign(this.deviceInfo, this.sendDate);
  71. },
  72. methods: {
  73. /**
  74. * 关闭图片
  75. * @param {Object} e
  76. */
  77. close(e) {
  78. this.imageList.splice(e, 1);
  79. },
  80. /**
  81. * 快速输入
  82. */
  83. chooseMsg() {
  84. uni.showActionSheet({
  85. itemList: this.msgContents,
  86. success: res => {
  87. this.sendDate.content = this.msgContents[res.tapIndex];
  88. }
  89. });
  90. },
  91. /**
  92. * 选择图片
  93. */
  94. chooseImg() {
  95. //选择图片
  96. uni.chooseImage({
  97. sourceType: ['camera', 'album'],
  98. sizeType: 'compressed',
  99. count: 5 - this.imageList.length,
  100. success: res => {
  101. this.imageList = this.imageList.concat(res.tempFilePaths);
  102. }
  103. });
  104. },
  105. /**
  106. * 评分
  107. * @param {Object} e
  108. */
  109. chooseStar(e) {
  110. //点击评星
  111. this.sendDate.score = e;
  112. },
  113. /**
  114. * 预览图片
  115. * @param {Object} index
  116. */
  117. previewImage(index) {
  118. uni.previewImage({
  119. urls: this.imageList,
  120. current: this.imageList[index]
  121. });
  122. },
  123. /**
  124. * 提交
  125. */
  126. send() {
  127. //发送反馈
  128. if (this.sendDate.content.length === 0) {
  129. uni.showModal({
  130. content: '请输入问题和意见',
  131. showCancel: false
  132. });
  133. return;
  134. }
  135. uni.showLoading({
  136. title: '上传中...'
  137. });
  138. let imgs = this.imageList.map((value, index) => {
  139. return {
  140. name: 'images' + index,
  141. uri: value
  142. };
  143. });
  144. // TODO 服务端限制上传文件一次最大不超过 2M, 图片一次最多不超过5张
  145. this.request(this.sendDate, imgs)
  146. .then(res => {
  147. if (typeof res.data === 'string') {
  148. res.data = JSON.parse(res.data);
  149. }
  150. if (res.statusCode === 200 && res.data && res.data.ret === 0) {
  151. uni.showModal({
  152. content: '反馈成功',
  153. showCancel: false
  154. });
  155. setTimeout(() => {
  156. uni.navigateBack({
  157. })
  158. }, 1000)
  159. this.imageList = [];
  160. this.sendDate = Object.assign(this.deviceInfo, {
  161. score: 0,
  162. content: '',
  163. contact: ''
  164. });
  165. } else if (res.statusCode !== 200) {
  166. uni.showModal({
  167. content: '反馈失败,错误码为:' + res.statusCode,
  168. showCancel: false
  169. });
  170. } else {
  171. uni.showModal({
  172. content: '反馈失败',
  173. showCancel: false
  174. });
  175. }
  176. })
  177. .catch(err => {
  178. console.log(err);
  179. });
  180. },
  181. /**
  182. * 发送请求到后台
  183. */
  184. request(sendDate, imgs) {
  185. return new Promise((resolve, reject) => {
  186. let fromData = {
  187. url: 'https://service.dcloud.net.cn/feedback',
  188. success: res => {
  189. resolve(res);
  190. },
  191. fail: res => {
  192. reject(res);
  193. },
  194. complete() {
  195. uni.hideLoading();
  196. }
  197. };
  198. if (imgs.length > 0) {
  199. fromData.files = imgs;
  200. fromData.formData = sendDate;
  201. uni.uploadFile(fromData);
  202. } else {
  203. fromData.data = sendDate;
  204. fromData.method = 'POST';
  205. uni.request(fromData);
  206. }
  207. });
  208. }
  209. }
  210. };
  211. </script>
  212. <style scoped>
  213. page {
  214. background-color: #efeff4;
  215. }
  216. .input-view {
  217. font-size: 28rpx;
  218. }
  219. /* 上传 */
  220. .uni-uploader {
  221. flex: 1;
  222. flex-direction: column;
  223. }
  224. .uni-uploader-head {
  225. display: flex;
  226. flex-direction: row;
  227. justify-content: space-between;
  228. }
  229. .uni-uploader-info {
  230. color: #B2B2B2;
  231. }
  232. .uni-uploader-body {
  233. margin-top: 16rpx;
  234. }
  235. .uni-uploader__files {
  236. display: flex;
  237. flex-direction: row;
  238. flex-wrap: wrap;
  239. }
  240. .uni-uploader__file {
  241. margin: 10rpx;
  242. width: 210rpx;
  243. height: 210rpx;
  244. }
  245. .uni-uploader__img {
  246. display: block;
  247. width: 210rpx;
  248. height: 210rpx;
  249. }
  250. .uni-uploader__input-box {
  251. position: relative;
  252. margin: 10rpx;
  253. width: 208rpx;
  254. height: 208rpx;
  255. border: 2rpx solid #D9D9D9;
  256. }
  257. .uni-uploader__input-box:before,
  258. .uni-uploader__input-box:after {
  259. content: " ";
  260. position: absolute;
  261. top: 50%;
  262. left: 50%;
  263. -webkit-transform: translate(-50%, -50%);
  264. transform: translate(-50%, -50%);
  265. background-color: #D9D9D9;
  266. }
  267. .uni-uploader__input-box:before {
  268. width: 4rpx;
  269. height: 79rpx;
  270. }
  271. .uni-uploader__input-box:after {
  272. width: 79rpx;
  273. height: 4rpx;
  274. }
  275. .uni-uploader__input-box:active {
  276. border-color: #999999;
  277. }
  278. .uni-uploader__input-box:active:before,
  279. .uni-uploader__input-box:active:after {
  280. background-color: #999999;
  281. }
  282. .uni-uploader__input {
  283. position: absolute;
  284. z-index: 1;
  285. top: 0;
  286. left: 0;
  287. width: 100%;
  288. height: 100%;
  289. opacity: 0;
  290. }
  291. /*问题反馈*/
  292. .feedback-title {
  293. display: flex;
  294. flex-direction: row;
  295. justify-content: space-between;
  296. align-items: center;
  297. padding: 20rpx;
  298. color: #8f8f94;
  299. font-size: 28rpx;
  300. }
  301. .feedback-star-view.feedback-title {
  302. justify-content: flex-start;
  303. margin: 0;
  304. }
  305. .feedback-quick {
  306. position: relative;
  307. padding-right: 40rpx;
  308. }
  309. .feedback-quick:after {
  310. font-family: uniicons;
  311. font-size: 40rpx;
  312. content: '\e581';
  313. position: absolute;
  314. right: 0;
  315. top: 50%;
  316. color: #bbb;
  317. -webkit-transform: translateY(-50%);
  318. transform: translateY(-50%);
  319. }
  320. .feedback-body {
  321. background: #fff;
  322. }
  323. .feedback-textare {
  324. height: 200rpx;
  325. font-size: 34rpx;
  326. line-height: 50rpx;
  327. width: 100%;
  328. box-sizing: border-box;
  329. padding: 20rpx 30rpx 0;
  330. }
  331. .feedback-input {
  332. font-size: 34rpx;
  333. height: 50rpx;
  334. min-height: 50rpx;
  335. padding: 15rpx 20rpx;
  336. line-height: 50rpx;
  337. }
  338. .feedback-uploader {
  339. padding: 22rpx 20rpx;
  340. }
  341. .feedback-star {
  342. font-family: uniicons;
  343. font-size: 40rpx;
  344. margin-left: 6rpx;
  345. }
  346. .feedback-star-view {
  347. margin-left: 20rpx;
  348. }
  349. .feedback-star:after {
  350. content: '\e408';
  351. }
  352. .feedback-star.active {
  353. color: #FFB400;
  354. }
  355. .feedback-star.active:after {
  356. content: '\e438';
  357. }
  358. .feedback-submit {
  359. background: #007AFF;
  360. color: #FFFFFF;
  361. margin: 20rpx;
  362. }
  363. .close-view {
  364. text-align: center;
  365. line-height: 14px;
  366. height: 16px;
  367. width: 16px;
  368. border-radius: 50%;
  369. background: #ff5053;
  370. color: #ffffff;
  371. position: absolute;
  372. top: -6px;
  373. right: -4px;
  374. font-size: 12px;
  375. }
  376. </style>