page.js 1.7 KB

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