index.vue 3.0 KB

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