diypage.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // nova-travel/page/page-view/page-view.js
  2. var Parse = getApp().Parse;
  3. var company = getApp().globalData.company
  4. var Nova = getApp().Nova;
  5. const getTabs = require("../../utils/getTabs")
  6. Component({
  7. /**
  8. * 组件的属性列表
  9. */
  10. properties: {
  11. pageid: null,
  12. blocks: null,
  13. options: null,
  14. titleColor: {
  15. type: String,
  16. value: '#ffffff'
  17. },
  18. compcb: null,
  19. pulldownTime: { // 生命周期 pulldown:父组件在当前组件页面刷新是触发
  20. type: Number,
  21. value: null,
  22. observer: function (current, old) { // 属性值变化时执行
  23. console.log("pulldown diypage", current, old)
  24. if (current != old) {
  25. this.initPageBlocks().then(result => {
  26. wx.stopPullDownRefresh();
  27. });
  28. }
  29. }
  30. }
  31. // {
  32. // type: Object,
  33. // value: null,
  34. // observer:"update"
  35. // }
  36. },
  37. pageLifetimes: {
  38. // onPullDownRefresh: function(){
  39. // console.log("pulldown diypage",this.data)
  40. // setTimeout(() => {
  41. // wx.stopPullDownRefresh();
  42. // }, 2000);
  43. // }
  44. },
  45. lifetimes: {
  46. detached: function () {
  47. // 在组件实例被从页面节点树移除时执行
  48. },
  49. },
  50. attached: async function () {
  51. // 在组件实例进入页面节点树时执行
  52. console.log("attached diypage", this.data)
  53. this.data.options && this.setData({
  54. pageid: this.data.options.id,
  55. })
  56. this.initPageBlocks()
  57. this.getActiveColor()
  58. },
  59. /**
  60. * 组件的初始数据
  61. */
  62. data: {
  63. activeColor: null,
  64. background: "#ffffff"
  65. },
  66. /**
  67. * 组件的方法列表
  68. */
  69. methods: {
  70. onPullDownRefresh() {
  71. console.log("onpulldown diypage")
  72. // wx.startPullDownRefresh();
  73. this.initPageBlocks().then(result => {
  74. wx.stopPullDownRefresh();
  75. });
  76. },
  77. // 初始化页面区块内容
  78. async initPageBlocks() {
  79. let { pageid } = this.data
  80. console.log(pageid);
  81. if (pageid) {
  82. console.log("initPageBlocks")
  83. let query = new Parse.Query("DiyPage");
  84. let tab = await query.get(pageid);
  85. if (tab && tab.id) {
  86. this.setData({
  87. titleName: tab.get("titleBar") && tab.get("titleBar").title,
  88. titleType: tab.get("titleBar") && tab.get("titleBar").type,
  89. blocks: tab.get("blocks"),
  90. background: tab.get("titleBar") && tab.get("titleBar").backgroundColor
  91. })
  92. }
  93. console.log(this.data)
  94. return true;
  95. } else {
  96. return false
  97. }
  98. },
  99. async getActiveColor() {
  100. let tabbarOption = await getTabs.getDiyTabs()
  101. let activeColor = tabbarOption.activeColor && tabbarOption.activeColor
  102. this.setData({
  103. activeColor
  104. })
  105. },
  106. // 获取父组件传递的数据
  107. update(newValue) {
  108. this.blocks = newValue
  109. console.log(this.blocks)
  110. },
  111. },
  112. pageLifetimes: {
  113. ready: function (ev) {
  114. },
  115. show: function (ev) {
  116. console.log("pageLifetimes", ev)
  117. }
  118. }
  119. })