内嵌了js,css
This commit is contained in:
parent
11c7191e31
commit
d110c85fd4
@ -41,27 +41,34 @@ export class StockDetailsEditor extends EditorPane {
|
|||||||
contentOptions: {
|
contentOptions: {
|
||||||
allowScripts: true,
|
allowScripts: true,
|
||||||
localResourceRoots: [], // 根据需求设置本地资源根路径
|
localResourceRoots: [], // 根据需求设置本地资源根路径
|
||||||
|
localResourceRoots: [], // 根据需求设置本地资源根路径
|
||||||
},
|
},
|
||||||
extension: undefined,
|
extension: undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
// 将 WebView 定位到父元素
|
// 将 WebView 定位到父元素
|
||||||
if (this.webview) {
|
if (this.webview) {
|
||||||
|
// 获取当前激活的窗口
|
||||||
// 获取当前激活的窗口
|
// 获取当前激活的窗口
|
||||||
const targetWindow = DOM.getActiveWindow();
|
const targetWindow = DOM.getActiveWindow();
|
||||||
|
|
||||||
|
|
||||||
if (!targetWindow) {
|
if (!targetWindow) {
|
||||||
console.error('无法获取活动窗口');
|
console.error('无法获取活动窗口');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Claim WebView 所有权,绑定到目标窗口
|
||||||
// Claim WebView 所有权,绑定到目标窗口
|
// Claim WebView 所有权,绑定到目标窗口
|
||||||
this.webview.claim(this, targetWindow as any, undefined);
|
this.webview.claim(this, targetWindow as any, undefined);
|
||||||
|
|
||||||
|
// 使用 layoutWebviewOverElement 方法,将 WebView 定位到 `parent`
|
||||||
|
|
||||||
// 使用 layoutWebviewOverElement 方法,将 WebView 定位到 `parent`
|
// 使用 layoutWebviewOverElement 方法,将 WebView 定位到 `parent`
|
||||||
this.webview.layoutWebviewOverElement(parent, new Dimension(parent.offsetWidth, parent.offsetHeight));
|
this.webview.layoutWebviewOverElement(parent, new Dimension(parent.offsetWidth, parent.offsetHeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -79,7 +86,6 @@ export class StockDetailsEditor extends EditorPane {
|
|||||||
console.log(`setInput 接收到股票代码: ${input.getCode()}`);
|
console.log(`setInput 接收到股票代码: ${input.getCode()}`);
|
||||||
const stockCode = input.getCode();
|
const stockCode = input.getCode();
|
||||||
|
|
||||||
|
|
||||||
if (!stockCode || stockCode.trim() === '') {
|
if (!stockCode || stockCode.trim() === '') {
|
||||||
this.renderErrorMessage('股票代码为空,请选择有效的股票。');
|
this.renderErrorMessage('股票代码为空,请选择有效的股票。');
|
||||||
return;
|
return;
|
||||||
@ -142,6 +148,8 @@ export class StockDetailsEditor extends EditorPane {
|
|||||||
font-family: Arial, sans-serif;
|
font-family: Arial, sans-serif;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
|
background: #f5f5f5;
|
||||||
|
color: #333;
|
||||||
}
|
}
|
||||||
h1 {
|
h1 {
|
||||||
font-size: 24px;
|
font-size: 24px;
|
||||||
@ -174,17 +182,22 @@ export class StockDetailsEditor extends EditorPane {
|
|||||||
* 渲染错误消息。
|
* 渲染错误消息。
|
||||||
*/
|
*/
|
||||||
private renderErrorMessage(message: string): void {
|
private renderErrorMessage(message: string): void {
|
||||||
if (!this.container) {
|
if (this.webview) {
|
||||||
return;
|
const errorContent = `
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>错误</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1 style="color: red;">错误</h1>
|
||||||
|
<p>${message}</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
`;
|
||||||
|
this.webview.setHtml(errorContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.container.textContent = ''; // 清空之前的内容
|
|
||||||
|
|
||||||
const errorDiv = document.createElement('div');
|
|
||||||
errorDiv.className = 'stock-error';
|
|
||||||
errorDiv.textContent = message;
|
|
||||||
|
|
||||||
this.container.appendChild(errorDiv);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -194,10 +207,13 @@ export class StockDetailsEditor extends EditorPane {
|
|||||||
if (this.webview && this.webview.container) {
|
if (this.webview && this.webview.container) {
|
||||||
const webviewContainer = this.webview.container;
|
const webviewContainer = this.webview.container;
|
||||||
|
|
||||||
|
// 设置 WebView 的宽高
|
||||||
|
|
||||||
// 设置 WebView 的宽高
|
// 设置 WebView 的宽高
|
||||||
webviewContainer.style.width = `${dimension.width}px`;
|
webviewContainer.style.width = `${dimension.width}px`;
|
||||||
webviewContainer.style.height = `${dimension.height}px`;
|
webviewContainer.style.height = `${dimension.height}px`;
|
||||||
|
|
||||||
|
// 限制 WebView 到当前编辑器区域
|
||||||
// 限制 WebView 到当前编辑器区域
|
// 限制 WebView 到当前编辑器区域
|
||||||
const clippingContainer = this.getContainer();
|
const clippingContainer = this.getContainer();
|
||||||
if (clippingContainer) {
|
if (clippingContainer) {
|
||||||
@ -221,3 +237,5 @@ export class StockDetailsEditor extends EditorPane {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user