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

248 lines
5.7 KiB

  1. <template>
  2. <view class="chapter-container">
  3. <view class="header">
  4. <view class="nav-bar" style="position: relative; height: 44px;">
  5. <view class="back" @click="goBack">
  6. <uv-icon name="arrow-left" color="black" size="48"></uv-icon>
  7. </view>
  8. <view class="title">兽王进化从被小萝莉...</view>
  9. <view class="right-icons"></view>
  10. </view>
  11. <view class="tabs">
  12. <view class="tab" :class="{ active: activeTab === 'draft' }" @click="switchTab('draft')">草稿箱</view>
  13. <view class="tab" :class="{ active: activeTab === 'published' }" @click="switchTab('published')">已发布</view>
  14. </view>
  15. </view>
  16. <view class="chapter-list">
  17. <view class="chapter-item" v-for="(chapter, index) in chapters" :key="index" @click="editChapter(chapter)">
  18. <view class="chapter-info">
  19. <text class="chapter-title">章节名</text>
  20. <text class="chapter-number">{{index + 1}}</text>
  21. </view>
  22. <uv-icon name="arrow-right" color="#999" size="28"></uv-icon>
  23. </view>
  24. </view>
  25. <view class="bottom-actions">
  26. <button class="btn-settings" @click="handleSettings">设置作品</button>
  27. <button class="btn-new" @click="addNewChapter">新建章节</button>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. export default {
  33. data() {
  34. return {
  35. activeTab: 'draft',
  36. chapters: [] // 真实章节数据
  37. }
  38. },
  39. onLoad(options) {
  40. // 根据tab参数决定初始tab
  41. if (options && options.tab === 'published') {
  42. this.activeTab = 'published';
  43. } else {
  44. this.activeTab = 'draft';
  45. }
  46. this.loadChapters();
  47. // 判断是否需要弹窗
  48. if (options && options.fromSave === '1') {
  49. uni.showToast({
  50. title: '保存成功',
  51. icon: 'success'
  52. });
  53. }
  54. if (options && options.fromPublish === '1') {
  55. uni.showToast({
  56. title: '发布成功',
  57. icon: 'success'
  58. });
  59. }
  60. },
  61. methods: {
  62. loadChapters() {
  63. if (this.activeTab === 'published') {
  64. this.chapters = uni.getStorageSync('publishedChapters') || [];
  65. } else {
  66. this.chapters = uni.getStorageSync('chapters') || [];
  67. }
  68. },
  69. goBack() {
  70. uni.navigateBack()
  71. },
  72. switchTab(tab) {
  73. this.activeTab = tab;
  74. this.loadChapters();
  75. },
  76. addNewChapter() {
  77. uni.navigateTo({
  78. url: '/pages_order/author/editor'
  79. })
  80. },
  81. editChapter(chapter) {
  82. uni.navigateTo({
  83. url: '/pages_order/author/editor?id=' + chapter.id
  84. })
  85. },
  86. handleSettings() {
  87. uni.navigateTo({
  88. url: '/pages_order/novel/createNovel?type=edit'
  89. })
  90. }
  91. }
  92. }
  93. </script>
  94. <style lang="scss" scoped>
  95. .chapter-container {
  96. min-height: 100vh;
  97. background-color: #fff;
  98. padding-bottom: 70px;
  99. .header {
  100. background: #fff;
  101. .nav-bar {
  102. position: relative;
  103. height: 44px;
  104. .back {
  105. position: absolute;
  106. left: 0;
  107. top: 0;
  108. bottom: 0;
  109. width: 48px;
  110. display: flex;
  111. align-items: center;
  112. justify-content: center;
  113. z-index: 2;
  114. }
  115. .right-icons {
  116. position: absolute;
  117. right: 0;
  118. top: 0;
  119. bottom: 0;
  120. width: 48px;
  121. display: flex;
  122. align-items: center;
  123. justify-content: center;
  124. z-index: 2;
  125. }
  126. .title {
  127. position: absolute;
  128. left: 0;
  129. right: 0;
  130. top: 0;
  131. bottom: 0;
  132. margin: auto;
  133. height: 44px;
  134. display: flex;
  135. align-items: center;
  136. justify-content: center;
  137. font-size: 16px;
  138. font-weight: 500;
  139. color: #222;
  140. overflow: hidden;
  141. text-overflow: ellipsis;
  142. white-space: nowrap;
  143. text-align: center;
  144. z-index: 1;
  145. pointer-events: none;
  146. }
  147. }
  148. .tabs {
  149. display: flex;
  150. margin-top: 4px;
  151. margin-left: 120rpx;
  152. justify-content: space-between;
  153. .tab {
  154. font-size: 15px;
  155. color: #888;
  156. margin-right: 120rpx;
  157. position: relative;
  158. &.active {
  159. color: #223a7a;
  160. font-weight: 600;
  161. &::after {
  162. content: '';
  163. display: block;
  164. width: 24px;
  165. height: 3px;
  166. background: #223a7a;
  167. border-radius: 2px;
  168. position: absolute;
  169. left: 50%;
  170. transform: translateX(-50%);
  171. bottom: -6px;
  172. }
  173. }
  174. }
  175. }
  176. }
  177. .chapter-list {
  178. padding: 20rpx 40rpx;
  179. background-color: rgb(255, 254, 254);
  180. margin: 50rpx 40rpx;
  181. border-radius: 3%;
  182. .chapter-item {
  183. display: flex;
  184. justify-content: space-between;
  185. align-items: center;
  186. padding: 15px 0;
  187. border-bottom: 1px solid #eee;
  188. .chapter-info {
  189. .chapter-title {
  190. font-size: 14px;
  191. color: #999;
  192. margin-bottom: 5px;
  193. display: block;
  194. }
  195. .chapter-number {
  196. font-size: 16px;
  197. color: #333;
  198. display: block;
  199. }
  200. }
  201. .icon-arrow {
  202. color: #999;
  203. font-size: 16px;
  204. }
  205. }
  206. }
  207. .bottom-actions {
  208. position: fixed;
  209. bottom: 0;
  210. left: 0;
  211. right: 0;
  212. display: flex;
  213. padding: 10px 15px;
  214. background: #fff;
  215. box-shadow: 0 -2px 6px rgba(0,0,0,0.05);
  216. button {
  217. flex: 1;
  218. height: 40px;
  219. border-radius: 20px;
  220. font-size: 16px;
  221. margin: 0 5px;
  222. &.btn-settings {
  223. background: #fff;
  224. border: 1px solid #ddd;
  225. color: #333;
  226. }
  227. &.btn-new {
  228. background: #2b4acb;
  229. color: #fff;
  230. border: none;
  231. }
  232. }
  233. }
  234. }
  235. </style>