index.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import HomeApi from '../../services/home'
  2. import { share } from '../../utils/http'
  3. // pages/atphotos/index.ts
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. cid: -1,
  10. idx: 0,
  11. loading: false,
  12. tabs: [] as {
  13. title: string
  14. acname: string
  15. acid: number
  16. }[],
  17. },
  18. /**
  19. * 生命周期函数--监听页面加载
  20. */
  21. onLoad({ id }: { id: string }) {
  22. this.setData({
  23. loading: true,
  24. })
  25. HomeApi.GetExtraItemDetail({
  26. id,
  27. })
  28. .then((rsp) => {
  29. const result = rsp.result
  30. this.setData({
  31. tabs: result.albums,
  32. idx: 0,
  33. cid: result.albums[0].acid,
  34. loading: false,
  35. })
  36. // this.setData({
  37. // loading: false,
  38. // wait: false,
  39. // allItems: items,
  40. // idx: -1,
  41. // cates,
  42. // total: currentItems.length,
  43. // items: currentItems,
  44. // views: takes,
  45. // viewcnt: takes.length,
  46. // })
  47. wx.setNavigationBarTitle({
  48. // @ts-ignore
  49. title: result.title,
  50. })
  51. })
  52. .catch(() => {
  53. this.setData({
  54. loading: false,
  55. })
  56. })
  57. },
  58. /**
  59. * 生命周期函数--监听页面初次渲染完成
  60. */
  61. onReady() {},
  62. /**
  63. * 生命周期函数--监听页面显示
  64. */
  65. onShow() {},
  66. /**
  67. * 生命周期函数--监听页面隐藏
  68. */
  69. onHide() {},
  70. /**
  71. * 生命周期函数--监听页面卸载
  72. */
  73. onUnload() {},
  74. /**
  75. * 页面相关事件处理函数--监听用户下拉动作
  76. */
  77. onPullDownRefresh() {},
  78. /**
  79. * 页面上拉触底事件的处理函数
  80. */
  81. onReachBottom() {
  82. // 当页面触底时触发的事件
  83. const myComponent = this.selectComponent('#nlist')
  84. if (myComponent) {
  85. myComponent.fetchNext() // 调用组件的加载数据方法
  86. }
  87. },
  88. /**
  89. * 用户点击右上角分享
  90. */
  91. onShareAppMessage() {
  92. let pages = getCurrentPages(); //获取所有页面栈实例列表
  93. let nowPage = pages[pages.length - 1]; //当前页页面实例
  94. return {
  95. title: share.title,
  96. path: `/${nowPage.route}`,
  97. imageUrl: share.imageUrl,
  98. success(res) {
  99. console.log('success(res)==', res);
  100. },
  101. fail(res) {
  102. console.log('fail(res)==', res);
  103. }
  104. }
  105. },
  106. onTabChange(event: WechatMiniprogram.CustomEvent<{}, {}, { index: number }>) {
  107. const idx = event.currentTarget.dataset.index
  108. this.setData({
  109. idx,
  110. cid: this.data.tabs[idx].acid,
  111. })
  112. },
  113. })