-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex_simple.html
More file actions
639 lines (552 loc) · 18.1 KB
/
Copy pathindex_simple.html
File metadata and controls
639 lines (552 loc) · 18.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DeskMate - 智能办公助手</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
background: #0d1117;
color: #c9d1d9;
height: 100vh;
display: flex;
flex-direction: column;
}
.container {
display: flex;
flex: 1;
overflow: hidden;
}
.sidebar {
width: 260px;
background: #161b22;
border-right: 1px solid #30363d;
display: flex;
flex-direction: column;
padding: 16px;
}
.main-content {
flex: 1;
display: flex;
flex-direction: column;
overflow: hidden;
}
.header {
padding: 16px 20px;
background: #161b22;
border-bottom: 1px solid #30363d;
display: flex;
align-items: center;
justify-content: space-between;
}
.logo {
font-size: 20px;
font-weight: 600;
color: #58a6ff;
display: flex;
align-items: center;
gap: 8px;
}
.chat-container {
flex: 1;
display: flex;
flex-direction: column;
overflow: hidden;
}
.messages {
flex: 1;
overflow-y: auto;
padding: 20px;
display: flex;
flex-direction: column;
gap: 12px;
}
.message {
max-width: 85%;
padding: 12px 16px;
border-radius: 8px;
animation: fadeIn 0.3s ease;
line-height: 1.6;
}
.message.user {
align-self: flex-end;
background: #1f6feb;
color: #ffffff;
border-radius: 8px 8px 0 8px;
}
.message.ai {
align-self: flex-start;
background: #21262d;
border: 1px solid #30363d;
border-radius: 8px 8px 8px 0;
}
.input-container {
padding: 16px 20px;
background: #161b22;
border-top: 1px solid #30363d;
}
.input-wrapper {
display: flex;
gap: 12px;
align-items: flex-end;
}
.chat-input {
flex: 1;
padding: 12px 16px;
border: 1px solid #30363d;
border-radius: 6px;
background: #0d1117;
color: #c9d1d9;
font-size: 14px;
outline: none;
transition: all 0.2s ease;
resize: none;
min-height: 44px;
max-height: 120px;
}
.chat-input:focus {
border-color: #58a6ff;
box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.2);
}
.send-btn {
padding: 12px 24px;
background: #238636;
color: #ffffff;
border: none;
border-radius: 6px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
transition: all 0.2s ease;
height: 44px;
}
.send-btn:hover {
background: #2ea043;
}
.send-btn:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.sidebar-item {
padding: 10px 12px;
margin-bottom: 4px;
border-radius: 6px;
background: transparent;
cursor: pointer;
transition: all 0.2s ease;
display: flex;
align-items: center;
gap: 10px;
color: #8b949e;
font-size: 14px;
}
.sidebar-item:hover {
background: #21262d;
color: #c9d1d9;
}
.sidebar-item.active {
background: #21262d;
color: #c9d1d9;
font-weight: 500;
}
.sidebar-icon {
font-size: 16px;
}
.loading {
display: flex;
align-items: center;
gap: 8px;
padding: 12px;
background: rgba(88, 166, 255, 0.1);
border-radius: 6px;
}
.loading-spinner {
width: 16px;
height: 16px;
border: 2px solid #58a6ff;
border-top: 2px solid transparent;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(8px); }
to { opacity: 1; transform: translateY(0); }
}
.file-list {
margin-top: 16px;
padding: 12px;
background: #21262d;
border-radius: 6px;
border: 1px solid #30363d;
}
.file-item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px;
margin-bottom: 6px;
background: #0d1117;
border-radius: 4px;
font-size: 13px;
}
.file-name {
color: #c9d1d9;
font-weight: 500;
}
.file-size {
color: #8b949e;
font-size: 12px;
}
.delete-btn {
padding: 4px 10px;
background: #da3633;
color: #ffffff;
border: none;
border-radius: 4px;
font-size: 12px;
cursor: pointer;
transition: all 0.2s ease;
}
.delete-btn:hover {
background: #f85149;
}
.status-bar {
padding: 8px 16px;
background: #0d1117;
border-top: 1px solid #30363d;
font-size: 12px;
color: #8b949e;
display: flex;
align-items: center;
gap: 8px;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #238636;
}
.status-dot.offline {
background: #da3633;
}
</style>
</head>
<body>
<div class="container">
<div class="sidebar">
<div class="logo">
<span>🚀</span>
<span>DeskMate</span>
</div>
<div class="sidebar-item active">
<span class="sidebar-icon">💬</span>
<span>对话</span>
</div>
<div class="sidebar-item">
<span class="sidebar-icon">📁</span>
<span>文件</span>
</div>
<div class="sidebar-item">
<span class="sidebar-icon">📊</span>
<span>分析</span>
</div>
<div class="sidebar-item" onclick="showSettings()">
<span class="sidebar-icon">⚙️</span>
<span>设置</span>
</div>
<div class="file-list">
<div style="font-size: 11px; color: #8b949e; margin-bottom: 8px; font-weight: 500;">已上传文件</div>
<div id="file-items"></div>
</div>
</div>
<div class="main-content">
<div class="header">
<div class="logo">
<span>🚀</span>
<span>DeskMate</span>
</div>
<div style="font-size: 13px; color: #8b949e;">智能办公助手</div>
</div>
<div class="chat-container">
<div class="messages" id="messages"></div>
<div class="input-container">
<div class="input-wrapper">
<textarea class="chat-input" id="chat-input" placeholder="输入您的消息..." rows="1"></textarea>
<button class="send-btn" id="send-btn" onclick="sendMessage()">发送</button>
</div>
</div>
</div>
<div class="status-bar">
<div class="status-dot" id="status-dot"></div>
<span id="status-text">就绪</span>
</div>
</div>
</div>
<div id="settings-modal" style="display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.7); z-index: 1000; display: flex; align-items: center; justify-content: center;">
<div style="background: #161b22; border: 1px solid #30363d; border-radius: 8px; padding: 24px; width: 500px; max-width: 90%;">
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px;">
<div style="font-size: 18px; font-weight: 600; color: #c9d1d9;">设置</div>
<button onclick="hideSettings()" style="background: none; border: none; color: #8b949e; font-size: 24px; cursor: pointer;">×</button>
</div>
<div style="margin-bottom: 16px;">
<label style="display: block; font-size: 14px; color: #c9d1d9; margin-bottom: 8px;">API密钥</label>
<input type="password" id="api-key-input" placeholder="请输入您的千问API密钥" style="width: 100%; padding: 10px; border: 1px solid #30363d; border-radius: 6px; background: #0d1117; color: #c9d1d9; font-size: 14px; outline: none;">
</div>
<div style="margin-bottom: 16px;">
<label style="display: block; font-size: 14px; color: #c9d1d9; margin-bottom: 8px;">API Endpoint</label>
<input type="text" id="api-endpoint-input" placeholder="https://api.modelarts-maas.com/openai/v1/chat/completions" style="width: 100%; padding: 10px; border: 1px solid #30363d; border-radius: 6px; background: #0d1117; color: #c9d1d9; font-size: 14px; outline: none;">
</div>
<div style="margin-bottom: 24px;">
<label style="display: block; font-size: 14px; color: #c9d1d9; margin-bottom: 8px;">模型名称</label>
<input type="text" id="model-input" placeholder="qwen3-coder-480b-a35b-instruct" style="width: 100%; padding: 10px; border: 1px solid #30363d; border-radius: 6px; background: #0d1117; color: #c9d1d9; font-size: 14px; outline: none;">
</div>
<div style="display: flex; gap: 12px; justify-content: flex-end;">
<button onclick="hideSettings()" style="padding: 10px 20px; background: #30363d; color: #c9d1d9; border: none; border-radius: 6px; font-size: 14px; cursor: pointer;">取消</button>
<button onclick="saveSettings()" style="padding: 10px 20px; background: #238636; color: #ffffff; border: none; border-radius: 6px; font-size: 14px; cursor: pointer;">保存</button>
</div>
</div>
</div>
<script>
// 千问API配置 - 从localStorage读取
let QWEN_API_KEY = localStorage.getItem('qwen_api_key') || "iNjoFN6OE1BS_tio6SWa478Dw6DPbIuKpccEOp7wKOh_f3xf6eDxS0EGgHTYYJG-j3tp-TdGuNATgl0l2WJ0wQ";
let QWEN_API_ENDPOINT = localStorage.getItem('qwen_api_endpoint') || "https://api.modelarts-maas.com/openai/v1/chat/completions";
let QWEN_MODEL = localStorage.getItem('qwen_model') || "qwen3-coder-480b-a35b-instruct";
// 显示设置对话框
function showSettings() {
const modal = document.getElementById('settings-modal');
modal.style.display = 'flex';
// 填充当前配置
document.getElementById('api-key-input').value = QWEN_API_KEY;
document.getElementById('api-endpoint-input').value = QWEN_API_ENDPOINT;
document.getElementById('model-input').value = QWEN_MODEL;
}
// 隐藏设置对话框
function hideSettings() {
const modal = document.getElementById('settings-modal');
modal.style.display = 'none';
}
// 保存设置
function saveSettings() {
const apiKey = document.getElementById('api-key-input').value.trim();
const apiEndpoint = document.getElementById('api-endpoint-input').value.trim();
const model = document.getElementById('model-input').value.trim();
if (!apiKey) {
alert('请输入API密钥');
return;
}
// 保存到localStorage
localStorage.setItem('qwen_api_key', apiKey);
localStorage.setItem('qwen_api_endpoint', apiEndpoint);
localStorage.setItem('qwen_model', model);
// 更新全局变量
QWEN_API_KEY = apiKey;
QWEN_API_ENDPOINT = apiEndpoint;
QWEN_MODEL = model;
// 隐藏对话框
hideSettings();
// 提示用户
addMessage('ai', '✅ 设置已保存!');
}
// 全局变量
let selectedFiles = [];
let excelDataList = [];
let columnNamesList = [];
let conversationHistory = [];
let isProcessing = false;
// 添加消息到聊天界面
function addMessage(type, content) {
const messagesDiv = document.getElementById('messages');
const messageDiv = document.createElement('div');
messageDiv.className = `message ${type}`;
// 处理不同类型的消息
if (type === 'loading') {
messageDiv.innerHTML = `
<div class="loading">
<div class="loading-spinner"></div>
<span>${content}</span>
</div>
`;
} else {
// 处理普通文本消息
const formattedContent = content.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
.replace(/\n/g, '<br>');
messageDiv.innerHTML = `
<div style="font-size: 14px;">
${formattedContent}
</div>
`;
}
messagesDiv.appendChild(messageDiv);
messagesDiv.scrollTop = messagesDiv.scrollHeight;
// 添加到对话历史
conversationHistory.push({
type: type,
content: content,
timestamp: new Date()
});
// 返回消息元素,以便后续操作
return messageDiv;
}
// 更新状态
function updateStatus(status, text) {
const statusDot = document.getElementById('status-dot');
const statusText = document.getElementById('status-text');
statusDot.className = `status-dot ${status === 'offline' ? 'offline' : ''}`;
statusText.textContent = text;
}
// 调用千问API
async function callQwenAPI(messages) {
try {
const response = await fetch(QWEN_API_ENDPOINT, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${QWEN_API_KEY}`
},
body: JSON.stringify({
model: QWEN_MODEL,
messages: messages,
temperature: 0.7,
max_tokens: 2000
})
});
if (!response.ok) {
throw new Error(`API请求失败: ${response.status}`);
}
const data = await response.json();
return data.choices[0].message.content;
} catch (error) {
console.error('调用千问API失败:', error);
throw error;
}
}
// 发送消息
async function sendMessage() {
if (isProcessing) {
return;
}
const input = document.getElementById('chat-input');
const sendBtn = document.getElementById('send-btn');
const message = input.value.trim();
if (!message) {
return;
}
// 添加用户消息
addMessage('user', message);
input.value = '';
sendBtn.disabled = true;
isProcessing = true;
updateStatus('processing', '处理中...');
// 显示加载状态
const loadingMessage = addMessage('ai', '正在思考...');
try {
// 构建消息历史
const messages = [
{
role: 'system',
content: '你是一个专业的办公助手,擅长处理Excel数据、文档、邮件等办公任务。请用简洁、专业的语言回答用户的问题。'
},
...conversationHistory.map(msg => ({
role: msg.type === 'user' ? 'user' : 'assistant',
content: msg.content
})),
{
role: 'user',
content: message
}
];
// 调用千问API
const result = await callQwenAPI(messages);
// 移除加载消息
loadingMessage.remove();
// 显示结果
addMessage('ai', result);
updateStatus('ready', '就绪');
} catch (error) {
console.error('处理失败:', error);
loadingMessage.remove();
addMessage('ai', `处理失败: ${error.message}`);
updateStatus('error', '错误');
}
sendBtn.disabled = false;
isProcessing = false;
}
// 上传文件
async function uploadFiles() {
try {
const result = await window.electronAPI.openFileDialog();
if (result) {
const file = {
name: result.split(/[/\\]/).pop(),
path: result
};
selectedFiles.push(file);
updateFileList();
addMessage('ai', `✅ 文件已上传: ${file.name}`);
}
} catch (error) {
console.error('上传文件失败:', error);
addMessage('ai', `❌ 上传文件失败: ${error.message}`);
}
}
// 更新文件列表
function updateFileList() {
const fileItemsDiv = document.getElementById('file-items');
fileItemsDiv.innerHTML = '';
selectedFiles.forEach((file, index) => {
const fileItem = document.createElement('div');
fileItem.className = 'file-item';
fileItem.innerHTML = `
<div>
<div class="file-name">${file.name}</div>
<div class="file-size">${file.path}</div>
</div>
<button class="delete-btn" onclick="deleteFile(${index})">删除</button>
`;
fileItemsDiv.appendChild(fileItem);
});
}
// 删除文件
function deleteFile(index) {
selectedFiles.splice(index, 1);
updateFileList();
addMessage('ai', '🗑️ 文件已删除');
}
// 自动调整文本框高度
document.getElementById('chat-input').addEventListener('input', function() {
this.style.height = 'auto';
this.style.height = Math.min(this.scrollHeight, 120) + 'px';
});
// 键盘事件
document.getElementById('chat-input').addEventListener('keypress', function(e) {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
sendMessage();
}
});
// 初始化
window.addEventListener('DOMContentLoaded', function() {
addMessage('ai', '👋 你好!我是DeskMate,你的智能办公助手。');
addMessage('ai', '我可以帮你处理以下任务:');
addMessage('ai', '• 📊 Excel数据分析和可视化');
addMessage('ai', '• 📄 文档处理和转换');
addMessage('ai', '• 📧 邮件管理和发送');
addMessage('ai', '• 📈 生成报告和总结');
addMessage('ai', '• 🔍 网络搜索和信息查询');
addMessage('ai', '');
addMessage('ai', '请上传文件或直接告诉我你的需求,我会尽力帮助你!');
updateStatus('ready', '就绪');
});
</script>
</body>
</html>