@ -33,10 +33,10 @@ function getTierIconUri(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const tierIconMap: Record<string, string> = {
|
const tierIconMap: Record<string, string> = {
|
||||||
BASIC: "free.png",
|
'BASIC': 'free.png',
|
||||||
TRIAL: "PRO-Try.png",
|
'TRIAL': 'PRO-Try.png',
|
||||||
ADVANCED: "PRO.png",
|
'ADVANCED': 'PRO.png',
|
||||||
PROFESSIONAL: "PRO+.png",
|
'PROFESSIONAL': 'PRO+.png'
|
||||||
};
|
};
|
||||||
|
|
||||||
const iconFile = tierIconMap[tierCode];
|
const iconFile = tierIconMap[tierCode];
|
||||||
@ -45,13 +45,7 @@ function getTierIconUri(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const iconUri = webview.asWebviewUri(
|
const iconUri = webview.asWebviewUri(
|
||||||
vscode.Uri.joinPath(
|
vscode.Uri.joinPath(context.extensionUri, 'src', 'assets', 'titleIcon', iconFile)
|
||||||
context.extensionUri,
|
|
||||||
"src",
|
|
||||||
"assets",
|
|
||||||
"titleIcon",
|
|
||||||
iconFile
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return iconUri.toString();
|
return iconUri.toString();
|
||||||
@ -100,7 +94,7 @@ export async function showICHelperPanel(
|
|||||||
retainContextWhenHidden: true,
|
retainContextWhenHidden: true,
|
||||||
localResourceRoots: [
|
localResourceRoots: [
|
||||||
vscode.Uri.joinPath(context.extensionUri, "media"),
|
vscode.Uri.joinPath(context.extensionUri, "media"),
|
||||||
vscode.Uri.joinPath(context.extensionUri, "src", "assets"),
|
vscode.Uri.joinPath(context.extensionUri, "src", "assets")
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -125,40 +119,16 @@ export async function showICHelperPanel(
|
|||||||
|
|
||||||
// 获取模型图标URI
|
// 获取模型图标URI
|
||||||
const autoIconUri = panel.webview.asWebviewUri(
|
const autoIconUri = panel.webview.asWebviewUri(
|
||||||
vscode.Uri.joinPath(
|
vscode.Uri.joinPath(context.extensionUri, "src", "assets", "model", "Auto.png")
|
||||||
context.extensionUri,
|
|
||||||
"src",
|
|
||||||
"assets",
|
|
||||||
"model",
|
|
||||||
"Auto.png"
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
const liteIconUri = panel.webview.asWebviewUri(
|
const liteIconUri = panel.webview.asWebviewUri(
|
||||||
vscode.Uri.joinPath(
|
vscode.Uri.joinPath(context.extensionUri, "src", "assets", "model", "lite.png")
|
||||||
context.extensionUri,
|
|
||||||
"src",
|
|
||||||
"assets",
|
|
||||||
"model",
|
|
||||||
"lite.png"
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
const syIconUri = panel.webview.asWebviewUri(
|
const syIconUri = panel.webview.asWebviewUri(
|
||||||
vscode.Uri.joinPath(
|
vscode.Uri.joinPath(context.extensionUri, "src", "assets", "model", "Sy.png")
|
||||||
context.extensionUri,
|
|
||||||
"src",
|
|
||||||
"assets",
|
|
||||||
"model",
|
|
||||||
"Sy.png"
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
const maxIconUri = panel.webview.asWebviewUri(
|
const maxIconUri = panel.webview.asWebviewUri(
|
||||||
vscode.Uri.joinPath(
|
vscode.Uri.joinPath(context.extensionUri, "src", "assets", "model", "Max.png")
|
||||||
context.extensionUri,
|
|
||||||
"src",
|
|
||||||
"assets",
|
|
||||||
"model",
|
|
||||||
"Max.png"
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// 设置HTML内容
|
// 设置HTML内容
|
||||||
@ -177,20 +147,16 @@ export async function showICHelperPanel(
|
|||||||
|
|
||||||
if (userInfo) {
|
if (userInfo) {
|
||||||
// 使用缓存的用户信息
|
// 使用缓存的用户信息
|
||||||
console.log("[ICHelperPanel] 使用缓存的用户信息:", userInfo);
|
console.log('[ICHelperPanel] 使用缓存的用户信息:', userInfo);
|
||||||
const tierIconUrl = getTierIconUri(
|
const tierIconUrl = getTierIconUri(panel.webview, context, userInfo.membership?.tierCode);
|
||||||
panel.webview,
|
|
||||||
context,
|
|
||||||
userInfo.membership?.tierCode
|
|
||||||
);
|
|
||||||
panel.webview.postMessage({
|
panel.webview.postMessage({
|
||||||
command: "updateUserInfo",
|
command: 'updateUserInfo',
|
||||||
userInfo: {
|
userInfo: {
|
||||||
userId: userInfo.userId,
|
userId: userInfo.userId,
|
||||||
nickname: userInfo.nickname,
|
nickname: userInfo.nickname,
|
||||||
username: userInfo.username,
|
username: userInfo.username
|
||||||
},
|
},
|
||||||
tierIconUrl: tierIconUrl,
|
tierIconUrl: tierIconUrl
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// 如果没有缓存,从 session 中获取
|
// 如果没有缓存,从 session 中获取
|
||||||
@ -198,22 +164,19 @@ export async function showICHelperPanel(
|
|||||||
createIfNone: false,
|
createIfNone: false,
|
||||||
});
|
});
|
||||||
if (session) {
|
if (session) {
|
||||||
console.log(
|
console.log('[ICHelperPanel] 从 session 获取用户信息, account:', session.account);
|
||||||
"[ICHelperPanel] 从 session 获取用户信息, account:",
|
|
||||||
session.account
|
|
||||||
);
|
|
||||||
panel.webview.postMessage({
|
panel.webview.postMessage({
|
||||||
command: "updateUserInfo",
|
command: 'updateUserInfo',
|
||||||
userInfo: {
|
userInfo: {
|
||||||
userId: session.account.id,
|
userId: session.account.id,
|
||||||
nickname: session.account.label,
|
nickname: session.account.label,
|
||||||
username: session.account.label,
|
username: session.account.label
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("[ICHelperPanel] 获取用户信息失败:", error);
|
console.error('[ICHelperPanel] 获取用户信息失败:', error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理消息
|
// 处理消息
|
||||||
@ -250,14 +213,14 @@ export async function showICHelperPanel(
|
|||||||
historyManager.switchToPanelTask(panelId);
|
historyManager.switchToPanelTask(panelId);
|
||||||
|
|
||||||
// 显示进度条
|
// 显示进度条
|
||||||
panel.webview.postMessage({ type: "showProgress" });
|
panel.webview.postMessage({ type: 'showProgress' });
|
||||||
|
|
||||||
handleUserMessage(
|
handleUserMessage(
|
||||||
panel,
|
panel,
|
||||||
message.text,
|
message.text,
|
||||||
context.extensionPath,
|
context.extensionPath,
|
||||||
message.mode,
|
message.mode,
|
||||||
message.model // 传递服务等级
|
message.model // 传递服务等级
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case "readFile":
|
case "readFile":
|
||||||
@ -286,10 +249,7 @@ export async function showICHelperPanel(
|
|||||||
case "openWaveformViewer":
|
case "openWaveformViewer":
|
||||||
// 在新列中打开波形查看器
|
// 在新列中打开波形查看器
|
||||||
if (message.vcdFilePath) {
|
if (message.vcdFilePath) {
|
||||||
vscode.commands.executeCommand(
|
vscode.commands.executeCommand('ic-coder.openVCDViewer', message.vcdFilePath);
|
||||||
"ic-coder.openVCDViewer",
|
|
||||||
message.vcdFilePath
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "getVCDInfo":
|
case "getVCDInfo":
|
||||||
@ -432,11 +392,7 @@ export async function showICHelperPanel(
|
|||||||
try {
|
try {
|
||||||
const items = fs.readdirSync(dir, { withFileTypes: true });
|
const items = fs.readdirSync(dir, { withFileTypes: true });
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
if (
|
if (item.isDirectory() && item.name !== "node_modules" && !item.name.startsWith(".")) {
|
||||||
item.isDirectory() &&
|
|
||||||
item.name !== "node_modules" &&
|
|
||||||
!item.name.startsWith(".")
|
|
||||||
) {
|
|
||||||
const fullPath = path.join(dir, item.name);
|
const fullPath = path.join(dir, item.name);
|
||||||
const relativePath = path.relative(baseDir, fullPath);
|
const relativePath = path.relative(baseDir, fullPath);
|
||||||
folders.push({ path: fullPath, relativePath });
|
folders.push({ path: fullPath, relativePath });
|
||||||
@ -465,7 +421,7 @@ export async function showICHelperPanel(
|
|||||||
canSelectMany: true,
|
canSelectMany: true,
|
||||||
openLabel: "选择图片",
|
openLabel: "选择图片",
|
||||||
filters: {
|
filters: {
|
||||||
图片文件: ["png", "jpg", "jpeg", "gif", "bmp", "svg", "webp"],
|
"图片文件": ["png", "jpg", "jpeg", "gif", "bmp", "svg", "webp"],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (imageUris && imageUris.length > 0) {
|
if (imageUris && imageUris.length > 0) {
|
||||||
@ -485,8 +441,8 @@ export async function showICHelperPanel(
|
|||||||
canSelectMany: true,
|
canSelectMany: true,
|
||||||
openLabel: "选择文档",
|
openLabel: "选择文档",
|
||||||
filters: {
|
filters: {
|
||||||
文档文件: ["pdf", "doc", "docx", "txt", "md"],
|
"文档文件": ["pdf", "doc", "docx", "txt", "md"],
|
||||||
所有文件: ["*"],
|
"所有文件": ["*"],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (docUris && docUris.length > 0) {
|
if (docUris && docUris.length > 0) {
|
||||||
@ -522,29 +478,6 @@ export async function showICHelperPanel(
|
|||||||
hasWorkspace: hasWorkspace,
|
hasWorkspace: hasWorkspace,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
// 新增:处理面板宽度不足
|
|
||||||
case "panelWidthInsufficient":
|
|
||||||
// 关闭面板
|
|
||||||
panel.dispose();
|
|
||||||
vscode.window.showWarningMessage(
|
|
||||||
"聊天面板宽度不足(最小 200px),已自动关闭"
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
undefined,
|
|
||||||
context.subscriptions
|
|
||||||
);
|
|
||||||
|
|
||||||
// 监听面板状态变化,检查宽度
|
|
||||||
panel.onDidChangeViewState(
|
|
||||||
(e) => {
|
|
||||||
if (e.webviewPanel.visible) {
|
|
||||||
// 请求前端检查宽度
|
|
||||||
panel.webview.postMessage({
|
|
||||||
command: "checkPanelWidth",
|
|
||||||
minWidth: 200,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
undefined,
|
undefined,
|
||||||
|
|||||||
@ -632,21 +632,6 @@ export function getWebviewContent(
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'checkPanelWidth':
|
|
||||||
// 检查面板宽度
|
|
||||||
const minWidth = message.minWidth || 200;
|
|
||||||
const currentWidth = document.body.clientWidth;
|
|
||||||
console.log('[WebView] 检查面板宽度:', currentWidth, '最小宽度:', minWidth);
|
|
||||||
if (currentWidth < minWidth) {
|
|
||||||
// 宽度不足,通知后端关闭面板
|
|
||||||
vscode.postMessage({
|
|
||||||
command: 'panelWidthInsufficient',
|
|
||||||
currentWidth: currentWidth,
|
|
||||||
minWidth: minWidth
|
|
||||||
});
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'vcdInfo':
|
case 'vcdInfo':
|
||||||
// 渲染迷你波形预览信息
|
// 渲染迷你波形预览信息
|
||||||
try {
|
try {
|
||||||
@ -757,35 +742,6 @@ export function getWebviewContent(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 监听窗口大小变化,检查面板宽度
|
|
||||||
let resizeTimer;
|
|
||||||
const MIN_PANEL_WIDTH = 500;
|
|
||||||
|
|
||||||
function checkPanelWidth() {
|
|
||||||
const currentWidth = document.body.clientWidth;
|
|
||||||
if (currentWidth < MIN_PANEL_WIDTH) {
|
|
||||||
console.log('[WebView] 面板宽度不足:', currentWidth, 'px,最小要求:', MIN_PANEL_WIDTH, 'px');
|
|
||||||
vscode.postMessage({
|
|
||||||
command: 'panelWidthInsufficient',
|
|
||||||
currentWidth: currentWidth,
|
|
||||||
minWidth: MIN_PANEL_WIDTH
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
window.addEventListener('resize', () => {
|
|
||||||
// 使用防抖,避免频繁检查
|
|
||||||
clearTimeout(resizeTimer);
|
|
||||||
resizeTimer = setTimeout(() => {
|
|
||||||
checkPanelWidth();
|
|
||||||
}, 300);
|
|
||||||
});
|
|
||||||
|
|
||||||
// 初始加载时也检查一次
|
|
||||||
setTimeout(() => {
|
|
||||||
checkPanelWidth();
|
|
||||||
}, 500);
|
|
||||||
|
|
||||||
${getMessageAreaScript()}
|
${getMessageAreaScript()}
|
||||||
${getAgentCardScript()}
|
${getAgentCardScript()}
|
||||||
${getWaveformPreviewScript()}
|
${getWaveformPreviewScript()}
|
||||||
|
|||||||
Reference in New Issue
Block a user