main
黄海 1 year ago
parent 7102f73fb1
commit 4f133eec70

@ -17,7 +17,7 @@
+ 4.表单数据的获取与回显,禁用全表单 + 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) { , function (exports) {
var $ = layui.jquery var $ = layui.jquery
, layer = layui.layer , layer = layui.layer
@ -662,8 +662,8 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme
_html += '<textarea name="{0}" placeholder="{3}" width="{2}" class="layui-textarea{6}" {4} {5} {7}>{1}</textarea>' _html += '<textarea name="{0}" placeholder="{3}" width="{2}" class="layui-textarea{6}" {4} {5} {7}>{1}</textarea>'
.format(json.id, json.defaultValue ? json.defaultValue : '', json.width, json.placeholder, _disabled, _required, _disabledClass, _readonly); .format(json.id, json.defaultValue ? json.defaultValue : '', json.width, json.placeholder, _disabled, _required, _disabledClass, _readonly);
$('#' + json.id + ' .layui-input-block').append(_html); $('#' + json.id + ' .layui-input-block').append(_html);
$label.css({width: '{0}'.format(json.width)}); $label.css({ width: '{0}'.format(json.width) });
$block.css({width: '{0}'.format(json.width)}); $block.css({ width: '{0}'.format(json.width) });
if (json.required) { if (json.required) {
$label.append('<span style="color:red;">*</span>'); $label.append('<span style="color:red;">*</span>');
} }
@ -796,15 +796,15 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme
} }
$label.append(json.label + ":"); $label.append(json.label + ":");
form.render('select', json.id); 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) { if (json.hideLabel) {
$label.css("display", "none"); $label.css("display", "none");
$block.css("margin-left", "0px"); $block.css("margin-left", "0px");
$block.css({width: 'calc({0})'.format(json.width)}); $block.css({ width: 'calc({0})'.format(json.width) });
} else { } else {
$label.css("display", "block"); $label.css("display", "block");
$block.css("margin-left", json.labelWidth); $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) { if (json.hideLabel) {
$label.css("display", "none"); $label.css("display", "none");
$block.css("margin-left", "0px"); $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 { } else {
$label.css("display", "block"); $label.css("display", "block");
$block.css("margin-left", json.labelWidth); $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 = ''; var _html = '';
//重绘设计区改id下的所有元素 //重绘设计区改id下的所有元素
@ -1186,11 +1186,11 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme
$label.css("display", "none"); $label.css("display", "none");
$block.css("margin-left", "0px"); $block.css("margin-left", "0px");
$block.css("border", "0px"); $block.css("border", "0px");
$block.css({width: 'calc({0})'.format(json.width)}); $block.css({ width: 'calc({0})'.format(json.width) });
} else { } else {
$label.css("display", "block"); $label.css("display", "block");
$block.css("margin-left", json.labelWidth); $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.css("width", json.labelWidth);
form.render('checkbox'); form.render('checkbox');
@ -1301,11 +1301,11 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme
if (json.hideLabel) { if (json.hideLabel) {
$label.css("display", "none"); $label.css("display", "none");
$block.css("margin-left", "0px"); $block.css("margin-left", "0px");
$block.css({width: 'calc({0})'.format(json.width)}); $block.css({ width: 'calc({0})'.format(json.width) });
} else { } else {
$label.css("display", "block"); $label.css("display", "block");
$block.css("margin-left", json.labelWidth); $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({ slider.render({
elem: '#' + json.tag + json.id, elem: '#' + json.tag + json.id,
@ -1439,11 +1439,11 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme
if (json.hideLabel) { if (json.hideLabel) {
$label.css("display", "none"); $label.css("display", "none");
$block.css("margin-left", "0px"); $block.css("margin-left", "0px");
$block.css({width: 'calc({0})'.format(json.width)}); $block.css({ width: 'calc({0})'.format(json.width) });
} else { } else {
$label.css("display", "block"); $label.css("display", "block");
$block.css("margin-left", json.labelWidth); $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.css("width", json.labelWidth);
if (json.required) { if (json.required) {
@ -1968,7 +1968,7 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme
_html += '</div>'; _html += '</div>';
elem.append(_html); elem.append(_html);
if (that.config.viewOrDesign) { 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); images.push(data);
} }
}, },
@ -2093,7 +2093,7 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme
_html += '</div>'; _html += '</div>';
elem.append(_html); elem.append(_html);
if (that.config.viewOrDesign) { 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); files.push(data);
} }
}, },
@ -2563,11 +2563,11 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme
if (json.hideLabel) { if (json.hideLabel) {
$label.css("display", "none"); $label.css("display", "none");
$block.css("margin-left", "0px"); $block.css("margin-left", "0px");
$block.css({width: 'calc({0})'.format(json.width)}); $block.css({ width: 'calc({0})'.format(json.width) });
} else { } else {
$label.css("display", "block"); $label.css("display", "block");
$block.css("margin-left", json.labelWidth); $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.css("width", json.labelWidth);
$label.append(json.label + ":"); $label.append(json.label + ":");
@ -2892,11 +2892,11 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme
if (json.hideLabel) { if (json.hideLabel) {
$label.css("display", "none"); $label.css("display", "none");
$block.css("margin-left", "0px"); $block.css("margin-left", "0px");
$block.css({width: 'calc({0})'.format(json.width)}); $block.css({ width: 'calc({0})'.format(json.width) });
} else { } else {
$label.css("display", "block"); $label.css("display", "block");
$block.css("margin-left", json.labelWidth); $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.css("width", json.labelWidth);
if (json.required) { if (json.required) {
@ -3068,11 +3068,11 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme
if (json.hideLabel) { if (json.hideLabel) {
$label.css("display", "none"); $label.css("display", "none");
$block.css("margin-left", "0px"); $block.css("margin-left", "0px");
$block.css({width: 'calc({0})'.format(json.width)}); $block.css({ width: 'calc({0})'.format(json.width) });
} else { } else {
$label.css("display", "block"); $label.css("display", "block");
$block.css("margin-left", json.labelWidth); $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.css("width", json.labelWidth);
$label.append(json.label + ":"); $label.append(json.label + ":");
@ -3623,7 +3623,7 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme
, options = that.config; , options = that.config;
$('#select-option-add').on('click', function () { $('#select-option-add').on('click', function () {
//添加html //添加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 = ''; var _htmloption = '';
_htmloption += '<div class="layui-form-item option select-options" data-index="{0}">'.format(json.options.length - 1); _htmloption += '<div class="layui-form-item option select-options" data-index="{0}">'.format(json.options.length - 1);
_htmloption += ' <div class="layui-inline" style="width: 30px; margin-right: 0px;">'; _htmloption += ' <div class="layui-inline" style="width: 30px; margin-right: 0px;">';
@ -4366,6 +4366,7 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme
case 'checkbox-value': case 'checkbox-value':
//找到 id=key 下的 option值 //找到 id=key 下的 option值
var _index = parseInt($(this).parent().parent().attr("data-index")); var _index = parseInt($(this).parent().parent().attr("data-index"));
alert(_index);
if (_key === 'select-text' || _key === 'radio-text' || _key === 'checkbox-text') { if (_key === 'select-text' || _key === 'radio-text' || _key === 'checkbox-text') {
_json.options[_index].text = $(this).val(); _json.options[_index].text = $(this).val();
} else { } else {
@ -4406,8 +4407,15 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme
}); });
form.on('radio', function (data) { 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; var _json = options.selectItem;
console.log(_json);
switch (_json.tag) { switch (_json.tag) {
case 'radio': case 'radio':
var _index = parseInt($("#" + _json.id + " .layui-input-block div.layui-form-radio").index(data.othis[0])); 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: default:
break; break;
} }
}) });
form.on('checkbox', function (data) { form.on('checkbox', function (data) {
var _json = options.selectItem; var _json = options.selectItem;
switch (_json.tag) { switch (_json.tag) {
@ -4460,6 +4471,7 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme
break; break;
} }
}); });
} }
/*--------------------------------------------------以下属于非修改内容---------------------------------------------------------*/ /*--------------------------------------------------以下属于非修改内容---------------------------------------------------------*/
@ -4513,7 +4525,6 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme
var that = this var that = this
, options = that.config; , options = that.config;
//增加于2024-02-02 黄海
options.data.forEach(function (item, index) { options.data.forEach(function (item, index) {
if (index === 0) { if (index === 0) {
options.selectItem = item; options.selectItem = item;
@ -4827,7 +4838,6 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme
}); });
}); });
that.renderForm(); that.renderForm();
} }
@ -4984,6 +4994,7 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme
var json = form.val(); var json = form.val();
for (let key in iceEditorObjects) { for (let key in iceEditorObjects) {
json[key] = iceEditorObjects[key].getHTML(); json[key] = iceEditorObjects[key].getHTML();
} }
@ -5054,7 +5065,8 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme
/* 重新渲染设计区*/ /* 重新渲染设计区*/
Class.prototype.renderForm = function () { Class.prototype.renderForm = function () {
var that = this, options = that.config; var that = this
, options = that.config;
if (options.viewOrDesign) { if (options.viewOrDesign) {
var that = this var that = this
, options = that.config; , 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.components[tag].property(options.selectItem, that);
that.bindPropertyEvent(options.selectItem); that.bindPropertyEvent();
//移除 #formDesignerForm .layui-form-item 下所有的 active //移除 #formDesignerForm .layui-form-item 下所有的 active
$('#formDesignerForm .layui-form-item').removeClass('active'); $('#formDesignerForm .layui-form-item').removeClass('active');
//给当前元素增加class //给当前元素增加class
@ -5230,6 +5241,7 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme
return undefined; return undefined;
} }
/* 复制json中的节点并返回上一个节点*/ /* 复制json中的节点并返回上一个节点*/
Class.prototype.copyJsonAfterItem = function (json, id) { Class.prototype.copyJsonAfterItem = function (json, id) {
var that = this, var that = this,
@ -5350,5 +5362,6 @@ layui.config({base: './ayq/modules/'}).define(["layer", 'flow', "laytpl", "eleme
return result; return result;
} }
exports('formDesigner', formDesigner); exports('formDesigner'
, formDesigner);
}); });
Loading…
Cancel
Save