list.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { getCardNovelsMore } from '../../api/api'
  2. import { goToBookDetail } from '../../utils/util'
  3. Page({
  4. data: {
  5. pageTitle: '',
  6. bookList: [],
  7. loading: false,
  8. id: ''
  9. },
  10. onLoad(options) {
  11. const pageTitle = options.name || '书籍列表'
  12. this.setData({
  13. pageTitle,
  14. id: options.id
  15. })
  16. // 加载数据
  17. this.loadBookList()
  18. },
  19. // 加载书籍列表
  20. async loadBookList() {
  21. if (this.data.loading) return
  22. this.setData({ loading: true })
  23. try {
  24. const result = await getCardNovelsMore(this.data.id)
  25. this.setData({
  26. bookList: result || [],
  27. loading: false
  28. })
  29. } catch (error) {
  30. console.error('加载书籍列表失败:', error)
  31. this.setData({ loading: false })
  32. wx.showToast({
  33. title: '加载失败,请重试',
  34. icon: 'none'
  35. })
  36. }
  37. },
  38. // 点击书籍项
  39. onBookTap(e) {
  40. const bookId = e.currentTarget.dataset.bookId;
  41. const wxBookId = e.currentTarget.dataset.wxBookId;
  42. const chapterId = e.currentTarget.dataset.chapterId;
  43. console.log('bookId',bookId);
  44. console.log('wxBookId',wxBookId);
  45. console.log('chapterId',chapterId);
  46. goToBookDetail({
  47. bookId,
  48. wxBookId,
  49. chapterId
  50. });
  51. },
  52. // 返回上一页
  53. goBack() {
  54. wx.navigateBack({
  55. delta: 1
  56. });
  57. }
  58. })