index.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. if (!Math) {
  4. StatusBar();
  5. }
  6. const StatusBar = () => "./StatusBar.js";
  7. const _sfc_main = {
  8. __name: "index",
  9. props: {
  10. title: { type: String },
  11. hideLeft: { type: Boolean, default: false },
  12. warn: { type: Boolean, default: false },
  13. // 警告
  14. shadow: { type: Boolean, default: false }
  15. // 警告
  16. },
  17. setup(__props) {
  18. const systemInfo = common_vendor.index.getWindowInfo();
  19. let menuButtonInfo = {};
  20. menuButtonInfo = common_vendor.index.getMenuButtonBoundingClientRect();
  21. const props = __props;
  22. const slots = common_vendor.useSlots();
  23. const getIsHome = common_vendor.computed(() => {
  24. const pages = getCurrentPages();
  25. return pages.length >= 2;
  26. });
  27. const ifShowRight = common_vendor.computed(() => slots.right || props.warn);
  28. const statusBarHeight = common_vendor.computed(() => systemInfo.statusBarHeight);
  29. const getNavWrapStyle = common_vendor.computed(() => {
  30. const { windowWidth } = systemInfo;
  31. const { top, right, height } = menuButtonInfo;
  32. return {
  33. padding: `${top - common_vendor.unref(statusBarHeight)}px ${windowWidth - right}px`,
  34. height: `${height + (top - common_vendor.unref(statusBarHeight)) * 2}px`
  35. };
  36. });
  37. const getNavBarContent = common_vendor.computed(() => {
  38. const { width } = menuButtonInfo;
  39. const style = {};
  40. if (common_vendor.unref(ifShowRight)) {
  41. style.paddingRight = width + "px";
  42. } else {
  43. style.position = "absolute";
  44. style.width = "100%";
  45. style.top = "0";
  46. style.bottom = "0";
  47. style.zIndex = "-1";
  48. style.padding = `0 ${width + 10}px`;
  49. }
  50. return style;
  51. });
  52. function go(type) {
  53. switch (type) {
  54. case "back":
  55. common_vendor.index.navigateBack();
  56. break;
  57. case "home":
  58. common_vendor.index.reLaunch({
  59. url: "/pages/index/index"
  60. });
  61. break;
  62. default:
  63. common_vendor.index.navigateTo({ url: type });
  64. break;
  65. }
  66. }
  67. return (_ctx, _cache) => {
  68. return common_vendor.e({
  69. a: !__props.hideLeft
  70. }, !__props.hideLeft ? {
  71. b: common_vendor.o(($event) => go("back")),
  72. c: common_vendor.o(($event) => go("home")),
  73. d: !getIsHome.value ? 1 : ""
  74. } : {}, {
  75. e: common_vendor.t(__props.title),
  76. f: ifShowRight.value
  77. }, ifShowRight.value ? {} : {}, {
  78. g: ifShowRight.value ? 1 : "",
  79. h: common_vendor.s(getNavBarContent.value),
  80. i: common_vendor.s(getNavWrapStyle.value),
  81. j: __props.shadow ? 1 : ""
  82. });
  83. };
  84. }
  85. };
  86. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-1633aa0e"]]);
  87. wx.createComponent(Component);
  88. //# sourceMappingURL=../../../.sourcemap/mp-weixin/components/NavBar/index.js.map