From 43a2e04f031cf85f36a87067d2fda4b7ed90d235 Mon Sep 17 00:00:00 2001 From: Anyon Date: Mon, 11 Jul 2022 19:23:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=9B=BE=E7=89=87=E8=A3=81?= =?UTF-8?q?=E5=89=AA=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit data-cut-width data-cut-height --- app/admin/view/api/upload.js | 8 ++++++-- public/static/admin.js | 12 +++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/admin/view/api/upload.js b/app/admin/view/api/upload.js index ebca802ab..8d9c222e5 100644 --- a/app/admin/view/api/upload.js +++ b/app/admin/view/api/upload.js @@ -15,6 +15,8 @@ define(['md5', 'notify'], function (SparkMD5, Notify, allowMime) { this.option.quality = parseFloat(this.option.elem.data('quality') || '1.0'); this.option.maxWidth = parseInt(this.option.elem.data('max-width') || '0'); this.option.maxHeight = parseInt(this.option.elem.data('max-height') || '0'); + this.option.cutHeight = parseInt(this.option.elem.data('cut-height') || '0'); + this.option.cutHeight = parseInt(this.option.elem.data('cut-height') || '0'); /*! 查找表单元素, 如果没有找到将不会自动写值 */ if (!this.option.elem.data('input') && this.option.elem.data('field')) { @@ -36,6 +38,8 @@ define(['md5', 'notify'], function (SparkMD5, Notify, allowMime) { file.quality = that.option.quality; file.maxWidth = that.option.maxWidth; file.maxHeight = that.option.maxHeight; + file.cutWidth = that.option.cutWidth; + file.cutHeight = that.option.cutHeight; }); that.adapter.event('upload.choose', obj.items); that.adapter.upload(obj.items, done); @@ -75,10 +79,10 @@ define(['md5', 'notify'], function (SparkMD5, Notify, allowMime) { // 禁传异常状态文件 if (typeof file.xstate === 'number' && file.xstate === -1) return; // 图片限宽限高压缩 - if (/^image\//.test(file.type) && (file.maxWidth > 0 || file.maxHeight > 0 || file.quality !== 1)) { + if (/^image\//.test(file.type) && (file.maxWidth + file.maxHeight + file.cutWidth + file.cutHeight > 0 || file.quality !== 1)) { require(['compressor'], function (Compressor) { new Compressor(file, { - quality: file.quality, maxWidth: file.maxWidth, maxHeight: file.maxHeight, success(blob) { + quality: file.quality, resize: 'cover', width: file.cutWidth || 0, height: file.cutHeight || 0, maxWidth: file.maxWidth, maxHeight: file.maxHeight, success(blob) { files[index] = blob, blob.index = file.index, files[index].notify = file.notify; that.hash(files[index]).then(function (file) { that.event('upload.hash', file).request(file, done); diff --git a/public/static/admin.js b/public/static/admin.js index cefb1e354..bde40b34e 100644 --- a/public/static/admin.js +++ b/public/static/admin.js @@ -584,11 +584,7 @@ $(function () { return this.each(function () { if ($(this).data('inited')) return true; else $(this).data('inited', true); var $in = $(this), $bt = $('').data('input', this); - $bt.attr('data-size', $in.data('size') || 0).attr('data-type', $in.data('type') || 'mp4') - .attr('data-max-width', $in.data('max-width')) - .attr('data-max-height', $in.data('max-height')) - - .find('span').on('click', function (event) { + $bt.attr('data-size', $in.data('size') || 0).attr('data-type', $in.data('type') || 'mp4').find('span').on('click', function (event) { event.stopPropagation(); if ($(this).index() === 0) $bt.attr('style', ''), $in.val(''); else $in.val() && $.previewImage(encodeURI($in.val())); }), $in.on('change', function () { @@ -611,7 +607,8 @@ $(function () { event.stopPropagation(), $bt.attr('style', ''), $in.val(''); }).find('[data-file]').data('input', this).attr({ 'data-size': $in.data('size') || 0, 'data-type': $in.data('type') || 'gif,png,jpg,jpeg', - 'data-max-width': $in.data('max-width') || 0, 'data-max-height': $in.data('max-height') || 0 + 'data-max-width': $in.data('max-width') || 0, 'data-max-height': $in.data('max-height') || 0, + 'data-cut-width': $in.data('cut-width') || 0, 'data-cut-height': $in.data('cut-height') || 0, }); }); }; @@ -624,7 +621,8 @@ $(function () { var ims = this.value ? this.value.split('|') : [], $in = $(this).after($bt); $bt.find('[data-file]').attr({ 'data-size': $in.data('size') || 0, 'data-type': $in.data('type') || 'gif,png,jpg,jpeg', - 'data-max-width': $in.data('max-width') || 0, 'data-max-height': $in.data('max-height') || 0 + 'data-max-width': $in.data('max-width') || 0, 'data-max-height': $in.data('max-height') || 0, + 'data-cut-width': $in.data('cut-width') || 0, 'data-cut-height': $in.data('cut-height') || 0, }).on('push', function (evt, src) { ims.push(src), $in.val(ims.join('|')), showImageContainer([src]); }) && (ims.length > 0 && showImageContainer(ims));