不再提供模板
This commit is contained in:
270
src/panels/views/ConfigView.ts
Normal file
270
src/panels/views/ConfigView.ts
Normal file
@@ -0,0 +1,270 @@
|
||||
// src/panels/views/ConfigView.ts
|
||||
import { BaseView } from './BaseView';
|
||||
import { ContainerConfigData, ConfigViewData } from '../types/ViewTypes';
|
||||
|
||||
export class ConfigView extends BaseView {
|
||||
render(data?: ContainerConfigData): string {
|
||||
const container = data?.container;
|
||||
const configs = data?.configs || [];
|
||||
|
||||
// 生成配置列表的 HTML - 添加文件名编辑功能
|
||||
const configsHtml = configs.map((config: ConfigViewData) => `
|
||||
<tr>
|
||||
<td>
|
||||
<span class="editable" onclick="editConfigName('${config.id}', '${config.name}')">🔧 ${config.name}</span>
|
||||
</td>
|
||||
<td>
|
||||
<span class="editable" onclick="editFileName('${config.id}', '${config.fileName}')">📄 ${config.fileName}</span>
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn-delete" onclick="deleteConfig('${config.id}')">删除</button>
|
||||
</td>
|
||||
</tr>
|
||||
`).join('');
|
||||
|
||||
return `<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>配置管理</title>
|
||||
${this.getStyles()}
|
||||
</head>
|
||||
<body>
|
||||
<div class="header">
|
||||
<h2>⚙️ 配置管理 - <span style="color: var(--vscode-textLink-foreground);">${container?.name || '未知容器'}</span></h2>
|
||||
<button class="back-btn" onclick="goBackToContainers()">← 返回容器管理</button>
|
||||
</div>
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="30%">配置</th>
|
||||
<th width="40%">文件</th>
|
||||
<th width="30%">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
${configsHtml}
|
||||
<tr>
|
||||
<td colspan="3" style="text-align: center; padding: 20px;">
|
||||
<button class="btn-new" onclick="createNewConfig()">+ 新建配置</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<!-- 配置文件编辑器 -->
|
||||
<div class="config-editor" id="configEditor" style="display: none;">
|
||||
<h3>📝 编辑配置文件</h3>
|
||||
<textarea id="configContent" placeholder="在此编辑配置文件内容..."></textarea>
|
||||
<div style="margin-top: 15px;">
|
||||
<button class="btn-primary" onclick="saveConfigFile()">💾 保存到文件系统</button>
|
||||
<button class="back-btn" onclick="closeEditor()">取消</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const vscode = acquireVsCodeApi();
|
||||
let currentConfigId = null;
|
||||
|
||||
function editConfigName(configId, currentName) {
|
||||
showPromptDialog(
|
||||
'修改配置名称',
|
||||
'请输入新的配置名称:',
|
||||
currentName,
|
||||
function(newName) {
|
||||
if (newName && newName !== currentName) {
|
||||
vscode.postMessage({
|
||||
type: 'updateConfigName',
|
||||
configId: configId,
|
||||
name: newName
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function editFileName(configId, currentFileName) {
|
||||
showPromptDialog(
|
||||
'修改文件名',
|
||||
'请输入新的文件名(包含扩展名):',
|
||||
currentFileName,
|
||||
function(newFileName) {
|
||||
if (newFileName && newFileName !== currentFileName) {
|
||||
vscode.postMessage({
|
||||
type: 'updateConfigFileName',
|
||||
configId: configId,
|
||||
fileName: newFileName
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function openConfigFile(configId) {
|
||||
currentConfigId = configId;
|
||||
document.getElementById('configEditor').style.display = 'block';
|
||||
|
||||
vscode.postMessage({
|
||||
type: 'loadConfigFile',
|
||||
configId: configId
|
||||
});
|
||||
}
|
||||
|
||||
function createNewConfig() {
|
||||
showPromptDialog(
|
||||
'新建配置',
|
||||
'请输入配置名称:',
|
||||
'',
|
||||
function(name) {
|
||||
if (name) {
|
||||
vscode.postMessage({
|
||||
type: 'createConfig',
|
||||
name: name
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function deleteConfig(configId) {
|
||||
showConfirmDialog(
|
||||
'确认删除',
|
||||
'确定删除这个配置文件吗?',
|
||||
function() {
|
||||
vscode.postMessage({
|
||||
type: 'deleteConfig',
|
||||
configId: configId
|
||||
});
|
||||
},
|
||||
function() {
|
||||
// 用户取消删除
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function saveConfigFile() {
|
||||
const content = document.getElementById('configContent').value;
|
||||
vscode.postMessage({
|
||||
type: 'saveConfigFile',
|
||||
configId: currentConfigId,
|
||||
content: content
|
||||
});
|
||||
closeEditor();
|
||||
}
|
||||
|
||||
function closeEditor() {
|
||||
document.getElementById('configEditor').style.display = 'none';
|
||||
currentConfigId = null;
|
||||
}
|
||||
|
||||
function goBackToContainers() {
|
||||
vscode.postMessage({ type: 'goBackToContainers' });
|
||||
}
|
||||
|
||||
// 对话框函数
|
||||
function showConfirmDialog(title, message, onConfirm, onCancel) {
|
||||
const overlay = document.createElement('div');
|
||||
overlay.className = 'modal-overlay';
|
||||
overlay.id = 'confirmModal';
|
||||
|
||||
overlay.innerHTML = \`
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-title">\${title}</div>
|
||||
<div>\${message}</div>
|
||||
<div class="modal-buttons">
|
||||
<button class="modal-btn modal-btn-secondary" onclick="closeConfirmDialog(false)">取消</button>
|
||||
<button class="modal-btn modal-btn-primary" onclick="closeConfirmDialog(true)">确定</button>
|
||||
</div>
|
||||
</div>
|
||||
\`;
|
||||
|
||||
document.body.appendChild(overlay);
|
||||
|
||||
window.confirmCallback = function(result) {
|
||||
if (result && onConfirm) {
|
||||
onConfirm();
|
||||
} else if (!result && onCancel) {
|
||||
onCancel();
|
||||
}
|
||||
delete window.confirmCallback;
|
||||
};
|
||||
}
|
||||
|
||||
function closeConfirmDialog(result) {
|
||||
const modal = document.getElementById('confirmModal');
|
||||
if (modal) {
|
||||
modal.remove();
|
||||
}
|
||||
if (window.confirmCallback) {
|
||||
window.confirmCallback(result);
|
||||
}
|
||||
}
|
||||
|
||||
function showPromptDialog(title, message, defaultValue, onConfirm) {
|
||||
const overlay = document.createElement('div');
|
||||
overlay.className = 'modal-overlay';
|
||||
overlay.id = 'promptModal';
|
||||
|
||||
overlay.innerHTML = \`
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-title">\${title}</div>
|
||||
<div>\${message}</div>
|
||||
<input type="text" id="promptInput" value="\${defaultValue}" style="width: 100%; margin: 10px 0; padding: 6px; background: var(--vscode-input-background); color: var(--vscode-input-foreground); border: 1px solid var(--vscode-input-border);">
|
||||
<div class="modal-buttons">
|
||||
<button class="modal-btn modal-btn-secondary" onclick="closePromptDialog(null)">取消</button>
|
||||
<button class="modal-btn modal-btn-primary" onclick="closePromptDialog(document.getElementById('promptInput').value)">确定</button>
|
||||
</div>
|
||||
</div>
|
||||
\`;
|
||||
|
||||
document.body.appendChild(overlay);
|
||||
|
||||
setTimeout(() => {
|
||||
const input = document.getElementById('promptInput');
|
||||
if (input) {
|
||||
input.focus();
|
||||
input.select();
|
||||
}
|
||||
}, 100);
|
||||
|
||||
window.promptCallback = onConfirm;
|
||||
}
|
||||
|
||||
function closePromptDialog(result) {
|
||||
const modal = document.getElementById('promptModal');
|
||||
if (modal) {
|
||||
modal.remove();
|
||||
}
|
||||
if (window.promptCallback) {
|
||||
window.promptCallback(result);
|
||||
}
|
||||
delete window.promptCallback;
|
||||
}
|
||||
|
||||
window.addEventListener('message', event => {
|
||||
const message = event.data;
|
||||
if (message.type === 'configFileLoaded') {
|
||||
document.getElementById('configContent').value = message.content;
|
||||
}
|
||||
});
|
||||
|
||||
// 修改:点击文件名时打开编辑器
|
||||
document.addEventListener('click', function(event) {
|
||||
if (event.target.classList.contains('editable') && event.target.textContent.includes('📄')) {
|
||||
const row = event.target.closest('tr');
|
||||
if (row) {
|
||||
const configNameCell = row.querySelector('td:first-child .editable');
|
||||
if (configNameCell) {
|
||||
const configId = configNameCell.onclick.toString().match(/'([^']+)'/)[1];
|
||||
openConfigFile(configId);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>`;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user