2.0阶段5调整4: 模型卡默认仅名称/id/状态+余额与token占位,编辑图标开统一弹窗(编辑/删除/新增复用);新增全局confirmModal/promptModal替代全部原生弹窗;新建文件按钮改primary样式
This commit is contained in:
@@ -239,6 +239,7 @@ body {
|
||||
padding: 10px 12px; font-size: 15px; margin-bottom: 10px; outline: none;
|
||||
}
|
||||
.modal input:focus { border-color: #2a5299; }
|
||||
.modal input:disabled { background: #f2f3f7; color: #99a; }
|
||||
.modal select {
|
||||
width: 100%; border: 1px solid #dde; border-radius: 8px;
|
||||
padding: 10px 12px; font-size: 15px; margin-bottom: 10px; outline: none;
|
||||
@@ -262,6 +263,7 @@ body {
|
||||
border-radius: 10px; padding: 11px; font-size: 15px; cursor: pointer;
|
||||
}
|
||||
.ghost-btn:active { background: #e8eaf0; }
|
||||
.ghost-btn.danger { background: #fdf3f2; color: #c0392b; border-color: #eac2bd; }
|
||||
.btn-row { display: flex; gap: 10px; }
|
||||
.btn-row .primary-btn { flex: 1; }
|
||||
.modal .modal-text { font-size: 14px; color: #556; margin-bottom: 12px; }
|
||||
@@ -322,6 +324,15 @@ body {
|
||||
.model-card-state.busy { background: #fdecea; color: #b3382c; }
|
||||
/* 配置已加但还没重启进运行池 */
|
||||
.model-card-state.pending { background: #fff4dc; color: #a06a00; }
|
||||
.model-card-right { display: flex; align-items: center; gap: 4px; }
|
||||
.model-edit-ico {
|
||||
background: none; border: none; cursor: pointer; padding: 5px; border-radius: 8px;
|
||||
}
|
||||
.model-edit-ico svg {
|
||||
width: 17px; height: 17px; stroke: #7f8db0; fill: none;
|
||||
stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
|
||||
}
|
||||
.model-edit-ico:active { background: #eef0f6; }
|
||||
.model-card-meta { font-size: 12px; color: #888; margin-top: 4px; }
|
||||
.model-card-foot { display: flex; justify-content: flex-end; gap: 14px; margin-top: 6px; }
|
||||
|
||||
|
||||
@@ -211,20 +211,50 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 添加模型弹窗 -->
|
||||
<div id="model-add-modal" class="modal-overlay hidden" onclick="if(event.target===this)modelsUI.closeAdd()">
|
||||
<!-- 模型编辑/新增弹窗 -->
|
||||
<div id="model-edit-modal" class="modal-overlay hidden" onclick="if(event.target===this)modelsUI.close()">
|
||||
<div class="modal">
|
||||
<button class="modal-close-btn" onclick="modelsUI.closeAdd()">
|
||||
<button class="modal-close-btn" onclick="modelsUI.close()">
|
||||
<svg viewBox="0 0 24 24"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>
|
||||
</button>
|
||||
<h3>添加模型</h3>
|
||||
<input type="text" id="model-new-id" placeholder="id(唯一标识,如 ds3)" style="width:100%">
|
||||
<input type="text" id="model-new-name" placeholder="显示名(留空同 id)" style="width:100%">
|
||||
<input type="text" id="model-new-url" placeholder="上游地址(OpenAI 兼容 /v1)" style="width:100%">
|
||||
<input type="text" id="model-new-key" placeholder="api_key(选填,留空不带鉴权头)" style="width:100%">
|
||||
<label class="del-dir"><input type="checkbox" id="model-new-vision">支持图片输入(vision)</label>
|
||||
<button class="primary-btn" style="width:100%" onclick="modelsUI.add()">添加</button>
|
||||
<div class="cfg-note">写入 config.yml 的 models 段,到「设置」页重启服务后生效。</div>
|
||||
<h3 id="moe-title">编辑模型</h3>
|
||||
<input type="text" id="moe-name" placeholder="显示名(留空同 id)" style="width:100%">
|
||||
<input type="text" id="moe-id" placeholder="id(唯一标识)" style="width:100%">
|
||||
<input type="text" id="moe-url" placeholder="上游地址(OpenAI 兼容 /v1)" style="width:100%">
|
||||
<input type="text" id="moe-key" placeholder="api_key(留空则不带鉴权头)" style="width:100%">
|
||||
<label class="del-dir"><input type="checkbox" id="moe-vision">支持图片输入(vision)</label>
|
||||
<div class="btn-row">
|
||||
<button class="ghost-btn danger hidden" id="moe-del-btn" onclick="modelsUI.del()">删除</button>
|
||||
<button class="primary-btn" onclick="modelsUI.save()">保存</button>
|
||||
</div>
|
||||
<div class="cfg-note">写入 config.yml,到「设置」页重启服务后生效。id 不可在此修改(历史会话按 id 绑定),如需改动请编辑配置文件原文。</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 全局确认弹窗(替代原生 confirm) -->
|
||||
<div id="confirm-modal" class="modal-overlay hidden" onclick="if(event.target===this)confirmClose(false)">
|
||||
<div class="modal">
|
||||
<h3 id="confirm-title">请确认</h3>
|
||||
<div class="modal-text" id="confirm-text"></div>
|
||||
<div class="btn-row">
|
||||
<button class="ghost-btn" onclick="confirmClose(false)">取消</button>
|
||||
<button class="primary-btn" id="confirm-ok-btn" onclick="confirmClose(true)">确定</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 全局输入弹窗(替代原生 prompt) -->
|
||||
<div id="prompt-modal" class="modal-overlay hidden" onclick="if(event.target===this)promptCancel()">
|
||||
<div class="modal">
|
||||
<button class="modal-close-btn" onclick="promptCancel()">
|
||||
<svg viewBox="0 0 24 24"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>
|
||||
</button>
|
||||
<h3 id="prompt-title">请输入</h3>
|
||||
<input type="text" id="prompt-input" style="width:100%">
|
||||
<div class="btn-row">
|
||||
<button class="ghost-btn" onclick="promptCancel()">取消</button>
|
||||
<button class="primary-btn" onclick="promptOk()">确定</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -247,10 +277,10 @@
|
||||
<div class="toast hidden" id="toast"></div>
|
||||
|
||||
<!-- 发版时更新 v 参数,避免移动端浏览器缓存旧 JS -->
|
||||
<script src="/js/core.js?v=20260901i"></script>
|
||||
<script src="/js/tasks.js?v=20260901i"></script>
|
||||
<script src="/js/skills.js?v=20260901i"></script>
|
||||
<script src="/js/models.js?v=20260901i"></script>
|
||||
<script src="/js/settings.js?v=20260901i"></script>
|
||||
<script src="/js/core.js?v=20260901j"></script>
|
||||
<script src="/js/tasks.js?v=20260901j"></script>
|
||||
<script src="/js/skills.js?v=20260901j"></script>
|
||||
<script src="/js/models.js?v=20260901j"></script>
|
||||
<script src="/js/settings.js?v=20260901j"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -70,6 +70,49 @@ function toast(msg) {
|
||||
toast._t = setTimeout(() => el.classList.add('hidden'), 2500);
|
||||
}
|
||||
|
||||
// ---------- 统一弹窗(替代原生 confirm/prompt;同屏仅弹一个) ----------
|
||||
let _dlgResolve = null;
|
||||
function _dlgSettle(val) {
|
||||
$('confirm-modal').classList.add('hidden');
|
||||
$('prompt-modal').classList.add('hidden');
|
||||
const r = _dlgResolve;
|
||||
_dlgResolve = null;
|
||||
if (r) r(val);
|
||||
}
|
||||
// 确认框:resolve(true/false);danger=true 时确定钮红色
|
||||
function confirmModal(title, text, okText, danger) {
|
||||
return new Promise(resolve => {
|
||||
_dlgResolve = resolve;
|
||||
$('confirm-title').textContent = title || '请确认';
|
||||
$('confirm-text').textContent = text || '';
|
||||
const ok = $('confirm-ok-btn');
|
||||
ok.textContent = okText || '确定';
|
||||
ok.style.background = danger ? 'linear-gradient(135deg,#a3352a,#d2483c)' : '';
|
||||
$('confirm-modal').classList.remove('hidden');
|
||||
});
|
||||
}
|
||||
function confirmClose(v) { _dlgSettle(v); }
|
||||
// 输入框:resolve(字符串) 或取消 resolve(null)
|
||||
function promptModal(title, placeholder, initial) {
|
||||
return new Promise(resolve => {
|
||||
_dlgResolve = resolve;
|
||||
$('prompt-title').textContent = title || '请输入';
|
||||
const inp = $('prompt-input');
|
||||
inp.placeholder = placeholder || '';
|
||||
inp.value = initial || '';
|
||||
$('prompt-modal').classList.remove('hidden');
|
||||
setTimeout(() => inp.focus(), 60);
|
||||
});
|
||||
}
|
||||
function promptOk() { _dlgSettle($('prompt-input').value); }
|
||||
function promptCancel() { _dlgSettle(null); }
|
||||
(function () {
|
||||
const inp = document.getElementById('prompt-input');
|
||||
if (inp) inp.addEventListener('keydown', e => {
|
||||
if (e.key === 'Enter') { e.preventDefault(); promptOk(); }
|
||||
});
|
||||
})();
|
||||
|
||||
// ---------- 底部导航路由(hash) ----------
|
||||
const TABS = ['tasks', 'skills', 'models', 'settings'];
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
// 模型 Tab(阶段 5):模型池状态 + 增 / 改 / 删(仅写 config.yml,到「设置」页重启才生效)。
|
||||
// 状态(忙/闲)来自运行中的模型池 /api/models;配置(名称/地址/key/vision)来自 /api/config effective。
|
||||
// 说明:删除/新增按整段替换 models(该段注释会丢失);id 不提供页面修改(会话按 id 绑定,改 id 属危险操作)。
|
||||
// 卡片默认只展示:名称 / id / 运行状态 + 余额、token 用量占位(功能后续上线)。
|
||||
// 编辑走统一弹窗(新增复用同一弹窗);id 不可页面修改(会话按 id 绑定,改 id 走配置文件原文)。
|
||||
'use strict';
|
||||
|
||||
window.tabModules = window.tabModules || {};
|
||||
|
||||
// 配置里的模型数组(下标即 PATCH 下标);运行态按 id 关联
|
||||
let cfgModels = [];
|
||||
let runtimeById = {};
|
||||
let cfgModels = []; // 配置里的模型数组(下标即 PATCH 下标)
|
||||
let runtimeById = {}; // 运行池状态,按 id 关联
|
||||
let modelsPendingRestart = false;
|
||||
let moeIdx = -1; // 当前编辑弹窗对应的下标;-1 = 新增
|
||||
|
||||
async function loadModelCards() {
|
||||
const el = $('model-cards');
|
||||
@@ -30,23 +30,23 @@ async function loadModelCards() {
|
||||
: '<span class="model-card-state pending">待重启</span>';
|
||||
return '<div class="model-card">' +
|
||||
'<div class="model-card-head">' +
|
||||
'<span class="model-card-name">' + esc(m.display_name || m.id) + '</span>' + stateHtml +
|
||||
'<span class="model-card-name">' + esc(m.display_name || m.id) + '</span>' +
|
||||
'<span class="model-card-right">' + stateHtml +
|
||||
'<button class="model-edit-ico" title="编辑" onclick="modelsUI.openEdit(\'' + encodeURIComponent(m.id) + '\')">' +
|
||||
'<svg viewBox="0 0 24 24"><path d="M17 3a2.83 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5z"></path></svg>' +
|
||||
'</button>' +
|
||||
'</span>' +
|
||||
'</div>' +
|
||||
'<div class="model-card-meta">' + esc(m.id) +
|
||||
(run && run.is_busy && run.current_session_id ? ' · 会话 ' + esc(run.current_session_id) : '') + '</div>' +
|
||||
'<div class="cfg-kv"><label>地址</label><b>' + esc(m.url) + '</b>' +
|
||||
'<button class="file-act" onclick="modelsUI.edit(\'' + encodeURIComponent(m.id) + '\',\'url\')">改</button></div>' +
|
||||
'<div class="cfg-kv"><label>api_key</label><b>' + (m.api_key ? '已设置(••••' + esc(String(m.api_key).slice(-4)) + ')' : '(未设置)') + '</b>' +
|
||||
'<button class="file-act" onclick="modelsUI.edit(\'' + encodeURIComponent(m.id) + '\',\'api_key\')">改</button></div>' +
|
||||
'<div class="cfg-kv"><label>支持图片</label><b>' + (m.vision ? '是' : '否') + '</b>' +
|
||||
'<button class="file-act" onclick="modelsUI.toggleVision(\'' + encodeURIComponent(m.id) + '\')">' + (m.vision ? '关' : '开') + '</button></div>' +
|
||||
'<div class="model-card-foot"><button class="file-act" onclick="modelsUI.rename(\'' + encodeURIComponent(m.id) + '\')">改显示名</button>' +
|
||||
'<button class="file-act del" onclick="modelsUI.del(\'' + encodeURIComponent(m.id) + '\')">删除模型</button></div>' +
|
||||
'<div class="cfg-kv"><label>余额</label><b>--</b></div>' +
|
||||
'<div class="cfg-kv"><label>今日 token</label><b>--</b></div>' +
|
||||
'<div class="cfg-kv"><label>累计 token</label><b>--</b></div>' +
|
||||
'</div>';
|
||||
}).join('') +
|
||||
(modelsPendingRestart
|
||||
? '<div class="empty-tip">已写入 config.yml,到「设置」页重启服务后生效。</div>'
|
||||
: '<div class="empty-tip">改动写入 config.yml,重启服务后生效。token 用量统计在阶段 4 上线。</div>');
|
||||
: '<div class="empty-tip">余额与 token 用量统计后续上线;改动写入 config.yml,重启服务后生效。</div>');
|
||||
} catch (e) {
|
||||
el.innerHTML = '<div class="empty-tip">加载失败:' + esc(e.message) + '</div>';
|
||||
}
|
||||
@@ -56,100 +56,78 @@ function idxOf(id) {
|
||||
for (let i = 0; i < cfgModels.length; i++) if (cfgModels[i].id === id) return i;
|
||||
return -1;
|
||||
}
|
||||
function afterWrite(r) {
|
||||
function afterWrite() {
|
||||
modelsPendingRestart = true;
|
||||
toast('已写入 config.yml,到「设置」页重启后生效');
|
||||
loadModelCards();
|
||||
}
|
||||
|
||||
// ---------- 增 ----------
|
||||
function openAddModel() {
|
||||
['model-new-id', 'model-new-name', 'model-new-url', 'model-new-key'].forEach(i => { $(i).value = ''; });
|
||||
$('model-new-vision').checked = false;
|
||||
$('model-add-modal').classList.remove('hidden');
|
||||
$('model-new-id').focus();
|
||||
// ---------- 编辑/新增弹窗 ----------
|
||||
function openModelEditor(rawId) {
|
||||
const add = rawId == null;
|
||||
moeIdx = add ? -1 : idxOf(decodeURIComponent(rawId));
|
||||
if (!add && moeIdx < 0) return toast('模型不存在');
|
||||
const m = add ? { display_name: '', id: '', url: '', api_key: '', vision: false } : cfgModels[moeIdx];
|
||||
$('moe-title').textContent = add ? '添加模型' : '编辑模型';
|
||||
$('moe-name').value = m.display_name || '';
|
||||
const idIn = $('moe-id');
|
||||
idIn.value = m.id || '';
|
||||
idIn.disabled = !add; // 编辑时禁改 id(历史会话按 id 绑定)
|
||||
$('moe-url').value = m.url || '';
|
||||
$('moe-key').value = m.api_key || '';
|
||||
$('moe-vision').checked = !!m.vision;
|
||||
$('moe-del-btn').classList.toggle('hidden', add);
|
||||
$('model-edit-modal').classList.remove('hidden');
|
||||
}
|
||||
function closeAddModel() { $('model-add-modal').classList.add('hidden'); }
|
||||
function closeModelEditor() { $('model-edit-modal').classList.add('hidden'); }
|
||||
|
||||
async function addModel() {
|
||||
const id = $('model-new-id').value.trim();
|
||||
const url = $('model-new-url').value.trim();
|
||||
if (!id) { toast('请填写 id'); return; }
|
||||
if (idxOf(id) >= 0) { toast('id 已存在:' + id); return; }
|
||||
if (!url) { toast('请填写上游地址'); return; }
|
||||
const m = {
|
||||
async function saveModelEditor() {
|
||||
const add = moeIdx < 0;
|
||||
const id = $('moe-id').value.trim();
|
||||
const url = $('moe-url').value.trim().replace(/\/+$/, '');
|
||||
if (!id) return toast('请填写 id');
|
||||
if (!url) return toast('请填写上游地址');
|
||||
const obj = {
|
||||
id,
|
||||
display_name: $('model-new-name').value.trim() || id,
|
||||
display_name: $('moe-name').value.trim() || id,
|
||||
url,
|
||||
api_key: $('model-new-key').value.trim(),
|
||||
vision: $('model-new-vision').checked,
|
||||
api_key: $('moe-key').value.trim(),
|
||||
vision: $('moe-vision').checked,
|
||||
};
|
||||
let body;
|
||||
if (add) {
|
||||
if (idxOf(id) >= 0) return toast('id 已存在:' + id);
|
||||
body = { path: 'models', value: cfgModels.concat([obj]) };
|
||||
} else {
|
||||
// 整项替换;key 顺序固定,保持配置文件观感一致
|
||||
body = { path: ['models', moeIdx], value: obj };
|
||||
}
|
||||
try {
|
||||
const r = await req('PATCH', '/api/config', { path: 'models', value: cfgModels.concat([m]) });
|
||||
closeAddModel();
|
||||
afterWrite(r);
|
||||
} catch (e) { toast('添加失败:' + e.message); }
|
||||
}
|
||||
|
||||
// ---------- 改 ----------
|
||||
async function patchModel(id, field, value) {
|
||||
const i = idxOf(id);
|
||||
if (i < 0) return toast('模型不存在:' + id);
|
||||
try {
|
||||
const r = await req('PATCH', '/api/config', { path: ['models', i, field], value });
|
||||
afterWrite(r);
|
||||
await req('PATCH', '/api/config', body);
|
||||
closeModelEditor();
|
||||
afterWrite();
|
||||
} catch (e) { toast('保存失败:' + e.message); }
|
||||
}
|
||||
|
||||
async function editModel(rawId, field) {
|
||||
const id = decodeURIComponent(rawId);
|
||||
const m = cfgModels[idxOf(id)] || {};
|
||||
const label = field === 'url' ? '上游地址(OpenAI 兼容 /v1,不带尾斜杠)' : 'API Key(留空则不带鉴权头)';
|
||||
// api_key 不回填旧值,避免密钥展示在输入框
|
||||
const v = prompt(label + ':', field === 'url' ? (m.url || '') : '');
|
||||
if (v == null) return;
|
||||
await patchModel(id, field, v.trim());
|
||||
}
|
||||
|
||||
async function renameModel(rawId) {
|
||||
const id = decodeURIComponent(rawId);
|
||||
const m = cfgModels[idxOf(id)] || {};
|
||||
const v = prompt('显示名:', m.display_name || '');
|
||||
if (v == null) return;
|
||||
const name = v.trim();
|
||||
if (!name) return toast('显示名不能为空');
|
||||
await patchModel(id, 'display_name', name);
|
||||
}
|
||||
|
||||
async function toggleVision(rawId) {
|
||||
const id = decodeURIComponent(rawId);
|
||||
const m = cfgModels[idxOf(id)] || {};
|
||||
if (!confirm('模型「' + (m.display_name || id) + '」支持图片输入(vision)?\n确定=开启,取消=关闭')) return;
|
||||
await patchModel(id, 'vision', !m.vision);
|
||||
}
|
||||
|
||||
// ---------- 删(整段替换 models,会丢该段注释) ----------
|
||||
async function delModel(rawId) {
|
||||
const id = decodeURIComponent(rawId);
|
||||
const i = idxOf(id);
|
||||
if (i < 0) return;
|
||||
const m = cfgModels[i];
|
||||
async function delModelFromModal() {
|
||||
if (moeIdx < 0) return;
|
||||
const m = cfgModels[moeIdx];
|
||||
closeModelEditor();
|
||||
if (cfgModels.length <= 1) return toast('至少要保留一个模型');
|
||||
if (!confirm('删除模型「' + (m.display_name || id) + '」?将整体重写 models 段(注释可能丢失)。')) return;
|
||||
const ok = await confirmModal('删除模型', '删除模型「' + (m.display_name || m.id) + '」?将整体重写 models 段(注释可能丢失)。', '删除', true);
|
||||
if (!ok) return;
|
||||
try {
|
||||
const r = await req('PATCH', '/api/config', { path: 'models', value: cfgModels.filter(x => x.id !== id) });
|
||||
afterWrite(r);
|
||||
await req('PATCH', '/api/config', { path: 'models', value: cfgModels.filter(x => x.id !== m.id) });
|
||||
afterWrite();
|
||||
} catch (e) { toast('删除失败:' + e.message); }
|
||||
}
|
||||
|
||||
window.modelsUI = {
|
||||
openAdd: openAddModel,
|
||||
closeAdd: closeAddModel,
|
||||
add: addModel,
|
||||
edit: editModel,
|
||||
rename: renameModel,
|
||||
toggleVision: toggleVision,
|
||||
del: delModel,
|
||||
openAdd: function () { openModelEditor(null); },
|
||||
openEdit: openModelEditor,
|
||||
close: closeModelEditor,
|
||||
save: saveModelEditor,
|
||||
del: delModelFromModal,
|
||||
};
|
||||
|
||||
tabModules.models = {
|
||||
|
||||
@@ -179,13 +179,13 @@ async function saveForm() {
|
||||
|
||||
// ---------- 重启 ----------
|
||||
async function restart() {
|
||||
if (!confirm('重启服务使新配置生效?正在执行的 AI 会话会被打断。')) return;
|
||||
if (!await confirmModal('重启服务', '重启服务使新配置生效?正在执行的 AI 会话会被打断。', '重启')) return;
|
||||
try {
|
||||
await req('POST', '/api/system/restart');
|
||||
} catch (e) {
|
||||
if (e.status === 409 && /个任务.*执行中/.test(e.message)) {
|
||||
// 仅「有会话在跑」值得二次确认强打;配置不合法等 409 强打也无法启动,直接报给用户
|
||||
if (!confirm(e.message + '\n\n仍要强制重启?')) return;
|
||||
if (!await confirmModal('有任务在跑', e.message, '强制重启', true)) return;
|
||||
try { await req('POST', '/api/system/restart?force=true'); }
|
||||
catch (e2) { toast('重启失败:' + e2.message); return; }
|
||||
} else { toast('重启失败:' + e.message); return; }
|
||||
@@ -227,8 +227,9 @@ async function saveCfgEditor() {
|
||||
toast('配置不合法,未写入');
|
||||
}
|
||||
}
|
||||
function closeCfgEditor() {
|
||||
if ($('cfg-editor-area').value !== cfgOrig && !confirm('有未保存的修改,确定关闭?')) return;
|
||||
async function closeCfgEditor() {
|
||||
if ($('cfg-editor-area').value !== cfgOrig &&
|
||||
!await confirmModal('未保存的修改', '有未保存的修改,确定关闭并丢弃?', '关闭', true)) return;
|
||||
$('cfg-editor').classList.add('hidden');
|
||||
loadSettings(); // 原文可能改了生效值相关的显示,回到本页时刷新
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ async function loadSkillDetail() {
|
||||
try {
|
||||
const d = await req('GET', '/api/skills/' + encodeURIComponent(curSkill));
|
||||
$('skills-title').textContent = d.name;
|
||||
const newBtn = '<button class="ghost-btn" style="width:100%;margin-top:10px" onclick="skillsUI.newFile()">+ 新建文件</button>';
|
||||
const newBtn = '<button class="primary-btn" style="width:100%;margin-top:10px" onclick="skillsUI.newFile()">+ 新建文件</button>';
|
||||
if (!d.files.length) {
|
||||
el.innerHTML = '<div class="skill-files"><div class="empty-tip">技能目录是空的</div></div>' + newBtn;
|
||||
return;
|
||||
@@ -120,7 +120,7 @@ async function createSkill() {
|
||||
async function renameSkill(nameEnc) {
|
||||
const name = nameEnc ? decodeURIComponent(nameEnc) : curSkill;
|
||||
if (!name) return;
|
||||
const nn = prompt('新的技能名:', name);
|
||||
const nn = await promptModal('重命名技能', '新的技能名', name);
|
||||
if (nn == null) return;
|
||||
const newName = nn.trim();
|
||||
if (!newName || newName === name) return;
|
||||
@@ -135,7 +135,7 @@ async function renameSkill(nameEnc) {
|
||||
async function deleteSkill(nameEnc) {
|
||||
const name = nameEnc ? decodeURIComponent(nameEnc) : curSkill;
|
||||
if (!name) return;
|
||||
if (!confirm('确定删除技能「' + name + '」?目录下所有文件将不可恢复。')) return;
|
||||
if (!await confirmModal('删除技能', '确定删除技能「' + name + '」?目录下所有文件将不可恢复。', '删除', true)) return;
|
||||
try {
|
||||
await req('DELETE', '/api/skills/' + encodeURIComponent(name));
|
||||
toast('已删除 ' + name);
|
||||
@@ -166,9 +166,9 @@ async function saveSkillFile() {
|
||||
} catch (e) { toast('保存失败:' + e.message); }
|
||||
}
|
||||
|
||||
function closeSkillEditor() {
|
||||
async function closeSkillEditor() {
|
||||
if ($('skill-editor-area').value !== editorOrig &&
|
||||
!confirm('有未保存的修改,确定关闭编辑器?')) return;
|
||||
!await confirmModal('未保存的修改', '有未保存的修改,确定关闭编辑器并丢弃?', '关闭', true)) return;
|
||||
editorPath = null; editorOrig = '';
|
||||
setSkillsView('detail');
|
||||
loadSkillDetail();
|
||||
@@ -176,7 +176,7 @@ function closeSkillEditor() {
|
||||
|
||||
async function newSkillFile() {
|
||||
if (!curSkill) return;
|
||||
const p = prompt('新建文件路径(相对技能目录,可含子目录):', '');
|
||||
const p = await promptModal('新建文件', '相对技能目录的路径,可含子目录(如 scripts/run.sh)', '');
|
||||
if (p == null) return;
|
||||
const rel = p.trim();
|
||||
if (!rel) { toast('路径为空'); return; }
|
||||
@@ -189,7 +189,7 @@ async function newSkillFile() {
|
||||
|
||||
async function deleteSkillFile(path) {
|
||||
const rel = decodeURIComponent(path);
|
||||
if (!confirm('删除文件 ' + rel + ' ?')) return;
|
||||
if (!await confirmModal('删除文件', '删除文件 ' + rel + ' ?', '删除', true)) return;
|
||||
try {
|
||||
await req('DELETE', '/api/skills/' + encodeURIComponent(curSkill) + '/file?path=' + encodeURIComponent(rel));
|
||||
toast('已删除');
|
||||
@@ -213,7 +213,7 @@ async function uploadSkillFile(ev) {
|
||||
toast('已上传 ' + file.name);
|
||||
} catch (e) {
|
||||
if (/已存在/.test(e.message)) {
|
||||
if (!confirm(file.name + ' 已存在,覆盖?')) return;
|
||||
if (!await confirmModal('文件已存在', file.name + ' 已存在,覆盖?', '覆盖')) return;
|
||||
try { await send(true); toast('已覆盖 ' + file.name); }
|
||||
catch (e2) { toast('上传失败:' + e2.message); }
|
||||
} else {
|
||||
|
||||
@@ -452,7 +452,7 @@ const ui = {
|
||||
} catch (e) { toast('上传失败:' + e.message); }
|
||||
},
|
||||
async deleteFile(name) {
|
||||
if (!confirm('删除文件 ' + name + '?')) return;
|
||||
if (!await confirmModal('删除文件', '删除文件 ' + name + ' ?', '删除', true)) return;
|
||||
try {
|
||||
await req('DELETE', '/api/sessions/' + state.sessionId + '/files?path=' + encodeURIComponent(name));
|
||||
loadFiles();
|
||||
|
||||
Reference in New Issue
Block a user