小说小程序前端代码仓库(小程序)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

196 lines
4.2 KiB

  1. <template>
  2. <view class="review-page">
  3. <!-- 顶部导航栏 -->
  4. <navbar title="写书评" leftClick @leftClick="$utils.navigateBack" />
  5. <view class="review-content">
  6. <view class="book-title-label">书本名称</view>
  7. <view class="book-title">{{ bookTitle }}</view>
  8. <view class="form-area flex-grow">
  9. <view class="form-label-row">
  10. <text class="required-star">*</text>
  11. <text class="form-label">书评内容</text>
  12. </view>
  13. <textarea v-model="form.content" class="review-textarea custom-placeholder full-textarea"
  14. placeholder="请输入书评内容" />
  15. </view>
  16. </view>
  17. <view class="review-footer">
  18. <view class="footer-divider"></view>
  19. <button class="submit-btn" @click="submitReview">发布</button>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. import navbar from '@/components/base/navbar.vue'
  25. export default {
  26. components: {
  27. navbar
  28. },
  29. data() {
  30. return {
  31. bookTitle: '',
  32. form: {
  33. content: ''
  34. },
  35. id: 0
  36. }
  37. },
  38. onLoad(options) {
  39. // 通过路由参数获取书名
  40. this.bookTitle = options.title || '未知书名'
  41. this.id = options.id || 0
  42. this.getDateil()
  43. },
  44. methods: {
  45. getDateil(){
  46. this.$fetch('getBookDetail', {
  47. id : this.id
  48. }).then(res => {
  49. this.bookTitle = res.name
  50. })
  51. },
  52. async submitReview() {
  53. if(this.$utils.verificationAll(this.form, {
  54. content : '请输入书评内容'
  55. })){
  56. return
  57. }
  58. await this.$fetch('saveComment', {
  59. bookId : this.id,
  60. content : this.form.content,
  61. })
  62. uni.showToast({
  63. title: '发布成功',
  64. icon: 'none'
  65. })
  66. setTimeout(() => {
  67. uni.navigateBack()
  68. }, 1000)
  69. }
  70. }
  71. }
  72. </script>
  73. <style scoped lang="scss">
  74. .review-page {
  75. min-height: 100vh;
  76. background: #f7f7f7;
  77. display: flex;
  78. flex-direction: column;
  79. }
  80. .review-content {
  81. background: #fff;
  82. margin: 0 24rpx;
  83. margin-top: 24rpx;
  84. border-radius: 16rpx;
  85. padding: 32rpx 24rpx 24rpx 24rpx;
  86. display: flex;
  87. flex-direction: column;
  88. flex: 1;
  89. padding-bottom: 140rpx;
  90. .flex-grow {
  91. flex: 1 1 0;
  92. display: flex;
  93. flex-direction: column;
  94. min-height: 0;
  95. }
  96. .book-title-label {
  97. color: #bdbdbd;
  98. font-size: 24rpx;
  99. margin-bottom: 4rpx;
  100. }
  101. .book-title {
  102. font-size: 28rpx;
  103. color: #222;
  104. margin-bottom: 36rpx;
  105. border-bottom: 1px solid #ededed;
  106. padding-bottom: 8rpx;
  107. }
  108. .form-area {
  109. margin-top: 18rpx;
  110. }
  111. .form-label-row {
  112. display: flex;
  113. align-items: center;
  114. margin-bottom: 8rpx;
  115. }
  116. .required-star {
  117. color: #e23d3d;
  118. font-size: 22rpx;
  119. margin-right: 4rpx;
  120. line-height: 1;
  121. }
  122. .form-label {
  123. color: #222;
  124. font-size: 26rpx;
  125. font-weight: 400;
  126. }
  127. .review-textarea {
  128. width: 100%;
  129. min-height: 320rpx;
  130. border: none;
  131. background: transparent;
  132. font-size: 28rpx;
  133. color: #333;
  134. resize: none;
  135. margin-top: 0;
  136. outline: none;
  137. }
  138. .review-textarea.custom-placeholder::placeholder {
  139. color: #d2d2d2;
  140. font-size: 26rpx;
  141. }
  142. .full-textarea {
  143. flex: 1;
  144. min-height: 0;
  145. max-height: none;
  146. box-sizing: border-box;
  147. margin-bottom: 0;
  148. }
  149. }
  150. .review-footer {
  151. position: fixed;
  152. left: 0;
  153. right: 0;
  154. bottom: 90rpx;
  155. background: #fff;
  156. padding: 24rpx 32rpx 32rpx 32rpx;
  157. box-shadow: 0 -2rpx 12rpx rgba(0, 0, 0, 0.03);
  158. z-index: 10;
  159. .footer-divider {
  160. width: 100%;
  161. height: 2rpx;
  162. background: #f2f2f2;
  163. margin-bottom: 24rpx;
  164. }
  165. .submit-btn {
  166. width: 100%;
  167. height: 80rpx;
  168. background: #0a225f;
  169. color: #fff;
  170. font-size: 30rpx;
  171. border-radius: 40rpx;
  172. font-weight: 500;
  173. letter-spacing: 2rpx;
  174. }
  175. }
  176. </style>