index.uvue
3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<template>
<!-- 引用示例:<CustomEmpty preset="contract" :icon="'/static/empty/icon-base-empty.png'" :title="'自定义文案'" :customStyle="{ backgroundColor: '#999999', width: '300rpx' }"/> -->
<view class="empty-wrapper" :style="wrapperStyle">
<!-- 图标插槽,支持完全自定义图标 -->
<slot name="icon">
<image
v-if="showIcon"
class="empty-icon"
:src="iconSrc"
mode="heightFix"
/>
</slot>
<!-- 文字与自定义内容插槽 -->
<slot>
<view class="empty-text">
<text v-if="showTitle" class="empty-title">{{ displayTitle }}</text>
<text v-if="showDescription" class="empty-desc">{{ props.description }}</text>
</view>
</slot>
</view>
</template>
<script setup lang="uts">
import { computed } from 'vue'
import {
EMPTY_FALLBACK_TITLE,
EMPTY_PROP_DEFAULT_DESCRIPTION,
EMPTY_PROP_DEFAULT_ICON,
EMPTY_PROP_DEFAULT_PRESET,
EMPTY_PROP_DEFAULT_TITLE,
getEmptyPreset,
TYPE_ICON_BASE_PATH,
type EmptyTypeConfig
} from './presets.uts'
type Props = {
preset?: String
icon?: String
title?: String
description?: String
customStyle?: any | null
}
const props = withDefaults(defineProps<Props>(), {
preset: EMPTY_PROP_DEFAULT_PRESET,
icon: EMPTY_PROP_DEFAULT_ICON,
title: EMPTY_PROP_DEFAULT_TITLE,
description: EMPTY_PROP_DEFAULT_DESCRIPTION,
customStyle: null
})
const typeConfig = computed<EmptyTypeConfig | null>(() => {
return getEmptyPreset(props.preset)
})
const iconSrc = computed<String>(() => {
if (props.icon != EMPTY_PROP_DEFAULT_ICON) {
return props.icon
}
const config = typeConfig.value
if (config == null) {
return EMPTY_PROP_DEFAULT_ICON
}
return `${TYPE_ICON_BASE_PATH}${config.icon}`
})
const displayTitle = computed<String>(() => {
if (props.title != EMPTY_PROP_DEFAULT_TITLE) {
return props.title
}
const cfg = typeConfig.value
if (cfg == null) {
return EMPTY_FALLBACK_TITLE
}
return cfg.title
})
const wrapperStyle = computed<any>(() => {
return props.customStyle ?? {}
})
const showIcon = computed<boolean>(() => {
return iconSrc.value != EMPTY_PROP_DEFAULT_ICON
})
const showTitle = computed<boolean>(() => {
return displayTitle.value != EMPTY_PROP_DEFAULT_TITLE
})
const showDescription = computed<boolean>(() => {
return props.description != EMPTY_PROP_DEFAULT_DESCRIPTION
})
</script>
<style>
.empty-wrapper {
/* 默认宽高占满容器,居中显示,适配手机与 Pad */
width: 100%;
min-height: 300rpx;
padding: 40rpx 32rpx;
box-sizing: border-box;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.empty-icon {
height: 104px;
width: auto;
}
.empty-text {
display: flex;
flex-direction: column;
align-items: center;
font-size: 12px;
font-weight: 400;
}
.empty-title {
color: #999999;
}
.empty-desc {
color: #999999;
margin-top: 12rpx;
}
</style>