feat: 实现试用用户欢迎引导和过期检测功能

- 新增试用用户首次登录欢迎弹窗,展示使用教程
- 新增试用期过期检测服务和过期提醒弹窗
- 从 JWT token 中提取 ispluginTrial 标识判断用户类型
- 试用用户跳过邀请码验证流程
- 在消息发送前检查试用期是否过期
- 新增 ExpiredPanel 和 WelcomePanel 面板组件
- 新增 expiredModal 和 welcomeModal 视图组件
- 优化用户登录流程,根据用户类型显示不同引导
This commit is contained in:
Roe-xin
2026-02-26 15:42:18 +08:00
parent 316c784bde
commit 208c24682b
12 changed files with 924 additions and 7 deletions

218
src/views/expiredModal.ts Normal file
View File

@ -0,0 +1,218 @@
/**
* 试用期过期弹窗
* 功能:在聊天面板内显示过期提醒模态窗口
* 依赖:无
* 使用场景:试用用户过期时在聊天面板内显示
*/
/**
* 获取过期弹窗的 HTML 内容
*/
export function getExpiredModalContent(logoUri?: string): string {
return `
<!-- 过期弹窗 -->
<div id="expiredModal" class="expired-modal" style="display: none;">
<div class="expired-modal-overlay"></div>
<div class="expired-modal-content">
${logoUri ? `<img src="${logoUri}" class="expired-logo-corner" alt="IC Coder" />` : ""}
<div class="expired-modal-header">
<div class="expired-icon">⏰</div>
<h2>您的试用期已到期</h2>
<p class="expired-modal-subtitle">感谢您使用 IC Coder您的 15 天试用期已结束。</p>
</div>
<div class="expired-modal-body">
<p class="expired-message">如需继续使用,请联系我们获取正式版本。</p>
<button id="expiredContactBtn" class="expired-btn expired-btn-primary">
<span>联系我们</span>
<svg width="16" height="16" viewBox="0 0 16 16" fill="none">
<path d="M6 3L11 8L6 13" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</button>
</div>
</div>
</div>
`;
}
/**
* 获取过期弹窗的 CSS 样式
*/
export function getExpiredModalStyles(): string {
return `
/* 过期弹窗样式 */
.expired-modal {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 10000;
display: flex;
align-items: center;
justify-content: center;
padding: 20px;
font-family: var(--vscode-font-family, "Segoe UI", Tahoma, Geneva, Verdana, sans-serif);
}
.expired-modal-overlay {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.7);
backdrop-filter: blur(5px);
animation: fadeIn 0.3s ease-out;
}
.expired-modal-content {
position: relative;
background: var(--vscode-editor-background);
border: 1px solid var(--vscode-widget-border);
border-radius: 12px;
width: 100%;
max-width: 450px;
box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
animation: modalSlideIn 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
overflow: hidden;
}
.expired-logo-corner {
position: absolute;
top: 16px;
left: 24px;
height: 40px;
width: auto;
opacity: 0.9;
z-index: 10;
}
.expired-modal-header {
padding: 60px 32px 20px;
text-align: center;
}
.expired-icon {
font-size: 48px;
margin-bottom: 16px;
}
.expired-modal-header h2 {
margin: 0 0 12px;
font-size: 24px;
font-weight: 600;
color: var(--vscode-errorForeground);
}
.expired-modal-subtitle {
margin: 0;
font-size: 14px;
color: var(--vscode-descriptionForeground);
line-height: 1.5;
}
.expired-modal-body {
padding: 0 32px 32px;
text-align: center;
}
.expired-message {
font-size: 14px;
color: var(--vscode-descriptionForeground);
margin: 20px 0;
line-height: 1.6;
}
.expired-btn {
width: 100%;
padding: 12px 16px;
font-size: 14px;
font-weight: 600;
border: none;
border-radius: 6px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
background: var(--vscode-button-background);
color: var(--vscode-button-foreground);
transition: all 0.2s;
margin-top: 24px;
}
.expired-btn:hover {
background: var(--vscode-button-hoverBackground);
transform: translateY(-1px);
box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.expired-btn:active {
transform: translateY(0);
}
`;
}
/**
* 获取过期弹窗的 JavaScript 逻辑
*/
export function getExpiredModalScript(): string {
return `
// 过期弹窗逻辑
(function() {
const modal = document.getElementById('expiredModal');
const contactBtn = document.getElementById('expiredContactBtn');
const overlay = modal?.querySelector('.expired-modal-overlay');
// 显示过期弹窗
window.showExpiredModal = function() {
if (modal) {
modal.style.display = 'flex';
}
};
// 隐藏过期弹窗
window.hideExpiredModal = function() {
if (modal) {
modal.style.display = 'none';
}
};
// 点击"联系我们"按钮
if (contactBtn) {
contactBtn.addEventListener('click', function() {
// 可以打开联系页面
// window.open('https://iccoder.com/contact', '_blank');
hideExpiredModal();
});
}
// 点击遮罩层关闭弹窗
if (overlay) {
overlay.addEventListener('click', function() {
hideExpiredModal();
});
}
// 阻止点击弹窗内容时关闭
const content = modal?.querySelector('.expired-modal-content');
if (content) {
content.addEventListener('click', function(e) {
e.stopPropagation();
});
}
// 监听来自后端的消息
window.addEventListener('message', function(event) {
const message = event.data;
if (message.command === 'showExpiredModal') {
showExpiredModal();
}
});
})();
`;
}

View File

@ -339,12 +339,14 @@ export function getInputAreaScript(): string {
if (messageInput) {
messageInput.addEventListener('input', autoResizeTextarea);
// 监听点击事件,检测工作区状态和邀请码验证状态
// 监听点击事件,检测工作区状态、试用期过期和邀请码验证状态
messageInput.addEventListener('focus', () => {
if (!hasCheckedWorkspace) {
hasCheckedWorkspace = true;
vscode.postMessage({ command: 'checkWorkspace' });
}
// 检查试用期是否过期
vscode.postMessage({ command: 'checkTrialExpiration' });
// 检查邀请码验证状态
vscode.postMessage({ command: 'checkInvitationCode' });
});

View File

@ -30,6 +30,16 @@ import {
getInvitationModalStyles,
getInvitationModalScript,
} from "./invitationModal";
import {
getWelcomeModalContent,
getWelcomeModalStyles,
getWelcomeModalScript,
} from "./welcomeModal";
import {
getExpiredModalContent,
getExpiredModalStyles,
getExpiredModalScript,
} from "./expiredModal";
/**
* 获取 WebView 面板的 HTML 内容
*/
@ -100,6 +110,8 @@ export function getWebviewContent(
${getProgressBarStyles()}
${getInputAreaStyles()}
${getInvitationModalStyles()}
${getWelcomeModalStyles()}
${getExpiredModalStyles()}
.file-editor-section {
margin-bottom: 15px;
@ -466,6 +478,8 @@ export function getWebviewContent(
${getConversationHistoryBarContent()}
${getProgressBarContent()}
${getInvitationModalContent(qrCodeUri, logoUri)}
${getWelcomeModalContent(logoUri)}
${getExpiredModalContent(logoUri)}
<div class="header">
<div style="display: flex; align-items: center; justify-content: center;">
<img src="${logoUri}" alt="IC Coder" style="max-width: 100%; height: auto; max-height: 80px;" />
@ -873,6 +887,8 @@ export function getWebviewContent(
${getProgressBarScript()}
${getInputAreaScript()}
${getInvitationModalScript()}
${getWelcomeModalScript()}
${getExpiredModalScript()}
</script></body>
</html>`;
}

261
src/views/welcomeModal.ts Normal file
View File

@ -0,0 +1,261 @@
/**
* 欢迎弹窗(试用用户)
* 功能:在聊天面板内显示欢迎模态窗口
* 依赖:无
* 使用场景:试用用户首次登录时在聊天面板内显示
*/
/**
* 获取欢迎弹窗的 HTML 内容
*/
export function getWelcomeModalContent(logoUri?: string): string {
return `
<!-- 欢迎弹窗 -->
<div id="welcomeModal" class="welcome-modal" style="display: none;">
<div class="welcome-modal-overlay"></div>
<div class="welcome-modal-content">
${logoUri ? `<img src="${logoUri}" class="welcome-logo-corner" alt="IC Coder" />` : ""}
<div class="welcome-modal-header">
<div class="welcome-icon">🎉</div>
<h2>欢迎使用 IC Coder</h2>
<p class="welcome-modal-subtitle">您已成功激活 15 天试用期,让我们开始探索 IC Coder 的强大功能吧!</p>
</div>
<div class="welcome-modal-body">
<div class="welcome-step">
<div class="welcome-step-icon">📝</div>
<div class="welcome-step-content">
<h3>步骤 1打开聊天面板</h3>
<p>点击侧边栏的 IC Coder 图标,或使用命令面板搜索 "IC Coder: Open Chat"</p>
</div>
</div>
<div class="welcome-step">
<div class="welcome-step-icon">💬</div>
<div class="welcome-step-content">
<h3>步骤 2输入您的需求</h3>
<p>描述您想要生成的 Verilog 代码或需要帮助的问题AI 将为您提供专业的解决方案</p>
</div>
</div>
<div class="welcome-step">
<div class="welcome-step-icon">🔬</div>
<div class="welcome-step-content">
<h3>步骤 3运行仿真</h3>
<p>使用 "生成 VCD" 命令运行 iverilog 仿真,并通过波形查看器查看仿真结果</p>
</div>
</div>
<button id="welcomeStartBtn" class="welcome-btn welcome-btn-primary">
<span>开始使用</span>
<svg width="16" height="16" viewBox="0 0 16 16" fill="none">
<path d="M6 3L11 8L6 13" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</button>
</div>
</div>
</div>
`;
}
/**
* 获取欢迎弹窗的 CSS 样式
*/
export function getWelcomeModalStyles(): string {
return `
/* 欢迎弹窗样式 */
.welcome-modal {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 10000;
display: flex;
align-items: center;
justify-content: center;
padding: 20px;
font-family: var(--vscode-font-family, "Segoe UI", Tahoma, Geneva, Verdana, sans-serif);
}
.welcome-modal-overlay {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.7);
backdrop-filter: blur(5px);
animation: fadeIn 0.3s ease-out;
}
.welcome-modal-content {
position: relative;
background: var(--vscode-editor-background);
border: 1px solid var(--vscode-widget-border);
border-radius: 12px;
width: 100%;
max-width: 500px;
box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
animation: modalSlideIn 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
overflow: hidden;
}
.welcome-logo-corner {
position: absolute;
top: 16px;
left: 24px;
height: 40px;
width: auto;
opacity: 0.9;
z-index: 10;
}
.welcome-modal-header {
padding: 60px 32px 20px;
text-align: center;
}
.welcome-icon {
font-size: 48px;
margin-bottom: 16px;
}
.welcome-modal-header h2 {
margin: 0 0 12px;
font-size: 24px;
font-weight: 600;
color: var(--vscode-foreground);
}
.welcome-modal-subtitle {
margin: 0;
font-size: 14px;
color: var(--vscode-descriptionForeground);
line-height: 1.5;
}
.welcome-modal-body {
padding: 0 32px 32px;
}
.welcome-step {
display: flex;
gap: 16px;
margin: 20px 0;
padding: 16px;
background: var(--vscode-editor-inactiveSelectionBackground);
border-radius: 8px;
border-left: 4px solid var(--vscode-textLink-foreground);
}
.welcome-step-icon {
font-size: 24px;
flex-shrink: 0;
}
.welcome-step-content h3 {
margin: 0 0 8px;
font-size: 15px;
font-weight: 600;
color: var(--vscode-textLink-foreground);
}
.welcome-step-content p {
margin: 0;
font-size: 13px;
color: var(--vscode-descriptionForeground);
line-height: 1.5;
}
.welcome-btn {
width: 100%;
padding: 12px 16px;
font-size: 14px;
font-weight: 600;
border: none;
border-radius: 6px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
background: var(--vscode-button-background);
color: var(--vscode-button-foreground);
transition: all 0.2s;
margin-top: 24px;
}
.welcome-btn:hover {
background: var(--vscode-button-hoverBackground);
transform: translateY(-1px);
box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.welcome-btn:active {
transform: translateY(0);
}
`;
}
/**
* 获取欢迎弹窗的 JavaScript 逻辑
*/
export function getWelcomeModalScript(): string {
return `
// 欢迎弹窗逻辑
(function() {
const modal = document.getElementById('welcomeModal');
const startBtn = document.getElementById('welcomeStartBtn');
const overlay = modal?.querySelector('.welcome-modal-overlay');
// 显示欢迎弹窗
window.showWelcomeModal = function() {
if (modal) {
modal.style.display = 'flex';
}
};
// 隐藏欢迎弹窗
window.hideWelcomeModal = function() {
if (modal) {
modal.style.display = 'none';
}
};
// 点击"开始使用"按钮
if (startBtn) {
startBtn.addEventListener('click', function() {
hideWelcomeModal();
});
}
// 点击遮罩层关闭弹窗
if (overlay) {
overlay.addEventListener('click', function() {
hideWelcomeModal();
});
}
// 阻止点击弹窗内容时关闭
const content = modal?.querySelector('.welcome-modal-content');
if (content) {
content.addEventListener('click', function(e) {
e.stopPropagation();
});
}
// 监听来自后端的消息
window.addEventListener('message', function(event) {
const message = event.data;
if (message.command === 'showWelcomeModal') {
showWelcomeModal();
}
});
// 页面加载时检查是否需要显示欢迎弹窗
vscode.postMessage({ command: 'checkWelcomeModal' });
})();
`;
}