@cainiaofe/cn-ui-charts
Version:
511 lines (509 loc) • 15.1 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import { COL, GRID, P, SECTION, TILE } from "../util/const";
import { getItemDefaultProps, getItemListByPosition, getItemPrototypeListByPosition, handleI18nLabel } from "../util/util";
import { componentMap as featureComponentMap } from "./feature";
import CheckboxSetter from "../setter/checkbox-setter";
import { DisplayPosition } from "../../types/display-position";
import IdSetter from "../setter/id-setter";
export function getObjectSetterSnippet(config) {
var _ref = config || {},
items = _ref.items;
return {
componentName: 'ObjectSetter',
props: {
config: {
items: items
}
}
};
}
export function createHeaderSnippet() {
return {
componentName: 'CnLayoutHeader',
title: '页头',
props: {},
children: [createCellSnippet()]
};
}
;
export var createCellSnippet = function createCellSnippet(children) {
return {
componentName: 'CnLayoutCell',
title: '容器',
props: {},
children: children || []
};
};
export var createFooterSnippet = function createFooterSnippet() {
return {
componentName: 'CnLayoutFooter',
title: '页尾',
props: {},
children: [createCellSnippet()]
};
};
export var createSectionSnippet = function createSectionSnippet(_temp) {
var _ref2 = _temp === void 0 ? {} : _temp,
blockProps = _ref2.blockProps;
return {
componentName: SECTION,
title: '瓷片分组',
props: {},
children: [createBlockSnippet({
blockProps: blockProps
})]
};
};
export var createBlockSnippet = function createBlockSnippet(_temp2) {
var _ref3 = _temp2 === void 0 ? {} : _temp2,
blockProps = _ref3.blockProps;
return {
componentName: TILE,
title: '瓷片',
props: _extends({}, blockProps),
children: [createCellSnippet()]
};
};
export var createGridlSnippet = function createGridlSnippet() {
return {
componentName: GRID,
title: '网格容器',
props: {
rows: 2,
cols: 2
},
children: []
};
};
export var createRowColSnippet = function createRowColSnippet(componentName) {
if (componentName === void 0) {
componentName = COL;
}
return {
componentName: componentName,
title: componentName === COL ? '列容器' : '行容器',
props: {},
children: []
};
};
export var createAsideSnippet = function createAsideSnippet() {
return {
componentName: 'CnLayoutAside',
title: '侧边栏',
props: {},
children: [createCellSnippet(createSectionSnippet())]
};
};
/**
* 返回包裹了P标签的schema,会根据dragged的类型设置不同的属性
* @param {*} dragged 被拖入的组件,是个引擎 node 类型
* @returns {} 返回值是个对象
*/
export var createPSnippet = function createPSnippet() {
return {
componentName: P,
title: '段落',
props: {},
children: []
};
};
export function getDataOriginSetterSnippet(config) {
if (config === void 0) {
config = {};
}
return _extends({
name: 'dataOrigin',
title: '数据来源',
display: 'block',
initialValue: 'static',
setter: {
componentName: 'RadioGroupSetter',
props: {
options: [{
title: '静态数据',
value: 'static'
}, {
title: '远程请求',
value: 'request'
}]
}
}
}, config);
}
export function createSectionInitialChildren() {
return [createBlockSnippet({
blockProps: {
_layout: {
span: 6
}
}
}), createBlockSnippet({
blockProps: {
_layout: {
span: 6
}
}
})];
}
export function createFilterSelectSetters(config, extraConfig) {
var _ref4 = config || {},
mode = _ref4.mode;
return [_extends({
name: '_bindFilter',
title: '选择筛选栏',
setter: function setter(prop) {
var _prop$getNode, _prop$getNode$call, _prop$getNode$call$do, _prop$getNode$call$do2;
var options = [];
prop === null || prop === void 0 ? void 0 : (_prop$getNode = prop.getNode) === null || _prop$getNode === void 0 ? void 0 : (_prop$getNode$call = _prop$getNode.call(prop)) === null || _prop$getNode$call === void 0 ? void 0 : (_prop$getNode$call$do = _prop$getNode$call.document) === null || _prop$getNode$call$do === void 0 ? void 0 : (_prop$getNode$call$do2 = _prop$getNode$call$do.nodesMap) === null || _prop$getNode$call$do2 === void 0 ? void 0 : _prop$getNode$call$do2.forEach(function (item) {
if (item.getPropValue('isCnFilter')) {
var _item$propsData;
var prefix = '筛选栏';
var id = item.id || '';
var title = prefix + "_" + (handleI18nLabel(item === null || item === void 0 ? void 0 : (_item$propsData = item.propsData) === null || _item$propsData === void 0 ? void 0 : _item$propsData.title) || '');
options.push({
title: title,
value: id
});
}
});
return {
componentName: 'CnSelectSetter',
props: {
mode: mode,
options: options,
selectProps: {
hasClear: true
}
}
};
}
}, extraConfig)];
}
export function createFilterConfigSetter() {
return {
name: 'filterConfig',
title: '过滤条件',
setter: getObjectSetterSnippet({
items: [].concat(createFilterSelectSetters({
mode: 'multiple'
}, {
title: '绑定筛选条件'
}))
})
};
}
export function getChartCommonStyleSetterSnippet(config) {
var _ref5 = config || {},
_ref5$items = _ref5.items,
items = _ref5$items === void 0 ? [] : _ref5$items,
heightConfig = _ref5.heightConfig;
return {
name: 'chartStyle',
title: '样式',
display: 'accordion',
setter: getObjectSetterSnippet({
items: [_extends({
name: 'height',
title: '高度',
setter: 'NumberSetter',
defaultValue: 288
}, heightConfig)].concat(items)
})
};
}
export function getGroupSetterSnippet(config) {
var _ref6 = config || {},
outerConfig = _ref6.outerConfig,
items = _ref6.items;
return _extends({
type: 'group',
title: '分组',
// extraProps: {
// display: 'block',
// },
display: 'accordion',
items: items
}, outerConfig);
}
export function getArraySetterSnippet(config) {
var _ref7 = config || {},
initialValue = _ref7.initialValue,
configure = _ref7.configure;
return {
componentName: 'ArraySetter',
props: {
mode: 'list',
itemSetter: {
componentName: 'ObjectSetter',
initialValue: initialValue,
props: {
config: {
items: configure
}
}
}
}
};
}
export function getCnSelectSetterSnippet(config) {
var _ref8 = config || {},
propsConfig = _ref8.propsConfig,
options = _ref8.options;
return {
componentName: 'CnSelectSetter',
props: _extends({
options: options,
selectProps: {
hasClear: true
}
}, propsConfig)
};
}
export function getComponentSlotSetterSnippet(config) {
var _ref9 = config || {},
title = _ref9.title,
slotInitialValue = _ref9.slotInitialValue;
return {
name: 'componentSlot',
title: title || '开启区域筛选',
setter: {
componentName: "SlotSetter",
title: "组件坑位",
initialValue: slotInitialValue || {
type: "JSSlot",
value: [createDefaultFilter()]
}
},
extraProps: {
getValue: function getValue(target, value) {
if (value && (value === null || value === void 0 ? void 0 : value.type) === 'JSSlot') {
return value;
} else if (value === undefined || value === null) {
return '';
} else {
return {
type: "JSSlot",
value: [{
componentName: "CnFilter",
props: {
title: '区域的筛选栏'
}
}]
};
}
}
}
};
}
export function getChartCommonOptions() {
return {
autoFit: true
// theme: "classic",
};
}
export function getPieCharOptions() {
return _extends({}, getChartCommonOptions(), {
type: "interval",
coordinate: {
type: "theta"
},
transform: [{
type: "stackY"
}],
animate: {
enter: {
type: "waveIn"
}
}
});
}
export function getColumnCharOptions() {
return _extends({}, getChartCommonOptions(), {
type: "interval"
});
}
export function getLineCharOptions() {
return _extends({}, getChartCommonOptions(), {
type: "line"
});
}
export function createDefaultFilter() {
return {
componentName: "CnFilter",
props: {
title: '瓷片筛选栏',
filterStyle: {
showFolder: false,
showSelected: false,
enableConfig: false,
showBottomLine: false,
hideButton: true,
removeEmptyLabel: true,
size: 'small',
maxVisibleRow: 999
},
className: 'l2-cn-filter-in-chart',
config: [{
"label": "",
"name": "radio",
"componentName": "RadioGroup",
"options": {
"extra": {
"direction": "hoz",
"type": "button"
},
"dataSource": [{
"label": "选项1",
"value": "radio1"
}, {
"label": "选项2",
"value": "radio2"
}],
"dataOrigin": "static"
}
}]
}
};
}
export function createFeatureSetters(config) {
if (config === void 0) {
config = {};
}
var _config = config,
position = _config.position;
var prototypeList = getItemPrototypeListByPosition({
position: position,
primaryKey: 'name',
componentMap: featureComponentMap
});
var configure = [];
if ((prototypeList === null || prototypeList === void 0 ? void 0 : prototypeList.length) > 0) {
configure.push({
name: 'options',
display: 'plain',
title: '请完善配置',
setter: {
componentName: 'ObjectSetter',
props: {
config: {
items: [].concat(prototypeList)
}
}
}
});
} else {
return [];
}
return {
componentName: 'ArraySetter',
props: {
mode: 'list',
itemSetter: {
componentName: 'ObjectSetter',
initialValue: {
active: true
},
props: {
config: {
items: [{
name: 'name',
display: 'inline',
title: '功能名称',
isRequired: true,
setter: {
componentName: 'SelectSetter',
props: function props(field) {
var _field$parent, _field$parent$parent, _field$parent$parent$, _field$parent$parent$2;
var parentComponentConfig = field === null || field === void 0 ? void 0 : (_field$parent = field.parent) === null || _field$parent === void 0 ? void 0 : (_field$parent$parent = _field$parent.parent) === null || _field$parent$parent === void 0 ? void 0 : (_field$parent$parent$ = _field$parent$parent.parent) === null || _field$parent$parent$ === void 0 ? void 0 : (_field$parent$parent$2 = _field$parent$parent$.getValue) === null || _field$parent$parent$2 === void 0 ? void 0 : _field$parent$parent$2.call(_field$parent$parent$);
var componentName = parentComponentConfig === null || parentComponentConfig === void 0 ? void 0 : parentComponentConfig.componentName;
var validatorList = getItemListByPosition({
position: position,
componentMap: featureComponentMap,
extraQueryParams: {
showInFilterComponentList: componentName
}
});
return {
options: validatorList
};
}
},
extraProps: {
setValue: function setValue(target, value) {
var _Object$keys;
var defaultProps = getItemDefaultProps(featureComponentMap, position, value);
if (defaultProps && ((_Object$keys = Object.keys(defaultProps)) === null || _Object$keys === void 0 ? void 0 : _Object$keys.length) > 0) {
var _target$parent, _target$parent$setPro;
target === null || target === void 0 ? void 0 : (_target$parent = target.parent) === null || _target$parent === void 0 ? void 0 : (_target$parent$setPro = _target$parent.setPropValue) === null || _target$parent$setPro === void 0 ? void 0 : _target$parent$setPro.call(_target$parent, 'options', defaultProps);
} else {
var _target$parent2, _target$parent2$setPr;
target === null || target === void 0 ? void 0 : (_target$parent2 = target.parent) === null || _target$parent2 === void 0 ? void 0 : (_target$parent2$setPr = _target$parent2.setPropValue) === null || _target$parent2$setPr === void 0 ? void 0 : _target$parent2$setPr.call(_target$parent2, 'options', {});
}
}
}
}, {
name: 'active',
display: 'inline',
isRequired: true,
// className: 'cn-array-setter-validator-active',
title: '启用',
// setter: <CheckboxSetter />,
setter: {
componentName: 'MixedSetter',
props: {
setters: [{
componentName: /*#__PURE__*/React.createElement(CheckboxSetter, null),
title: '启用/禁用'
}]
}
}
}].concat(configure)
}
}
}
}
};
}
export function getJSXTemplate(config) {
if (config) {
var _ref10 = config || {},
position = _ref10.position;
var temp = {
componentName: 'CnJSXSetter',
props: {
usePopup: true,
enableFullscreen: true,
theme: 'vs'
},
title: 'React JSX代码'
};
if ([DisplayPosition.statisticCard_titleTip].includes(position)) {
temp.initialValue = {
type: 'js',
source: "function content(item, state) { \n \n}",
compiled: 'function main(){\n \n "use strict";\n\nvar __compiledFunc__ = function content(item, state) {\n \n};\n return __compiledFunc__.apply(this, arguments);\n }',
error: {}
};
}
return temp;
}
}
export function getNodeIdSetterSnippet() {
return {
name: '_nodeId',
title: '节点 ID',
display: 'inline',
initialValue: function initialValue() {
return this.getNode().id;
},
setter: /*#__PURE__*/React.createElement(IdSetter, null)
};
}
export function getComponentTitle(config) {
return _extends({
name: 'title',
title: '组件名称',
display: 'inline',
setter: 'StringSetter'
}, config);
}