diff --git a/src/views/exampleShowcase.ts b/src/views/exampleShowcase.ts index eaa2549..939d0df 100644 --- a/src/views/exampleShowcase.ts +++ b/src/views/exampleShowcase.ts @@ -4,7 +4,14 @@ export function getExampleShowcaseContent(): string { return `
-
示例
+
+
示例
+ +
@@ -54,12 +61,44 @@ export function getExampleShowcaseStyles(): string { display: none; } + .showcase-header { + display: flex; + align-items: center; + justify-content: space-between; + margin-bottom: 12px; + } + .showcase-title { font-size: 14px; font-weight: 600; color: var(--vscode-foreground); - margin-bottom: 12px; - text-align: left; + } + + .refresh-button { + background: transparent; + border: none; + color: var(--vscode-foreground); + cursor: pointer; + padding: 4px; + display: flex; + align-items: center; + justify-content: center; + border-radius: 4px; + transition: all 0.2s ease; + opacity: 0.6; + } + + .refresh-button:hover { + opacity: 1; + background: var(--vscode-input-background); + } + + .refresh-button svg { + transition: transform 0.3s ease; + } + + .refresh-button:active svg { + transform: rotate(180deg); } .example-cards { @@ -173,15 +212,74 @@ export function getExampleShowcaseStyles(): string { */ export function getExampleShowcaseScript(): string { return ` - // 示例文本数组 - const exampleTexts = [ - '生成一个SPI控制器', - '生成一个GMII接口的以太网UDP通信模块' + // 所有可用的示例 + const allExamples = [ + '设计一个算术逻辑单元,完成常见运算', + '实现一个优先编码器,多个输入同时有效时,只输出优先级最高的那个编号', + '实现一个译码器,把二进制编号转换成 one-hot 输出', + '实现一个移位寄存器,完成串行/并行数据移位与装载', + '实现一个按键消抖模块,解决机械按键抖动问题', + '实现一个跑马灯控制器,控制 LED 形成不同流动效果', + '实现一个序列检测器,检测串行输入中是否出现指定比特序列', + '实现一个LFSR 伪随机数发生器', + '实现一个自动售货机,模拟一个简单售货逻辑', + '实现一个交通灯控制器,控制两方向交通灯的切换', + '实现一个先进先出的数据缓冲区', + '单端口 RAM 读写控制器', + '实现一个移位加法乘法器,不用 * 运算符' ]; + // 当前显示的示例文本 + let exampleTexts = ['生成一个SPI控制器', '生成一个GMII接口的以太网UDP通信模块']; + // 存储待发送的示例索引 let pendingExampleIndex = -1; + // 节流控制 + let refreshing = false; + + // 刷新示例 + function refreshExamples() { + if (refreshing) return; + refreshing = true; + + const used = new Set(); + const newExamples = []; + while (newExamples.length < 2) { + const idx = Math.floor(Math.random() * allExamples.length); + if (!used.has(idx)) { + used.add(idx); + newExamples.push(allExamples[idx]); + } + } + exampleTexts = newExamples; + updateExampleCards(); + + setTimeout(() => { refreshing = false; }, 500); + } + + // 更新示例卡片显示 + function updateExampleCards() { + const container = document.querySelector('.example-cards'); + if (!container) return; + container.innerHTML = exampleTexts.map((text, i) => \` +
+
+ + + + + + + +
+
+
\${text}
+
+
+ \`).join(''); + } + // 直接发送示例消息 function sendExample(index) { // 先检查邀请码验证状态