//文件上传处理 var obj = null; function changeImg(e) { let reads = new FileReader(); reads.readAsDataURL($(e).get(0).files[0]); if ($(e).get(0).files[0].size / 1000 > 500) { layer.alert('上传的图片文件不能超过500KB。', {icon: 5}); return; } reads.onload = function (ee) { let image = new Image(); image.src = ee.target.result; image.onload = function () { if (this.width > this.height) { layer.alert("请上传竖图!", {icon: 5}); return; } else { var img = $(e).prev().get(0); var formData = new FormData(); formData.append("uploadImg", $(e).get(0).files[0]); $.ajax({ url: 'https://event.geexek.com/upload/file.do', /*接口域名地址*/ type: 'post', data: formData, contentType: false, processData: false, success: function (res) { console.log(res); if (res.code == "1") { // 获取返回URL img.src = res.result; $(img).parent().attr('data-file', res.result); setTimeout(function () { $(img).removeClass('add'); }, 500) } else { console.log(res); } } }) } }; }; } $(function () { $('body').on('change', '.saveFile', function (e) { changeImg($(this)) }) obj = $('.copy').clone(); $('body').on('click', '.delBtn', function () { let parent = $(this).parents('.saveLine'); let id = parent.find('.manualId').val(); qikoo.dialog.confirm('确认要删除?', function () { //确认 $.ajax({ url: '/gk/cmpt/manual/delManual?id=' + id, /*接口域名地址*/ type: 'post', contentType: 'application/json', processData: false, success: function (res) { parent.remove(); console.log(res); if (res.code == "1") { layer.msg('保存成功', {icon: 1, time: 1500}); } else { console.log(res); } } }); }, function () { }); }); $('body').on('click', '.saveBtn', function () { let catalogPhotoURL = $(this).parents('.saveLine').find('.cataFile').attr('src'); let visibility = ''; let parent = $(this).parents('.saveLine'); let name = parent.find('.one input').val(); let id = parent.find('.manualId').val(); if (parent.find('.filecheck').prop('checked')) { visibility = '1'; } else { visibility = '0'; } //获取file对象 let filedata = parent.find('.file').attr('data-file'); if (!filedata || !catalogPhotoURL) { layer.msg('请选择上传的文件', {icon: 1, time: 1500}); return; } $.ajax({ url: '/gk/cmpt/manual/saveManual', /*接口域名地址*/ type: 'post', data: JSON.stringify({ 'id': id, 'name': name, 'visibility': visibility, 'catalogPhotoURL': catalogPhotoURL, 'cmptId': getCmptId() }), contentType: 'application/json', processData: false, success: function (res) { console.log(res); if (res.code == 200) { layer.msg('保存成功', {icon: 1, time: 1500}); if (!id) { parent.find('.manualId').val(res.id); } } else { console.log(res); } } }); }); }); function cmptManaulInsert() { $('.tbody').append(obj.clone().removeClass("hide-class")); }