添加了一个可视化仓库功能
This commit is contained in:
@@ -115,59 +115,154 @@ class BaseView {
|
||||
cursor: pointer;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.modal-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.modal-dialog {
|
||||
background: var(--vscode-editor-background);
|
||||
border: 1px solid var(--vscode-panel-border);
|
||||
border-radius: 4px;
|
||||
padding: 20px;
|
||||
min-width: 300px;
|
||||
max-width: 500px;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.modal-title {
|
||||
margin-bottom: 15px;
|
||||
font-weight: bold;
|
||||
color: var(--vscode-editor-foreground);
|
||||
}
|
||||
|
||||
.modal-buttons {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.modal-btn {
|
||||
padding: 6px 12px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.modal-btn-primary {
|
||||
background: var(--vscode-button-background);
|
||||
color: var(--vscode-button-foreground);
|
||||
}
|
||||
|
||||
.modal-btn-secondary {
|
||||
background: var(--vscode-button-secondaryBackground);
|
||||
color: var(--vscode-button-secondaryForeground);
|
||||
}
|
||||
.modal-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.modal-dialog {
|
||||
background: var(--vscode-editor-background);
|
||||
border: 1px solid var(--vscode-panel-border);
|
||||
border-radius: 4px;
|
||||
padding: 20px;
|
||||
min-width: 300px;
|
||||
max-width: 500px;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.modal-title {
|
||||
margin-bottom: 15px;
|
||||
font-weight: bold;
|
||||
color: var(--vscode-editor-foreground);
|
||||
}
|
||||
|
||||
.modal-buttons {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.modal-btn {
|
||||
padding: 6px 12px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.modal-btn-primary {
|
||||
background: var(--vscode-button-background);
|
||||
color: var(--vscode-button-foreground);
|
||||
}
|
||||
|
||||
.modal-btn-secondary {
|
||||
background: var(--vscode-button-secondaryBackground);
|
||||
color: var(--vscode-button-secondaryForeground);
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
(function () {
|
||||
// 避免在同一个 Webview 中重复注册
|
||||
if (window.__dcspRepoDialogInitialized) {
|
||||
return;
|
||||
}
|
||||
window.__dcspRepoDialogInitialized = true;
|
||||
|
||||
function showRepoSelectDialog(repos) {
|
||||
// 移除已有弹窗
|
||||
var existing = document.getElementById('repoSelectModal');
|
||||
if (existing) {
|
||||
existing.remove();
|
||||
}
|
||||
|
||||
var overlay = document.createElement('div');
|
||||
overlay.className = 'modal-overlay';
|
||||
overlay.id = 'repoSelectModal';
|
||||
|
||||
var hasRepos = Array.isArray(repos) && repos.length > 0;
|
||||
var optionsHtml = '';
|
||||
if (hasRepos) {
|
||||
for (var i = 0; i < repos.length; i++) {
|
||||
var r = repos[i];
|
||||
if (!r || !r.name) continue;
|
||||
optionsHtml += '<option value="' + r.name + '">' + r.name + '</option>';
|
||||
}
|
||||
}
|
||||
|
||||
var disabledAttr = hasRepos ? '' : 'disabled';
|
||||
|
||||
var noRepoTip = '';
|
||||
if (!hasRepos) {
|
||||
noRepoTip = '<div style="margin-top:8px; font-size:12px; color: var(--vscode-descriptionForeground);">当前配置中没有仓库,请先在“仓库配置”中添加。</div>';
|
||||
}
|
||||
|
||||
overlay.innerHTML =
|
||||
'<div class="modal-dialog">' +
|
||||
'<div class="modal-title">获取仓库</div>' +
|
||||
'<div style="margin-bottom: 10px;">' +
|
||||
'<label style="display:block; margin-bottom:6px;">请选择仓库:</label>' +
|
||||
'<select id="repoSelect" style="width:100%; padding:6px; background: var(--vscode-input-background); color: var(--vscode-input-foreground); border:1px solid var(--vscode-input-border); border-radius:4px;">' +
|
||||
optionsHtml +
|
||||
'</select>' +
|
||||
noRepoTip +
|
||||
'</div>' +
|
||||
'<div class="modal-buttons">' +
|
||||
'<button class="modal-btn modal-btn-secondary" id="repoSelectCancelBtn">取消</button>' +
|
||||
'<button class="modal-btn modal-btn-primary" id="repoSelectOkBtn" ' + disabledAttr + '>确定</button>' +
|
||||
'</div>' +
|
||||
'</div>';
|
||||
|
||||
document.body.appendChild(overlay);
|
||||
|
||||
var cancelBtn = document.getElementById('repoSelectCancelBtn');
|
||||
var okBtn = document.getElementById('repoSelectOkBtn');
|
||||
var select = document.getElementById('repoSelect');
|
||||
|
||||
if (cancelBtn) {
|
||||
cancelBtn.addEventListener('click', function () {
|
||||
overlay.remove();
|
||||
});
|
||||
}
|
||||
|
||||
if (okBtn) {
|
||||
okBtn.addEventListener('click', function () {
|
||||
if (!select || !(select instanceof HTMLSelectElement)) {
|
||||
overlay.remove();
|
||||
return;
|
||||
}
|
||||
var repoName = select.value;
|
||||
if (!repoName) {
|
||||
alert('请选择一个仓库');
|
||||
return;
|
||||
}
|
||||
if (typeof vscode !== 'undefined') {
|
||||
vscode.postMessage({
|
||||
type: 'repoSelectedForBranches',
|
||||
repoName: repoName
|
||||
});
|
||||
}
|
||||
overlay.remove();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('message', function (event) {
|
||||
var message = event.data;
|
||||
if (!message || !message.type) return;
|
||||
if (message.type === 'showRepoSelect') {
|
||||
showRepoSelectDialog(message.repos || []);
|
||||
}
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user