feat: add srcdoc property to IFrameBlock element #454

pr675
Hufe921 2 years ago
parent 5027d730c4
commit 66969925ac

@ -22,6 +22,7 @@
"richtext", "richtext",
"rowmargin", "rowmargin",
"rowspan", "rowspan",
"srcdoc",
"TEXTLIKE", "TEXTLIKE",
"trlist", "trlist",
"updown", "updown",

@ -139,7 +139,8 @@ interface IElement {
VIDEO = 'video' VIDEO = 'video'
}; };
iframeBlock?: { iframeBlock?: {
src: string; src?: string;
srcdoc?: string;
}; };
videoBlock?: { videoBlock?: {
src: string; src: string;

@ -139,7 +139,8 @@ interface IElement {
VIDEO = 'video' VIDEO = 'video'
}; };
iframeBlock?: { iframeBlock?: {
src: string; src?: string;
srcdoc?: string;
}; };
videoBlock?: { videoBlock?: {
src: string; src: string;

@ -20,7 +20,11 @@ export class IFrameBlock {
iframe.style.border = 'none' iframe.style.border = 'none'
iframe.style.width = '100%' iframe.style.width = '100%'
iframe.style.height = '100%' iframe.style.height = '100%'
iframe.src = block.iframeBlock?.src || '' if (block.iframeBlock?.src) {
iframe.src = block.iframeBlock.src
} else if (block.iframeBlock?.srcdoc) {
iframe.srcdoc = block.iframeBlock.srcdoc
}
blockItemContainer.append(iframe) blockItemContainer.append(iframe)
} }
} }

@ -1,7 +1,8 @@
import { BlockType } from '../dataset/enum/Block' import { BlockType } from '../dataset/enum/Block'
export interface IIFrameBlock { export interface IIFrameBlock {
src: string src?: string
srcdoc?: string
} }
export interface IVideoBlock { export interface IVideoBlock {

@ -900,32 +900,43 @@ window.onload = function () {
placeholder: '请输入高度' placeholder: '请输入高度'
}, },
{ {
type: 'textarea', type: 'input',
label: '地址', label: '地址',
height: 100, name: 'src',
name: 'value', required: false,
required: true,
placeholder: '请输入地址' placeholder: '请输入地址'
},
{
type: 'textarea',
label: 'HTML',
height: 100,
name: 'srcdoc',
required: false,
placeholder: '请输入HTML代码仅网址类型有效'
} }
], ],
onConfirm: payload => { onConfirm: payload => {
const type = payload.find(p => p.name === 'type')?.value const type = payload.find(p => p.name === 'type')?.value
if (!type) return if (!type) return
const value = payload.find(p => p.name === 'value')?.value
if (!value) return
const width = payload.find(p => p.name === 'width')?.value const width = payload.find(p => p.name === 'width')?.value
const height = payload.find(p => p.name === 'height')?.value const height = payload.find(p => p.name === 'height')?.value
if (!height) return if (!height) return
// 地址或HTML代码至少存在一项
const src = payload.find(p => p.name === 'src')?.value
const srcdoc = payload.find(p => p.name === 'srcdoc')?.value
const block: IBlock = { const block: IBlock = {
type: <BlockType>type type: <BlockType>type
} }
if (block.type === BlockType.IFRAME) { if (block.type === BlockType.IFRAME) {
if (!src && !srcdoc) return
block.iframeBlock = { block.iframeBlock = {
src: value src,
srcdoc
} }
} else if (block.type === BlockType.VIDEO) { } else if (block.type === BlockType.VIDEO) {
if (!src) return
block.videoBlock = { block.videoBlock = {
src: value src
} }
} }
const blockElement: IElement = { const blockElement: IElement = {

Loading…
Cancel
Save