小说小程序前端代码仓库(小程序)
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.

230 lines
4.5 KiB

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
  1. <template>
  2. <view class="page">
  3. <navbar title="新建章节" leftClick @leftClick="$utils.navigateBack" />
  4. <view class="form-box top-fixed">
  5. <view class="form-item">
  6. <text class="required">*</text>
  7. <text class="label">章节名称</text>
  8. <input class="input"
  9. type="text"
  10. placeholder='请输入章节号与章节名。例如:"第十章天降奇缘"'
  11. v-model="form.title" />
  12. </view>
  13. <view class="form-item"
  14. style="justify-content: space-between;align-items: center;flex-direction: row;">
  15. <view class="">
  16. <text class="required">*</text>
  17. <text class="label">是否付费</text>
  18. </view>
  19. <uv-switch v-model="value" size="70rpx"></uv-switch>
  20. </view>
  21. <view class="form-item">
  22. <text class="required">*</text>
  23. <text class="label">章节内容</text>
  24. <view class="textarea-container">
  25. <!-- <textarea class="textarea"
  26. placeholder="请输入章节内容"
  27. :maxlength="100000"
  28. v-model="form.details" /> -->
  29. <!-- <view class="toolbar">
  30. <view class="indent-btn" @tap="addIndent">缩进</view>
  31. </view> -->
  32. <uv-textarea v-model="form.details"
  33. :maxlength="-1"
  34. autoHeight
  35. class="textarea"
  36. placeholder="请输入章节内容"></uv-textarea>
  37. </view>
  38. </view>
  39. </view>
  40. <view class="footer-btns">
  41. <button class="btn save-btn" @click="onPublish(0)">保存成草稿</button>
  42. <button class="btn publish-btn" @click="onPublish(1)">发布</button>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. export default {
  48. data() {
  49. return {
  50. form: {
  51. title: '',
  52. details: '',
  53. },
  54. id : 0,
  55. cid : 0,
  56. value : false,
  57. }
  58. },
  59. onLoad({id, cid}) {
  60. this.id = id
  61. this.cid = cid || 0
  62. if(this.cid){
  63. this.getChapterDetail()
  64. }
  65. },
  66. methods: {
  67. getChapterDetail(){
  68. this.$fetch('getBookCatalogDetail', {
  69. id: this.cid
  70. }).then(res => {
  71. this.form.title = res.title
  72. this.form.details = res.details
  73. this.value = res.isPay == 'Y'
  74. })
  75. },
  76. async onPublish(status) {
  77. let data = {
  78. bookId : this.id,
  79. num : this.form.details.length,
  80. title : this.form.title,
  81. details : this.form.details,
  82. isPay : this.value ? 'Y' : 'N'
  83. }
  84. if(this.cid){
  85. data.id = this.cid
  86. }
  87. data.status = status
  88. await this.$fetch('saveOrUpdateCatalog', data)
  89. uni.showToast({
  90. title: status ? '发布成功' : '保存成功'
  91. })
  92. setTimeout(uni.navigateBack, 800, -1)
  93. },
  94. }
  95. }
  96. </script>
  97. <style scoped lang="scss">
  98. .page {
  99. min-height: 100vh;
  100. background: #f7f8fa;
  101. display: flex;
  102. flex-direction: column;
  103. }
  104. .form-box {
  105. background: #fff;
  106. margin: 0;
  107. padding: 0 32rpx;
  108. border-radius: 0;
  109. position: relative;
  110. }
  111. .top-fixed {
  112. margin-top: 0;
  113. }
  114. .form-item {
  115. display: flex;
  116. flex-direction: column;
  117. margin-top: 32rpx;
  118. position: relative;
  119. }
  120. .label {
  121. font-size: 28rpx;
  122. color: #222;
  123. margin-bottom: 12rpx;
  124. margin-left: 32rpx;
  125. }
  126. .required {
  127. color: #f44;
  128. position: absolute;
  129. left: 0;
  130. top: 0;
  131. font-size: 32rpx;
  132. }
  133. .input {
  134. border: none;
  135. border-bottom: 1rpx solid #eee;
  136. font-size: 28rpx;
  137. padding: 16rpx 0;
  138. background: transparent;
  139. }
  140. .textarea-container {
  141. position: relative;
  142. line-height: 50rpx;
  143. padding-bottom: 200rpx;
  144. /deep/ .uv-textarea{
  145. min-height: 70vh;
  146. border: none !important;
  147. font-size: 28rpx;
  148. padding: 16rpx 0;
  149. background: transparent;
  150. resize: none;
  151. width: 100%;
  152. }
  153. }
  154. .textarea {
  155. min-height: 70vh;
  156. border: none;
  157. border-bottom: 1rpx solid #eee;
  158. font-size: 28rpx;
  159. padding: 16rpx 0;
  160. background: transparent;
  161. resize: none;
  162. width: 100%;
  163. }
  164. .toolbar {
  165. display: flex;
  166. padding: 10rpx 0;
  167. margin-top: 10rpx;
  168. }
  169. .indent-btn {
  170. background: #eaeaea;
  171. color: #333;
  172. padding: 8rpx 20rpx;
  173. border-radius: 6rpx;
  174. font-size: 26rpx;
  175. }
  176. .footer-btns {
  177. position: fixed;
  178. left: 0;
  179. bottom: 0;
  180. width: 100vw;
  181. background: #fff;
  182. display: flex;
  183. justify-content: space-between;
  184. padding: 24rpx 48rpx 32rpx 48rpx;
  185. box-sizing: border-box;
  186. z-index: 10;
  187. box-shadow: 0 -2rpx 12rpx rgba(0, 0, 0, 0.03);
  188. }
  189. .btn {
  190. flex: 1;
  191. height: 80rpx;
  192. font-size: 32rpx;
  193. border-radius: 40rpx;
  194. margin: 0 12rpx;
  195. font-weight: 500;
  196. }
  197. .save-btn {
  198. background: #fff;
  199. color: #0a225f;
  200. border: 2rpx solid #0a225f;
  201. }
  202. .publish-btn {
  203. background: #0a225f;
  204. color: #fff;
  205. border: none;
  206. }
  207. </style>