feedback.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. <template>
  2. <view class="acct-pwd-page">
  3. <view class="acct-pwd-nav" :style="{ paddingTop: statusBar + 'px' }">
  4. <view class="acct-pwd-nav-row">
  5. <view class="acct-pwd-back" @tap="goBack">
  6. <text class="acct-pwd-back-icon">←</text>
  7. </view>
  8. <text class="acct-pwd-nav-title">{{ copy.pageTitle }}</text>
  9. <view class="fb-nav-link" @tap="openMyList">
  10. <text class="fb-nav-link-txt">{{ copy.myList }}</text>
  11. </view>
  12. </view>
  13. </view>
  14. <scroll-view
  15. scroll-y
  16. class="acct-pwd-scroll"
  17. :style="{ height: scrollHeight + 'px' }"
  18. >
  19. <view class="acct-pwd-body" :style="{ paddingBottom: footerPad + 'px' }">
  20. <view class="acct-pwd-hero">
  21. <view class="acct-pwd-hero-icon-wrap">
  22. <text class="acct-pwd-hero-icon">💬</text>
  23. </view>
  24. <text class="acct-pwd-hero-title">{{ copy.heroTitle }}</text>
  25. <text class="acct-pwd-hero-desc">{{ copy.heroDesc }}</text>
  26. </view>
  27. <view class="fb-section-row">
  28. <text class="cp-section">{{ copy.sectionContent }}</text>
  29. <text class="fb-quick" @tap="chooseQuickText">{{ copy.quickInput }}</text>
  30. </view>
  31. <view class="acct-pwd-card">
  32. <textarea
  33. v-model="form.content"
  34. class="cp-textarea"
  35. maxlength="-1"
  36. :placeholder="copy.contentPlaceholder"
  37. placeholder-class="cp-textarea-placeholder"
  38. />
  39. </view>
  40. <text class="cp-section">{{ copy.sectionScreenshots }}</text>
  41. <view class="acct-pwd-card">
  42. <view class="cp-img-head">
  43. <text class="cp-img-head-label">{{ copy.previewImages }}</text>
  44. <text class="cp-img-head-count">{{ form.images.length }}/{{ maxImages }}</text>
  45. </view>
  46. <view class="cp-img-grid">
  47. <view
  48. v-for="(image, index) in form.images"
  49. :key="index"
  50. class="cp-img-cell"
  51. >
  52. <image
  53. class="cp-img-thumb"
  54. :src="thumb(image)"
  55. mode="aspectFill"
  56. @tap="previewImages(index)"
  57. />
  58. <view class="cp-img-remove" @tap.stop="removeImage(index)">
  59. <text class="cp-img-remove-icon">×</text>
  60. </view>
  61. </view>
  62. <view
  63. v-if="form.images.length < maxImages"
  64. class="cp-img-cell cp-img-cell--add"
  65. @tap="pickImages"
  66. >
  67. <text class="cp-img-add-icon">+</text>
  68. <text class="cp-img-add-txt">{{ copy.addImage }}</text>
  69. </view>
  70. </view>
  71. </view>
  72. <text class="cp-section">{{ copy.sectionContact }}</text>
  73. <view class="acct-pwd-card fb-contact-card">
  74. <input
  75. v-model="form.contact"
  76. class="fb-contact-input"
  77. :placeholder="copy.contactPlaceholder"
  78. placeholder-class="cp-textarea-placeholder"
  79. />
  80. </view>
  81. <view class="acct-pwd-card fb-rate-card">
  82. <text class="fb-rate-label">{{ copy.sectionRating }}</text>
  83. <view class="fb-stars">
  84. <text
  85. v-for="n in 5"
  86. :key="n"
  87. class="fb-star"
  88. :class="{ 'fb-star--on': form.score >= n }"
  89. @tap="setScore(n)"
  90. >★</text>
  91. </view>
  92. </view>
  93. </view>
  94. </scroll-view>
  95. <view class="cp-footer" :style="{ paddingBottom: safeBottom + 'px' }">
  96. <button
  97. class="acct-pwd-submit"
  98. :disabled="submitting"
  99. :loading="submitting"
  100. :class="{ 'acct-pwd-submit--busy': submitting }"
  101. @tap="submit"
  102. >
  103. <text class="acct-pwd-submit__text">{{ submitting ? copy.submitting : copy.submit }}</text>
  104. </button>
  105. </view>
  106. </view>
  107. </template>
  108. <script>
  109. import {
  110. submitFeedback,
  111. uploadFeedbackImage,
  112. buildDeviceInfo
  113. } from '@/features/account/feedback-gateway'
  114. export default {
  115. data() {
  116. return {
  117. statusBar: 0,
  118. scrollHeight: 600,
  119. safeBottom: 0,
  120. footerPad: 120,
  121. maxImages: 8,
  122. submitting: false,
  123. uploading: false,
  124. form: {
  125. score: 0,
  126. content: '',
  127. images: [],
  128. contact: ''
  129. }
  130. }
  131. },
  132. computed: {
  133. copy() {
  134. const t = this.$t.bind(this)
  135. return {
  136. pageTitle: t('user.feedback'),
  137. myList: t('feedback.myList'),
  138. heroTitle: t('feedback.heroTitle'),
  139. heroDesc: t('feedback.heroDesc'),
  140. sectionContent: t('feedback.questionAndSuggestion'),
  141. quickInput: t('feedback.quickInput'),
  142. contentPlaceholder: t('feedback.enterDescription'),
  143. sectionScreenshots: t('feedback.problemScreenshots'),
  144. previewImages: t('feedback.clickToPreview'),
  145. addImage: t('feedback.addImage'),
  146. sectionContact: t('feedback.contactInfo'),
  147. contactPlaceholder: t('feedback.contactPlaceholder'),
  148. sectionRating: t('feedback.appRating'),
  149. submit: t('feedback.submit'),
  150. submitting: t('feedback.submitting'),
  151. contentRequired: t('feedback.contentRequired'),
  152. submitOk: t('feedback.submitOk'),
  153. network: t('user.realnameNetworkError'),
  154. uploading: t('feedback.uploading')
  155. }
  156. },
  157. quickIssues() {
  158. return [
  159. this.$t('feedback.issue1'),
  160. this.$t('feedback.issue2'),
  161. this.$t('feedback.issue3'),
  162. this.$t('feedback.issue4')
  163. ]
  164. }
  165. },
  166. onLoad() {
  167. const sys = uni.getSystemInfoSync()
  168. this.statusBar = sys.statusBarHeight || 0
  169. this.safeBottom = sys.safeAreaInsets ? sys.safeAreaInsets.bottom : 0
  170. const navH = this.statusBar + uni.upx2px(88)
  171. this.scrollHeight = (sys.windowHeight || 667) - navH - uni.upx2px(120)
  172. this.footerPad = uni.upx2px(120) + this.safeBottom
  173. },
  174. methods: {
  175. goBack() {
  176. if (getCurrentPages().length > 1) {
  177. uni.navigateBack({ delta: 1 })
  178. } else {
  179. uni.switchTab({
  180. url: '/pages/mine/index',
  181. fail: () => uni.reLaunch({ url: '/pages/mine/index' })
  182. })
  183. }
  184. },
  185. openMyList() {
  186. uni.navigateTo({ url: '/pages/account/feedback-lists' })
  187. },
  188. thumb(url) {
  189. return this.$appKit && this.$appKit.oss ? this.$appKit.oss(url, 200, 200) : url
  190. },
  191. setScore(n) {
  192. this.form.score = n
  193. },
  194. chooseQuickText() {
  195. uni.showActionSheet({
  196. itemList: this.quickIssues,
  197. success: (res) => {
  198. const text = this.quickIssues[res.tapIndex]
  199. if (text) this.form.content = text
  200. }
  201. })
  202. },
  203. pickImages() {
  204. if (this.uploading) return
  205. const remain = this.maxImages - this.form.images.length
  206. if (remain <= 0) return
  207. uni.chooseImage({
  208. sourceType: ['camera', 'album'],
  209. sizeType: ['compressed'],
  210. count: remain,
  211. success: (res) => {
  212. this.uploadChosen(res.tempFilePaths || [])
  213. }
  214. })
  215. },
  216. async uploadChosen(paths) {
  217. if (!paths.length) return
  218. this.uploading = true
  219. uni.showLoading({ mask: true, title: this.copy.uploading })
  220. try {
  221. for (const path of paths) {
  222. const url = await uploadFeedbackImage(path)
  223. if (url) this.form.images.push(url)
  224. }
  225. } catch (err) {
  226. this.$appKit.msg((err && err.message) || this.copy.network)
  227. } finally {
  228. this.uploading = false
  229. uni.hideLoading()
  230. }
  231. },
  232. removeImage(index) {
  233. this.form.images.splice(index, 1)
  234. },
  235. previewImages(index) {
  236. const urls = this.form.images.map((item) =>
  237. this.$appKit.oss ? this.$appKit.oss(item, 500) : item
  238. )
  239. uni.previewImage({
  240. urls,
  241. current: urls[index],
  242. indicator: 'number'
  243. })
  244. },
  245. async submit() {
  246. if (this.submitting) return
  247. if (!String(this.form.content || '').trim()) {
  248. this.$appKit.msg(this.copy.contentRequired)
  249. return
  250. }
  251. this.submitting = true
  252. uni.showLoading({ mask: true })
  253. try {
  254. await submitFeedback({
  255. score: this.form.score,
  256. content: String(this.form.content).trim(),
  257. images: this.form.images,
  258. contact: String(this.form.contact || '').trim(),
  259. device: buildDeviceInfo()
  260. })
  261. this.$appKit.msg(this.copy.submitOk)
  262. setTimeout(() => {
  263. uni.navigateTo({ url: '/pages/account/feedback-lists' })
  264. }, 400)
  265. } catch (err) {
  266. this.$appKit.msg((err && err.message) || this.copy.network)
  267. } finally {
  268. this.submitting = false
  269. uni.hideLoading()
  270. }
  271. }
  272. }
  273. }
  274. </script>
  275. <style scoped>
  276. @import './account-flow.css';
  277. .fb-nav-link {
  278. min-width: 64rpx;
  279. padding: 8rpx 0;
  280. }
  281. .fb-nav-link-txt {
  282. font-size: 26rpx;
  283. color: #4a8cff;
  284. font-weight: 500;
  285. }
  286. .fb-section-row {
  287. display: flex;
  288. flex-direction: row;
  289. align-items: center;
  290. justify-content: space-between;
  291. padding: 0 8rpx 16rpx;
  292. }
  293. .fb-quick {
  294. font-size: 26rpx;
  295. color: #4a8cff;
  296. font-weight: 500;
  297. }
  298. .fb-contact-card {
  299. padding: 8rpx 28rpx;
  300. }
  301. .fb-contact-input {
  302. width: 100%;
  303. height: 88rpx;
  304. font-size: 30rpx;
  305. color: #1a1d26;
  306. }
  307. .fb-rate-card {
  308. display: flex;
  309. flex-direction: row;
  310. align-items: center;
  311. justify-content: space-between;
  312. padding: 28rpx;
  313. }
  314. .fb-rate-label {
  315. font-size: 30rpx;
  316. color: #1a1d26;
  317. font-weight: 500;
  318. }
  319. .fb-stars {
  320. display: flex;
  321. flex-direction: row;
  322. }
  323. .fb-star {
  324. font-size: 48rpx;
  325. color: #d5dae6;
  326. line-height: 1;
  327. margin-left: 8rpx;
  328. }
  329. .fb-star--on {
  330. color: #f59e0b;
  331. }
  332. .cp-section {
  333. display: block;
  334. padding: 0 8rpx 16rpx;
  335. font-size: 26rpx;
  336. color: #8a8d9e;
  337. }
  338. .cp-textarea {
  339. width: 100%;
  340. min-height: 220rpx;
  341. font-size: 28rpx;
  342. color: #1a1d26;
  343. line-height: 1.5;
  344. }
  345. .cp-textarea-placeholder {
  346. color: #b8bcc8;
  347. }
  348. .cp-img-head {
  349. display: flex;
  350. flex-direction: row;
  351. align-items: center;
  352. justify-content: space-between;
  353. margin-bottom: 20rpx;
  354. }
  355. .cp-img-head-label {
  356. font-size: 28rpx;
  357. color: #1a1d26;
  358. font-weight: 500;
  359. }
  360. .cp-img-head-count {
  361. font-size: 24rpx;
  362. color: #8a8d9e;
  363. }
  364. .cp-img-grid {
  365. display: flex;
  366. flex-direction: row;
  367. flex-wrap: wrap;
  368. margin: -8rpx;
  369. }
  370. .cp-img-cell {
  371. position: relative;
  372. width: calc(25% - 16rpx);
  373. height: 152rpx;
  374. margin: 8rpx;
  375. border-radius: 16rpx;
  376. overflow: hidden;
  377. background-color: #f0f3f8;
  378. }
  379. .cp-img-cell--add {
  380. display: flex;
  381. flex-direction: column;
  382. align-items: center;
  383. justify-content: center;
  384. border: 2rpx dashed #d5dae6;
  385. background-color: #f7f9fc;
  386. }
  387. .cp-img-thumb {
  388. width: 100%;
  389. height: 100%;
  390. }
  391. .cp-img-remove {
  392. position: absolute;
  393. top: 0;
  394. right: 0;
  395. width: 40rpx;
  396. height: 40rpx;
  397. background: rgba(239, 68, 68, 0.92);
  398. display: flex;
  399. align-items: center;
  400. justify-content: center;
  401. border-bottom-left-radius: 12rpx;
  402. }
  403. .cp-img-remove-icon {
  404. color: #ffffff;
  405. font-size: 28rpx;
  406. line-height: 1;
  407. }
  408. .cp-img-add-icon {
  409. font-size: 44rpx;
  410. color: #4a8cff;
  411. line-height: 1;
  412. }
  413. .cp-img-add-txt {
  414. margin-top: 6rpx;
  415. font-size: 20rpx;
  416. color: #8a8d9e;
  417. }
  418. .cp-footer {
  419. position: fixed;
  420. left: 0;
  421. right: 0;
  422. bottom: 0;
  423. padding: 16rpx 28rpx 0;
  424. background: linear-gradient(180deg, rgba(244, 246, 251, 0) 0%, #f4f6fb 28%);
  425. box-sizing: border-box;
  426. }
  427. </style>