Trae Assistant commited on
Commit
e77d5c3
·
1 Parent(s): 92a264e

Fix Vue setup return object and clean up template file

Browse files
Files changed (1) hide show
  1. templates/index.html +45 -45
templates/index.html CHANGED
@@ -349,6 +349,51 @@
349
  downloadAnchorNode.remove();
350
  };
351
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
352
  const pollStats = () => {
353
  if (pollTimer) clearTimeout(pollTimer);
354
 
@@ -403,49 +448,4 @@
403
  }).mount('#app');
404
  </script>
405
  </body>
406
- </html>
407
- isRunning.value = data.running;
408
-
409
- // Push data to charts
410
- if (data.running) {
411
- const now = new Date().toLocaleTimeString();
412
- timeData.push(now);
413
- rpsData.push(data.rps);
414
- latencyData.push(data.avg_latency);
415
-
416
- // Keep only last 30 points
417
- if (timeData.length > 30) {
418
- timeData.shift();
419
- rpsData.shift();
420
- latencyData.shift();
421
- }
422
- updateCharts();
423
- }
424
-
425
- if (data.running) {
426
- pollStats();
427
- }
428
- } catch (e) {
429
- console.error(e);
430
- }
431
- }, 1000);
432
- };
433
-
434
- onMounted(() => {
435
- initCharts();
436
- });
437
-
438
- return {
439
- config,
440
- stats,
441
- isRunning,
442
- errorRate,
443
- startTest,
444
- stopTest,
445
- downloadReport
446
- };
447
- }
448
- }).mount('#app');
449
- </script>
450
- </body>
451
  </html>
 
349
  downloadAnchorNode.remove();
350
  };
351
 
352
+ const handleExport = () => {
353
+ const dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(config.value, null, 2));
354
+ const downloadAnchorNode = document.createElement('a');
355
+ downloadAnchorNode.setAttribute("href", dataStr);
356
+ downloadAnchorNode.setAttribute("download", "config_" + new Date().toISOString() + ".json");
357
+ document.body.appendChild(downloadAnchorNode);
358
+ downloadAnchorNode.click();
359
+ downloadAnchorNode.remove();
360
+ };
361
+
362
+ const handleImport = (event) => {
363
+ const file = event.target.files[0];
364
+ if (!file) return;
365
+
366
+ // 1. Size Validation (< 5MB)
367
+ if (file.size > 5 * 1024 * 1024) {
368
+ alert('文件过大!请上传小于 5MB 的文件。');
369
+ event.target.value = ''; // Reset input
370
+ return;
371
+ }
372
+
373
+ const reader = new FileReader();
374
+ reader.onload = (e) => {
375
+ const content = e.target.result;
376
+
377
+ // 2. Binary / Null Byte Check
378
+ if (content.includes('\0')) {
379
+ alert('检测到二进制内容或非法字符,请上传有效的 JSON 文件。');
380
+ event.target.value = '';
381
+ return;
382
+ }
383
+
384
+ try {
385
+ const importedConfig = JSON.parse(content);
386
+ // Merge imported config
387
+ config.value = { ...config.value, ...importedConfig };
388
+ alert('配置导入成功!');
389
+ } catch (err) {
390
+ alert('无效的 JSON 文件格式。');
391
+ }
392
+ event.target.value = ''; // Reset input
393
+ };
394
+ reader.readAsText(file);
395
+ };
396
+
397
  const pollStats = () => {
398
  if (pollTimer) clearTimeout(pollTimer);
399
 
 
448
  }).mount('#app');
449
  </script>
450
  </body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
451
  </html>