feat:设置最小宽度
- 小于最小宽度就自动关闭面板并且提供提示
This commit is contained in:
@ -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,7 +45,13 @@ function getTierIconUri(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const iconUri = webview.asWebviewUri(
|
const iconUri = webview.asWebviewUri(
|
||||||
vscode.Uri.joinPath(context.extensionUri, 'src', 'assets', 'titleIcon', iconFile)
|
vscode.Uri.joinPath(
|
||||||
|
context.extensionUri,
|
||||||
|
"src",
|
||||||
|
"assets",
|
||||||
|
"titleIcon",
|
||||||
|
iconFile
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
return iconUri.toString();
|
return iconUri.toString();
|
||||||
@ -94,7 +100,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"),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -119,16 +125,40 @@ export async function showICHelperPanel(
|
|||||||
|
|
||||||
// 获取模型图标URI
|
// 获取模型图标URI
|
||||||
const autoIconUri = panel.webview.asWebviewUri(
|
const autoIconUri = panel.webview.asWebviewUri(
|
||||||
vscode.Uri.joinPath(context.extensionUri, "src", "assets", "model", "Auto.png")
|
vscode.Uri.joinPath(
|
||||||
|
context.extensionUri,
|
||||||
|
"src",
|
||||||
|
"assets",
|
||||||
|
"model",
|
||||||
|
"Auto.png"
|
||||||
|
)
|
||||||
);
|
);
|
||||||
const liteIconUri = panel.webview.asWebviewUri(
|
const liteIconUri = panel.webview.asWebviewUri(
|
||||||
vscode.Uri.joinPath(context.extensionUri, "src", "assets", "model", "lite.png")
|
vscode.Uri.joinPath(
|
||||||
|
context.extensionUri,
|
||||||
|
"src",
|
||||||
|
"assets",
|
||||||
|
"model",
|
||||||
|
"lite.png"
|
||||||
|
)
|
||||||
);
|
);
|
||||||
const syIconUri = panel.webview.asWebviewUri(
|
const syIconUri = panel.webview.asWebviewUri(
|
||||||
vscode.Uri.joinPath(context.extensionUri, "src", "assets", "model", "Sy.png")
|
vscode.Uri.joinPath(
|
||||||
|
context.extensionUri,
|
||||||
|
"src",
|
||||||
|
"assets",
|
||||||
|
"model",
|
||||||
|
"Sy.png"
|
||||||
|
)
|
||||||
);
|
);
|
||||||
const maxIconUri = panel.webview.asWebviewUri(
|
const maxIconUri = panel.webview.asWebviewUri(
|
||||||
vscode.Uri.joinPath(context.extensionUri, "src", "assets", "model", "Max.png")
|
vscode.Uri.joinPath(
|
||||||
|
context.extensionUri,
|
||||||
|
"src",
|
||||||
|
"assets",
|
||||||
|
"model",
|
||||||
|
"Max.png"
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
// 设置HTML内容
|
// 设置HTML内容
|
||||||
@ -147,16 +177,20 @@ export async function showICHelperPanel(
|
|||||||
|
|
||||||
if (userInfo) {
|
if (userInfo) {
|
||||||
// 使用缓存的用户信息
|
// 使用缓存的用户信息
|
||||||
console.log('[ICHelperPanel] 使用缓存的用户信息:', userInfo);
|
console.log("[ICHelperPanel] 使用缓存的用户信息:", userInfo);
|
||||||
const tierIconUrl = getTierIconUri(panel.webview, context, userInfo.membership?.tierCode);
|
const tierIconUrl = getTierIconUri(
|
||||||
|
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 中获取
|
||||||
@ -164,19 +198,22 @@ export async function showICHelperPanel(
|
|||||||
createIfNone: false,
|
createIfNone: false,
|
||||||
});
|
});
|
||||||
if (session) {
|
if (session) {
|
||||||
console.log('[ICHelperPanel] 从 session 获取用户信息, account:', session.account);
|
console.log(
|
||||||
|
"[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);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理消息
|
// 处理消息
|
||||||
@ -213,14 +250,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":
|
||||||
@ -249,7 +286,10 @@ export async function showICHelperPanel(
|
|||||||
case "openWaveformViewer":
|
case "openWaveformViewer":
|
||||||
// 在新列中打开波形查看器
|
// 在新列中打开波形查看器
|
||||||
if (message.vcdFilePath) {
|
if (message.vcdFilePath) {
|
||||||
vscode.commands.executeCommand('ic-coder.openVCDViewer', message.vcdFilePath);
|
vscode.commands.executeCommand(
|
||||||
|
"ic-coder.openVCDViewer",
|
||||||
|
message.vcdFilePath
|
||||||
|
);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "getVCDInfo":
|
case "getVCDInfo":
|
||||||
@ -392,7 +432,11 @@ 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 (item.isDirectory() && item.name !== "node_modules" && !item.name.startsWith(".")) {
|
if (
|
||||||
|
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 });
|
||||||
@ -421,7 +465,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) {
|
||||||
@ -441,8 +485,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) {
|
||||||
@ -478,6 +522,29 @@ 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,6 +632,21 @@ 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 {
|
||||||
@ -742,6 +757,35 @@ 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