From 4f133eec70db43eb43d0de9f767fd981f6b1037a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=B5=B7?= <10402852@qq.com> Date: Mon, 5 Feb 2024 08:17:06 +0800 Subject: [PATCH] 'commit' --- .../view/tb/form/ayq/modules/formDesigner.js | 75 +++++++++++-------- 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/WebRoot/view/tb/form/ayq/modules/formDesigner.js b/WebRoot/view/tb/form/ayq/modules/formDesigner.js index cd621d07..5276c333 100644 --- a/WebRoot/view/tb/form/ayq/modules/formDesigner.js +++ b/WebRoot/view/tb/form/ayq/modules/formDesigner.js @@ -17,7 +17,7 @@ + 4.表单数据的获取与回显,禁用全表单 +------------------------------------------------------------------------------------+ */ -layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "element", "form", "slider", "laydate", "rate", "colorpicker", "layedit", "carousel", "upload", "formField", "staticField", "numberInput", "iconPicker", "cron", "labelGeneration"] +layui.config({ base: './ayq/modules/' }).define(["layer", 'flow', "laytpl", "element", "form", "slider", "laydate", "rate", "colorpicker", "layedit", "carousel", "upload", "formField", "staticField", "numberInput", "iconPicker", "cron", "labelGeneration"] , function (exports) { var $ = layui.jquery , layer = layui.layer @@ -662,8 +662,8 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme _html += '' .format(json.id, json.defaultValue ? json.defaultValue : '', json.width, json.placeholder, _disabled, _required, _disabledClass, _readonly); $('#' + json.id + ' .layui-input-block').append(_html); - $label.css({width: '{0}'.format(json.width)}); - $block.css({width: '{0}'.format(json.width)}); + $label.css({ width: '{0}'.format(json.width) }); + $block.css({ width: '{0}'.format(json.width) }); if (json.required) { $label.append('*'); } @@ -796,15 +796,15 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme } $label.append(json.label + ":"); form.render('select', json.id); - $('#' + json.id + ' .layui-input-block div.layui-unselect.layui-form-select').css({width: '{0}'.format(json.width)}); + $('#' + json.id + ' .layui-input-block div.layui-unselect.layui-form-select').css({ width: '{0}'.format(json.width) }); if (json.hideLabel) { $label.css("display", "none"); $block.css("margin-left", "0px"); - $block.css({width: 'calc({0})'.format(json.width)}); + $block.css({ width: 'calc({0})'.format(json.width) }); } else { $label.css("display", "block"); $block.css("margin-left", json.labelWidth); - $block.css({width: 'calc({0} - {1}px)'.format(json.width, json.labelWidth)}); + $block.css({ width: 'calc({0} - {1}px)'.format(json.width, json.labelWidth) }); } }, /** @@ -927,11 +927,11 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme if (json.hideLabel) { $label.css("display", "none"); $block.css("margin-left", "0px"); - $block.css({width: 'calc({0} - {1}px)'.format(json.width, json.labelWidth)}); + $block.css({ width: 'calc({0} - {1}px)'.format(json.width, json.labelWidth) }); } else { $label.css("display", "block"); $block.css("margin-left", json.labelWidth); - $block.css({width: 'calc({0} - {1}px)'.format(json.width, json.labelWidth)}); + $block.css({ width: 'calc({0} - {1}px)'.format(json.width, json.labelWidth) }); } var _html = ''; //重绘设计区改id下的所有元素 @@ -1186,11 +1186,11 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme $label.css("display", "none"); $block.css("margin-left", "0px"); $block.css("border", "0px"); - $block.css({width: 'calc({0})'.format(json.width)}); + $block.css({ width: 'calc({0})'.format(json.width) }); } else { $label.css("display", "block"); $block.css("margin-left", json.labelWidth); - $block.css({width: 'calc({0} - {1}px)'.format(json.width, json.labelWidth)}); + $block.css({ width: 'calc({0} - {1}px)'.format(json.width, json.labelWidth) }); } $label.css("width", json.labelWidth); form.render('checkbox'); @@ -1301,11 +1301,11 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme if (json.hideLabel) { $label.css("display", "none"); $block.css("margin-left", "0px"); - $block.css({width: 'calc({0})'.format(json.width)}); + $block.css({ width: 'calc({0})'.format(json.width) }); } else { $label.css("display", "block"); $block.css("margin-left", json.labelWidth); - $block.css({width: 'calc({0} - {1}px)'.format(json.width, json.labelWidth)}); + $block.css({ width: 'calc({0} - {1}px)'.format(json.width, json.labelWidth) }); } slider.render({ elem: '#' + json.tag + json.id, @@ -1439,11 +1439,11 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme if (json.hideLabel) { $label.css("display", "none"); $block.css("margin-left", "0px"); - $block.css({width: 'calc({0})'.format(json.width)}); + $block.css({ width: 'calc({0})'.format(json.width) }); } else { $label.css("display", "block"); $block.css("margin-left", json.labelWidth); - $block.css({width: 'calc({0} - {1}px)'.format(json.width, json.labelWidth)}); + $block.css({ width: 'calc({0} - {1}px)'.format(json.width, json.labelWidth) }); } $label.css("width", json.labelWidth); if (json.required) { @@ -1968,7 +1968,7 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme _html += ''; elem.append(_html); if (that.config.viewOrDesign) { - var data = {"select": json.tag + json.id, "uploadUrl": json.uploadUrl}; + var data = { "select": json.tag + json.id, "uploadUrl": json.uploadUrl }; images.push(data); } }, @@ -2093,7 +2093,7 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme _html += ''; elem.append(_html); if (that.config.viewOrDesign) { - var data = {"select": json.tag + json.id, "uploadUrl": json.uploadUrl}; + var data = { "select": json.tag + json.id, "uploadUrl": json.uploadUrl }; files.push(data); } }, @@ -2563,11 +2563,11 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme if (json.hideLabel) { $label.css("display", "none"); $block.css("margin-left", "0px"); - $block.css({width: 'calc({0})'.format(json.width)}); + $block.css({ width: 'calc({0})'.format(json.width) }); } else { $label.css("display", "block"); $block.css("margin-left", json.labelWidth); - $block.css({width: 'calc({0} - {1}px)'.format(json.width, json.labelWidth)}); + $block.css({ width: 'calc({0} - {1}px)'.format(json.width, json.labelWidth) }); } $label.css("width", json.labelWidth); $label.append(json.label + ":"); @@ -2892,11 +2892,11 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme if (json.hideLabel) { $label.css("display", "none"); $block.css("margin-left", "0px"); - $block.css({width: 'calc({0})'.format(json.width)}); + $block.css({ width: 'calc({0})'.format(json.width) }); } else { $label.css("display", "block"); $block.css("margin-left", json.labelWidth); - $block.css({width: 'calc({0} - {1}px)'.format(json.width, json.labelWidth)}); + $block.css({ width: 'calc({0} - {1}px)'.format(json.width, json.labelWidth) }); } $label.css("width", json.labelWidth); if (json.required) { @@ -3068,11 +3068,11 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme if (json.hideLabel) { $label.css("display", "none"); $block.css("margin-left", "0px"); - $block.css({width: 'calc({0})'.format(json.width)}); + $block.css({ width: 'calc({0})'.format(json.width) }); } else { $label.css("display", "block"); $block.css("margin-left", json.labelWidth); - $block.css({width: 'calc({0} - {1}px)'.format(json.width, json.labelWidth)}); + $block.css({ width: 'calc({0} - {1}px)'.format(json.width, json.labelWidth) }); } $label.css("width", json.labelWidth); $label.append(json.label + ":"); @@ -3623,7 +3623,7 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme , options = that.config; $('#select-option-add').on('click', function () { //添加html - json.options.splice(json.options.length + 1, 0, {text: 'option', value: 'value', checked: false}); + json.options.splice(json.options.length + 1, 0, { text: 'option', value: 'value', checked: false }); var _htmloption = ''; _htmloption += '
'.format(json.options.length - 1); _htmloption += '
'; @@ -4366,6 +4366,7 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme case 'checkbox-value': //找到 id=key 下的 option值 var _index = parseInt($(this).parent().parent().attr("data-index")); + alert(_index); if (_key === 'select-text' || _key === 'radio-text' || _key === 'checkbox-text') { _json.options[_index].text = $(this).val(); } else { @@ -4406,8 +4407,15 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme }); form.on('radio', function (data) { + + var thisName = $(this).attr("name"); + options.data.forEach(function (item, index) { + if (item.id === thisName) { + options.selectItem = item; + } + }); + var _json = options.selectItem; - console.log(_json); switch (_json.tag) { case 'radio': var _index = parseInt($("#" + _json.id + " .layui-input-block div.layui-form-radio").index(data.othis[0])); @@ -4439,7 +4447,10 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme default: break; } - }) + }); + + + form.on('checkbox', function (data) { var _json = options.selectItem; switch (_json.tag) { @@ -4460,6 +4471,7 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme break; } }); + } /*--------------------------------------------------以下属于非修改内容---------------------------------------------------------*/ @@ -4513,7 +4525,6 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme var that = this , options = that.config; - //增加于2024-02-02 黄海 options.data.forEach(function (item, index) { if (index === 0) { options.selectItem = item; @@ -4827,7 +4838,6 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme }); }); - that.renderForm(); } @@ -4984,6 +4994,7 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme var json = form.val(); + for (let key in iceEditorObjects) { json[key] = iceEditorObjects[key].getHTML(); } @@ -5054,7 +5065,8 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme /* 重新渲染设计区*/ Class.prototype.renderForm = function () { - var that = this, options = that.config; + var that = this + , options = that.config; if (options.viewOrDesign) { var that = this , options = that.config; @@ -5173,8 +5185,7 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme //显示当前的属性 that.components[tag].property(options.selectItem, that); - that.bindPropertyEvent(options.selectItem); - + that.bindPropertyEvent(); //移除 #formDesignerForm .layui-form-item 下所有的 active $('#formDesignerForm .layui-form-item').removeClass('active'); //给当前元素增加class @@ -5230,6 +5241,7 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme return undefined; } + /* 复制json中的节点并返回上一个节点*/ Class.prototype.copyJsonAfterItem = function (json, id) { var that = this, @@ -5350,5 +5362,6 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme return result; } - exports('formDesigner', formDesigner); + exports('formDesigner' + , formDesigner); }); \ No newline at end of file