diff --git a/devui/upload/__tests__/upload.spec.ts b/devui/upload/__tests__/upload.spec.ts
new file mode 100644
index 0000000000000000000000000000000000000000..31dcf2239c7aae1b3f7a42a593626cb9b9dedc0f
--- /dev/null
+++ b/devui/upload/__tests__/upload.spec.ts
@@ -0,0 +1,198 @@
+import { mount } from '@vue/test-utils'
+import { ref, nextTick, reactive } from 'vue'
+import DSingleUpload from '../src/single-upload'
+import DMultipleUpload from '../src/multiple-upload'
+const getMockFile = (element: Element, files: File[]): void => {
+ Object.defineProperty(element, 'files', {
+ get() {
+ return files
+ },
+ })
+}
+
+describe('single upload', () => {
+ it('should render correctly', () => {
+ const TestComponent = {
+ components: {
+ 'd-single-upload': DSingleUpload,
+ },
+ template: `
+
+ `,
+ setup() {
+ const fileOptions = reactive({
+ accept: '',
+ multiple: false,
+ webkitdirectory: false,
+ })
+ const uploadOptions = reactive({
+ uri: 'http://localhost:4000/files/upload',
+ })
+ const uploadedFiles = ref([])
+ return {
+ fileOptions,
+ uploadedFiles,
+ uploadOptions,
+ }
+ },
+ }
+ mount(TestComponent)
+ })
+ it('should work with `disabled` prop', () => {
+ const TestComponent = {
+ components: {
+ 'd-single-upload': DSingleUpload,
+ },
+ template: `
+
+ `,
+ setup() {
+ const fileOptions = reactive({
+ accept: '',
+ multiple: false,
+ webkitdirectory: false,
+ })
+ const uploadOptions = reactive({
+ uri: 'http://localhost:4000/files/upload',
+ })
+ const uploadedFiles = ref([])
+ return {
+ fileOptions,
+ uploadedFiles,
+ uploadOptions,
+ }
+ },
+ }
+ const wrapper = mount(TestComponent)
+ expect(wrapper.find('.devui-input-group.disabled').exists()).toBe(true)
+ })
+ it('should work with `before-upload auto-upload withoutBtn` prop', async () => {
+ const beforeUpload = jest.fn(async () => true)
+
+ const TestComponent = {
+ components: {
+ 'd-single-upload': DSingleUpload,
+ },
+ template: `
+
+ `,
+ setup() {
+ const fileOptions = reactive({
+ accept: '',
+ multiple: false,
+ webkitdirectory: false,
+ })
+ const uploadOptions = reactive({
+ uri: 'http://localhost:4000/files/upload',
+ })
+ const uploadedFiles = ref([])
+ return {
+ fileOptions,
+ uploadedFiles,
+ uploadOptions,
+ beforeUpload,
+ }
+ },
+ }
+ const wrapper = mount(TestComponent)
+ const uploadElment = wrapper.find('.devui-input-group')
+ await uploadElment.trigger('click')
+ await nextTick()
+ const input = document.getElementById('d-upload-temp')
+ const fileList = [new File(['test'], 'file.txt')]
+ getMockFile(input, fileList)
+ const evt = new Event('change')
+ await input.dispatchEvent(evt)
+ expect(beforeUpload).toHaveBeenCalled()
+ expect(wrapper.find('.devui-upload button').exists()).toBe(false)
+ })
+ it('should work with `showTip placeholderText uploadText` prop', async () => {
+ const TestComponent = {
+ components: {
+ 'd-single-upload': DSingleUpload,
+ },
+ template: `
+
+ `,
+ setup() {
+ const fileOptions = reactive({
+ accept: '',
+ multiple: false,
+ webkitdirectory: false,
+ })
+ const uploadOptions = reactive({
+ uri: 'http://localhost:4000/files/upload',
+ })
+ const uploadedFiles = ref([])
+ return {
+ fileOptions,
+ uploadedFiles,
+ uploadOptions,
+ }
+ },
+ }
+ const wrapper = mount(TestComponent)
+ expect(wrapper.find('.devui-upload-tip').exists()).toBe(true)
+ expect(wrapper.find('.devui-upload-placeholder').text()).toBe('select file')
+ expect(wrapper.find('.devui-upload button').text()).toBe('upload')
+ })
+})
+
+describe('multi upload', () => {
+ it('should render correctly', () => {
+ const TestComponent = {
+ components: {
+ 'd-multi-upload': DMultipleUpload,
+ },
+ template: `
+
+
+
+ `,
+ setup() {
+ const fileOptions = reactive({
+ accept: '',
+ multiple: true,
+ webkitdirectory: false,
+ })
+ const uploadOptions = reactive({
+ uri: 'http://localhost:4000/files/upload',
+ })
+ const uploadedFiles = ref([])
+ return {
+ fileOptions,
+ uploadedFiles,
+ uploadOptions,
+ }
+ },
+ }
+ mount(TestComponent)
+ })
+})
diff --git a/devui/upload/src/file-drop-directive.ts b/devui/upload/src/file-drop-directive.ts
index eae3e67e741af3225e02ed66703d2d299bb87ca3..e74602f6911ee9ceb94cf7f4269d9acf8a20e72e 100644
--- a/devui/upload/src/file-drop-directive.ts
+++ b/devui/upload/src/file-drop-directive.ts
@@ -10,7 +10,7 @@ interface BindingType {
const getTransfer = (event: any) => {
return event.dataTransfer
? event.dataTransfer
- : event.originalEvent.dataTransfer
+ : event.originalEvent?.dataTransfer
}
const haveFiles = (types: any) => {
diff --git a/devui/upload/src/upload-types.ts b/devui/upload/src/upload-types.ts
index cc5ad91580ad011c1da666b74eb0bd755f5cd25b..1567766aa35c53c34003545ebc17f4299dac26e8 100644
--- a/devui/upload/src/upload-types.ts
+++ b/devui/upload/src/upload-types.ts
@@ -53,10 +53,6 @@ export const uploadProps = {
type: Object as PropType,
required: true,
},
- filePath: {
- type: String,
- required: true,
- },
autoUpload: {
type: Boolean,
default: false,
@@ -134,9 +130,6 @@ export const multiUploadProps = {
type: Object as PropType,
required: true,
},
- filePath: {
- type: String,
- },
autoUpload: {
type: Boolean,
default: false,
diff --git a/docs/components/upload/index.md b/docs/components/upload/index.md
index 6300ab68fb1b8789e32e91a372c6fd051dbe73cb..eddf5a362c6aa8e1f569a0203a92c056b2a897de 100644
--- a/docs/components/upload/index.md
+++ b/docs/components/upload/index.md
@@ -221,7 +221,6 @@ export default {
:file-options="fileOptions"
:upload-options="uploadOptions"
v-model:uploaded-files="uploadedFiles"
- filePath="name"
@success-event="onSuccess"
@error-event="onError"
:showTip="true"
@@ -290,7 +289,6 @@ export default {
:file-options="fileOptions"
:upload-options="uploadOptions"
v-model:uploaded-files="uploadedFiles"
- filePath="name"
@success-event="onSuccess"
@error-event="onError"
:showTip="true"
@@ -358,7 +356,6 @@ export default {
:file-options="fileOptions"
:upload-options="uploadOptions"
v-model:uploaded-files="uploadedFiles"
- filePath="name"
@success-event="onSuccess"
@error-event="onError"
:showTip="true"
@@ -1188,21 +1185,20 @@ export default {
d-single-upload 参数
-| **参数** | **类型** | **默认** | 说明 | **跳转 Demo** |
-| ---------------------- | --------------------------------- | ---------- | ---------------------------------------------------------------------------------------- | --------------------- |
-| fileOptions | [IFileOptions](#ifileoptions) | -- | 必选,待上传文件配置 | [基本用法](#基本用法) |
-| filePath | `string` | -- | 文件路径 | [基本用法](#基本用法) |
-| uploadOptions | [IUploadOptions](#iuploadoptions) | \-- | 必选,上传配置 | [基本用法](#基本用法) |
-| autoUpload | `boolean` | false | 可选,是否自动上传 | [基本用法](#基本用法) |
-| placeholderText | `string` | '选择文件' | 可选,上传输入框中的 Placeholder 文字 | [基本用法](#基本用法) |
-| uploadText | `string` | '上传' | 可选,上传按钮文字 | [基本用法](#基本用法) |
-| uploadedFiles | `Array