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

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