index.vue 2.7 KB

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