custom-nav-bar.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const common_assets = require("../../common/assets.js");
  4. const _sfc_main = {
  5. data() {
  6. return {
  7. logoImage: common_assets._imports_0,
  8. opacity: 0,
  9. scrollTop: 0,
  10. statusBarHeight: 0,
  11. // 状态按钮高度
  12. myback: {
  13. show: true
  14. },
  15. // top样式
  16. topStyle: {}
  17. };
  18. },
  19. props: {
  20. // 标题内容
  21. title: String,
  22. // 标题颜色
  23. titleColor: {
  24. type: String,
  25. default: "#000000"
  26. },
  27. // 返回按钮相关配置
  28. back: {
  29. type: Object,
  30. default: function() {
  31. return {
  32. // 是否显示返回按钮,默认显示
  33. show: true,
  34. logoShow: false
  35. // 返回按钮的图片地址
  36. // imgUrl: require('../../static/images/ico_back.png')
  37. };
  38. }
  39. },
  40. // 开启背景图片,未开启,使用背景颜色,开启backgroundImage为必填项
  41. backgroundImageShow: {
  42. type: Boolean,
  43. default: false
  44. },
  45. // 背景颜色,支持渐变色,如:linear-gradient(to top right, #CDDC39, #8BC34A, #FFEB3B);
  46. backgroundColor: {
  47. type: String,
  48. default: "linear-gradient(to top right, #CDDC39, #8BC34A, #FFEB3B)"
  49. },
  50. // 背景图片地址,使用前需配置backgroundImageShow为true。
  51. backgroundImage: String,
  52. // 是否保存顶部栏高度
  53. hideHeight: {
  54. type: Boolean,
  55. default: true
  56. },
  57. // 高度(除状态栏)
  58. topHeight: {
  59. type: Number,
  60. default: 80
  61. }
  62. },
  63. mounted() {
  64. this.init();
  65. },
  66. methods: {
  67. goBack() {
  68. const data = getCurrentPages();
  69. if (data.length > 1) {
  70. common_vendor.index.navigateBack();
  71. } else {
  72. common_vendor.index.switchTab({
  73. url: `/pages/index/index`
  74. });
  75. }
  76. },
  77. init() {
  78. this.statusBarHeight = this.getSysInfo().statusBarHeight;
  79. for (let key in this.back) {
  80. this.myback[key] = this.back[key];
  81. }
  82. },
  83. getSysInfo() {
  84. return common_vendor.index.getSystemInfoSync();
  85. },
  86. // 转接到达顶部距离参数
  87. scrollScroll(event) {
  88. this.scrollTop = event;
  89. if (event < 200) {
  90. this.opacity = event / 100 / 2;
  91. } else {
  92. this.opacity = 1;
  93. }
  94. }
  95. }
  96. };
  97. if (!Array) {
  98. const _easycom_u_icon2 = common_vendor.resolveComponent("u-icon");
  99. _easycom_u_icon2();
  100. }
  101. const _easycom_u_icon = () => "../../uni_modules/uview-plus/components/u-icon/u-icon.js";
  102. if (!Math) {
  103. _easycom_u_icon();
  104. }
  105. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  106. return common_vendor.e({
  107. a: common_vendor.s("height: " + $data.statusBarHeight + "px"),
  108. b: common_vendor.s("height: " + $props.topHeight + "rpx"),
  109. c: !$props.backgroundImageShow ? $props.backgroundColor : "url(" + $props.backgroundImage + ") no-repeat;",
  110. d: $data.opacity,
  111. e: common_vendor.s("height: " + $data.statusBarHeight + "px"),
  112. f: $data.myback.show
  113. }, $data.myback.show ? {
  114. g: common_vendor.p({
  115. size: "20",
  116. name: "arrow-left"
  117. }),
  118. h: common_vendor.o((...args) => $options.goBack && $options.goBack(...args))
  119. } : {}, {
  120. i: $data.myback.logoShow
  121. }, $data.myback.logoShow ? {
  122. j: $data.logoImage,
  123. k: common_vendor.o((...args) => $options.goBack && $options.goBack(...args))
  124. } : {}, {
  125. l: common_vendor.t($props.title),
  126. m: $props.titleColor,
  127. n: common_vendor.s("height:" + $props.topHeight + "rpx"),
  128. o: common_vendor.s("height: calc(" + $data.statusBarHeight + "px + " + $props.topHeight + "rpx)")
  129. });
  130. }
  131. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-10729898"]]);
  132. wx.createComponent(Component);