Merge pull request #7580 from wibetter/master

fix(amis-editor): sparkline走势图 属性配置面板升级
This commit is contained in:
刘丹 2023-07-28 16:00:48 +08:00 committed by GitHub
commit f1985e9513
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 20 deletions

View File

@ -9,6 +9,7 @@ import {
import cx from 'classnames';
import {prompt, toast} from 'amis';
import debounce from 'lodash/debounce';
import isArray from 'lodash/isArray';
import findIndex from 'lodash/findIndex';
import {parse, stringify} from 'json-ast-comments';
import isPlainObject from 'lodash/isPlainObject';
@ -115,12 +116,17 @@ export default class AMisCodeEditor extends React.Component<AMisCodeEditorProps>
obj2str(value: any, props: AMisCodeEditorProps) {
// 隐藏公共配置
value = filterSchemaForConfig(value);
value = {
type: value?.type,
...value
};
if (!value.type && props.$schema?.match(/PageSchema/i)) {
if (!isArray(value)) {
value = {
type: value?.type,
...value
};
}
if (isArray(value)) {
return stringify(value);
} else if (!value.type && props.$schema?.match(/PageSchema/i)) {
value.type = 'page';
} else if (!value.type) {
delete value.type;
@ -153,7 +159,7 @@ export default class AMisCodeEditor extends React.Component<AMisCodeEditorProps>
const {onChange, value} = this.props;
let ret: any = this.str2obj(this.state.contents);
if (!ret || !isPlainObject(ret)) {
if (!ret || (!isPlainObject(ret) && !isArray(ret))) {
this.setState({
wrongSchema: this.state.contents
});

View File

@ -99,7 +99,8 @@ export function autoPreRegisterEditorCustomPlugins() {
}
/**
* Editor插件
* Editor插件
* 备注: 支持覆盖原有组件 priority
* @param editor
*/
export function registerEditorPlugin(klass: PluginClass) {

View File

@ -334,10 +334,7 @@ export class ChartPlugin extends BasePlugin {
}
]
},
{
title: '状态',
body: [getSchemaTpl('ref'), getSchemaTpl('visible')]
}
getSchemaTpl('status')
])
]
},

View File

@ -3,7 +3,7 @@
*/
import {registerEditorPlugin} from 'amis-editor-core';
import {BasePlugin} from 'amis-editor-core';
import {BasePlugin, BaseEventContext} from 'amis-editor-core';
import {defaultValue, getSchemaTpl} from 'amis-editor-core';
export class SparklinePlugin extends BasePlugin {
@ -30,14 +30,54 @@ export class SparklinePlugin extends BasePlugin {
};
panelTitle = '走势图';
panelBody = [
getSchemaTpl('layout:originPosition', {value: 'left-top'}),
{
name: 'height',
type: 'input-number',
label: '高度'
}
];
panelJustify = true;
panelBodyCreator = (context: BaseEventContext) => {
return [
getSchemaTpl('tabs', [
{
title: '属性',
body: [
getSchemaTpl('collapseGroup', [
{
title: '基本',
body: [
getSchemaTpl('layout:originPosition', {value: 'left-top'}),
getSchemaTpl('name')
]
},
{
title: '宽高设置',
body: [
{
name: 'width',
type: 'input-number',
label: '宽度'
},
{
name: 'height',
type: 'input-number',
label: '高度'
}
]
},
getSchemaTpl('status')
])
]
},
{
title: '外观',
body: getSchemaTpl('collapseGroup', [
...getSchemaTpl('theme:common', {exclude: ['layout']}),
{
title: '自定义 CSS 类名',
body: [getSchemaTpl('className')]
}
])
}
])
];
};
}
registerEditorPlugin(SparklinePlugin);