<script>
function addFile_btn() {
var file = $("#onefile")[0].files[0],size = file.size;
if (file == null) {swal({ text: '还未选择任何文件', button: false, icon: 'warning', timer: 1500 });return;}
if (size / 1024 / 1024 > 50) { swal({ text: "文件大小不能超过50M", button: '确认', icon: 'warning' }); return false; }
var formData = new FormData();
formData.append("file", file);
$.ajax({
url: '/Service/EasyUiService.ashx?Method=addfile', type: 'post', dataType: 'json', data: formData, contentType: false, processData: false, success: function (d) {
if (d.code == 200) {
var node = $("#summernote").summernote("code");
$("#summernote").summernote("code", node + "<a href='" + d.data + "'>" + d.fname + "</a>"), $("#addFile_modal").modal("hide");
} else { swal({ text: "文件上传失败!", button: false, icon: "warning", timer: 2000 });}
}
})
}
$("#summernote").summernote({
placeholder: '截图与描述', table: 2, height: 280, lang: 'zh-CN',
toolbar: [['style', ['style']],
['font', ['bold', 'italic', 'underline', 'strikethrough', 'superscript', 'subscript', 'clear']], ['fontname', ['fontname']],
['fontsize', ['fontsize']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']],
['height', ['height']],
['table', ['table']],
['insert', ['link', 'picture','file', 'hr', 'video']],
['view', ['fullscreen', 'codeview']],
['help', ['help']],
], buttons: { "file": fileAdd },
callbacks: {
onMediaDelete: function (file, editor, $editable) {
if (imgUrl == "") return;
$.ajax({
url: '/Service/EasyUiService.ashx?Method=RemoveImg', type: 'post', dataType: 'json', data: { 'file': imgUrl }, success: function (d) {
console.log('移除成功!');
}
})
},
onImageUpload: function (file, editor, $editable) {
var size = file[0].size;
if (size / 1024 / 1024 > 2) { swal({ text: "图片大小不能超过2M", button: '确认', icon: 'warning' }); return false; }
var gs = file[0].name;
if (gs != "") { gs = gs.substring(gs.indexOf(".") + 1, gs.length), gs = gs.toUpperCase(); }
if (gs != "PNG" && gs != "TIFF" && gs != "BMP" && gs != "GIF" && gs != "PSD" && gs != "TGA" && gs != "EPS" && gs != "JPEG") {
swal({ text: "格式不允许", button: '确认', icon: 'warning' }); return false;
}
var formData = new FormData();
formData.append("file", file[0]);
$.ajax({
url: '/Service/EasyUiService.ashx?Method=addfile', type: 'post', dataType: 'json', contentType: false, processData: false, data: formData, success: function (d) {
d.code == 200 ? (imgUrl = d.data, $("#summernote").summernote("insertImage", d.data, "img")) : (swal({ text: "图片上传失败!", button: false, icon: "warning", timer: 2000 }));
}
})
}
}
})
function addFile_btn() {
var file = $("#onefile")[0].files[0],size = file.size;
if (file == null) {swal({ text: '还未选择任何文件', button: false, icon: 'warning', timer: 1500 });return;}
if (size / 1024 / 1024 > 50) { swal({ text: "文件大小不能超过50M", button: '确认', icon: 'warning' }); return false; }
var formData = new FormData();
formData.append("file", file);
$.ajax({
url: '/Service/EasyUiService.ashx?Method=addfile', type: 'post', dataType: 'json', data: formData, contentType: false, processData: false, success: function (d) {
if (d.code == 200) {
var node = $("#summernote").summernote("code");
$("#summernote").summernote("code", node + "<a href='" + d.data + "'>" + d.fname + "</a>"), $("#addFile_modal").modal("hide");
} else { swal({ text: "文件上传失败!", button: false, icon: "warning", timer: 2000 });}
}
})
}
var fileAdd = function(content) {
var ui = $.summernote.ui;
var button = ui.button({
contents: '<i class="fa fa-child" /><span class="glyphicon glyphicon-paperclip"></span>',
tooltip: '上传文件',
click: function () {$("#addFile_modal").modal("show");}
})
return button.render();
}
</script>