kui-vue 3.6.2 → 3.6.4
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/card/card.jsx +19 -9
- package/components/card/demo/basic.md +3 -3
- package/components/card/demo/border.md +1 -7
- package/components/card/demo/index.jsx +9 -7
- package/components/card/demo/notitle.md +23 -0
- package/components/card/styles/index.less +5 -3
- package/components/checkbox/styles/index.less +1 -0
- package/components/collapse/styles/index.less +2 -2
- package/components/colorPicker/mode.jsx +1 -1
- package/components/components.js +3 -0
- package/components/drawer/demo/target.md +2 -2
- package/components/drawer/drawer.jsx +48 -74
- package/components/drawer/styles/index.less +38 -67
- package/components/dropdown/demo/basic.md +1 -1
- package/components/dropdown/demo/rightmenu.md +1 -1
- package/components/dropdown/styles/index.less +181 -24
- package/components/flex/demo/size.md +14 -5
- package/components/form/demo/customvalid.md +1 -1
- package/components/form/demo/dynamicvalid.md +1 -1
- package/components/form/demo/length.md +1 -13
- package/components/form/demo/valid.md +10 -1
- package/components/form/form.jsx +1 -1
- package/components/grid/demo/align.md +5 -5
- package/components/grid/demo/basic.md +2 -2
- package/components/grid/demo/fill.md +8 -8
- package/components/grid/demo/flex.md +7 -7
- package/components/grid/demo/gutter.md +2 -4
- package/components/grid/demo/offset.md +5 -5
- package/components/input/demo/icon.md +9 -2
- package/components/input/demo/theme.md +1 -1
- package/components/input/input.jsx +12 -10
- package/components/inputNumber/demo/basic.md +1 -0
- package/components/inputNumber/demo/format.md +3 -8
- package/components/inputNumber/inputNumber.jsx +116 -139
- package/components/inputNumber/styles/index.less +3 -3
- package/components/layout/demo/layout2.md +0 -12
- package/components/layout/demo/layout5.md +0 -1
- package/components/locale/de.js +1 -0
- package/components/locale/el.js +1 -0
- package/components/locale/en.js +1 -0
- package/components/locale/fr.js +1 -0
- package/components/locale/it.js +1 -0
- package/components/locale/ja.js +1 -0
- package/components/locale/ko.js +1 -0
- package/components/locale/ru.js +1 -0
- package/components/locale/th.js +1 -0
- package/components/locale/uk.js +1 -0
- package/components/locale/vi.js +1 -0
- package/components/locale/zh-CN.js +1 -0
- package/components/locale/zh-TW.js +1 -0
- package/components/menu/demo/collapsed.md +9 -9
- package/components/menu/index.md +1 -0
- package/components/menu/styles/index.less +229 -375
- package/components/message/group.jsx +11 -4
- package/components/rate/rate.jsx +7 -2
- package/components/rate/star.jsx +20 -5
- package/components/select/demo/filterable.md +1 -0
- package/components/select/demo/multiple.md +3 -0
- package/components/select/select.jsx +23 -19
- package/components/slider/demo/vertical.md +2 -1
- package/components/slider/demo/withNumber.md +0 -2
- package/components/slider/index.md +2 -3
- package/components/slider/slider.jsx +296 -291
- package/components/slider/styles/index.less +11 -12
- package/components/slider/thumb.jsx +70 -148
- package/components/spin/demo/container.md +1 -1
- package/components/spin/demo/mode.md +1 -1
- package/components/statCard/countup.js +254 -0
- package/components/statCard/countup.jsx +45 -0
- package/components/statCard/demo/basic.md +31 -0
- package/components/statCard/demo/card.md +40 -0
- package/components/statCard/demo/index.jsx +19 -0
- package/components/statCard/demo/info.md +9 -0
- package/components/statCard/demo/with-card.md +43 -0
- package/components/statCard/index.js +3 -0
- package/components/statCard/index.md +28 -0
- package/components/statCard/rollup.jsx +64 -0
- package/components/statCard/statCard.jsx +42 -0
- package/components/statCard/statNumber.jsx +53 -0
- package/components/statCard/styles/index.less +76 -0
- package/components/styles/color.less +4 -2
- package/components/styles/index.less +1 -0
- package/components/styles/sys.less +2 -3
- package/components/styles/var.less +1 -0
- package/components/table/demo/col-row-span.md +1 -1
- package/components/table/demo/custom-header.md +1 -1
- package/components/table/demo/fixed-col-head.md +1 -1
- package/components/table/demo/head-span.md +2 -2
- package/components/table/demo/size.md +1 -1
- package/components/table/demo/table-check.md +11 -1
- package/components/table/index.md +13 -12
- package/components/table/styles/index.less +67 -58
- package/components/table/table.jsx +7 -5
- package/components/tabs/demo/sample.md +1 -8
- package/components/tabs/index.md +9 -9
- package/components/tabs/tabs.jsx +6 -4
- package/components/treeselect/treeselect.jsx +17 -17
- package/components/upload/demo/custom.md +5 -2
- package/components/upload/demo/exceed.md +1 -1
- package/components/upload/demo/pictures.md +14 -0
- package/components/upload/fileList.jsx +24 -47
- package/components/upload/index.md +13 -4
- package/components/upload/selector.jsx +37 -117
- package/components/upload/styles/index.less +2 -3
- package/components/upload/upload.jsx +189 -116
- package/components/utils/number.js +79 -65
- package/components/utils/placement.js +4 -4
- package/components/utils/vnode.jsx +46 -25
- package/dist/k-ui.cjs.js +2 -2
- package/dist/k-ui.css +2 -2
- package/dist/k-ui.d.ts +242 -200
- package/dist/k-ui.esm.js +2 -2
- package/dist/k-ui.umd.js +2 -2
- package/dist/locale/de.js +2 -2
- package/dist/locale/el.js +2 -2
- package/dist/locale/en.js +2 -2
- package/dist/locale/fr.js +2 -2
- package/dist/locale/it.js +2 -2
- package/dist/locale/ja.js +2 -2
- package/dist/locale/ko.js +2 -2
- package/dist/locale/ru.js +2 -2
- package/dist/locale/th.js +2 -2
- package/dist/locale/uk.js +2 -2
- package/dist/locale/vi.js +2 -2
- package/dist/locale/zh-CN.js +2 -2
- package/dist/locale/zh-TW.js +2 -2
- package/package.json +3 -1
- package/types/affix/Affix.d.ts +1 -1
- package/types/alert/Alert.d.ts +1 -1
- package/types/avatar/Avatar.d.ts +1 -1
- package/types/backtop/BackTop.d.ts +1 -1
- package/types/badge/Badge.d.ts +1 -1
- package/types/breadcrumb/Breadcrumb.d.ts +1 -1
- package/types/breadcrumb/BreadcrumbItem.d.ts +1 -1
- package/types/button/Button.d.ts +1 -1
- package/types/button/ButtonGroup.d.ts +1 -1
- package/types/card/Card.d.ts +1 -1
- package/types/carousel/Carousel.d.ts +1 -1
- package/types/carousel/CarouselItem.d.ts +1 -1
- package/types/checkbox/Checkbox.d.ts +1 -1
- package/types/checkbox/CheckboxGroup.d.ts +1 -1
- package/types/collapse/Collapse.d.ts +1 -1
- package/types/collapse/CollapsePanel.d.ts +1 -1
- package/types/colorPicker/ColorPicker.d.ts +1 -1
- package/types/datePicker/DatePicker.d.ts +1 -1
- package/types/descriptions/Descriptions.d.ts +1 -1
- package/types/descriptions/DescriptionsItem.d.ts +1 -1
- package/types/divider/Divider.d.ts +1 -1
- package/types/drawer/Drawer.d.ts +2 -2
- package/types/dropdown/Dropdown.d.ts +1 -1
- package/types/dropdown/DropdownButton.d.ts +1 -1
- package/types/empty/Empty.d.ts +1 -1
- package/types/flex/Flex.d.ts +1 -1
- package/types/form/Form.d.ts +1 -1
- package/types/form/formitem.d.ts +1 -1
- package/types/grid/Col.d.ts +1 -1
- package/types/grid/Row.d.ts +1 -1
- package/types/icon/Icon.d.ts +1 -1
- package/types/image/ImageGroup.d.ts +1 -1
- package/types/image/KImage.d.ts +1 -1
- package/types/index.d.ts +16 -12
- package/types/input/Input.d.ts +1 -1
- package/types/input/InputGroup.d.ts +1 -1
- package/types/input/TextArea.d.ts +1 -1
- package/types/inputNumber/InputNumber.d.ts +1 -1
- package/types/layout/sider.d.ts +1 -1
- package/types/loading/loading.d.ts +1 -1
- package/types/menu/Menu.d.ts +1 -1
- package/types/menu/MenuDivider.d.ts +1 -1
- package/types/menu/MenuGroup.d.ts +1 -1
- package/types/menu/MenuItem.d.ts +1 -1
- package/types/menu/SubMenu.d.ts +1 -1
- package/types/modal/Modal.d.ts +1 -1
- package/types/page/Page.d.ts +1 -1
- package/types/popconfirm/Popconfirm.d.ts +1 -1
- package/types/poptip/Poptip.d.ts +1 -1
- package/types/progress/Progress.d.ts +1 -1
- package/types/radio/Radio.d.ts +1 -1
- package/types/radio/RadioButton.d.ts +1 -1
- package/types/radio/RadioGroup.d.ts +1 -1
- package/types/rate/Rate.d.ts +2 -2
- package/types/select/Option.d.ts +1 -1
- package/types/select/Select.d.ts +1 -1
- package/types/skeleton/Skeleton.d.ts +1 -1
- package/types/skeleton/SkeletonAvatar.d.ts +1 -1
- package/types/skeleton/SkeletonButton.d.ts +1 -1
- package/types/skeleton/SkeletonImage.d.ts +1 -1
- package/types/skeleton/SkeletonText.d.ts +1 -1
- package/types/slider/Slider.d.ts +8 -7
- package/types/space/Space.d.ts +1 -1
- package/types/spin/Spin.d.ts +1 -1
- package/types/statCard/StatCard.d.ts +20 -0
- package/types/statCard/StatNumber.d.ts +26 -0
- package/types/switch/Switch.d.ts +1 -1
- package/types/table/Table.d.ts +2 -1
- package/types/tabs/TabPanel.d.ts +1 -1
- package/types/tabs/Tabs.d.ts +1 -1
- package/types/tag/Tag.d.ts +1 -1
- package/types/timeline/TimeLine.d.ts +1 -1
- package/types/timeline/TimeLineItem.d.ts +1 -1
- package/types/tooltip/Tooltip.d.ts +1 -1
- package/types/tree/Tree.d.ts +1 -1
- package/types/treeselect/TreeSelect.d.ts +1 -1
- package/types/upload/Upload.d.ts +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ref, defineComponent
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
1
|
+
import { ref, defineComponent } from "vue";
|
|
2
|
+
import Icon from "../icon";
|
|
3
|
+
import { Add } from "kui-icons";
|
|
4
4
|
|
|
5
5
|
export default defineComponent({
|
|
6
6
|
name: "Selector",
|
|
@@ -14,139 +14,54 @@ export default defineComponent({
|
|
|
14
14
|
uploadText: String,
|
|
15
15
|
uploadSubText: String,
|
|
16
16
|
draggable: Boolean,
|
|
17
|
+
locale: Object,
|
|
17
18
|
fileList: Array,
|
|
18
19
|
uploadIcon: [String, Object, Array],
|
|
19
|
-
minSize: Number,
|
|
20
|
-
maxSize: Number,
|
|
21
|
-
autoTrigger: { type: Boolean, default: true },
|
|
22
20
|
type: {
|
|
23
21
|
type: String,
|
|
24
22
|
default: "list",
|
|
25
23
|
validator: (val) => ["list", "picture"].indexOf(val) >= 0,
|
|
26
24
|
},
|
|
27
25
|
},
|
|
28
|
-
setup(
|
|
29
|
-
const injectedLocale = inject("locale", zhCN);
|
|
30
|
-
|
|
31
|
-
const locale = computed(() => {
|
|
32
|
-
return injectedLocale instanceof Object && "value" in injectedLocale
|
|
33
|
-
? injectedLocale.value
|
|
34
|
-
: injectedLocale;
|
|
35
|
-
});
|
|
26
|
+
setup(props, { emit, slots }) {
|
|
36
27
|
const dragOver = ref(false);
|
|
37
28
|
const uploadFileRef = ref(null);
|
|
38
|
-
const defaultFileList = ref(ps.fileList || []);
|
|
39
29
|
const onDragEnter = (e) => {
|
|
40
30
|
dragOver.value = true;
|
|
41
31
|
e.preventDefault();
|
|
42
32
|
return false;
|
|
43
33
|
};
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
if (fileSize < 1024) {
|
|
47
|
-
return fileSize + "B";
|
|
48
|
-
} else if (fileSize < 1024 * 1024) {
|
|
49
|
-
temp = fileSize / 1024;
|
|
50
|
-
return temp.toFixed(2) + "KB";
|
|
51
|
-
} else if (fileSize < 1024 * 1024 * 1024) {
|
|
52
|
-
temp = fileSize / (1024 * 1024);
|
|
53
|
-
return temp.toFixed(2) + "MB";
|
|
54
|
-
} else {
|
|
55
|
-
temp = fileSize / (1024 * 1024 * 1024);
|
|
56
|
-
return temp.toFixed(2) + "GB";
|
|
57
|
-
}
|
|
34
|
+
const onDragLeave = () => {
|
|
35
|
+
dragOver.value = false;
|
|
58
36
|
};
|
|
59
|
-
const selectFiles = (e) => {
|
|
60
|
-
let { limit, minSize, maxSize, autoTrigger } = ps;
|
|
61
|
-
let files = e.dataTransfer ? e.dataTransfer.files : e.target.files;
|
|
62
|
-
|
|
63
|
-
for (let i = 0; i < files.length; i++) {
|
|
64
|
-
let { size, type } = files[i];
|
|
65
|
-
if (files[i].name == ".DS_Store") {
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
let item = {
|
|
70
|
-
uid: uuid(),
|
|
71
|
-
filename: files[i].name,
|
|
72
|
-
size: formatFileSize(size),
|
|
73
|
-
status: "wait",
|
|
74
|
-
percent: 0,
|
|
75
|
-
preview: null,
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
emit("select", { item, file: files[i] });
|
|
79
|
-
|
|
80
|
-
// uploadTemp[item.uid] = files[i];
|
|
81
|
-
|
|
82
|
-
if (limit && i > limit - 1) {
|
|
83
|
-
emit("exceed");
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
if ((type || "").indexOf("image/") >= 0) {
|
|
87
|
-
item.preview = window.URL.createObjectURL(files[i]);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
let error = false;
|
|
91
|
-
if (
|
|
92
|
-
(minSize !== undefined && minSize >= 0 && size / 1024 < minSize) ||
|
|
93
|
-
(maxSize !== undefined && maxSize >= 0 && size / 1024 > maxSize)
|
|
94
|
-
) {
|
|
95
|
-
error = true;
|
|
96
|
-
item.errorText = locale?.value.k.upload.errorFileSize;
|
|
97
|
-
item.status = "error";
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
defaultFileList.value.push(item);
|
|
101
|
-
|
|
102
|
-
emit("before-upload", {
|
|
103
|
-
file: item,
|
|
104
|
-
fileList: defaultFileList.value,
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
if (error) {
|
|
108
|
-
emit("change", {
|
|
109
|
-
file: item,
|
|
110
|
-
fileList: defaultFileList.value,
|
|
111
|
-
});
|
|
112
|
-
emit("size-error", {
|
|
113
|
-
file: item,
|
|
114
|
-
fileList: defaultFileList.value,
|
|
115
|
-
});
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
37
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
38
|
+
const selectFiles = (e) => {
|
|
39
|
+
const files = e.dataTransfer ? e.dataTransfer.files : e.target.files;
|
|
40
|
+
if (files && files.length > 0) {
|
|
41
|
+
emit("select", files);
|
|
123
42
|
}
|
|
124
|
-
e.target.value = "";
|
|
43
|
+
e.target.value = ""; // 清空 input 防止重复选同文件不触发 change
|
|
44
|
+
e.preventDefault();
|
|
45
|
+
dragOver.value = false;
|
|
125
46
|
};
|
|
126
47
|
const onDrop = (e) => {
|
|
127
48
|
selectFiles(e);
|
|
128
|
-
e.preventDefault();
|
|
129
|
-
dragOver.value = false;
|
|
130
49
|
return false;
|
|
131
50
|
};
|
|
132
51
|
|
|
133
52
|
const onDragOver = (e) => {
|
|
134
53
|
e.stopPropagation();
|
|
135
54
|
e.preventDefault();
|
|
55
|
+
dragOver.value = true;
|
|
136
56
|
};
|
|
137
57
|
|
|
138
58
|
const triggerSelect = (e) => {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
if (uploadFileRef.value) {
|
|
143
|
-
uploadFileRef.value.click();
|
|
144
|
-
}
|
|
145
|
-
return false;
|
|
59
|
+
if (props.disabled) return;
|
|
60
|
+
uploadFileRef.value?.click();
|
|
146
61
|
};
|
|
147
62
|
|
|
148
63
|
return () => {
|
|
149
|
-
|
|
64
|
+
const {
|
|
150
65
|
name,
|
|
151
66
|
accept,
|
|
152
67
|
multiple,
|
|
@@ -158,28 +73,31 @@ export default defineComponent({
|
|
|
158
73
|
draggable,
|
|
159
74
|
uploadIcon,
|
|
160
75
|
type,
|
|
161
|
-
|
|
76
|
+
fileList,
|
|
77
|
+
locale,
|
|
78
|
+
} = props;
|
|
162
79
|
let isPicture = type == "picture";
|
|
80
|
+
const isLimitExceeded = limit && fileList && fileList.length >= limit;
|
|
81
|
+
const showSelector = !isPicture || !isLimitExceeded;
|
|
82
|
+
if (!showSelector) return null;
|
|
83
|
+
|
|
163
84
|
let addProps = {
|
|
164
85
|
attrs: {
|
|
165
86
|
drag: draggable && dragOver.value ? "over" : null,
|
|
166
87
|
},
|
|
88
|
+
class: ["k-upload-add", { "k-upload-drag-over": dragOver.value }],
|
|
167
89
|
on: {
|
|
168
90
|
dragenter: onDragEnter,
|
|
169
91
|
drop: onDrop,
|
|
170
92
|
dragover: onDragOver,
|
|
171
|
-
dragleave:
|
|
93
|
+
dragleave: onDragLeave,
|
|
172
94
|
click: triggerSelect,
|
|
173
95
|
},
|
|
174
96
|
};
|
|
175
|
-
|
|
176
|
-
(isPicture && limit && limit > defaultFileList.value.length) ||
|
|
177
|
-
!isPicture ||
|
|
178
|
-
!limit;
|
|
179
|
-
// console.log(type, isPicture, draggable);
|
|
97
|
+
|
|
180
98
|
return showSelector ? (
|
|
181
99
|
<div class="k-upload-select">
|
|
182
|
-
<div
|
|
100
|
+
<div {...addProps}>
|
|
183
101
|
<input
|
|
184
102
|
type="file"
|
|
185
103
|
class="k-upload-file"
|
|
@@ -192,18 +110,20 @@ export default defineComponent({
|
|
|
192
110
|
ref={uploadFileRef}
|
|
193
111
|
/>
|
|
194
112
|
{isPicture || draggable ? (
|
|
195
|
-
<Icon type={uploadIcon} />
|
|
113
|
+
<Icon type={uploadIcon || Add} />
|
|
196
114
|
) : (
|
|
197
115
|
slots.default?.()
|
|
198
116
|
)}
|
|
199
|
-
{isPicture || (draggable && uploadText)
|
|
117
|
+
{(isPicture || (draggable && uploadText)) && (
|
|
200
118
|
<span class="k-upload-text">{uploadText}</span>
|
|
201
|
-
)
|
|
202
|
-
{draggable && uploadSubText
|
|
119
|
+
)}
|
|
120
|
+
{draggable && uploadSubText && (
|
|
203
121
|
<span class="k-upload-sub-text">
|
|
204
|
-
{dragOver.value
|
|
122
|
+
{dragOver.value
|
|
123
|
+
? locale?.k.upload.releaseToUpload
|
|
124
|
+
: uploadSubText}
|
|
205
125
|
</span>
|
|
206
|
-
)
|
|
126
|
+
)}
|
|
207
127
|
</div>
|
|
208
128
|
</div>
|
|
209
129
|
) : null;
|
|
@@ -156,6 +156,7 @@
|
|
|
156
156
|
display: inline-flex;
|
|
157
157
|
margin-top: 0;
|
|
158
158
|
flex-wrap: wrap;
|
|
159
|
+
gap: 8px;
|
|
159
160
|
}
|
|
160
161
|
|
|
161
162
|
.k-upload-select {
|
|
@@ -191,11 +192,9 @@
|
|
|
191
192
|
|
|
192
193
|
.k-upload-file-picture-item {
|
|
193
194
|
width: 96px;
|
|
194
|
-
height:
|
|
195
|
+
height: 96px;
|
|
195
196
|
border-radius: var(--kui-border-radius);
|
|
196
197
|
border: 1px solid var(--kui-color-border);
|
|
197
|
-
margin-bottom: 8px;
|
|
198
|
-
margin-right: 8px;
|
|
199
198
|
position: relative;
|
|
200
199
|
overflow: hidden;
|
|
201
200
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { ref, reactive, watch, defineComponent } from "vue";
|
|
2
|
-
import { Add } from "kui-icons";
|
|
1
|
+
import { ref, reactive, watch, defineComponent, inject, computed } from "vue";
|
|
3
2
|
import { withInstall } from "../utils/vue";
|
|
4
3
|
import Selector from "./selector";
|
|
5
4
|
import FileList from "./fileList";
|
|
5
|
+
import { v4 as uuid } from "uuid";
|
|
6
|
+
import zhCN from "../locale/zh-CN";
|
|
6
7
|
|
|
7
8
|
const Upload = defineComponent({
|
|
8
9
|
name: "Upload",
|
|
@@ -33,36 +34,158 @@ const Upload = defineComponent({
|
|
|
33
34
|
uploadIcon: [String, Object, Array],
|
|
34
35
|
draggable: Boolean,
|
|
35
36
|
},
|
|
36
|
-
emits: [
|
|
37
|
+
emits: [
|
|
38
|
+
"remove",
|
|
39
|
+
"exceed",
|
|
40
|
+
"beforeUpload",
|
|
41
|
+
"change",
|
|
42
|
+
"sizeError",
|
|
43
|
+
"update:fileList",
|
|
44
|
+
"onSelectFiles",
|
|
45
|
+
],
|
|
37
46
|
setup(props, { emit, slots, expose }) {
|
|
38
|
-
const
|
|
47
|
+
const injectedLocale = inject("locale", zhCN);
|
|
48
|
+
|
|
49
|
+
const locale = computed(() => {
|
|
50
|
+
return injectedLocale instanceof Object && "value" in injectedLocale
|
|
51
|
+
? injectedLocale.value
|
|
52
|
+
: injectedLocale;
|
|
53
|
+
});
|
|
54
|
+
const innerFileList = ref([...(props.fileList || [])]);
|
|
39
55
|
const uploadTemp = reactive({});
|
|
40
56
|
|
|
41
57
|
// Watch for fileList changes
|
|
42
58
|
watch(
|
|
43
59
|
() => props.fileList,
|
|
44
60
|
(newVal) => {
|
|
45
|
-
|
|
46
|
-
}
|
|
61
|
+
innerFileList.value = newVal || [];
|
|
62
|
+
},
|
|
63
|
+
{ deep: true }
|
|
47
64
|
);
|
|
65
|
+
const formatFileSize = (fileSize) => {
|
|
66
|
+
var temp = 0;
|
|
67
|
+
if (fileSize < 1024) {
|
|
68
|
+
return fileSize + "B";
|
|
69
|
+
} else if (fileSize < 1024 * 1024) {
|
|
70
|
+
temp = fileSize / 1024;
|
|
71
|
+
return temp.toFixed(2) + "KB";
|
|
72
|
+
} else if (fileSize < 1024 * 1024 * 1024) {
|
|
73
|
+
temp = fileSize / (1024 * 1024);
|
|
74
|
+
return temp.toFixed(2) + "MB";
|
|
75
|
+
} else {
|
|
76
|
+
temp = fileSize / (1024 * 1024 * 1024);
|
|
77
|
+
return temp.toFixed(2) + "GB";
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const triggerUpdate = (fileItem) => {
|
|
82
|
+
emit("update:fileList", innerFileList.value);
|
|
83
|
+
emit("change", { file: fileItem, fileList: innerFileList.value });
|
|
84
|
+
};
|
|
85
|
+
const onSelectFiles = (files) => {
|
|
86
|
+
const currentCount = innerFileList.value?.length;
|
|
87
|
+
const { limit, minSize, maxSize } = props;
|
|
88
|
+
for (let i = 0; i < files.length; i++) {
|
|
89
|
+
const file = files[i];
|
|
90
|
+
if (file.name == ".DS_Store") {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
let item = {
|
|
95
|
+
uid: uuid(),
|
|
96
|
+
filename: file.name,
|
|
97
|
+
size: formatFileSize(file.size),
|
|
98
|
+
status: "wait",
|
|
99
|
+
percent: 0,
|
|
100
|
+
preview: null,
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
if (limit && currentCount + i >= limit) {
|
|
104
|
+
emit("exceed");
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if ((file.type || "").indexOf("image/") >= 0) {
|
|
108
|
+
item.preview = window.URL.createObjectURL(file);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (
|
|
112
|
+
(minSize !== undefined &&
|
|
113
|
+
minSize >= 0 &&
|
|
114
|
+
file.size / 1024 < minSize) ||
|
|
115
|
+
(maxSize !== undefined && maxSize >= 0 && file.size / 1024 > maxSize)
|
|
116
|
+
) {
|
|
117
|
+
item.errorText = locale?.value.k.upload.errorFileSize;
|
|
118
|
+
item.status = "error";
|
|
119
|
+
innerFileList.value.push(item);
|
|
120
|
+
triggerUpdate(item);
|
|
121
|
+
emit("sizeError", {
|
|
122
|
+
file: item,
|
|
123
|
+
fileList: innerFileList.value,
|
|
124
|
+
});
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
handleSelect({ item, file });
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
emit("onSelectFiles", innerFileList.value);
|
|
132
|
+
};
|
|
133
|
+
// 处理 Selector 发来的选择事件
|
|
134
|
+
const handleSelect = ({ item, file }) => {
|
|
135
|
+
innerFileList.value.push(item);
|
|
136
|
+
|
|
137
|
+
const reactiveItem = innerFileList.value.find((x) => x.uid === item.uid);
|
|
138
|
+
if (!reactiveItem) return;
|
|
139
|
+
|
|
140
|
+
uploadTemp[reactiveItem.uid] = file;
|
|
141
|
+
triggerUpdate(reactiveItem);
|
|
142
|
+
|
|
143
|
+
if (props.autoTrigger) {
|
|
144
|
+
uploadFile(reactiveItem, file);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
// 处理 FileList 发来的移除事件
|
|
149
|
+
const handleRemove = ({ index, file }) => {
|
|
150
|
+
const item = innerFileList.value[index];
|
|
151
|
+
if (!item) return;
|
|
152
|
+
|
|
153
|
+
if (item.xhr) {
|
|
154
|
+
item.xhr.abort();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
innerFileList.value.splice(index, 1);
|
|
158
|
+
delete uploadTemp[file.uid];
|
|
159
|
+
|
|
160
|
+
if (file.preview) window.URL.revokeObjectURL(file.preview);
|
|
161
|
+
|
|
162
|
+
emit("update:fileList", innerFileList.value);
|
|
163
|
+
emit("remove", { file, fileList: innerFileList.value });
|
|
164
|
+
};
|
|
48
165
|
|
|
49
166
|
const upload = () => {
|
|
50
167
|
if (!props.autoTrigger && !props.disabled) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
item &&
|
|
55
|
-
|
|
168
|
+
Object.keys(uploadTemp).forEach((uid) => {
|
|
169
|
+
const item = innerFileList.value.find((x) => x.uid === uid);
|
|
170
|
+
const file = uploadTemp[uid];
|
|
171
|
+
if (item && file && item.status === "wait") {
|
|
172
|
+
uploadFile(item, file);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
56
175
|
}
|
|
57
176
|
};
|
|
58
177
|
|
|
59
178
|
const uploadFile = async (item, file) => {
|
|
179
|
+
emit("beforeUpload", {
|
|
180
|
+
file: item,
|
|
181
|
+
fileList: innerFileList.value,
|
|
182
|
+
});
|
|
60
183
|
if (props.transformFile) {
|
|
61
|
-
const
|
|
62
|
-
if (
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
184
|
+
const result = props.transformFile(file);
|
|
185
|
+
if (result instanceof Promise) {
|
|
186
|
+
result.then((f) => toUpload(item, f));
|
|
187
|
+
} else {
|
|
188
|
+
toUpload(item, result);
|
|
66
189
|
}
|
|
67
190
|
} else {
|
|
68
191
|
toUpload(item, file);
|
|
@@ -70,89 +193,71 @@ const Upload = defineComponent({
|
|
|
70
193
|
};
|
|
71
194
|
|
|
72
195
|
const toUpload = (item, file) => {
|
|
73
|
-
|
|
74
|
-
|
|
196
|
+
const { action, name, headers, data } = props;
|
|
197
|
+
const formdata = new FormData();
|
|
75
198
|
formdata.append(name, file);
|
|
76
199
|
|
|
77
200
|
if (data) {
|
|
78
|
-
for (
|
|
201
|
+
for (const k in data) {
|
|
79
202
|
formdata.append(k, data[k]);
|
|
80
203
|
}
|
|
81
204
|
}
|
|
82
205
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
item.xhr = xhr;
|
|
206
|
+
const xhr = new XMLHttpRequest();
|
|
207
|
+
item.xhr = xhr; // 将 xhr 挂载到对象上以便取消
|
|
86
208
|
|
|
87
209
|
xhr.open("post", action);
|
|
88
210
|
if (headers) {
|
|
89
|
-
for (
|
|
211
|
+
for (const k in headers) {
|
|
90
212
|
xhr.setRequestHeader(k, headers[k]);
|
|
91
213
|
}
|
|
92
214
|
}
|
|
93
215
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
216
|
+
xhr.onreadystatechange = () => {
|
|
217
|
+
if (xhr.readyState === 4) {
|
|
218
|
+
if (xhr.status === 200) {
|
|
219
|
+
item.status = "success";
|
|
220
|
+
item.percent = 100; // 确保完成是 100%
|
|
221
|
+
try {
|
|
222
|
+
item.response = JSON.parse(xhr.responseText);
|
|
223
|
+
} catch (e) {
|
|
224
|
+
item.response = xhr.responseText;
|
|
225
|
+
}
|
|
226
|
+
delete uploadTemp[item.uid];
|
|
227
|
+
triggerUpdate(item);
|
|
228
|
+
} else {
|
|
229
|
+
// 处理非 200 的完成状态
|
|
230
|
+
handleError();
|
|
231
|
+
}
|
|
106
232
|
}
|
|
107
233
|
};
|
|
108
234
|
|
|
109
|
-
xhr.upload.onloadstart = () =>
|
|
235
|
+
xhr.upload.onloadstart = () => {
|
|
236
|
+
item.status = "uploading";
|
|
237
|
+
triggerUpdate(item);
|
|
238
|
+
};
|
|
110
239
|
|
|
111
|
-
//获取上传的进度
|
|
112
240
|
xhr.upload.onprogress = (event) => {
|
|
113
241
|
if (event.lengthComputable) {
|
|
114
|
-
|
|
115
|
-
item.percent =
|
|
116
|
-
}
|
|
117
|
-
emit("change", {
|
|
118
|
-
file: Object.assign(item, { response: xhr.responseText }),
|
|
119
|
-
fileList: defaultFileList.value,
|
|
120
|
-
event,
|
|
121
|
-
});
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
xhr.onload = (event) => {
|
|
125
|
-
if (xhr.status != 200) {
|
|
126
|
-
item.status = "error";
|
|
127
|
-
delete uploadTemp[item.uid];
|
|
128
|
-
|
|
129
|
-
emit("change", {
|
|
130
|
-
file: Object.assign(item, { response: xhr.responseText }),
|
|
131
|
-
fileList: defaultFileList.value,
|
|
132
|
-
event: event,
|
|
133
|
-
});
|
|
242
|
+
// 直接修改响应式对象,Vue 会自动更新 UI
|
|
243
|
+
item.percent = (event.loaded / event.total) * 100;
|
|
134
244
|
}
|
|
135
245
|
};
|
|
136
246
|
|
|
137
|
-
|
|
247
|
+
const handleError = () => {
|
|
138
248
|
item.status = "error";
|
|
139
249
|
delete uploadTemp[item.uid];
|
|
140
|
-
|
|
141
|
-
emit("change", {
|
|
142
|
-
file: Object.assign(item, { response: xhr.responseText }),
|
|
143
|
-
fileList: defaultFileList.value,
|
|
144
|
-
event: event,
|
|
145
|
-
});
|
|
250
|
+
triggerUpdate(item);
|
|
146
251
|
};
|
|
147
252
|
|
|
148
|
-
|
|
253
|
+
xhr.onerror = handleError;
|
|
149
254
|
xhr.send(formdata);
|
|
150
255
|
};
|
|
151
256
|
|
|
152
257
|
expose({ upload });
|
|
153
258
|
|
|
154
259
|
return () => {
|
|
155
|
-
|
|
260
|
+
const {
|
|
156
261
|
type,
|
|
157
262
|
showUploadList,
|
|
158
263
|
uploadIcon,
|
|
@@ -165,26 +270,9 @@ const Upload = defineComponent({
|
|
|
165
270
|
uploadSubText,
|
|
166
271
|
draggable,
|
|
167
272
|
disabled,
|
|
168
|
-
minSize,
|
|
169
|
-
maxSize,
|
|
170
|
-
autoTrigger,
|
|
171
273
|
} = props;
|
|
172
274
|
|
|
173
|
-
|
|
174
|
-
if (uploadIcon === undefined) {
|
|
175
|
-
uploadIcon = Add;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
const propsData = {
|
|
179
|
-
class: [
|
|
180
|
-
"k-upload",
|
|
181
|
-
{
|
|
182
|
-
["k-upload-disabled"]: disabled,
|
|
183
|
-
["k-upload-picture"]: isPicture,
|
|
184
|
-
["k-upload-drag"]: draggable,
|
|
185
|
-
},
|
|
186
|
-
],
|
|
187
|
-
};
|
|
275
|
+
const isPicture = type === "picture";
|
|
188
276
|
|
|
189
277
|
const selectorProps = {
|
|
190
278
|
props: {
|
|
@@ -198,32 +286,11 @@ const Upload = defineComponent({
|
|
|
198
286
|
uploadText,
|
|
199
287
|
uploadSubText,
|
|
200
288
|
draggable,
|
|
201
|
-
fileList:
|
|
289
|
+
fileList: innerFileList.value,
|
|
202
290
|
uploadIcon,
|
|
203
|
-
|
|
204
|
-
maxSize,
|
|
205
|
-
autoTrigger,
|
|
206
|
-
},
|
|
207
|
-
on: {
|
|
208
|
-
upload: ({ item, file }) => {
|
|
209
|
-
uploadFile(item, file);
|
|
210
|
-
},
|
|
211
|
-
select: ({ item, file }) => {
|
|
212
|
-
uploadTemp[item.uid] = file;
|
|
213
|
-
},
|
|
214
|
-
exceed: (data) => {
|
|
215
|
-
emit("exceed", data);
|
|
216
|
-
},
|
|
217
|
-
"before-upload": (data) => {
|
|
218
|
-
emit("before-upload", data);
|
|
219
|
-
},
|
|
220
|
-
change: (data) => {
|
|
221
|
-
emit("change", data);
|
|
222
|
-
},
|
|
223
|
-
"size-error": (data) => {
|
|
224
|
-
emit("size-error", data);
|
|
225
|
-
},
|
|
291
|
+
locale: locale.value,
|
|
226
292
|
},
|
|
293
|
+
on: { select: onSelectFiles },
|
|
227
294
|
};
|
|
228
295
|
const SelectorNode = (
|
|
229
296
|
<Selector
|
|
@@ -234,17 +301,14 @@ const Upload = defineComponent({
|
|
|
234
301
|
const fileListProps = {
|
|
235
302
|
props: {
|
|
236
303
|
type,
|
|
237
|
-
fileList:
|
|
304
|
+
fileList: innerFileList.value,
|
|
238
305
|
showUploadList,
|
|
239
306
|
disabled,
|
|
307
|
+
locale: locale.value,
|
|
240
308
|
},
|
|
241
|
-
on: {
|
|
242
|
-
remove: (data) => {
|
|
243
|
-
delete uploadTemp[data.file.uid];
|
|
244
|
-
emit("remove", data);
|
|
245
|
-
},
|
|
246
|
-
},
|
|
309
|
+
on: { remove: handleRemove },
|
|
247
310
|
};
|
|
311
|
+
// console.log(innerFileList.value, 222);
|
|
248
312
|
const FileListNode = (
|
|
249
313
|
<FileList
|
|
250
314
|
{...fileListProps}
|
|
@@ -252,7 +316,16 @@ const Upload = defineComponent({
|
|
|
252
316
|
/>
|
|
253
317
|
);
|
|
254
318
|
return (
|
|
255
|
-
<div
|
|
319
|
+
<div
|
|
320
|
+
class={[
|
|
321
|
+
"k-upload",
|
|
322
|
+
{
|
|
323
|
+
"k-upload-disabled": disabled,
|
|
324
|
+
"k-upload-picture": isPicture,
|
|
325
|
+
"k-upload-drag": draggable,
|
|
326
|
+
},
|
|
327
|
+
]}
|
|
328
|
+
>
|
|
256
329
|
{!isPicture ? [SelectorNode, FileListNode] : FileListNode}
|
|
257
330
|
</div>
|
|
258
331
|
);
|