page.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. 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 { globalData } = getApp();
  38. const { pageTemp = {} } = globalData;
  39. const componentData = pageTemp[pageType] || {};
  40. this.setData({
  41. title,
  42. header,
  43. pageType,
  44. componentData,
  45. query: other,
  46. background: background || "#1677FF",
  47. color: color || "#fff",
  48. backBtnColor: backBtnColor || false,
  49. });
  50. },
  51. onUnload() {
  52. if (getApp().globalData.pageTemp) {
  53. delete getApp().globalData.pageTemp[this.data.pageType];
  54. }
  55. },
  56. // 分享
  57. onShareAppMessage() {
  58. const { pageType, query, title } = this.data;
  59. return {
  60. title,
  61. path: `${this.route}?pageType=${pageType}&title=${title}${queryToUrl(
  62. query
  63. )}`,
  64. };
  65. },
  66. });
  67. export default getOptions;