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