Commit 898261cc by 前端

Merge branch 'v1.0.7' of http://192.168.3.233:8090/glsx/gl_tape into v1.0.7

2 parents f328f2be 5af0605a
......@@ -472,7 +472,7 @@ export default {
}
}
.record-list {
height: calc(100% - 252rpx);
height: calc(100% - 248rpx);
position: relative;
z-index: 4;
}
......
......@@ -2,110 +2,96 @@ class OSSUpLoader {
/**
* yourRegion填写Bucket所在地域。以华东1(杭州)为例,yourRegion填写为oss-cn-hangzhou。
*/
region = "oss-cn-shenzhen";
region = 'oss-cn-shenzhen'
/**
* 填写Bucket名称。
*/
bucket = "glsk-oss";
bucket = 'glsk-oss'
/**
* 文件的 MIME 类型
*/
mime = "audio/mp3";
mime = 'audio/mp3'
/**
* 本地保存文件路径(待上传文件路径)
*/
filePath;
filePath
/**
* 从STS服务获取的临时访问密钥(AccessKey ID和AccessKey Secret)。
*/
accessKeyId;
accessKeyId
/**
* 从STS服务获取的安全令牌(SecurityToken)。
*/
accessKeySecret;
accessKeySecret
/**
* 从STS服务获取的安Token。
*/
stsToken;
stsToken
/**
* OSS 文件上传实例
*/
client = null;
client = null
/**
* 同时上传的最大任务数
*/
parallel = 4;
parallel = 4
/**
* 每个上传分片的大小(字节)。默认500kb。
*/
partSize = 500;
partSize = 500
/**
* 最小文件大小
*/
minPartSize = 100;
minPartSize = 100
/**
* 上传任务的超时时间(毫秒):默认60
*/
timeout = 60 * 1000;
timeout = 60 * 1000
// headers,
/**
* 自定义元数据,通过HeadObject接口可以获取Object的元数据。
*/
meta = {};
meta = {}
/**
* 初始化重传次数
*/
retryCount = 0;
retryCount = 0
/**
* 上传失败时的最大重试次数
*/
retryCountMax = 3;
retryCountMax = 3
/**
* 上传失败时的重试间隔时间(毫秒)
*/
retryInterval = 3 * 1000;
currentCheckpoint;
retryInterval = 3 * 1000
currentCheckpoint
/**
* OSS 存储桶中的目标文件夹路径
*/
ossFolder = "quality/";
ossFolder = 'quality/'
/**
* 构造函数
*/
constructor({
region = this.region,
bucket = this.bucket,
accessKeyId,
accessKeySecret,
stsToken,
mime = this.mime,
partSize = this.partSize,
parallel = this.parallel,
timeout = this.timeout,
filePath,
retryCountMax = this.retryCountMax,
retryInterval = this.retryInterval,
ossFolder = this.ossFolder,
}) {
constructor({ region = this.region, bucket = this.bucket, accessKeyId, accessKeySecret, stsToken, mime = this.mime, partSize = this.partSize, parallel = this.parallel, timeout = this.timeout, filePath, retryCountMax = this.retryCountMax, retryInterval = this.retryInterval, ossFolder = this.ossFolder }) {
if (partSize < this.minPartSize) {
throw new Error(common.constants.CODE.FILE_PART_SIZE_TOO_SMALL);
throw new Error(common.constants.CODE.FILE_PART_SIZE_TOO_SMALL)
}
this.mime = mime;
this.partSize = partSize;
this.parallel = parallel;
this.timeout = timeout;
this.filePath = filePath;
this.retryCountMax = retryCountMax;
this.retryInterval = retryInterval;
this.ossFolder = ossFolder;
this.mime = mime
this.partSize = partSize
this.parallel = parallel
this.timeout = timeout
this.filePath = filePath
this.retryCountMax = retryCountMax
this.retryInterval = retryInterval
this.ossFolder = ossFolder
//实例化OSS
this.client = new OSS({
region,
bucket,
accessKeyId,
accessKeySecret,
stsToken,
});
stsToken
})
}
/**
* 上传文件到指定的 OSS 存储空间
......@@ -118,12 +104,12 @@ class OSSUpLoader {
this.filePath + fileName,
function (result) {
if (result.code === common.constants.CODE.FILE_PATH_TRANSFORM_SUCCESS) {
this._upload(fileName, result.data.file, callback);
this._upload(fileName, result.data.file, callback)
} else {
callback(result);
callback(result)
}
}.bind(this)
);
)
}
/**
......@@ -140,58 +126,58 @@ class OSSUpLoader {
.multipartUpload(this.ossFolder + fileName, file, {
// 获取分片上传进度、断点和返回值。
progress: (p, checkpoint, res) => {
this.currentCheckpoint = checkpoint;
console.log(p);
this.currentCheckpoint = checkpoint
console.log(p)
},
// 设置并发上传的分片数量。
parallel: this.parallel,
//分片大小(kb) 最小为100kb 默认500kb
partSize: 1024 * this.partSize,
timeout: this.timeout,
mime: this.mime,
mime: this.mime
})
.then((res) => {
.then(res => {
// console.log(JSON.stringify(res),res.status,res.status==200)
if (res.res.statusCode == 200) {
// console.log('upload success: %j', JSON.stringify(res));
this.currentCheckpoint = null;
this.retryCount = 0;
this.currentCheckpoint = null
this.retryCount = 0
callback(
common.genCallBacks("FILE_UPLOAD_OSS_SUCCESS", {
oss: res,
common.genCallBacks('FILE_UPLOAD_OSS_SUCCESS', {
oss: res
})
);
)
} else {
callback(
common.genCallBacks("FILE_UPLOAD_OSS_FAIL", {
common.genCallBacks('FILE_UPLOAD_OSS_FAIL', {
errMsg: `OSS返回错误 状态码: ${res.status}`,
oss: res,
oss: res
})
);
)
}
})
.catch((err) => {
console.error(err);
console.log(`err.name : ${err.name}`);
console.log(`err.message : ${err.message}`);
.catch(err => {
console.error(err)
console.log(`err.name : ${err.name}`)
console.log(`err.message : ${err.message}`)
// if (err.name.toLowerCase().indexOf('connectiontimeout') !== -1) {
// timeout retry
if (this.retryCount < this.retryCountMax) {
this.retryCount++;
console.error(`retryCount : ${this.retryCount}`);
this.retryCount++
console.error(`retryCount : ${this.retryCount}`)
setTimeout(() => {
this._upload(fileName, file, callback);
}, this.retryInterval);
this._upload(fileName, file, callback)
}, this.retryInterval)
} else {
callback(
common.genCallBacks("FILE_UPLOAD_OSS_TIMEOUT_OR_OTHER", {
common.genCallBacks('FILE_UPLOAD_OSS_TIMEOUT_OR_OTHER', {
errMsg: err.message,
err,
err
})
);
)
}
// }
});
})
}
/**
......@@ -203,39 +189,39 @@ class OSSUpLoader {
* @throws {Error} 如果请求过程中发生错误,将抛出错误
*/
_pathToFile(filePath, callback) {
window.webkitURL = window.webkitURL || window.URL;
var xhr = new XMLHttpRequest();
xhr.open("GET", filePath, true);
xhr.responseType = "blob";
window.webkitURL = window.webkitURL || window.URL
var xhr = new XMLHttpRequest()
xhr.open('GET', filePath, true)
xhr.responseType = 'blob'
xhr.onload = function () {
if (this.status == 200) {
var file = this.response;
var file = this.response
callback(
common.genCallBacks("FILE_PATH_TRANSFORM_SUCCESS", {
file,
common.genCallBacks('FILE_PATH_TRANSFORM_SUCCESS', {
file
})
);
)
} else {
callback(common.genCallBacks("FILE_PATH_TRANSFORM_FAIL"));
callback(common.genCallBacks('FILE_PATH_TRANSFORM_FAIL'))
}
};
}
xhr.onerror = function (errType, errMsg) {
callback(
common.genCallBacks("FILE_PATH_REQUEST_FAIL", {
common.genCallBacks('FILE_PATH_REQUEST_FAIL', {
errType,
errMsg,
errMsg
})
);
};
xhr.send();
)
}
xhr.send()
}
/**
* 销毁当前实例对象,释放资源并重置状态
* 该方法将重置上传器的重试次数为 0,并将客户端实例置为 null
*/
destroy() {
this.retryCount = 0;
this.client = null;
this.retryCount = 0
this.client = null
}
}
......@@ -247,17 +233,17 @@ const common = {
FILE_PATH_TRANSFORM_FAIL: 2,
FILE_UPLOAD_OSS_SUCCESS: 0,
FILE_UPLOAD_OSS_FAIL: 3,
FILE_UPLOAD_OSS_TIMEOUT_OR_OTHER: 4,
FILE_UPLOAD_OSS_TIMEOUT_OR_OTHER: 4
},
MESSAGE: {
FILE_PATH_TRANSFORM_SUCCESS: "文件转换成功",
FILE_PATH_REQUEST_FAIL: "文件转换请求失败",
FILE_PATH_TRANSFORM_FAIL: "文件转换失败",
FILE_UPLOAD_OSS_SUCCESS: "文件上传至OSS成功",
FILE_UPLOAD_OSS_FAIL: "文件上传至OSS失败",
FILE_UPLOAD_OSS_TIMEOUT_OR_OTHER: "文件上传至OSS超时或其他错误",
FILE_PART_SIZE_TOO_SMALL: "分片大小不能小于100kb",
},
FILE_PATH_TRANSFORM_SUCCESS: '文件转换成功',
FILE_PATH_REQUEST_FAIL: '文件转换请求失败',
FILE_PATH_TRANSFORM_FAIL: '文件转换失败',
FILE_UPLOAD_OSS_SUCCESS: '文件上传至OSS成功',
FILE_UPLOAD_OSS_FAIL: '文件上传至OSS失败',
FILE_UPLOAD_OSS_TIMEOUT_OR_OTHER: '文件上传至OSS超时或其他错误',
FILE_PART_SIZE_TOO_SMALL: '分片大小不能小于100kb'
}
},
/**
* 生成回调对象
......@@ -267,11 +253,11 @@ const common = {
* @return {Object} 回调对象
*/
genCallBacks(key, data = {}) {
const { CODE, MESSAGE } = common.constants;
const { CODE, MESSAGE } = common.constants
return {
code: CODE[key],
message: MESSAGE[key],
data,
};
},
};
data
}
}
}
......@@ -43,6 +43,7 @@ export default {
} else {
this.reportError(recordId,filePathOnClient)
this.polling()
this.$sendSentry(`上传失败:文件名-${fileName} 错误码-${data.oss.res.status},失败原因-${JSON.stringify(data.oss.res)}`);
}
},
/**
......
......@@ -9,8 +9,6 @@
<view
class="detail-box"
@dblclick="dbClick"
@touchstart.stop="touchStart"
@touchend.stop="touchEnd"
>
<view class="nav-bar">
<view
......@@ -28,6 +26,8 @@
<view
:class="['view', { showView: id == item.id }]"
:key="index"
@touchstart.stop="touchStart"
@touchend.stop="touchEnd"
>
<component
:is="item.componentName"
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!