index.js 2.1 KB

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