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

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