| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- <template>
- <view class="empty-state" :style="containerStyle">
- <!-- 空状态图标 -->
- <view class="empty-icon-box" :style="iconBoxStyle">
- <image
- v-if="image"
- class="empty-image"
- :src="image"
- mode="aspectFit"
- />
- <uni-icons
- v-else
- :type="icon"
- :size="iconSize"
- :color="iconColor"
- ></uni-icons>
- </view>
- <!-- 提示文字 -->
- <text class="empty-text" :style="textStyle">{{ text }}</text>
- <!-- 副文字(可选) -->
- <text v-if="subText" class="empty-sub-text">{{ subText }}</text>
- <!-- 操作按钮(可选) -->
- <view v-if="showBtn" class="empty-btn" :style="btnStyle" @click="handleClick">
- <text class="empty-btn-text">{{ btnText }}</text>
- </view>
- </view>
- </template>
- <script setup>
- import { computed } from 'vue'
- const props = defineProps({
- // 提示文字
- text: {
- type: String,
- default: '暂无数据'
- },
- // 副文字
- subText: {
- type: String,
- default: ''
- },
- // 图标名称(uni-icons type)
- icon: {
- type: String,
- default: 'list'
- },
- // 图标大小
- iconSize: {
- type: Number,
- default: 80
- },
- // 图标颜色
- iconColor: {
- type: String,
- default: '#CCCCCC'
- },
- // 自定义图片(优先级高于icon)
- image: {
- type: String,
- default: '/static/image/public/no-data.png'
- },
- // 是否显示按钮
- showBtn: {
- type: Boolean,
- default: false
- },
- // 按钮文字
- btnText: {
- type: String,
- default: '刷新'
- },
- // 按钮颜色
- btnColor: {
- type: String,
- default: '#4080FF'
- },
- // 上边距(rpx)
- marginTop: {
- type: Number,
- default: 120
- },
- // 下边距(rpx)
- marginBottom: {
- type: Number,
- default: 0
- }
- })
- const emit = defineEmits(['click'])
- const containerStyle = computed(() => {
- return {
- marginTop: (props.marginTop / 2) + 'px',
- marginBottom: (props.marginBottom / 2) + 'px'
- }
- })
- const iconBoxStyle = computed(() => {
- return {
- width: (props.iconSize * 1.5 / 2) + 'px',
- height: (props.iconSize * 1.5 / 2) + 'px'
- }
- })
- const textStyle = computed(() => {
- return {
- color: '#999999'
- }
- })
- const btnStyle = computed(() => {
- return {
- backgroundColor: props.btnColor
- }
- })
- const handleClick = () => {
- emit('click')
- }
- </script>
- <style scoped>
- .empty-state {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- padding: 60rpx 40rpx;
- }
- .empty-icon-box {
- display: flex;
- align-items: center;
- justify-content: center;
- margin-bottom: 32rpx;
- border-radius: 50%;
- background: #f5f6f8;
- }
- .empty-image {
- width: 100%;
- height: 100%;
- }
- .empty-text {
- font-size: 28rpx;
- color: #999999;
- line-height: 1.5;
- text-align: center;
- }
- .empty-sub-text {
- font-size: 24rpx;
- color: #BBBBBB;
- margin-top: 12rpx;
- text-align: center;
- line-height: 1.5;
- }
- .empty-btn {
- margin-top: 40rpx;
- padding: 16rpx 56rpx;
- border-radius: 40rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- .empty-btn-text {
- font-size: 28rpx;
- color: #FFFFFF;
- font-weight: 500;
- }
- </style>
|