index.vue 2.6 KB

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