vue-devui 1.0.0-beta.10 → 1.0.0-beta.14
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/README.md +62 -45
- package/accordion/index.es.js +309 -38
- package/accordion/index.umd.js +1 -1
- package/accordion/style.css +1 -1
- package/alert/index.es.js +5 -2
- package/alert/index.umd.js +1 -1
- package/auto-complete/index.d.ts +7 -0
- package/auto-complete/index.es.js +1121 -0
- package/auto-complete/index.umd.js +1 -0
- package/auto-complete/package.json +7 -0
- package/auto-complete/style.css +1 -0
- package/button/index.es.js +213 -8
- package/button/index.umd.js +1 -1
- package/button/style.css +1 -1
- package/color-picker/index.d.ts +7 -0
- package/color-picker/index.es.js +2960 -0
- package/color-picker/index.umd.js +1 -0
- package/color-picker/package.json +7 -0
- package/color-picker/style.css +1 -0
- package/dragdrop/index.es.js +135 -10
- package/dragdrop/index.umd.js +1 -1
- package/drawer/index.es.js +38 -6
- package/drawer/index.umd.js +1 -1
- package/dropdown/index.es.js +30 -22
- package/dropdown/index.umd.js +1 -1
- package/dropdown/style.css +1 -1
- package/editable-select/index.es.js +67 -3
- package/editable-select/index.umd.js +11 -11
- package/form/index.es.js +59 -17
- package/form/index.umd.js +1 -1
- package/gantt/index.es.js +3 -3
- package/gantt/index.umd.js +1 -1
- package/image-preview/index.es.js +33 -15
- package/image-preview/index.umd.js +1 -1
- package/modal/index.es.js +214 -13
- package/modal/index.umd.js +1 -1
- package/modal/style.css +1 -1
- package/nuxt/components/AutoComplete.js +3 -0
- package/nuxt/components/ColorPicker.js +3 -0
- package/nuxt/components/DrawerService.js +3 -0
- package/overlay/index.es.js +1 -1
- package/overlay/index.umd.js +1 -1
- package/package.json +1 -16
- package/popover/index.es.js +13 -4
- package/popover/index.umd.js +1 -1
- package/progress/index.es.js +8 -8
- package/progress/index.umd.js +3 -3
- package/radio/index.es.js +5 -5
- package/radio/index.umd.js +1 -1
- package/slider/index.es.js +2 -5
- package/slider/index.umd.js +1 -1
- package/slider/style.css +1 -1
- package/splitter/index.es.js +191 -14
- package/splitter/index.umd.js +1 -1
- package/splitter/style.css +1 -1
- package/statistic/index.es.js +4 -4
- package/statistic/index.umd.js +1 -1
- package/statistic/style.css +1 -1
- package/style.css +1 -1
- package/table/index.es.js +236 -26
- package/table/index.umd.js +1 -1
- package/table/style.css +1 -1
- package/time-picker/index.es.js +221 -11
- package/time-picker/index.umd.js +1 -1
- package/time-picker/style.css +1 -1
- package/toast/index.es.js +8 -5
- package/toast/index.umd.js +1 -1
- package/toast/style.css +1 -1
- package/transfer/index.es.js +503 -59
- package/transfer/index.umd.js +1 -1
- package/transfer/style.css +1 -1
- package/tree/index.es.js +6 -5
- package/tree/index.umd.js +1 -1
- package/tree-select/index.es.js +129 -34
- package/tree-select/index.umd.js +1 -1
- package/tree-select/style.css +1 -1
- package/upload/index.es.js +165 -507
- package/upload/index.umd.js +1 -1
- package/upload/style.css +1 -1
- package/vue-devui.es.js +16501 -13904
- package/vue-devui.umd.js +19 -19
- package/nuxt/components/MultiUpload.js +0 -3
package/upload/index.es.js
CHANGED
|
@@ -21,7 +21,7 @@ var __publicField = (obj, key, value) => {
|
|
|
21
21
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
22
22
|
return value;
|
|
23
23
|
};
|
|
24
|
-
import { defineComponent, createVNode, getCurrentInstance, ref, computed, watch, nextTick, onUnmounted, mergeProps, createApp, toRefs, withDirectives, resolveComponent,
|
|
24
|
+
import { defineComponent, createVNode, getCurrentInstance, ref, computed, watch, nextTick, onUnmounted, mergeProps, createApp, toRefs, withDirectives, resolveComponent, isVNode, resolveDirective } from "vue";
|
|
25
25
|
var toast = "";
|
|
26
26
|
const toastProps = {
|
|
27
27
|
value: {
|
|
@@ -149,7 +149,7 @@ var ToastImage = defineComponent({
|
|
|
149
149
|
"class": wrapperCls
|
|
150
150
|
}, [showIcon() ? createVNode(Icon, {
|
|
151
151
|
"name": severityIconMap[severity],
|
|
152
|
-
"size": "
|
|
152
|
+
"size": "16px"
|
|
153
153
|
}, null) : null]);
|
|
154
154
|
}
|
|
155
155
|
});
|
|
@@ -1841,19 +1841,22 @@ var Toast = defineComponent({
|
|
|
1841
1841
|
if (props.lifeMode === "single") {
|
|
1842
1842
|
setTimeout(() => {
|
|
1843
1843
|
messages.value.forEach((msg, i) => {
|
|
1844
|
-
timeoutArr[i] = setTimeout(() => singleModeRemove(msg
|
|
1844
|
+
timeoutArr[i] = setTimeout(() => singleModeRemove(msg), msg.life || severityDelay(msg));
|
|
1845
1845
|
});
|
|
1846
1846
|
});
|
|
1847
1847
|
} else {
|
|
1848
1848
|
timeout = setTimeout(() => removeAll(), defaultLife.value);
|
|
1849
1849
|
}
|
|
1850
1850
|
}
|
|
1851
|
-
function singleModeRemove(msg
|
|
1851
|
+
function singleModeRemove(msg) {
|
|
1852
1852
|
removeMsgAnimation(msg);
|
|
1853
1853
|
setTimeout(() => {
|
|
1854
1854
|
onCloseEvent(msg);
|
|
1855
1855
|
if (hasMsgAnimation()) {
|
|
1856
|
-
messages.value.
|
|
1856
|
+
const index2 = messages.value.indexOf(msg);
|
|
1857
|
+
if (index2 !== -1) {
|
|
1858
|
+
messages.value.splice(index2, 1);
|
|
1859
|
+
}
|
|
1857
1860
|
} else {
|
|
1858
1861
|
messages.value = [];
|
|
1859
1862
|
}
|
|
@@ -1913,7 +1916,7 @@ var Toast = defineComponent({
|
|
|
1913
1916
|
if (props.lifeMode === "single") {
|
|
1914
1917
|
const msgLife = msg.life || severityDelay(msg);
|
|
1915
1918
|
const remainTime = msgLife - (Date.now() - timestamp);
|
|
1916
|
-
timeoutArr[i] = setTimeout(() => singleModeRemove(msg
|
|
1919
|
+
timeoutArr[i] = setTimeout(() => singleModeRemove(msg), remainTime);
|
|
1917
1920
|
} else {
|
|
1918
1921
|
resetDelay(() => removeAll());
|
|
1919
1922
|
}
|
|
@@ -2060,13 +2063,20 @@ var UploadStatus;
|
|
|
2060
2063
|
UploadStatus2[UploadStatus2["failed"] = 3] = "failed";
|
|
2061
2064
|
})(UploadStatus || (UploadStatus = {}));
|
|
2062
2065
|
const uploadProps = {
|
|
2066
|
+
accept: {
|
|
2067
|
+
type: String
|
|
2068
|
+
},
|
|
2069
|
+
webkitdirectory: {
|
|
2070
|
+
type: Boolean,
|
|
2071
|
+
default: false
|
|
2072
|
+
},
|
|
2063
2073
|
uploadOptions: {
|
|
2064
2074
|
type: Object,
|
|
2065
2075
|
required: true
|
|
2066
2076
|
},
|
|
2067
|
-
|
|
2068
|
-
type:
|
|
2069
|
-
|
|
2077
|
+
multiple: {
|
|
2078
|
+
type: Boolean,
|
|
2079
|
+
default: false
|
|
2070
2080
|
},
|
|
2071
2081
|
autoUpload: {
|
|
2072
2082
|
type: Boolean,
|
|
@@ -2102,10 +2112,6 @@ const uploadProps = {
|
|
|
2102
2112
|
type: Boolean,
|
|
2103
2113
|
default: false
|
|
2104
2114
|
},
|
|
2105
|
-
showTip: {
|
|
2106
|
-
type: Boolean,
|
|
2107
|
-
default: false
|
|
2108
|
-
},
|
|
2109
2115
|
onChange: {
|
|
2110
2116
|
type: Function
|
|
2111
2117
|
},
|
|
@@ -2121,96 +2127,128 @@ const uploadProps = {
|
|
|
2121
2127
|
type: Function,
|
|
2122
2128
|
default: void 0
|
|
2123
2129
|
},
|
|
2124
|
-
|
|
2130
|
+
deleteUploadedFile: {
|
|
2125
2131
|
type: Function,
|
|
2126
2132
|
default: void 0
|
|
2127
2133
|
},
|
|
2128
|
-
|
|
2134
|
+
"on-error": {
|
|
2129
2135
|
type: Function,
|
|
2130
2136
|
default: void 0
|
|
2131
2137
|
},
|
|
2132
|
-
|
|
2138
|
+
"on-success": {
|
|
2133
2139
|
type: Function,
|
|
2134
2140
|
default: void 0
|
|
2135
|
-
}
|
|
2136
|
-
};
|
|
2137
|
-
const multiUploadProps = {
|
|
2138
|
-
uploadOptions: {
|
|
2139
|
-
type: Object,
|
|
2140
|
-
required: true
|
|
2141
|
-
},
|
|
2142
|
-
fileOptions: {
|
|
2143
|
-
type: Object,
|
|
2144
|
-
required: true
|
|
2145
|
-
},
|
|
2146
|
-
autoUpload: {
|
|
2147
|
-
type: Boolean,
|
|
2148
|
-
default: false
|
|
2149
|
-
},
|
|
2150
|
-
withoutBtn: {
|
|
2151
|
-
type: Boolean,
|
|
2152
|
-
default: false
|
|
2153
|
-
},
|
|
2154
|
-
showTip: {
|
|
2155
|
-
type: Boolean,
|
|
2156
|
-
default: false
|
|
2157
|
-
},
|
|
2158
|
-
uploadedFiles: {
|
|
2159
|
-
type: Array,
|
|
2160
|
-
default: () => []
|
|
2161
|
-
},
|
|
2162
|
-
enableDrop: {
|
|
2163
|
-
type: Boolean,
|
|
2164
|
-
default: false
|
|
2165
|
-
},
|
|
2166
|
-
placeholderText: {
|
|
2167
|
-
type: String,
|
|
2168
|
-
default: "\u9009\u62E9\u6587\u4EF6"
|
|
2169
|
-
},
|
|
2170
|
-
uploadText: {
|
|
2171
|
-
type: String,
|
|
2172
|
-
default: "\u4E0A\u4F20"
|
|
2173
2141
|
},
|
|
2174
2142
|
oneTimeUpload: {
|
|
2175
2143
|
type: Boolean,
|
|
2176
2144
|
default: false
|
|
2177
|
-
},
|
|
2178
|
-
disabled: {
|
|
2179
|
-
type: Boolean,
|
|
2180
|
-
default: false
|
|
2181
|
-
},
|
|
2182
|
-
beforeUpload: {
|
|
2183
|
-
type: Function
|
|
2184
|
-
},
|
|
2185
|
-
fileDrop: {
|
|
2186
|
-
type: Function,
|
|
2187
|
-
default: void 0
|
|
2188
|
-
},
|
|
2189
|
-
fileOver: {
|
|
2190
|
-
type: Function,
|
|
2191
|
-
default: void 0
|
|
2192
|
-
},
|
|
2193
|
-
fileSelect: {
|
|
2194
|
-
type: Function,
|
|
2195
|
-
default: void 0
|
|
2196
|
-
},
|
|
2197
|
-
errorEvent: {
|
|
2198
|
-
type: Function,
|
|
2199
|
-
default: void 0
|
|
2200
|
-
},
|
|
2201
|
-
successEvent: {
|
|
2202
|
-
type: Function,
|
|
2203
|
-
default: void 0
|
|
2204
|
-
},
|
|
2205
|
-
deleteUploadedFileEvent: {
|
|
2206
|
-
type: Function,
|
|
2207
|
-
default: void 0
|
|
2208
|
-
},
|
|
2209
|
-
setCustomUploadOptions: {
|
|
2210
|
-
type: Function,
|
|
2211
|
-
default: void 0
|
|
2212
2145
|
}
|
|
2213
2146
|
};
|
|
2147
|
+
const getFailedFilesCount = (failedCount) => `${failedCount}\u4E2A\u6587\u4EF6\u4E0A\u4F20\u5931\u8D25\uFF01`;
|
|
2148
|
+
const getUploadingFilesCount = (uploadingCount, filesCount) => `${uploadingCount}/${filesCount}\u6B63\u5728\u4E0A\u4F20`;
|
|
2149
|
+
const getSelectedFilesCount = (filesCount) => `\u5DF2\u6DFB\u52A0${filesCount}\u4E2A\u6587\u4EF6`;
|
|
2150
|
+
const getAllFilesBeyondMaximalFileSizeMsg = (maximalSize) => `\u6700\u5927\u652F\u6301\u4E0A\u4F20${maximalSize}MB\u7684\u6587\u4EF6, \u60A8\u672C\u6B21\u4E0A\u4F20\u7684\u6240\u6709\u6587\u4EF6\u8D85\u8FC7\u53EF\u4E0A\u4F20\u6587\u4EF6\u5927\u5C0F`;
|
|
2151
|
+
const getBeyondMaximalFileSizeMsg = (filename, maximalSize) => {
|
|
2152
|
+
return `\u6700\u5927\u652F\u6301\u4E0A\u4F20${maximalSize}MB\u7684\u6587\u4EF6, \u60A8\u4E0A\u4F20\u7684\u6587\u4EF6"${filename}"\u8D85\u8FC7\u53EF\u4E0A\u4F20\u6587\u4EF6\u5927\u5C0F`;
|
|
2153
|
+
};
|
|
2154
|
+
const getNotAllowedFileTypeMsg = (filename, scope) => {
|
|
2155
|
+
return `\u652F\u6301\u7684\u6587\u4EF6\u7C7B\u578B: "${scope}", \u60A8\u4E0A\u4F20\u7684\u6587\u4EF6"${filename}"\u4E0D\u5728\u5141\u8BB8\u8303\u56F4\u5185\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9\u6587\u4EF6`;
|
|
2156
|
+
};
|
|
2157
|
+
const getExistSameNameFilesMsg = (sameNames) => {
|
|
2158
|
+
return `\u60A8\u4E0A\u4F20\u7684 "${sameNames}" \u5B58\u5728\u91CD\u540D\u6587\u4EF6, \u8BF7\u91CD\u65B0\u9009\u62E9\u6587\u4EF6`;
|
|
2159
|
+
};
|
|
2160
|
+
const useSelectFiles = () => {
|
|
2161
|
+
const BEYOND_MAXIMAL_FILE_SIZE_MSG = ref("");
|
|
2162
|
+
const simulateClickEvent = (input) => {
|
|
2163
|
+
const evt = document.createEvent("MouseEvents");
|
|
2164
|
+
evt.initMouseEvent("click", true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
|
|
2165
|
+
input.dispatchEvent(evt);
|
|
2166
|
+
};
|
|
2167
|
+
const selectFiles = ({ multiple, accept, webkitdirectory }) => {
|
|
2168
|
+
return new Promise((resolve) => {
|
|
2169
|
+
const tempNode = document.getElementById("d-upload-temp");
|
|
2170
|
+
if (tempNode) {
|
|
2171
|
+
document.body.removeChild(tempNode);
|
|
2172
|
+
}
|
|
2173
|
+
const input = document.createElement("input");
|
|
2174
|
+
input.style.position = "fixed";
|
|
2175
|
+
input.style.left = "-2000px";
|
|
2176
|
+
input.style.top = "-2000px";
|
|
2177
|
+
input.setAttribute("id", "d-upload-temp");
|
|
2178
|
+
input.setAttribute("type", "file");
|
|
2179
|
+
if (multiple) {
|
|
2180
|
+
input.setAttribute("multiple", "");
|
|
2181
|
+
}
|
|
2182
|
+
if (accept) {
|
|
2183
|
+
input.setAttribute("accept", accept);
|
|
2184
|
+
}
|
|
2185
|
+
if (webkitdirectory) {
|
|
2186
|
+
input.setAttribute("webkitdirectory", "");
|
|
2187
|
+
}
|
|
2188
|
+
input.addEventListener("change", (event) => {
|
|
2189
|
+
resolve(Array.prototype.slice.call(event.target.files));
|
|
2190
|
+
});
|
|
2191
|
+
document.body.appendChild(input);
|
|
2192
|
+
simulateClickEvent(input);
|
|
2193
|
+
});
|
|
2194
|
+
};
|
|
2195
|
+
const isAllowedFileType = (accept, file) => {
|
|
2196
|
+
if (accept) {
|
|
2197
|
+
const acceptArr = accept.split(",");
|
|
2198
|
+
const baseMimeType = file.type.replace(/\/.*$/, "");
|
|
2199
|
+
return acceptArr.some((type) => {
|
|
2200
|
+
const validType = type.trim();
|
|
2201
|
+
if (validType.startsWith(".")) {
|
|
2202
|
+
return file.name.toLowerCase().indexOf(validType.toLowerCase(), file.name.toLowerCase().length - validType.toLowerCase().length) > -1;
|
|
2203
|
+
} else if (/\/\*$/.test(validType)) {
|
|
2204
|
+
return baseMimeType === validType.replace(/\/.*$/, "");
|
|
2205
|
+
}
|
|
2206
|
+
return file.type === validType;
|
|
2207
|
+
});
|
|
2208
|
+
}
|
|
2209
|
+
return true;
|
|
2210
|
+
};
|
|
2211
|
+
const beyondMaximalSize = (fileSize, maximumSize) => {
|
|
2212
|
+
if (maximumSize) {
|
|
2213
|
+
return fileSize > 1024 * 1024 * maximumSize;
|
|
2214
|
+
}
|
|
2215
|
+
return false;
|
|
2216
|
+
};
|
|
2217
|
+
const _validateFiles = (file, accept, uploadOptions) => {
|
|
2218
|
+
if (!isAllowedFileType(accept, file)) {
|
|
2219
|
+
return {
|
|
2220
|
+
checkError: true,
|
|
2221
|
+
errorMsg: getNotAllowedFileTypeMsg(file.name, accept)
|
|
2222
|
+
};
|
|
2223
|
+
}
|
|
2224
|
+
if (uploadOptions && beyondMaximalSize(file.size, uploadOptions.maximumSize)) {
|
|
2225
|
+
return {
|
|
2226
|
+
checkError: true,
|
|
2227
|
+
errorMsg: getBeyondMaximalFileSizeMsg(file.name, uploadOptions.maximumSize)
|
|
2228
|
+
};
|
|
2229
|
+
}
|
|
2230
|
+
return { checkError: false, errorMsg: void 0 };
|
|
2231
|
+
};
|
|
2232
|
+
const triggerSelectFiles = (fileOptions) => {
|
|
2233
|
+
const { multiple, accept, webkitdirectory } = fileOptions;
|
|
2234
|
+
return selectFiles({ multiple, accept, webkitdirectory });
|
|
2235
|
+
};
|
|
2236
|
+
const triggerDropFiles = (files) => {
|
|
2237
|
+
return Promise.resolve(files);
|
|
2238
|
+
};
|
|
2239
|
+
const checkAllFilesSize = (fileSize, maximumSize) => {
|
|
2240
|
+
if (beyondMaximalSize(fileSize, maximumSize)) {
|
|
2241
|
+
BEYOND_MAXIMAL_FILE_SIZE_MSG.value = getAllFilesBeyondMaximalFileSizeMsg(maximumSize);
|
|
2242
|
+
return { checkError: true, errorMsg: BEYOND_MAXIMAL_FILE_SIZE_MSG.value };
|
|
2243
|
+
}
|
|
2244
|
+
};
|
|
2245
|
+
return {
|
|
2246
|
+
triggerSelectFiles,
|
|
2247
|
+
_validateFiles,
|
|
2248
|
+
triggerDropFiles,
|
|
2249
|
+
checkAllFilesSize
|
|
2250
|
+
};
|
|
2251
|
+
};
|
|
2214
2252
|
class FileUploader {
|
|
2215
2253
|
constructor(file, uploadOptions) {
|
|
2216
2254
|
__publicField(this, "xhr");
|
|
@@ -2412,402 +2450,17 @@ const useUpload = () => {
|
|
|
2412
2450
|
_oneTimeUpload
|
|
2413
2451
|
};
|
|
2414
2452
|
};
|
|
2415
|
-
const i18nText = {
|
|
2416
|
-
warning: "\u63D0\u9192",
|
|
2417
|
-
upload: "\u4E0A\u4F20",
|
|
2418
|
-
chooseFile: "\u9009\u62E9\u6587\u4EF6",
|
|
2419
|
-
chooseFiles: "\u9009\u62E9\u591A\u4E2A\u6587\u4EF6",
|
|
2420
|
-
preload: "\u9884\u52A0\u8F7D",
|
|
2421
|
-
uploading: "\u4E0A\u4F20\u4E2D...",
|
|
2422
|
-
uploaded: "\u5DF2\u4E0A\u4F20",
|
|
2423
|
-
uploadFailed: "\u4E0A\u4F20\u5931\u8D25",
|
|
2424
|
-
uploadSuccess: "\u4E0A\u4F20\u6210\u529F!",
|
|
2425
|
-
delete: "\u5220\u9664",
|
|
2426
|
-
reUpload: "\u91CD\u65B0\u4E0A\u4F20",
|
|
2427
|
-
cancelUpload: "\u53D6\u6D88\u4E0A\u4F20"
|
|
2428
|
-
};
|
|
2429
|
-
const getFailedFilesCount = (failedCount) => `${failedCount}\u4E2A\u6587\u4EF6\u4E0A\u4F20\u5931\u8D25\uFF01`;
|
|
2430
|
-
const getUploadingFilesCount = (uploadingCount, filesCount) => `${uploadingCount}/${filesCount}\u6B63\u5728\u4E0A\u4F20`;
|
|
2431
|
-
const getSelectedFilesCount = (filesCount) => `\u5DF2\u6DFB\u52A0${filesCount}\u4E2A\u6587\u4EF6`;
|
|
2432
|
-
const getAllFilesBeyondMaximalFileSizeMsg = (maximalSize) => `\u6700\u5927\u652F\u6301\u4E0A\u4F20${maximalSize}MB\u7684\u6587\u4EF6, \u60A8\u672C\u6B21\u4E0A\u4F20\u7684\u6240\u6709\u6587\u4EF6\u8D85\u8FC7\u53EF\u4E0A\u4F20\u6587\u4EF6\u5927\u5C0F`;
|
|
2433
|
-
const getBeyondMaximalFileSizeMsg = (filename, maximalSize) => {
|
|
2434
|
-
return `\u6700\u5927\u652F\u6301\u4E0A\u4F20${maximalSize}MB\u7684\u6587\u4EF6, \u60A8\u4E0A\u4F20\u7684\u6587\u4EF6"${filename}"\u8D85\u8FC7\u53EF\u4E0A\u4F20\u6587\u4EF6\u5927\u5C0F`;
|
|
2435
|
-
};
|
|
2436
|
-
const getNotAllowedFileTypeMsg = (filename, scope) => {
|
|
2437
|
-
return `\u652F\u6301\u7684\u6587\u4EF6\u7C7B\u578B: "${scope}", \u60A8\u4E0A\u4F20\u7684\u6587\u4EF6"${filename}"\u4E0D\u5728\u5141\u8BB8\u8303\u56F4\u5185\uFF0C\u8BF7\u91CD\u65B0\u9009\u62E9\u6587\u4EF6`;
|
|
2438
|
-
};
|
|
2439
|
-
const getExistSameNameFilesMsg = (sameNames) => {
|
|
2440
|
-
return `\u60A8\u4E0A\u4F20\u7684 "${sameNames}" \u5B58\u5728\u91CD\u540D\u6587\u4EF6, \u8BF7\u91CD\u65B0\u9009\u62E9\u6587\u4EF6`;
|
|
2441
|
-
};
|
|
2442
|
-
const useSelectFiles = () => {
|
|
2443
|
-
const BEYOND_MAXIMAL_FILE_SIZE_MSG = ref("");
|
|
2444
|
-
const simulateClickEvent = (input) => {
|
|
2445
|
-
const evt = document.createEvent("MouseEvents");
|
|
2446
|
-
evt.initMouseEvent("click", true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
|
|
2447
|
-
input.dispatchEvent(evt);
|
|
2448
|
-
};
|
|
2449
|
-
const selectFiles = ({
|
|
2450
|
-
multiple,
|
|
2451
|
-
accept,
|
|
2452
|
-
webkitdirectory
|
|
2453
|
-
}) => {
|
|
2454
|
-
return new Promise((resolve) => {
|
|
2455
|
-
const tempNode = document.getElementById("d-upload-temp");
|
|
2456
|
-
if (tempNode) {
|
|
2457
|
-
document.body.removeChild(tempNode);
|
|
2458
|
-
}
|
|
2459
|
-
const input = document.createElement("input");
|
|
2460
|
-
input.style.position = "fixed";
|
|
2461
|
-
input.style.left = "-2000px";
|
|
2462
|
-
input.style.top = "-2000px";
|
|
2463
|
-
input.setAttribute("id", "d-upload-temp");
|
|
2464
|
-
input.setAttribute("type", "file");
|
|
2465
|
-
if (multiple) {
|
|
2466
|
-
input.setAttribute("multiple", "");
|
|
2467
|
-
}
|
|
2468
|
-
if (accept) {
|
|
2469
|
-
input.setAttribute("accept", accept);
|
|
2470
|
-
}
|
|
2471
|
-
if (webkitdirectory) {
|
|
2472
|
-
input.setAttribute("webkitdirectory", "");
|
|
2473
|
-
}
|
|
2474
|
-
input.addEventListener("change", (event) => {
|
|
2475
|
-
resolve(Array.prototype.slice.call(event.target.files));
|
|
2476
|
-
});
|
|
2477
|
-
document.body.appendChild(input);
|
|
2478
|
-
simulateClickEvent(input);
|
|
2479
|
-
});
|
|
2480
|
-
};
|
|
2481
|
-
const isAllowedFileType = (accept, file) => {
|
|
2482
|
-
if (accept) {
|
|
2483
|
-
const acceptArr = accept.split(",");
|
|
2484
|
-
const baseMimeType = file.type.replace(/\/.*$/, "");
|
|
2485
|
-
return acceptArr.some((type) => {
|
|
2486
|
-
const validType = type.trim();
|
|
2487
|
-
if (validType.startsWith(".")) {
|
|
2488
|
-
return file.name.toLowerCase().indexOf(validType.toLowerCase(), file.name.toLowerCase().length - validType.toLowerCase().length) > -1;
|
|
2489
|
-
} else if (/\/\*$/.test(validType)) {
|
|
2490
|
-
return baseMimeType === validType.replace(/\/.*$/, "");
|
|
2491
|
-
}
|
|
2492
|
-
return file.type === validType;
|
|
2493
|
-
});
|
|
2494
|
-
}
|
|
2495
|
-
return true;
|
|
2496
|
-
};
|
|
2497
|
-
const beyondMaximalSize = (fileSize, maximumSize) => {
|
|
2498
|
-
if (maximumSize) {
|
|
2499
|
-
return fileSize > 1024 * 1024 * maximumSize;
|
|
2500
|
-
}
|
|
2501
|
-
return false;
|
|
2502
|
-
};
|
|
2503
|
-
const _validateFiles = (file, accept, uploadOptions) => {
|
|
2504
|
-
if (!isAllowedFileType(accept, file)) {
|
|
2505
|
-
return {
|
|
2506
|
-
checkError: true,
|
|
2507
|
-
errorMsg: getNotAllowedFileTypeMsg(file.name, accept)
|
|
2508
|
-
};
|
|
2509
|
-
}
|
|
2510
|
-
if (uploadOptions && beyondMaximalSize(file.size, uploadOptions.maximumSize)) {
|
|
2511
|
-
return {
|
|
2512
|
-
checkError: true,
|
|
2513
|
-
errorMsg: getBeyondMaximalFileSizeMsg(file.name, uploadOptions.maximumSize)
|
|
2514
|
-
};
|
|
2515
|
-
}
|
|
2516
|
-
return { checkError: false, errorMsg: void 0 };
|
|
2517
|
-
};
|
|
2518
|
-
const triggerSelectFiles = (fileOptions) => {
|
|
2519
|
-
const { multiple, accept, webkitdirectory } = fileOptions;
|
|
2520
|
-
return selectFiles({ multiple, accept, webkitdirectory });
|
|
2521
|
-
};
|
|
2522
|
-
const triggerDropFiles = (files) => {
|
|
2523
|
-
return Promise.resolve(files);
|
|
2524
|
-
};
|
|
2525
|
-
const checkAllFilesSize = (fileSize, maximumSize) => {
|
|
2526
|
-
if (beyondMaximalSize(fileSize, maximumSize)) {
|
|
2527
|
-
BEYOND_MAXIMAL_FILE_SIZE_MSG.value = getAllFilesBeyondMaximalFileSizeMsg(maximumSize);
|
|
2528
|
-
return { checkError: true, errorMsg: BEYOND_MAXIMAL_FILE_SIZE_MSG.value };
|
|
2529
|
-
}
|
|
2530
|
-
};
|
|
2531
|
-
return {
|
|
2532
|
-
triggerSelectFiles,
|
|
2533
|
-
_validateFiles,
|
|
2534
|
-
triggerDropFiles,
|
|
2535
|
-
checkAllFilesSize
|
|
2536
|
-
};
|
|
2537
|
-
};
|
|
2538
2453
|
var upload = "";
|
|
2539
|
-
var Upload = defineComponent({
|
|
2540
|
-
name: "DSingleUpload",
|
|
2541
|
-
props: uploadProps,
|
|
2542
|
-
emits: ["fileDrop", "fileOver", "fileSelect", "successEvent", "errorEvent", "deleteUploadedFileEvent", "update:uploadedFiles"],
|
|
2543
|
-
setup(props, ctx) {
|
|
2544
|
-
const {
|
|
2545
|
-
uploadOptions,
|
|
2546
|
-
fileOptions,
|
|
2547
|
-
placeholderText,
|
|
2548
|
-
autoUpload,
|
|
2549
|
-
withoutBtn,
|
|
2550
|
-
uploadText,
|
|
2551
|
-
disabled,
|
|
2552
|
-
beforeUpload,
|
|
2553
|
-
enableDrop,
|
|
2554
|
-
showTip,
|
|
2555
|
-
uploadedFiles
|
|
2556
|
-
} = toRefs(props);
|
|
2557
|
-
const isDropOVer = ref(false);
|
|
2558
|
-
const {
|
|
2559
|
-
getFiles,
|
|
2560
|
-
fileUploaders,
|
|
2561
|
-
addFile,
|
|
2562
|
-
getFullFiles,
|
|
2563
|
-
deleteFile,
|
|
2564
|
-
upload: upload2,
|
|
2565
|
-
removeFiles
|
|
2566
|
-
} = useUpload();
|
|
2567
|
-
const {
|
|
2568
|
-
triggerSelectFiles,
|
|
2569
|
-
_validateFiles,
|
|
2570
|
-
triggerDropFiles
|
|
2571
|
-
} = useSelectFiles();
|
|
2572
|
-
const filename = computed(() => (getFiles()[0] || {}).name || "");
|
|
2573
|
-
const alertMsg = (errorMsg) => {
|
|
2574
|
-
ToastService.open({
|
|
2575
|
-
value: [{
|
|
2576
|
-
severity: "warn",
|
|
2577
|
-
content: errorMsg
|
|
2578
|
-
}]
|
|
2579
|
-
});
|
|
2580
|
-
};
|
|
2581
|
-
const canUpload = () => {
|
|
2582
|
-
let uploadResult = Promise.resolve(true);
|
|
2583
|
-
if (beforeUpload.value) {
|
|
2584
|
-
const result = beforeUpload.value(getFullFiles()[0] || {});
|
|
2585
|
-
if (typeof result !== "undefined") {
|
|
2586
|
-
if (result.then) {
|
|
2587
|
-
uploadResult = result;
|
|
2588
|
-
} else {
|
|
2589
|
-
uploadResult = Promise.resolve(result);
|
|
2590
|
-
}
|
|
2591
|
-
}
|
|
2592
|
-
}
|
|
2593
|
-
return uploadResult;
|
|
2594
|
-
};
|
|
2595
|
-
const fileUpload = () => {
|
|
2596
|
-
canUpload().then((canUpload2) => {
|
|
2597
|
-
if (!canUpload2) {
|
|
2598
|
-
return;
|
|
2599
|
-
}
|
|
2600
|
-
upload2().then((results) => {
|
|
2601
|
-
ctx.emit("successEvent", results);
|
|
2602
|
-
const newFiles = results.map((result) => result.file);
|
|
2603
|
-
const newUploadedFiles = [...newFiles, ...uploadedFiles.value];
|
|
2604
|
-
ctx.emit("update:uploadedFiles", newUploadedFiles);
|
|
2605
|
-
}).catch((error) => {
|
|
2606
|
-
console.error(error);
|
|
2607
|
-
if (fileUploaders.value[0]) {
|
|
2608
|
-
fileUploaders.value[0].percentage = 0;
|
|
2609
|
-
}
|
|
2610
|
-
ctx.emit("errorEvent", error);
|
|
2611
|
-
});
|
|
2612
|
-
});
|
|
2613
|
-
};
|
|
2614
|
-
const checkValid = () => {
|
|
2615
|
-
fileUploaders.value.forEach((fileUploader) => {
|
|
2616
|
-
const checkResult = _validateFiles(fileUploader.file, fileOptions.value.accept, fileUploader.uploadOptions);
|
|
2617
|
-
if (checkResult.checkError) {
|
|
2618
|
-
deleteFile(fileUploader.file);
|
|
2619
|
-
alertMsg(checkResult.errorMsg);
|
|
2620
|
-
}
|
|
2621
|
-
});
|
|
2622
|
-
};
|
|
2623
|
-
const _dealFiles = (promise) => {
|
|
2624
|
-
promise.then((files) => {
|
|
2625
|
-
var _a;
|
|
2626
|
-
files.forEach((file2) => {
|
|
2627
|
-
removeFiles();
|
|
2628
|
-
addFile(file2, uploadOptions.value);
|
|
2629
|
-
});
|
|
2630
|
-
checkValid();
|
|
2631
|
-
const file = (_a = fileUploaders.value[0]) == null ? void 0 : _a.file;
|
|
2632
|
-
if (props.onChange) {
|
|
2633
|
-
props.onChange(file);
|
|
2634
|
-
}
|
|
2635
|
-
if (file) {
|
|
2636
|
-
ctx.emit("fileSelect", file);
|
|
2637
|
-
}
|
|
2638
|
-
if (autoUpload.value) {
|
|
2639
|
-
fileUpload();
|
|
2640
|
-
}
|
|
2641
|
-
}).catch((error) => {
|
|
2642
|
-
alertMsg(error.message);
|
|
2643
|
-
});
|
|
2644
|
-
};
|
|
2645
|
-
const handleClick = () => {
|
|
2646
|
-
var _a;
|
|
2647
|
-
if (disabled.value || fileUploaders.value[0] && ((_a = fileUploaders.value[0]) == null ? void 0 : _a.status) === UploadStatus.uploading) {
|
|
2648
|
-
return;
|
|
2649
|
-
}
|
|
2650
|
-
_dealFiles(triggerSelectFiles(fileOptions.value));
|
|
2651
|
-
};
|
|
2652
|
-
const onDeleteFile = (event) => {
|
|
2653
|
-
event.stopPropagation();
|
|
2654
|
-
const files = getFiles();
|
|
2655
|
-
deleteFile(files[0]);
|
|
2656
|
-
};
|
|
2657
|
-
const deleteUploadedFile = (file) => {
|
|
2658
|
-
const newUploadedFiles = uploadedFiles.value.filter((uploadedFile) => {
|
|
2659
|
-
return uploadedFile.name !== file.name;
|
|
2660
|
-
});
|
|
2661
|
-
ctx.emit("deleteUploadedFileEvent", file);
|
|
2662
|
-
ctx.emit("update:uploadedFiles", newUploadedFiles);
|
|
2663
|
-
};
|
|
2664
|
-
const onFileDrop = (files) => {
|
|
2665
|
-
isDropOVer.value = false;
|
|
2666
|
-
_dealFiles(triggerDropFiles(files));
|
|
2667
|
-
ctx.emit("fileDrop", files[0]);
|
|
2668
|
-
};
|
|
2669
|
-
const onFileOver = (event) => {
|
|
2670
|
-
isDropOVer.value = event;
|
|
2671
|
-
ctx.emit("fileOver", event);
|
|
2672
|
-
};
|
|
2673
|
-
return {
|
|
2674
|
-
placeholderText,
|
|
2675
|
-
filename,
|
|
2676
|
-
autoUpload,
|
|
2677
|
-
withoutBtn,
|
|
2678
|
-
fileUploaders,
|
|
2679
|
-
uploadText,
|
|
2680
|
-
handleClick,
|
|
2681
|
-
onDeleteFile,
|
|
2682
|
-
fileUpload,
|
|
2683
|
-
enableDrop,
|
|
2684
|
-
onFileDrop,
|
|
2685
|
-
onFileOver,
|
|
2686
|
-
isDropOVer,
|
|
2687
|
-
showTip,
|
|
2688
|
-
uploadedFiles,
|
|
2689
|
-
deleteUploadedFile
|
|
2690
|
-
};
|
|
2691
|
-
},
|
|
2692
|
-
render() {
|
|
2693
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
2694
|
-
const {
|
|
2695
|
-
placeholderText,
|
|
2696
|
-
filename,
|
|
2697
|
-
autoUpload,
|
|
2698
|
-
withoutBtn,
|
|
2699
|
-
fileUploaders,
|
|
2700
|
-
uploadText,
|
|
2701
|
-
handleClick,
|
|
2702
|
-
onDeleteFile,
|
|
2703
|
-
fileUpload,
|
|
2704
|
-
enableDrop,
|
|
2705
|
-
onFileDrop,
|
|
2706
|
-
onFileOver,
|
|
2707
|
-
isDropOVer,
|
|
2708
|
-
disabled,
|
|
2709
|
-
showTip,
|
|
2710
|
-
uploadedFiles,
|
|
2711
|
-
deleteUploadedFile
|
|
2712
|
-
} = this;
|
|
2713
|
-
return createVNode("div", null, [withDirectives(createVNode("div", {
|
|
2714
|
-
"class": "devui-upload",
|
|
2715
|
-
"style": `border: ${isDropOVer ? "1px solid #15bf15" : "0"}`
|
|
2716
|
-
}, [((_b = (_a = this.$slots).default) == null ? void 0 : _b.call(_a)) ? createVNode("div", {
|
|
2717
|
-
"onClick": handleClick
|
|
2718
|
-
}, [this.$slots.default()]) : createVNode("div", {
|
|
2719
|
-
"class": `devui-input-group ${disabled || ((_c = fileUploaders[0]) == null ? void 0 : _c.status) === UploadStatus.uploading ? "disabled" : ""}`,
|
|
2720
|
-
"onClick": handleClick
|
|
2721
|
-
}, [createVNode("div", {
|
|
2722
|
-
"class": "devui-form-control devui-files-list"
|
|
2723
|
-
}, [!filename && createVNode("div", {
|
|
2724
|
-
"class": "devui-file-item devui-upload-placeholder"
|
|
2725
|
-
}, [placeholderText]), !!filename && createVNode("div", {
|
|
2726
|
-
"class": "devui-file-tag devui-file-item",
|
|
2727
|
-
"title": filename,
|
|
2728
|
-
"style": "display: inline-block; margin: 0 2px 2px 0"
|
|
2729
|
-
}, [createVNode("span", {
|
|
2730
|
-
"class": `devui-filename ${((_d = fileUploaders[0]) == null ? void 0 : _d.status) === UploadStatus.failed ? "devui-failed-color" : ""}`
|
|
2731
|
-
}, [filename]), createVNode(resolveComponent("d-icon"), {
|
|
2732
|
-
"name": "close",
|
|
2733
|
-
"class": `${((_e = fileUploaders[0]) == null ? void 0 : _e.status) === UploadStatus.failed ? "devui-upload-delete-file-button" : ""} ${((_f = fileUploaders[0]) == null ? void 0 : _f.status) === UploadStatus.uploading || ((_g = fileUploaders[0]) == null ? void 0 : _g.status) === UploadStatus.uploaded ? "devui-uploading-delete" : ""}`,
|
|
2734
|
-
"onClick": (event) => onDeleteFile(event)
|
|
2735
|
-
}, null), ((_h = fileUploaders[0]) == null ? void 0 : _h.status) === UploadStatus.uploading && createVNode("div", {
|
|
2736
|
-
"class": "icon devui-upload-progress"
|
|
2737
|
-
}, [createVNode(resolveComponent("d-progress"), {
|
|
2738
|
-
"isCircle": true,
|
|
2739
|
-
"percentage": fileUploaders[0].percentage,
|
|
2740
|
-
"barbgcolor": "#50D4AB",
|
|
2741
|
-
"strokeWidth": 8,
|
|
2742
|
-
"showContent": false
|
|
2743
|
-
}, null)]), fileUploaders[0].status === UploadStatus.failed && createVNode(resolveComponent("d-icon"), {
|
|
2744
|
-
"name": "running",
|
|
2745
|
-
"onClick": fileUpload
|
|
2746
|
-
}, null), fileUploaders[0].status === UploadStatus.uploaded && createVNode(resolveComponent("d-icon"), {
|
|
2747
|
-
"name": "right",
|
|
2748
|
-
"color": "#50d4ab"
|
|
2749
|
-
}, null)])]), createVNode("span", {
|
|
2750
|
-
"class": "devui-input-group-addon"
|
|
2751
|
-
}, [createVNode(resolveComponent("d-icon"), {
|
|
2752
|
-
"name": "more-operate",
|
|
2753
|
-
"color": "#252b3a"
|
|
2754
|
-
}, null)])]), !autoUpload && !withoutBtn && createVNode(resolveComponent("d-button"), {
|
|
2755
|
-
"style": "marginLeft: 8px",
|
|
2756
|
-
"bsStyle": "common",
|
|
2757
|
-
"onClick": fileUpload,
|
|
2758
|
-
"disabled": disabled || ((_i = fileUploaders[0]) == null ? void 0 : _i.status) === UploadStatus.uploading
|
|
2759
|
-
}, {
|
|
2760
|
-
default: () => {
|
|
2761
|
-
var _a2, _b2, _c2, _d2;
|
|
2762
|
-
return [(!fileUploaders[0] || !((_a2 = fileUploaders[0]) == null ? void 0 : _a2.status)) && createVNode("span", null, [uploadText]), ((_b2 = fileUploaders[0]) == null ? void 0 : _b2.status) === UploadStatus.uploading && createVNode("span", null, [createTextVNode("\u4E0A\u4F20\u4E2D...")]), ((_c2 = fileUploaders[0]) == null ? void 0 : _c2.status) === UploadStatus.uploaded && createVNode("span", null, [createTextVNode("\u5DF2\u4E0A\u4F20")]), ((_d2 = fileUploaders[0]) == null ? void 0 : _d2.status) === UploadStatus.failed && createVNode("span", null, [createTextVNode("\u4E0A\u4F20\u5931\u8D25")])];
|
|
2763
|
-
}
|
|
2764
|
-
})]), [[resolveDirective("file-drop"), {
|
|
2765
|
-
enableDrop,
|
|
2766
|
-
isSingle: true,
|
|
2767
|
-
onFileDrop,
|
|
2768
|
-
onFileOver
|
|
2769
|
-
}]]), showTip && createVNode("div", {
|
|
2770
|
-
"class": "devui-upload-tip"
|
|
2771
|
-
}, [((_j = fileUploaders[0]) == null ? void 0 : _j.status) === UploadStatus.uploading && createVNode("span", {
|
|
2772
|
-
"class": "devui-loading"
|
|
2773
|
-
}, [i18nText.uploading]), ((_k = fileUploaders[0]) == null ? void 0 : _k.status) === UploadStatus.uploaded && createVNode("div", {
|
|
2774
|
-
"class": "devui-loaded"
|
|
2775
|
-
}, [createVNode(resolveComponent("d-icon"), {
|
|
2776
|
-
"name": "right-o",
|
|
2777
|
-
"color": "#50d4ab"
|
|
2778
|
-
}, null), createVNode("span", {
|
|
2779
|
-
"style": "vertical-align: middle"
|
|
2780
|
-
}, [i18nText.uploadSuccess])]), ((_l = fileUploaders[0]) == null ? void 0 : _l.status) === UploadStatus.failed && createVNode("div", {
|
|
2781
|
-
"class": "devui-upload-failed"
|
|
2782
|
-
}, [createVNode(resolveComponent("d-icon"), {
|
|
2783
|
-
"name": "info-o",
|
|
2784
|
-
"color": "#f66f6a"
|
|
2785
|
-
}, null), createVNode("span", {
|
|
2786
|
-
"style": "vertical-align: middle"
|
|
2787
|
-
}, [createVNode("span", {
|
|
2788
|
-
"style": "margin-right: 8px"
|
|
2789
|
-
}, [i18nText.uploadFailed]), createVNode("a", {
|
|
2790
|
-
"onClick": fileUpload
|
|
2791
|
-
}, [i18nText.reUpload])])])]), createVNode("div", null, [(_n = (_m = this.$slots).preloadFiles) == null ? void 0 : _n.call(_m, {
|
|
2792
|
-
fileUploaders,
|
|
2793
|
-
deleteFile: onDeleteFile
|
|
2794
|
-
})]), createVNode("div", null, [(_p = (_o = this.$slots).uploadedFiles) == null ? void 0 : _p.call(_o, {
|
|
2795
|
-
uploadedFiles,
|
|
2796
|
-
deleteFile: deleteUploadedFile
|
|
2797
|
-
})])]);
|
|
2798
|
-
}
|
|
2799
|
-
});
|
|
2800
2454
|
function _isSlot(s) {
|
|
2801
2455
|
return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
|
|
2802
2456
|
}
|
|
2803
|
-
var
|
|
2804
|
-
name: "
|
|
2805
|
-
props:
|
|
2806
|
-
emits: ["fileDrop", "fileOver", "fileSelect", "
|
|
2457
|
+
var Upload = defineComponent({
|
|
2458
|
+
name: "DUpload",
|
|
2459
|
+
props: uploadProps,
|
|
2460
|
+
emits: ["fileDrop", "fileOver", "fileSelect", "deleteUploadedFile", "update:uploadedFiles"],
|
|
2807
2461
|
setup(props, ctx) {
|
|
2808
2462
|
const {
|
|
2809
2463
|
uploadOptions,
|
|
2810
|
-
fileOptions,
|
|
2811
2464
|
placeholderText,
|
|
2812
2465
|
autoUpload,
|
|
2813
2466
|
withoutBtn,
|
|
@@ -2816,8 +2469,10 @@ var MultiUpload = defineComponent({
|
|
|
2816
2469
|
beforeUpload,
|
|
2817
2470
|
enableDrop,
|
|
2818
2471
|
oneTimeUpload,
|
|
2819
|
-
|
|
2820
|
-
|
|
2472
|
+
uploadedFiles,
|
|
2473
|
+
multiple,
|
|
2474
|
+
accept,
|
|
2475
|
+
webkitdirectory
|
|
2821
2476
|
} = toRefs(props);
|
|
2822
2477
|
const {
|
|
2823
2478
|
triggerSelectFiles,
|
|
@@ -2826,7 +2481,6 @@ var MultiUpload = defineComponent({
|
|
|
2826
2481
|
checkAllFilesSize
|
|
2827
2482
|
} = useSelectFiles();
|
|
2828
2483
|
const {
|
|
2829
|
-
getFiles,
|
|
2830
2484
|
fileUploaders,
|
|
2831
2485
|
addFile,
|
|
2832
2486
|
getFullFiles,
|
|
@@ -2851,7 +2505,7 @@ var MultiUpload = defineComponent({
|
|
|
2851
2505
|
let totalFileSize = 0;
|
|
2852
2506
|
fileUploaders.value.forEach((fileUploader) => {
|
|
2853
2507
|
totalFileSize += fileUploader.file.size;
|
|
2854
|
-
const checkResult = _validateFiles(fileUploader.file,
|
|
2508
|
+
const checkResult = _validateFiles(fileUploader.file, accept.value, fileUploader.uploadOptions);
|
|
2855
2509
|
if (checkResult && checkResult.checkError) {
|
|
2856
2510
|
deleteFile(fileUploader.file);
|
|
2857
2511
|
alertMsg(checkResult.errorMsg);
|
|
@@ -2870,6 +2524,9 @@ var MultiUpload = defineComponent({
|
|
|
2870
2524
|
resetSameNameFiles();
|
|
2871
2525
|
promise.then((files) => {
|
|
2872
2526
|
files.forEach((file) => {
|
|
2527
|
+
if (!multiple.value) {
|
|
2528
|
+
removeFiles();
|
|
2529
|
+
}
|
|
2873
2530
|
addFile(file, uploadOptions.value);
|
|
2874
2531
|
});
|
|
2875
2532
|
checkValid();
|
|
@@ -2880,7 +2537,7 @@ var MultiUpload = defineComponent({
|
|
|
2880
2537
|
const selectedFiles = fileUploaders.value.filter((fileUploader) => fileUploader.status === UploadStatus.preLoad).map((fileUploader) => fileUploader.file);
|
|
2881
2538
|
ctx.emit("fileSelect", selectedFiles);
|
|
2882
2539
|
if (autoUpload.value) {
|
|
2883
|
-
|
|
2540
|
+
fileUpload();
|
|
2884
2541
|
}
|
|
2885
2542
|
}).catch((error) => {
|
|
2886
2543
|
alertMsg(error.message);
|
|
@@ -2890,7 +2547,11 @@ var MultiUpload = defineComponent({
|
|
|
2890
2547
|
if (disabled.value) {
|
|
2891
2548
|
return;
|
|
2892
2549
|
}
|
|
2893
|
-
_dealFiles(triggerSelectFiles(
|
|
2550
|
+
_dealFiles(triggerSelectFiles({
|
|
2551
|
+
accept: accept.value,
|
|
2552
|
+
multiple: multiple.value,
|
|
2553
|
+
webkitdirectory: webkitdirectory.value
|
|
2554
|
+
}));
|
|
2894
2555
|
};
|
|
2895
2556
|
const onFileDrop = (files) => {
|
|
2896
2557
|
isDropOVer.value = false;
|
|
@@ -2901,17 +2562,20 @@ var MultiUpload = defineComponent({
|
|
|
2901
2562
|
isDropOVer.value = event;
|
|
2902
2563
|
ctx.emit("fileOver", event);
|
|
2903
2564
|
};
|
|
2904
|
-
const onDeleteFile = (event, file) => {
|
|
2905
|
-
event.stopPropagation();
|
|
2906
|
-
deleteFile(file);
|
|
2907
|
-
};
|
|
2908
2565
|
const deleteUploadedFile = (file) => {
|
|
2909
2566
|
const newUploadedFiles = uploadedFiles.value.filter((uploadedFile) => {
|
|
2910
2567
|
return uploadedFile.name !== file.name;
|
|
2911
2568
|
});
|
|
2912
|
-
ctx.emit("
|
|
2569
|
+
ctx.emit("deleteUploadedFile", file);
|
|
2913
2570
|
ctx.emit("update:uploadedFiles", newUploadedFiles);
|
|
2914
2571
|
};
|
|
2572
|
+
const onDeleteFile = (event, file, status) => {
|
|
2573
|
+
event.stopPropagation();
|
|
2574
|
+
if (status === UploadStatus.uploaded) {
|
|
2575
|
+
deleteUploadedFile(file);
|
|
2576
|
+
}
|
|
2577
|
+
deleteFile(file);
|
|
2578
|
+
};
|
|
2915
2579
|
const canUpload = () => {
|
|
2916
2580
|
let uploadResult = Promise.resolve(true);
|
|
2917
2581
|
if (beforeUpload.value) {
|
|
@@ -2937,12 +2601,12 @@ var MultiUpload = defineComponent({
|
|
|
2937
2601
|
}
|
|
2938
2602
|
const uploadObservable = oneTimeUpload.value ? _oneTimeUpload() : upload2(fileUploader);
|
|
2939
2603
|
uploadObservable.then((results) => {
|
|
2940
|
-
|
|
2604
|
+
props["on-success"] && props["on-success"](results);
|
|
2941
2605
|
const newFiles = results.map((result) => result.file);
|
|
2942
2606
|
const newUploadedFiles = [...newFiles, ...uploadedFiles.value];
|
|
2943
2607
|
ctx.emit("update:uploadedFiles", newUploadedFiles);
|
|
2944
2608
|
}).catch((error) => {
|
|
2945
|
-
|
|
2609
|
+
props["on-error"] && props["on-error"](error);
|
|
2946
2610
|
});
|
|
2947
2611
|
});
|
|
2948
2612
|
};
|
|
@@ -2987,7 +2651,6 @@ var MultiUpload = defineComponent({
|
|
|
2987
2651
|
};
|
|
2988
2652
|
return {
|
|
2989
2653
|
uploadOptions,
|
|
2990
|
-
fileOptions,
|
|
2991
2654
|
placeholderText,
|
|
2992
2655
|
autoUpload,
|
|
2993
2656
|
withoutBtn,
|
|
@@ -3002,11 +2665,11 @@ var MultiUpload = defineComponent({
|
|
|
3002
2665
|
fileUploaders,
|
|
3003
2666
|
onDeleteFile,
|
|
3004
2667
|
fileUpload,
|
|
3005
|
-
showTip,
|
|
3006
2668
|
getStatus,
|
|
3007
2669
|
uploadTips,
|
|
3008
2670
|
cancelUpload,
|
|
3009
|
-
deleteUploadedFile
|
|
2671
|
+
deleteUploadedFile,
|
|
2672
|
+
multiple
|
|
3010
2673
|
};
|
|
3011
2674
|
},
|
|
3012
2675
|
render() {
|
|
@@ -3017,7 +2680,6 @@ var MultiUpload = defineComponent({
|
|
|
3017
2680
|
withoutBtn,
|
|
3018
2681
|
uploadText,
|
|
3019
2682
|
disabled,
|
|
3020
|
-
beforeUpload,
|
|
3021
2683
|
enableDrop,
|
|
3022
2684
|
isDropOVer,
|
|
3023
2685
|
onFileDrop,
|
|
@@ -3026,14 +2688,11 @@ var MultiUpload = defineComponent({
|
|
|
3026
2688
|
fileUploaders,
|
|
3027
2689
|
onDeleteFile,
|
|
3028
2690
|
fileUpload,
|
|
3029
|
-
showTip,
|
|
3030
|
-
getStatus,
|
|
3031
|
-
uploadTips,
|
|
3032
|
-
cancelUpload,
|
|
3033
2691
|
uploadedFiles,
|
|
3034
|
-
deleteUploadedFile
|
|
2692
|
+
deleteUploadedFile,
|
|
2693
|
+
multiple
|
|
3035
2694
|
} = this;
|
|
3036
|
-
return createVNode(
|
|
2695
|
+
return createVNode("div", null, [withDirectives(createVNode("div", {
|
|
3037
2696
|
"class": "devui-upload",
|
|
3038
2697
|
"style": `border: ${isDropOVer ? "1px solid #15bf15" : "0"}`
|
|
3039
2698
|
}, [((_b = (_a = this.$slots).default) == null ? void 0 : _b.call(_a)) ? createVNode("div", {
|
|
@@ -3055,7 +2714,7 @@ var MultiUpload = defineComponent({
|
|
|
3055
2714
|
}, [fileUploader.file.name]), createVNode(resolveComponent("d-icon"), {
|
|
3056
2715
|
"name": "close",
|
|
3057
2716
|
"class": `${(fileUploader == null ? void 0 : fileUploader.status) === UploadStatus.failed ? "devui-upload-delete-file-button" : ""} ${(fileUploader == null ? void 0 : fileUploader.status) === UploadStatus.uploading || (fileUploader == null ? void 0 : fileUploader.status) === UploadStatus.uploaded ? "devui-uploading-delete" : ""}`,
|
|
3058
|
-
"onClick": (event) => onDeleteFile(event, fileUploader.file)
|
|
2717
|
+
"onClick": (event) => onDeleteFile(event, fileUploader.file, fileUploader.status)
|
|
3059
2718
|
}, null), fileUploader.status === UploadStatus.uploading && createVNode("div", {
|
|
3060
2719
|
"class": "icon devui-upload-progress"
|
|
3061
2720
|
}, [createVNode(resolveComponent("d-progress"), {
|
|
@@ -3077,14 +2736,14 @@ var MultiUpload = defineComponent({
|
|
|
3077
2736
|
"color": "#252b3a"
|
|
3078
2737
|
}, null)])]), !autoUpload && !withoutBtn && createVNode(resolveComponent("d-button"), {
|
|
3079
2738
|
"style": "marginLeft: 8px",
|
|
3080
|
-
"
|
|
2739
|
+
"variant": "common",
|
|
3081
2740
|
"disabled": disabled,
|
|
3082
2741
|
"onClick": fileUpload
|
|
3083
2742
|
}, _isSlot(uploadText) ? uploadText : {
|
|
3084
2743
|
default: () => [uploadText]
|
|
3085
2744
|
})]), [[resolveDirective("file-drop"), {
|
|
3086
2745
|
enableDrop,
|
|
3087
|
-
isSingle:
|
|
2746
|
+
isSingle: !multiple,
|
|
3088
2747
|
onFileDrop,
|
|
3089
2748
|
onFileOver
|
|
3090
2749
|
}]]), createVNode("div", null, [(_d = (_c = this.$slots).preloadFiles) == null ? void 0 : _d.call(_c, {
|
|
@@ -3148,7 +2807,7 @@ const onDrop = (el, binding) => {
|
|
|
3148
2807
|
if (isSingle) {
|
|
3149
2808
|
onFileDrop && onFileDrop([transfer.files[0]]);
|
|
3150
2809
|
} else {
|
|
3151
|
-
onFileDrop && onFileDrop(transfer.files);
|
|
2810
|
+
onFileDrop && onFileDrop(Array.from(transfer.files));
|
|
3152
2811
|
}
|
|
3153
2812
|
});
|
|
3154
2813
|
};
|
|
@@ -3166,7 +2825,6 @@ const fileDropDirective = {
|
|
|
3166
2825
|
Upload.install = function(app) {
|
|
3167
2826
|
app.directive("file-drop", fileDropDirective);
|
|
3168
2827
|
app.component(Upload.name, Upload);
|
|
3169
|
-
app.component(MultiUpload.name, MultiUpload);
|
|
3170
2828
|
};
|
|
3171
2829
|
var index = {
|
|
3172
2830
|
title: "Upload \u4E0A\u4F20",
|
|
@@ -3176,4 +2834,4 @@ var index = {
|
|
|
3176
2834
|
app.use(Upload);
|
|
3177
2835
|
}
|
|
3178
2836
|
};
|
|
3179
|
-
export {
|
|
2837
|
+
export { Upload, index as default };
|