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

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