mirror of https://github.com/msgbyte/tailchat
feat: 增加自定义网页面板
parent
3816daf174
commit
ebce488a0e
@ -0,0 +1,43 @@
|
|||||||
|
import React, { useMemo } from 'react';
|
||||||
|
import { encode } from 'js-base64';
|
||||||
|
import { isValidStr } from '@capital/common';
|
||||||
|
import { Translate } from '../translate';
|
||||||
|
import { FilterXSS, getDefaultWhiteList } from 'xss';
|
||||||
|
import _mapValues from 'lodash/mapValues';
|
||||||
|
|
||||||
|
const xss = new FilterXSS({
|
||||||
|
// 允许style存在
|
||||||
|
whiteList: {
|
||||||
|
..._mapValues(getDefaultWhiteList(), (v) => [...v, 'style']),
|
||||||
|
style: [],
|
||||||
|
},
|
||||||
|
css: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const GroupCustomWebPanelRender: React.FC<{ panelInfo: any }> = (props) => {
|
||||||
|
const panelInfo = props.panelInfo;
|
||||||
|
|
||||||
|
if (!panelInfo) {
|
||||||
|
return <div>{Translate.notfound}</div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const html = panelInfo?.meta?.html;
|
||||||
|
const src = useMemo(() => {
|
||||||
|
if (isValidStr(html)) {
|
||||||
|
try {
|
||||||
|
return `data:text/html;charset=utf8;base64,${encode(
|
||||||
|
xss.process(html)
|
||||||
|
)}`;
|
||||||
|
} catch (e) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}, [html]);
|
||||||
|
|
||||||
|
return <iframe className="w-full h-full" src={src} />;
|
||||||
|
};
|
||||||
|
GroupCustomWebPanelRender.displayName = 'GroupCustomWebPanelRender';
|
||||||
|
|
||||||
|
export default GroupCustomWebPanelRender;
|
@ -0,0 +1,19 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Translate } from '../translate';
|
||||||
|
|
||||||
|
const GroupWebPanelRender: React.FC<{ panelInfo: any }> = (props) => {
|
||||||
|
const panelInfo = props.panelInfo;
|
||||||
|
|
||||||
|
if (!panelInfo) {
|
||||||
|
return <div>{Translate.notfound}</div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = panelInfo?.meta?.url;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<iframe key={String(url)} className="w-full h-full bg-white" src={url} />
|
||||||
|
);
|
||||||
|
};
|
||||||
|
GroupWebPanelRender.displayName = 'GroupWebPanelRender';
|
||||||
|
|
||||||
|
export default GroupWebPanelRender;
|
@ -1,27 +1,24 @@
|
|||||||
import React from 'react';
|
import { Loadable, regGroupPanel } from '@capital/common';
|
||||||
import { regGroupPanel } from '@capital/common';
|
|
||||||
import { Translate } from './translate';
|
import { Translate } from './translate';
|
||||||
|
|
||||||
const PLUGIN_NAME = 'com.msgbyte.webview';
|
const PLUGIN_NAME = 'com.msgbyte.webview';
|
||||||
|
|
||||||
const GroupWebPanelRender: React.FC<{ panelInfo: any }> = (props) => {
|
|
||||||
const panelInfo = props.panelInfo;
|
|
||||||
|
|
||||||
if (!panelInfo) {
|
|
||||||
return <div>{Translate.notfound}</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
const url = panelInfo?.meta?.url;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<iframe key={String(url)} className="w-full h-full bg-white" src={url} />
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
regGroupPanel({
|
regGroupPanel({
|
||||||
name: `${PLUGIN_NAME}/grouppanel`,
|
name: `${PLUGIN_NAME}/grouppanel`,
|
||||||
label: Translate.webpanel,
|
label: Translate.webpanel,
|
||||||
provider: PLUGIN_NAME,
|
provider: PLUGIN_NAME,
|
||||||
extraFormMeta: [{ type: 'text', name: 'url', label: Translate.website }],
|
extraFormMeta: [{ type: 'text', name: 'url', label: Translate.website }],
|
||||||
render: GroupWebPanelRender,
|
render: Loadable(() => import('./group/GroupWebPanelRender')),
|
||||||
|
});
|
||||||
|
|
||||||
|
regGroupPanel({
|
||||||
|
name: `${PLUGIN_NAME}/customwebpanel`,
|
||||||
|
label: Translate.customwebpanel,
|
||||||
|
provider: PLUGIN_NAME,
|
||||||
|
extraFormMeta: [
|
||||||
|
{ type: 'textarea', name: 'html', label: Translate.htmlcode },
|
||||||
|
],
|
||||||
|
render: Loadable(() => import('./group/GroupCustomWebPanelRender'), {
|
||||||
|
componentName: 'com.msgbyte.webview:GroupCustomWebPanelRender',
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue