@atooyu/uxto-ui 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +259 -0
- package/dist/index.js +5055 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +5055 -0
- package/dist/index.mjs.map +1 -0
- package/dist/style.css +2528 -0
- package/package.json +93 -0
- package/src/components/index.ts +51 -0
- package/src/components/u-avatar/u-avatar.vue +205 -0
- package/src/components/u-badge/u-badge.vue +145 -0
- package/src/components/u-button/u-button.vue +239 -0
- package/src/components/u-cell/u-cell.vue +179 -0
- package/src/components/u-cell-group/u-cell-group.vue +46 -0
- package/src/components/u-checkbox/u-checkbox.vue +174 -0
- package/src/components/u-checkbox-group/u-checkbox-group.vue +72 -0
- package/src/components/u-code-input/u-code-input.vue +248 -0
- package/src/components/u-count-down/u-count-down.vue +182 -0
- package/src/components/u-datetime-picker/u-datetime-picker.vue +377 -0
- package/src/components/u-divider/u-divider.vue +71 -0
- package/src/components/u-empty/u-empty.vue +98 -0
- package/src/components/u-grid/u-grid.vue +63 -0
- package/src/components/u-grid-item/u-grid-item.vue +170 -0
- package/src/components/u-icon/icons/account.svg +3 -0
- package/src/components/u-icon/icons/arrow-down.svg +3 -0
- package/src/components/u-icon/icons/arrow-left.svg +3 -0
- package/src/components/u-icon/icons/arrow-right.svg +3 -0
- package/src/components/u-icon/icons/arrow-up.svg +3 -0
- package/src/components/u-icon/icons/bell.svg +3 -0
- package/src/components/u-icon/icons/bookmark-o.svg +3 -0
- package/src/components/u-icon/icons/bookmark.svg +3 -0
- package/src/components/u-icon/icons/chat.svg +3 -0
- package/src/components/u-icon/icons/check-circle.svg +3 -0
- package/src/components/u-icon/icons/check.svg +3 -0
- package/src/components/u-icon/icons/chevron-left.svg +3 -0
- package/src/components/u-icon/icons/chevron-right.svg +3 -0
- package/src/components/u-icon/icons/clear-o.svg +3 -0
- package/src/components/u-icon/icons/clear.svg +3 -0
- package/src/components/u-icon/icons/clipboard.svg +3 -0
- package/src/components/u-icon/icons/clock.svg +3 -0
- package/src/components/u-icon/icons/close.svg +3 -0
- package/src/components/u-icon/icons/code.svg +3 -0
- package/src/components/u-icon/icons/copy.svg +3 -0
- package/src/components/u-icon/icons/delete.svg +3 -0
- package/src/components/u-icon/icons/download.svg +3 -0
- package/src/components/u-icon/icons/edit.svg +3 -0
- package/src/components/u-icon/icons/email.svg +3 -0
- package/src/components/u-icon/icons/error-o.svg +3 -0
- package/src/components/u-icon/icons/error.svg +3 -0
- package/src/components/u-icon/icons/exit-fullscreen.svg +3 -0
- package/src/components/u-icon/icons/expand-less.svg +3 -0
- package/src/components/u-icon/icons/expand-more.svg +3 -0
- package/src/components/u-icon/icons/eye-off.svg +3 -0
- package/src/components/u-icon/icons/eye.svg +3 -0
- package/src/components/u-icon/icons/flag-o.svg +3 -0
- package/src/components/u-icon/icons/flag.svg +3 -0
- package/src/components/u-icon/icons/fullscreen.svg +3 -0
- package/src/components/u-icon/icons/grid.svg +3 -0
- package/src/components/u-icon/icons/group.svg +3 -0
- package/src/components/u-icon/icons/heart-o.svg +3 -0
- package/src/components/u-icon/icons/heart.svg +3 -0
- package/src/components/u-icon/icons/info-o.svg +3 -0
- package/src/components/u-icon/icons/info.svg +3 -0
- package/src/components/u-icon/icons/keyboard-arrow-down.svg +3 -0
- package/src/components/u-icon/icons/keyboard-arrow-left.svg +3 -0
- package/src/components/u-icon/icons/keyboard-arrow-right.svg +3 -0
- package/src/components/u-icon/icons/keyboard-arrow-up.svg +3 -0
- package/src/components/u-icon/icons/like-o.svg +3 -0
- package/src/components/u-icon/icons/like.svg +3 -0
- package/src/components/u-icon/icons/link.svg +3 -0
- package/src/components/u-icon/icons/list.svg +3 -0
- package/src/components/u-icon/icons/loading.svg +3 -0
- package/src/components/u-icon/icons/lock.svg +3 -0
- package/src/components/u-icon/icons/menu-o.svg +3 -0
- package/src/components/u-icon/icons/menu.svg +3 -0
- package/src/components/u-icon/icons/message.svg +3 -0
- package/src/components/u-icon/icons/minus.svg +3 -0
- package/src/components/u-icon/icons/notification.svg +3 -0
- package/src/components/u-icon/icons/phone.svg +3 -0
- package/src/components/u-icon/icons/plus.svg +3 -0
- package/src/components/u-icon/icons/question.svg +3 -0
- package/src/components/u-icon/icons/redo.svg +3 -0
- package/src/components/u-icon/icons/refresh-o.svg +3 -0
- package/src/components/u-icon/icons/refresh.svg +3 -0
- package/src/components/u-icon/icons/reload.svg +3 -0
- package/src/components/u-icon/icons/search-o.svg +3 -0
- package/src/components/u-icon/icons/search.svg +3 -0
- package/src/components/u-icon/icons/setting.svg +3 -0
- package/src/components/u-icon/icons/share.svg +3 -0
- package/src/components/u-icon/icons/smile-o.svg +3 -0
- package/src/components/u-icon/icons/smile.svg +3 -0
- package/src/components/u-icon/icons/star-o.svg +3 -0
- package/src/components/u-icon/icons/star.svg +3 -0
- package/src/components/u-icon/icons/success-o.svg +3 -0
- package/src/components/u-icon/icons/success.svg +3 -0
- package/src/components/u-icon/icons/sync.svg +3 -0
- package/src/components/u-icon/icons/tick.svg +3 -0
- package/src/components/u-icon/icons/undo.svg +3 -0
- package/src/components/u-icon/icons/unlock.svg +3 -0
- package/src/components/u-icon/icons/upload.svg +3 -0
- package/src/components/u-icon/icons/user.svg +3 -0
- package/src/components/u-icon/icons/warning-o.svg +3 -0
- package/src/components/u-icon/icons/warning.svg +3 -0
- package/src/components/u-icon/icons/zoom-in.svg +3 -0
- package/src/components/u-icon/icons/zoom-out.svg +3 -0
- package/src/components/u-icon/index.ts +219 -0
- package/src/components/u-icon/u-icon.vue +117 -0
- package/src/components/u-image/u-image.vue +106 -0
- package/src/components/u-input/u-input.vue +208 -0
- package/src/components/u-keyboard/u-keyboard.vue +213 -0
- package/src/components/u-layout/u-layout.vue +58 -0
- package/src/components/u-line-progress/u-line-progress.vue +156 -0
- package/src/components/u-link/u-link.vue +113 -0
- package/src/components/u-list/u-list.vue +148 -0
- package/src/components/u-list-item/u-list-item.vue +180 -0
- package/src/components/u-loading/u-loading.vue +80 -0
- package/src/components/u-loading-page/u-loading-page.vue +94 -0
- package/src/components/u-modal/u-modal.vue +159 -0
- package/src/components/u-notice-bar/u-notice-bar.vue +113 -0
- package/src/components/u-number-box/u-number-box.vue +262 -0
- package/src/components/u-parse/u-parse.vue +197 -0
- package/src/components/u-picker/u-picker.vue +219 -0
- package/src/components/u-popup/u-popup.vue +257 -0
- package/src/components/u-radio/u-radio.vue +159 -0
- package/src/components/u-radio-group/u-radio-group.vue +61 -0
- package/src/components/u-rate/u-rate.vue +187 -0
- package/src/components/u-read-more/u-read-more.vue +117 -0
- package/src/components/u-search/u-search.vue +238 -0
- package/src/components/u-skeleton/u-skeleton.vue +192 -0
- package/src/components/u-slider/u-slider.vue +453 -0
- package/src/components/u-swiper/u-swiper.vue +301 -0
- package/src/components/u-swiper-item/u-swiper-item.vue +82 -0
- package/src/components/u-switch/u-switch.vue +105 -0
- package/src/components/u-tabbar/u-tabbar.vue +221 -0
- package/src/components/u-tag/u-tag.vue +144 -0
- package/src/components/u-textarea/u-textarea.vue +189 -0
- package/src/components/u-toast/u-toast.vue +186 -0
- package/src/components/u-tooltip/u-tooltip.vue +364 -0
- package/src/components/u-transition/u-transition.vue +216 -0
- package/src/components/u-upload/u-upload.vue +403 -0
- package/src/styles/index.scss +59 -0
- package/src/styles/variables.scss +68 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="u-read-more">
|
|
3
|
+
<view
|
|
4
|
+
class="u-read-more__content"
|
|
5
|
+
:style="contentStyle"
|
|
6
|
+
>
|
|
7
|
+
<slot />
|
|
8
|
+
</view>
|
|
9
|
+
<view
|
|
10
|
+
v-if="showToggle"
|
|
11
|
+
class="u-read-more__toggle"
|
|
12
|
+
@click="handleToggle"
|
|
13
|
+
>
|
|
14
|
+
<text class="u-read-more__toggle-text">{{ toggleText }}</text>
|
|
15
|
+
<text class="u-read-more__toggle-icon">{{ expanded ? '↑' : '↓' }}</text>
|
|
16
|
+
</view>
|
|
17
|
+
</view>
|
|
18
|
+
</template>
|
|
19
|
+
|
|
20
|
+
<script setup lang="ts">
|
|
21
|
+
import { computed, ref, watch } from 'vue'
|
|
22
|
+
|
|
23
|
+
interface Props {
|
|
24
|
+
maxLength?: number
|
|
25
|
+
rows?: number
|
|
26
|
+
expandText?: string
|
|
27
|
+
collapseText?: string
|
|
28
|
+
autoCollapse?: boolean
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
32
|
+
maxLength: 200,
|
|
33
|
+
rows: 3,
|
|
34
|
+
expandText: '展开',
|
|
35
|
+
collapseText: '收起',
|
|
36
|
+
autoCollapse: false
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
const emit = defineEmits<{
|
|
40
|
+
(e: 'expand'): void
|
|
41
|
+
(e: 'collapse'): void
|
|
42
|
+
}>()
|
|
43
|
+
|
|
44
|
+
const expanded = ref(false)
|
|
45
|
+
const showToggle = ref(true)
|
|
46
|
+
|
|
47
|
+
// 内容区域样式
|
|
48
|
+
const contentStyle = computed(() => {
|
|
49
|
+
if (expanded.value) {
|
|
50
|
+
return {}
|
|
51
|
+
}
|
|
52
|
+
// 使用 line-clamp 限制行数
|
|
53
|
+
return {
|
|
54
|
+
display: '-webkit-box',
|
|
55
|
+
overflow: 'hidden',
|
|
56
|
+
textOverflow: 'ellipsis',
|
|
57
|
+
webkitLineClamp: String(props.rows),
|
|
58
|
+
webkitBoxOrient: 'vertical'
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
// 切换按钮文字
|
|
63
|
+
const toggleText = computed(() => {
|
|
64
|
+
return expanded.value ? props.collapseText : props.expandText
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
// 切换展开/收起
|
|
68
|
+
const handleToggle = () => {
|
|
69
|
+
expanded.value = !expanded.value
|
|
70
|
+
|
|
71
|
+
if (expanded.value) {
|
|
72
|
+
emit('expand')
|
|
73
|
+
} else {
|
|
74
|
+
emit('collapse')
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
</script>
|
|
78
|
+
|
|
79
|
+
<script lang="ts">
|
|
80
|
+
export default {
|
|
81
|
+
options: {
|
|
82
|
+
virtualHost: true,
|
|
83
|
+
styleIsolation: 'shared'
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
</script>
|
|
87
|
+
|
|
88
|
+
<style lang="scss" scoped>
|
|
89
|
+
.u-read-more {
|
|
90
|
+
&__content {
|
|
91
|
+
font-size: $--font-size-md;
|
|
92
|
+
color: $--text-color;
|
|
93
|
+
line-height: 1.6;
|
|
94
|
+
word-break: break-all;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
&__toggle {
|
|
98
|
+
display: inline-flex;
|
|
99
|
+
align-items: center;
|
|
100
|
+
margin-top: $--spacing-sm;
|
|
101
|
+
color: $--color-primary;
|
|
102
|
+
font-size: $--font-size-md;
|
|
103
|
+
|
|
104
|
+
&:active {
|
|
105
|
+
opacity: 0.7;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
&__toggle-text {
|
|
110
|
+
margin-right: $--spacing-xs;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
&__toggle-icon {
|
|
114
|
+
font-size: $--font-size-sm;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
</style>
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view
|
|
3
|
+
class="u-search"
|
|
4
|
+
:class="{
|
|
5
|
+
'u-search--disabled': disabled,
|
|
6
|
+
'u-search--focus': isFocus
|
|
7
|
+
}"
|
|
8
|
+
>
|
|
9
|
+
<view class="u-search__content" :style="contentStyle">
|
|
10
|
+
<view v-if="showSearchIcon" class="u-search__icon">
|
|
11
|
+
<text class="u-search__icon-text">🔍</text>
|
|
12
|
+
</view>
|
|
13
|
+
|
|
14
|
+
<view class="u-search__body">
|
|
15
|
+
<input
|
|
16
|
+
class="u-search__control"
|
|
17
|
+
:type="type"
|
|
18
|
+
:value="modelValue"
|
|
19
|
+
:placeholder="placeholder"
|
|
20
|
+
:placeholder-style="placeholderStyle"
|
|
21
|
+
:placeholder-class="'u-search__placeholder'"
|
|
22
|
+
:disabled="disabled"
|
|
23
|
+
:maxlength="maxlength"
|
|
24
|
+
:focus="focus"
|
|
25
|
+
:confirm-type="confirmType"
|
|
26
|
+
:adjust-position="adjustPosition"
|
|
27
|
+
@input="handleInput"
|
|
28
|
+
@focus="handleFocus"
|
|
29
|
+
@blur="handleBlur"
|
|
30
|
+
@confirm="handleSearch"
|
|
31
|
+
/>
|
|
32
|
+
</view>
|
|
33
|
+
|
|
34
|
+
<view v-if="clearable && modelValue" class="u-search__clear" @click="handleClear">
|
|
35
|
+
<text class="u-search__clear-icon">×</text>
|
|
36
|
+
</view>
|
|
37
|
+
</view>
|
|
38
|
+
|
|
39
|
+
<view v-if="$slots.action || actionText" class="u-search__action" @click="handleAction">
|
|
40
|
+
<slot name="action">
|
|
41
|
+
<text class="u-search__action-text">{{ actionText }}</text>
|
|
42
|
+
</slot>
|
|
43
|
+
</view>
|
|
44
|
+
</view>
|
|
45
|
+
</template>
|
|
46
|
+
|
|
47
|
+
<script setup lang="ts">
|
|
48
|
+
import { ref, computed } from 'vue'
|
|
49
|
+
|
|
50
|
+
type ConfirmType = 'send' | 'search' | 'next' | 'go' | 'done'
|
|
51
|
+
|
|
52
|
+
interface Props {
|
|
53
|
+
modelValue?: string | number
|
|
54
|
+
type?: 'text' | 'number' | 'idcard' | 'digit'
|
|
55
|
+
placeholder?: string
|
|
56
|
+
placeholderStyle?: string
|
|
57
|
+
disabled?: boolean
|
|
58
|
+
maxlength?: number
|
|
59
|
+
clearable?: boolean
|
|
60
|
+
focus?: boolean
|
|
61
|
+
confirmType?: ConfirmType
|
|
62
|
+
adjustPosition?: boolean
|
|
63
|
+
showSearchIcon?: boolean
|
|
64
|
+
actionText?: string
|
|
65
|
+
inputAlign?: 'left' | 'center' | 'right'
|
|
66
|
+
shape?: 'square' | 'round'
|
|
67
|
+
background?: string
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
71
|
+
modelValue: '',
|
|
72
|
+
type: 'text',
|
|
73
|
+
placeholder: '请输入搜索关键词',
|
|
74
|
+
disabled: false,
|
|
75
|
+
maxlength: 140,
|
|
76
|
+
clearable: true,
|
|
77
|
+
focus: false,
|
|
78
|
+
confirmType: 'search',
|
|
79
|
+
adjustPosition: true,
|
|
80
|
+
showSearchIcon: true,
|
|
81
|
+
actionText: '',
|
|
82
|
+
inputAlign: 'left',
|
|
83
|
+
shape: 'round',
|
|
84
|
+
background: '#f7f8fa'
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
const emit = defineEmits<{
|
|
88
|
+
'update:modelValue': [value: string]
|
|
89
|
+
input: [value: string]
|
|
90
|
+
focus: [event: FocusEvent]
|
|
91
|
+
blur: [event: FocusEvent]
|
|
92
|
+
search: [value: string]
|
|
93
|
+
clear: []
|
|
94
|
+
action: []
|
|
95
|
+
}>()
|
|
96
|
+
|
|
97
|
+
const isFocus = ref(false)
|
|
98
|
+
|
|
99
|
+
const contentStyle = computed(() => {
|
|
100
|
+
const style: Record<string, string> = {
|
|
101
|
+
background: props.background,
|
|
102
|
+
'text-align': props.inputAlign
|
|
103
|
+
}
|
|
104
|
+
if (props.shape === 'round') {
|
|
105
|
+
style['border-radius'] = '999px'
|
|
106
|
+
}
|
|
107
|
+
return style
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
const handleInput = (event: any) => {
|
|
111
|
+
const value = event.detail.value
|
|
112
|
+
emit('update:modelValue', value)
|
|
113
|
+
emit('input', value)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const handleFocus = (event: FocusEvent) => {
|
|
117
|
+
isFocus.value = true
|
|
118
|
+
emit('focus', event)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const handleBlur = (event: FocusEvent) => {
|
|
122
|
+
isFocus.value = false
|
|
123
|
+
emit('blur', event)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const handleSearch = (event: any) => {
|
|
127
|
+
emit('search', event.detail.value)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const handleClear = () => {
|
|
131
|
+
emit('update:modelValue', '')
|
|
132
|
+
emit('input', '')
|
|
133
|
+
emit('clear')
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const handleAction = () => {
|
|
137
|
+
if (!props.disabled) {
|
|
138
|
+
emit('action')
|
|
139
|
+
emit('search', String(props.modelValue))
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
</script>
|
|
143
|
+
|
|
144
|
+
<script lang="ts">
|
|
145
|
+
export default {
|
|
146
|
+
options: {
|
|
147
|
+
virtualHost: true,
|
|
148
|
+
styleIsolation: 'shared'
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
</script>
|
|
152
|
+
|
|
153
|
+
<style lang="scss" scoped>
|
|
154
|
+
.u-search {
|
|
155
|
+
display: flex;
|
|
156
|
+
align-items: center;
|
|
157
|
+
width: 100%;
|
|
158
|
+
padding: $--spacing-sm $--spacing-md;
|
|
159
|
+
|
|
160
|
+
&--disabled {
|
|
161
|
+
opacity: 0.6;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
&__content {
|
|
165
|
+
flex: 1;
|
|
166
|
+
display: flex;
|
|
167
|
+
align-items: center;
|
|
168
|
+
height: $--search-height;
|
|
169
|
+
padding: 0 $--spacing-md;
|
|
170
|
+
background-color: $--bg-color-2;
|
|
171
|
+
border-radius: $--border-radius-lg;
|
|
172
|
+
transition: all $--transition-duration;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
&--focus .u-search__content {
|
|
176
|
+
background-color: $--bg-color-2;
|
|
177
|
+
box-shadow: 0 0 0 1px $--color-primary;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
&__icon {
|
|
181
|
+
display: flex;
|
|
182
|
+
align-items: center;
|
|
183
|
+
margin-right: $--spacing-sm;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
&__icon-text {
|
|
187
|
+
font-size: $--font-size-md;
|
|
188
|
+
color: $--text-color-2;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
&__body {
|
|
192
|
+
flex: 1;
|
|
193
|
+
display: flex;
|
|
194
|
+
align-items: center;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
&__control {
|
|
198
|
+
flex: 1;
|
|
199
|
+
width: 100%;
|
|
200
|
+
height: 100%;
|
|
201
|
+
font-size: $--font-size-md;
|
|
202
|
+
color: $--text-color;
|
|
203
|
+
background: transparent;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
&__placeholder {
|
|
207
|
+
color: $--text-color-3;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
&__clear {
|
|
211
|
+
display: flex;
|
|
212
|
+
align-items: center;
|
|
213
|
+
justify-content: center;
|
|
214
|
+
width: 16px;
|
|
215
|
+
height: 16px;
|
|
216
|
+
margin-left: $--spacing-sm;
|
|
217
|
+
background-color: $--text-color-3;
|
|
218
|
+
border-radius: 50%;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
&__clear-icon {
|
|
222
|
+
color: $--bg-color-2;
|
|
223
|
+
font-size: 12px;
|
|
224
|
+
line-height: 1;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
&__action {
|
|
228
|
+
display: flex;
|
|
229
|
+
align-items: center;
|
|
230
|
+
padding: $--spacing-sm $--spacing-md;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
&__action-text {
|
|
234
|
+
font-size: $--font-size-md;
|
|
235
|
+
color: $--color-primary;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
</style>
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view v-if="!loading" class="u-skeleton__content">
|
|
3
|
+
<slot />
|
|
4
|
+
</view>
|
|
5
|
+
<view v-else class="u-skeleton" :class="{ 'u-skeleton--animate': animate }">
|
|
6
|
+
<!-- 头像骨架 -->
|
|
7
|
+
<view
|
|
8
|
+
v-if="avatar"
|
|
9
|
+
class="u-skeleton__avatar"
|
|
10
|
+
:class="`u-skeleton__avatar--${avatarShape}`"
|
|
11
|
+
:style="avatarStyle"
|
|
12
|
+
/>
|
|
13
|
+
<!-- 内容区域 -->
|
|
14
|
+
<view class="u-skeleton__content">
|
|
15
|
+
<!-- 标题骨架 -->
|
|
16
|
+
<view
|
|
17
|
+
v-if="title"
|
|
18
|
+
class="u-skeleton__title"
|
|
19
|
+
:style="titleStyle"
|
|
20
|
+
/>
|
|
21
|
+
<!-- 段落骨架 -->
|
|
22
|
+
<view class="u-skeleton__paragraphs">
|
|
23
|
+
<view
|
|
24
|
+
v-for="(row, index) in rowList"
|
|
25
|
+
:key="index"
|
|
26
|
+
class="u-skeleton__paragraph"
|
|
27
|
+
:style="getRowStyle(index)"
|
|
28
|
+
/>
|
|
29
|
+
</view>
|
|
30
|
+
</view>
|
|
31
|
+
</view>
|
|
32
|
+
</template>
|
|
33
|
+
|
|
34
|
+
<script setup lang="ts">
|
|
35
|
+
import { computed } from 'vue'
|
|
36
|
+
|
|
37
|
+
type AvatarShape = 'circle' | 'square'
|
|
38
|
+
type TitleWidth = number | string
|
|
39
|
+
|
|
40
|
+
interface Props {
|
|
41
|
+
loading?: boolean
|
|
42
|
+
animate?: boolean
|
|
43
|
+
avatar?: boolean
|
|
44
|
+
avatarSize?: number | string
|
|
45
|
+
avatarShape?: AvatarShape
|
|
46
|
+
title?: boolean
|
|
47
|
+
titleWidth?: TitleWidth
|
|
48
|
+
row?: number
|
|
49
|
+
rowWidth?: number | string | (number | string)[]
|
|
50
|
+
rowHeight?: number | string | (number | string)[]
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
54
|
+
loading: true,
|
|
55
|
+
animate: true,
|
|
56
|
+
avatar: false,
|
|
57
|
+
avatarSize: 40,
|
|
58
|
+
avatarShape: 'circle',
|
|
59
|
+
title: true,
|
|
60
|
+
titleWidth: '40%',
|
|
61
|
+
row: 3,
|
|
62
|
+
rowWidth: '100%',
|
|
63
|
+
rowHeight: 16
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
const avatarStyle = computed(() => {
|
|
67
|
+
const size = typeof props.avatarSize === 'number'
|
|
68
|
+
? `${props.avatarSize}px`
|
|
69
|
+
: props.avatarSize
|
|
70
|
+
return {
|
|
71
|
+
width: size,
|
|
72
|
+
height: size
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
const titleStyle = computed(() => {
|
|
77
|
+
const width = typeof props.titleWidth === 'number'
|
|
78
|
+
? `${props.titleWidth}px`
|
|
79
|
+
: props.titleWidth
|
|
80
|
+
return { width }
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
const rowList = computed(() => {
|
|
84
|
+
return Array.from({ length: props.row }, (_, i) => i)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
const getRowStyle = (index: number) => {
|
|
88
|
+
const style: Record<string, string> = {}
|
|
89
|
+
|
|
90
|
+
// 处理宽度
|
|
91
|
+
if (Array.isArray(props.rowWidth)) {
|
|
92
|
+
const width = props.rowWidth[index]
|
|
93
|
+
if (width !== undefined) {
|
|
94
|
+
style.width = typeof width === 'number' ? `${width}px` : width
|
|
95
|
+
}
|
|
96
|
+
} else if (index === props.row - 1 && props.rowWidth === '100%') {
|
|
97
|
+
// 最后一行默认 60% 宽度(如果是 100% 才处理)
|
|
98
|
+
style.width = '60%'
|
|
99
|
+
} else {
|
|
100
|
+
style.width = typeof props.rowWidth === 'number'
|
|
101
|
+
? `${props.rowWidth}px`
|
|
102
|
+
: props.rowWidth
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// 处理高度
|
|
106
|
+
if (Array.isArray(props.rowHeight)) {
|
|
107
|
+
const height = props.rowHeight[index]
|
|
108
|
+
if (height !== undefined) {
|
|
109
|
+
style.height = typeof height === 'number' ? `${height}px` : height
|
|
110
|
+
}
|
|
111
|
+
} else {
|
|
112
|
+
style.height = typeof props.rowHeight === 'number'
|
|
113
|
+
? `${props.rowHeight}px`
|
|
114
|
+
: props.rowHeight
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return style
|
|
118
|
+
}
|
|
119
|
+
</script>
|
|
120
|
+
|
|
121
|
+
<script lang="ts">
|
|
122
|
+
export default {
|
|
123
|
+
options: {
|
|
124
|
+
virtualHost: true,
|
|
125
|
+
styleIsolation: 'shared'
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
</script>
|
|
129
|
+
|
|
130
|
+
<style lang="scss" scoped>
|
|
131
|
+
.u-skeleton {
|
|
132
|
+
display: flex;
|
|
133
|
+
gap: $--spacing-md;
|
|
134
|
+
|
|
135
|
+
&--animate {
|
|
136
|
+
.u-skeleton__avatar,
|
|
137
|
+
.u-skeleton__title,
|
|
138
|
+
.u-skeleton__paragraph {
|
|
139
|
+
animation: skeleton-blink 1.2s ease-in-out infinite;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
&__avatar {
|
|
144
|
+
flex-shrink: 0;
|
|
145
|
+
background-color: $--bg-color-3;
|
|
146
|
+
border-radius: 50%;
|
|
147
|
+
|
|
148
|
+
&--circle {
|
|
149
|
+
border-radius: 50%;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
&--square {
|
|
153
|
+
border-radius: $--radius-sm;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
&__content {
|
|
158
|
+
flex: 1;
|
|
159
|
+
min-width: 0;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
&__title {
|
|
163
|
+
height: 20px;
|
|
164
|
+
margin-bottom: $--spacing-md;
|
|
165
|
+
background-color: $--bg-color-3;
|
|
166
|
+
border-radius: $--radius-sm;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
&__paragraphs {
|
|
170
|
+
display: flex;
|
|
171
|
+
flex-direction: column;
|
|
172
|
+
gap: $--spacing-sm;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
&__paragraph {
|
|
176
|
+
background-color: $--bg-color-3;
|
|
177
|
+
border-radius: $--radius-sm;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
@keyframes skeleton-blink {
|
|
182
|
+
0% {
|
|
183
|
+
opacity: 1;
|
|
184
|
+
}
|
|
185
|
+
50% {
|
|
186
|
+
opacity: 0.5;
|
|
187
|
+
}
|
|
188
|
+
100% {
|
|
189
|
+
opacity: 1;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
</style>
|