@veltra/mobile 1.0.0 → 1.1.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/package.json +32 -6
- package/src/components/_internal/bottom-sheet/bottom-sheet.vue +81 -0
- package/src/components/_internal/bottom-sheet/index.ts +1 -0
- package/src/components/_internal/bottom-sheet/style.scss +116 -0
- package/src/components/_internal/bottom-sheet/style.ts +1 -0
- package/src/components/_internal/overlay-container.ts +34 -0
- package/src/components/avatar/avatar.vue +44 -0
- package/src/components/avatar/index.ts +1 -0
- package/src/components/avatar/style.scss +53 -0
- package/src/components/avatar/style.ts +1 -0
- package/src/components/badge/badge.vue +59 -0
- package/src/components/badge/index.ts +1 -0
- package/src/components/badge/style.scss +62 -0
- package/src/components/badge/style.ts +1 -0
- package/src/components/button/button.vue +76 -0
- package/src/components/button/index.ts +1 -0
- package/src/components/button/style.scss +207 -0
- package/src/components/button/style.ts +1 -0
- package/src/components/card/card.vue +24 -0
- package/src/components/card/index.ts +1 -0
- package/src/components/card/style.scss +35 -0
- package/src/components/card/style.ts +1 -0
- package/src/components/cascade/cascade.vue +595 -0
- package/src/components/cascade/index.ts +1 -0
- package/src/components/cascade/node.ts +29 -0
- package/src/components/cascade/style.scss +424 -0
- package/src/components/cascade/style.ts +2 -0
- package/src/components/check-tag/check-tag.vue +35 -0
- package/src/components/check-tag/index.ts +1 -0
- package/src/components/check-tag/style.scss +46 -0
- package/src/components/check-tag/style.ts +1 -0
- package/src/components/checkbox/checkbox.vue +67 -0
- package/src/components/checkbox/index.ts +1 -0
- package/src/components/checkbox/style.scss +132 -0
- package/src/components/checkbox/style.ts +2 -0
- package/src/components/checkbox-group/checkbox-group.vue +94 -0
- package/src/components/checkbox-group/index.ts +1 -0
- package/src/components/checkbox-group/style.scss +57 -0
- package/src/components/checkbox-group/style.ts +2 -0
- package/src/components/collapse/collapse-item.vue +134 -0
- package/src/components/collapse/collapse.vue +117 -0
- package/src/components/collapse/di.ts +18 -0
- package/src/components/collapse/index.ts +3 -0
- package/src/components/collapse/style.scss +157 -0
- package/src/components/collapse/style.ts +1 -0
- package/src/components/date-picker/date-picker.vue +326 -0
- package/src/components/date-picker/index.ts +1 -0
- package/src/components/date-picker/style.scss +236 -0
- package/src/components/date-picker/style.ts +2 -0
- package/src/components/descriptions/descriptions-item.vue +12 -0
- package/src/components/descriptions/descriptions.vue +50 -0
- package/src/components/descriptions/index.ts +2 -0
- package/src/components/descriptions/style.scss +120 -0
- package/src/components/descriptions/style.ts +1 -0
- package/src/components/dialog/dialog.vue +143 -0
- package/src/components/dialog/index.ts +1 -0
- package/src/components/dialog/style.scss +163 -0
- package/src/components/dialog/style.ts +4 -0
- package/src/components/divider/divider.vue +29 -0
- package/src/components/divider/index.ts +1 -0
- package/src/components/divider/style.scss +91 -0
- package/src/components/divider/style.ts +1 -0
- package/src/components/drawer/drawer.vue +168 -0
- package/src/components/drawer/index.ts +1 -0
- package/src/components/drawer/style.scss +240 -0
- package/src/components/drawer/style.ts +2 -0
- package/src/components/empty/empty.vue +22 -0
- package/src/components/empty/index.ts +1 -0
- package/src/components/empty/style.scss +36 -0
- package/src/components/empty/style.ts +1 -0
- package/src/components/form/form.vue +119 -0
- package/src/components/form/index.ts +1 -0
- package/src/components/form/is-field-modified.ts +16 -0
- package/src/components/form/style.scss +58 -0
- package/src/components/form/style.ts +2 -0
- package/src/components/form/use-form-fields.ts +115 -0
- package/src/components/form/use-node-interceptor.ts +101 -0
- package/src/components/form-item/form-item.vue +171 -0
- package/src/components/form-item/helper.ts +9 -0
- package/src/components/form-item/index.ts +1 -0
- package/src/components/form-item/style.scss +121 -0
- package/src/components/form-item/style.ts +1 -0
- package/src/components/form-item/validate.ts +131 -0
- package/src/components/icon/icon.vue +23 -0
- package/src/components/icon/index.ts +1 -0
- package/src/components/icon/style.scss +37 -0
- package/src/components/icon/style.ts +1 -0
- package/src/components/input/index.ts +1 -0
- package/src/components/input/input.vue +187 -0
- package/src/components/input/style.scss +121 -0
- package/src/components/input/style.ts +1 -0
- package/src/components/list/index.ts +3 -0
- package/src/components/list/list-item.vue +20 -0
- package/src/components/list/list.vue +20 -0
- package/src/components/list/style.scss +50 -0
- package/src/components/list/style.ts +1 -0
- package/src/components/loading/directive.ts +34 -0
- package/src/components/loading/index.ts +3 -0
- package/src/components/loading/loading.vue +25 -0
- package/src/components/loading/style.scss +179 -0
- package/src/components/loading/style.ts +2 -0
- package/src/components/message/helper.ts +28 -0
- package/src/components/message/index.ts +3 -0
- package/src/components/message/message-box.vue +31 -0
- package/src/components/message/message.ts +122 -0
- package/src/components/message/message.vue +54 -0
- package/src/components/message/style.scss +130 -0
- package/src/components/message/style.ts +1 -0
- package/src/components/message-confirm/index.ts +3 -0
- package/src/components/message-confirm/message-confirm-box.vue +36 -0
- package/src/components/message-confirm/message-confirm.ts +139 -0
- package/src/components/message-confirm/message-confirm.vue +53 -0
- package/src/components/message-confirm/style.scss +138 -0
- package/src/components/message-confirm/style.ts +1 -0
- package/src/components/multi-select/index.ts +1 -0
- package/src/components/multi-select/multi-select.vue +410 -0
- package/src/components/multi-select/style.scss +376 -0
- package/src/components/multi-select/style.ts +2 -0
- package/src/components/number-input/index.ts +1 -0
- package/src/components/number-input/number-input.vue +407 -0
- package/src/components/number-input/style.scss +118 -0
- package/src/components/number-input/style.ts +2 -0
- package/src/components/password-input/index.ts +1 -0
- package/src/components/password-input/password-input.vue +134 -0
- package/src/components/password-input/style.scss +40 -0
- package/src/components/password-input/style.ts +2 -0
- package/src/components/progress/index.ts +1 -0
- package/src/components/progress/progress.vue +90 -0
- package/src/components/progress/style.scss +73 -0
- package/src/components/progress/style.ts +1 -0
- package/src/components/radio/index.ts +1 -0
- package/src/components/radio/radio.vue +57 -0
- package/src/components/radio/style.scss +113 -0
- package/src/components/radio/style.ts +1 -0
- package/src/components/radio-group/index.ts +1 -0
- package/src/components/radio-group/radio-group.vue +60 -0
- package/src/components/radio-group/style.scss +29 -0
- package/src/components/radio-group/style.ts +2 -0
- package/src/components/segment/index.ts +1 -0
- package/src/components/segment/segment.vue +121 -0
- package/src/components/segment/style.scss +118 -0
- package/src/components/segment/style.ts +1 -0
- package/src/components/select/index.ts +1 -0
- package/src/components/select/select.vue +278 -0
- package/src/components/select/style.scss +237 -0
- package/src/components/select/style.ts +2 -0
- package/src/components/select/use-options.ts +195 -0
- package/src/components/skeleton/index.ts +1 -0
- package/src/components/skeleton/skeleton.vue +37 -0
- package/src/components/skeleton/style.scss +95 -0
- package/src/components/skeleton/style.ts +1 -0
- package/src/components/space/index.ts +1 -0
- package/src/components/space/space.vue +45 -0
- package/src/components/space/style.scss +41 -0
- package/src/components/space/style.ts +1 -0
- package/src/components/steps/index.ts +1 -0
- package/src/components/steps/steps.vue +114 -0
- package/src/components/steps/style.scss +231 -0
- package/src/components/steps/style.ts +1 -0
- package/src/components/switch/index.ts +1 -0
- package/src/components/switch/style.scss +137 -0
- package/src/components/switch/style.ts +1 -0
- package/src/components/switch/switch.vue +63 -0
- package/src/components/tabs/index.ts +1 -0
- package/src/components/tabs/style.scss +285 -0
- package/src/components/tabs/style.ts +1 -0
- package/src/components/tabs/tabs.vue +127 -0
- package/src/components/tag/index.ts +1 -0
- package/src/components/tag/style.scss +114 -0
- package/src/components/tag/style.ts +1 -0
- package/src/components/tag/tag.vue +49 -0
- package/src/components/text/index.ts +1 -0
- package/src/components/text/style.scss +63 -0
- package/src/components/text/style.ts +1 -0
- package/src/components/text/text.vue +63 -0
- package/src/components/textarea/index.ts +1 -0
- package/src/components/textarea/style.scss +124 -0
- package/src/components/textarea/style.ts +1 -0
- package/src/components/textarea/textarea.vue +121 -0
- package/src/components/textarea/utils.ts +11 -0
- package/src/components/time-picker/index.ts +1 -0
- package/src/components/time-picker/style.scss +216 -0
- package/src/components/time-picker/style.ts +2 -0
- package/src/components/time-picker/time-picker.vue +263 -0
- package/src/components/timeline/index.ts +2 -0
- package/src/components/timeline/style.scss +107 -0
- package/src/components/timeline/style.ts +1 -0
- package/src/components/timeline/timeline-item.vue +43 -0
- package/src/components/timeline/timeline.vue +16 -0
- package/src/components/uploader/index.ts +1 -0
- package/src/components/uploader/style.scss +220 -0
- package/src/components/uploader/style.ts +1 -0
- package/src/components/uploader/uploader.vue +306 -0
- package/src/env.d.ts +7 -0
- package/src/index.ts +99 -1
- package/src/shared/bem.ts +12 -0
- package/src/shared/use-scroll-lock.ts +111 -0
- package/src/shared/use-touch-gesture.ts +150 -0
- package/src/styles/_tokens.scss +129 -0
- package/src/types/avatar.ts +31 -0
- package/src/types/badge.ts +28 -0
- package/src/types/button.ts +48 -0
- package/src/types/card.ts +16 -0
- package/src/types/cascade.ts +87 -0
- package/src/types/check-tag.ts +24 -0
- package/src/types/checkbox-group.ts +20 -0
- package/src/types/checkbox.ts +15 -0
- package/src/types/collapse.ts +79 -0
- package/src/types/date-picker.ts +39 -0
- package/src/types/descriptions.ts +22 -0
- package/src/types/dialog.ts +54 -0
- package/src/types/divider.ts +14 -0
- package/src/types/drawer.ts +38 -0
- package/src/types/empty.ts +19 -0
- package/src/types/form-item.ts +22 -0
- package/src/types/form.ts +54 -0
- package/src/types/icon.ts +10 -0
- package/src/types/input.ts +51 -0
- package/src/types/list.ts +13 -0
- package/src/types/loading.ts +20 -0
- package/src/types/message-confirm.ts +72 -0
- package/src/types/message.ts +71 -0
- package/src/types/multi-select.ts +38 -0
- package/src/types/number-input.ts +32 -0
- package/src/types/password-input.ts +19 -0
- package/src/types/progress.ts +22 -0
- package/src/types/radio-group.ts +33 -0
- package/src/types/radio.ts +18 -0
- package/src/types/segment.ts +42 -0
- package/src/types/select.ts +63 -0
- package/src/types/skeleton.ts +29 -0
- package/src/types/space.ts +22 -0
- package/src/types/steps.ts +67 -0
- package/src/types/switch.ts +17 -0
- package/src/types/tabs.ts +63 -0
- package/src/types/tag.ts +19 -0
- package/src/types/text.ts +28 -0
- package/src/types/textarea.ts +76 -0
- package/src/types/time-picker.ts +40 -0
- package/src/types/timeline.ts +15 -0
- package/src/types/uploader.ts +50 -0
- package/.turbo/turbo-build.log +0 -2
- package/.turbo/turbo-check-types.log +0 -1
- package/tsconfig.json +0 -12
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
@use 'pkg:@veltra/styles/mixins' as m with ($namespace: um);
|
|
2
|
+
@use 'pkg:@veltra/styles/functions' as fn;
|
|
3
|
+
@use '../../styles/tokens' as t;
|
|
4
|
+
|
|
5
|
+
$root-name: list;
|
|
6
|
+
$item-name: $root-name + '-item';
|
|
7
|
+
|
|
8
|
+
// 移动端列表:无滚动包装层,原生 ul/li 直接承载滚动;
|
|
9
|
+
// 行高、字号、行间距走 --um-* 密度 token,行高保底 44px 触控热区
|
|
10
|
+
@include m.b($root-name) {
|
|
11
|
+
margin: 0;
|
|
12
|
+
padding: 0;
|
|
13
|
+
list-style: none;
|
|
14
|
+
|
|
15
|
+
// 行基础形态(与尺寸档无关)+ 可点行按压态
|
|
16
|
+
@include m.bem($item-name) {
|
|
17
|
+
display: flex;
|
|
18
|
+
align-items: center;
|
|
19
|
+
line-height: 1.4;
|
|
20
|
+
font-size: t.use-var(font-size-main);
|
|
21
|
+
|
|
22
|
+
// 绑定 @click 即视为可点行:移动端无 hover,用 :active 提供按压反馈
|
|
23
|
+
@include m.is(clickable) {
|
|
24
|
+
-webkit-tap-highlight-color: transparent;
|
|
25
|
+
|
|
26
|
+
&:active {
|
|
27
|
+
background-color: fn.use-var(bg-color, hover);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 尺寸档:行高取控件高度档并保底 44px,横向内边距走间距刻度
|
|
33
|
+
@include m.size using ($size) {
|
|
34
|
+
@include m.bem($item-name) {
|
|
35
|
+
$padding: t.use-var(spacing-lg);
|
|
36
|
+
|
|
37
|
+
@if $size == small {
|
|
38
|
+
$padding: t.use-var(spacing-md);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@if $size == large {
|
|
42
|
+
$padding: t.use-var(spacing-xl);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
padding: 0 $padding;
|
|
46
|
+
border-radius: t.control-radius($size);
|
|
47
|
+
min-height: max(t.control-height($size), t.use-var(touch-target));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './style.scss'
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createVNode, render, type DirectiveBinding, type ObjectDirective } from 'vue'
|
|
2
|
+
|
|
3
|
+
import { bem } from '../../shared/bem'
|
|
4
|
+
import type { LoadingType } from '../../types/loading'
|
|
5
|
+
import LoadingComponent from './loading.vue'
|
|
6
|
+
|
|
7
|
+
const loadingCls = bem('loading')
|
|
8
|
+
const loadingContainerCls = loadingCls.e('container')
|
|
9
|
+
|
|
10
|
+
function renderLoading(el: HTMLElement, binding: DirectiveBinding) {
|
|
11
|
+
el.classList.add(loadingContainerCls)
|
|
12
|
+
|
|
13
|
+
const node = createVNode(LoadingComponent, { type: binding.arg as LoadingType })
|
|
14
|
+
|
|
15
|
+
render(node, el)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function removeLoading(el: HTMLElement) {
|
|
19
|
+
render(null, el)
|
|
20
|
+
el.classList.remove(loadingContainerCls)
|
|
21
|
+
}
|
|
22
|
+
export const vLoading: ObjectDirective<HTMLElement> = {
|
|
23
|
+
mounted(el, binding) {
|
|
24
|
+
binding.value && renderLoading(el, binding)
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
updated(el, binding) {
|
|
28
|
+
binding.value ? renderLoading(el, binding) : removeLoading(el)
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
unmounted(el) {
|
|
32
|
+
removeLoading(el)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<transition name="fade" appear>
|
|
3
|
+
<div :class="className" :style="{ zIndex: zIndex() }">
|
|
4
|
+
<div :class="cls.e('loader')"></div>
|
|
5
|
+
</div>
|
|
6
|
+
</transition>
|
|
7
|
+
</template>
|
|
8
|
+
|
|
9
|
+
<script lang="ts" setup>
|
|
10
|
+
import { zIndex } from '@veltra/utils'
|
|
11
|
+
import { computed } from 'vue'
|
|
12
|
+
|
|
13
|
+
import { bem } from '../../shared/bem'
|
|
14
|
+
import type { LoadingProps } from '../../types/loading'
|
|
15
|
+
|
|
16
|
+
defineOptions({ name: 'ULoading' })
|
|
17
|
+
|
|
18
|
+
const props = withDefaults(defineProps<LoadingProps>(), { type: 'dual-ring' })
|
|
19
|
+
|
|
20
|
+
const cls = bem('loading')
|
|
21
|
+
|
|
22
|
+
const className = computed(() => {
|
|
23
|
+
return [cls.b, cls.e(props.type)]
|
|
24
|
+
})
|
|
25
|
+
</script>
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
@use 'pkg:@veltra/styles/mixins' as m with ($namespace: um);
|
|
2
|
+
@use 'pkg:@veltra/styles/functions' as fn;
|
|
3
|
+
@use '../../styles/tokens' as t;
|
|
4
|
+
|
|
5
|
+
$root-name: loading;
|
|
6
|
+
|
|
7
|
+
// 指示器基准边长:走 --um-* 密度 token,各形态几何按其比例推导
|
|
8
|
+
$indicator: t.use-var(loading-indicator);
|
|
9
|
+
// 环形描边与内环参数(比例常量)
|
|
10
|
+
$ring-border: calc(#{$indicator} / 12);
|
|
11
|
+
$ring-inner-border: calc(#{$indicator} / 18);
|
|
12
|
+
$ring-inner-inset: calc(#{$indicator} / 6);
|
|
13
|
+
// 三点 / 竖条的单元尺寸(比例常量)
|
|
14
|
+
$dot-size: calc(#{$indicator} / 4);
|
|
15
|
+
$dot-gap: calc(#{$indicator} / 6);
|
|
16
|
+
$bar-width: calc(#{$indicator} / 6);
|
|
17
|
+
$bar-height: calc(#{$indicator} * 3 / 4);
|
|
18
|
+
|
|
19
|
+
@include m.b($root-name) {
|
|
20
|
+
position: absolute;
|
|
21
|
+
width: 100%;
|
|
22
|
+
height: 100%;
|
|
23
|
+
background-color: fn.use-var(bg-color, top, alpha);
|
|
24
|
+
color: fn.use-var(color, primary);
|
|
25
|
+
@include m.flex($justify: center, $align: center);
|
|
26
|
+
|
|
27
|
+
@include m.e(container) {
|
|
28
|
+
position: relative;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// ============================================================
|
|
32
|
+
// dual-ring — 双环反向旋转(经典 loader)
|
|
33
|
+
// 外环顺时针,内嵌小环逆时针,border + linear 旋转无缝循环
|
|
34
|
+
// ============================================================
|
|
35
|
+
@include m.e(dual-ring) {
|
|
36
|
+
@include m.bem($root-name, loader) {
|
|
37
|
+
width: $indicator;
|
|
38
|
+
aspect-ratio: 1;
|
|
39
|
+
border-radius: 50%;
|
|
40
|
+
border: #{$ring-border} solid fn.color-a(color, 22, primary);
|
|
41
|
+
border-top-color: currentColor;
|
|
42
|
+
position: relative;
|
|
43
|
+
animation: um-loading-spin 0.8s linear infinite;
|
|
44
|
+
|
|
45
|
+
&::after {
|
|
46
|
+
content: '';
|
|
47
|
+
position: absolute;
|
|
48
|
+
inset: $ring-inner-inset;
|
|
49
|
+
border-radius: 50%;
|
|
50
|
+
border: #{$ring-inner-border} solid fn.color-a(color, 22, primary);
|
|
51
|
+
border-bottom-color: currentColor;
|
|
52
|
+
animation: um-loading-spin 1.2s linear infinite reverse;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// ============================================================
|
|
58
|
+
// dot — 三点呼吸弹跳
|
|
59
|
+
// 元素自身 + 两个伪元素,交错起伏
|
|
60
|
+
// ============================================================
|
|
61
|
+
@include m.e(dot) {
|
|
62
|
+
@include m.bem($root-name, loader) {
|
|
63
|
+
width: $dot-size;
|
|
64
|
+
height: $dot-size;
|
|
65
|
+
border-radius: 50%;
|
|
66
|
+
background: currentColor;
|
|
67
|
+
position: relative;
|
|
68
|
+
animation: um-loading-dot 1.2s cubic-bezier(0.45, 0, 0.55, 1) infinite;
|
|
69
|
+
|
|
70
|
+
&::before,
|
|
71
|
+
&::after {
|
|
72
|
+
content: '';
|
|
73
|
+
position: absolute;
|
|
74
|
+
top: 0;
|
|
75
|
+
width: $dot-size;
|
|
76
|
+
height: $dot-size;
|
|
77
|
+
border-radius: 50%;
|
|
78
|
+
background: currentColor;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
&::before {
|
|
82
|
+
left: calc(-1 * (#{$dot-size} + #{$dot-gap}));
|
|
83
|
+
animation: um-loading-dot 1.2s cubic-bezier(0.45, 0, 0.55, 1) infinite;
|
|
84
|
+
animation-delay: 0.18s;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
&::after {
|
|
88
|
+
right: calc(-1 * (#{$dot-size} + #{$dot-gap}));
|
|
89
|
+
animation: um-loading-dot 1.2s cubic-bezier(0.45, 0, 0.55, 1) infinite;
|
|
90
|
+
animation-delay: 0.36s;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// ============================================================
|
|
96
|
+
// ring — 单环旋转
|
|
97
|
+
// ============================================================
|
|
98
|
+
@include m.e(ring) {
|
|
99
|
+
@include m.bem($root-name, loader) {
|
|
100
|
+
width: $indicator;
|
|
101
|
+
aspect-ratio: 1;
|
|
102
|
+
border-radius: 50%;
|
|
103
|
+
border: #{$ring-border} solid fn.color-a(color, 22, primary);
|
|
104
|
+
border-top-color: currentColor;
|
|
105
|
+
animation: um-loading-spin 0.9s linear infinite;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// ============================================================
|
|
110
|
+
// bars — 三条音频跳动
|
|
111
|
+
// 三根竖条以容器中心为基准上下对称伸缩
|
|
112
|
+
// ============================================================
|
|
113
|
+
@include m.e(bars) {
|
|
114
|
+
@include m.bem($root-name, loader) {
|
|
115
|
+
width: $bar-width;
|
|
116
|
+
height: $bar-height;
|
|
117
|
+
background: currentColor;
|
|
118
|
+
border-radius: calc(#{$bar-width} / 2);
|
|
119
|
+
position: relative;
|
|
120
|
+
animation: um-loading-bars 1s ease-in-out infinite;
|
|
121
|
+
animation-delay: 0.15s;
|
|
122
|
+
|
|
123
|
+
&::before,
|
|
124
|
+
&::after {
|
|
125
|
+
content: '';
|
|
126
|
+
position: absolute;
|
|
127
|
+
top: 50%;
|
|
128
|
+
transform: translateY(-50%);
|
|
129
|
+
width: $bar-width;
|
|
130
|
+
height: $bar-height;
|
|
131
|
+
background: currentColor;
|
|
132
|
+
border-radius: calc(#{$bar-width} / 2);
|
|
133
|
+
animation: um-loading-bars 1s ease-in-out infinite;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
&::before {
|
|
137
|
+
left: calc(-1 * (#{$bar-width} + #{$dot-gap}));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
&::after {
|
|
141
|
+
right: calc(-1 * (#{$bar-width} + #{$dot-gap}));
|
|
142
|
+
animation-delay: 0.3s;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// ================================================================
|
|
149
|
+
// 关键帧
|
|
150
|
+
// ================================================================
|
|
151
|
+
|
|
152
|
+
@keyframes um-loading-spin {
|
|
153
|
+
to {
|
|
154
|
+
transform: rotate(1turn);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
@keyframes um-loading-dot {
|
|
159
|
+
0%,
|
|
160
|
+
100% {
|
|
161
|
+
transform: scale(0.5);
|
|
162
|
+
opacity: 0.3;
|
|
163
|
+
}
|
|
164
|
+
50% {
|
|
165
|
+
transform: scale(1);
|
|
166
|
+
opacity: 1;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// 竖条伸缩的上下限按指示器基准推导(CSS 变量在关键帧内按动画元素解析)
|
|
171
|
+
@keyframes um-loading-bars {
|
|
172
|
+
0%,
|
|
173
|
+
100% {
|
|
174
|
+
height: calc(#{$indicator} / 4);
|
|
175
|
+
}
|
|
176
|
+
50% {
|
|
177
|
+
height: $bar-height;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CircleCheckFilled,
|
|
3
|
+
CircleClose,
|
|
4
|
+
InfoFilled,
|
|
5
|
+
QuestionFilled,
|
|
6
|
+
WarningFilled
|
|
7
|
+
} from '@veltra/icons/normal'
|
|
8
|
+
import type { ColorType } from '@veltra/utils'
|
|
9
|
+
import type { DefineComponent } from 'vue'
|
|
10
|
+
|
|
11
|
+
import type { MessageType } from '../../types/message'
|
|
12
|
+
|
|
13
|
+
const typeIcons = {
|
|
14
|
+
default: InfoFilled,
|
|
15
|
+
info: QuestionFilled,
|
|
16
|
+
success: CircleCheckFilled,
|
|
17
|
+
warn: WarningFilled,
|
|
18
|
+
error: CircleClose
|
|
19
|
+
}
|
|
20
|
+
export function getTypeIcon(type: MessageType, icon?: DefineComponent): DefineComponent {
|
|
21
|
+
return (icon ?? typeIcons[type]) as any
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const typeColors = { error: 'danger', warn: 'warning' }
|
|
25
|
+
|
|
26
|
+
export function getTypeColor(type: MessageType): ColorType {
|
|
27
|
+
return typeColors[type] ?? type
|
|
28
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<transition-group name="message" appear @after-leave="handleAfterLeave">
|
|
3
|
+
<UMessage
|
|
4
|
+
v-for="({ onClose, ...message }, index) of messages"
|
|
5
|
+
:key="message.key"
|
|
6
|
+
v-bind="message"
|
|
7
|
+
:data-id="message.key"
|
|
8
|
+
@close="handleClose(index, onClose)"
|
|
9
|
+
/>
|
|
10
|
+
</transition-group>
|
|
11
|
+
</template>
|
|
12
|
+
|
|
13
|
+
<script lang="ts" setup>
|
|
14
|
+
import type { MessageOptions } from '../../types/message'
|
|
15
|
+
import UMessage from './message.vue'
|
|
16
|
+
|
|
17
|
+
defineOptions({ name: 'UMessageBox' })
|
|
18
|
+
|
|
19
|
+
defineProps<{ messages: Array<Omit<MessageOptions & { key: string }, 'onClosed'>> }>()
|
|
20
|
+
|
|
21
|
+
const emit = defineEmits<{ (e: 'closed', id: string): void; (e: 'close', index: number): void }>()
|
|
22
|
+
|
|
23
|
+
function handleAfterLeave(el: Element) {
|
|
24
|
+
emit('closed', (el as HTMLElement).dataset.id as string)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function handleClose(i: number, onClose?: () => void) {
|
|
28
|
+
emit('close', i)
|
|
29
|
+
onClose?.()
|
|
30
|
+
}
|
|
31
|
+
</script>
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { setStyles, zIndex } from '@veltra/utils'
|
|
2
|
+
import { h, render, shallowReactive } from 'vue'
|
|
3
|
+
|
|
4
|
+
import { bem } from '../../shared/bem'
|
|
5
|
+
import type { Message, MessageInstance, MessageOptions } from '../../types/message'
|
|
6
|
+
import { getOverlayContainer } from '../_internal/overlay-container'
|
|
7
|
+
import UMessageBox from './message-box.vue'
|
|
8
|
+
|
|
9
|
+
const cls = bem('message')
|
|
10
|
+
|
|
11
|
+
/** 消息项数据结构 */
|
|
12
|
+
type MessageItem = MessageOptions & { key: string }
|
|
13
|
+
|
|
14
|
+
/** --- 状态管理 --- */
|
|
15
|
+
let container: HTMLElement | null = null
|
|
16
|
+
const messages = shallowReactive<MessageItem[]>([])
|
|
17
|
+
|
|
18
|
+
/** 消息关闭后回调 */
|
|
19
|
+
const closedCallbacks = new Map<string, () => void>()
|
|
20
|
+
|
|
21
|
+
/** 用于计数正在显示的 DOM 节点 (包含动画执行中) */
|
|
22
|
+
let activeCount = 0
|
|
23
|
+
let uid = 0
|
|
24
|
+
|
|
25
|
+
/** --- 内部辅助函数 --- */
|
|
26
|
+
|
|
27
|
+
/** 彻底销毁容器 */
|
|
28
|
+
const destroy = () => {
|
|
29
|
+
if (container) {
|
|
30
|
+
render(null, container)
|
|
31
|
+
container.remove()
|
|
32
|
+
container = null
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** 离开动画结束后的清理 */
|
|
37
|
+
const handleClosed = (id: string) => {
|
|
38
|
+
activeCount--
|
|
39
|
+
|
|
40
|
+
const cb = closedCallbacks.get(id)
|
|
41
|
+
if (cb) {
|
|
42
|
+
cb()
|
|
43
|
+
closedCallbacks.delete(id)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// 没有活跃消息时销毁容器,保持页面干净
|
|
47
|
+
if (activeCount === 0) destroy()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** 触发关闭 (仅从数组移除,触发 Transition 离开动画) */
|
|
51
|
+
const handleClose = (id: string) => {
|
|
52
|
+
const index = messages.findIndex((m) => m.key === id)
|
|
53
|
+
if (index !== -1) messages.splice(index, 1)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** 挂载并渲染容器 */
|
|
57
|
+
const ensureContainer = () => {
|
|
58
|
+
// 宿主容器可能随设备外壳卸载而失效,失联时重建
|
|
59
|
+
if (container?.isConnected) return container
|
|
60
|
+
container = null
|
|
61
|
+
|
|
62
|
+
container = document.createElement('ul')
|
|
63
|
+
container.className = cls.e('container')
|
|
64
|
+
getOverlayContainer().appendChild(container)
|
|
65
|
+
return container
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** 执行 Vue 渲染逻辑 */
|
|
69
|
+
const updateView = () => {
|
|
70
|
+
const el = ensureContainer()
|
|
71
|
+
setStyles(el, { zIndex: zIndex() })
|
|
72
|
+
|
|
73
|
+
const vnode = h(UMessageBox, {
|
|
74
|
+
messages,
|
|
75
|
+
onClosed: handleClosed,
|
|
76
|
+
onClose: (i: number) => messages.splice(i, 1)
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
vnode.appContext = message._context
|
|
80
|
+
render(vnode, el)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** 创建消息实例 */
|
|
84
|
+
const createMessage = (options: MessageOptions): MessageInstance => {
|
|
85
|
+
const { onClosed: userOnClosed, ...messageOptions } = options
|
|
86
|
+
const id = `msg_${uid++}`
|
|
87
|
+
activeCount++
|
|
88
|
+
|
|
89
|
+
// 生命周期 Promise
|
|
90
|
+
let resolveClosed: () => void
|
|
91
|
+
const onClosed = new Promise<void>((r) => (resolveClosed = r))
|
|
92
|
+
|
|
93
|
+
closedCallbacks.set(id, () => {
|
|
94
|
+
userOnClosed?.()
|
|
95
|
+
resolveClosed()
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
messages.push({ key: id, ...messageOptions })
|
|
99
|
+
updateView()
|
|
100
|
+
|
|
101
|
+
return { id, close: () => handleClose(id), onClosed }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** --- 导出 API --- */
|
|
105
|
+
|
|
106
|
+
export const message = ((options) => {
|
|
107
|
+
const mergedOptions = typeof options === 'string' ? { message: options } : options
|
|
108
|
+
return createMessage(mergedOptions)
|
|
109
|
+
}) as Message
|
|
110
|
+
|
|
111
|
+
message._context = null
|
|
112
|
+
|
|
113
|
+
// 挂载快捷方法: message.success(...)
|
|
114
|
+
const messageTypes = ['success', 'warn', 'info', 'error', 'default'] as const
|
|
115
|
+
messageTypes.forEach((type) => {
|
|
116
|
+
message[type] = (msg, config) => message({ ...config, message: msg, type })
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
/** 关闭所有当前显示的消息 */
|
|
120
|
+
message.closeAll = () => {
|
|
121
|
+
messages.splice(0)
|
|
122
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<li :class="[cls.b, cls.m('color-' + getTypeColor(type))]">
|
|
3
|
+
<span :class="cls.e('icon')">
|
|
4
|
+
<UIcon>
|
|
5
|
+
<component :is="getTypeIcon(type, icon)" />
|
|
6
|
+
</UIcon>
|
|
7
|
+
</span>
|
|
8
|
+
<div :class="cls.e('content')" v-if="html" v-html="message"></div>
|
|
9
|
+
<div :class="cls.e('content')" v-else>
|
|
10
|
+
{{ message }}
|
|
11
|
+
</div>
|
|
12
|
+
<button
|
|
13
|
+
:class="cls.e('close')"
|
|
14
|
+
v-if="closable || duration === 0"
|
|
15
|
+
type="button"
|
|
16
|
+
aria-label="关闭"
|
|
17
|
+
@click.stop="immediateClose"
|
|
18
|
+
>
|
|
19
|
+
<UIcon><Close /></UIcon>
|
|
20
|
+
</button>
|
|
21
|
+
</li>
|
|
22
|
+
</template>
|
|
23
|
+
|
|
24
|
+
<script lang="ts" setup>
|
|
25
|
+
import { Close } from '@veltra/icons/normal'
|
|
26
|
+
import { onBeforeUnmount, onMounted } from 'vue'
|
|
27
|
+
|
|
28
|
+
import { bem } from '../../shared/bem'
|
|
29
|
+
import type { MessageProps } from '../../types/message'
|
|
30
|
+
import { UIcon } from '../icon'
|
|
31
|
+
import { getTypeColor, getTypeIcon } from './helper'
|
|
32
|
+
|
|
33
|
+
defineOptions({ name: 'UMessage' })
|
|
34
|
+
|
|
35
|
+
const props = withDefaults(defineProps<MessageProps>(), { type: 'default', duration: 3000 })
|
|
36
|
+
|
|
37
|
+
const emit = defineEmits<{ (e: 'close'): void }>()
|
|
38
|
+
|
|
39
|
+
const cls = bem('message')
|
|
40
|
+
|
|
41
|
+
// 移动端无 hover,不做悬停暂停:到时关闭,点击关闭按钮立即关闭
|
|
42
|
+
let timer: number | undefined
|
|
43
|
+
|
|
44
|
+
onMounted(() => {
|
|
45
|
+
if (props.duration <= 0) return
|
|
46
|
+
timer = setTimeout(() => emit('close'), props.duration)
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
onBeforeUnmount(() => clearTimeout(timer))
|
|
50
|
+
|
|
51
|
+
function immediateClose() {
|
|
52
|
+
emit('close')
|
|
53
|
+
}
|
|
54
|
+
</script>
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
@use 'pkg:@veltra/styles/mixins' as m with ($namespace: um);
|
|
2
|
+
@use 'pkg:@veltra/styles/functions' as fn;
|
|
3
|
+
@use 'pkg:@veltra/styles/vars' as vars;
|
|
4
|
+
@use '../../styles/tokens' as t;
|
|
5
|
+
|
|
6
|
+
// 方便拼接
|
|
7
|
+
$root-name: message;
|
|
8
|
+
|
|
9
|
+
// 顶部轻提示容器:视口顶部居中列排,避让刘海安全区
|
|
10
|
+
@include m.bem($root-name, container) {
|
|
11
|
+
position: fixed;
|
|
12
|
+
top: 0;
|
|
13
|
+
left: 0;
|
|
14
|
+
width: 100%;
|
|
15
|
+
box-sizing: border-box;
|
|
16
|
+
display: flex;
|
|
17
|
+
flex-direction: column;
|
|
18
|
+
align-items: center;
|
|
19
|
+
// 两侧留白保证提示在窄视口内不贴边溢出;顶部避让刘海安全区
|
|
20
|
+
padding: calc(#{t.use-var(spacing-md)} + constant(safe-area-inset-top)) #{t.use-var(spacing-md)} 0;
|
|
21
|
+
padding: calc(#{t.use-var(spacing-md)} + env(safe-area-inset-top)) #{t.use-var(spacing-md)} 0;
|
|
22
|
+
pointer-events: none;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@include m.b($root-name) {
|
|
26
|
+
pointer-events: auto;
|
|
27
|
+
box-sizing: border-box;
|
|
28
|
+
display: inline-flex;
|
|
29
|
+
align-items: center;
|
|
30
|
+
// 触控热区不小于 44(含可关闭提示的整条热区)
|
|
31
|
+
min-height: t.use-var(touch-target);
|
|
32
|
+
max-width: 100%;
|
|
33
|
+
margin-bottom: t.use-var(spacing-sm);
|
|
34
|
+
padding: t.use-var(spacing-sm) t.use-var(spacing-lg);
|
|
35
|
+
gap: t.use-var(spacing-sm);
|
|
36
|
+
border-radius: t.use-var('panel-radius');
|
|
37
|
+
font-size: t.use-var(font-size-main);
|
|
38
|
+
line-height: 1.5;
|
|
39
|
+
box-shadow: fn.use-var(shadow, lg);
|
|
40
|
+
|
|
41
|
+
@include m.e(icon) {
|
|
42
|
+
display: inline-flex;
|
|
43
|
+
flex-shrink: 0;
|
|
44
|
+
|
|
45
|
+
// 与 UIcon 的 1em 图标对齐
|
|
46
|
+
> svg {
|
|
47
|
+
width: 1em;
|
|
48
|
+
height: 1em;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@include m.e(content) {
|
|
53
|
+
min-width: 0;
|
|
54
|
+
word-break: break-all;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@include m.e(close) {
|
|
58
|
+
// 关闭热区不小于 44x44(外扩补足,不挤压内容)
|
|
59
|
+
flex-shrink: 0;
|
|
60
|
+
display: inline-flex;
|
|
61
|
+
align-items: center;
|
|
62
|
+
justify-content: center;
|
|
63
|
+
min-width: t.use-var(touch-target);
|
|
64
|
+
min-height: t.use-var(touch-target);
|
|
65
|
+
margin: calc(-1 * #{t.use-var(spacing-sm)}) calc(-1 * #{t.use-var(spacing-lg)});
|
|
66
|
+
padding: 0;
|
|
67
|
+
border: none;
|
|
68
|
+
background: none;
|
|
69
|
+
color: inherit;
|
|
70
|
+
font-size: 1em;
|
|
71
|
+
-webkit-appearance: none;
|
|
72
|
+
-webkit-tap-highlight-color: transparent;
|
|
73
|
+
|
|
74
|
+
> svg {
|
|
75
|
+
width: 1em;
|
|
76
|
+
height: 1em;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@each $type, $_ in vars.$color-types {
|
|
81
|
+
@if ($type == 'default') {
|
|
82
|
+
@include m.m(color-#{$type}) {
|
|
83
|
+
background-color: fn.use-var(color, $type);
|
|
84
|
+
color: fn.use-var(text-color, main);
|
|
85
|
+
}
|
|
86
|
+
} @else {
|
|
87
|
+
@include m.m(color-#{$type}) {
|
|
88
|
+
background-color: fn.use-var(color, $type, 'light-9');
|
|
89
|
+
color: fn.use-var(color, $type);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/* 进出场:自顶部滑入滑出(transition-group name="message") */
|
|
96
|
+
.#{$root-name}-move,
|
|
97
|
+
.#{$root-name}-enter-active,
|
|
98
|
+
.#{$root-name}-leave-active {
|
|
99
|
+
transition:
|
|
100
|
+
opacity fn.use-var(transition, normal) fn.use-var(transition, ease),
|
|
101
|
+
transform fn.use-var(transition, normal) fn.use-var(transition, ease);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.#{$root-name}-enter-from,
|
|
105
|
+
.#{$root-name}-leave-to {
|
|
106
|
+
opacity: 0;
|
|
107
|
+
transform: translateY(-100%);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/* 确保将离开的元素从布局流中删除
|
|
111
|
+
以便能够正确地计算移动的动画。 */
|
|
112
|
+
.#{$root-name}-leave-active {
|
|
113
|
+
position: absolute;
|
|
114
|
+
width: max-content;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// 减弱动态效果:不位移、不缩放,堆叠重排也不滑动,只保留透明度
|
|
118
|
+
@media (prefers-reduced-motion: reduce) {
|
|
119
|
+
.message-move,
|
|
120
|
+
.message-enter-active,
|
|
121
|
+
.message-leave-active {
|
|
122
|
+
transition-property: opacity;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
.message-enter-from,
|
|
126
|
+
.message-leave-to {
|
|
127
|
+
transform: none;
|
|
128
|
+
opacity: 0;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './style.scss'
|