index.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <view class="container" :style="appThemeStyle">
  3. <!-- 店铺页面组件 -->
  4. <Page :items="items" />
  5. </view>
  6. </template>
  7. <script>
  8. import * as Api from '@/api/page'
  9. import Page from '@/components/page'
  10. export default {
  11. components: {
  12. Page
  13. },
  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. methods: {
  34. /**
  35. * 加载页面数据
  36. * @param {Object} callback
  37. */
  38. getPageData(callback) {
  39. const app = this
  40. const pageId = app.options.pageId || 0
  41. Api.detail(pageId)
  42. .then(result => {
  43. // 设置页面数据
  44. const { data: { pageData } } = result
  45. app.page = pageData.page
  46. app.items = pageData.items
  47. // 设置顶部导航栏栏
  48. app.setPageBar()
  49. })
  50. .finally(() => callback && callback())
  51. },
  52. /**
  53. * 设置顶部导航栏
  54. */
  55. setPageBar() {
  56. const { page } = this
  57. // 设置页面标题
  58. uni.setNavigationBarTitle({
  59. title: page.params.title
  60. })
  61. // 设置navbar标题、颜色
  62. uni.setNavigationBarColor({
  63. // #ifndef MP-ALIPAY
  64. frontColor: page.style.titleTextColor === 'white' ? '#ffffff' : '#000000',
  65. // #endif
  66. backgroundColor: page.style.titleBackgroundColor
  67. })
  68. },
  69. },
  70. /**
  71. * 下拉刷新
  72. */
  73. onPullDownRefresh() {
  74. // 获取首页数据
  75. this.getPageData(() => {
  76. uni.stopPullDownRefresh()
  77. })
  78. },
  79. /**
  80. * 分享当前页面
  81. */
  82. onShareAppMessage() {
  83. const app = this
  84. const { page } = app
  85. return {
  86. title: page.params.shareTitle,
  87. path: "/pages/custom/index?" + app.$getShareUrlParams({ pageId: app.options.pageId })
  88. }
  89. },
  90. /**
  91. * 分享到朋友圈
  92. * 本接口为 Beta 版本,暂只在 Android 平台支持,详见分享到朋友圈 (Beta)
  93. * https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share-timeline.html
  94. */
  95. onShareTimeline() {
  96. const app = this
  97. const { page } = app
  98. return {
  99. title: page.params.shareTitle,
  100. path: "/pages/custom/index?" + app.$getShareUrlParams({ pageId: app.options.pageId })
  101. }
  102. }
  103. }
  104. </script>
  105. <style lang="scss" scoped>
  106. .container {
  107. background: #fff;
  108. }
  109. </style>