kui-vue 3.2.4 → 3.2.5
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/components/_tool/utils.js +2 -2
- package/components/alert/styles/index.less +19 -19
- package/components/avatar/styles/index.less +3 -3
- package/components/backtop/styles/index.less +2 -2
- package/components/badge/demo/dot.md +1 -1
- package/components/badge/demo/dynamic.md +1 -1
- package/components/badge/demo/max.md +1 -1
- package/components/badge/styles/index.less +21 -21
- package/components/base/input.jsx +16 -10
- package/components/breadcrumb/styles/index.less +4 -4
- package/components/button/button.jsx +14 -8
- package/components/button/buttonGroup.jsx +6 -6
- package/components/button/demo/base.md +2 -1
- package/components/button/demo/disabled.md +14 -16
- package/components/button/demo/group.md +2 -2
- package/components/button/demo/index.vue +6 -2
- package/components/button/demo/light.md +26 -0
- package/components/button/demo/loading.md +1 -1
- package/components/button/demo/normal.md +25 -0
- package/components/button/demo/size.md +2 -2
- package/components/button/demo/solid.md +16 -0
- package/components/button/demo/with-icon.md +4 -3
- package/components/button/index.md +3 -3
- package/components/button/styles/index.less +106 -45
- package/components/card/demo/base.md +1 -1
- package/components/card/demo/border.md +2 -2
- package/components/card/styles/index.less +6 -6
- package/components/carousel/styles/index.less +1 -1
- package/components/checkbox/demo/group-vertical.md +47 -0
- package/components/checkbox/demo/index.vue +4 -0
- package/components/checkbox/demo/options.md +46 -0
- package/components/checkbox/group.jsx +9 -3
- package/components/checkbox/index.md +8 -7
- package/components/checkbox/styles/index.less +30 -20
- package/components/collapse/styles/index.less +10 -10
- package/components/colorPicker/styles/index.less +14 -14
- package/components/datePicker/datepicker.jsx +11 -3
- package/components/datePicker/demo/index.vue +2 -0
- package/components/datePicker/demo/theme.md +34 -0
- package/components/datePicker/index.md +4 -1
- package/components/datePicker/styles/calendar.less +39 -38
- package/components/datePicker/styles/datepicker.less +37 -20
- package/components/divider/styles/index.less +6 -6
- package/components/drawer/styles/index.less +12 -10
- package/components/dropdown/demo/base.md +4 -4
- package/components/dropdown/demo/cascading.md +3 -3
- package/components/dropdown/demo/divider.md +3 -3
- package/components/dropdown/styles/index.less +4 -4
- package/components/empty/styles/index.less +2 -2
- package/components/form/demo/base.md +25 -2
- package/components/form/demo/index.vue +1 -1
- package/components/form/demo/valid.md +9 -0
- package/components/form/form.jsx +2 -0
- package/components/form/formitem.jsx +18 -10
- package/components/form/styles/index.less +17 -13
- package/components/grid/styles/index.less +1 -1
- package/components/icon/demo/base.md +4 -4
- package/components/icon/demo/search.vue +6 -9
- package/components/image/styles/index.less +18 -18
- package/components/index.js +3 -1
- package/components/input/demo/index.vue +3 -1
- package/components/input/demo/theme.md +39 -0
- package/components/input/index.md +9 -6
- package/components/input/input.jsx +10 -3
- package/components/input/styles/index.less +120 -78
- package/components/input/textarea.jsx +1 -0
- package/components/layout/demo/base.md +5 -3
- package/components/layout/demo/index.vue +0 -2
- package/components/layout/demo/info.md +0 -2
- package/components/layout/demo/layout1.md +40 -47
- package/components/layout/demo/layout2.md +42 -49
- package/components/layout/demo/layout3.md +44 -22
- package/components/layout/demo/layout4.md +19 -18
- package/components/layout/demo/layout5.md +47 -44
- package/components/layout/styles/index.less +1 -6
- package/components/loading/styles/index.less +4 -4
- package/components/menu/demo/accrodion.md +2 -2
- package/components/menu/demo/base.md +5 -13
- package/components/menu/demo/collapsed.md +2 -2
- package/components/menu/demo/index.vue +0 -2
- package/components/menu/demo/inline.md +6 -10
- package/components/menu/demo/mode.md +2 -2
- package/components/menu/demo/theme.md +2 -2
- package/components/menu/demo/vertical.md +2 -2
- package/components/menu/index.md +0 -3
- package/components/menu/menu.jsx +4 -4
- package/components/menu/menuitem.jsx +1 -13
- package/components/menu/styles/dropmenu.less +28 -20
- package/components/menu/styles/index.less +148 -251
- package/components/menu/submenu.jsx +4 -64
- package/components/message/group.jsx +1 -1
- package/components/message/styles/index.less +13 -8
- package/components/modal/demo/base.md +15 -2
- package/components/modal/demo/custom.md +2 -2
- package/components/modal/demo/more.md +6 -6
- package/components/modal/modal.jsx +11 -5
- package/components/modal/styles/index.less +24 -17
- package/components/notice/styles/index.less +14 -13
- package/components/page/styles/index.less +16 -16
- package/components/popconfirm/styles/index.less +6 -6
- package/components/poptip/styles/index.less +10 -9
- package/components/progress/styles/index.less +13 -13
- package/components/radio/button.jsx +2 -2
- package/components/radio/demo/button.md +3 -3
- package/components/radio/demo/group-vertical.md +46 -0
- package/components/radio/demo/index.vue +4 -0
- package/components/radio/demo/options.md +43 -0
- package/components/radio/group.jsx +14 -8
- package/components/radio/index.md +11 -9
- package/components/radio/styles/index.less +33 -22
- package/components/rate/styles/index.less +2 -2
- package/components/select/demo/icon.md +40 -0
- package/components/select/demo/index.vue +4 -0
- package/components/select/demo/size.md +5 -5
- package/components/select/demo/theme.md +46 -0
- package/components/select/index.md +5 -2
- package/components/select/select.jsx +20 -13
- package/components/select/styles/index.less +113 -49
- package/components/slider/slider.jsx +9 -4
- package/components/slider/styles/index.less +7 -7
- package/components/space/demo/align.md +1 -1
- package/components/spin/styles/index.less +7 -11
- package/components/steps/styles/index.less +11 -11
- package/components/styles/color.less +158 -0
- package/components/styles/index.less +3 -1
- package/components/styles/sys.less +34 -0
- package/components/styles/var.less +150 -0
- package/components/switch/styles/index.less +11 -11
- package/components/table/styles/index.less +29 -32
- package/components/tabs/styles/index.less +20 -19
- package/components/tag/styles/index.less +45 -45
- package/components/timeline/styles/index.less +5 -5
- package/components/tooltip/styles/index.less +19 -18
- package/components/tree/styles/index.less +15 -15
- package/components/treeselect/styles/index.less +5 -5
- package/components/upload/demo/accept.md +68 -0
- package/components/upload/demo/avatar.md +40 -0
- package/components/upload/demo/base.md +40 -0
- package/components/upload/demo/custom.md +47 -0
- package/components/upload/demo/directory.md +36 -0
- package/components/upload/demo/drag.md +0 -0
- package/components/upload/demo/draggable.md +45 -0
- package/components/upload/demo/exceed.md +42 -0
- package/components/upload/demo/file-list.md +42 -0
- package/components/upload/demo/form.md +120 -0
- package/components/upload/demo/index.vue +37 -0
- package/components/upload/demo/info.md +10 -0
- package/components/upload/demo/picture.md +54 -0
- package/components/upload/index.md +26 -0
- package/components/upload/styles/index.less +258 -0
- package/components/upload/upload.jsx +336 -0
- package/dist/k-ui.css +1 -1
- package/dist/k-ui.js +2 -2
- package/package.json +9 -4
- package/components/button/demo/hollow.md +0 -15
- package/components/layout/demo/layout6.md +0 -142
- package/components/menu/demo/vertical-affix.md +0 -69
- package/components/styles/dark.less +0 -70
- package/components/styles/global-dark.less +0 -36
- package/components/styles/global.less +0 -44
- package/components/upload/upload.vue +0 -137
- package/dist/k-ui-dark.css +0 -1
|
@@ -1,5 +1,263 @@
|
|
|
1
|
+
@import '../../styles/var.less';
|
|
1
2
|
.k-upload {
|
|
2
3
|
display: inline-block;
|
|
4
|
+
.k-upload-file {
|
|
5
|
+
display: none;
|
|
6
|
+
}
|
|
7
|
+
.k-upload-file-list {
|
|
8
|
+
margin-top: 8px;
|
|
9
|
+
display: flex;
|
|
10
|
+
flex-wrap: wrap;
|
|
11
|
+
}
|
|
12
|
+
.k-upload-file-list-item {
|
|
13
|
+
display: flex;
|
|
14
|
+
align-items: center;
|
|
15
|
+
justify-content: space-between;
|
|
16
|
+
height: 52px;
|
|
17
|
+
width: 256px;
|
|
18
|
+
cursor: pointer;
|
|
19
|
+
background-color: var(--kui-color-hover);
|
|
20
|
+
border-radius: var(--kui-border-radius);
|
|
21
|
+
font-size: 12px;
|
|
22
|
+
margin-bottom: 8px;
|
|
23
|
+
margin-right: 8px;
|
|
24
|
+
}
|
|
25
|
+
.k-upload-file-item-remove {
|
|
26
|
+
padding: 5px;
|
|
27
|
+
margin: 0 8px;
|
|
28
|
+
border-radius: var(--kui-border-radius);
|
|
29
|
+
color: var(--kui-color-font);
|
|
30
|
+
font-size: 18px;
|
|
31
|
+
&:hover {
|
|
32
|
+
background-color: var(--kui-color-border);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
.k-upload-file-preview {
|
|
36
|
+
width: 36px;
|
|
37
|
+
height: 36px;
|
|
38
|
+
padding: 8px;
|
|
39
|
+
box-sizing: content-box;
|
|
40
|
+
flex-shrink: 0;
|
|
41
|
+
display: flex;
|
|
42
|
+
align-items: center;
|
|
43
|
+
justify-content: center;
|
|
44
|
+
.k-icon {
|
|
45
|
+
font-size: 20px;
|
|
46
|
+
background-color: var(--kui-color-border);
|
|
47
|
+
padding: 8px;
|
|
48
|
+
border-radius: var(--kui-border-radius);
|
|
49
|
+
}
|
|
50
|
+
img {
|
|
51
|
+
width: 36px;
|
|
52
|
+
height: 36px;
|
|
53
|
+
object-fit: cover;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
.k-upload-file-item-remove {
|
|
57
|
+
flex-shrink: 0;
|
|
58
|
+
}
|
|
59
|
+
.k-upload-file-item-info {
|
|
60
|
+
display: flex;
|
|
61
|
+
flex-direction: column;
|
|
62
|
+
flex: 1;
|
|
63
|
+
overflow: hidden;
|
|
64
|
+
}
|
|
65
|
+
.k-upload-file-main {
|
|
66
|
+
display: flex;
|
|
67
|
+
flex: 1;
|
|
68
|
+
flex-basis: 100%;
|
|
69
|
+
align-items: center;
|
|
70
|
+
}
|
|
71
|
+
.k-upload-file-status {
|
|
72
|
+
flex: 1;
|
|
73
|
+
.k-icon {
|
|
74
|
+
margin-right: 3px;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
.k-upload-file-name {
|
|
78
|
+
font-size: 14px;
|
|
79
|
+
white-space: nowrap;
|
|
80
|
+
overflow: hidden;
|
|
81
|
+
text-overflow: ellipsis;
|
|
82
|
+
display: block;
|
|
83
|
+
display: inline-block;
|
|
84
|
+
font-weight: 600;
|
|
85
|
+
}
|
|
86
|
+
.k-upload-file-size {
|
|
87
|
+
color: #999;
|
|
88
|
+
margin-left: 8px;
|
|
89
|
+
}
|
|
90
|
+
.k-upload-file-status-success .k-upload-file-status-text {
|
|
91
|
+
color: var(--kui-color-success);
|
|
92
|
+
display: flex;
|
|
93
|
+
align-items: center;
|
|
94
|
+
.k-icon {
|
|
95
|
+
font-size: 14px;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
.k-upload-file-status-error .k-upload-file-status-text {
|
|
99
|
+
display: flex;
|
|
100
|
+
align-items: center;
|
|
101
|
+
color: var(--kui-color-danger);
|
|
102
|
+
.k-icon {
|
|
103
|
+
font-size: 14px;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
//picture
|
|
107
|
+
.k-upload-file-picture-item {}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.k-upload-picture {
|
|
111
|
+
display: flex;
|
|
112
|
+
flex-wrap: wrap;
|
|
113
|
+
.k-upload-text {
|
|
114
|
+
font-size: 14px;
|
|
115
|
+
color: var(--kui-color-gray-30);
|
|
116
|
+
margin-top: 8px;
|
|
117
|
+
white-space: nowrap;
|
|
118
|
+
overflow: hidden;
|
|
119
|
+
text-overflow: ellipsis;
|
|
120
|
+
padding: 0 8px;
|
|
121
|
+
width: 100%;
|
|
122
|
+
box-sizing: border-box;
|
|
123
|
+
text-align: center;
|
|
124
|
+
}
|
|
125
|
+
.k-upload-picture-list {
|
|
126
|
+
display: inline-flex;
|
|
127
|
+
margin-top: 0;
|
|
128
|
+
}
|
|
129
|
+
.k-upload-select {
|
|
130
|
+
width: 96px;
|
|
131
|
+
height: 96px;
|
|
132
|
+
border-radius: var(--kui-border-radius);
|
|
133
|
+
border: 1px dashed var(--kui-color-border);
|
|
134
|
+
background-color: var(--kui-color-gray-90);
|
|
135
|
+
display: inline-block;
|
|
136
|
+
cursor: pointer;
|
|
137
|
+
.k-upload-add {
|
|
138
|
+
display: flex;
|
|
139
|
+
flex-direction: column;
|
|
140
|
+
align-items: center;
|
|
141
|
+
justify-content: center;
|
|
142
|
+
width: 100%;
|
|
143
|
+
height: 100%;
|
|
144
|
+
overflow: hidden;
|
|
145
|
+
}
|
|
146
|
+
&:hover {
|
|
147
|
+
border-color: var(--kui-color-main);
|
|
148
|
+
}
|
|
149
|
+
.k-icon {
|
|
150
|
+
font-size: 30px;
|
|
151
|
+
color: #999;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
.k-upload-file-picture-item {
|
|
155
|
+
width: 96px;
|
|
156
|
+
height: 95px;
|
|
157
|
+
border-radius: var(--kui-border-radius);
|
|
158
|
+
border: 1px solid var(--kui-color-border);
|
|
159
|
+
margin-bottom: 8px;
|
|
160
|
+
margin-right: 8px;
|
|
161
|
+
position: relative;
|
|
162
|
+
overflow: hidden;
|
|
163
|
+
&:hover {
|
|
164
|
+
.k-upload-file-picture-remove {
|
|
165
|
+
display: block;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
.k-upload-picture-preview {
|
|
170
|
+
width: 100%;
|
|
171
|
+
height: 100%;
|
|
172
|
+
padding: 0px;
|
|
173
|
+
overflow: hidden;
|
|
174
|
+
img {
|
|
175
|
+
width: 100%;
|
|
176
|
+
height: 100%;
|
|
177
|
+
object-fit: cover;
|
|
178
|
+
border: none;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
.k-upload-file-picture-remove {
|
|
182
|
+
display: none;
|
|
183
|
+
position: absolute;
|
|
184
|
+
background-color: var(--kui-color-mask);
|
|
185
|
+
border-radius: 50%;
|
|
186
|
+
color: #fff;
|
|
187
|
+
padding: 2px;
|
|
188
|
+
cursor: pointer;
|
|
189
|
+
font-size: 12px;
|
|
190
|
+
top: 8px;
|
|
191
|
+
right: 8px;
|
|
192
|
+
z-index: 1;
|
|
193
|
+
}
|
|
194
|
+
.k-upload-file-status-uploading {
|
|
195
|
+
.k-upload-file-item-info {
|
|
196
|
+
position: absolute;
|
|
197
|
+
width: 100%;
|
|
198
|
+
height: 100%;
|
|
199
|
+
bottom: 0;
|
|
200
|
+
pointer-events: none;
|
|
201
|
+
left: 0;
|
|
202
|
+
z-index: 1;
|
|
203
|
+
}
|
|
204
|
+
.k-upload-file-status {
|
|
205
|
+
width: 100%;
|
|
206
|
+
height: 100%;
|
|
207
|
+
display: flex;
|
|
208
|
+
align-items: center;
|
|
209
|
+
justify-content: center;
|
|
210
|
+
background: var(--kui-color-mask);
|
|
211
|
+
.k-progress {
|
|
212
|
+
width: 30%;
|
|
213
|
+
height: 30%;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
.k-upload-file-status-error {
|
|
218
|
+
.k-upload-file-item-info {
|
|
219
|
+
position: absolute;
|
|
220
|
+
left: 10px;
|
|
221
|
+
bottom: 10px;
|
|
222
|
+
color: var(--kui-color-danger);
|
|
223
|
+
.k-icon {
|
|
224
|
+
font-size: 20px;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
border-color: var(--kui-color-danger);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
.k-upload-drag {
|
|
232
|
+
width: 100%;
|
|
233
|
+
.k-upload-add {
|
|
234
|
+
border-radius: var(--kui-border-radius);
|
|
235
|
+
border: 1px dashed var(--kui-color-border);
|
|
236
|
+
display: flex;
|
|
237
|
+
flex-direction: column;
|
|
238
|
+
align-items: center;
|
|
239
|
+
justify-content: center;
|
|
240
|
+
background: var(--kui-color-gray-90);
|
|
241
|
+
padding: 16px 0;
|
|
242
|
+
cursor: pointer;
|
|
243
|
+
&:hover {
|
|
244
|
+
border-color: var(--kui-color-main);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
.k-upload-add .k-icon {
|
|
248
|
+
font-size: 30px;
|
|
249
|
+
color: var(--kui-color-main);
|
|
250
|
+
margin-bottom: 10px;
|
|
251
|
+
}
|
|
252
|
+
.k-upload-text {
|
|
253
|
+
color: var(--kui-color-gray-30);
|
|
254
|
+
font-size: 14px;
|
|
255
|
+
}
|
|
256
|
+
.k-upload-sub-text {
|
|
257
|
+
color: var(--kui-color-gray-30);
|
|
258
|
+
font-size: 12px;
|
|
259
|
+
margin-top: 4px;
|
|
260
|
+
}
|
|
3
261
|
}
|
|
4
262
|
|
|
5
263
|
.k-upload-disabled {
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import Icon from '../icon'
|
|
2
|
+
import Progress from '../progress'
|
|
3
|
+
import Tooltip from '../tooltip'
|
|
4
|
+
let count = 0
|
|
5
|
+
const timestamp = Date.now()
|
|
6
|
+
function getUuid() {
|
|
7
|
+
return `k-upload-${timestamp}-${count++}`
|
|
8
|
+
}
|
|
9
|
+
export default {
|
|
10
|
+
name: "Upload",
|
|
11
|
+
props: {
|
|
12
|
+
method: { type: String, default: "post" },
|
|
13
|
+
name: { type: String, default: 'file' }, //提交的 name值
|
|
14
|
+
action: { type: String, required: true },
|
|
15
|
+
type: { type: String, default: "list", validator: (val) => ['list', 'picture'].indexOf(val) >= 0 },
|
|
16
|
+
data: { type: Object, default: () => { } },
|
|
17
|
+
disabled: Boolean,
|
|
18
|
+
directory: Boolean,
|
|
19
|
+
multiple: Boolean,
|
|
20
|
+
accept: String,
|
|
21
|
+
headers: Object,
|
|
22
|
+
showUploadList: { type: Boolean, default: true },
|
|
23
|
+
transformFile: Function,
|
|
24
|
+
fileList: Array,
|
|
25
|
+
autoTrigger: { type: Boolean, default: true },
|
|
26
|
+
limit: Number,
|
|
27
|
+
minSize: Number,
|
|
28
|
+
maxSize: Number,
|
|
29
|
+
uploadText: String,
|
|
30
|
+
uploadSubText: String,
|
|
31
|
+
uploadIcon: { type: String, default: 'add' },
|
|
32
|
+
draggable: Boolean,
|
|
33
|
+
},
|
|
34
|
+
watch: {
|
|
35
|
+
fileList(v) {
|
|
36
|
+
this.defaultFileList = v || []
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
data() {
|
|
40
|
+
return {
|
|
41
|
+
defaultFileList: this.fileList || [],
|
|
42
|
+
count: 0,
|
|
43
|
+
uploadTemp: {},
|
|
44
|
+
dragOver: false
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
mounted() {
|
|
48
|
+
if (this.draggable) {
|
|
49
|
+
window.addEventListener("dragover", function (e) {
|
|
50
|
+
e = e || event;
|
|
51
|
+
e.preventDefault();
|
|
52
|
+
}, false);
|
|
53
|
+
window.addEventListener("drop", function (e) {
|
|
54
|
+
e = e || event;
|
|
55
|
+
e.preventDefault();
|
|
56
|
+
}, false);
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
methods: {
|
|
60
|
+
formatFileSize(fileSize) {
|
|
61
|
+
if (fileSize < 1024) {
|
|
62
|
+
return fileSize + 'B';
|
|
63
|
+
} else if (fileSize < (1024 * 1024)) {
|
|
64
|
+
var temp = fileSize / 1024;
|
|
65
|
+
temp = temp.toFixed(2);
|
|
66
|
+
return temp + 'KB';
|
|
67
|
+
} else if (fileSize < (1024 * 1024 * 1024)) {
|
|
68
|
+
var temp = fileSize / (1024 * 1024);
|
|
69
|
+
temp = temp.toFixed(2);
|
|
70
|
+
return temp + 'MB';
|
|
71
|
+
} else {
|
|
72
|
+
var temp = fileSize / (1024 * 1024 * 1024);
|
|
73
|
+
temp = temp.toFixed(2);
|
|
74
|
+
return temp + 'GB';
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
triggerSelect(e) {
|
|
78
|
+
e.cancelBubble = true;
|
|
79
|
+
if (this.disabled) return false;
|
|
80
|
+
|
|
81
|
+
this.$refs["k-upload-file"].click();
|
|
82
|
+
return false;
|
|
83
|
+
},
|
|
84
|
+
remove(i) {
|
|
85
|
+
if (this.disabled) return false;
|
|
86
|
+
let item = this.defaultFileList[i]
|
|
87
|
+
this.defaultFileList.splice(i, 1)
|
|
88
|
+
|
|
89
|
+
delete this.uploadTemp[item.uid]
|
|
90
|
+
item.xhr && item.xhr.abort()
|
|
91
|
+
this.$emit('remove', {
|
|
92
|
+
file: item,
|
|
93
|
+
fileList: this.defaultFileList
|
|
94
|
+
})
|
|
95
|
+
},
|
|
96
|
+
upload() {
|
|
97
|
+
if (!this.autoTrigger && !this.disabled) {
|
|
98
|
+
let files = this.uploadTemp
|
|
99
|
+
for (let k in files) {
|
|
100
|
+
let item = this.defaultFileList.filter(x => x.uid == k)[0]
|
|
101
|
+
item && this.uploadFile(item, files[k])
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
selectFiles(e) {
|
|
106
|
+
let { limit, minSize, maxSize, autoTrigger } = this
|
|
107
|
+
let files = e.dataTransfer ? e.dataTransfer.files : e.target.files
|
|
108
|
+
for (let i = 0; i < files.length; i++) {
|
|
109
|
+
|
|
110
|
+
let { size, type } = files[i]
|
|
111
|
+
if (files[i].name == '.DS_Store') {
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
let item = {
|
|
115
|
+
uid: getUuid(),
|
|
116
|
+
filename: files[i].name, size: this.formatFileSize(size),
|
|
117
|
+
status: 'wait', percent: 0, preview: false
|
|
118
|
+
}
|
|
119
|
+
this.uploadTemp[item.uid] = files[i]
|
|
120
|
+
|
|
121
|
+
if (limit && i > limit - 1) {
|
|
122
|
+
this.$emit('exceed')
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if ((type || '').indexOf('image') >= 0) {
|
|
126
|
+
item.preview = window.URL.createObjectURL(files[i])
|
|
127
|
+
}
|
|
128
|
+
let error = false
|
|
129
|
+
if ((minSize !== undefined && minSize >= 0 && size / 1024 < minSize) ||
|
|
130
|
+
(maxSize !== undefined && maxSize >= 0 && size / 1024 > maxSize)
|
|
131
|
+
) {
|
|
132
|
+
error = true
|
|
133
|
+
item.errorText = '文件尺寸不合法'
|
|
134
|
+
item.status = 'error'
|
|
135
|
+
}
|
|
136
|
+
// if (multiple) {
|
|
137
|
+
this.defaultFileList.push(item)
|
|
138
|
+
|
|
139
|
+
this.$emit('before-upload', {
|
|
140
|
+
file: item,
|
|
141
|
+
fileList: this.defaultFileList,
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
if (error) {
|
|
145
|
+
this.$emit('change', {
|
|
146
|
+
file: item,
|
|
147
|
+
fileList: this.defaultFileList,
|
|
148
|
+
})
|
|
149
|
+
this.$emit('size-error', {
|
|
150
|
+
file: item,
|
|
151
|
+
fileList: this.defaultFileList,
|
|
152
|
+
})
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
// } else {
|
|
156
|
+
// this.defaultFileList = [item]
|
|
157
|
+
// }
|
|
158
|
+
if (autoTrigger) {
|
|
159
|
+
this.uploadFile(item, files[i])
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
e.target.value = ''
|
|
163
|
+
},
|
|
164
|
+
uploadFile(item, file) {
|
|
165
|
+
let { action, name, headers, data } = this
|
|
166
|
+
|
|
167
|
+
var formdata = new FormData();
|
|
168
|
+
formdata.append(name, file);
|
|
169
|
+
if (data) {
|
|
170
|
+
for (let k in data) {
|
|
171
|
+
formdata.append(k, data[k]);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
//创建xhr,使用ajax进行文件上传
|
|
175
|
+
var xhr = new XMLHttpRequest();
|
|
176
|
+
item.xhr = xhr
|
|
177
|
+
|
|
178
|
+
xhr.open("post", action);
|
|
179
|
+
if (headers) {
|
|
180
|
+
for (let k in headers) {
|
|
181
|
+
xhr.setRequestHeader(k, headers[k])
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
//回调
|
|
185
|
+
xhr.onreadystatechange = event => {
|
|
186
|
+
if (xhr.readyState == 4 && xhr.status == 200) {
|
|
187
|
+
item.status = 'success'
|
|
188
|
+
delete this.uploadTemp[item.uid]
|
|
189
|
+
this.$emit('change', {
|
|
190
|
+
file: Object.assign(item, { response: JSON.parse(xhr.responseText) }),
|
|
191
|
+
fileList: this.defaultFileList,
|
|
192
|
+
event
|
|
193
|
+
})
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
xhr.upload.onloadstart = () => item.status = 'uploading'
|
|
197
|
+
//获取上传的进度
|
|
198
|
+
xhr.upload.onprogress = (event) => {
|
|
199
|
+
// console.log(event)
|
|
200
|
+
if (event.lengthComputable) {
|
|
201
|
+
var percent = (event.loaded / event.total) * 100;
|
|
202
|
+
// console.log(percent)
|
|
203
|
+
item.percent = percent
|
|
204
|
+
}
|
|
205
|
+
this.$emit('change', {
|
|
206
|
+
file: Object.assign(item, { response: xhr.responseText }),
|
|
207
|
+
fileList: this.defaultFileList,
|
|
208
|
+
event
|
|
209
|
+
})
|
|
210
|
+
}
|
|
211
|
+
xhr.onerror = event => {
|
|
212
|
+
item.status = 'error'
|
|
213
|
+
|
|
214
|
+
delete this.uploadTemp[item.uid]
|
|
215
|
+
|
|
216
|
+
this.$emit('change', {
|
|
217
|
+
file: Object.assign(item, { response: xhr.responseText }),
|
|
218
|
+
fileList: this.defaultFileList,
|
|
219
|
+
event: event
|
|
220
|
+
})
|
|
221
|
+
}
|
|
222
|
+
//将formdata上传
|
|
223
|
+
xhr.send(formdata);
|
|
224
|
+
},
|
|
225
|
+
getPreview(item) {
|
|
226
|
+
if (item.preview == true && item.url) {
|
|
227
|
+
return <img src={item.url} />
|
|
228
|
+
}
|
|
229
|
+
if (item.preview) {
|
|
230
|
+
return <img src={item.preview} />
|
|
231
|
+
} else if (item.url) {
|
|
232
|
+
return <img src={item.url} />
|
|
233
|
+
} else {
|
|
234
|
+
return null
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
onDrop(e) {
|
|
238
|
+
// var files = e.dataTransfer.files;
|
|
239
|
+
this.selectFiles(e)
|
|
240
|
+
e.preventDefault()
|
|
241
|
+
return false
|
|
242
|
+
},
|
|
243
|
+
onDragEnter(e) {
|
|
244
|
+
this.dragOver = true
|
|
245
|
+
e.preventDefault()
|
|
246
|
+
return false
|
|
247
|
+
}
|
|
248
|
+
},
|
|
249
|
+
|
|
250
|
+
render() {
|
|
251
|
+
let { name, accept, multiple, directory, type, showUploadList, uploadIcon,
|
|
252
|
+
defaultFileList, limit, uploadText, uploadSubText, draggable } = this
|
|
253
|
+
let isPicture = type == 'picture'
|
|
254
|
+
const props = {
|
|
255
|
+
class: [
|
|
256
|
+
"k-upload",
|
|
257
|
+
{
|
|
258
|
+
["k-upload-disabled"]: this.disabled,
|
|
259
|
+
["k-upload-picture"]: isPicture,
|
|
260
|
+
["k-upload-drag"]: draggable
|
|
261
|
+
}
|
|
262
|
+
],
|
|
263
|
+
}
|
|
264
|
+
// let list
|
|
265
|
+
// let childs = getChild(this.$slots.default)
|
|
266
|
+
// let child = childs.map(child => {
|
|
267
|
+
// return cloneVNode(child, { on: { click: this.triggerSelect } })
|
|
268
|
+
// })
|
|
269
|
+
let addProps = {
|
|
270
|
+
on: {
|
|
271
|
+
dragenter: this.onDragEnter,
|
|
272
|
+
drop: this.onDrop,
|
|
273
|
+
click: this.triggerSelect
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
let showSelector = (isPicture && limit && limit > defaultFileList.length ) || !isPicture || !limit
|
|
278
|
+
const selector = showSelector ? <div class='k-upload-select'>
|
|
279
|
+
<div class="k-upload-add" {...addProps}>
|
|
280
|
+
<input type="file" class="k-upload-file"
|
|
281
|
+
webkitdirectory={directory}
|
|
282
|
+
name={name} accept={accept} multiple={multiple}
|
|
283
|
+
onChange={this.selectFiles} ref="k-upload-file" />
|
|
284
|
+
{(isPicture || draggable) ? <Icon type={uploadIcon} /> : this.$slots.default}
|
|
285
|
+
{(isPicture || draggable && uploadText) ? <span class="k-upload-text">{uploadText}</span> : null}
|
|
286
|
+
{(draggable && uploadSubText) ? <span class="k-upload-sub-text">{uploadSubText}</span> : null}
|
|
287
|
+
</div>
|
|
288
|
+
</div> : null
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
const filsList = () => {
|
|
292
|
+
return (showUploadList && !isPicture) || isPicture ? <div class={`k-upload-${isPicture ? 'picture' : 'file'}-list`}>
|
|
293
|
+
{
|
|
294
|
+
defaultFileList.map((item, i) => {
|
|
295
|
+
let statusText = item.status == 'success' ? '上传成功' : (item.errorText || '上传失败')
|
|
296
|
+
delete item.errorText
|
|
297
|
+
item.uid = item.uid || getUuid()
|
|
298
|
+
return (
|
|
299
|
+
<div class={[`k-upload-file-${type}-item`, `k-upload-file-status-${item.status}`]} key={item.uid}>
|
|
300
|
+
<div class={`k-upload-${isPicture ? 'picture' : 'file'}-preview`}>
|
|
301
|
+
{
|
|
302
|
+
this.getPreview(item) || <Icon type="document-text-outline" />
|
|
303
|
+
}
|
|
304
|
+
</div>
|
|
305
|
+
<div class="k-upload-file-item-info">
|
|
306
|
+
{!isPicture ? <div class="k-upload-file-main">
|
|
307
|
+
<span class="k-upload-file-name">{item.filename}</span>
|
|
308
|
+
<span class="k-upload-file-size">{item.size}</span>
|
|
309
|
+
</div> : null}
|
|
310
|
+
{
|
|
311
|
+
(item.status != 'wait') ?
|
|
312
|
+
<div class="k-upload-file-status">
|
|
313
|
+
{item.status == 'uploading' ?
|
|
314
|
+
<Progress percent={item.percent} type={`${isPicture ? 'circle' : 'line'}`} size="small" showInfo={false} status="active" />
|
|
315
|
+
:
|
|
316
|
+
statusText && !isPicture ? <div class="k-upload-file-status-text"><Icon type="alert-circle" />{statusText}</div> : null
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
{isPicture && item.status == 'error' ? <Tooltip title={statusText} placement="bottom"><Icon type="alert-circle" /></Tooltip> : null}
|
|
320
|
+
</div> : null}
|
|
321
|
+
</div>
|
|
322
|
+
<Icon type="close-outline" class={`k-upload-file-${isPicture ? 'picture' : 'item'}-remove`} onClick={() => this.remove(i)} />
|
|
323
|
+
</div>
|
|
324
|
+
)
|
|
325
|
+
})
|
|
326
|
+
}
|
|
327
|
+
{isPicture && selector}
|
|
328
|
+
</div> : null
|
|
329
|
+
}
|
|
330
|
+
return (
|
|
331
|
+
<div {...props} >
|
|
332
|
+
{!isPicture ? [selector, filsList()] : filsList(selector)}
|
|
333
|
+
</div >
|
|
334
|
+
)
|
|
335
|
+
}
|
|
336
|
+
}
|