cu-custom.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. <!-- 返回 -->
  6. <view class="action" @tap="BackPage" v-if="isBack">
  7. <image style="width: 32rpx;height: 32rpx;margin-right: 16rpx;" src="/static/user/bask.png"></image>
  8. <slot name="backText"> </slot>
  9. </view>
  10. <view class="action" v-else>
  11. <slot name="backText"></slot>
  12. </view>
  13. <!-- 居中标题 -->
  14. <view class="action" :style="[{top:StatusBar + 'px'}]">
  15. <slot name="content"></slot>
  16. </view>
  17. <!-- 最右端内容 -->
  18. <view class="action" :style="[{top:StatusBar + 'px'}]" >
  19. <slot name="right"></slot>
  20. </view>
  21. </view>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. export default {
  27. data() {
  28. return {
  29. StatusBar: this.StatusBar,
  30. CustomBar: this.CustomBar
  31. };
  32. },
  33. name: 'cu-custom',
  34. computed: {
  35. style() {
  36. var StatusBar= this.StatusBar;
  37. var CustomBar= this.CustomBar;
  38. var bgImage = this.bgImage;
  39. var style = `height:${CustomBar}px;padding-top:${StatusBar}px;`;
  40. if (this.bgImage) {
  41. style = `${style}background-image:url(${bgImage});`;
  42. }
  43. return style
  44. }
  45. },
  46. props: {
  47. bgColor: {
  48. type: String,
  49. default: ''
  50. },
  51. isBack: {
  52. type: [Boolean, String],
  53. default: false
  54. },
  55. isBackIndex: {
  56. type: [Boolean, String],
  57. default: true
  58. },
  59. backNum:{
  60. type:Number,
  61. default:0
  62. },
  63. bgImage: {
  64. type: String,
  65. default: ''
  66. },
  67. },
  68. methods: {
  69. BackPage() {
  70. if(this.isBackIndex){
  71. if(this.backNum){
  72. uni.navigateBack({
  73. delta: this.backNum
  74. });
  75. }
  76. uni.navigateBack({
  77. delta: 1
  78. });
  79. }else{
  80. uni.navigateTo({
  81. url:"/pages/index/index"
  82. })
  83. }
  84. }
  85. }
  86. }
  87. </script>
  88. <style>
  89. .cu-bar .action:last-child {
  90. margin-right: 5px;
  91. }
  92. </style>