feat: 全局文件选择器 + 项目管理路径选择按钮
- app.js新增window.pickPath(mode,callback)全局复用 - 项目管理「工作目录」+Git部署「目标目录」添加📁选择按钮 - Git部署不再硬编码data/projects,改用用户选择的目标目录 - files.js picker模式读取URL cb参数实现callback_id回传 - app.js版本号更新至v=0701 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
99c3e3e853
commit
dc0bb79a7e
4 files changed
+25
-3
No files matched your search
@@ -72,6 +72,6 @@
|
|||||||
<script src="./static/js/chart.js?v=0603"></script>
|
<script src="./static/js/chart.js?v=0603"></script>
|
||||||
|
|
||||||
<!-- 🟢 2. 再加载主逻辑 -->
|
<!-- 🟢 2. 再加载主逻辑 -->
|
||||||
<script src="./static/js/app.js?v=0700"></script>
|
<script src="./static/js/app.js?v=0701"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -172,6 +172,26 @@ async function loadPluginPage(pluginName) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ═══ Global file/dir picker (reusable by any page) ═══
|
||||||
|
// Usage: pickPath('dir', function(path) { document.getElementById('my-input').value = path; })
|
||||||
|
window.pickPath = function(mode, callback) {
|
||||||
|
var id = 'picker_' + Date.now();
|
||||||
|
window['_pickCallback_' + id] = callback;
|
||||||
|
var url = './static/pages/files.html?picker=1&mode=' + (mode || 'dir') + '&cb=' + id;
|
||||||
|
var w = window.open(url, 'fm-picker', 'width=680,height=520');
|
||||||
|
if (!w) { alert('请允许弹窗以使用文件选择器'); return; }
|
||||||
|
// Listen for pick result
|
||||||
|
window.addEventListener('message', function handler(e) {
|
||||||
|
try {
|
||||||
|
var d = JSON.parse(e.data);
|
||||||
|
if (d.action === 'fm-picked' && d.callback_id === id) {
|
||||||
|
window.removeEventListener('message', handler);
|
||||||
|
if (d.path && callback) callback(d.path);
|
||||||
|
}
|
||||||
|
} catch(ex) {}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
// ═══ Sidebar toggle ═══
|
// ═══ Sidebar toggle ═══
|
||||||
function toggleSidebar() {
|
function toggleSidebar() {
|
||||||
document.getElementById('app').classList.toggle('collapsed');
|
document.getElementById('app').classList.toggle('collapsed');
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ window.FilesModule = {
|
|||||||
if (params.get('picker') === '1') {
|
if (params.get('picker') === '1') {
|
||||||
self.pickerMode = true;
|
self.pickerMode = true;
|
||||||
self.pickerMode = params.get('mode') || 'dir';
|
self.pickerMode = params.get('mode') || 'dir';
|
||||||
|
self.pickerCallback = params.get('cb') || null;
|
||||||
}
|
}
|
||||||
window.addEventListener('message', function(e) {
|
window.addEventListener('message', function(e) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
<h3 style="margin-bottom:12px">添加新项目</h3>
|
<h3 style="margin-bottom:12px">添加新项目</h3>
|
||||||
<div class="input-group"><span class="label">项目名称</span><input class="input" id="proj-name" placeholder="如: my-app"></div>
|
<div class="input-group"><span class="label">项目名称</span><input class="input" id="proj-name" placeholder="如: my-app"></div>
|
||||||
<div class="input-group"><span class="label">启动命令</span><input class="input" id="proj-cmd" placeholder="如: python3 main.py"></div>
|
<div class="input-group"><span class="label">启动命令</span><input class="input" id="proj-cmd" placeholder="如: python3 main.py"></div>
|
||||||
<div class="input-group"><span class="label">工作目录</span><input class="input" id="proj-cwd" value="."></div>
|
<div class="input-group"><span class="label">工作目录</span><div style="display:flex;gap:6px"><input class="input" id="proj-cwd" value="." style="flex:1"><button class="btn btn-sm btn-outlined" onclick="pickPath('dir',function(p){document.getElementById('proj-cwd').value=p})" title="选择目录" style="flex-shrink:0"><svg width="14" height="14" viewBox="0 0 24 24"><path fill="currentColor" d="M20 6h-8l-2-2H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2zm0 12H4V6h5.17l2 2H20v10z"/></svg></button></div></div>
|
||||||
<div class="input-group"><span class="label">端口 (可选)</span><input class="input" id="proj-port" type="number" placeholder="5000" style="width:120px"></div>
|
<div class="input-group"><span class="label">端口 (可选)</span><input class="input" id="proj-port" type="number" placeholder="5000" style="width:120px"></div>
|
||||||
<div class="input-group"><span class="label">代理路径 (可选)</span><input class="input" id="proj-proxy" placeholder="如: /myapp" style="width:200px"></div>
|
<div class="input-group"><span class="label">代理路径 (可选)</span><input class="input" id="proj-proxy" placeholder="如: /myapp" style="width:200px"></div>
|
||||||
<button class="btn btn-filled" onclick="addProject()" style="margin-top:8px">启动项目</button>
|
<button class="btn btn-filled" onclick="addProject()" style="margin-top:8px">启动项目</button>
|
||||||
@@ -29,6 +29,7 @@
|
|||||||
<h3 style="margin-bottom:12px">从 Git 部署</h3>
|
<h3 style="margin-bottom:12px">从 Git 部署</h3>
|
||||||
<div class="input-group"><span class="label">Git URL</span><input class="input" id="git-url" placeholder="https://git.yeij.top/user/repo.git"></div>
|
<div class="input-group"><span class="label">Git URL</span><input class="input" id="git-url" placeholder="https://git.yeij.top/user/repo.git"></div>
|
||||||
<div class="input-group"><span class="label">分支</span><input class="input" id="git-branch" value="main" style="width:160px"></div>
|
<div class="input-group"><span class="label">分支</span><input class="input" id="git-branch" value="main" style="width:160px"></div>
|
||||||
|
<div class="input-group"><span class="label">目标目录</span><div style="display:flex;gap:6px"><input class="input" id="git-cwd" value="data/projects" style="flex:1"><button class="btn btn-sm btn-outlined" onclick="pickPath("dir",function(p){document.getElementById("git-cwd").value=p})" title="选择目录" style="flex-shrink:0"><svg width="14" height="14" viewBox="0 0 24 24"><path fill="currentColor" d="M20 6h-8l-2-2H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2zm0 12H4V6h5.17l2 2H20v10z"/></svg></button></div></div>
|
||||||
<button class="btn btn-filled" onclick="deployGit()" style="margin-top:8px">克隆并部署</button>
|
<button class="btn btn-filled" onclick="deployGit()" style="margin-top:8px">克隆并部署</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -50,7 +51,7 @@ async function deployGit(){
|
|||||||
var u=document.getElementById("git-url").value,b=document.getElementById("git-branch").value;
|
var u=document.getElementById("git-url").value,b=document.getElementById("git-branch").value;
|
||||||
if(!u){alert("请填写 Git URL");return}
|
if(!u){alert("请填写 Git URL");return}
|
||||||
var n=u.split("/").pop().replace(".git","");
|
var n=u.split("/").pop().replace(".git","");
|
||||||
await fetch("./api/projects/run",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:n,cmd:["git","clone","-b",b,u,n],cwd:"data/projects"})});
|
await fetch("./api/projects/run",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:n,cmd:["git","clone","-b",b,u,n],cwd:document.getElementById("git-cwd").value})});
|
||||||
refresh()
|
refresh()
|
||||||
}
|
}
|
||||||
async function stopP(el,n){await fetch("./api/projects/"+n+"/stop",{method:"POST"});refresh()}
|
async function stopP(el,n){await fetch("./api/projects/"+n+"/stop",{method:"POST"});refresh()}
|
||||||
|
|||||||
Reference in new issue
Block a user