index.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <view class="container">
  3. <!-- 店铺页面组件 -->
  4. <Page :items="items" />
  5. </view>
  6. </template>
  7. <script>
  8. import { setCartTabBadge } from '@/core/app'
  9. import * as Api from '@/api/page'
  10. import Page from '@/components/page'
  11. const App = getApp()
  12. export default {
  13. components: { Page },
  14. data() {
  15. return {
  16. // 页面参数
  17. options: {},
  18. // 页面属性
  19. page: {},
  20. // 页面元素
  21. items: []
  22. }
  23. },
  24. /**
  25. * 生命周期函数--监听页面加载
  26. */
  27. onLoad(options) {
  28. // 当前页面参数
  29. this.options = options
  30. // 加载页面数据
  31. this.getPageData();
  32. },
  33. /**
  34. * 生命周期函数--监听页面显示
  35. */
  36. onShow() {
  37. // 更新购物车角标
  38. setCartTabBadge()
  39. },
  40. methods: {
  41. /**
  42. * 加载页面数据
  43. * @param {Object} callback
  44. */
  45. getPageData(callback) {
  46. const app = this
  47. const pageId = app.options.pageId || 0
  48. // 设置顶部导航栏栏
  49. Api.detail(pageId)
  50. .then(result => {
  51. // 设置页面数据
  52. const { data: { pageData } } = result
  53. app.page = pageData.page
  54. app.items = pageData.items
  55. // 设置顶部导航栏栏
  56. app.setPageBar();
  57. })
  58. .finally(() => callback && callback())
  59. },
  60. /**
  61. * 设置顶部导航栏
  62. */
  63. setPageBar() {
  64. const { page } = this
  65. // 设置页面标题
  66. uni.setNavigationBarTitle({
  67. title: page.params.title
  68. });
  69. // 设置navbar标题、颜色
  70. uni.setNavigationBarColor({
  71. frontColor: page.style.titleTextColor === 'white' ? '#ffffff' : '#000000',
  72. backgroundColor: page.style.titleBackgroundColor
  73. })
  74. },
  75. },
  76. /**
  77. * 下拉刷新
  78. */
  79. onPullDownRefresh() {
  80. // 获取首页数据
  81. this.getPageData(() => {
  82. uni.stopPullDownRefresh()
  83. })
  84. },
  85. /**
  86. * 分享当前页面
  87. */
  88. onShareAppMessage() {
  89. const app = this
  90. const { page } = app
  91. return {
  92. title: page.params.share_title,
  93. path: "/pages/index/index?" + app.$getShareUrlParams()
  94. }
  95. },
  96. /**
  97. * 分享到朋友圈
  98. * 本接口为 Beta 版本,暂只在 Android 平台支持,详见分享到朋友圈 (Beta)
  99. * https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share-timeline.html
  100. */
  101. onShareTimeline() {
  102. const app = this
  103. const { page } = app
  104. return {
  105. title: page.params.share_title,
  106. path: "/pages/index/index?" + app.$getShareUrlParams()
  107. }
  108. }
  109. }
  110. </script>
  111. <style lang="scss" scoped>
  112. .container {
  113. background: #fff;
  114. }
  115. </style>