index.vue 2.7 KB

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