cu-custom.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <template>
  2. <view>
  3. <view class="cu-custom" :style="[{height:CustomBar + 'px'}]">
  4. <view class="cu-bar fixed" :style="style" :class="[bgImage!=''?'none-bg text-white bg-img':'', bgColorClass]">
  5. <view class="action" @tap="BackPage" v-if="isBack">
  6. <text class="cuIcon-back"></text>
  7. <slot name="backText"></slot>
  8. </view>
  9. <view class="content" :style="[{top:StatusBar + 'px'}]">
  10. <slot name="content"></slot>
  11. </view>
  12. <slot name="right"></slot>
  13. </view>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. data() {
  20. return {
  21. StatusBar: this.StatusBar,
  22. CustomBar: this.CustomBar,
  23. bgColorClass : 'bg-gradual-pink',
  24. };
  25. },
  26. name: 'cu-custom',
  27. computed: {
  28. style() {
  29. var StatusBar= this.StatusBar;
  30. var CustomBar= this.CustomBar;
  31. var bgImage = this.bgImage;
  32. var style = `height:${CustomBar}px;padding-top:${StatusBar}px;`;
  33. if (this.bgColor) {
  34. var bgColor = this.bgColor;
  35. style = `${style};${bgColor};`;
  36. } else if (this.bgImage) {
  37. style = `${style}background-image:url(${bgImage});`;
  38. }
  39. return style
  40. }
  41. },
  42. props: {
  43. bgColor: {
  44. type: String,
  45. default: ''
  46. },
  47. isBack: {
  48. type: [Boolean, String],
  49. default: false
  50. },
  51. bgImage: {
  52. type: String,
  53. default: ''
  54. },
  55. },
  56. methods: {
  57. BackPage() {
  58. if (this.Dever.source == 'h5') {
  59. window.history.back();
  60. } else {
  61. if (getCurrentPages().length < 2 && 'undefined' !== typeof __wxConfig) {
  62. let url = '/' + __wxConfig.pages[0]
  63. return uni.redirectTo({url})
  64. }
  65. uni.navigateBack({
  66. delta: 1
  67. });
  68. }
  69. }
  70. }
  71. }
  72. </script>
  73. <style>
  74. </style>