index.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. const App = getApp();
  2. Page({
  3. data: {
  4. // 页面参数
  5. options: {},
  6. // 页面元素
  7. items: {},
  8. scrollTop: 0,
  9. },
  10. /**
  11. * 生命周期函数--监听页面加载
  12. */
  13. onLoad(options) {
  14. // 当前页面参数
  15. this.setData({
  16. options
  17. });
  18. // 加载页面数据
  19. this.getPageData();
  20. },
  21. /**
  22. * 生命周期函数--监听页面显示
  23. */
  24. onShow() {
  25. // 更新购物车角标
  26. App.setCartTabBadge()
  27. },
  28. /**
  29. * 加载页面数据
  30. */
  31. getPageData(callback) {
  32. let _this = this;
  33. App._get('page/index', {
  34. page_id: _this.data.options.page_id || 0
  35. }, result => {
  36. // 设置顶部导航栏栏
  37. _this.setPageBar(result.data.page);
  38. _this.setData(result.data);
  39. // 回调函数
  40. typeof callback === 'function' && callback();
  41. });
  42. },
  43. /**
  44. * 设置顶部导航栏
  45. */
  46. setPageBar(page) {
  47. // 设置页面标题
  48. wx.setNavigationBarTitle({
  49. title: page.params.title
  50. });
  51. // 设置navbar标题、颜色
  52. wx.setNavigationBarColor({
  53. frontColor: page.style.titleTextColor === 'white' ? '#ffffff' : '#000000',
  54. backgroundColor: page.style.titleBackgroundColor
  55. })
  56. },
  57. /**
  58. * 下拉刷新
  59. */
  60. onPullDownRefresh() {
  61. // 获取首页数据
  62. this.getPageData(function () {
  63. wx.stopPullDownRefresh();
  64. });
  65. },
  66. /**
  67. * 分享当前页面
  68. */
  69. onShareAppMessage() {
  70. const _this = this;
  71. return {
  72. title: _this.data.page.params.share_title,
  73. path: "/pages/index/index?" + App.getShareUrlParams()
  74. };
  75. },
  76. /**
  77. * 分享到朋友圈
  78. * 本接口为 Beta 版本,暂只在 Android 平台支持,详见分享到朋友圈 (Beta)
  79. * https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share-timeline.html
  80. */
  81. onShareTimeline() {
  82. const _this = this;
  83. return {
  84. title: _this.data.page.params.share_title,
  85. path: "/pages/index/index?" + App.getShareUrlParams()
  86. };
  87. }
  88. });