<button class="blueButton fileinput-button" style="width:165px;" @click="importExcel_1">
<input type="file" ref="importFile1">
导入录播、中控数据
</button>

  

importExcel_1(){
let finput = this.$refs.importFile1;
finput.onchange = (() => {
if (finput.value.match(/\.(xls|xlsx|xlsm)(\?.*)?$/)) {
this.templateObj.excel1.fileName = this.setExcelName(finput.files[0].name);
this.templateObj.excel1.file = finput.files[0];
} else {
new FailHint().show('请选择正确的Excel格式文件!');
}
});
}
js方法:
文件断点续传:
弹框:
<Modal v-model="uploadWinFlag" :mask-closable="false" @on-cancel="cancelUpload()">
<p slot="header">
<span>上传</span>
</p>
<div class="videoBody">
<Form ref="loadForm" style="padding-right: 40px;" :rules="ruleUpload" :model="currentUpload" :label-width="80">
<Form-item label="资源名称" prop="resourcename">
<Input v-model="currentUpload.resourcename"></Input>
</Form-item>
<Form-item style="position: relative;" label="作者" prop="userid">
<Select :loading="status.loading" placeholder="请输入教师姓名" remote :remote-method="searchTeacher"
class="customInput"
v-model="currentUpload.userid" clearable filterable>
<Option-group v-for="it in teacherList" :label="it.title" :key="it.id">
<Option v-for="tea in it.teachers" :value="tea.id" :label="tea.name"
:key="tea"></Option>
</Option-group>
</Select>
</Form-item>
<Form-item label="所属教室">
<tree-select class="custom-input" style="width: 2.6rem;" v-model="currentUpload.areaid" :data="treeList"
nameprops="title"></tree-select>
</Form-item>
<div style="padding-left: 15px;">
<button class="modalBtn blueButton fileinput-button" @click="pickVideo()" style="width:80px;">
<input type="file" ref="videoInput" multiple="true">
选择文件
</button>
</div>
<ul class="loadedVideoCls">
<li v-for="(it,index) in currentUpload.list" :title="it.showName" >
<span style="margin-right: 10px;text-overflow:ellipsis;white-space: nowrap;overflow: hidden;">{{it.showName}}</span>
<i style="cursor: pointer;position: relative;" class="ivu-icon ivu-icon-close" @click="removeLoaded(index)" ></i>
</li>
</ul>
</Form>
</div>
<div>
<ul class="loadingVideoCls">
<li v-for="(it,index) in uploadingVideos" v-show="!it.complete">
<div>{{it.name}}</div>
<div class="progressCls">
<div>
<div style="background: #1FB529;width: 33px;height: 100%;" :style="{width:it.percentLoaded+'%'}"></div>
</div>
<span class="percentNum" >{{it.percentLoaded}}%</span>
<i :style="{visibility:it.complete?'hidden':'visible'}" class="ivu-icon ivu-icon-close-circled progressClose" @click="removeLoading(index)"></i>
</div>
<div>
<div>速度:{{it.bytesSpeed}}M/s</div>
<div>已上传:{{it.bytesLoaded}}M/{{it.bytesTotal}}M</div>
<div>剩余时间:{{it.remainTime}}s</div>
</div>
</li>
</ul>
</div>
<div slot="footer">
<button class="buttonCls modalBtn" @click="cancelUpload()">取消</button>
<button class="modalBtn blueButton" @click="valiadateUpload('loadForm')">
保存
</button>
</div>
</Modal>

  

removeLoaded(index){
console.log('------------>>>deleteloaded',index);
this.currentUpload.list.splice(index,1);
this.uploadingVideos.splice(index,1);
let finput = this.$refs.videoInput;
finput.value = '';
},
removeLoading(index){
console.log('----------deleteloading',index);
this.uploadedUtil.deleteLoading(index);
},
pickVideo(){
let finput = this.$refs.videoInput;
finput.value == "";
finput.onchange = this.finputChange;
},
finputChange(){
let finput = this.$refs.videoInput;
if (finput.value.match(/\.(MP4|mp4)(\?.*)?$/)) {
let len = finput.files.length;
for (let i = 0; i < len; i++)
{
let f = finput.files[i];
console.log('===========>obj=',this.currentUploadObj)
if (this.currentUploadObj.hasOwnProperty(f.name))
{
util.arrayAdd(this.currentUpload.list,this.currentUploadObj[f.name],'showName')
// this.currentUpload.list.push(this.currentUploadObj[f.name]);
continue;
}
this.uploadingVideoFiles.push(f);
this.uploadingVideos.push({name:f.name,bytesLoaded: '-', bytesTotal: '-', bytesSpeed: '-', remainTime: '-', percentLoaded: 0, complete: false})
}
if (!this.uploadedUtil) {
this.uploadedUtil = new uploadUtilBatch(
this.uploadingVideoFiles, // 需要上传的文件列表
baseURL + 'tk', // 获取token的url
baseURL + "zonekeyresource/uploadVedio", // 下载文件的url
{areaid:this.currentUpload.areaid}, // post需要传的参数
// 上传进度
(progressInfo) => {
console.log('----progress=>', progressInfo)
let video = this.uploadingVideos[progressInfo.videoIndex];
if (!video)
return;
video.bytesLoaded = Math.round(progressInfo.bytesLoaded/1048576);
video.bytesTotal = Math.round(progressInfo.bytesTotal/1048576);
video.bytesSpeed = Math.round(progressInfo.bytesSpeed/1048576);
video.remainTime = Math.max(0,progressInfo.remainTime);
video.percentLoaded = progressInfo.percentLoaded;
},
// 文件上传完成回调
(index,info) => {
let video = this.uploadingVideos[index];
video['complete'] = true;
let fileBean = info.fileBean;
let infoObj = {name:fileBean.name,size:fileBean.size,resourcePath:fileBean.fileurl,showName:info.showName};
this.currentUploadObj[info.showName] = infoObj;
this.currentUpload.list.push(infoObj);
this.currentUpload.floder = info.floder;
console.log('----complete=>', index);
},(index) =>{
finput.value = '';
this.uploadingVideos.splice(index,1);
finput.value == "";
});
this.uploadedUtil.start();
}else
this.uploadedUtil.resumeUpload();
} else {
new FailHint().show('请选择正确的视频格式文件!');
}
},
valiadateUpload(name){
this.$refs[name].validate((valid) => {
if (valid) {
this.uploadFile();
}
})
},
uploadFile(){
videoServer.saveZonekeyResource(this.currentUpload).then(res=>{
if (res.id=='0')
{
new SuccessHint().show("已保存!");
this.cancelUpload();
this.selectItem = this.treeList[0];
this.firstNodeId = this.selectItem.id;
this.selectItem['open'] = true;
this.getVideoList();
}
else
new FailHint().show("保存失败!");
});
// this.uploadingVideoFiles = [];
// this.uploadingVideos = [];
},
// 取消上传
cancelUpload(){
this.currentUploadObj = {};
this.uploadingVideoFiles = [];
this.uploadingVideos = [];
this.uploadWinFlag = false;
this.uploadedUtil = null;
this.currentUpload = {areaid:'',userid:'',resourcename:'',list:[]};
}, util: /**
* Created by ZHX on 2017/6/12.
*/
import * as util from './Util' function UploadUtilBatch(files, tokenUrl, postUrl, params, progressFun, endFun, delBack) {
this.tokenUrl = tokenUrl;
this.postUrl = postUrl;
this.initPostUrl = postUrl;
this.params = params;
this.files = files;
this.progressFun = progressFun;
this.endFun = endFun;
this.delBack = delBack;
} UploadUtilBatch.prototype = {
tokenUrl: "",
initPostUrl:'',
postUrl: "",
files: [],
progressFun: "",
endFun: "",
// 块大小 10M.
filePiece: 10485760,
// 正在下载的文件
currentFile: null,
// 正在下载的文件索引
cfIndex: 0,
xhrHandler: "",
XHR: "",
params: {},
// 记录每次开始位置
bytesStart: 0,
floder: '',
FileBean: null,
// 下载中
loading: false,
start(){
this.floder = '';
if (util.isArray(this.files) && this.files.length > 0) {
this.upload(this.files[this.cfIndex]);
}
else
new Error("穿入文件列表为空!");
},
upload (f) {
this.loading = true;
this.currentFile = f;
this.FileBean = null;
console.log('===========currentFile', f);
/** request the server to figure out what's the token for the file: */
let xhr = new XMLHttpRequest;
let vars = {
name: this.currentFile['name'],
size: this.currentFile['size'],
};
let tokenUrl = fAddVars(vars, this.tokenUrl) + "&" + util.fGetRandom();
xhr.open("GET", tokenUrl, !0);
xhr.onreadystatechange = () => {
if (xhr.readyState != 4 || xhr.status < 200)
return false;
try {
let token = JSON.parse(xhr.responseText).token;
this.initFile({token, size: this.currentFile.size, name: this.currentFile.name})
} catch (e) {
console.log(e);
}
}
xhr.send();
},
initFile(params){
let xhr = new XMLHttpRequest;
let initUrl = fAddVars(params, this.initPostUrl) + "&" + util.fGetRandom();
xhr.open("GET", initUrl, !0);
xhr.onreadystatechange = () => {
if (xhr.readyState != 4 || xhr.status < 200)
return false;
try {
let res = JSON.parse(xhr.responseText);
this.postUrl = fAddVars(
fMergeJson(params, this.params),
this.initPostUrl);
this.uploadFile(res.hasOwnProperty('start')?Number(res.start):0);
} catch (e) {
console.log(e);
}
}
xhr.send();
},
uploadFile(pos){
this.XHR = new XMLHttpRequest;
this.bytesStart = pos;
let _xhr = this.XHR, upload = _xhr.upload;
this.xhrHandler = fExtend(this.loadHandler, this);
upload.addEventListener("progress", this.xhrHandler, !1);
_xhr.addEventListener("load", this.xhrHandler, !1);
_xhr.addEventListener("loadend", this.xhrHandler, !1);
_xhr.onreadystatechange = () => {
if (_xhr.readyState != 4 || _xhr.status < 200)
return false;
try {
let data = JSON.parse(_xhr.responseText);
(data.hasOwnProperty('zonekeyResource')) && (this.floder = data.zonekeyResource.floder);
(data.hasOwnProperty('FileBean')) && (this.FileBean = data.FileBean);
} catch (e) {
console.log(e);
}
}
let blob = this.sliceFile(this.currentFile, pos, pos + this.filePiece);
let range = "bytes " + pos + "-" + (pos + blob.size) + "/" + this.currentFile.size;
let purl = this.floder ? (this.postUrl + '&floder=' + this.floder) : this.postUrl;
_xhr.open("POST", purl, !0);
_xhr.setRequestHeader("Content-Range", range);
_xhr.setRequestHeader("Content-type", "application/x-www-four-urlencoded");
_xhr.send(blob);
},
loadHandler(event){
let xhr = this.XHR;
switch (event.type) {
case "load":
console.log("load");
let uploaded = 0;
let respJson = null;
let bError = !1;
try {
if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 308)) {
uploaded = (respJson = eval("(" + xhr.responseText + ")")) ? respJson.start : -1;
} else if (xhr.status < 500 && xhr.status >= 400) {
bError = !0;
} else if (xhr.status < 200) {
return;
}
/** the response can't process the request, so throws out the error. */
bError = bError || respJson.success == false;
} catch (e) {
bError = this.retriedTimes > 2;
if (!bError) {
// this.retry();
return;
}
}
//check whether upload complete yet
if (uploaded < this.currentFile.size - 1) {
this.retriedTimes = 0;
this.uploadFile(uploaded);
} else {
this.endFun(this.cfIndex, {floder: this.floder, fileBean: this.FileBean, showName: this.currentFile.name});
let files = this.files;
if (files.length - 1 > this.cfIndex)
this.upload(files[++this.cfIndex]);
else
this.loading = false;
}
break;
case "loaded":
console.log("loaded");
break;
case "progress": {
// console.log('------------->progressBack',event)
let total = this.currentFile.size, loaded = this.bytesStart + event.loaded,
now = Date.now(), cost = (now - this.preTime) / 1E3, totalSpeeds = 0;
if (0.68 <= cost || 0 === this.bytesSpeeds.length) {
this.bytesPrevLoaded = Math.max(this.bytesStart, this.bytesPrevLoaded);
this.bytesSpeed = Math.round((loaded - this.bytesPrevLoaded) / cost);
this.bytesPrevLoaded = loaded;
this.preTime = now;
5 < this.bytesSpeeds.length && this.bytesSpeeds.shift();
5 > this.bytesSpeeds.length && (this.bytesSpeed = this.bytesSpeed / 2);
this.bytesSpeeds.push(this.bytesSpeed);
for (let i = 0; i < this.bytesSpeeds.length; i++)
totalSpeeds += this.bytesSpeeds[i];
this.bytesSpeed = Math.round(totalSpeeds / this.bytesSpeeds.length);
this.remainTime = Math.ceil((total - loaded) / this.bytesSpeed);
}
this.progressFun({
videoIndex: this.cfIndex,
originEvent: event,
bytesLoaded: loaded,
bytesTotal: total,
bytesSpeed: this.bytesSpeed,
remainTime: this.remainTime,
percentLoaded: Math.min(100, Math.floor(1E4 * loaded / total) / 100)
});
}
break;
}
},
deleteLoading(index){
this.files.splice(index, 1);
if (index == this.cfIndex) {
this.cancelUpload();
this.delBack(index);
if (this.files.length - 1 > this.cfIndex)
this.upload(this.files[this.cfIndex]);
else
this.cfIndex = this.files.length - 1;
}
else
this.delBack(index);
},
// 继续下载
resumeUpload(){
// 如果当前不在下载状态
if (!this.loading) {
console.log('---------->total',this.files.length,this.cfIndex);
if (this.files.length - 1 > this.cfIndex)
this.upload(this.files[++this.cfIndex]);
}
},
cancelUpload() {
this.XHR && (this.XHR.abort(), this.resetXhr());
this.loading = false;
},
resetXhr(){
if (this.XHR) {
try {
this.XHR.upload.removeEventListener("progress", this.xhrHandler)
this.XHR.removeEventListener("loadend", this.xhrHandler)
this.XHR.removeEventListener("load", this.xhrHandler)
} catch (e) {
throw e;
}
this.XHR = null;
}
},
bytesPrevLoaded: 0, bytesSpeeds: [], bytesStart: 0, preTime: 0,
sliceFile(f, startPos, endPos) {
startPos = startPos || 0;
endPos = endPos || 0;
return f.slice ? f.slice(startPos, endPos) : f.webkitSlice ? f.webkitSlice(startPos, endPos) : f.mozSlice ? f.mozSlice(startPos, endPos) : f; },
removeFile(){ }
}; function fExtend(a, b) {
var c = 2 < arguments.length ? [arguments[2]] : null;
return function () {
var d = "string" === typeof a ? b[a] : a, e = c ? [arguments[0]].concat(c) : arguments;
return d.apply(b || d, e);
};
} function fAddVars(json, url, c) {
var _array = [], _sep = "&", f = function (json, c) {
var e = url ? /\[\]$/.test(url) ? url : url + "[" + c + "]" : c;
"undefined" != e && "undefined" != c
&& _array.push("object" === typeof json
? fAddVars(json, e, !0)
: "[object Function]" === Object.prototype.toString.call(json)
? encodeURI(e) + "=" + encodeURI(json())
: encodeURI(e) + "=" + encodeURI(json))
};
if (!c && url)
_sep = /\?/.test(url) ? /\?$/.test(url) ? "" : "&" : "?",
_array.push(url),
_array.push(fAddVars(json));
else if ("[object Array]" === Object.prototype.toString.call(json)
&& "undefined" != typeof json)
for (var g = 0, c = json.length; g < c; ++g)
f(json[g], g);
else if ("undefined" != typeof json && null !== json && "object" === typeof json)
for (g in json)
f(json[g], g);
else
_array.push(encodeURI(url) + "=" + encodeURI(json));
return _array.join(_sep).replace(/^&/, "").replace(/%20/g, "+")
} function fMergeJson(base, extend) {
var result = {};
for (var attr in base)
result[attr] = base[attr];
for (var attr in extend)
result[attr] = extend[attr];
return result;
} export default UploadUtilBatch;

  

input 文件上传的更多相关文章

  1. 自定义input文件上传样式

    前言 文件上传是我们经常会用到的功能,但是原生的input样式太丑了,能不能自定义一个input文件上传样式呢?我这里写了两种方法,form表单提交跟ajax异步提交都没有问题,自动上传或者点击上传按 ...

  2. input文件上传(上传单个文件/多选文件/文件夹、拖拽上传、分片上传)

    //上传单个/多个文件 <input title="点击选择文件" id="h5Input1" multiple="" accept= ...

  3. 自定义input文件上传 file的提示文字及样式

    简单记录一下 效果图: 代码: <input class="aload" type='button' value='上传附件' onClick='javascript:$(& ...

  4. selenium+python-autoit文件上传

    前言 关于非input文件上传,点上传按钮后,这个弹出的windows的控件了,已经跳出三界之外了,不属于selenium的管辖范围(selenium不是万能的,只能操作web上元素).autoit工 ...

  5. [转]autoid文件上传

    原文地址:https://www.cnblogs.com/yoyoketang/p/7612026.html 前言 关于非input文件上传,点上传按钮后,这个弹出的windows的控件了,已经跳出三 ...

  6. selenium+python自动化77-autoit文件上传

    前言 关于非input文件上传,点上传按钮后,这个弹出的windows的控件了,已经跳出三界之外了,不属于selenium的管辖范围(selenium不是万能的,只能操作web上元素).autoit工 ...

  7. selenium+python自动化77-autoit文件上传【转载】

    前言 关于非input文件上传,点上传按钮后,这个弹出的windows的控件了,已经跳出三界之外了,不属于selenium的管辖范围(selenium不是万能的,只能操作web上元素).autoit工 ...

  8. .net mvc 多文件上传

    1.input文件上传设置允许选择多个文件,设置属性 multiple即可 <input type="file" multiple="multiple" ...

  9. 基于Metronic的Bootstrap开发框架经验总结(5)--Bootstrap文件上传插件File Input的使用

    Bootstrap文件上传插件File Input是一个不错的文件上传控件,但是搜索使用到的案例不多,使用的时候,也是一步一个脚印一样摸着石头过河,这个控件在界面呈现上,叫我之前使用过的Uploadi ...

随机推荐

  1. CSU 1805 Three Capitals(矩阵树定理+Best定理)

    http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1805 题意: A和B之间有a条边,A和G之间有b条边,B和G之间有c条边.现在从A点出发走遍所 ...

  2. C#在服务端验证客户端证书(Certificate)

    使用https协议进行通讯的时候可以设置双向证书认证,客户端验证服务端证书的方法前面已经介绍过了,现在说一下在服务端验证客户端证书的方案. 这里给出的方案比较简单,只需要在Service端的配置文件中 ...

  3. 样本打散后计算单特征 NDCG

    单特征 NDCG 能计算模型的 NDCG,也就能计算单特征的 NDCG,用于评估单特征的有效性,跟 Group AUC 用途一样 单特征 NDCG 如何衡量好坏 如果是 AUC,越大于或小于 0.5, ...

  4. Jmeter 中多线程并发和循环控制器

    今天遇到一个场景, 给一个手机号发送短信验证码,通过正确输入短信验证码即登录并获得token,进行其他操作. 短信验证码是4位,即9999个组合, 接口没有对验证次数做校验,所以可以一直一直尝试通过验 ...

  5. servlet生命周期深入理解

    什么是Servlet Java Servlet 是运行在 Web 服务器或应用服务器上的程序,它是作为来自 Web 浏览器或其他 HTTP 客户端的请求和 HTTP 服务器上的数据库或应用程序之间的中 ...

  6. LIBS+=

    ZC: “LIBS+=”是要结合“LIBPATH += ”一起使用的?类似下面的用法: ZC: “LIBS+=”指明lib文件的名称,“LIBPATH += ”指明lib文件的路径.最后还要把DLL文 ...

  7. Spring AMQP 源码分析 08 - XML 配置

    ### 准备 ## 目标 通过 XML 配置文件使用 Spring AMQP ## 前置知识 <Spring AMQP 源码分析 07 - MessageListenerAdapter> ...

  8. OpenGL入门程序四:颜色模式

    1.OpenGL支持两种颜色模式: 1>RGBA颜色模式 ,用 glClearColor 指定清空屏幕后的颜色,即“空颜色” . 2>索引颜色模式,用 glClearIndex 指定清空屏 ...

  9. Java 常用对象-Object类

    2017-10-31 23:42:08 Object类:类 Object 是类层次结构的根类.每个类都使用 Object 作为超类.所有对象(包括数组)都实现这个类的方法. 或者说,每个类都直接或者间 ...

  10. WPF几种高级绑定

    (1)Binding  + RelativeSource + AncestorType 模式  , 根据关联源所指定的类型,可动态绑定指定类型的Path属性(Path可以省略)(PS:动态指父级在运行 ...