51 lines
1.3 KiB
JavaScript
51 lines
1.3 KiB
JavaScript
Tea.context(function () {
|
||
this.platform = "android";
|
||
this.version = this.defaultVersion || "1.0.0";
|
||
this.isUploading = false;
|
||
|
||
if (!Array.isArray(this.uploadedFiles)) {
|
||
this.uploadedFiles = [];
|
||
}
|
||
|
||
this.beforeUpload = function () {
|
||
var maxSize = 20 * 1024 * 1024; // 20MB
|
||
var inputs = document.querySelectorAll("input[type=file]");
|
||
for (var i = 0; i < inputs.length; i++) {
|
||
var files = inputs[i].files;
|
||
if (files != null && files.length > 0) {
|
||
if (files[0].size > maxSize) {
|
||
teaweb.warn("文件 \"" + files[0].name + "\" 超过 20MB 限制(" + (files[0].size / 1024 / 1024).toFixed(1) + "MB),请压缩后重试");
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
this.isUploading = true;
|
||
};
|
||
|
||
this.doneUpload = function () {
|
||
this.isUploading = false;
|
||
};
|
||
|
||
this.successUpload = function () {
|
||
teaweb.success("上传成功", function () {
|
||
window.location = "/httpdns/apps/sdk?appId=" + this.app.id;
|
||
}.bind(this));
|
||
};
|
||
|
||
this.deleteUploadedFile = function (filename) {
|
||
let that = this;
|
||
teaweb.confirm("确定要删除文件 " + filename + " 吗?", function () {
|
||
that.$post("/httpdns/apps/sdk/upload/delete")
|
||
.params({
|
||
appId: that.app.id,
|
||
filename: filename
|
||
})
|
||
.success(function () {
|
||
teaweb.success("删除成功", function () {
|
||
window.location.reload();
|
||
});
|
||
});
|
||
});
|
||
};
|
||
});
|