From db77dc3cacaa39acf50fcc1c962931a886bed3ce Mon Sep 17 00:00:00 2001 From: liaoxuezhi <2betop.cn@gmail.com> Date: Fri, 10 Jun 2022 10:13:00 +0800 Subject: [PATCH 01/13] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20anchor-nav=20?= =?UTF-8?q?=E6=BB=9A=E5=8A=A8=E6=9D=A1=E5=BC=82=E5=B8=B8=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20(#4576)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis-ui/scss/components/_anchor-nav.scss | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/amis-ui/scss/components/_anchor-nav.scss b/packages/amis-ui/scss/components/_anchor-nav.scss index 941f34ce0..52c85a1fd 100644 --- a/packages/amis-ui/scss/components/_anchor-nav.scss +++ b/packages/amis-ui/scss/components/_anchor-nav.scss @@ -106,6 +106,7 @@ overflow: auto; scroll-behavior: smooth; background: var(--Tabs-content-bg); + position: relative; > .#{$ns}AnchorNav-section { display: block; From 00bcca021b8cc9601c2b812842322009bfafee02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E4=B8=B9?= <365533093@qq.com> Date: Fri, 10 Jun 2022 10:13:54 +0800 Subject: [PATCH 02/13] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=9D=9Etabs=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E6=A8=A1=E5=BC=8F=E4=B8=8B=E5=87=BA=E7=8E=B0=E5=A4=9A?= =?UTF-8?q?=E4=BD=99=E3=80=8Cself=E3=80=8D=E6=A0=87=E7=AD=BE=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20(#4579)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * docs: 修复线上bug,内外网都发一版 1.9.1-beta.21 * fix(inputFormula): 修正非tabs展示模式下出现多余「self」标签问题 --- packages/amis-ui/src/components/formula/Editor.tsx | 2 +- packages/amis-ui/src/components/formula/VariableList.tsx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/amis-ui/src/components/formula/Editor.tsx b/packages/amis-ui/src/components/formula/Editor.tsx index dbfc70252..fe61f3315 100644 --- a/packages/amis-ui/src/components/formula/Editor.tsx +++ b/packages/amis-ui/src/components/formula/Editor.tsx @@ -239,7 +239,7 @@ export class FormulaEditor extends React.Component< handleVariableSelect(item: VariableItem) { const {evalMode, selfVariableName} = this.props; - if (item && item.value && selfVariableName === item.value) { + if (item && item.value && (selfVariableName && selfVariableName === item.value)) { toast.warning('不能使用当前变量[self],避免循环引用。'); return; } diff --git a/packages/amis-ui/src/components/formula/VariableList.tsx b/packages/amis-ui/src/components/formula/VariableList.tsx index 31fdf2c53..46738d6e2 100644 --- a/packages/amis-ui/src/components/formula/VariableList.tsx +++ b/packages/amis-ui/src/components/formula/VariableList.tsx @@ -46,7 +46,7 @@ function VariableList(props: VariableListProps) { : (option: Option, states: ItemRenderStates): JSX.Element => { return ( - {option.label && option.value === selfVariableName && ( + {option.label && (selfVariableName && option.value === selfVariableName) && ( {option.label} )} - {option.label && option.value !== selfVariableName && ( + {option.label && (!selfVariableName || option.value !== selfVariableName) && ( )} {option?.tag ? ( From 4b9bfec58ab62502ef6f898e31d190c6c2382a7d Mon Sep 17 00:00:00 2001 From: hongyang03 Date: Fri, 10 Jun 2022 11:37:49 +0800 Subject: [PATCH 03/13] =?UTF-8?q?fix:=20collapse=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E5=8A=A8=E4=BD=9C=E6=97=A0=E6=95=88=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis-ui/src/components/Collapse.tsx | 2 +- packages/amis-ui/src/components/CollapseGroup.tsx | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/amis-ui/src/components/Collapse.tsx b/packages/amis-ui/src/components/Collapse.tsx index 7db1a44c6..55d41651d 100644 --- a/packages/amis-ui/src/components/Collapse.tsx +++ b/packages/amis-ui/src/components/Collapse.tsx @@ -25,7 +25,7 @@ const collapseStyles: { export interface CollapseProps { key?: string; - id?: string; + collapseId?: string; propKey?: string; mountOnEnter?: boolean; unmountOnExit?: boolean; diff --git a/packages/amis-ui/src/components/CollapseGroup.tsx b/packages/amis-ui/src/components/CollapseGroup.tsx index 3c7bf5be5..dc60e33c8 100644 --- a/packages/amis-ui/src/components/CollapseGroup.tsx +++ b/packages/amis-ui/src/components/CollapseGroup.tsx @@ -64,7 +64,7 @@ class CollapseGroup extends React.Component< activeKey = []; } else { for (let i = 0; i < activeKey.length; i++) { - if (activeKey[i] === item.id) { + if (activeKey[i] === item.collapseId) { activeKey.splice(i, 1); break; } @@ -72,9 +72,9 @@ class CollapseGroup extends React.Component< } } else { if (this.props.accordion) { - activeKey = [item.id as string]; + activeKey = [item.collapseId as string]; } else { - activeKey.push(item.id as string); + activeKey.push(item.collapseId as string); } } this.setState({ @@ -90,13 +90,13 @@ class CollapseGroup extends React.Component< return children.map((child: React.ReactElement, index: number) => { let props = child.props; - const id = props.propKey || String(index); - const collapsed = this.state.activeKey.indexOf(id) === -1; + const collapseId = props.propKey || String(index); + const collapsed = this.state.activeKey.indexOf(collapseId) === -1; return React.cloneElement(child as any, { ...props, - key: id, - id, + key: collapseId, + collapseId, collapsed, expandIcon: this.props.expandIcon, propsUpdate: true, From b16a38bc13577d55d1f848dca52adef59ae6a9b9 Mon Sep 17 00:00:00 2001 From: liaoxuezhi <2betop.cn@gmail.com> Date: Fri, 10 Jun 2022 15:18:43 +0800 Subject: [PATCH 04/13] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dchained-select?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98=20(#4586?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__snapshots__/chainedSelect.test.tsx.snap | 2 +- .../renderers/Form/chainedSelect.test.tsx | 74 ++++++++++++++----- 2 files changed, 57 insertions(+), 19 deletions(-) diff --git a/packages/amis/__tests__/renderers/Form/__snapshots__/chainedSelect.test.tsx.snap b/packages/amis/__tests__/renderers/Form/__snapshots__/chainedSelect.test.tsx.snap index 9297ee0f6..fc87cd0b5 100644 --- a/packages/amis/__tests__/renderers/Form/__snapshots__/chainedSelect.test.tsx.snap +++ b/packages/amis/__tests__/renderers/Form/__snapshots__/chainedSelect.test.tsx.snap @@ -99,7 +99,7 @@ exports[`Renderer:chained-select 1`] = `
- B 0 + B 1
{ - const {container, findByText} = render( + const {container, findByText, getByText, getByTestId} = render( amisRender( { type: 'form', @@ -24,26 +28,60 @@ test('Renderer:chained-select', async () => { }, {}, makeEnv({ - fetcher: async (config: any) => { - return { - status: 200, - headers: {}, - data: { - status: 0, - msg: '', - data: [ - {label: 'A 0', value: 'a'}, - {label: 'B 0', value: 'b'}, - {label: 'C 0', value: 'c'}, - {label: 'D 0', value: 'd'} - ] - } - }; + async fetcher(config: any): Promise { + const level = parseInt(config.query.level, 10) || 0; + const maxLevel = parseInt(config.query.maxLevel, 10) || 0; + if (level >= maxLevel) { + return { + status: 200, + headers: {}, + data: { + status: 0, + data: null + } + }; + } else { + return { + status: 200, + headers: {}, + data: { + status: 0, + msg: '', + data: [ + { + label: `A ${level}`, + value: 'a' + }, + + { + label: `B ${level}`, + value: 'b' + }, + + { + label: `C ${level}`, + value: 'c' + }, + + { + label: `D ${level}`, + value: 'd' + } + ] + } + }; + } } }) ) ); - await wait(500); + await waitFor(() => { + expect(getByText('B 1')).toBeInTheDocument(); + expect( + container.querySelector('[data-testid="spinner"]') + ).not.toBeInTheDocument(); + }); + expect(container).toMatchSnapshot(); }); From 4b2f118be032c50de826e8586f67adf2f79f0959 Mon Sep 17 00:00:00 2001 From: liaoxuezhi <2betop.cn@gmail.com> Date: Fri, 10 Jun 2022 15:19:07 +0800 Subject: [PATCH 05/13] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E9=A1=B5=E9=9D=A2=E5=88=87=E5=88=B0=20React=2018=20?= =?UTF-8?q?=E5=90=8E,=20=E5=88=87=E6=8D=A2=E6=B2=A1=E6=9C=89=E9=94=80?= =?UTF-8?q?=E6=AF=81=E7=94=A8=E4=BA=8E=E9=A2=84=E8=A7=88=E7=9A=84=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=AE=9E=E4=BE=8B=20(#4583)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/components/MdRenderer.jsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/components/MdRenderer.jsx b/examples/components/MdRenderer.jsx index 76f71dee2..6e70dd55c 100644 --- a/examples/components/MdRenderer.jsx +++ b/examples/components/MdRenderer.jsx @@ -66,8 +66,10 @@ class Preview extends React.Component { } componentWillUnmount() { - // TODO: 会报错,可能得后续 amis 内部的 render 也改才行 - // this.roots.forEach(root => root.unmount()); + // 立即 unmout 会报错 + window.requestAnimationFrame(() => { + this.roots.forEach(root => root.unmount()); + }); } divRef(ref) { From be54d169286ea2c62e6d593fa88c5b534eb2d0e8 Mon Sep 17 00:00:00 2001 From: liaoxuezhi <2betop.cn@gmail.com> Date: Fri, 10 Jun 2022 15:19:38 +0800 Subject: [PATCH 06/13] =?UTF-8?q?feat:=20echart=20=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E8=AE=A9=E6=9B=B4=E5=A4=9A=E7=9A=84=E5=B1=9E=E6=80=A7=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20function=20=E6=A0=BC=E5=BC=8F,=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E8=A1=A5=E5=85=85=E6=96=87=E6=A1=A3=20(#4567)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh-CN/components/chart.md | 57 ++++++++++++++++++++------- packages/amis/src/renderers/Chart.tsx | 20 +++++++++- 2 files changed, 60 insertions(+), 17 deletions(-) diff --git a/docs/zh-CN/components/chart.md b/docs/zh-CN/components/chart.md index e0bc60e86..bee1583cf 100755 --- a/docs/zh-CN/components/chart.md +++ b/docs/zh-CN/components/chart.md @@ -433,23 +433,50 @@ window.echarts = amisRequire('echarts'); 然后通过 script 标签引入这两个文件。 +## 动态处理 echart 配置 + +echarts 的 config 一般是静态配置的,支持简单的数据映射。如果你觉得还不够灵活可以通过自己手写逻辑代码来完成配置。 + +通过配置 dataFiler 来处理。 + +```schema: scope="body" +{ + "type": "chart", + "data": { + "line": [65, 63, 10, 73, 42, 21], + "line2": [22, 33, 90, 20, 11, 33] + }, + "config": { + "xAxis": { + "type": "category", + "data": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] + }, + "yAxis": { + "type": "value" + } + }, + "dataFilter": "config.series = [];Object.keys(data).forEach(function(key) {config.series.push({data: data[key], type: 'line'})})" +} +``` + ## 属性表 -| 属性名 | 类型 | 默认值 | 说明 | -| ------------------ | -------------------------------------------- | --------- | ------------------------------------------------------------------ | -| type | `string` | `"chart"` | 指定为 chart 渲染器 | -| className | `string` | | 外层 Dom 的类名 | -| body | [SchemaNode](../../docs/types/schemanode) | | 内容容器 | -| api | [api](../../docs/types/api) | | 配置项接口地址 | -| source | [数据映射](../../docs/concepts/data-mapping) | | 通过数据映射获取数据链中变量值作为配置 | -| initFetch | `boolean` | | 组件初始化时,是否请求接口 | -| interval | `number` | | 刷新时间(最小 1000) | -| config | `object` 或 `string` | | 设置 eschars 的配置项,当为`string`的时候可以设置 function 等配置项 | -| style | `object` | | 设置根元素的 style | -| width | `string` | | 设置根元素的宽度 | -| height | `string` | | 设置根元素的高度 | -| replaceChartOption | `boolean` | `false` | 每次更新是完全覆盖配置项还是追加? | -| `trackExpression` | `string` | | 当这个表达式的值有变化时更新图表 | +| 属性名 | 类型 | 默认值 | 说明 | +| ------------------ | -------------------------------------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| type | `string` | `"chart"` | 指定为 chart 渲染器 | +| className | `string` | | 外层 Dom 的类名 | +| body | [SchemaNode](../../docs/types/schemanode) | | 内容容器 | +| api | [api](../../docs/types/api) | | 配置项接口地址 | +| source | [数据映射](../../docs/concepts/data-mapping) | | 通过数据映射获取数据链中变量值作为配置 | +| initFetch | `boolean` | | 组件初始化时,是否请求接口 | +| interval | `number` | | 刷新时间(最小 1000) | +| config | `object` 或 `string` | | 设置 eschars 的配置项,当为`string`的时候可以设置 function 等配置项 | +| style | `object` | | 设置根元素的 style | +| width | `string` | | 设置根元素的宽度 | +| height | `string` | | 设置根元素的高度 | +| replaceChartOption | `boolean` | `false` | 每次更新是完全覆盖配置项还是追加? | +| trackExpression | `string` | | 当这个表达式的值有变化时更新图表 | +| dataFilter | `string` | | 自定义 echart config 转换,函数签名:function(config, echarts, data) {return config;} 配置时直接写函数体。其中 config 是当前 echart 配置,echarts 就是 echarts 对象,data 为上下文数据。 | ## 动作表 diff --git a/packages/amis/src/renderers/Chart.tsx b/packages/amis/src/renderers/Chart.tsx index f86d5a9f0..d050072a9 100644 --- a/packages/amis/src/renderers/Chart.tsx +++ b/packages/amis/src/renderers/Chart.tsx @@ -122,11 +122,27 @@ const EVAL_CACHE: {[key: string]: Function} = {}; /** * ECharts 中有些配置项可以写函数,但 JSON 中无法支持,为了实现这个功能,需要将看起来像函数的字符串转成函数类型 * 目前 ECharts 中可能有函数的配置项有如下:interval、formatter、color、min、max、labelFormatter、pageFormatter、optionToContent、contentToOption、animationDelay、animationDurationUpdate、animationDelayUpdate、animationDuration、position、sort - * 其中用得最多的是 formatter、sort,所以目前先只支持它们 * @param config ECharts 配置 */ function recoverFunctionType(config: object) { - ['formatter', 'sort', 'renderItem'].forEach((key: string) => { + [ + 'interval', + 'formatter', + 'color', + 'min', + 'max', + 'labelFormatter', + 'pageFormatter', + 'optionToContent', + 'contentToOption', + 'animationDelay', + 'animationDurationUpdate', + 'animationDelayUpdate', + 'animationDuration', + 'position', + 'sort', + 'renderItem' + ].forEach((key: string) => { const objects = findObjectsWithKey(config, key); for (const object of objects) { const code = object[key]; From 48b759962d56a247f24aa163027d632f11a39e22 Mon Sep 17 00:00:00 2001 From: RUNZE LU <36724300+lurunze1226@users.noreply.github.com> Date: Fri, 10 Jun 2022 16:38:54 +0800 Subject: [PATCH 07/13] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20crud=20?= =?UTF-8?q?=E4=B8=AD=20actionType=20reload=20=E5=85=B6=E4=BB=96=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=A4=B1=E6=95=88=E9=97=AE=E9=A2=98=20&=20submit?= =?UTF-8?q?=E9=85=8D=E7=BD=AErequired=E5=9C=A8=E5=BC=B9=E7=AA=97=E4=B8=AD?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E5=85=B3=E9=97=AD=E9=97=AE=E9=A2=98=20(#4593?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis-core/src/renderers/Form.tsx | 3 +++ packages/amis/src/renderers/CRUD.tsx | 2 +- packages/amis/src/renderers/Table/index.tsx | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/amis-core/src/renderers/Form.tsx b/packages/amis-core/src/renderers/Form.tsx index 6fa5f7deb..9e59112c5 100644 --- a/packages/amis-core/src/renderers/Form.tsx +++ b/packages/amis-core/src/renderers/Form.tsx @@ -974,6 +974,9 @@ export default class Form extends React.Component { if (!dispatcher?.prevented) { env.notify('error', __('Form.validateFailed')); } + + /** 抛异常是为了在dialog中catch这个错误,避免弹窗直接关闭 */ + return Promise.reject(__('Form.validateFailed')); } else { dispatchEvent('validateSucc', this.props.data); this.handleAction( diff --git a/packages/amis/src/renderers/CRUD.tsx b/packages/amis/src/renderers/CRUD.tsx index 708fa4a88..af3f23c93 100644 --- a/packages/amis/src/renderers/CRUD.tsx +++ b/packages/amis/src/renderers/CRUD.tsx @@ -670,7 +670,7 @@ export default class CRUD extends React.Component { throw e; } }); - } else if (action.actionType === 'reload') { + } else if (action.actionType === 'reload' && !action.target) { this.reload(); } else if ( pickerMode && diff --git a/packages/amis/src/renderers/Table/index.tsx b/packages/amis/src/renderers/Table/index.tsx index 6c078a351..ecfd102a3 100644 --- a/packages/amis/src/renderers/Table/index.tsx +++ b/packages/amis/src/renderers/Table/index.tsx @@ -2818,6 +2818,22 @@ export class TableRenderer extends Table { return scoped.send(subPath, values); } } + + reload(subPath?: string, query?: any, ctx?: any) { + const scoped = this.context as IScopedContext; + const parents = scoped?.parent?.getComponents(); + + if (Array.isArray(parents) && parents.length) { + // CRUD的name会透传给Table,这样可以保证找到CRUD + const crud = parents.find(cmpt => cmpt?.props?.name === this.props?.name); + + return crud?.reload?.(subPath, query, ctx); + } + + if (subPath) { + return scoped.reload(subPath, ctx); + } + } } export {TableCell}; From 9182a45619b72065dc607c07383efb0d656022d4 Mon Sep 17 00:00:00 2001 From: hsm-lv <80095014+hsm-lv@users.noreply.github.com> Date: Fri, 10 Jun 2022 17:24:39 +0800 Subject: [PATCH 08/13] =?UTF-8?q?fix:crud=E4=B8=8D=E5=AF=B9table=E4=B8=8B?= =?UTF-8?q?=E5=8F=91onEvent=EF=BC=8C=E9=81=BF=E5=85=8D=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E7=9B=91=E5=90=AC=20(#4594)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis/src/renderers/CRUD.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/amis/src/renderers/CRUD.tsx b/packages/amis/src/renderers/CRUD.tsx index af3f23c93..67bacf815 100644 --- a/packages/amis/src/renderers/CRUD.tsx +++ b/packages/amis/src/renderers/CRUD.tsx @@ -2067,6 +2067,7 @@ export default class CRUD extends React.Component { autoGenerateFilter, onSelect, autoFillHeight, + onEvent, ...rest } = this.props; From 1173a98d28cbcd3534bb5024aefcca1992929b03 Mon Sep 17 00:00:00 2001 From: pianruijie <13522335863@163.com> Date: Fri, 10 Jun 2022 18:12:07 +0800 Subject: [PATCH 09/13] =?UTF-8?q?feat=EF=BC=9A=E5=A4=9A=E8=A1=8C=E6=96=87?= =?UTF-8?q?=E6=9C=AC=E6=A1=86=E6=94=AF=E6=8C=81change=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis/src/renderers/Form/Textarea.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/amis/src/renderers/Form/Textarea.tsx b/packages/amis/src/renderers/Form/Textarea.tsx index a69dea2f7..91b4f53fb 100644 --- a/packages/amis/src/renderers/Form/Textarea.tsx +++ b/packages/amis/src/renderers/Form/Textarea.tsx @@ -104,6 +104,13 @@ export default class TextAreaControl extends React.Component< this.inputRef.current?.focus(); } + @autobind + @bindRendererEvent('change') + handleChange(e: React.ChangeEvent) { + const {onChange} = this.props; + onChange && onChange(e); + } + @autobind @bindRendererEvent('focus') handleFocus(e: React.FocusEvent) { @@ -142,7 +149,7 @@ export default class TextAreaControl extends React.Component< const {...rest} = this.props; return ( -