@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,144 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="u-tag" :class="[`u-tag--${type}`, `u-tag--${size}`, { 'u-tag--plain': plain, 'u-tag--round': round }]" :style="tagStyle">
|
|
3
|
+
<text class="u-tag__text"><slot /></text>
|
|
4
|
+
<view v-if="closable" class="u-tag__close" @click="handleClose">
|
|
5
|
+
<text>×</text>
|
|
6
|
+
</view>
|
|
7
|
+
</view>
|
|
8
|
+
</template>
|
|
9
|
+
|
|
10
|
+
<script setup lang="ts">
|
|
11
|
+
import { computed } from 'vue'
|
|
12
|
+
|
|
13
|
+
type TagType = 'primary' | 'success' | 'warning' | 'danger' | 'default'
|
|
14
|
+
type TagSize = 'large' | 'medium' | 'small'
|
|
15
|
+
|
|
16
|
+
interface Props {
|
|
17
|
+
type?: TagType
|
|
18
|
+
size?: TagSize
|
|
19
|
+
plain?: boolean
|
|
20
|
+
round?: boolean
|
|
21
|
+
closable?: boolean
|
|
22
|
+
color?: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
26
|
+
type: 'default',
|
|
27
|
+
size: 'medium',
|
|
28
|
+
plain: false,
|
|
29
|
+
round: false,
|
|
30
|
+
closable: false
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
const emit = defineEmits<{
|
|
34
|
+
close: []
|
|
35
|
+
}>()
|
|
36
|
+
|
|
37
|
+
const tagStyle = computed(() => {
|
|
38
|
+
if (props.color) {
|
|
39
|
+
return {
|
|
40
|
+
backgroundColor: props.plain ? 'transparent' : props.color,
|
|
41
|
+
borderColor: props.color,
|
|
42
|
+
color: props.plain ? props.color : '#fff'
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return {}
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const handleClose = () => {
|
|
49
|
+
emit('close')
|
|
50
|
+
}
|
|
51
|
+
</script>
|
|
52
|
+
|
|
53
|
+
<script lang="ts">
|
|
54
|
+
export default {
|
|
55
|
+
options: {
|
|
56
|
+
virtualHost: true,
|
|
57
|
+
styleIsolation: 'shared'
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
</script>
|
|
61
|
+
|
|
62
|
+
<style lang="scss" scoped>
|
|
63
|
+
.u-tag {
|
|
64
|
+
display: inline-flex;
|
|
65
|
+
align-items: center;
|
|
66
|
+
padding: 0 $--spacing-sm;
|
|
67
|
+
border-radius: 2px;
|
|
68
|
+
border: 1px solid transparent;
|
|
69
|
+
font-size: $--font-size-sm;
|
|
70
|
+
|
|
71
|
+
&--default {
|
|
72
|
+
color: $--text-color;
|
|
73
|
+
background-color: $--bg-color-3;
|
|
74
|
+
border-color: $--bg-color-3;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
&--primary {
|
|
78
|
+
color: $--text-color-white;
|
|
79
|
+
background-color: $--color-primary;
|
|
80
|
+
border-color: $--color-primary;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
&--success {
|
|
84
|
+
color: $--text-color-white;
|
|
85
|
+
background-color: $--color-success;
|
|
86
|
+
border-color: $--color-success;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
&--warning {
|
|
90
|
+
color: $--text-color-white;
|
|
91
|
+
background-color: $--color-warning;
|
|
92
|
+
border-color: $--color-warning;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
&--danger {
|
|
96
|
+
color: $--text-color-white;
|
|
97
|
+
background-color: $--color-danger;
|
|
98
|
+
border-color: $--color-danger;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
&--large {
|
|
102
|
+
padding: $--spacing-sm $--spacing-md;
|
|
103
|
+
font-size: $--font-size-md;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
&--small {
|
|
107
|
+
padding: 0 $--spacing-xs;
|
|
108
|
+
font-size: $--font-size-xs;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
&--plain {
|
|
112
|
+
background-color: transparent;
|
|
113
|
+
|
|
114
|
+
&.u-tag--primary {
|
|
115
|
+
color: $--color-primary;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
&.u-tag--success {
|
|
119
|
+
color: $--color-success;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
&.u-tag--warning {
|
|
123
|
+
color: $--color-warning;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
&.u-tag--danger {
|
|
127
|
+
color: $--color-danger;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
&--round {
|
|
132
|
+
border-radius: 999px;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
&__text {
|
|
136
|
+
line-height: 1.4;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
&__close {
|
|
140
|
+
margin-left: 2px;
|
|
141
|
+
font-size: 12px;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
</style>
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view
|
|
3
|
+
class="u-textarea"
|
|
4
|
+
:class="{
|
|
5
|
+
'u-textarea--disabled': disabled,
|
|
6
|
+
'u-textarea--error': error,
|
|
7
|
+
'u-textarea--focus': isFocus
|
|
8
|
+
}"
|
|
9
|
+
>
|
|
10
|
+
<textarea
|
|
11
|
+
class="u-textarea__control"
|
|
12
|
+
:value="modelValue"
|
|
13
|
+
:placeholder="placeholder"
|
|
14
|
+
:placeholder-style="placeholderStyle"
|
|
15
|
+
:placeholder-class="'u-textarea__placeholder'"
|
|
16
|
+
:disabled="disabled"
|
|
17
|
+
:maxlength="maxlength"
|
|
18
|
+
:focus="focus"
|
|
19
|
+
:auto-height="autoHeight"
|
|
20
|
+
:fixed="fixed"
|
|
21
|
+
:cursor-spacing="cursorSpacing"
|
|
22
|
+
:show-confirm-bar="showConfirmBar"
|
|
23
|
+
:adjust-position="adjustPosition"
|
|
24
|
+
:style="textareaStyle"
|
|
25
|
+
@input="handleInput"
|
|
26
|
+
@focus="handleFocus"
|
|
27
|
+
@blur="handleBlur"
|
|
28
|
+
@confirm="handleConfirm"
|
|
29
|
+
@linechange="handleLineChange"
|
|
30
|
+
/>
|
|
31
|
+
|
|
32
|
+
<view v-if="showWordLimit && maxlength" class="u-textarea__limit">
|
|
33
|
+
<text class="u-textarea__limit-text">{{ currentLength }}/{{ maxlength }}</text>
|
|
34
|
+
</view>
|
|
35
|
+
</view>
|
|
36
|
+
</template>
|
|
37
|
+
|
|
38
|
+
<script setup lang="ts">
|
|
39
|
+
import { ref, computed } from 'vue'
|
|
40
|
+
|
|
41
|
+
interface Props {
|
|
42
|
+
modelValue?: string
|
|
43
|
+
placeholder?: string
|
|
44
|
+
placeholderStyle?: string
|
|
45
|
+
disabled?: boolean
|
|
46
|
+
maxlength?: number
|
|
47
|
+
focus?: boolean
|
|
48
|
+
autoHeight?: boolean
|
|
49
|
+
fixed?: boolean
|
|
50
|
+
cursorSpacing?: number
|
|
51
|
+
showConfirmBar?: boolean
|
|
52
|
+
adjustPosition?: boolean
|
|
53
|
+
showWordLimit?: boolean
|
|
54
|
+
error?: boolean
|
|
55
|
+
rows?: number
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
59
|
+
modelValue: '',
|
|
60
|
+
placeholder: '请输入内容',
|
|
61
|
+
disabled: false,
|
|
62
|
+
maxlength: -1,
|
|
63
|
+
focus: false,
|
|
64
|
+
autoHeight: false,
|
|
65
|
+
fixed: false,
|
|
66
|
+
cursorSpacing: 0,
|
|
67
|
+
showConfirmBar: true,
|
|
68
|
+
adjustPosition: true,
|
|
69
|
+
showWordLimit: false,
|
|
70
|
+
error: false,
|
|
71
|
+
rows: 3
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
const emit = defineEmits<{
|
|
75
|
+
'update:modelValue': [value: string]
|
|
76
|
+
input: [value: string]
|
|
77
|
+
focus: [event: FocusEvent]
|
|
78
|
+
blur: [event: FocusEvent]
|
|
79
|
+
confirm: [value: string]
|
|
80
|
+
linechange: [event: any]
|
|
81
|
+
}>()
|
|
82
|
+
|
|
83
|
+
const isFocus = ref(false)
|
|
84
|
+
|
|
85
|
+
const currentLength = computed(() => {
|
|
86
|
+
return String(props.modelValue).length
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
const textareaStyle = computed(() => {
|
|
90
|
+
if (props.autoHeight) return {}
|
|
91
|
+
return {
|
|
92
|
+
minHeight: `calc($--font-size-md * $--textarea-line-height * ${props.rows})`
|
|
93
|
+
}
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
const handleInput = (event: any) => {
|
|
97
|
+
const value = event.detail.value
|
|
98
|
+
emit('update:modelValue', value)
|
|
99
|
+
emit('input', value)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const handleFocus = (event: FocusEvent) => {
|
|
103
|
+
isFocus.value = true
|
|
104
|
+
emit('focus', event)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const handleBlur = (event: FocusEvent) => {
|
|
108
|
+
isFocus.value = false
|
|
109
|
+
emit('blur', event)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const handleConfirm = (event: any) => {
|
|
113
|
+
emit('confirm', event.detail.value)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const handleLineChange = (event: any) => {
|
|
117
|
+
emit('linechange', event)
|
|
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-textarea {
|
|
132
|
+
position: relative;
|
|
133
|
+
display: flex;
|
|
134
|
+
flex-direction: column;
|
|
135
|
+
width: 100%;
|
|
136
|
+
padding: $--spacing-md;
|
|
137
|
+
background-color: $--bg-color-2;
|
|
138
|
+
border-radius: $--border-radius-md;
|
|
139
|
+
border: 1px solid $--border-color;
|
|
140
|
+
transition: all $--transition-duration;
|
|
141
|
+
|
|
142
|
+
&--focus {
|
|
143
|
+
border-color: $--color-primary;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
&--error {
|
|
147
|
+
border-color: $--color-danger;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
&--disabled {
|
|
151
|
+
background-color: $--bg-color;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
&__control {
|
|
155
|
+
width: 100%;
|
|
156
|
+
min-height: calc($--font-size-md * $--textarea-line-height * 3);
|
|
157
|
+
font-size: $--font-size-md;
|
|
158
|
+
line-height: $--textarea-line-height;
|
|
159
|
+
color: $--text-color;
|
|
160
|
+
background: transparent;
|
|
161
|
+
resize: none;
|
|
162
|
+
outline: none;
|
|
163
|
+
border: none;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
&__placeholder {
|
|
167
|
+
color: $--text-color-3;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
&__limit {
|
|
171
|
+
display: flex;
|
|
172
|
+
justify-content: flex-end;
|
|
173
|
+
padding-top: $--spacing-sm;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
&__limit-text {
|
|
177
|
+
font-size: $--font-size-sm;
|
|
178
|
+
color: $--text-color-3;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
&--disabled &__limit-text {
|
|
182
|
+
color: $--text-color-3;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
&--error &__limit-text {
|
|
186
|
+
color: $--color-danger;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
</style>
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view v-if="visible" class="u-toast" :class="toastClass" :style="toastStyle">
|
|
3
|
+
<view class="u-toast__content">
|
|
4
|
+
<view v-if="type === 'loading'" class="u-toast__loading">
|
|
5
|
+
<view class="u-toast__loading-icon" />
|
|
6
|
+
</view>
|
|
7
|
+
<text v-else-if="icon" class="u-toast__icon">{{ icon }}</text>
|
|
8
|
+
<text v-if="message" class="u-toast__text">{{ message }}</text>
|
|
9
|
+
</view>
|
|
10
|
+
</view>
|
|
11
|
+
</template>
|
|
12
|
+
|
|
13
|
+
<script setup lang="ts">
|
|
14
|
+
import { ref, computed, onUnmounted } from 'vue'
|
|
15
|
+
|
|
16
|
+
type ToastType = 'text' | 'loading' | 'success' | 'fail' | 'info'
|
|
17
|
+
|
|
18
|
+
interface Props {
|
|
19
|
+
message?: string
|
|
20
|
+
type?: ToastType
|
|
21
|
+
duration?: number
|
|
22
|
+
position?: 'top' | 'middle' | 'bottom'
|
|
23
|
+
icon?: string
|
|
24
|
+
forbidClick?: boolean
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
28
|
+
message: '',
|
|
29
|
+
type: 'text',
|
|
30
|
+
duration: 2000,
|
|
31
|
+
position: 'middle',
|
|
32
|
+
icon: '',
|
|
33
|
+
forbidClick: false
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
const visible = ref(false)
|
|
37
|
+
let timer: ReturnType<typeof setTimeout> | null = null
|
|
38
|
+
|
|
39
|
+
const icons: Record<string, string> = {
|
|
40
|
+
success: '✓',
|
|
41
|
+
fail: '✗',
|
|
42
|
+
info: 'ℹ'
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const displayIcon = computed(() => {
|
|
46
|
+
if (props.icon) return props.icon
|
|
47
|
+
if (props.type === 'loading') return ''
|
|
48
|
+
return icons[props.type] || ''
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
const toastClass = computed(() => [
|
|
52
|
+
`u-toast--${props.position}`,
|
|
53
|
+
{
|
|
54
|
+
'u-toast--forbid-click': props.forbidClick,
|
|
55
|
+
'u-toast--loading': props.type === 'loading'
|
|
56
|
+
}
|
|
57
|
+
])
|
|
58
|
+
|
|
59
|
+
const toastStyle = computed(() => ({
|
|
60
|
+
zIndex: 1000
|
|
61
|
+
}))
|
|
62
|
+
|
|
63
|
+
const show = () => {
|
|
64
|
+
visible.value = true
|
|
65
|
+
|
|
66
|
+
if (props.type !== 'loading' && props.duration > 0) {
|
|
67
|
+
timer = setTimeout(() => {
|
|
68
|
+
hide()
|
|
69
|
+
}, props.duration)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const hide = () => {
|
|
74
|
+
visible.value = false
|
|
75
|
+
if (timer) {
|
|
76
|
+
clearTimeout(timer)
|
|
77
|
+
timer = null
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
onUnmounted(() => {
|
|
82
|
+
if (timer) {
|
|
83
|
+
clearTimeout(timer)
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
defineExpose({
|
|
88
|
+
show,
|
|
89
|
+
hide
|
|
90
|
+
})
|
|
91
|
+
</script>
|
|
92
|
+
|
|
93
|
+
<script lang="ts">
|
|
94
|
+
export default {
|
|
95
|
+
options: {
|
|
96
|
+
virtualHost: true,
|
|
97
|
+
styleIsolation: 'shared'
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
</script>
|
|
101
|
+
|
|
102
|
+
<style lang="scss" scoped>
|
|
103
|
+
.u-toast {
|
|
104
|
+
position: fixed;
|
|
105
|
+
left: 50%;
|
|
106
|
+
transform: translateX(-50%);
|
|
107
|
+
z-index: 1000;
|
|
108
|
+
pointer-events: none;
|
|
109
|
+
|
|
110
|
+
&--top {
|
|
111
|
+
top: 50px;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
&--middle {
|
|
115
|
+
top: 50%;
|
|
116
|
+
transform: translate(-50%, -50%);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
&--bottom {
|
|
120
|
+
bottom: 50px;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
&--forbid-click {
|
|
124
|
+
pointer-events: auto;
|
|
125
|
+
width: 100vw;
|
|
126
|
+
height: 100vh;
|
|
127
|
+
left: 0;
|
|
128
|
+
top: 0;
|
|
129
|
+
transform: none;
|
|
130
|
+
background-color: transparent;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
&__content {
|
|
134
|
+
display: flex;
|
|
135
|
+
flex-direction: column;
|
|
136
|
+
align-items: center;
|
|
137
|
+
justify-content: center;
|
|
138
|
+
padding: $--spacing-base $--spacing-lg;
|
|
139
|
+
background-color: rgba(0, 0, 0, 0.7);
|
|
140
|
+
border-radius: $--radius-lg;
|
|
141
|
+
min-width: 100px;
|
|
142
|
+
max-width: 280px;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
&--loading &__content {
|
|
146
|
+
min-width: 80px;
|
|
147
|
+
min-height: 80px;
|
|
148
|
+
padding: $--spacing-lg;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
&__icon {
|
|
152
|
+
font-size: 32px;
|
|
153
|
+
color: $--text-color-white;
|
|
154
|
+
margin-bottom: $--spacing-sm;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
&__loading {
|
|
158
|
+
display: flex;
|
|
159
|
+
align-items: center;
|
|
160
|
+
justify-content: center;
|
|
161
|
+
margin-bottom: $--spacing-sm;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
&__loading-icon {
|
|
165
|
+
width: 24px;
|
|
166
|
+
height: 24px;
|
|
167
|
+
border: 2px solid rgba(255, 255, 255, 0.3);
|
|
168
|
+
border-top-color: $--text-color-white;
|
|
169
|
+
border-radius: 50%;
|
|
170
|
+
animation: u-toast-loading 0.8s linear infinite;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
@keyframes u-toast-loading {
|
|
174
|
+
to {
|
|
175
|
+
transform: rotate(360deg);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
&__text {
|
|
180
|
+
font-size: $--font-size-base;
|
|
181
|
+
color: $--text-color-white;
|
|
182
|
+
line-height: 1.4;
|
|
183
|
+
text-align: center;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
</style>
|