page.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { createPublish } from 'applet-page-component';
  2. import { queryToUrl } from './index';
  3. const getOptions = () => ({ ...createPublish(),
  4. data: {
  5. pageType: undefined,
  6. componentData: undefined,
  7. query: {},
  8. title: '',
  9. header: 'show',
  10. background: '#1677FF',
  11. color: '#fff',
  12. backBtnColor: '#000000'
  13. },
  14. onReadyHeader({
  15. height
  16. }) {
  17. const {
  18. componentData = {}
  19. } = this.data;
  20. componentData.headerHeight = height;
  21. this.setData({
  22. componentData: { ...componentData
  23. }
  24. });
  25. },
  26. onLoad(query) {
  27. const {
  28. title,
  29. pageType,
  30. header = 'show',
  31. background,
  32. color,
  33. backBtnColor,
  34. ...other
  35. } = query;
  36. title && my.setNavigationBar({
  37. title,
  38. backgroundColor: background || '#1677FF'
  39. });
  40. const {
  41. globalData
  42. } = getApp();
  43. const {
  44. pageTemp = {}
  45. } = globalData;
  46. const componentData = pageTemp[pageType] || {};
  47. this.setData({
  48. title,
  49. header,
  50. pageType,
  51. componentData,
  52. query: other,
  53. background: background || '#1677FF',
  54. color: color || '#fff',
  55. backBtnColor: backBtnColor || false
  56. });
  57. },
  58. onUnload() {
  59. if (getApp().globalData.pageTemp) {
  60. delete getApp().globalData.pageTemp[this.data.pageType];
  61. }
  62. },
  63. // 分享
  64. onShareAppMessage() {
  65. const {
  66. pageType,
  67. query,
  68. title
  69. } = this.data;
  70. return {
  71. title,
  72. path: `${this.route}?pageType=${pageType}&title=${title}${queryToUrl(query)}`
  73. };
  74. }
  75. });
  76. export default getOptions;