import snippets from './snippets'; import { RequiredSetter } from '../_setters'; import { baseValidationSection, labelProps, stateProps, switchTypeProps } from '../_props'; import { IPublicModelSettingField } from '@alilc/lowcode-types'; import { uuid } from '../_utils/utils'; import { checkParentWhitelist } from '../_utils/nestingRules'; import { version } from '../../package.json'; const baseValidation = { ...baseValidationSection, items: baseValidationSection.items.filter((item) => item.name !== 'required'), }; export default { snippets: snippets, // 表单页显示组件 group: '基础组件', componentName: 'RsSwitch', title: '开关', category: '表单元素', priority: 38, npm: { package: 'components-page', version, exportName: 'RsSwitch', main: 'src\\index.tsx', destructuring: true, subName: '', }, props: [ { name: 'rs_id', title: { label: { type: 'i18n', zh_CN: '组件ID', en_US: 'id', }, tip: { type: 'i18n', zh_CN: '属性: id | 说明: 字段唯一识别', en_US: 'prop: id | description: field ID', }, }, propType: 'string', setter: { componentName: RequiredSetter, initialValue: () => 'switch_' + uuid(), }, extraProps: { setValue: (target: IPublicModelSettingField, value: any) => { if (!value) return; target.getProps().setPropValue('ref', value); }, }, }, ...labelProps, // { // name: 'label', // title: { label: '标题', tip: '标题' }, // propType: 'string', // setter: 'StringSetter' // }, // { // name: 'id', // title: { label: '字段名称', tip: '字段名称' }, // propType: 'string', // setter: 'StringSetter' // }, // { // name: 'labelPosition', // title: { label: '标题位置', tip: '标题位置' }, // propType: { type: 'oneOf', value: ['horizontal', 'vertical'] }, // setter: { // componentName: 'RadioGroupSetter', // props: { // options: [ // { // title: '左侧', // value: 'horizontal', // }, // { // title: '上方', // value: 'vertical', // }, // ], // }, // initialValue: 'horizontal', // }, // }, // { // name: 'labelShow', // title: { label: '标题是否显示', tip: '标题是否显示' }, // propType: 'bool', // defaultValue: true, // setter: 'BoolSetter' // }, // { // name: 'labelTipShow', // title: { label: '标题提示开关', tip: '标题提示开关' }, // propType: 'bool', // defaultValue: false, // setter: 'BoolSetter' // }, // { // name: 'labelTipContent', // title: { label: '标题提示内容', tip: '标题提示内容' }, // propType: 'string', // setter: 'StringSetter', // condition: (target: IPublicModelSettingField) => { // return target.getProps().getPropValue('labelTipShow'); // } // }, // { // name: 'switchStatus', // title: { label: '状态', tip: '状态' }, // propType: 'string', // setter: { // componentName: 'RadioGroupSetter', // props: { // options: [ // { // title: '普通', // value: 'normal', // }, // { // title: '禁用', // value: 'disabled', // }, // { // title: '只读', // value: 'readdonly', // }, // { // title: '隐藏', // value: 'hide', // }, // ], // }, // initialValue: 'normal', // }, // }, stateProps, ...switchTypeProps, // { // name: 'defaultChecked', // title: { label: '默认选中', tip: '默认是否选中' }, // propType: 'bool', // defaultValue: true, // setter: 'BoolSetter', // }, { name: 'checked', title: { label: '是否选中', tip: '当前是否选中' }, propType: 'bool', defaultValue: true, setter: 'BoolSetter', supportVariable: true, }, // { // name: 'autoFocus', // title: { label: '自动聚焦', tip: '组件自动获取焦点' }, // propType: 'bool', // defaultValue: false, // setter: 'BoolSetter', // }, { name: 'checkedChildren', title: { label: '选中时内容', tip: '选中时的内容' }, propType: 'string', setter: 'StringSetter', }, { name: 'unCheckedChildren', title: { label: '非选中时内容', tip: '非选中时的内容' }, propType: 'string', setter: 'StringSetter', }, // { // name: 'disabled', // title: { label: '是否禁用', tip: '是否为禁用状态' }, // propType: 'bool', // defaultValue: false, // setter: 'BoolSetter' // }, // { // name: 'loading', // title: { label: '加载中', tip: '加载中' }, // propType: 'bool', // defaultValue: false, // setter: 'BoolSetter', // }, // { // name: 'size', // title: { label: '尺寸', tip: '开关大小' }, // propType: { type: 'oneOf', value: ['default', 'small'] }, // setter: { // componentName: 'RadioGroupSetter', // props: { // options: [ // { // title: '默认', // value: 'default', // }, // { // title: '小', // value: 'small', // }, // ], // }, // initialValue: 'default', // }, // }, baseValidation, { name: 'onChange', title: { label: '变化时回调函数', tip: '变化时回调函数' }, propType: 'func', }, { name: 'onClick', title: { label: '点击时回调函数', tip: '点击时回调函数' }, propType: 'func', }, // { // name: 'className', // title: { label: '类名', tip: '类名' }, // propType: 'string', // }, ], configure: { component: { nestingRule: { parentWhitelist: (testNode: IPublicModelSettingField) => { return checkParentWhitelist(testNode); }, }, }, supports: { style: true, events: [ { name: 'onChange', template: "onChange(checked,event,${extParams}){\n\t\t// 变化时回调函数\n\t\tconsole.log('onChange',checked);\n\t}\n", }, { name: 'onClick', template: "onClick(checked,event,${extParams}){\n\t\t// 点击时回调函数\n\t\tconsole.log('onClick',checked);\n\t}\n", }, ], }, }, };