-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpath-editor.html
More file actions
539 lines (476 loc) · 19.8 KB
/
path-editor.html
File metadata and controls
539 lines (476 loc) · 19.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>PF系列插件文档</title>
<!-- 引入 Vue 3 -->
<script src="https://unpkg.com/vue@3.3.4/dist/vue.global.prod.js"></script>
<!-- 引入 Sortable.js -->
<script src="https://unpkg.com/sortablejs@1.15.0/Sortable.min.js"></script>
<!-- 引入 VueDraggable Next -->
<script src="https://unpkg.com/vuedraggable@4.1.0/dist/vuedraggable.umd.js"></script>
<style>
:root {
--primary-color: #007bff;
--bg-color: #f8f9fa;
--border-color: #dee2e6;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
height: 100vh;
background-color: var(--bg-color);
}
header {
background-color: #212529;
color: white;
padding: 15px 20px;
display: flex;
justify-content: space-between;
align-items: center;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.toolbar-btn {
background: var(--primary-color);
color: white;
border: none;
padding: 8px 15px;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
margin-left: 10px;
transition: 0.2s;
}
.toolbar-btn:hover {
background: #0056b3;
}
.toolbar-btn.export {
background: #28a745;
}
.toolbar-btn.export:hover {
background: #218838;
}
.main-container {
display: flex;
flex: 1;
overflow: hidden;
}
.tree-panel {
width: 45%;
border-right: 1px solid var(--border-color);
background: white;
padding: 20px;
overflow-y: auto;
}
.edit-panel {
width: 55%;
padding: 30px;
background: #fff;
overflow-y: auto;
}
/* 拖拽树样式 */
.drag-area {
min-height: 20px;
}
.nested-area {
margin-left: 20px;
padding-left: 10px;
border-left: 2px dashed #ccc;
margin-top: 5px;
}
.node-item {
display: flex;
align-items: center;
padding: 8px 10px;
border: 1px solid #eee;
margin-bottom: 5px;
background: #fff;
border-radius: 4px;
transition: 0.2s;
user-select: none;
}
.node-item:hover {
background: #f1f8ff;
border-color: #c0dffd;
}
.node-item.active {
background: #e6f2ff;
border-color: var(--primary-color);
box-shadow: 0 0 0 1px var(--primary-color);
}
.drag-handle {
cursor: grab;
margin-right: 10px;
color: #adb5bd;
font-size: 18px;
}
.drag-handle:active {
cursor: grabbing;
}
.node-title {
font-weight: bold;
font-size: 14px;
color: #333;
}
.node-path {
margin-left: 10px;
color: #6c757d;
font-size: 12px;
}
.node-actions {
margin-left: auto;
display: flex;
gap: 8px;
}
.icon-btn {
background: none;
border: none;
cursor: pointer;
font-size: 16px;
padding: 0 4px;
border-radius: 3px;
}
.icon-btn:hover {
background: #e9ecef;
}
/* 表单样式 */
.form-section {
margin-bottom: 25px;
padding-bottom: 15px;
border-bottom: 1px solid #eee;
}
.form-section h3 {
margin-top: 0;
margin-bottom: 15px;
color: #495057;
font-size: 18px;
display: flex;
justify-content: space-between;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
font-weight: 600;
font-size: 14px;
color: #495057;
}
.form-group input {
width: 100%;
padding: 10px;
box-sizing: border-box;
border: 1px solid #ced4da;
border-radius: 4px;
font-size: 14px;
transition: border-color 0.15s ease-in-out;
}
.form-group input:focus {
border-color: #80bdff;
outline: 0;
box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, .25);
}
.form-group textarea {
width: 100%;
padding: 10px;
box-sizing: border-box;
border: 1px solid #ced4da;
border-radius: 4px;
font-family: monospace;
font-size: 13px;
resize: vertical;
min-height: 120px;
white-space: pre;
background: #f8f9fa;
}
.empty-state {
text-align: center;
color: #adb5bd;
margin-top: 100px;
}
</style>
</head>
<body>
<div id="app">
<header>
<div style="font-size: 18px; font-weight: bold;">📖 path.json 结构编辑器</div>
<div>
<input type="file" id="fileInput" accept=".json" style="display: none" @change="importJson">
<button class="toolbar-btn" @click="triggerFileInput">📁 导入 path.json</button>
<button class="toolbar-btn export" @click="exportJson">💾 导出 JSON</button>
</div>
</header>
<div class="main-container">
<!-- 左侧:目录树区域 -->
<div class="tree-panel">
<div v-if="rootNode">
<div style="margin-bottom: 10px; font-weight: bold; color: #666;">根节点 (Root)</div>
<!-- 根节点固定项 -->
<div class="node-item" :class="{ active: selectedNode === rootNode }" @click="selectNode(rootNode)">
<span style="margin-right: 10px;">🏠</span>
<span class="node-title">{{ rootNode.title || '未命名' }}</span>
<span class="node-path">{{ rootNode.path }}</span>
<div class="node-actions">
<button class="icon-btn" @click.stop="addChildNode(rootNode)" title="添加子节点">➕</button>
</div>
</div>
<div style="margin-top: 15px; font-weight: bold; color: #666; font-size: 13px;">子结构 (可拖拽排序):</div>
<!-- 递归组件入口 -->
<nested-draggable :tasks="rootNode.children"></nested-draggable>
</div>
<div v-else class="empty-state">
<p>请点击右上角导入 path.json 文件,</p>
<button class="toolbar-btn" @click="createEmptyTemplate">或者创建一个空模板</button>
</div>
</div>
<!-- 右侧:编辑区域 -->
<div class="edit-panel">
<div v-if="selectedNode">
<div class="form-section">
<h3>基础信息配置</h3>
<div class="form-group">
<label>节点名称 (title) :</label>
<input type="text" v-model="selectedNode.title" placeholder="如:首页、GUGUbot">
</div>
<div class="form-group">
<label>节点路径 (path) :</label>
<input type="text" v-model="selectedNode.path" placeholder="如:PF-gugubot 或留空">
</div>
</div>
<div class="form-section">
<h3>
主页索引 (index)
<button class="toolbar-btn" style="padding: 4px 8px; font-size: 12px;"
v-if="!selectedNode.index" @click="addIndexObj">➕ 开启 Index 配置</button>
<button class="toolbar-btn" style="padding: 4px 8px; font-size: 12px; background: #dc3545;"
v-if="selectedNode.index" @click="removeIndexObj">🗑️ 移除 Index</button>
</h3>
<div v-if="selectedNode.index">
<div class="form-group">
<label>Index 标题 (index.title) :</label>
<input type="text" v-model="selectedNode.index.title" placeholder="如:README、前言">
</div>
<div class="form-group">
<label>Index 路径 (index.path) :</label>
<input type="text" v-model="selectedNode.index.path"
placeholder="如:PF-gugubot/README.md">
</div>
<div class="form-group">
<label>Index Git 数据 (高级 / JSON格式) :</label>
<textarea :value="getGitJson(selectedNode.index)"
@change="setGitJson(selectedNode.index, $event.target.value)"
placeholder="此处粘贴或编辑Git贡献者JSON数据..."></textarea>
</div>
</div>
<div v-else style="color: #6c757d; font-size: 13px;">该节点当前没有 index 属性。(一般仅目录级别节点需要)</div>
</div>
<div class="form-section">
<h3>节点 Git 数据 (git)</h3>
<div class="form-group">
<label>Node Git 数据 (高级 / JSON格式) :</label>
<textarea :value="getGitJson(selectedNode)"
@change="setGitJson(selectedNode, $event.target.value)"
placeholder="此处粘贴或编辑Git贡献者JSON数据..."></textarea>
<p style="font-size: 12px; color: #888; margin-top: 5px;">* 提示:直接修改内容并在框外点击任意处即可应用保存。如果不需要
git 对象,请清空内容。</p>
</div>
</div>
</div>
<div v-else-if="rootNode" class="empty-state">
<p>👈 请在左侧选择一个节点进行编辑</p>
</div>
</div>
</div>
</div>
<script>
const { createApp, ref, provide, inject } = Vue;
// --- 定义递归子组件 NestedDraggable ---
const NestedDraggable = {
name: "nested-draggable",
components: {
draggable: window.vuedraggable
},
props: {
tasks: { required: true, type: Array }
},
setup() {
const selectNode = inject('selectNode');
const selectedNode = inject('selectedNode');
const deleteNode = inject('deleteNode');
const addChildNode = inject('addChildNode');
return { selectNode, selectedNode, deleteNode, addChildNode };
},
template: `
<draggable class="drag-area" :list="tasks" group="g1" item-key="path" handle=".drag-handle" :animation="150" :fallbackOnBody="true" :swapThreshold="0.65">
<template #item="{ element, index }">
<div>
<div class="node-item" :class="{ active: selectedNode === element }" @click.stop="selectNode(element)">
<span class="drag-handle" title="按住拖拽排序">☰</span>
<span class="node-title">{{ element.title || '未命名' }}</span>
<span class="node-path">{{ element.path }}</span>
<span v-if="element.children && element.children.length > 0" style="margin-left:5px; font-size:12px; color:#aaa">({{element.children.length}})</span>
<div class="node-actions">
<button class="icon-btn" @click.stop="addChildNode(element)" title="添加子节点">➕</button>
<button class="icon-btn" @click.stop="deleteNode(tasks, index)" title="删除此节点" style="color: #dc3545;">🗑️</button>
</div>
</div>
<!-- 递归渲染子列表 -->
<nested-draggable v-if="element.children" :tasks="element.children" class="nested-area" />
</div>
</template>
</draggable>
`
};
// --- 主 Vue 实例 ---
const app = createApp({
setup() {
const rootNode = ref(null);
const selectedNode = ref(null);
// 选择节点
const selectNode = (node) => {
selectedNode.value = node;
};
// 添加子节点
const addChildNode = (parentNode) => {
if (!parentNode.children) {
parentNode.children = [];
}
const newNode = {
title: "新建节点",
path: parentNode.path ? parentNode.path + "/new" : "new",
children: []
};
parentNode.children.push(newNode);
selectedNode.value = newNode; // 自动选中新节点
};
// 删除节点
const deleteNode = (parentList, index) => {
if (confirm('确定要删除此节点及其所有内容吗?')) {
const deleted = parentList.splice(index, 1)[0];
// 如果删除的是当前选中的节点,重置选中项为根节点
if (selectedNode.value === deleted) {
selectedNode.value = rootNode.value;
}
}
};
// 递归格式化引入的数据,确保 children 数组存在,防止拖拽报错
const sanitizeData = (node) => {
if (!node.children) node.children = [];
node.children.forEach(sanitizeData);
};
// 触发文件选择
const triggerFileInput = () => {
document.getElementById('fileInput').click();
};
// 导入 JSON
const importJson = (event) => {
const file = event.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = (e) => {
try {
const parsed = JSON.parse(e.target.result);
sanitizeData(parsed);
rootNode.value = parsed;
selectedNode.value = rootNode.value;
} catch (err) {
alert("JSON 文件解析失败,请检查文件格式是否正确。\n错误信息:" + err.message);
}
// 清空input以便重复上传同名文件
event.target.value = '';
};
reader.readAsText(file);
};
// 导出 JSON
const exportJson = () => {
if (!rootNode.value) {
alert("当前没有可导出的数据!");
return;
}
// 使用四个空格格式化 JSON 字符串
const dataStr = JSON.stringify(rootNode.value, null, 4);
const blob = new Blob([dataStr], { type: "application/json" });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = "path.json";
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
};
// 创建空模板
const createEmptyTemplate = () => {
rootNode.value = {
title: "首页",
path: "",
children: []
};
selectedNode.value = rootNode.value;
};
// Index 属性的添加与移除
const addIndexObj = () => {
if (selectedNode.value) {
selectedNode.value.index = {
title: "README",
path: selectedNode.value.path ? selectedNode.value.path + "/README.md" : "README.md",
git: {}
};
}
};
const removeIndexObj = () => {
if (selectedNode.value && confirm("确定要移除该节点的 index 属性吗?")) {
delete selectedNode.value.index;
}
};
// 处理 Git JSON 的显示与编辑
const getGitJson = (targetObj) => {
if (!targetObj || !targetObj.git) return "";
return JSON.stringify(targetObj.git, null, 4);
};
const setGitJson = (targetObj, jsonString) => {
if (!targetObj) return;
// 如果清空了输入框,直接删除 git 属性
if (!jsonString || jsonString.trim() === "") {
delete targetObj.git;
return;
}
try {
const parsed = JSON.parse(jsonString);
targetObj.git = parsed;
} catch (err) {
alert("Git 数据 JSON 格式错误,请检查语法!\n错误信息: " + err.message);
}
};
// 通过 provide 将方法与状态注入给递归的子组件 NestedDraggable
provide('selectNode', selectNode);
provide('selectedNode', selectedNode);
provide('deleteNode', deleteNode);
provide('addChildNode', addChildNode);
return {
rootNode,
selectedNode,
selectNode,
addChildNode,
triggerFileInput,
importJson,
exportJson,
createEmptyTemplate,
addIndexObj,
removeIndexObj,
getGitJson,
setGitJson
};
}
});
// 注册递归组件
app.component('nested-draggable', NestedDraggable);
// 挂载实例
app.mount('#app');
</script>
</body>
</html>