V2.4.0-beta.1

master
git 9 years ago
parent e2f7e18b6b
commit 05d6158671

@ -16,7 +16,7 @@
var FileUpload = require('vue-upload-component'); var FileUpload = require('vue-upload-component');
new Vue({ new Vue({
template: '<file-upload post-action="/post.method" put-action="/put.method"></file-upload>', template: '<file-upload post-action="/post.method" put-action="/put.method">Upload file</file-upload>',
components: { components: {
FileUpload: FileUpload FileUpload: FileUpload
} }
@ -28,7 +28,7 @@
```js ```js
import FileUpload from 'vue-upload-component' import FileUpload from 'vue-upload-component'
new Vue({ new Vue({
template: '<file-upload post-action="/post.method" put-action="/put.method"></file-upload>', template: '<file-upload post-action="/post.method" put-action="/put.method">Upload file</file-upload>',
components: { components: {
FileUpload FileUpload
} }
@ -52,7 +52,6 @@ var nodeExternals = require('webpack-node-externals');
] ]
//..... //.....
} }
``` ```
## Examples ## Examples
@ -61,12 +60,9 @@ https://lian-yue.github.io/vue-upload-component/
https://github.com/lian-yue/vue-upload-component/tree/2.0/example/ https://github.com/lian-yue/vue-upload-component/tree/2.0/example/
``` html ``` html
<!-- Example file ./index.html -->
<!-- Example file ./src/example.js -->
<div id="app"> <div id="app">
<file-upload title="Add upload files"></file-upload> <file-upload>Upload file</file-upload>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
@ -102,8 +98,6 @@ npm run build
## Props ## Props
``` html ``` html
<file-upload <file-upload
title="Add upload files"
name="post file name" name="post file name"
drop="Boolean (true = $parent) or Element or Css Selector" drop="Boolean (true = $parent) or Element or Css Selector"
@ -122,51 +116,28 @@ npm run build
timeout="3600000" timeout="3600000"
events="Object"
headers="Request headers object" headers="Request headers object"
data="Request data object" data="Request data object"
files="Upload files"
thread="Number (Multi-file uploads at the same time)" thread="Number (Multi-file uploads at the same time)"
>
</file-upload>
```
filter="Function(file) (Custom upload filters)"
value="Upload files"
@input="Function(files)"
### Props events @input-file="Function(newFile, oldFile)"
``` js >
events: { Add Files
add(file, component) { </file-upload>
console.log('add');
if (this.auto) {
component.active = true;
}
file.headers['X-Filename'] = encodeURIComponent(file.name)
file.data.filename = file.name
// file.putAction = 'xxx'
// file.postAction = 'xxx'
},
progress(file, component) {
console.log('progress ' + file.progress);
},
after(file, component) {
console.log('after');
},
before(file, component) {
console.log('before');
}
}
``` ```
### Props files
### Props value
``` js ``` js
[ [
{ {
@ -219,7 +190,9 @@ npm run build
## methods ## methods
```` ````
clear() // Clear all files clear()
remove(id or file Object) // Remove a file return file object or false get(id or file Object)
abort(id or file Object) // Stop a file upload return file object or false add(window.File Object or object)
update(id or file Object, data)
remove(id or file Object)
``` ```

10142
dist/example.js vendored

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -1,30 +0,0 @@
<template>
<div id="app">
<header id="header">
<h1>Upload test</h1>
<nav>
<h2>Navigation</h2>
<h3>Please click on the navigation</h3>
<ul>
<li><router-link to="/">Home</router-link></li>
<li><router-link to="/multi">Multi components</router-link></li>
<li><router-link to="/cross-router">Cross router</router-link></li>
<li><router-link to="/vuex">Vuex</router-link></li>
</ul>
</nav>
</header>
<router-view id="main"></router-view>
<footer id="footer">
<div>Powered by:<a href="//www.lianyue.org">LianYue</a></div>
</footer>
</div>
</template>
<style>
nav {
margin-bottom: 1em
}
</style>
<script>
export default {
}
</script>

@ -1,50 +0,0 @@
<style>
.cross-router {
margin-top: 2em
}
.cross-router .file-uploads {
font-size: 18px;
padding: .6em;
font-weight: bold;
border: 1px solid #888;
background: #f3f3f3
}
.cross-router button {
padding: .6em;
}
.cross-router .list li {
border-bottom: 1px solid #888;
}
.cross-router .list span {
display: inline-block;
padding: .4em
}
</style>
<template>
<main class="cross-router">
<nav>
<h3>Sub navigation</h3>
<ul>
<li><router-link to="/cross-router">File upload</router-link></li>
<li><router-link to="/cross-router/list">File list</router-link></li>
</ul>
</nav>
<keep-alive>
<router-view :files="files"></router-view>
</keep-alive>
</main>
</template>
<script>
export default {
data() {
return {
files: [],
}
},
}
</script>

@ -1,47 +0,0 @@
<template>
<div>
<h2>List</h2>
<div class="lists">
<table>
<thead>
<tr>
<th>Index</th>
<th>ID</th>
<th>Name</th>
<th>Size</th>
<th>Progress</th>
<th>Speed</th>
<th>Active</th>
<th>Error</th>
<th>Success</th>
</tr>
</thead>
<tbody>
<tr v-for="(file, index) in files">
<td>{{index}}</td>
<td>{{file.id}}</td>
<td>{{file.name}}</td>
<td>{{file.size | formatSize}}</td>
<td>{{file.progress}}</td>
<td>{{file.speed | formatSize}}</td>
<td>{{file.active}}</td>
<td>{{file.error}}</td>
<td>{{file.success}}</td>
</tr>
</tbody>
</table>
</div>
</div>
</template>
<script>
export default {
props: {
files: {
type: Array,
default: () => [],
},
}
}
</script>

@ -1,41 +0,0 @@
<template>
<div>
<div class="upload-btn">
<file-upload
title="Add upload files"
name="file"
post-action="/post"
put-action="/put"
:multiple="true"
:files="files"
ref="upload">
</file-upload>
<button v-show="!upload.active" @click.prevent="upload.active = true" type="button">Start upload</button>
<button v-show="upload.active" @click.prevent="upload.active = false" type="button">Stop upload</button>
</div>
</div>
</template>
<script>
import FileUpload from '../src'
export default {
components: {
FileUpload,
},
props: {
files: {
type: Array,
default: () => [],
},
},
data() {
return {
upload: {},
}
},
mounted() {
this.upload = this.$refs.upload.$data
}
}
</script>

@ -42,6 +42,7 @@ table th,table td {
<tr> <tr>
<th>Index</th> <th>Index</th>
<th>ID</th> <th>ID</th>
<th>Image</th>
<th>Name</th> <th>Name</th>
<th>Size</th> <th>Size</th>
<th>Progress</th> <th>Progress</th>
@ -50,6 +51,7 @@ table th,table td {
<th>Error</th> <th>Error</th>
<th>Success</th> <th>Success</th>
<th>Abort</th> <th>Abort</th>
<th>customError</th>
<th>Delete</th> <th>Delete</th>
</tr> </tr>
</thead> </thead>
@ -57,6 +59,10 @@ table th,table td {
<tr v-for="(file, index) in files"> <tr v-for="(file, index) in files">
<td>{{index}}</td> <td>{{index}}</td>
<td>{{file.id}}</td> <td>{{file.id}}</td>
<td v-if="file.type.substr(0, 6) == 'image/' && file.blob">
<img :src="file.blob" width="50" height="auto" />
</td>
<td v-else></td>
<td>{{file.name}}</td> <td>{{file.name}}</td>
<td>{{file.size | formatSize}}</td> <td>{{file.size | formatSize}}</td>
<td>{{file.progress}}</td> <td>{{file.progress}}</td>
@ -64,7 +70,8 @@ table th,table td {
<td>{{file.active}}</td> <td>{{file.active}}</td>
<td>{{file.error}}</td> <td>{{file.error}}</td>
<td>{{file.success}}</td> <td>{{file.success}}</td>
<td><button type="button" @click.prevent="file.active = false">Abort</button></td> <td><button type="button" @click.prevent="abort(file)">Abort</button></td>
<td><button type="button" @click.prevent="customError(file)">custom error</button></td>
<td><button type="button" @click.prevent="remove(file)">x</button></td> <td><button type="button" @click.prevent="remove(file)">x</button></td>
</tr> </tr>
</tbody> </tbody>
@ -76,8 +83,6 @@ table th,table td {
<tr> <tr>
<td> <td>
<file-upload <file-upload
:title="title"
:events="events"
:name="name" :name="name"
:post-action="postAction" :post-action="postAction"
:put-action="putAction" :put-action="putAction"
@ -89,13 +94,15 @@ table th,table td {
:headers="headers" :headers="headers"
:data="data" :data="data"
:drop="drop" :drop="drop"
:files="files" v-model="files"
@input-file="inputFile"
ref="upload"> ref="upload">
Add upload files
</file-upload> </file-upload>
</td> </td>
<td> <td>
<button v-show="!upload.active" @click.prevent="upload.active = true" type="button">Start upload</button> <button v-show="!$refs.upload || !$refs.upload.active" @click.prevent="$refs.upload.active = true" type="button">Start upload</button>
<button v-show="upload.active" @click.prevent="upload.active = false" type="button">Stop upload</button> <button v-show="$refs.upload && $refs.upload.active" @click.prevent="$refs.upload.active = false" type="button">Stop upload</button>
</td> </td>
<td> <td>
<label> <label>
@ -138,22 +145,22 @@ table th,table td {
Auto start: {{auto}} Auto start: {{auto}}
</td> </td>
<td> <td>
Active: {{upload.active}} Active: {{$refs.upload ? $refs.upload.active : false}}
</td> </td>
<td> <td>
Uploaded: {{upload.uploaded}} Uploaded: {{$refs.upload ? $refs.upload.uploaded : true}}
</td> </td>
<td> <td>
Drop active: {{upload.dropActive}} Drop active: {{$refs.upload ? $refs.upload.dropActive : false}}
</td> </td>
<td> <td>
<label for="file">Click</label> <label :for="name">Click</label>
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</div> </div>
<div v-show="upload.dropActive" class="drop-active"> <div v-show="$refs.upload && $refs.upload.dropActive" class="drop-active">
Drop ing Drop ing
</div> </div>
</main> </main>
@ -162,7 +169,6 @@ table th,table td {
<script> <script>
import FileUpload from '../src' import FileUpload from '../src'
export default { export default {
components: { components: {
FileUpload, FileUpload,
@ -170,19 +176,16 @@ export default {
data() { data() {
return { return {
accept: 'image/*', files: [],
accept: '', accept: 'image/png,image/gif,image/jpeg,image/webp',
size: 1024 * 1024 * 10, size: 1024 * 1024 * 10,
extensions: 'gif,jpg,jpeg,png,webp',
// extensions: ['gif', 'jpg', 'jpeg','png', 'webp'],
// extensions: /\.(gif|jpe?g|png|webp)$/i,
multiple: true, multiple: true,
extensions: 'gif,jpg,png',
// extensions: ['gif','jpg','png'],
// extensions: /\.(gif|png|jpg)$/i,
files: [],
upload: {},
title: 'Add upload files',
drop: true, drop: true,
auto: false, thread: 3,
thread: 1,
name: 'file', name: 'file',
postAction: './post.php', postAction: './post.php',
@ -196,42 +199,69 @@ export default {
"_csrf_token": "xxxxxx", "_csrf_token": "xxxxxx",
}, },
events: {
add(file, component) {
console.log('add');
if (this.$parent.auto) {
component.active = true;
}
file.headers['X-Filename'] = encodeURIComponent(file.name)
file.data.finename = file.name
// file.putAction = 'xxx' auto: false,
// file.postAction = 'xxx' }
},
progress(file, component) {
console.log('progress ' + file.progress);
}, },
after(file, component) {
console.log('after'); watch: {
auto(auto) {
if (auto && !this.$refs.upload.uploaded && !this.$refs.upload.active) {
this.$refs.upload.active = true
}
}
}, },
before(file, component) {
console.log('before'); methods: {
// Custom filter
filter(file) {
// min size
if (file.size < 100 * 1024) {
file = this.$refs.upload.update(file, {error: 'size'})
}
return file
}, },
// File Event
inputFile(newFile, oldFile) {
if (newFile && !oldFile) {
console.log('add', newFile)
var URL = window.URL || window.webkitURL
if (URL && URL.createObjectURL) {
this.$refs.upload.update(newFile, {blob: URL.createObjectURL(newFile.file)})
}
}
if (newFile && oldFile) {
console.log('update', newFile, oldFile)
if (newFile.progress != oldFile.progress) {
console.log('progress', newFile.progress)
}
} }
if (!newFile && oldFile) {
console.log('remove', oldFile)
}
if (this.auto && !this.$refs.upload.uploaded && !this.$refs.upload.active) {
this.$refs.upload.active = true
} }
}, },
mounted() { abort(file) {
this.upload = this.$refs.upload.$data this.$refs.upload.update(file, {active: false})
// or
// this.$refs.upload.update(file, {error: 'abort'})
}, },
methods: { customError(file) {
this.$refs.upload.update(file, {error: 'custom'})
},
remove(file) { remove(file) {
var index = this.files.indexOf(file) this.$refs.upload.remove(file)
if (index != -1) {
this.files.splice(index, 1);
}
}, },
}, },
} }

@ -1,123 +0,0 @@
<template>
<main class="multi">
<div class="image">
<div class="lists">
<table>
<thead>
<tr>
<th>Index</th>
<th>ID</th>
<th>Name</th>
<th>Size</th>
<th>Progress</th>
<th>Speed</th>
<th>Active</th>
<th>Error</th>
<th>Success</th>
</tr>
</thead>
<tbody>
<tr v-for="(file, index) in imageFiles">
<td>{{index}}</td>
<td>{{file.id}}</td>
<td>{{file.name}}</td>
<td>{{file.size | formatSize}}</td>
<td>{{file.progress}}</td>
<td>{{file.speed | formatSize}}</td>
<td>{{file.active}}</td>
<td>{{file.error}}</td>
<td>{{file.success}}</td>
</tr>
</tbody>
</table>
</div>
<div class="upload-btn">
<file-upload
title="Add upload images"
name="image"
post-action="/image"
put-action="/image"
accept='image/*'
:multiple="true"
:files="imageFiles"
ref="image">
</file-upload>
<button v-show="!image.active" @click.prevent="image.active = true" type="button">Start upload</button>
</div>
</div>
<div class="video">
<div class="lists">
<table>
<thead>
<tr>
<th>Index</th>
<th>ID</th>
<th>Name</th>
<th>Size</th>
<th>Progress</th>
<th>Speed</th>
<th>Active</th>
<th>Error</th>
<th>Success</th>
</tr>
</thead>
<tbody>
<tr v-for="(file, index) in videoFiles">
<td>{{index}}</td>
<td>{{file.id}}</td>
<td>{{file.name}}</td>
<td>{{file.size | formatSize}}</td>
<td>{{file.progress}}</td>
<td>{{file.speed | formatSize}}</td>
<td>{{file.active}}</td>
<td>{{file.error}}</td>
<td>{{file.success}}</td>
</tr>
</tbody>
</table>
</div>
<div class="upload-btn">
<file-upload
title="Add upload videos"
name="video"
post-action="/video"
put-action="/video"
accept='video/*'
:multiple="true"
:files="videoFiles"
ref="video">
</file-upload>
<button v-show="!video.active" @click.prevent="video.active = true" type="button">Start upload</button>
<button v-show="video.active" @click.prevent="video.active = false" type="button">Stop upload</button>
</div>
</div>
</main>
</template>
<script>
import FileUpload from '../src'
export default {
components: {
FileUpload,
},
data() {
return {
image: {},
imageFiles: [],
video: {},
videoFiles: [],
}
},
mounted() {
this.image = this.$refs.image.$data
this.video = this.$refs.video.$data
},
}
</script>

@ -1,110 +1,32 @@
<template> <template>
<div>
<div class="upload-btn">
<file-upload <file-upload
title="Add upload files"
name="file" name="file"
post-action="/" post-action="/post"
:multiple="true" put-action="/put"
:events="events" :value="files"
@input="input"
@input-file="inputFile"
ref="upload"> ref="upload">
Add upload files
</file-upload> </file-upload>
<button v-show="!upload.active" @click.prevent="upload.active = true" type="button">Start upload</button>
<button v-show="upload.active" @click.prevent="upload.active = false" type="button">Stop upload</button>
</div>
<div class="lists">
<table>
<thead>
<tr>
<th>Index</th>
<th>ID</th>
<th>Name</th>
<th>Size</th>
<th>Progress</th>
<th>Speed</th>
<th>Active</th>
<th>Error</th>
<th>Success</th>
<th>Abort</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<tr v-for="(file, index) in files">
<td>{{index}}</td>
<td>{{file.id}}</td>
<td>{{file.name}}</td>
<td>{{file.size | formatSize}}</td>
<td>{{file.progress}}</td>
<td>{{file.speed | formatSize}}</td>
<td>{{file.active}}</td>
<td>{{file.error}}</td>
<td>{{file.success}}</td>
<td><button type="button" @click.prevent="abort(file)">Abort</button></td>
<td><button type="button" @click.prevent="remove(file)">x</button></td>
</tr>
</tbody>
</table>
</div>
</div>
</template> </template>
<script> <script>
import FileUpload from '../src' import FileUpload from '../src'
import { mapState } from 'vuex' import { mapState } from 'vuex'
function addFile(file) {
var newFile = Object.assign({}, file)
file._vuex = newFile
this.$store.commit('addFile', newFile)
}
function updateFile(file) {
var oldFile = file._vuex
var newFile = Object.assign({}, file)
file._vuex = newFile
this.$store.commit('updateFile', {oldFile, newFile})
}
function removeFile(file) {
this.$store.commit('removeFile', file._vuex)
}
export default { export default {
components: { components: {
FileUpload, FileUpload,
}, },
data() {
return {
upload: {},
events: {
add: addFile,
progress: updateFile,
before: updateFile,
after: updateFile,
remove: removeFile,
},
}
},
computed: mapState({ computed: mapState({
files: state => state.files files: state => state.files
}), }),
methods: { methods: {
remove(file) { // Files Event
this.$store.commit('removeFile', file) input(files) {
this.$refs.upload.remove(file.id) this.$store.commit('updateFiles', files)
},
abort(file) {
this.$refs.upload.abort(file.id)
}, },
}, },
mounted() {
this.upload = this.$refs.upload.$data
}
} }
</script> </script>

@ -1,27 +1,14 @@
import Vue from 'vue' import Vue from 'vue'
import VueRouter from 'vue-router'
import App from './App'
import Home from './Home' import Home from './Home'
import Multi from './Multi'
import CrossRouter from './CrossRouter'
import CrossRouterUpload from './CrossRouterUpload'
import CrossRouterList from './CrossRouterList'
import VuexComponent from './Vuex'
import store from './store' import store from './store'
Vue.use(VueRouter)
Vue.config.silent = false; Vue.config.silent = false;
Vue.config.devtools = true; Vue.config.devtools = true;
Vue.filter('formatSize', function(size) { Vue.filter('formatSize', function(size) {
if (size > 1024 * 1024 * 1024 * 1024) { if (size > 1024 * 1024 * 1024 * 1024) {
return (size / 1024 / 1024 / 1024 / 1024).toFixed(2) + ' TB'; return (size / 1024 / 1024 / 1024 / 1024).toFixed(2) + ' TB';
@ -39,37 +26,7 @@ Vue.filter('formatSize', function(size) {
const router = new VueRouter({
mode: 'history',
base: __dirname,
routes: [
{
path: '/',
component: Home
},
{
path: '/multi',
component: Multi
},
{
path: '/cross-router',
component: CrossRouter,
children: [
{ path: '', component: CrossRouterUpload },
{ path: 'list', component: CrossRouterList }
]
},
{
path: '/vuex',
component: VuexComponent,
},
]
})
new Vue({ new Vue({
router,
store, store,
...App ...Home
}).$mount('#app') }).$mount('#app')

@ -10,37 +10,12 @@ const state = {
} }
const mutations = { const mutations = {
addFile (state, file) { updateFiles(state, files) {
state.files.push(file) state.files = files
},
updateFile (state, {oldFile, newFile}) {
var index = state.files.indexOf(oldFile)
if (index == -1) {
return
} }
state.files.splice(index, 1, newFile);
},
removeFile(state, file) {
var index = state.files.indexOf(file)
if (index != -1) {
state.files.splice(index, 1);
}
},
} }
const actions = {
}
const getters = {
}
export default new Vuex.Store({ export default new Vuex.Store({
strict: process.env.NODE_ENV !== 'production', strict: true,
state, state,
getters,
actions,
mutations mutations
}) })

@ -5,9 +5,8 @@
<title>vue-upload-component</title> <title>vue-upload-component</title>
</head> </head>
<body> <body>
<div id="app"></div> <div id="app"></div>
<script src="/vue-upload-component/dist/example.js"></script> <script src="https://unpkg.com/es6-promise@4.1.0/dist/es6-promise.auto.min.js"></script>
<script src="/dist/example.js"></script> <script src="./dist/example.js"></script>
</body> </body>
</html> </html>

@ -1,7 +1,7 @@
{ {
"name": "vue-upload-component", "name": "vue-upload-component",
"description": "Vue.js file upload component, Support for multiple file uploads, progress, html5, html4, support ie9", "description": "Vue.js file upload component, Support for multiple file uploads, progress, html5, html4, support ie9",
"version": "2.3.2", "version": "2.4.0-beta.1",
"author": "LianYue", "author": "LianYue",
"scripts": { "scripts": {
"dev": "webpack-dev-server --inline --hot", "dev": "webpack-dev-server --inline --hot",

File diff suppressed because it is too large Load Diff

@ -1,5 +1,4 @@
<template> <template>
<span class="file-uploads-input">
<input <input
type="file" type="file"
:name="$parent.name" :name="$parent.name"
@ -8,14 +7,13 @@
@change="change" @change="change"
:multiple="$parent.multiple && $parent.mode === 'html5'" :multiple="$parent.multiple && $parent.mode === 'html5'"
/> />
</span>
</template> </template>
<script> <script>
export default { export default {
methods: { methods: {
change(e) { change(e) {
this.$destroy() this.$destroy()
this.$parent._addInputFileElement(e.target) this.$parent.addInputFile(e.target)
} }
} }
} }

Loading…
Cancel
Save