use-empty.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <view class="use-empty-container tac" :class="eStyle == 'round' ? 'padding-sm' : ''" :style="{ height: height }">
  3. <view class="use-empty h-full dflex-c dflex-flow-c" :class="eStyle == 'round' ? 'round border-radius bg-main' : ''">
  4. <image v-if="imgurl" :src="imgurl"></image>
  5. <view v-if="tip" class="title padding-sm">{{tip}}</view>
  6. <button class="no-border use-btn" @click="to">{{btnTip}}</button>
  7. </view>
  8. </view>
  9. </template>
  10. <script>
  11. export default {
  12. props: {
  13. eStyle: {
  14. type: String,
  15. default: 'square'
  16. },
  17. eType: {
  18. type: String,
  19. default: 'other'
  20. },
  21. tip: {
  22. type: String,
  23. default: '暂无数据'
  24. },
  25. btnTip: {
  26. type: String,
  27. default: '去逛逛'
  28. },
  29. btnGoto: {
  30. type: String,
  31. default: '/pages/tabbar/home'
  32. },
  33. auto: {
  34. type: Boolean,
  35. default: !0
  36. },
  37. height: {
  38. type: String,
  39. default: '100vh'
  40. }
  41. },
  42. computed: {
  43. dtype: {
  44. get(){
  45. console.log('get dtype', arguments);
  46. let imgobj = this.imgs.find(x => x.type == this.eType);
  47. this.imgurl = imgobj ? imgobj.url : this.imgurl_dft;
  48. return this.eType
  49. },
  50. set(val){
  51. console.log('set dtype', arguments);
  52. }
  53. }
  54. },
  55. data() {
  56. return {
  57. imgurl_dft: '/static/images/empty/empty.jpg',
  58. imgurl: '',
  59. imgs: [
  60. { type: 'cart', url: '/static/images/empty/cart.jpg' },
  61. { type: 'search', url: '/static/images/empty/search.jpg' },
  62. { type: 'other', url: '/static/images/empty/empty.jpg' }
  63. ]
  64. };
  65. },
  66. methods: {
  67. to() {
  68. this.$emit('goto', {
  69. type: 'goto'
  70. });
  71. if (this.auto) {
  72. // 跳转指定页
  73. uni.switchTab({
  74. url: this.btnGoto
  75. })
  76. }
  77. }
  78. }
  79. };
  80. </script>
  81. <style lang="scss">
  82. .use-empty-container{
  83. .use-empty {
  84. .round {
  85. padding: 25% 50rpx;
  86. button{
  87. width: 220rpx;
  88. }
  89. }
  90. image {
  91. width: 160rpx;
  92. height: 160rpx;
  93. }
  94. .title {
  95. color: #c0c0c0;
  96. }
  97. .use-btn {
  98. font-size: $font-base + 2upx;
  99. display: inline-block;
  100. background-image: $base-bg-gradient-color;
  101. color: #FFF;
  102. }
  103. }
  104. }
  105. </style>