page.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. console.log("title ===>", title);
  33. title &&
  34. my.setNavigationBar({
  35. title,
  36. backgroundColor: background || "#1677FF",
  37. });
  38. const app = getApp();
  39. const { globalData } = app;
  40. const { pageTemp = {} } = globalData;
  41. const componentData = pageTemp[pageType] || {};
  42. this.setData({
  43. title,
  44. header,
  45. pageType,
  46. componentData,
  47. query: other,
  48. background: background || "#1677FF",
  49. color: color || "#fff",
  50. backBtnColor: backBtnColor || false,
  51. });
  52. if (!app.globalData.templateUUID) {
  53. // 如果没有页面配置,需要获取页面配置,否则下面bind的时候没有templateUUID
  54. await this.dispatch("init", query);
  55. title &&
  56. my.setNavigationBar({
  57. title,
  58. backgroundColor: background || "#1677FF",
  59. });
  60. }
  61. },
  62. onUnload() {
  63. if (getApp().globalData.pageTemp) {
  64. delete getApp().globalData.pageTemp[this.data.pageType];
  65. }
  66. },
  67. // 分享
  68. onShareAppMessage() {
  69. const { pageType, query, title } = this.data;
  70. return {
  71. title,
  72. path: `${this.route}?pageType=${pageType}&title=${title}${queryToUrl(
  73. query
  74. )}`,
  75. };
  76. },
  77. });
  78. export default getOptions;