cu-custom.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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':'',bgColor]">
  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. };
  24. },
  25. name: 'cu-custom',
  26. computed: {
  27. style() {
  28. var StatusBar= this.StatusBar;
  29. var CustomBar= this.CustomBar;
  30. var bgImage = this.bgImage;
  31. var style = `height:${CustomBar}px;padding-top:${StatusBar}px;`;
  32. if (this.bgImage) {
  33. style = `${style}background-image:url(${bgImage});`;
  34. }
  35. return style
  36. }
  37. },
  38. props: {
  39. bgColor: {
  40. type: String,
  41. default: ''
  42. },
  43. isBack: {
  44. type: [Boolean, String],
  45. default: false
  46. },
  47. bgImage: {
  48. type: String,
  49. default: ''
  50. },
  51. },
  52. methods: {
  53. BackPage() {
  54. if (getCurrentPages().length < 2 && 'undefined' !== typeof __wxConfig) {
  55. let url = '/' + __wxConfig.pages[0]
  56. return uni.redirectTo({url})
  57. }
  58. uni.navigateBack({
  59. delta: 1
  60. });
  61. }
  62. }
  63. }
  64. </script>
  65. <style>
  66. </style>