1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- const App = getApp();
- Page({
- data: {
- // 页面参数
- options: {},
- // 页面元素
- items: {},
- scrollTop: 0,
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- // 当前页面参数
- this.setData({
- options
- });
- // 加载页面数据
- this.getPageData();
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- // 更新购物车角标
- App.setCartTabBadge()
- },
- /**
- * 加载页面数据
- */
- getPageData(callback) {
- let _this = this;
- App._get('page/index', {
- page_id: _this.data.options.page_id || 0
- }, result => {
- // 设置顶部导航栏栏
- _this.setPageBar(result.data.page);
- _this.setData(result.data);
- // 回调函数
- typeof callback === 'function' && callback();
- });
- },
- /**
- * 设置顶部导航栏
- */
- setPageBar(page) {
- // 设置页面标题
- wx.setNavigationBarTitle({
- title: page.params.title
- });
- // 设置navbar标题、颜色
- wx.setNavigationBarColor({
- frontColor: page.style.titleTextColor === 'white' ? '#ffffff' : '#000000',
- backgroundColor: page.style.titleBackgroundColor
- })
- },
- /**
- * 下拉刷新
- */
- onPullDownRefresh() {
- // 获取首页数据
- this.getPageData(function () {
- wx.stopPullDownRefresh();
- });
- },
- /**
- * 分享当前页面
- */
- onShareAppMessage() {
- const _this = this;
- return {
- title: _this.data.page.params.share_title,
- path: "/pages/index/index?" + App.getShareUrlParams()
- };
- },
- /**
- * 分享到朋友圈
- * 本接口为 Beta 版本,暂只在 Android 平台支持,详见分享到朋友圈 (Beta)
- * https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share-timeline.html
- */
- onShareTimeline() {
- const _this = this;
- return {
- title: _this.data.page.params.share_title,
- path: "/pages/index/index?" + App.getShareUrlParams()
- };
- }
- });
|