| | |
| | | ref="uploader"
|
| | | :options="options"
|
| | | :file-status-text="statusText"
|
| | | :attrs="attrs"
|
| | | class="uploader-single"
|
| | | @file-added="onFileAdded"
|
| | | @complete="onComplete"
|
| | | >
|
| | | <el-input :placeholder="uploadPlaceholder" size="small" :readonly="true" v-model="fileName">
|
| | | <uploader-btn slot="suffix" >
|
| | | <uploader-btn slot="suffix">
|
| | | <el-tooltip :content="tipWords" placement="top" v-if="tip">
|
| | | <i class="el-icon-upload2" style="font-size:18px; color:#0088ff"></i>
|
| | | </el-tooltip>
|
| | |
| | | <uploader
|
| | | v-else
|
| | | ref="uploader"
|
| | | :attrs="attrs"
|
| | | :options="options"
|
| | | :file-status-text="statusText"
|
| | | class="uploader-example"
|
| | |
| | | @complete="onComplete"
|
| | | @close="closeHandle"
|
| | | >
|
| | | <uploader-btn ref="button"> |
| | | <uploader-btn ref="button" :attrs="attrs">
|
| | | <i class="el-icon-upload2" style="font-size:18px; color:#0088ff"></i>
|
| | | 上传
|
| | | </uploader-btn>
|
| | |
| | | UploaderList
|
| | | },
|
| | | props: {
|
| | | acptTypes: {
|
| | | type: String,
|
| | | default: ''
|
| | | },
|
| | | tip: {
|
| | | type: Boolean,
|
| | | default: false
|
| | |
| | | type: String,
|
| | | default: "/data/api-f/file/upload" //"//192.168.20.10:3000/upload"
|
| | | },
|
| | | attrs: {
|
| | | type: Object,
|
| | | // default () {
|
| | | // return {
|
| | |
|
| | | // }
|
| | | // }
|
| | | }
|
| | | },
|
| | | data() {
|
| | | data () {
|
| | | return {
|
| | | fileName: "",
|
| | | fileMd5: "",
|
| | | attrs: {
|
| | | accept: 'image/*'
|
| | | },
|
| | | // attrs: {
|
| | | // accept: 'image/*'
|
| | | // },
|
| | | statusText: {
|
| | | success: '上传成功',
|
| | | error: '上传失败',
|
| | |
| | | }
|
| | | },
|
| | | computed: {
|
| | | uploader() {
|
| | | uploader () {
|
| | | return this.$refs.uploader.uploader;
|
| | | },
|
| | | options() {
|
| | | options () {
|
| | | return {
|
| | | target: this.url,
|
| | | testChunks: true,
|
| | |
| | | }
|
| | | },
|
| | | methods: {
|
| | | onFileAdded(file) {
|
| | | onFileAdded (file) {
|
| | | if (this.single) {
|
| | | this.uploader.fileList = this.uploader.fileList.slice([-1]);
|
| | | this.$emit("file-added")
|
| | | }
|
| | | this.computeMD5(file);
|
| | | },
|
| | | computeMD5(file) {
|
| | | computeMD5 (file) {
|
| | | let fileReader = new FileReader();
|
| | | let time = new Date().getTime();
|
| | | let blobSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice;
|
| | |
| | | this.error(`文件${file.name}读取出错,请检查该文件`)
|
| | | file.cancel();
|
| | | };
|
| | | function loadNext() {
|
| | | function loadNext () {
|
| | | let start = currentChunk * chunkSize;
|
| | | let end = ((start + chunkSize) >= file.size) ? file.size : start + chunkSize;
|
| | | fileReader.readAsArrayBuffer(blobSlice.call(file.file, start, end));
|
| | | }
|
| | | },
|
| | | computeMD5Success(md5, file) {
|
| | | computeMD5Success (md5, file) {
|
| | | // 将自定义参数直接加载uploader实例的opts上
|
| | | // if (this.$route.path.indexOf("VideoManage") >= 0) {
|
| | | // Object.assign(this.uploader.opts, {
|
| | |
| | | file.resume();
|
| | | this.statusText.paused = "暂停中";
|
| | | },
|
| | | onComplete() {
|
| | | onComplete () {
|
| | | debugger
|
| | | this.$emit("complete", { filename: this.fileName, identifier: this.fileMd5 });
|
| | | },
|
| | | fileComplete() {
|
| | | fileComplete () {
|
| | | // console.log('file complete', arguments)
|
| | | },
|
| | | closeHandle() {
|
| | | closeHandle () {
|
| | | this.$emit("close")
|
| | | }
|
| | | },
|
| | | mounted() {
|
| | | mounted () {
|
| | | this.$nextTick(() => {
|
| | | console.log(this.acptTypes)
|
| | | window.uploader = this.$refs.uploader.uploader
|
| | | })
|
| | | }
|
| | |
| | |
|
| | | <style lang="scss">
|
| | | .file-uploader {
|
| | | .el-input__suffix,.el-input__suffix-inner{
|
| | | outline: none!important;
|
| | | .el-input__suffix,
|
| | | .el-input__suffix-inner {
|
| | | outline: none !important;
|
| | | }
|
| | | .el-tooltip.focusing{
|
| | | .el-tooltip.focusing {
|
| | | outline: none;
|
| | | }
|
| | | .uploader-example {
|
| | |
| | | display: none;
|
| | | }
|
| | | .uploader-btn {
|
| | | border: 0px; |
| | | border: 0px;
|
| | | }
|
| | | .uploader-file {
|
| | | height: 2px;
|