guangchao.xu | 070005a | 2020-12-07 09:56:40 +0800 | [diff] [blame^] | 1 | <template> |
| 2 | <view class="u-empty" v-if="show" :style="{ |
| 3 | marginTop: marginTop + 'rpx' |
| 4 | }"> |
| 5 | <u-icon |
| 6 | :name="src ? src : 'empty-' + mode" |
| 7 | :custom-style="iconStyle" |
| 8 | :label="text ? text : icons[mode]" |
| 9 | label-pos="bottom" |
| 10 | :label-color="color" |
| 11 | :label-size="fontSize" |
| 12 | :size="iconSize" |
| 13 | :color="iconColor" |
| 14 | margin-top="14" |
| 15 | ></u-icon> |
| 16 | <view class="u-slot-wrap"> |
| 17 | <slot name="bottom"></slot> |
| 18 | </view> |
| 19 | </view> |
| 20 | </template> |
| 21 | |
| 22 | <script> |
| 23 | /** |
| 24 | * empty 内容为空 |
| 25 | * @description 该组件用于需要加载内容,但是加载的第一页数据就为空,提示一个"没有内容"的场景, 我们精心挑选了十几个场景的图标,方便您使用。 |
| 26 | * @tutorial https://www.uviewui.com/components/empty.html |
| 27 | * @property {String} color 文字颜色(默认#c0c4cc) |
| 28 | * @property {String} text 文字提示(默认“无内容”) |
| 29 | * @property {String} src 自定义图标路径,如定义,mode参数会失效 |
| 30 | * @property {String Number} font-size 提示文字的大小,单位rpx(默认28) |
| 31 | * @property {String} mode 内置的图标,见官网说明(默认data) |
| 32 | * @property {String Number} img-width 图标的宽度,单位rpx(默认240) |
| 33 | * @property {String} img-height 图标的高度,单位rpx(默认auto) |
| 34 | * @property {String Number} margin-top 组件距离上一个元素之间的距离(默认0) |
| 35 | * @property {Boolean} show 是否显示组件(默认true) |
| 36 | * @event {Function} click 点击组件时触发 |
| 37 | * @event {Function} close 点击关闭按钮时触发 |
| 38 | * @example <u-empty text="所谓伊人,在水一方" mode="list"></u-empty> |
| 39 | */ |
| 40 | export default { |
| 41 | name: "u-empty", |
| 42 | props: { |
| 43 | // 图标路径 |
| 44 | src: { |
| 45 | type: String, |
| 46 | default: '' |
| 47 | }, |
| 48 | // 提示文字 |
| 49 | text: { |
| 50 | type: String, |
| 51 | default: '' |
| 52 | }, |
| 53 | // 文字颜色 |
| 54 | color: { |
| 55 | type: String, |
| 56 | default: '#c0c4cc' |
| 57 | }, |
| 58 | // 图标的颜色 |
| 59 | iconColor: { |
| 60 | type: String, |
| 61 | default: '#c0c4cc' |
| 62 | }, |
| 63 | // 图标的大小 |
| 64 | iconSize: { |
| 65 | type: [String, Number], |
| 66 | default: 120 |
| 67 | }, |
| 68 | // 文字大小,单位rpx |
| 69 | fontSize: { |
| 70 | type: [String, Number], |
| 71 | default: 26 |
| 72 | }, |
| 73 | // 选择预置的图标类型 |
| 74 | mode: { |
| 75 | type: String, |
| 76 | default: 'data' |
| 77 | }, |
| 78 | // 图标宽度,单位rpx |
| 79 | imgWidth: { |
| 80 | type: [String, Number], |
| 81 | default: 120 |
| 82 | }, |
| 83 | // 图标高度,单位rpx |
| 84 | imgHeight: { |
| 85 | type: [String, Number], |
| 86 | default: 'auto' |
| 87 | }, |
| 88 | // 是否显示组件 |
| 89 | show: { |
| 90 | type: Boolean, |
| 91 | default: true |
| 92 | }, |
| 93 | // 组件距离上一个元素之间的距离 |
| 94 | marginTop: { |
| 95 | type: [String, Number], |
| 96 | default: 0 |
| 97 | }, |
| 98 | iconStyle: { |
| 99 | type: Object, |
| 100 | default() { |
| 101 | return {} |
| 102 | } |
| 103 | } |
| 104 | }, |
| 105 | data() { |
| 106 | return { |
| 107 | icons: { |
| 108 | car: '购物车为空', |
| 109 | page: '页面不存在', |
| 110 | search: '没有搜索结果', |
| 111 | address: '没有收货地址', |
| 112 | wifi: '没有WiFi', |
| 113 | order: '订单为空', |
| 114 | coupon: '没有优惠券', |
| 115 | favor: '暂无收藏', |
| 116 | permission: '无权限', |
| 117 | history: '无历史记录', |
| 118 | news: '无新闻列表', |
| 119 | message: '消息列表为空', |
| 120 | list: '列表为空', |
| 121 | data: '数据为空' |
| 122 | }, |
| 123 | // icons: [{ |
| 124 | // icon: 'car', |
| 125 | // text: '购物车为空' |
| 126 | // },{ |
| 127 | // icon: 'page', |
| 128 | // text: '页面不存在' |
| 129 | // },{ |
| 130 | // icon: 'search', |
| 131 | // text: '没有搜索结果' |
| 132 | // },{ |
| 133 | // icon: 'address', |
| 134 | // text: '没有收货地址' |
| 135 | // },{ |
| 136 | // icon: 'wifi', |
| 137 | // text: '没有WiFi' |
| 138 | // },{ |
| 139 | // icon: 'order', |
| 140 | // text: '订单为空' |
| 141 | // },{ |
| 142 | // icon: 'coupon', |
| 143 | // text: '没有优惠券' |
| 144 | // },{ |
| 145 | // icon: 'favor', |
| 146 | // text: '暂无收藏' |
| 147 | // },{ |
| 148 | // icon: 'permission', |
| 149 | // text: '无权限' |
| 150 | // },{ |
| 151 | // icon: 'history', |
| 152 | // text: '无历史记录' |
| 153 | // },{ |
| 154 | // icon: 'news', |
| 155 | // text: '无新闻列表' |
| 156 | // },{ |
| 157 | // icon: 'message', |
| 158 | // text: '消息列表为空' |
| 159 | // },{ |
| 160 | // icon: 'list', |
| 161 | // text: '列表为空' |
| 162 | // },{ |
| 163 | // icon: 'data', |
| 164 | // text: '数据为空' |
| 165 | // }], |
| 166 | |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | </script> |
| 171 | |
| 172 | <style scoped lang="scss"> |
| 173 | @import "../../libs/css/style.components.scss"; |
| 174 | |
| 175 | .u-empty { |
| 176 | @include vue-flex; |
| 177 | flex-direction: column; |
| 178 | justify-content: center; |
| 179 | align-items: center; |
| 180 | height: 100%; |
| 181 | } |
| 182 | |
| 183 | .u-image { |
| 184 | margin-bottom: 20rpx; |
| 185 | } |
| 186 | |
| 187 | .u-slot-wrap { |
| 188 | @include vue-flex; |
| 189 | justify-content: center; |
| 190 | align-items: center; |
| 191 | margin-top: 20rpx; |
| 192 | } |
| 193 | </style> |