/* * @Descripttion : * @Author : liuzhifang * @Date : 2022-06-15 11:19:09 * @LastEditors : QianFox Team * @LastEditTime : 2024-08-13 09:21:59 */ // 添加字段 $('.select-field-box .field-item').on('click', function () { let $this = $(this), $diyContainer = $('#previewDiyForm'), $formContainer = $('#diyFormSet'), type = $this.attr('data-type'), diyId = 'diyid' + new Date().getTime(), fieldHtml = '', itemHtml = ''; switch (type) { case 'inputtext': fieldHtml = _inputPreviewHtml(); break; case 'textarea': fieldHtml = _textareaPreviewHtml(); break; case 'radio': fieldHtml = _radioPreviewHtml(); break; case 'checkbox': fieldHtml = _checkboxPreviewHtml(); break; case 'select': fieldHtml = _selectPreviewHtml(); break; case 'switch': fieldHtml = _switchPreviewHtml(); break; case 'datepicker': case 'timepicker': case 'datetimepicker': fieldHtml = _datetimepickerPreviewHtml(type); break; case 'image': fieldHtml = _imagePreviewHtml(); break; case 'color': fieldHtml = _colorPreviewHtml(); break; } switch (type) { case 'inputtext': itemHtml = _inputDiyHtml(); break; case 'textarea': itemHtml = _textareaDiyHtml(); break; case 'radio': itemHtml = _radioDiyHtml(); break; case 'checkbox': itemHtml = _checkboxDiyHtml(); break; case 'select': itemHtml = _selectDiyHtml(); break; case 'switch': itemHtml = _switchDiyHtml(); break; case 'datepicker': case 'timepicker': case 'datetimepicker': itemHtml = _datetimepickerDiyHtml(type); break; case 'image': itemHtml = _imageDiyHtml(); break; case 'color': itemHtml = _colorDiyHtml(); break; } if (fieldHtml && itemHtml) { $diyContainer.append(`
'); $formContainer.append( [ ` ', ].join('') ); $(`#${diyId}`).slideDown(); $(`.foxui-drag-item[data-diyid="${diyId}"]`).slideDown(); } }); // 修改label $(document).on('input', '#diyFormSet .form-label', function () { let $this = $(this), value = $this.val(), id = $this.closest('.foxui-drag-item').attr('data-diyid'); $(`#${id} .form-label`).text(value); }); // 修改 placeholder $(document).on('input', '#diyFormSet .form-input-placeholder', function () { let $this = $(this), value = $this.val(), id = $this.closest('.foxui-drag-item').attr('data-diyid'); $(`#${id} .form-input-placeholder`).attr('placeholder', value); }); // 修改是否必填 $(document).on('click', '#diyFormSet .form-label-require', function () { let $this = $(this), isChecked = $this.is('.is-checked'), id = $this.closest('.foxui-drag-item').attr('data-diyid'), $label = $(`#${id} .form-label`); isChecked ? $label.addClass('foxui-required') : $label.removeClass('foxui-required'); }); // 删除选项 $(document).on('click', '#diyFormSet .delete-option-btn', function () { let $this = $(this), $option = $this.closest('.foxui-input-group'), index = $option.index(), id = $this.closest('.foxui-drag-item').attr('data-diyid'), len = $(`#${id}`).find('.form-option').length; $(`#${id}`) .find('.form-option') .eq(index) .fadeOut(function () { $(this).remove(); }); $option.slideUp(function () { $(this).remove(); }); if (len <= 2) { $('#diyFormSet').find('.delete-option-btn').attr('disabled', true).addClass('is-disabled'); } }); // 添加选项 $(document).on('click', '#diyFormSet .add-option-btn', function () { let $this = $(this), $optionContainer = $this.parent().siblings('.option-box'), $option = $optionContainer.find('.foxui-input-group'), type = $this.attr('data-type'), len = $option.length, id = $this.closest('.foxui-drag-item').attr('data-diyid'), html = '', optionHtml = ''; if (len < 2) { $option.find('.delete-option-btn').attr('disabled', false).removeClass('is-disabled'); } if (type === 'radio') { html = [ ' ', ].join(''); optionHtml = [ ' ', ].join(''); } else if (type === 'checkbox') { html = [ ' ', ].join(''); optionHtml = [ ' ', ].join(''); } else if (type === 'select') { html = [ ' ', ].join(''); optionHtml = [' '].join(''); } $optionContainer.append(html); $optionContainer.find('.foxui-input-group:last-child').slideDown(); $(`#${id}`).find('.form-option-group').append(optionHtml); $(`#${id} .form-option-group .form-option:last-child`).fadeIn(); }); // 修改选项 $(document).on('input', '#diyFormSet .option-box .form-input-option', function () { let $this = $(this), index = $this.closest('.foxui-input-group').index(), value = $this.val(), id = $this.closest('.foxui-drag-item').attr('data-diyid'); $(`#${id} .form-option`).eq(index).find('.option-label').text(value); }); // 修改图片数量 $(document).on('input', '#diyFormSet .image-count', function () { let $this = $(this), count = $this.val(), id = $this.closest('.foxui-drag-item').attr('data-diyid'); $(`#${id} .foxui-images`).attr('data-count', count); }); // input 预览 html function _inputPreviewHtml() { return [ '