@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,220 @@
|
|
|
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: uploader;
|
|
6
|
+
|
|
7
|
+
@include m.b($root-name) {
|
|
8
|
+
@include m.size using ($size) {
|
|
9
|
+
@include m.bem($root-name, item) {
|
|
10
|
+
width: t.uploader-size($size);
|
|
11
|
+
height: t.uploader-size($size);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@include m.e(list) {
|
|
16
|
+
@include m.flex;
|
|
17
|
+
flex-wrap: wrap;
|
|
18
|
+
gap: t.use-var('spacing-sm');
|
|
19
|
+
margin: 0;
|
|
20
|
+
padding: 0;
|
|
21
|
+
list-style: none;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@include m.e(item) {
|
|
25
|
+
position: relative;
|
|
26
|
+
flex-shrink: 0;
|
|
27
|
+
box-sizing: border-box;
|
|
28
|
+
border-radius: t.control-radius(default);
|
|
29
|
+
overflow: hidden;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@include m.e(thumb) {
|
|
33
|
+
display: block;
|
|
34
|
+
width: 100%;
|
|
35
|
+
height: 100%;
|
|
36
|
+
object-fit: cover;
|
|
37
|
+
cursor: pointer;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@include m.e(file) {
|
|
41
|
+
display: flex;
|
|
42
|
+
flex-direction: column;
|
|
43
|
+
align-items: center;
|
|
44
|
+
justify-content: center;
|
|
45
|
+
gap: t.use-var('spacing-xs');
|
|
46
|
+
width: 100%;
|
|
47
|
+
height: 100%;
|
|
48
|
+
box-sizing: border-box;
|
|
49
|
+
padding: t.use-var('spacing-xs');
|
|
50
|
+
background-color: fn.use-var(color, default, light-9);
|
|
51
|
+
cursor: pointer;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@include m.e(file-badge) {
|
|
55
|
+
@include m.flex(inline-flex);
|
|
56
|
+
justify-content: center;
|
|
57
|
+
padding: 1px t.use-var('spacing-xs');
|
|
58
|
+
border-radius: t.control-radius(small);
|
|
59
|
+
color: fn.use-var(text-color, white);
|
|
60
|
+
font-size: t.use-var('font-size-auxiliary');
|
|
61
|
+
font-weight: 600;
|
|
62
|
+
line-height: 1.4;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@include m.e(file-name) {
|
|
66
|
+
max-width: 100%;
|
|
67
|
+
overflow: hidden;
|
|
68
|
+
text-overflow: ellipsis;
|
|
69
|
+
white-space: nowrap;
|
|
70
|
+
color: fn.use-var(text-color, second);
|
|
71
|
+
font-size: t.use-var('font-size-auxiliary');
|
|
72
|
+
line-height: 1.2;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@include m.is(failed) {
|
|
76
|
+
@include m.bem($root-name, file) {
|
|
77
|
+
border: fn.use-var(border, width) fn.use-var(border, style) fn.use-var(color, danger);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@include m.e(mask) {
|
|
82
|
+
// 上传中遮罩压暗主题无关,直接写 rgba(同 dialog overlay 处理)
|
|
83
|
+
position: absolute;
|
|
84
|
+
inset: 0;
|
|
85
|
+
display: flex;
|
|
86
|
+
align-items: center;
|
|
87
|
+
justify-content: center;
|
|
88
|
+
background-color: rgba(0, 0, 0, 0.45);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@include m.e(spinner) {
|
|
92
|
+
width: calc(#{t.use-var('loading-indicator')} / 2);
|
|
93
|
+
aspect-ratio: 1;
|
|
94
|
+
box-sizing: border-box;
|
|
95
|
+
border: 2px solid rgba(255, 255, 255, 0.35);
|
|
96
|
+
border-top-color: rgba(255, 255, 255, 0.95);
|
|
97
|
+
border-radius: 50%;
|
|
98
|
+
animation: um-uploader-spin 0.8s linear infinite;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
@include m.e(remove) {
|
|
102
|
+
position: absolute;
|
|
103
|
+
top: 0;
|
|
104
|
+
right: 0;
|
|
105
|
+
display: flex;
|
|
106
|
+
align-items: center;
|
|
107
|
+
justify-content: center;
|
|
108
|
+
width: t.use-var('spacing-xl');
|
|
109
|
+
height: t.use-var('spacing-xl');
|
|
110
|
+
padding: 0;
|
|
111
|
+
border: none;
|
|
112
|
+
border-bottom-left-radius: t.control-radius(small);
|
|
113
|
+
background-color: rgba(0, 0, 0, 0.55);
|
|
114
|
+
color: fn.use-var(text-color, white);
|
|
115
|
+
font-size: t.use-var('font-size-auxiliary');
|
|
116
|
+
line-height: 1;
|
|
117
|
+
cursor: pointer;
|
|
118
|
+
|
|
119
|
+
& > svg {
|
|
120
|
+
width: 1em;
|
|
121
|
+
height: 1em;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
@include m.e(trigger) {
|
|
126
|
+
display: flex;
|
|
127
|
+
align-items: center;
|
|
128
|
+
justify-content: center;
|
|
129
|
+
width: 100%;
|
|
130
|
+
height: 100%;
|
|
131
|
+
box-sizing: border-box;
|
|
132
|
+
padding: 0;
|
|
133
|
+
border: fn.use-var(border, width) dashed fn.use-var(border, muted-color);
|
|
134
|
+
border-radius: t.control-radius(default);
|
|
135
|
+
background-color: fn.use-var(color, default, light-9);
|
|
136
|
+
color: fn.use-var(text-color, assist);
|
|
137
|
+
font-size: t.use-var('font-size-title');
|
|
138
|
+
cursor: pointer;
|
|
139
|
+
transition:
|
|
140
|
+
border-color fn.use-var(transition, fast) fn.use-var(transition, ease),
|
|
141
|
+
color fn.use-var(transition, fast) fn.use-var(transition, ease);
|
|
142
|
+
|
|
143
|
+
&:active {
|
|
144
|
+
border-color: fn.use-var(color, primary);
|
|
145
|
+
color: fn.use-var(color, primary);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
& > svg {
|
|
149
|
+
width: 1em;
|
|
150
|
+
height: 1em;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
@include m.is(disabled) {
|
|
155
|
+
@include m.bem($root-name, trigger) {
|
|
156
|
+
border-color: fn.use-var(border, muted-color);
|
|
157
|
+
background-color: fn.use-var(color, disabled);
|
|
158
|
+
color: fn.use-var(text-color, disabled);
|
|
159
|
+
cursor: not-allowed;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
@include m.is(readonly) {
|
|
164
|
+
@include m.bem($root-name, thumb) {
|
|
165
|
+
cursor: default;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
@include m.bem($root-name, file) {
|
|
169
|
+
cursor: default;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
@include m.e(native) {
|
|
174
|
+
display: none;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// 内置图片大图预览:挂 overlay 容器(设备外壳内随壳定位)
|
|
178
|
+
@include m.e(previewer) {
|
|
179
|
+
position: fixed;
|
|
180
|
+
inset: 0;
|
|
181
|
+
display: flex;
|
|
182
|
+
align-items: center;
|
|
183
|
+
justify-content: center;
|
|
184
|
+
background-color: rgba(0, 0, 0, 0.85);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
@include m.e(previewer-image) {
|
|
188
|
+
max-width: 100%;
|
|
189
|
+
max-height: 100%;
|
|
190
|
+
object-fit: contain;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
@include m.e(previewer-close) {
|
|
194
|
+
position: absolute;
|
|
195
|
+
top: 0;
|
|
196
|
+
right: 0;
|
|
197
|
+
display: flex;
|
|
198
|
+
align-items: center;
|
|
199
|
+
justify-content: center;
|
|
200
|
+
width: t.use-var('touch-target');
|
|
201
|
+
height: t.use-var('touch-target');
|
|
202
|
+
padding: 0;
|
|
203
|
+
border: none;
|
|
204
|
+
background: none;
|
|
205
|
+
color: fn.use-var(text-color, white);
|
|
206
|
+
font-size: t.use-var('font-size-title');
|
|
207
|
+
cursor: pointer;
|
|
208
|
+
|
|
209
|
+
& > svg {
|
|
210
|
+
width: 1em;
|
|
211
|
+
height: 1em;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
@keyframes um-uploader-spin {
|
|
217
|
+
to {
|
|
218
|
+
transform: rotate(360deg);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './style.scss'
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div :class="uploaderClass">
|
|
3
|
+
<ul :class="cls.e('list')">
|
|
4
|
+
<li
|
|
5
|
+
v-for="(file, index) in modelValue"
|
|
6
|
+
:key="index"
|
|
7
|
+
:class="[cls.e('item'), bem.is('failed', file.status === 'failed')]"
|
|
8
|
+
@click="handleClick(file, index)"
|
|
9
|
+
>
|
|
10
|
+
<slot name="item" :file="file" :index="index">
|
|
11
|
+
<img
|
|
12
|
+
v-if="isImageFile(file) && file.url"
|
|
13
|
+
:src="file.url"
|
|
14
|
+
:alt="file.name ?? ''"
|
|
15
|
+
:class="cls.e('thumb')"
|
|
16
|
+
/>
|
|
17
|
+
<div v-else :class="cls.e('file')">
|
|
18
|
+
<span :class="cls.e('file-badge')" :style="{ backgroundColor: badgeColor(file) }">
|
|
19
|
+
{{ badgeLabel(file) }}
|
|
20
|
+
</span>
|
|
21
|
+
<span :class="cls.e('file-name')">{{ file.name }}</span>
|
|
22
|
+
</div>
|
|
23
|
+
</slot>
|
|
24
|
+
|
|
25
|
+
<span v-if="file.status === 'uploading'" :class="cls.e('mask')">
|
|
26
|
+
<span :class="cls.e('spinner')"></span>
|
|
27
|
+
</span>
|
|
28
|
+
|
|
29
|
+
<button
|
|
30
|
+
v-if="canRemove(file, index) && !disabled && !readonly"
|
|
31
|
+
type="button"
|
|
32
|
+
aria-label="删除"
|
|
33
|
+
:class="cls.e('remove')"
|
|
34
|
+
@click.stop="handleRemove(index)"
|
|
35
|
+
>
|
|
36
|
+
<Close />
|
|
37
|
+
</button>
|
|
38
|
+
</li>
|
|
39
|
+
|
|
40
|
+
<li v-if="showTrigger" :class="cls.e('item')">
|
|
41
|
+
<button
|
|
42
|
+
type="button"
|
|
43
|
+
aria-label="上传文件"
|
|
44
|
+
:class="cls.e('trigger')"
|
|
45
|
+
:disabled="disabled"
|
|
46
|
+
@click="pick"
|
|
47
|
+
>
|
|
48
|
+
<Plus />
|
|
49
|
+
</button>
|
|
50
|
+
</li>
|
|
51
|
+
</ul>
|
|
52
|
+
|
|
53
|
+
<input
|
|
54
|
+
ref="inputRef"
|
|
55
|
+
type="file"
|
|
56
|
+
:class="cls.e('native')"
|
|
57
|
+
:accept="accept"
|
|
58
|
+
:multiple="multiple"
|
|
59
|
+
@change="handleChange"
|
|
60
|
+
/>
|
|
61
|
+
|
|
62
|
+
<Teleport :to="getOverlayContainer()">
|
|
63
|
+
<div
|
|
64
|
+
v-if="previewUrl"
|
|
65
|
+
:class="cls.e('previewer')"
|
|
66
|
+
:style="{ zIndex: previewZIndex }"
|
|
67
|
+
@click="closePreview"
|
|
68
|
+
>
|
|
69
|
+
<img :src="previewUrl" alt="" :class="cls.e('previewer-image')" />
|
|
70
|
+
<button
|
|
71
|
+
type="button"
|
|
72
|
+
aria-label="关闭"
|
|
73
|
+
:class="cls.e('previewer-close')"
|
|
74
|
+
@click.stop="closePreview"
|
|
75
|
+
>
|
|
76
|
+
<Close />
|
|
77
|
+
</button>
|
|
78
|
+
</div>
|
|
79
|
+
</Teleport>
|
|
80
|
+
</div>
|
|
81
|
+
</template>
|
|
82
|
+
|
|
83
|
+
<script lang="ts" setup>
|
|
84
|
+
import { useFormFallbackProps } from '@veltra/compositions'
|
|
85
|
+
import { Close, Plus } from '@veltra/icons/normal'
|
|
86
|
+
import { injectFormContext, zIndex } from '@veltra/utils'
|
|
87
|
+
import { computed, reactive, ref } from 'vue'
|
|
88
|
+
|
|
89
|
+
import { bem } from '../../shared/bem'
|
|
90
|
+
import type { UploaderEmits, UploaderFileItem, UploaderProps } from '../../types/uploader'
|
|
91
|
+
import { getOverlayContainer } from '../_internal/overlay-container'
|
|
92
|
+
|
|
93
|
+
defineOptions({ name: 'UUploader' })
|
|
94
|
+
|
|
95
|
+
// deletable 的联合类型必须内联在泛型里且函数成员在前:跨包 extends(@veltra/utils)解析链路下,
|
|
96
|
+
// 经类型文件引用或别名引用的联合都会被宏丢失 Function 运行时类型(实测 boolean|fn 与别名均塌缩为 Boolean)
|
|
97
|
+
const props = withDefaults(
|
|
98
|
+
defineProps<
|
|
99
|
+
UploaderProps & { deletable?: ((file: UploaderFileItem, index: number) => boolean) | boolean }
|
|
100
|
+
>(),
|
|
101
|
+
{
|
|
102
|
+
accept: 'image/*,.pdf,.doc,.docx,.xls,.xlsx',
|
|
103
|
+
multiple: false,
|
|
104
|
+
maxCount: Number.POSITIVE_INFINITY,
|
|
105
|
+
deletable: true,
|
|
106
|
+
preview: true,
|
|
107
|
+
disabled: undefined,
|
|
108
|
+
readonly: undefined
|
|
109
|
+
}
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
const emit = defineEmits<UploaderEmits>()
|
|
113
|
+
|
|
114
|
+
defineSlots<{
|
|
115
|
+
/** 自定义文件瓦片内容,作用域参数为 `file` 与 `index`;遮罩与删除按钮始终由组件渲染 */
|
|
116
|
+
item?: (scope: { file: UploaderFileItem; index: number }) => any
|
|
117
|
+
}>()
|
|
118
|
+
|
|
119
|
+
const modelValue = defineModel<UploaderFileItem[]>()
|
|
120
|
+
|
|
121
|
+
const cls = bem('uploader')
|
|
122
|
+
|
|
123
|
+
const { formProps } = injectFormContext()
|
|
124
|
+
|
|
125
|
+
const { size, disabled, readonly } = useFormFallbackProps([formProps ?? {}, props])
|
|
126
|
+
|
|
127
|
+
const uploaderClass = computed(() => {
|
|
128
|
+
return [
|
|
129
|
+
cls.b,
|
|
130
|
+
cls.m(size.value),
|
|
131
|
+
bem.is('disabled', disabled.value),
|
|
132
|
+
bem.is('readonly', readonly.value)
|
|
133
|
+
]
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
const inputRef = ref<HTMLInputElement>()
|
|
137
|
+
|
|
138
|
+
/** 数量未满且可交互时才展示上传入口 */
|
|
139
|
+
const showTrigger = computed(() => {
|
|
140
|
+
if (disabled.value || readonly.value) return false
|
|
141
|
+
return (modelValue.value?.length ?? 0) < props.maxCount
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
// ===== 文件类型识别(图片缩略图,其余走扩展名徽标) =====
|
|
145
|
+
|
|
146
|
+
const IMAGE_EXTS = new Set(['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp', 'heic', 'heif'])
|
|
147
|
+
|
|
148
|
+
function extOf(name?: string): string {
|
|
149
|
+
if (!name) return ''
|
|
150
|
+
const dot = name.lastIndexOf('.')
|
|
151
|
+
return dot === -1 ? '' : name.slice(dot + 1)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function isImageFile(file: UploaderFileItem): boolean {
|
|
155
|
+
const ext = extOf(file.name)
|
|
156
|
+
if (ext) return IMAGE_EXTS.has(ext.toLowerCase())
|
|
157
|
+
// 无文件名的历史数据只能按地址猜测:data:image 与 blob 视为图片
|
|
158
|
+
return /^data:image|^blob:/.test(file.url)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** 扩展名徽标:文案 + 品牌底色(文件格式的行业惯用色,非主题色,不随暗色切换) */
|
|
162
|
+
const BADGES: Record<string, { label: string; color: string }> = {
|
|
163
|
+
pdf: { label: 'PDF', color: '#fa5151' },
|
|
164
|
+
doc: { label: 'DOC', color: '#2b7cd3' },
|
|
165
|
+
docx: { label: 'DOC', color: '#2b7cd3' },
|
|
166
|
+
xls: { label: 'XLS', color: '#217346' },
|
|
167
|
+
xlsx: { label: 'XLS', color: '#217346' }
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const FALLBACK_BADGE = { label: 'FILE', color: '#909399' }
|
|
171
|
+
|
|
172
|
+
function badgeOf(file: UploaderFileItem) {
|
|
173
|
+
return BADGES[extOf(file.name).toLowerCase()] ?? FALLBACK_BADGE
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const badgeLabel = (file: UploaderFileItem) => badgeOf(file).label
|
|
177
|
+
|
|
178
|
+
const badgeColor = (file: UploaderFileItem) => badgeOf(file).color
|
|
179
|
+
|
|
180
|
+
// ===== 选择与读取 =====
|
|
181
|
+
|
|
182
|
+
function pick() {
|
|
183
|
+
if (disabled.value || readonly.value) return
|
|
184
|
+
inputRef.value?.click()
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** accept 匹配:扩展名项(.pdf)按扩展名比对,MIME 项(application/pdf、image/*)按类型精确或通配比对 */
|
|
188
|
+
function matchAccept(file: File): boolean {
|
|
189
|
+
const tokens = props.accept
|
|
190
|
+
.split(',')
|
|
191
|
+
.map((token) => token.trim().toLowerCase())
|
|
192
|
+
.filter(Boolean)
|
|
193
|
+
const mimes = tokens.filter((token) => !token.startsWith('.'))
|
|
194
|
+
if (
|
|
195
|
+
file.type &&
|
|
196
|
+
mimes.some(
|
|
197
|
+
(mime) =>
|
|
198
|
+
mime === file.type || (mime.endsWith('/*') && file.type.startsWith(mime.slice(0, -1)))
|
|
199
|
+
)
|
|
200
|
+
) {
|
|
201
|
+
return true
|
|
202
|
+
}
|
|
203
|
+
const ext = extOf(file.name).toLowerCase()
|
|
204
|
+
return Boolean(ext) && tokens.includes(`.${ext}`)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
async function handleChange(event: Event) {
|
|
208
|
+
const input = event.target as HTMLInputElement
|
|
209
|
+
const picked = Array.from(input.files ?? [])
|
|
210
|
+
input.value = ''
|
|
211
|
+
|
|
212
|
+
if (!picked.length || disabled.value || readonly.value) return
|
|
213
|
+
|
|
214
|
+
const remaining = props.maxCount - (modelValue.value?.length ?? 0)
|
|
215
|
+
if (remaining <= 0) return
|
|
216
|
+
|
|
217
|
+
const oversize: File[] = []
|
|
218
|
+
const candidates: File[] = []
|
|
219
|
+
|
|
220
|
+
for (const file of picked.slice(0, remaining)) {
|
|
221
|
+
if (!matchAccept(file)) continue
|
|
222
|
+
if (props.maxSize && file.size > props.maxSize) {
|
|
223
|
+
oversize.push(file)
|
|
224
|
+
continue
|
|
225
|
+
}
|
|
226
|
+
candidates.push(file)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (oversize.length) emit('oversize', oversize)
|
|
230
|
+
if (!candidates.length) return
|
|
231
|
+
|
|
232
|
+
// beforeRead 并行校验,返回 false 或抛异常的文件剔除
|
|
233
|
+
const checked = await Promise.all(
|
|
234
|
+
candidates.map(async (file) => {
|
|
235
|
+
try {
|
|
236
|
+
return ((await props.beforeRead?.(file)) ?? true) && file
|
|
237
|
+
} catch {
|
|
238
|
+
return false
|
|
239
|
+
}
|
|
240
|
+
})
|
|
241
|
+
)
|
|
242
|
+
const accepted = checked.filter((file): file is File => Boolean(file))
|
|
243
|
+
if (!accepted.length) return
|
|
244
|
+
|
|
245
|
+
const items = await Promise.all(accepted.map((file) => toItem(file)))
|
|
246
|
+
const next = [...(modelValue.value ?? []), ...items]
|
|
247
|
+
modelValue.value = next
|
|
248
|
+
emit('change', next)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** File → 列表项:无 upload 时本地 blob 直显;有 upload 先占位再回填地址(reactive 包装保证异步回填触发视图更新) */
|
|
252
|
+
async function toItem(file: File): Promise<UploaderFileItem> {
|
|
253
|
+
const base: UploaderFileItem = { name: file.name, size: file.size }
|
|
254
|
+
|
|
255
|
+
if (!props.upload) return { ...base, url: URL.createObjectURL(file), status: 'done' }
|
|
256
|
+
|
|
257
|
+
const item = reactive<UploaderFileItem>({ ...base, url: '', status: 'uploading' })
|
|
258
|
+
props
|
|
259
|
+
.upload(file)
|
|
260
|
+
.then((url) => {
|
|
261
|
+
item.url = url
|
|
262
|
+
item.status = 'done'
|
|
263
|
+
})
|
|
264
|
+
.catch(() => {
|
|
265
|
+
item.status = 'failed'
|
|
266
|
+
})
|
|
267
|
+
return item
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// ===== 操作(deletable 支持按文件控制删除按钮显隐)=====
|
|
271
|
+
|
|
272
|
+
function canRemove(file: UploaderFileItem, index: number): boolean {
|
|
273
|
+
return typeof props.deletable === 'function'
|
|
274
|
+
? props.deletable(file, index)
|
|
275
|
+
: props.deletable !== false
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function handleRemove(index: number) {
|
|
279
|
+
if (disabled.value || readonly.value) return
|
|
280
|
+
const files = [...(modelValue.value ?? [])]
|
|
281
|
+
const [file] = files.splice(index, 1)
|
|
282
|
+
if (!file) return
|
|
283
|
+
modelValue.value = files
|
|
284
|
+
// 仅回收组件自身创建的本地预览地址
|
|
285
|
+
if (file.url.startsWith('blob:')) URL.revokeObjectURL(file.url)
|
|
286
|
+
emit('delete', file, index)
|
|
287
|
+
emit('change', files)
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const previewUrl = ref('')
|
|
291
|
+
const previewZIndex = ref(0)
|
|
292
|
+
|
|
293
|
+
function handleClick(file: UploaderFileItem, index: number) {
|
|
294
|
+
// 只读态保留预览能力(查看场景);禁用态完全不可交互
|
|
295
|
+
if (disabled.value) return
|
|
296
|
+
emit('click-file', file, index)
|
|
297
|
+
if (props.preview && file.status !== 'uploading' && isImageFile(file)) {
|
|
298
|
+
previewUrl.value = file.url
|
|
299
|
+
previewZIndex.value = zIndex()
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function closePreview() {
|
|
304
|
+
previewUrl.value = ''
|
|
305
|
+
}
|
|
306
|
+
</script>
|
package/src/env.d.ts
ADDED
package/src/index.ts
CHANGED
|
@@ -1 +1,99 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { UAvatar } from './components/avatar'
|
|
2
|
+
export { UBadge } from './components/badge'
|
|
3
|
+
export { UButton } from './components/button'
|
|
4
|
+
export { UCard } from './components/card'
|
|
5
|
+
export { UCascade } from './components/cascade'
|
|
6
|
+
export { UCheckTag } from './components/check-tag'
|
|
7
|
+
export { UCheckbox } from './components/checkbox'
|
|
8
|
+
export { UCheckboxGroup } from './components/checkbox-group'
|
|
9
|
+
export { UCollapse, UCollapseItem } from './components/collapse'
|
|
10
|
+
export { UDatePicker } from './components/date-picker'
|
|
11
|
+
export { UDescriptions, UDescriptionsItem } from './components/descriptions'
|
|
12
|
+
export { UDialog } from './components/dialog'
|
|
13
|
+
export { UDivider } from './components/divider'
|
|
14
|
+
export { UDrawer } from './components/drawer'
|
|
15
|
+
export { UEmpty } from './components/empty'
|
|
16
|
+
export { UForm } from './components/form'
|
|
17
|
+
export { UFormItem } from './components/form-item'
|
|
18
|
+
export { UIcon } from './components/icon'
|
|
19
|
+
export { UInput } from './components/input'
|
|
20
|
+
export { UList, UListItem } from './components/list'
|
|
21
|
+
export { ULoading, vLoading } from './components/loading'
|
|
22
|
+
export { UMessage, message } from './components/message'
|
|
23
|
+
export { UMessageConfirm, messageConfirm } from './components/message-confirm'
|
|
24
|
+
export { UMultiSelect } from './components/multi-select'
|
|
25
|
+
export { UNumberInput } from './components/number-input'
|
|
26
|
+
export { URadio } from './components/radio'
|
|
27
|
+
export { URadioGroup } from './components/radio-group'
|
|
28
|
+
export { UPasswordInput } from './components/password-input'
|
|
29
|
+
export { UProgress } from './components/progress'
|
|
30
|
+
export { USegment } from './components/segment'
|
|
31
|
+
export { USkeleton } from './components/skeleton'
|
|
32
|
+
export { USelect } from './components/select'
|
|
33
|
+
export { USwitch } from './components/switch'
|
|
34
|
+
export { USpace } from './components/space'
|
|
35
|
+
export { USteps } from './components/steps'
|
|
36
|
+
export { UTabs } from './components/tabs'
|
|
37
|
+
export { UTag } from './components/tag'
|
|
38
|
+
export { UText } from './components/text'
|
|
39
|
+
export { UTextarea } from './components/textarea'
|
|
40
|
+
export { UTimePicker } from './components/time-picker'
|
|
41
|
+
export { UUploader } from './components/uploader'
|
|
42
|
+
export { UTimeline, UTimelineItem } from './components/timeline'
|
|
43
|
+
|
|
44
|
+
export { useScrollLock } from './shared/use-scroll-lock'
|
|
45
|
+
export type { ScrollLock } from './shared/use-scroll-lock'
|
|
46
|
+
export {
|
|
47
|
+
horizontalSwipeDirection,
|
|
48
|
+
shouldCloseByDrag,
|
|
49
|
+
useTouchGesture
|
|
50
|
+
} from './shared/use-touch-gesture'
|
|
51
|
+
export type {
|
|
52
|
+
DragDismissOptions,
|
|
53
|
+
TouchGestureHandlers,
|
|
54
|
+
TouchGestureState,
|
|
55
|
+
UseTouchGestureOptions
|
|
56
|
+
} from './shared/use-touch-gesture'
|
|
57
|
+
|
|
58
|
+
export type * from './types/avatar'
|
|
59
|
+
export type * from './types/badge'
|
|
60
|
+
export type * from './types/button'
|
|
61
|
+
export type * from './types/card'
|
|
62
|
+
export type * from './types/cascade'
|
|
63
|
+
export type * from './types/check-tag'
|
|
64
|
+
export type * from './types/checkbox'
|
|
65
|
+
export type * from './types/checkbox-group'
|
|
66
|
+
export type * from './types/date-picker'
|
|
67
|
+
export type * from './types/collapse'
|
|
68
|
+
export type * from './types/icon'
|
|
69
|
+
export type * from './types/input'
|
|
70
|
+
export type * from './types/list'
|
|
71
|
+
export type * from './types/loading'
|
|
72
|
+
export type * from './types/message'
|
|
73
|
+
export type * from './types/message-confirm'
|
|
74
|
+
export type * from './types/multi-select'
|
|
75
|
+
export type * from './types/number-input'
|
|
76
|
+
export type * from './types/password-input'
|
|
77
|
+
export type * from './types/radio'
|
|
78
|
+
export type * from './types/radio-group'
|
|
79
|
+
export type * from './types/descriptions'
|
|
80
|
+
export type * from './types/dialog'
|
|
81
|
+
export type * from './types/divider'
|
|
82
|
+
export type * from './types/drawer'
|
|
83
|
+
export type * from './types/empty'
|
|
84
|
+
export type * from './types/form'
|
|
85
|
+
export type * from './types/form-item'
|
|
86
|
+
export type * from './types/progress'
|
|
87
|
+
export type * from './types/skeleton'
|
|
88
|
+
export type * from './types/select'
|
|
89
|
+
export type * from './types/switch'
|
|
90
|
+
export type * from './types/segment'
|
|
91
|
+
export type * from './types/space'
|
|
92
|
+
export type * from './types/steps'
|
|
93
|
+
export type * from './types/tabs'
|
|
94
|
+
export type * from './types/tag'
|
|
95
|
+
export type * from './types/text'
|
|
96
|
+
export type * from './types/textarea'
|
|
97
|
+
export type * from './types/time-picker'
|
|
98
|
+
export type * from './types/timeline'
|
|
99
|
+
export type * from './types/uploader'
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { makeBEM, type BEM } from '@veltra/utils'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 移动端类名前缀 `um-`(桌面端为 `u-`)
|
|
5
|
+
*
|
|
6
|
+
* 双端组件名刻意对齐,类名前缀必须分离:同一应用同时引入
|
|
7
|
+
* `@veltra/desktop` 与 `@veltra/mobile` 时,同名组件的样式互不覆盖。
|
|
8
|
+
* 对应 SCSS 侧 `@use ... with ($namespace: um)`。
|
|
9
|
+
*/
|
|
10
|
+
export const bem = makeBEM('um-')
|
|
11
|
+
|
|
12
|
+
export type MobileBEM<N extends string> = BEM<N, 'um-'>
|