This repository has been archived on 2024-07-11. You can view files and clone it, but cannot push or open issues or pull requests.
yoshop-wechat/pages/index/index.js

98 lines
2.0 KiB
JavaScript
Raw Permalink Normal View History

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