From 5579f0042f5e911f9a4545db2fbcc958395d7aea Mon Sep 17 00:00:00 2001 From: lSun <15893999301@qq.com> Date: Tue, 15 Apr 2025 09:35:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../child/importantMatterForm.js | 84 ------------------- .../child/importantMatterForm.html | 8 +- 2 files changed, 4 insertions(+), 88 deletions(-) diff --git a/src/main/resources/static/js/imageUpload/importantMatter/child/importantMatterForm.js b/src/main/resources/static/js/imageUpload/importantMatter/child/importantMatterForm.js index 8bb562f..850a4c5 100644 --- a/src/main/resources/static/js/imageUpload/importantMatter/child/importantMatterForm.js +++ b/src/main/resources/static/js/imageUpload/importantMatter/child/importantMatterForm.js @@ -24,90 +24,6 @@ layui.use(['laydate', 'upload'], function () { sourceTypeName: "重要事项及宣传照片" // 来源类型名称 }) - // 已上传图片计数 - var uploadedCount = 0; - // 最大允许上传数量 - var maxCount = 9; - // 渲染上传组件 - upload.render({ - elem: '#uploadBtn', // 绑定按钮 - url: '/imgTool/sys/file/uploadFile?token=' + tokens, // 上传接口地址 - accept: 'images', // 只允许上传图片 - multiple: true, // 允许多文件上传 - auto: true, // 选择文件后自动上传 - number: 9, // 每次最多选择3个文件 - field: 'files', - data: {params: violation}, - choose: function(obj){ // 选择文件后的回调 - debugger; - // 检查已上传数量 - var files = obj.pushFile(); - console.log(files) - alert(uploadedCount) - // 如果已上传+新选择的数量超过限制 - alert(files.length) - if(uploadedCount + files.length > maxCount){ - var canUpload = maxCount - uploadedCount; - layer.msg('最多上传'+maxCount+'张图片,还可上传'+canUpload+'张'); - // 截断文件数组,只保留可上传数量 - this.files = files.slice(0, canUpload); - // 如果已经没有可上传数量,则阻止上传 - if(canUpload <= 0){ - return false; - } - } - - // 预览图片 - obj.preview(function(index, file, result){ - $('#previewBox').append( - '
' + - ''+ file.name +'' + - '
' + - '' + - '
' + - '
' - ); - }); - }, - before: function(obj){ - // 上传前可以做一些处理 - }, - done: function(res, index, upload){ - // 上传成功回调 - uploadedCount++; - - // 如果已达到最大数量,禁用上传按钮 - if(uploadedCount >= maxCount){ - $('#uploadBtn').addClass('layui-btn-disabled').prop('disabled', true); - } - - // 在实际应用中,这里可以处理服务器返回的数据 - console.log(res); - }, - error: function(index, upload){ - // 上传失败回调 - layer.msg('第'+(index+1)+'张图片上传失败'); - }, - allDone: function(obj){ - // 全部上传完成回调 - console.log('全部上传完成'); - } - }); - - // 删除图片函数 - window.deleteImg = function(index){ - // 这里应该添加删除服务器上图片的逻辑 - // 例如通过AJAX请求删除接口 - // 从预览中移除 - $('.img-item[data-index="'+ index +'"]').remove(); - // 减少计数 - uploadedCount--; - // 重新启用上传按钮 - $('#uploadBtn').removeClass('layui-btn-disabled').prop('disabled', false); - } - - - // 多图片上传 var uploadcom1 = upload.render({ elem: '#test1', diff --git a/src/main/resources/static/pages/imageUpload/importantMatter/child/importantMatterForm.html b/src/main/resources/static/pages/imageUpload/importantMatter/child/importantMatterForm.html index 4a4d029..f95f2f8 100644 --- a/src/main/resources/static/pages/imageUpload/importantMatter/child/importantMatterForm.html +++ b/src/main/resources/static/pages/imageUpload/importantMatter/child/importantMatterForm.html @@ -104,7 +104,7 @@ - + -
+