@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,364 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view
|
|
3
|
+
class="u-tooltip"
|
|
4
|
+
:class="{
|
|
5
|
+
'u-tooltip--active': visible
|
|
6
|
+
}"
|
|
7
|
+
@longpress="handleLongPress"
|
|
8
|
+
@touchstart="handleTouchStart"
|
|
9
|
+
@touchend="handleTouchEnd"
|
|
10
|
+
>
|
|
11
|
+
<!-- 触发元素 -->
|
|
12
|
+
<view
|
|
13
|
+
class="u-tooltip__trigger"
|
|
14
|
+
:class="{
|
|
15
|
+
'u-tooltip__trigger--highlight': highlight && visible
|
|
16
|
+
}"
|
|
17
|
+
:style="highlight ? highlightStyle : {}"
|
|
18
|
+
>
|
|
19
|
+
<slot />
|
|
20
|
+
</view>
|
|
21
|
+
|
|
22
|
+
<!-- 提示气泡 -->
|
|
23
|
+
<view
|
|
24
|
+
v-if="visible"
|
|
25
|
+
class="u-tooltip__popup"
|
|
26
|
+
:class="[`u-tooltip__popup--${placement}`, `u-tooltip__popup--${actualPlacement}`]"
|
|
27
|
+
:style="popupStyle"
|
|
28
|
+
>
|
|
29
|
+
<!-- 箭头 -->
|
|
30
|
+
<view class="u-tooltip__arrow" :class="`u-tooltip__arrow--${actualPlacement}`"></view>
|
|
31
|
+
|
|
32
|
+
<!-- 内容 -->
|
|
33
|
+
<view class="u-tooltip__content">
|
|
34
|
+
<!-- 操作按钮 -->
|
|
35
|
+
<view v-if="actions.length" class="u-tooltip__actions">
|
|
36
|
+
<view
|
|
37
|
+
v-for="(action, index) in actions"
|
|
38
|
+
:key="index"
|
|
39
|
+
class="u-tooltip__action"
|
|
40
|
+
:class="{ 'u-tooltip__action--disabled': action.disabled }"
|
|
41
|
+
@click.stop="handleActionClick(action, index)"
|
|
42
|
+
>
|
|
43
|
+
<text class="u-tooltip__action-text">{{ action.text }}</text>
|
|
44
|
+
</view>
|
|
45
|
+
</view>
|
|
46
|
+
|
|
47
|
+
<!-- 自定义内容 -->
|
|
48
|
+
<slot v-else name="content">
|
|
49
|
+
<text class="u-tooltip__text">{{ content }}</text>
|
|
50
|
+
</slot>
|
|
51
|
+
</view>
|
|
52
|
+
</view>
|
|
53
|
+
</view>
|
|
54
|
+
</template>
|
|
55
|
+
|
|
56
|
+
<script setup lang="ts">
|
|
57
|
+
import { ref, computed, onMounted, onUnmounted } from 'vue'
|
|
58
|
+
|
|
59
|
+
// 检测是否在 uniapp 环境中
|
|
60
|
+
const isUniApp = typeof uni !== 'undefined'
|
|
61
|
+
|
|
62
|
+
interface Action {
|
|
63
|
+
text: string
|
|
64
|
+
disabled?: boolean
|
|
65
|
+
[key: string]: any
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
interface Props {
|
|
69
|
+
content?: string
|
|
70
|
+
placement?: 'top' | 'bottom'
|
|
71
|
+
actions?: Action[]
|
|
72
|
+
highlight?: boolean
|
|
73
|
+
highlightColor?: string
|
|
74
|
+
autoAdjust?: boolean
|
|
75
|
+
showDuration?: number
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
79
|
+
content: '',
|
|
80
|
+
placement: 'top',
|
|
81
|
+
actions: () => [],
|
|
82
|
+
highlight: false,
|
|
83
|
+
highlightColor: 'rgba(25, 137, 250, 0.1)',
|
|
84
|
+
autoAdjust: true,
|
|
85
|
+
showDuration: 0
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
const emit = defineEmits<{
|
|
89
|
+
show: []
|
|
90
|
+
hide: []
|
|
91
|
+
select: [action: Action, index: number]
|
|
92
|
+
}>()
|
|
93
|
+
|
|
94
|
+
const visible = ref(false)
|
|
95
|
+
const actualPlacement = ref(props.placement)
|
|
96
|
+
let hideTimer: ReturnType<typeof setTimeout> | null = null
|
|
97
|
+
let triggerRect = { top: 0, bottom: 0, left: 0, right: 0, width: 0, height: 0 }
|
|
98
|
+
|
|
99
|
+
const highlightStyle = computed(() => ({
|
|
100
|
+
backgroundColor: props.highlightColor
|
|
101
|
+
}))
|
|
102
|
+
|
|
103
|
+
const popupStyle = computed(() => ({}))
|
|
104
|
+
|
|
105
|
+
const handleTouchStart = (event: any) => {
|
|
106
|
+
const touch = event.touches?.[0]
|
|
107
|
+
if (isUniApp) {
|
|
108
|
+
// uni-app 使用 createSelectorQuery
|
|
109
|
+
const query = uni.createSelectorQuery()
|
|
110
|
+
query.select('.u-tooltip__trigger').boundingClientRect((rect: any) => {
|
|
111
|
+
if (rect) {
|
|
112
|
+
triggerRect = {
|
|
113
|
+
top: rect.top,
|
|
114
|
+
bottom: rect.bottom,
|
|
115
|
+
left: rect.left,
|
|
116
|
+
right: rect.right,
|
|
117
|
+
width: rect.width,
|
|
118
|
+
height: rect.height
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}).exec()
|
|
122
|
+
} else if (event.currentTarget) {
|
|
123
|
+
// 小程序/鸿蒙环境:使用 uni.createSelectorQuery 作为 fallback
|
|
124
|
+
uni.createSelectorQuery()
|
|
125
|
+
.select('.u-tooltip__trigger')
|
|
126
|
+
.boundingClientRect((rect: any) => {
|
|
127
|
+
if (rect) {
|
|
128
|
+
triggerRect = {
|
|
129
|
+
top: rect.top,
|
|
130
|
+
bottom: rect.bottom,
|
|
131
|
+
left: rect.left,
|
|
132
|
+
right: rect.right,
|
|
133
|
+
width: rect.width,
|
|
134
|
+
height: rect.height
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
})
|
|
138
|
+
.exec()
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const handleTouchEnd = () => {
|
|
143
|
+
// touch end handled
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const handleLongPress = () => {
|
|
147
|
+
show()
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const show = () => {
|
|
151
|
+
visible.value = true
|
|
152
|
+
emit('show')
|
|
153
|
+
|
|
154
|
+
if (props.autoAdjust) {
|
|
155
|
+
adjustPlacement()
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (props.showDuration > 0) {
|
|
159
|
+
hideTimer = setTimeout(() => {
|
|
160
|
+
hide()
|
|
161
|
+
}, props.showDuration)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const hide = () => {
|
|
166
|
+
visible.value = false
|
|
167
|
+
emit('hide')
|
|
168
|
+
if (hideTimer) {
|
|
169
|
+
clearTimeout(hideTimer)
|
|
170
|
+
hideTimer = null
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const adjustPlacement = () => {
|
|
175
|
+
// 简化的位置调整逻辑
|
|
176
|
+
if (isUniApp) {
|
|
177
|
+
// uni-app 中使用系统信息获取窗口高度
|
|
178
|
+
const systemInfo = uni.getSystemInfoSync()
|
|
179
|
+
const windowHeight = systemInfo.windowHeight
|
|
180
|
+
const spaceAbove = triggerRect.top
|
|
181
|
+
const spaceBelow = windowHeight - triggerRect.bottom
|
|
182
|
+
|
|
183
|
+
if (props.placement === 'top' && spaceAbove < 50) {
|
|
184
|
+
actualPlacement.value = 'bottom'
|
|
185
|
+
} else if (props.placement === 'bottom' && spaceBelow < 50) {
|
|
186
|
+
actualPlacement.value = 'top'
|
|
187
|
+
} else {
|
|
188
|
+
actualPlacement.value = props.placement
|
|
189
|
+
}
|
|
190
|
+
} else {
|
|
191
|
+
const windowHeight = window.innerHeight
|
|
192
|
+
const spaceAbove = triggerRect.top
|
|
193
|
+
const spaceBelow = windowHeight - triggerRect.bottom
|
|
194
|
+
|
|
195
|
+
if (props.placement === 'top' && spaceAbove < 50) {
|
|
196
|
+
actualPlacement.value = 'bottom'
|
|
197
|
+
} else if (props.placement === 'bottom' && spaceBelow < 50) {
|
|
198
|
+
actualPlacement.value = 'top'
|
|
199
|
+
} else {
|
|
200
|
+
actualPlacement.value = props.placement
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const handleActionClick = (action: Action, index: number) => {
|
|
206
|
+
if (action.disabled) return
|
|
207
|
+
emit('select', action, index)
|
|
208
|
+
hide()
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const handleClickOutside = (event: TouchEvent | MouseEvent) => {
|
|
212
|
+
if (visible.value) {
|
|
213
|
+
hide()
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
onMounted(() => {
|
|
218
|
+
if (isUniApp) {
|
|
219
|
+
// uni-app 中使用页面生命周期事件处理
|
|
220
|
+
} else {
|
|
221
|
+
document.addEventListener('click', handleClickOutside)
|
|
222
|
+
document.addEventListener('touchstart', handleClickOutside)
|
|
223
|
+
}
|
|
224
|
+
})
|
|
225
|
+
|
|
226
|
+
onUnmounted(() => {
|
|
227
|
+
if (isUniApp) {
|
|
228
|
+
// uni-app 清理
|
|
229
|
+
} else {
|
|
230
|
+
document.removeEventListener('click', handleClickOutside)
|
|
231
|
+
document.removeEventListener('touchstart', handleClickOutside)
|
|
232
|
+
}
|
|
233
|
+
if (hideTimer) {
|
|
234
|
+
clearTimeout(hideTimer)
|
|
235
|
+
}
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
defineExpose({
|
|
239
|
+
show,
|
|
240
|
+
hide
|
|
241
|
+
})
|
|
242
|
+
</script>
|
|
243
|
+
|
|
244
|
+
<script lang="ts">
|
|
245
|
+
export default {
|
|
246
|
+
options: {
|
|
247
|
+
virtualHost: true,
|
|
248
|
+
styleIsolation: 'shared'
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
</script>
|
|
252
|
+
|
|
253
|
+
<style lang="scss" scoped>
|
|
254
|
+
.u-tooltip {
|
|
255
|
+
position: relative;
|
|
256
|
+
display: inline-block;
|
|
257
|
+
|
|
258
|
+
&--active {
|
|
259
|
+
z-index: 999;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
&__trigger {
|
|
263
|
+
display: inline;
|
|
264
|
+
transition: background-color 0.15s;
|
|
265
|
+
|
|
266
|
+
&--highlight {
|
|
267
|
+
border-radius: 2px;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
&__popup {
|
|
272
|
+
position: absolute;
|
|
273
|
+
z-index: 1000;
|
|
274
|
+
padding: 8px 12px;
|
|
275
|
+
background: #323233;
|
|
276
|
+
border-radius: 8px;
|
|
277
|
+
white-space: nowrap;
|
|
278
|
+
animation: u-tooltip-fade-in 0.15s ease-out;
|
|
279
|
+
|
|
280
|
+
&--top {
|
|
281
|
+
bottom: 100%;
|
|
282
|
+
left: 50%;
|
|
283
|
+
transform: translateX(-50%);
|
|
284
|
+
margin-bottom: 8px;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
&--bottom {
|
|
288
|
+
top: 100%;
|
|
289
|
+
left: 50%;
|
|
290
|
+
transform: translateX(-50%);
|
|
291
|
+
margin-top: 8px;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
&__arrow {
|
|
296
|
+
position: absolute;
|
|
297
|
+
width: 0;
|
|
298
|
+
height: 0;
|
|
299
|
+
border: 6px solid transparent;
|
|
300
|
+
|
|
301
|
+
&--top {
|
|
302
|
+
bottom: -12px;
|
|
303
|
+
left: 50%;
|
|
304
|
+
transform: translateX(-50%);
|
|
305
|
+
border-top-color: #323233;
|
|
306
|
+
border-bottom: none;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
&--bottom {
|
|
310
|
+
top: -12px;
|
|
311
|
+
left: 50%;
|
|
312
|
+
transform: translateX(-50%);
|
|
313
|
+
border-bottom-color: #323233;
|
|
314
|
+
border-top: none;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
&__content {
|
|
319
|
+
display: flex;
|
|
320
|
+
align-items: center;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
&__text {
|
|
324
|
+
font-size: 14px;
|
|
325
|
+
color: #fff;
|
|
326
|
+
line-height: 1.4;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
&__actions {
|
|
330
|
+
display: flex;
|
|
331
|
+
gap: 16px;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
&__action {
|
|
335
|
+
display: flex;
|
|
336
|
+
align-items: center;
|
|
337
|
+
padding: 4px 0;
|
|
338
|
+
|
|
339
|
+
&--disabled {
|
|
340
|
+
opacity: 0.5;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
&:not(&--disabled):active {
|
|
344
|
+
opacity: 0.7;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
&__action-text {
|
|
349
|
+
font-size: 14px;
|
|
350
|
+
color: #fff;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
@keyframes u-tooltip-fade-in {
|
|
355
|
+
from {
|
|
356
|
+
opacity: 0;
|
|
357
|
+
transform: translateX(-50%) scale(0.9);
|
|
358
|
+
}
|
|
359
|
+
to {
|
|
360
|
+
opacity: 1;
|
|
361
|
+
transform: translateX(-50%) scale(1);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
</style>
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view
|
|
3
|
+
v-show="visible"
|
|
4
|
+
class="u-transition"
|
|
5
|
+
:class="transitionClass"
|
|
6
|
+
:style="transitionStyle"
|
|
7
|
+
@transitionend="onTransitionEnd"
|
|
8
|
+
>
|
|
9
|
+
<slot />
|
|
10
|
+
</view>
|
|
11
|
+
</template>
|
|
12
|
+
|
|
13
|
+
<script setup lang="ts">
|
|
14
|
+
import { computed, ref, watch } from 'vue'
|
|
15
|
+
|
|
16
|
+
type TransitionMode =
|
|
17
|
+
| 'fade'
|
|
18
|
+
| 'fade-up'
|
|
19
|
+
| 'fade-down'
|
|
20
|
+
| 'fade-left'
|
|
21
|
+
| 'fade-right'
|
|
22
|
+
| 'slide-up'
|
|
23
|
+
| 'slide-down'
|
|
24
|
+
| 'slide-left'
|
|
25
|
+
| 'slide-right'
|
|
26
|
+
| 'zoom'
|
|
27
|
+
| 'zoom-fade'
|
|
28
|
+
|
|
29
|
+
interface Props {
|
|
30
|
+
show?: boolean
|
|
31
|
+
mode?: TransitionMode
|
|
32
|
+
duration?: number
|
|
33
|
+
delay?: number
|
|
34
|
+
customStyle?: Record<string, string | number>
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
38
|
+
show: false,
|
|
39
|
+
mode: 'fade',
|
|
40
|
+
duration: 300,
|
|
41
|
+
delay: 0
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
const emit = defineEmits<{
|
|
45
|
+
(e: 'after-enter'): void
|
|
46
|
+
(e: 'after-leave'): void
|
|
47
|
+
}>()
|
|
48
|
+
|
|
49
|
+
const visible = ref(false)
|
|
50
|
+
const animationPhase = ref<'enter' | 'leave'>('enter')
|
|
51
|
+
|
|
52
|
+
// 监听 show 变化
|
|
53
|
+
watch(
|
|
54
|
+
() => props.show,
|
|
55
|
+
(val) => {
|
|
56
|
+
if (val) {
|
|
57
|
+
visible.value = true
|
|
58
|
+
animationPhase.value = 'enter'
|
|
59
|
+
} else {
|
|
60
|
+
animationPhase.value = 'leave'
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
{ immediate: true }
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
const transitionClass = computed(() => {
|
|
67
|
+
const classes: string[] = []
|
|
68
|
+
|
|
69
|
+
if (animationPhase.value === 'enter') {
|
|
70
|
+
classes.push(`u-transition--${props.mode}-enter`)
|
|
71
|
+
} else {
|
|
72
|
+
classes.push(`u-transition--${props.mode}-leave`)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return classes
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
const transitionStyle = computed(() => {
|
|
79
|
+
const style: Record<string, string | number> = {
|
|
80
|
+
transitionDuration: `${props.duration}ms`,
|
|
81
|
+
transitionDelay: `${props.delay}ms`,
|
|
82
|
+
transitionProperty: 'opacity, transform',
|
|
83
|
+
transitionTimingFunction: 'ease-out'
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (props.customStyle) {
|
|
87
|
+
Object.assign(style, props.customStyle)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return style
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
const onTransitionEnd = () => {
|
|
94
|
+
if (animationPhase.value === 'leave') {
|
|
95
|
+
visible.value = false
|
|
96
|
+
emit('after-leave')
|
|
97
|
+
} else {
|
|
98
|
+
emit('after-enter')
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
</script>
|
|
102
|
+
|
|
103
|
+
<script lang="ts">
|
|
104
|
+
export default {
|
|
105
|
+
options: {
|
|
106
|
+
virtualHost: true,
|
|
107
|
+
styleIsolation: 'shared'
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
</script>
|
|
111
|
+
|
|
112
|
+
<style lang="scss" scoped>
|
|
113
|
+
.u-transition {
|
|
114
|
+
// 基础状态
|
|
115
|
+
opacity: 1;
|
|
116
|
+
transform: none;
|
|
117
|
+
|
|
118
|
+
// 淡入淡出
|
|
119
|
+
&--fade-enter {
|
|
120
|
+
opacity: 0;
|
|
121
|
+
}
|
|
122
|
+
&--fade-leave {
|
|
123
|
+
opacity: 0;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// 上滑淡入
|
|
127
|
+
&--fade-up-enter {
|
|
128
|
+
opacity: 0;
|
|
129
|
+
transform: translateY(100%);
|
|
130
|
+
}
|
|
131
|
+
&--fade-up-leave {
|
|
132
|
+
opacity: 0;
|
|
133
|
+
transform: translateY(-100%);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// 下滑淡入
|
|
137
|
+
&--fade-down-enter {
|
|
138
|
+
opacity: 0;
|
|
139
|
+
transform: translateY(-100%);
|
|
140
|
+
}
|
|
141
|
+
&--fade-down-leave {
|
|
142
|
+
opacity: 0;
|
|
143
|
+
transform: translateY(100%);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// 左滑淡入
|
|
147
|
+
&--fade-left-enter {
|
|
148
|
+
opacity: 0;
|
|
149
|
+
transform: translateX(100%);
|
|
150
|
+
}
|
|
151
|
+
&--fade-left-leave {
|
|
152
|
+
opacity: 0;
|
|
153
|
+
transform: translateX(-100%);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// 右滑淡入
|
|
157
|
+
&--fade-right-enter {
|
|
158
|
+
opacity: 0;
|
|
159
|
+
transform: translateX(-100%);
|
|
160
|
+
}
|
|
161
|
+
&--fade-right-leave {
|
|
162
|
+
opacity: 0;
|
|
163
|
+
transform: translateX(100%);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// 上滑进入
|
|
167
|
+
&--slide-up-enter {
|
|
168
|
+
transform: translateY(100%);
|
|
169
|
+
}
|
|
170
|
+
&--slide-up-leave {
|
|
171
|
+
transform: translateY(-100%);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// 下滑进入
|
|
175
|
+
&--slide-down-enter {
|
|
176
|
+
transform: translateY(-100%);
|
|
177
|
+
}
|
|
178
|
+
&--slide-down-leave {
|
|
179
|
+
transform: translateY(100%);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// 左滑进入
|
|
183
|
+
&--slide-left-enter {
|
|
184
|
+
transform: translateX(100%);
|
|
185
|
+
}
|
|
186
|
+
&--slide-left-leave {
|
|
187
|
+
transform: translateX(-100%);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// 右滑进入
|
|
191
|
+
&--slide-right-enter {
|
|
192
|
+
transform: translateX(-100%);
|
|
193
|
+
}
|
|
194
|
+
&--slide-right-leave {
|
|
195
|
+
transform: translateX(100%);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// 缩放
|
|
199
|
+
&--zoom-enter {
|
|
200
|
+
transform: scale(0);
|
|
201
|
+
}
|
|
202
|
+
&--zoom-leave {
|
|
203
|
+
transform: scale(0);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// 缩放淡入
|
|
207
|
+
&--zoom-fade-enter {
|
|
208
|
+
opacity: 0;
|
|
209
|
+
transform: scale(0.5);
|
|
210
|
+
}
|
|
211
|
+
&--zoom-fade-leave {
|
|
212
|
+
opacity: 0;
|
|
213
|
+
transform: scale(0.5);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
</style>
|