From 16ee8294cc43a0fcd9e9065735fc46d48b4742de Mon Sep 17 00:00:00 2001 From: Guo XIn <371864209@qq.com> Date: Mon, 3 Jul 2023 16:00:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=AD=97=E5=85=B8=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E7=BB=84=E4=BB=B6=E5=A2=9E=E5=8A=A0=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E5=8F=AA=E8=AF=BB=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../static/js/common/layui/extend/dict.js | 57 +++++++++++-------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/shandan-common/src/main/resources/static/js/common/layui/extend/dict.js b/shandan-common/src/main/resources/static/js/common/layui/extend/dict.js index bc73c95..e9c9d4b 100644 --- a/shandan-common/src/main/resources/static/js/common/layui/extend/dict.js +++ b/shandan-common/src/main/resources/static/js/common/layui/extend/dict.js @@ -158,18 +158,19 @@ layui.define(['form'], function (exports) { } // 设置只读 - this.setReadonly(); + if (this.readonly) { + this.setReadonly(); + } } /** * 设置组件已读 */ setReadonly() { - if (this.readonly) { - // 设置延迟执行,确保在所有组件渲染完成后再设置只读,否则被layui的render方法执行后会将该只读设置重写覆盖而导致失效 - setTimeout(() => { - // 先添加用于覆盖layui样式的内部样式到head中 - $('head').append(` + // 设置延迟执行,确保在所有组件渲染完成后再设置只读,否则被layui的render方法执行后会将该只读设置重写覆盖而导致失效 + setTimeout(() => { + // 先添加用于覆盖layui样式的内部样式到head中 + $('head').append(` `); - let _elem = this.getElement(); - switch (this.type) { - case "radio": - case "checkbox": - let elements = _elem.parent().find(`input[type="${this.type}"][name="${this.name}"]`); - $.each(elements, function (index) { - let lay_elem = $(this).next(); - // 移除click事件监听 - lay_elem.off('click').addClass('radio-readonly').css('cursor', 'auto'); - }); - break; - case "select": - let lay_elem = _elem.parent().find(`select[name="${this.name}"]`).next(); - lay_elem.addClass('select-readonly'); - lay_elem.find('.layui-select-title').off('click').children().css('cursor', 'auto'); - } - }, 150); - } + let _elem = this.getElement(); + switch (this.type) { + case "radio": + case "checkbox": + let elements = _elem.parent().find(`input[type="${this.type}"][name="${this.name}"]`); + $.each(elements, function (index) { + let lay_elem = $(this).next(); + // 移除click事件监听 + lay_elem.off('click').addClass('radio-readonly').css('cursor', 'auto'); + }); + break; + case "select": + let lay_elem = _elem.parent().find(`select[name="${this.name}"]`).next(); + lay_elem.addClass('select-readonly'); + lay_elem.find('.layui-select-title').off('click').children().css('cursor', 'auto'); + } + }, 150); } /** @@ -386,6 +386,15 @@ layui.define(['form'], function (exports) { console.error('组件未定义:' + id); } }, + setReadonly: function (id) { + if (id) { + _cache.get(id).setReadonly(); + } else { + for (const dict of _cache.values()) { + dict.setReadonly(); + } + } + }, /** * 获取字典项的描述 * @param type 字典类型