git-sync-web 自动提交 2026-09-09 18:02:17
This commit is contained in:
@@ -113,6 +113,17 @@ const Editor = {
|
||||
if (this.cm) this.cm.setOption('theme', dark ? 'material-darker' : 'eclipse');
|
||||
},
|
||||
refresh() { if (this.cm) setTimeout(() => this.cm.refresh(), 30); },
|
||||
setChangedLines(lines) {
|
||||
this._changed = lines && lines.length ? lines : null;
|
||||
if (!this.cm) return;
|
||||
const n = this.cm.lineCount();
|
||||
for (let i = 0; i < n; i++) this.cm.removeLineClass(i, 'background', 'cm-chg');
|
||||
if (!this._changed) return;
|
||||
for (const ln of this._changed) {
|
||||
const idx = ln - 1;
|
||||
if (idx >= 0 && idx < n) this.cm.addLineClass(idx, 'background', 'cm-chg');
|
||||
}
|
||||
},
|
||||
onSave: null, // 由 cm-boot.js 的快捷键触发
|
||||
onChange: null, // 由 cm-boot.js 的 change 事件触发(草稿缓存)
|
||||
};
|
||||
@@ -316,6 +327,8 @@ function openDetail(name) {
|
||||
$('#btn-delete').hidden = false;
|
||||
$('#btn-clone').hidden = false;
|
||||
fillForm(r);
|
||||
$('#summary-box').hidden = false;
|
||||
loadSummary(name);
|
||||
showTab('log');
|
||||
$('#modal').hidden = false;
|
||||
}
|
||||
@@ -328,10 +341,22 @@ function openCreate() {
|
||||
$('#btn-delete').hidden = true;
|
||||
$('#btn-clone').hidden = true;
|
||||
fillForm(null);
|
||||
$('#summary-box').hidden = true;
|
||||
showTab('config');
|
||||
$('#modal').hidden = false;
|
||||
}
|
||||
|
||||
async function loadSummary(name) {
|
||||
if (!name) return;
|
||||
try {
|
||||
const d = await api(`/api/repos/${name}/summary`);
|
||||
$('#f-summary').value = d.pending || '';
|
||||
$('#summary-log').textContent = d.log ? d.log.trim() : '(暂无本地变更摘要记录)';
|
||||
} catch (err) {
|
||||
$('#summary-log').textContent = '读取摘要失败:' + err.message;
|
||||
}
|
||||
}
|
||||
|
||||
function closeModal() {
|
||||
$('#modal').hidden = true;
|
||||
current = null;
|
||||
@@ -817,6 +842,8 @@ async function loadFile(name, path) {
|
||||
showDraftNote(false);
|
||||
const d = await api(`/api/repos/${name}/file?path=${encodeURIComponent(path)}`);
|
||||
if (d.binary) {
|
||||
Editor.setChangedLines(null);
|
||||
const bh = $('#file-chg-hint'); if (bh) bh.hidden = true;
|
||||
Editor.value = `(二进制文件,大小 ${d.size} 字节,无法在网页编辑)`;
|
||||
Editor.disabled = true;
|
||||
draftServer = '';
|
||||
@@ -830,8 +857,13 @@ async function loadFile(name, path) {
|
||||
} else {
|
||||
Editor.value = draftServer;
|
||||
}
|
||||
Editor.setChangedLines(d.changed);
|
||||
const hint = $('#file-chg-hint');
|
||||
if (hint) hint.hidden = !(d.changed && d.changed.length);
|
||||
Editor.disabled = false;
|
||||
} catch (err) {
|
||||
Editor.setChangedLines(null);
|
||||
const eh = $('#file-chg-hint'); if (eh) eh.hidden = true;
|
||||
Editor.value = '读取失败:' + err.message;
|
||||
Editor.disabled = true;
|
||||
} finally {
|
||||
@@ -1069,6 +1101,19 @@ $('#btn-clone').addEventListener('click', () => {
|
||||
$('#f-name').focus();
|
||||
});
|
||||
|
||||
$('#btn-summary-save').addEventListener('click', async () => {
|
||||
if (!current) return;
|
||||
try {
|
||||
const res = await api(`/api/repos/${current}/summary`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ summary: $('#f-summary').value })
|
||||
});
|
||||
toast(res.ok ? '摘要已保存(本地,下次自动提交将使用此信息)' : '摘要保存失败', res.ok ? 'info' : 'error');
|
||||
await loadSummary(current);
|
||||
} catch (err) { toast('摘要保存失败:' + err.message, 'error'); }
|
||||
});
|
||||
|
||||
$('#btn-new').addEventListener('click', openCreate);
|
||||
$('#btn-empty-new').addEventListener('click', openCreate);
|
||||
$('#btn-sync-all').addEventListener('click', () => {
|
||||
|
||||
Reference in New Issue
Block a user