kui-vue 3.6.1 → 3.6.3
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/button/demo/size.md +1 -1
- 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/checkbox.jsx +17 -16
- package/components/checkbox/checkboxGroup.jsx +1 -1
- package/components/checkbox/styles/index.less +1 -0
- package/components/collapse/collapse.jsx +9 -10
- package/components/collapse/demo/accordion.md +2 -2
- package/components/collapse/demo/basic.md +2 -2
- package/components/collapse/demo/extra.md +2 -2
- package/components/collapse/demo/nesting.md +4 -4
- package/components/collapse/demo/sample.md +2 -2
- package/components/collapse/index.md +6 -6
- package/components/collapse/styles/index.less +2 -2
- package/components/colorPicker/demo/basic.md +14 -2
- package/components/colorPicker/demo/index.jsx +0 -8
- package/components/colorPicker/demo/size.md +24 -10
- package/components/colorPicker/mode.jsx +1 -1
- package/components/components.js +3 -0
- package/components/datePicker/demo/size.md +1 -1
- package/components/drawer/demo/target.md +2 -2
- package/components/dropdown/demo/basic.md +1 -1
- package/components/dropdown/dropdownButton.jsx +18 -7
- package/components/dropdown/styles/index.less +1 -0
- package/components/empty/demo/basic.md +1 -3
- package/components/empty/demo/nodesc.md +1 -3
- package/components/empty/demo/used.md +4 -6
- package/components/empty/empty.jsx +19 -17
- package/components/empty/styles/index.less +18 -5
- package/components/flex/demo/size.md +14 -5
- package/components/form/demo/align.md +10 -10
- 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 +11 -3
- package/components/form/form.jsx +2 -2
- package/components/form/formitem.jsx +1 -1
- package/components/image/preview.jsx +1 -1
- package/components/input/demo/basic.md +1 -1
- package/components/input/demo/group.md +1 -1
- package/components/input/input.jsx +19 -15
- package/components/input/inputBox.jsx +2 -2
- 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/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/message/demo/close.md +1 -1
- package/components/message/group.jsx +13 -6
- package/components/message/index.md +1 -1
- package/components/message/inner.jsx +26 -7
- package/components/notice/demo/close.md +1 -1
- package/components/notice/index.md +1 -1
- package/components/page/styles/index.less +7 -1
- package/components/popconfirm/popconfirm.jsx +14 -16
- package/components/progress/progress.jsx +1 -1
- package/components/radio/radio.jsx +14 -11
- package/components/radio/radioButton.jsx +1 -1
- package/components/radio/radioGroup.jsx +1 -1
- package/components/rate/demo/basic.md +12 -2
- package/components/rate/demo/character.md +16 -2
- package/components/rate/demo/index.jsx +0 -8
- package/components/rate/demo/tips.md +15 -5
- package/components/rate/rate.jsx +30 -6
- package/components/rate/star.jsx +20 -5
- package/components/select/demo/size.md +1 -1
- package/components/select/select.jsx +5 -4
- 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/space/styles/index.less +3 -1
- package/components/spin/demo/container.md +1 -1
- package/components/spin/demo/mode.md +1 -1
- package/components/spin/index.md +6 -5
- 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/switch/switch.jsx +1 -3
- package/components/table/demo/col-row-span.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 +2 -2
- 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 +7 -5
- package/components/tooltip/tooltip.jsx +13 -8
- package/components/treeselect/demo/basic.md +11 -8
- package/components/treeselect/demo/size.md +4 -3
- package/components/treeselect/demo/theme.md +0 -1
- package/components/treeselect/treeselect.jsx +5 -3
- 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 -117
- package/components/utils/number.js +79 -65
- package/components/utils/placement.js +62 -35
- package/dist/k-ui.cjs.js +2 -2
- package/dist/k-ui.css +2 -2
- package/dist/k-ui.d.ts +172 -129
- 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/ua.js +1 -1
- 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/checkbox/Checkbox.d.ts +1 -1
- package/types/collapse/Collapse.d.ts +1 -1
- package/types/index.d.ts +14 -10
- package/types/popconfirm/Popconfirm.d.ts +1 -0
- package/types/radio/Radio.d.ts +1 -1
- package/types/radio/RadioButton.d.ts +1 -1
- package/types/rate/Rate.d.ts +1 -1
- package/types/slider/Slider.d.ts +7 -6
- package/types/statCard/StatCard.d.ts +20 -0
- package/types/statCard/StatNumber.d.ts +26 -0
- package/types/switch/Switch.d.ts +1 -2
- package/types/table/Table.d.ts +1 -0
- package/types/tooltip/Tooltip.d.ts +1 -0
- package/components/base/collapse.jsx +0 -15
- package/components/base/input.jsx +0 -210
- package/components/colorPicker/demo/disabled.md +0 -16
- package/components/colorPicker/demo/disabledAlpha.md +0 -13
- package/components/colorPicker/demo/mode.md +0 -21
- package/components/colorPicker/demo/presets.md +0 -17
- package/components/rate/demo/clear.md +0 -13
- package/components/rate/demo/custom.md +0 -23
- package/components/rate/demo/disabled.md +0 -12
- package/components/rate/demo/half.md +0 -12
- package/components/utils/element.js +0 -122
|
@@ -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,127 +34,230 @@ 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
|
-
console.log(file)
|
|
69
191
|
toUpload(item, file);
|
|
70
192
|
}
|
|
71
193
|
};
|
|
72
194
|
|
|
73
195
|
const toUpload = (item, file) => {
|
|
74
|
-
|
|
75
|
-
|
|
196
|
+
const { action, name, headers, data } = props;
|
|
197
|
+
const formdata = new FormData();
|
|
76
198
|
formdata.append(name, file);
|
|
77
199
|
|
|
78
200
|
if (data) {
|
|
79
|
-
for (
|
|
201
|
+
for (const k in data) {
|
|
80
202
|
formdata.append(k, data[k]);
|
|
81
203
|
}
|
|
82
204
|
}
|
|
83
205
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
item.xhr = xhr;
|
|
206
|
+
const xhr = new XMLHttpRequest();
|
|
207
|
+
item.xhr = xhr; // 将 xhr 挂载到对象上以便取消
|
|
87
208
|
|
|
88
209
|
xhr.open("post", action);
|
|
89
210
|
if (headers) {
|
|
90
|
-
for (
|
|
211
|
+
for (const k in headers) {
|
|
91
212
|
xhr.setRequestHeader(k, headers[k]);
|
|
92
213
|
}
|
|
93
214
|
}
|
|
94
215
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
+
}
|
|
107
232
|
}
|
|
108
233
|
};
|
|
109
234
|
|
|
110
|
-
xhr.upload.onloadstart = () =>
|
|
235
|
+
xhr.upload.onloadstart = () => {
|
|
236
|
+
item.status = "uploading";
|
|
237
|
+
triggerUpdate(item);
|
|
238
|
+
};
|
|
111
239
|
|
|
112
|
-
//获取上传的进度
|
|
113
240
|
xhr.upload.onprogress = (event) => {
|
|
114
241
|
if (event.lengthComputable) {
|
|
115
|
-
|
|
116
|
-
item.percent =
|
|
117
|
-
}
|
|
118
|
-
emit("change", {
|
|
119
|
-
file: Object.assign(item, { response: xhr.responseText }),
|
|
120
|
-
fileList: defaultFileList.value,
|
|
121
|
-
event,
|
|
122
|
-
});
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
xhr.onload = (event) => {
|
|
126
|
-
if (xhr.status != 200) {
|
|
127
|
-
item.status = "error";
|
|
128
|
-
delete uploadTemp[item.uid];
|
|
129
|
-
|
|
130
|
-
emit("change", {
|
|
131
|
-
file: Object.assign(item, { response: xhr.responseText }),
|
|
132
|
-
fileList: defaultFileList.value,
|
|
133
|
-
event: event,
|
|
134
|
-
});
|
|
242
|
+
// 直接修改响应式对象,Vue 会自动更新 UI
|
|
243
|
+
item.percent = (event.loaded / event.total) * 100;
|
|
135
244
|
}
|
|
136
245
|
};
|
|
137
246
|
|
|
138
|
-
|
|
247
|
+
const handleError = () => {
|
|
139
248
|
item.status = "error";
|
|
140
249
|
delete uploadTemp[item.uid];
|
|
141
|
-
|
|
142
|
-
emit("change", {
|
|
143
|
-
file: Object.assign(item, { response: xhr.responseText }),
|
|
144
|
-
fileList: defaultFileList.value,
|
|
145
|
-
event: event,
|
|
146
|
-
});
|
|
250
|
+
triggerUpdate(item);
|
|
147
251
|
};
|
|
148
252
|
|
|
149
|
-
|
|
253
|
+
xhr.onerror = handleError;
|
|
150
254
|
xhr.send(formdata);
|
|
151
255
|
};
|
|
152
256
|
|
|
153
257
|
expose({ upload });
|
|
154
258
|
|
|
155
259
|
return () => {
|
|
156
|
-
|
|
260
|
+
const {
|
|
157
261
|
type,
|
|
158
262
|
showUploadList,
|
|
159
263
|
uploadIcon,
|
|
@@ -166,26 +270,9 @@ const Upload = defineComponent({
|
|
|
166
270
|
uploadSubText,
|
|
167
271
|
draggable,
|
|
168
272
|
disabled,
|
|
169
|
-
minSize,
|
|
170
|
-
maxSize,
|
|
171
|
-
autoTrigger,
|
|
172
273
|
} = props;
|
|
173
274
|
|
|
174
|
-
|
|
175
|
-
if (uploadIcon === undefined) {
|
|
176
|
-
uploadIcon = Add;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
const propsData = {
|
|
180
|
-
class: [
|
|
181
|
-
"k-upload",
|
|
182
|
-
{
|
|
183
|
-
["k-upload-disabled"]: disabled,
|
|
184
|
-
["k-upload-picture"]: isPicture,
|
|
185
|
-
["k-upload-drag"]: draggable,
|
|
186
|
-
},
|
|
187
|
-
],
|
|
188
|
-
};
|
|
275
|
+
const isPicture = type === "picture";
|
|
189
276
|
|
|
190
277
|
const selectorProps = {
|
|
191
278
|
props: {
|
|
@@ -199,32 +286,11 @@ const Upload = defineComponent({
|
|
|
199
286
|
uploadText,
|
|
200
287
|
uploadSubText,
|
|
201
288
|
draggable,
|
|
202
|
-
fileList:
|
|
289
|
+
fileList: innerFileList.value,
|
|
203
290
|
uploadIcon,
|
|
204
|
-
|
|
205
|
-
maxSize,
|
|
206
|
-
autoTrigger,
|
|
207
|
-
},
|
|
208
|
-
on: {
|
|
209
|
-
upload: ({ item, file }) => {
|
|
210
|
-
uploadFile(item, file);
|
|
211
|
-
},
|
|
212
|
-
select: ({ item, file }) => {
|
|
213
|
-
uploadTemp[item.uid] = file;
|
|
214
|
-
},
|
|
215
|
-
exceed: (data) => {
|
|
216
|
-
emit("exceed", data);
|
|
217
|
-
},
|
|
218
|
-
"before-upload": (data) => {
|
|
219
|
-
emit("before-upload", data);
|
|
220
|
-
},
|
|
221
|
-
change: (data) => {
|
|
222
|
-
emit("change", data);
|
|
223
|
-
},
|
|
224
|
-
"size-error": (data) => {
|
|
225
|
-
emit("size-error", data);
|
|
226
|
-
},
|
|
291
|
+
locale: locale.value,
|
|
227
292
|
},
|
|
293
|
+
on: { select: onSelectFiles },
|
|
228
294
|
};
|
|
229
295
|
const SelectorNode = (
|
|
230
296
|
<Selector
|
|
@@ -235,17 +301,14 @@ const Upload = defineComponent({
|
|
|
235
301
|
const fileListProps = {
|
|
236
302
|
props: {
|
|
237
303
|
type,
|
|
238
|
-
fileList:
|
|
304
|
+
fileList: innerFileList.value,
|
|
239
305
|
showUploadList,
|
|
240
306
|
disabled,
|
|
307
|
+
locale: locale.value,
|
|
241
308
|
},
|
|
242
|
-
on: {
|
|
243
|
-
remove: (data) => {
|
|
244
|
-
delete uploadTemp[data.file.uid];
|
|
245
|
-
emit("remove", data);
|
|
246
|
-
},
|
|
247
|
-
},
|
|
309
|
+
on: { remove: handleRemove },
|
|
248
310
|
};
|
|
311
|
+
// console.log(innerFileList.value, 222);
|
|
249
312
|
const FileListNode = (
|
|
250
313
|
<FileList
|
|
251
314
|
{...fileListProps}
|
|
@@ -253,7 +316,16 @@ const Upload = defineComponent({
|
|
|
253
316
|
/>
|
|
254
317
|
);
|
|
255
318
|
return (
|
|
256
|
-
<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
|
+
>
|
|
257
329
|
{!isPicture ? [SelectorNode, FileListNode] : FileListNode}
|
|
258
330
|
</div>
|
|
259
331
|
);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import Big from "big.js";
|
|
1
2
|
export function isEmpty(value) {
|
|
2
3
|
return (
|
|
3
4
|
value == null || // null 或 undefined
|
|
@@ -9,74 +10,87 @@ export function isEmpty(value) {
|
|
|
9
10
|
);
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (!/e/i.test(str)) return num;
|
|
22
|
-
return Number(num)
|
|
23
|
-
.toFixed(20)
|
|
24
|
-
.replace(/\.?0+$/, "")
|
|
25
|
-
}
|
|
26
|
-
// console.log(toDecimalString(1e3-10))
|
|
13
|
+
export const isRealNum = (val) => {
|
|
14
|
+
if (val === null || val === "" || Array.isArray(val)) return false;
|
|
15
|
+
try {
|
|
16
|
+
new Big(val);
|
|
17
|
+
return true;
|
|
18
|
+
} catch (e) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
27
22
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
return
|
|
32
|
-
}
|
|
23
|
+
export const normalize = (val, precision) => {
|
|
24
|
+
if (!isRealNum(val)) return "";
|
|
25
|
+
const b = new Big(val);
|
|
26
|
+
return precision !== undefined ? b.toFixed(precision) : b.toFixed();
|
|
27
|
+
};
|
|
33
28
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const aStr = toDecimalString(a)
|
|
37
|
-
const bStr = toDecimalString(b)
|
|
38
|
-
const maxLen = Math.max(getDecimalLength(aStr), getDecimalLength(bStr));
|
|
39
|
-
const factor = Math.pow(10, maxLen);
|
|
40
|
-
const result =
|
|
41
|
-
(Math.round(Number(aStr) * factor) + Math.round(Number(bStr) * factor)) /
|
|
42
|
-
factor;
|
|
43
|
-
return formatSmart(result);
|
|
44
|
-
}
|
|
45
|
-
// 判断结果是否为科学计数法
|
|
46
|
-
export function isScientificNotation(num) {
|
|
47
|
-
return /e/i.test(String(num));
|
|
48
|
-
}
|
|
49
|
-
// 智能格式化结果
|
|
50
|
-
function formatSmart(num) {
|
|
51
|
-
return isScientificNotation(num) ? toDecimalString(num) : num;
|
|
52
|
-
}
|
|
53
|
-
// 减法
|
|
54
|
-
export function subtract(a, b) {
|
|
55
|
-
const aStr = toDecimalString(a);
|
|
56
|
-
const bStr = toDecimalString(b);
|
|
57
|
-
const maxLen = Math.max(getDecimalLength(aStr), getDecimalLength(bStr));
|
|
58
|
-
const factor = Math.pow(10, maxLen);
|
|
59
|
-
const result =
|
|
60
|
-
(Math.round(Number(aStr) * factor) - Math.round(Number(bStr) * factor)) /
|
|
61
|
-
factor;
|
|
62
|
-
return formatSmart(result);
|
|
63
|
-
}
|
|
29
|
+
export const isValidBig = (val) => {
|
|
30
|
+
if (val === null || val === undefined || val === "") return false;
|
|
64
31
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const aStr = toDecimalString(a);
|
|
68
|
-
const bStr = toDecimalString(b);
|
|
69
|
-
const totalLen = getDecimalLength(aStr) + getDecimalLength(bStr);
|
|
70
|
-
const intA = Number(String(aStr).replace(".", ""));
|
|
71
|
-
const intB = Number(String(bStr).replace(".", ""));
|
|
72
|
-
const result = (intA * intB) / Math.pow(10, totalLen);
|
|
73
|
-
return formatSmart(result);
|
|
74
|
-
}
|
|
32
|
+
const str = String(val).trim();
|
|
33
|
+
if (str === "-" || str === "." || str === "-.") return false;
|
|
75
34
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
35
|
+
try {
|
|
36
|
+
new Big(str);
|
|
37
|
+
return true;
|
|
38
|
+
} catch (e) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const toBigSafe = (val, name) => {
|
|
44
|
+
try {
|
|
45
|
+
if (val === null || val === undefined || val === "") {
|
|
46
|
+
throw new Error();
|
|
47
|
+
}
|
|
48
|
+
return new Big(val);
|
|
49
|
+
} catch (e) {
|
|
50
|
+
// console.error(`Slider Error: [${name}] is an invalid number:`, val);
|
|
51
|
+
return new Big(0); // 降级处理
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const getClosestStep = (val, { min, max, step, marks }) => {
|
|
56
|
+
const bMin = toBigSafe(min);
|
|
57
|
+
const bMax = toBigSafe(max);
|
|
58
|
+
const bVal = toBigSafe(val);
|
|
59
|
+
|
|
60
|
+
const markValues = marks ? Object.keys(marks).map(Number) : [];
|
|
61
|
+
|
|
62
|
+
// 如果 step 为 null,强制吸附到最近的 mark 点
|
|
63
|
+
if (step === null || step === undefined) {
|
|
64
|
+
if (markValues.length > 0) {
|
|
65
|
+
// 在 marks 数组中寻找绝对值差最小的点
|
|
66
|
+
const closestMark = markValues.reduce((prev, curr) => {
|
|
67
|
+
return Math.abs(curr - val) < Math.abs(prev - val) ? curr : prev;
|
|
68
|
+
});
|
|
69
|
+
return closestMark;
|
|
70
|
+
}
|
|
71
|
+
// 如果既没有 step 也没有 marks,则不做吸附,直接返回经边界约束的值
|
|
72
|
+
const clampedVal = bVal.gt(bMax) ? bMax : bVal.lt(bMin) ? bMin : bVal;
|
|
73
|
+
return Number(clampedVal.toFixed());
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// 存在步长 step
|
|
77
|
+
const bStep = toBigSafe(step || 1);
|
|
78
|
+
const diff = bVal.minus(bMin);
|
|
79
|
+
const stepCount = Math.round(Number(diff.div(bStep)));
|
|
80
|
+
let closest = bMin.plus(bStep.times(stepCount));
|
|
81
|
+
|
|
82
|
+
// 同时对比 step 点和 marks 点,谁近取谁
|
|
83
|
+
if (markValues.length > 0) {
|
|
84
|
+
markValues.forEach((m) => {
|
|
85
|
+
if (Math.abs(m - val) < Math.abs(Number(closest.minus(val)))) {
|
|
86
|
+
closest = new Big(m);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
80
90
|
|
|
81
|
-
|
|
91
|
+
// 边界约束
|
|
92
|
+
if (closest.gt(bMax)) return Number(bMax.toFixed());
|
|
93
|
+
if (closest.lt(bMin)) return Number(bMin.toFixed());
|
|
82
94
|
|
|
95
|
+
return Number(closest.toFixed());
|
|
96
|
+
};
|