From 87ad5e446a60b6787e76edc8f8b1a5de78ed3e6f Mon Sep 17 00:00:00 2001 From: catchonme Date: Wed, 18 Sep 2019 14:38:07 +0800 Subject: [PATCH] =?UTF-8?q?iframe=E6=94=AF=E6=8C=81reload?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderers/Form/SubForm.tsx | 28 +++++++++++++++++++++++----- src/renderers/IFrame.tsx | 23 ++++++++++++++++++++++- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/renderers/Form/SubForm.tsx b/src/renderers/Form/SubForm.tsx index 80c6ddcfa..4b6ca3205 100644 --- a/src/renderers/Form/SubForm.tsx +++ b/src/renderers/Form/SubForm.tsx @@ -146,7 +146,9 @@ export default class SubFormControl extends React.PureComponent - {(value && labelField && value[labelField] && stripTag(value[labelField])) || - btnLabel} + {(value && labelField && value[labelField] && stripTag(value[labelField])) + || render('placeholder', + { + type: 'tpl', + tpl: btnLabel + }, + { + data + })} )) @@ -199,7 +208,7 @@ export default class SubFormControl extends React.PureComponent @@ -216,7 +225,16 @@ export default class SubFormControl extends React.PureComponent - {(value && labelField && value[labelField] && stripTag(value[labelField])) || btnLabel} + {(value && labelField && value[labelField] && stripTag(value[labelField])) + || render('placeholder', + { + type: 'tpl', + tpl: btnLabel + }, + { + data + } + )}} diff --git a/src/renderers/IFrame.tsx b/src/renderers/IFrame.tsx index 61adbb262..069085bcf 100644 --- a/src/renderers/IFrame.tsx +++ b/src/renderers/IFrame.tsx @@ -1,6 +1,8 @@ import React from 'react'; import {Renderer, RendererProps} from '../factory'; import {filter} from '../utils/tpl'; +import {autobind} from '../utils/helper'; +import {ScopedContext, IScopedContext} from '../Scoped'; export interface IFrameProps extends RendererProps { className?: string; @@ -8,6 +10,7 @@ export interface IFrameProps extends RendererProps { } export default class IFrame extends React.Component { + IFrameRef: React.RefObject = React.createRef(); static propsList: Array = ['src', 'className']; static defaultProps: Partial = { className: '', @@ -16,6 +19,11 @@ export default class IFrame extends React.Component { frameBorder: 0 }; + @autobind + reload() { + (this.IFrameRef.current as HTMLIFrameElement).src = (this.IFrameRef.current as HTMLIFrameElement).src; + } + render() { let {className, src, width, height, frameBorder, data, style} = this.props; @@ -31,6 +39,7 @@ export default class IFrame extends React.Component { className={className} frameBorder={frameBorder} style={style} + ref={this.IFrameRef} src={src ? filter(src, data) : undefined} /> ); @@ -41,4 +50,16 @@ export default class IFrame extends React.Component { test: /(^|\/)iframe$/, name: 'iframe' }) -export class IFrameRenderer extends IFrame {} +export class IFrameRenderer extends IFrame { + static contextType = ScopedContext; + + componentWillMount() { + const scoped = this.context as IScopedContext; + scoped.registerComponent(this); + } + + componentWillUnmount() { + const scoped = this.context as IScopedContext; + scoped.unRegisterComponent(this); + } +}