index.vue 2.8 KB

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