diff --git a/docs/docs/en.md b/docs/docs/en.md index a4e737f..f26e7b1 100644 --- a/docs/docs/en.md +++ b/docs/docs/en.md @@ -545,6 +545,25 @@ Whether to open the drag directory +### add-index + +* **Type:** `Boolean, Number` + +* **Default:** `undefined` + +* **Version:** : `>=2.6.1` + +* **Details:** + + The default value of the `index` parameter for the [`add()`](#instance-methods-add) method + +* **Usage:** + ```html + + ``` + + + ## Options / Events @@ -866,7 +885,7 @@ Add one or more files * **Arguments:** * `files: Array | File | window.File | Object` If it is an array of responses will be an array - * `start: Boolean` Whether it is inserted from the start position + * `index: Number | Boolean` = [`props.add-index`](#options-props-add-index) `true = ` Start, `false = ` End, `Number = ` Index * **Result:** `Object | Array | Boolean` The incoming array is returned to the array otherwise the object or `false` @@ -1013,6 +1032,17 @@ Remove a file object ``` +### replace() + Replace the location of the two files + +* **Arguments:** + + * `id1: File | Object | String` + * `id2: File | Object | String` + + +* **Result:** `Boolean` + ### clear() diff --git a/docs/docs/zh-cn.md b/docs/docs/zh-cn.md index 9f18e70..c6cbcb9 100644 --- a/docs/docs/zh-cn.md +++ b/docs/docs/zh-cn.md @@ -540,6 +540,23 @@ input标签的 `name` 属性 ``` +### add-index + +* **类型:** `Boolean, Number` + +* **默认值:** `undefined` + +* **详细:** + +* **版本:** `>= 2.6.1` + + [`add()`](#实例-方法-add) 方法 `index` 参数的默认值 + +* **示例:** + ```html + + ``` + ## 选项 / 事件 @@ -860,7 +877,7 @@ Add, update, remove pre-filter * **参数:** * `files: Array | File | window.File | Object` 如果它是一个数组的响应将是一个数组 - * `start: Boolean` 是否从开始位置插入 + * `index: Number | Boolean` = [`props.add-index`](#选项-属性-add-index) `true = ` 开始位置, `false = ` 结束位置, `Number = ` 下标位置 * **结果:** `Object | Array | Boolean` 传入的是数组返回数组否则对象或`false` @@ -1008,6 +1025,19 @@ Add, update, remove pre-filter ``` +### replace() + 替换两个文件的位置 + +* **参数:** + + * `id1: File | Object | String` + * `id2: File | Object | String` + + +* **结果:** `Boolean` + + + ### clear() 清空文件列表 diff --git a/docs/views/examples/Full.vue b/docs/views/examples/Full.vue index 3548ba4..82d6d16 100644 --- a/docs/views/examples/Full.vue +++ b/docs/views/examples/Full.vue @@ -97,6 +97,7 @@ :data="data" :drop="drop" :drop-directory="dropDirectory" + :add-index="addIndex" v-model="files" @input-filter="inputFilter" @input-file="inputFile" @@ -163,6 +164,14 @@ Min size: + + + + Start position to add + + + Add a file list to start the location to add + @@ -384,6 +393,7 @@ export default { directory: false, drop: true, dropDirectory: true, + addIndex: false, thread: 3, name: 'file', postAction: '/upload/post', diff --git a/package.json b/package.json index bfcfa93..ad43488 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "vue-upload-component", "description": "Vue.js file upload component, Multi-file upload, Upload directory, Drag upload, Drag the directory, Upload multiple files at the same time, html4 (IE 9), `PUT` method, Customize the filter", - "version": "2.6.0-beta.3", + "version": "2.6.1", "author": "LianYue", "scripts": { "dev": "cross-env NODE_ENV=development webpack-dev-server", diff --git a/src/FileUpload.vue b/src/FileUpload.vue index abe3958..3732029 100644 --- a/src/FileUpload.vue +++ b/src/FileUpload.vue @@ -56,6 +56,10 @@ export default { type: Boolean, }, + addIndex: { + type: [Boolean, Number], + }, + directory: { type: Boolean, }, @@ -189,17 +193,7 @@ export default { * uploading 正在上传的线程 * @return {[type]} [description] */ - /* - uploading() { - let uploading = 0 - for (var i = 0; i < this.files.length; i++) { - if (this.files[i].active) { - uploading++ - } - } - return uploading - }, - */ + /** * uploaded 文件列表是否全部已上传 * @return {[type]} [description] @@ -309,7 +303,7 @@ export default { }, // 添加 - add(_files, start) { + add(_files, index = this.addIndex) { let files = _files let isArray = files instanceof Array @@ -403,8 +397,11 @@ export default { // 添加进去 files let newFiles - if (start) { + if (index === true || index === 0) { newFiles = addFiles.concat(this.files) + } else if (index) { + newFiles = addFiles.concat([]) + newFiles.splice(index, 0, addFiles) } else { newFiles = this.files.concat(addFiles) } @@ -536,6 +533,25 @@ export default { }, + replace(id1, id2) { + let file1 = this.get(id1) + let file2 = this.get(id2) + if (!file1 || !file2 || file1 === file2) { + return false + } + let files = this.files.concat([]) + let index1 = files.indexOf(file1) + let index2 = files.indexOf(file2) + if (index1 === -1 || index2 === -1) { + return false + } + files[index1] = file2 + files[index2] = file1 + this.files = files + this.emitInput() + return true + }, + // 移除 remove(id) { let file = this.get(id) @@ -601,6 +617,7 @@ export default { }, + // 预处理 事件 过滤器 emitFilter(newFile, oldFile) { let isPrevent = false