1+ import * as vscode from 'vscode' ;
2+
3+ export function activateGuide ( context : vscode . ExtensionContext ) {
4+ const guideViewProvider = new GuideViewProvider ( context ) ;
5+ context . subscriptions . push (
6+ vscode . window . registerWebviewViewProvider ( 'guideView' , guideViewProvider )
7+ ) ;
8+
9+ guideViewProvider . webview ?. onDidReceiveMessage ( ( message ) => {
10+ switch ( message . command ) {
11+ case 'saveApiKey' :
12+ // 保存 API 密钥
13+ context . globalState . update ( 'deepSeekApiKey' , message . apiKey ) ;
14+ break ;
15+ case 'openCommand' :
16+ // 打开指令
17+ vscode . commands . executeCommand ( message . command ) ;
18+ break ;
19+ }
20+ } ) ;
21+ }
22+
23+ class GuideViewProvider implements vscode . WebviewViewProvider {
24+ constructor ( private context : vscode . ExtensionContext ) { }
25+
26+ resolveWebviewView ( webviewView : vscode . WebviewView ) {
27+ webviewView . webview . options = {
28+ enableScripts : true ,
29+ localResourceRoots : [ this . context . extensionUri ] ,
30+ } ;
31+ webviewView . webview . html = this . getWebviewContent ( ) ;
32+ }
33+
34+ private getWebviewContent ( ) : string {
35+ // 获取 DeepSeek API 密钥
36+ const apiKey = this . context . globalState . get ( 'deepSeekApiKey' ) || '' ;
37+
38+ return `
39+ <!DOCTYPE html>
40+ <html lang="zh-CN">
41+ <head>
42+ <meta charset="UTF-8">
43+ <title>引导页</title>
44+ <style>
45+ body {
46+ font-family: Arial, sans-serif;
47+ margin: 20px;
48+ }
49+ h1 {
50+ color: #333;
51+ }
52+ .section {
53+ margin-bottom: 20px;
54+ }
55+ .section label {
56+ display: block;
57+ margin-bottom: 5px;
58+ }
59+ .section input {
60+ width: 100%;
61+ padding: 8px;
62+ margin-bottom: 10px;
63+ border: 1px solid #ccc;
64+ border-radius: 4px;
65+ }
66+ .section button {
67+ padding: 8px 16px;
68+ border: none;
69+ background-color: #4CAF50;
70+ color: white;
71+ border-radius: 4px;
72+ cursor: pointer;
73+ }
74+ .section button:hover {
75+ background-color: #45a049;
76+ }
77+ .section a {
78+ color: #007BFF;
79+ text-decoration: none;
80+ }
81+ .section a:hover {
82+ text-decoration: underline;
83+ }
84+ </style>
85+ </head>
86+ <body>
87+ <h1>欢迎使用 CodeReDesign 插件!</h1>
88+ <div class="section">
89+ <label for="apiKey">DeepSeek API 密钥:</label>
90+ <input type="text" id="apiKey" value="${ apiKey } " placeholder="请输入您的 DeepSeek API 密钥" />
91+ <button id="saveApiKey">保存</button>
92+ </div>
93+ <div class="section">
94+ <h2>常用指令:</h2>
95+ <ul>
96+ <li><a href="#" id="generateCvb">生成 CVB 文件</a></li>
97+ <li><a href="#" id="uploadCvb">上传 CVB 文件</a></li>
98+ <li><a href="#" id="applyCvb">应用 CVB 文件</a></li>
99+ <li><a href="#" id="analyzeCode">分析代码</a></li>
100+ </ul>
101+ </div>
102+ <script>
103+ const vscode = acquireVsCodeApi();
104+
105+ // 保存 API 密钥
106+ document.getElementById('saveApiKey').addEventListener('click', () => {
107+ const apiKey = document.getElementById('apiKey').value;
108+ vscode.postMessage({ command: 'saveApiKey', apiKey });
109+ });
110+
111+ // 跳转到指令
112+ document.getElementById('generateCvb').addEventListener('click', () => {
113+ vscode.postMessage({ command: 'openCommand', command: 'codeReDesign.generateCvb' });
114+ });
115+ document.getElementById('uploadCvb').addEventListener('click', () => {
116+ vscode.postMessage({ command: 'openCommand', command: 'codeReDesign.uploadCvb' });
117+ });
118+ document.getElementById('applyCvb').addEventListener('click', () => {
119+ vscode.postMessage({ command: 'openCommand', command: 'codeReDesign.applyCvb' });
120+ });
121+ document.getElementById('analyzeCode').addEventListener('click', () => {
122+ vscode.postMessage({ command: 'openCommand', command: 'codeReDesign.analyzeCode' });
123+ });
124+ </script>
125+ </body>
126+ </html>
127+ ` ;
128+ }
129+
130+ }
0 commit comments