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

320 lines
7.5 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
  1. <template>
  2. <view class="page">
  3. <!-- 导航栏 -->
  4. <navbar title="书城"
  5. leftClick
  6. @leftClick="$utils.navigateBack"
  7. bgColor="#E3441A"
  8. color="#fff" />
  9. <!-- 分类商品列表 -->
  10. <view class="category"
  11. >
  12. <view class="tabs">
  13. <uv-tabs
  14. :list="category"
  15. :activeStyle="{color : '#f00', fontWeight : 600}"
  16. lineColor="#f00"
  17. :inactiveStyle="{color: 'rgba(0,0,0,.8)'}"
  18. lineHeight="8rpx"
  19. lineWidth="50rpx"
  20. :current="current"
  21. @click="clickTabs"></uv-tabs>
  22. </view>
  23. <uv-vtabs
  24. :list="category[current].children"
  25. :current="currentChildren"
  26. keyName="name"
  27. :chain="false"
  28. @change="change">
  29. <uv-vtabs-item>
  30. <view class="category-item">
  31. <view class="novel-list" v-if="categoryList.shopList.length > 0">
  32. <novelItem
  33. v-for="(book, index) in categoryList.shopList"
  34. :key="index"
  35. :book="book">
  36. </novelItem>
  37. </view>
  38. <uv-empty v-if="categoryList.shopList.length == 0" text="还没有呢"/>
  39. </view>
  40. </uv-vtabs-item>
  41. </uv-vtabs>
  42. </view>
  43. <!-- tabbar -->
  44. <tabber select="category" />
  45. </view>
  46. </template>
  47. <script>
  48. import {
  49. mapState
  50. } from 'vuex'
  51. import tabber from '@/components/base/tabbar.vue'
  52. import novelItem from '@/components/novel/novelItem.vue'
  53. export default {
  54. // mixins: [mixinsList],
  55. components: {
  56. tabber,
  57. novelItem
  58. },
  59. data() {
  60. return {
  61. mixinsListApi: '',
  62. current : 0,
  63. currentChildren : 0,
  64. categoryList: {
  65. shopList: [
  66. {
  67. id: '1',
  68. title: '我是半妖',
  69. cover: 'https://images.unsplash.com/photo-1506744038136-46273834b3fb?auto=format&fit=facearea&w=400&h=400',
  70. author: '东方不败',
  71. desc: '这是一部关于半妖少年成长的玄幻小说,讲述了主角在人妖两界的冒险故事。',
  72. tags: ['玄幻', '冒险', '热血'],
  73. status: '连载中'
  74. },
  75. {
  76. id: '2',
  77. title: '兽王进化',
  78. cover: 'https://images.unsplash.com/photo-1519125323398-675f0ddb6308?auto=format&fit=facearea&w=400&h=400',
  79. author: '天下霸唱',
  80. desc: '一场意外让主角获得兽王血脉,开始了进化之路...',
  81. tags: ['奇幻', '冒险'],
  82. status: '连载中'
  83. },
  84. {
  85. id: '3',
  86. title: '魔法少女纯爷们',
  87. cover: 'https://images.unsplash.com/photo-1465101046530-73398c7f28ca?auto=format&fit=facearea&w=400&h=400',
  88. author: '南派三叔',
  89. desc: '一个普通男孩意外获得魔法少女的力量,开始了奇妙冒险...',
  90. tags: ['搞笑', '奇幻'],
  91. status: '已完结'
  92. }
  93. ]
  94. },
  95. category: [
  96. {
  97. id: '1',
  98. name: '男生',
  99. children: [
  100. { id: '101', name: '玄幻' },
  101. { id: '102', name: '奇幻' },
  102. { id: '103', name: '武侠' },
  103. { id: '104', name: '仙侠' },
  104. { id: '105', name: '都市' },
  105. { id: '106', name: '历史' },
  106. { id: '107', name: '军事' },
  107. { id: '108', name: '游戏' },
  108. { id: '109', name: '体育' }
  109. ]
  110. },
  111. {
  112. id: '2',
  113. name: '女生',
  114. children: [
  115. { id: '201', name: '古代言情' },
  116. { id: '202', name: '现代言情' },
  117. { id: '203', name: '幻想言情' },
  118. { id: '204', name: '青春校园' },
  119. { id: '205', name: '纯爱' }
  120. ]
  121. },
  122. {
  123. id: '3',
  124. name: '出版',
  125. children: [
  126. { id: '301', name: '文学' },
  127. { id: '302', name: '传记' },
  128. { id: '303', name: '励志' },
  129. { id: '304', name: '名著' },
  130. { id: '305', name: '经管' }
  131. ]
  132. }
  133. ]
  134. }
  135. },
  136. computed: {
  137. },
  138. onLoad({
  139. search,
  140. cid
  141. }) {
  142. if (search) {
  143. this.queryParams.title = search
  144. }
  145. // 初始化默认分类的书籍列表
  146. if (this.category.length > 0) {
  147. if (cid) {
  148. // 如果有指定分类ID,则显示对应分类
  149. let foundCategory = false
  150. this.category.forEach((n, i) => {
  151. if (n.id == cid) {
  152. this.current = i
  153. foundCategory = true
  154. }
  155. })
  156. if (foundCategory) {
  157. this.updateBookList(this.category[this.current].children[0].id)
  158. } else {
  159. // 如果未找到指定分类,显示第一个分类
  160. this.updateBookList(this.category[0].children[0].id)
  161. }
  162. } else {
  163. // 没有指定分类ID,显示第一个分类
  164. this.updateBookList(this.category[0].children[0].id)
  165. }
  166. }
  167. // this.$store.commit('getCategoryList')
  168. // if(this.category.length > 0 && cid){
  169. // this.category.forEach((n, i) => {
  170. // if(n.id == cid){
  171. // this.current = i
  172. // }
  173. // })
  174. // // this.queryParams.classId = cid
  175. // }else if (this.category.length > 0) {
  176. // // this.queryParams.classId = this.category[0].id
  177. // }
  178. },
  179. methods: {
  180. change(e) {
  181. // this.queryParams.classId = this.category[e].id
  182. this.currentChildren = e
  183. // 更新对应分类的书籍列表
  184. this.updateBookList(this.category[this.current].children[e].id)
  185. },
  186. clickTabs({index}){
  187. this.current = index
  188. this.currentChildren = 0
  189. // 更新对应分类的书籍列表
  190. this.updateBookList(this.category[index].children[0].id)
  191. },
  192. updateBookList(categoryId) {
  193. // 模拟获取不同分类的书籍数据
  194. // 实际项目中应该调用API获取数据
  195. console.log('获取分类ID为: ' + categoryId + ' 的书籍')
  196. // 这里只是简单模拟不同分类有不同数量的书
  197. const bookCount = Math.floor(Math.random() * 3) + 1
  198. const tempList = []
  199. for (let i = 0; i < bookCount; i++) {
  200. tempList.push({
  201. id: categoryId + '-' + i,
  202. title: '分类' + categoryId + '的书' + i,
  203. cover: 'https://images.unsplash.com/photo-1506744038136-46273834b3fb?auto=format&fit=facearea&w=400&h=400',
  204. author: '作者' + categoryId,
  205. desc: '这是分类' + categoryId + '的第' + i + '本书...',
  206. tags: ['分类' + categoryId, '热门'],
  207. status: i % 2 === 0 ? '连载中' : '已完结'
  208. })
  209. }
  210. this.categoryList.shopList = tempList
  211. },
  212. search(){
  213. for(let i = 0;i < 10;i++){
  214. delete this.queryParams[i]
  215. }
  216. this.queryParams.pageSize = 10
  217. this.getData()
  218. },
  219. }
  220. }
  221. </script>
  222. <style scoped lang="scss">
  223. .page {
  224. /deep/ .uv-vtabs {
  225. height: calc(100vh - 600rpx) !important;
  226. }
  227. /deep/ .uv-vtabs__bar {
  228. height: calc(100vh - 600rpx) !important;
  229. }
  230. /deep/ .uv-vtabs__content {
  231. height: calc(100vh - 600rpx) !important;
  232. }
  233. .search {
  234. position: relative;
  235. background: #FFFFFF;
  236. margin: 20rpx;
  237. border-radius: 41rpx;
  238. padding: 10rpx 20rpx;
  239. display: flex;
  240. align-items: center;
  241. /deep/ .uv-search__action {
  242. background-color: $uni-color;
  243. color: #FFFFFF;
  244. padding: 10rpx 20rpx;
  245. border-radius: 30rpx;
  246. }
  247. }
  248. &::v-deep .uv-vtabs__content {
  249. background: transparent !important;
  250. overflow: hidden;
  251. }
  252. }
  253. .category {
  254. font-size: 30rpx;
  255. color: #333;
  256. .category-title{
  257. position: relative;
  258. display: flex;
  259. justify-content: center;
  260. align-items: center;
  261. height: 120rpx;
  262. &::before,
  263. &::after {
  264. position: absolute;
  265. top: 50%;
  266. content: '';
  267. width: 10%;
  268. border-top: 2rpx solid black;
  269. }
  270. &::before {
  271. left: 25%;
  272. }
  273. &::after {
  274. right: 25%;
  275. }
  276. }
  277. &::v-deep .uv-vtabs {
  278. width: 750rpx;
  279. overflow: hidden;
  280. }
  281. .list {
  282. width: 100%;
  283. padding: 0rpx 20rpx;
  284. box-sizing: border-box;
  285. }
  286. .category-item {
  287. padding: 0 20rpx;
  288. .novel-list {
  289. width: 100%;
  290. display: flex;
  291. flex-direction: column;
  292. gap: 10rpx;
  293. }
  294. }
  295. }
  296. </style>