import snippets from './snippets'; import { CustomOptionsSetter } from '../_setters'; import { isPageDesigner, uuid } from '../_utils/utils'; import { RequiredSetter } from '../_setters'; import { IPublicModelSettingField } from '@alilc/lowcode-types'; import { project } from '@alilc/lowcode-engine'; import { checkParentWhitelist } from '../_utils/nestingRules'; const { version } = require('../../package.json'); const TabMeta = { snippets: snippets, // 表单页显示组件 group: '基础组件', componentName: 'RsTab', title: '选项卡', category: '容器元素', priority: 22, npm: { package: 'components-page', version, exportName: 'RsTab', 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: '属性: rs_id | 说明: 组件ID', en_US: 'prop: rs_id | description: Component ID', }, }, propType: 'string', setter: { componentName: RequiredSetter, initialValue: () => 'tab_' + uuid(), }, supportVariable: true, }, { name: 'items', title: { label: { type: 'i18n', zh_CN: '标签项', en_US: 'items', }, tip: { type: 'i18n', zh_CN: '属性: items | 说明: 标签项', en_US: 'prop: items | description: Tab items', }, }, supportVariable: false, type: 'field', display: 'block', setter: { componentName: CustomOptionsSetter, props: { valueKey: 'value', labelKey: 'label', items: [ { name: 'checked', title: '默认选中', type: 'boolean', }, { name: 'label', title: '显示值', type: 'string', }, { name: 'value', title: '选项值', type: 'string', }, { name: 'isHidden', title: '是否隐藏', type: 'boolean', }, ], }, initialValue: () => { const key = uuid(); return { label: '标签名', value: key, checked: false, isHidden: false, children: { type: 'JSSlot', key: uuid(), value: [ { componentName: 'RsTab.TabPane', key: uuid(), props: { label: '标签名', key: key, padding: '16px', }, }, ], }, }; }, }, }, { title: { label: { type: 'i18n', zh_CN: '外观', en_US: 'Appearance', }, tip: { type: 'i18n', zh_CN: '属性: 无 | 说明: 外观设置分组', en_US: 'prop: none | description: Appearance settings group', }, }, display: 'block', type: 'group', items: [ { name: 'shape', title: { label: { type: 'i18n', zh_CN: '形态', en_US: 'shape', }, tip: { type: 'i18n', zh_CN: '属性: shape | 说明: 形态', en_US: 'prop: shape | description: Shape', }, }, setter: { componentName: 'RadioGroupSetter', initialValue: 'normal', props: { options: [ { title: '普通型', value: 'normal' }, { title: '包裹型', value: 'wrapped' }, { title: '文本型', value: 'text' }, { title: '胶囊型', value: 'capsule' }, ] }, }, }, { name: 'tabPosition', title: { label: { type: 'i18n', zh_CN: '选项卡位置', en_US: 'tab position', }, tip: { type: 'i18n', zh_CN: '属性: tabPosition | 说明: 选项卡位置', en_US: 'prop: tabPosition | description: Tab position', }, }, setter: { componentName: 'RadioGroupSetter', initialValue: 'top', props: { options: [ { title: '上', value: 'top' }, { title: '左', value: 'left' }, { title: '下', value: 'bottom' }, { title: '右', value: 'right' }, ] }, }, }, { name: 'tabBarGutter', title: { label: { type: 'i18n', zh_CN: '页签头间隙', en_US: 'tabBarGutter', }, tip: { type: 'i18n', zh_CN: '属性: tabBarGutter | 说明: tabs 之间的间隙', en_US: 'prop: tabBarGutter | description: tabBarGutter', }, }, propType: 'string', setter: { componentName: 'NumberSetter', initialValue: '24px', props: { units: 'px', }, }, }, { name: 'padding', title: { label: { type: 'i18n', zh_CN: '内边距', en_US: 'contentPadding', }, tip: { type: 'i18n', zh_CN: '属性: contentPadding | 说明: 内边距', en_US: 'prop: contentPadding | description: Padding', }, }, setter: { componentName: 'RadioGroupSetter', initialValue: '12px', props: { options: [ { title: '无', value: '0px', }, { title: '12px', value: '12px', }, { title: '16px', value: '16px', }, ] }, }, extraProps: { setValue: (target: IPublicModelSettingField, value: any) => { let items = target.getProps().getPropValue('items'); items.forEach((item: any) => { const id = item?.children?.value[0]?.id; if (id) { const node = project?.currentDocument?.getNodeById(id); node?.setPropValue('padding', value); } }); }, }, propType: { type: 'oneOf', value: ['0px', '12px', '16px'] }, }, { name: 'margin', title: { label: { type: 'i18n', zh_CN: '外边距', en_US: 'contentPadding', }, tip: { type: 'i18n', zh_CN: '属性: margin | 说明: 外边距', en_US: 'prop: margin | description: margin', }, }, setter: { componentName: 'RadioGroupSetter', initialValue: '0px', props: { options: [ { title: '无', value: '0px', }, { title: '12px', value: '12px', }, { title: '20px', value: '20px', }, { title: '24px', value: '24px', }, ], }, }, extraProps: { setValue: (target: IPublicModelSettingField, value: any) => { let items = target.getProps().getPropValue('items'); items.forEach((item: any) => { const id = item.children.value[0].id; if (id) { const node = project?.currentDocument?.getNodeById(id); node?.setPropValue('margin', value); } }); }, }, propType: { type: 'oneOf', value: ['0px', '12px', '20px', '24px'] }, }, { name: 'excessMode', title: { label: { type: 'i18n', zh_CN: '选项卡过多时的滑动模式', en_US: 'excessMode', }, tip: { type: 'i18n', zh_CN: '属性: excessMode | 说明: 选项卡过多时的滑动模式', en_US: 'prop: excessMode | description: Sliding mode when there are too many tabs', }, }, setter: { componentName: 'RadioGroupSetter', initialValue: 'slide', props: { options: [ { title: '滑动', value: 'slide' }, { title: '下拉', value: 'dropdown' }, ], }, }, }, ], }, { title: { label: { type: 'i18n', zh_CN: '高级', en_US: 'Advanced', }, tip: { type: 'i18n', zh_CN: '属性: 无 | 说明: 高级设置分组', en_US: 'prop: none | description: Advanced settings group', }, }, display: 'block', type: 'group', items: [ { name: 'switchToDestruction', condition: () => { return isPageDesigner(); }, extraProps: { getValue: (target: IPublicModelSettingField, fieldValue: boolean) => { return isPageDesigner() ? fieldValue : false; }, }, title: { label: { type: 'i18n', zh_CN: '切换销毁', en_US: 'switchToDestruction', }, tip: { type: 'i18n', zh_CN: '属性: switchToDestruction | 说明: 切换销毁', en_US: 'prop: switchToDestruction | description: Destroy when switching', }, }, setter: { componentName: 'BoolSetter', props: { defaultValue: false, }, }, }, { name: 'lazyLoad', title: { label: { type: 'i18n', zh_CN: '延迟加载', en_US: 'lazyLoad', }, tip: { type: 'i18n', zh_CN: '属性: lazyLoad | 说明: 延迟加载', en_US: 'prop: lazyLoad | description: Lazy load', }, }, setter: { componentName: 'BoolSetter', defaultValue: true, }, }, ], }, ], configure: { component: { isContainer: true, nestingRule: { childWhitelist: ['RsTab.TabPane'], parentWhitelist: (testNode: IPublicModelSettingField) => { return checkParentWhitelist(testNode); }, }, }, supports: { events: [ { name: 'onChange', template: "onChange(activeKey){\n\t\t// 切换面板的回调\n\t\tconsole.log('onChange',activeKey);\n\t}\n", }, { name: 'onTabClick', template: "onTabClick(key,event,${extParams}){\n\t\t// tab 被点击的回调\n\t\tconsole.log('onTabClick',key,event);\n\t}\n", }, { name: 'onTabScroll', template: "onTabScroll({direction},${extParams}){\n\t\t// tab 滚动时触\n\t\tconsole.log('onTabScroll',direction);\n\t}\n", }, ], style: true, }, }, }; export default TabMeta;