openprototype 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/product/demo/pc/customer//350/256/242/345/215/225/order_list.html +25 -0
- package/product/demo/pc/customer//350/256/242/345/215/225/order_list.md +18 -0
- package/product/demo/pc/index.html +98 -24
- package/product/demo/pc/nav-tree.json +9 -0
- package/runtime/server.js +96 -2
- package/scripts/check/sync-nav-tree.js +1 -0
- package/templates/product-shell/index.html +98 -24
package/package.json
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>订单列表</title>
|
|
7
|
+
<style>
|
|
8
|
+
*, *::before, *::after { box-sizing: border-box; }
|
|
9
|
+
body {
|
|
10
|
+
margin: 0;
|
|
11
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', 'PingFang SC', 'Hiragino Sans GB', sans-serif;
|
|
12
|
+
font-size: 13px; color: #20242d; background: #f3f5f8; padding: 20px;
|
|
13
|
+
}
|
|
14
|
+
.page-title { font-size: 18px; font-weight: 600; margin: 0 0 16px; }
|
|
15
|
+
.panel { background: #fff; border: 1px solid #e6ebf2; border-radius: 8px; padding: 20px; }
|
|
16
|
+
.placeholder { color: #7b8495; margin: 0; }
|
|
17
|
+
</style>
|
|
18
|
+
</head>
|
|
19
|
+
<body>
|
|
20
|
+
<h1 class="page-title">订单列表</h1>
|
|
21
|
+
<div class="panel">
|
|
22
|
+
<p class="placeholder">「订单列表」原型待完善:可直接编辑本文件,或在导航页选中该页面后通过右侧 Agent 生成内容。</p>
|
|
23
|
+
</div>
|
|
24
|
+
</body>
|
|
25
|
+
</html>
|
|
@@ -284,6 +284,11 @@ body.is-resizing-sidebar .preview-frame {
|
|
|
284
284
|
.file-row.tree-drag-before::before { top: -1px; }
|
|
285
285
|
.folder-head.tree-drag-after::after,
|
|
286
286
|
.file-row.tree-drag-after::after { bottom: -1px; }
|
|
287
|
+
.folder-head.tree-drag-into {
|
|
288
|
+
color: #0958d9;
|
|
289
|
+
background: #e6f4ff;
|
|
290
|
+
box-shadow: inset 0 0 0 1px #1677ff;
|
|
291
|
+
}
|
|
287
292
|
|
|
288
293
|
/* ── Folder ── */
|
|
289
294
|
.folder-head {
|
|
@@ -597,12 +602,8 @@ body.is-resizing-sidebar .preview-frame {
|
|
|
597
602
|
<div class="create-modal-title" id="createModalTitle">新建页面</div>
|
|
598
603
|
<div class="create-modal-location" id="createModalLocation"></div>
|
|
599
604
|
<div class="create-modal-field">
|
|
600
|
-
<label for="createNameInput"
|
|
601
|
-
<input id="createNameInput" type="text" placeholder="如
|
|
602
|
-
</div>
|
|
603
|
-
<div class="create-modal-field" id="createTitleField">
|
|
604
|
-
<label for="createTitleInput">页面标题(可选,用于页面 <title> 与 PRD)</label>
|
|
605
|
-
<input id="createTitleInput" type="text" placeholder="如 订单列表" autocomplete="off">
|
|
605
|
+
<label for="createNameInput" id="createNameLabel">名称</label>
|
|
606
|
+
<input id="createNameInput" type="text" placeholder="如 订单列表" autocomplete="off">
|
|
606
607
|
</div>
|
|
607
608
|
<div class="create-modal-error" id="createModalError"></div>
|
|
608
609
|
<div class="create-modal-actions">
|
|
@@ -822,7 +823,8 @@ const breadcrumbMap = {};
|
|
|
822
823
|
function buildBreadcrumbs(nodes, trail) {
|
|
823
824
|
nodes.forEach(n => {
|
|
824
825
|
if (n.file) {
|
|
825
|
-
|
|
826
|
+
const label = n.title || n.file;
|
|
827
|
+
breadcrumbMap[n.path] = trail ? trail + ' / ' + label : label;
|
|
826
828
|
} else {
|
|
827
829
|
buildBreadcrumbs(n.children || [], trail ? trail + ' / ' + n.name : n.name);
|
|
828
830
|
}
|
|
@@ -1072,24 +1074,24 @@ function treeSortingBlocked() {
|
|
|
1072
1074
|
}
|
|
1073
1075
|
|
|
1074
1076
|
function clearTreeDragStyles() {
|
|
1075
|
-
document.querySelectorAll('.dragging, .tree-drag-before, .tree-drag-after').forEach(element => {
|
|
1076
|
-
element.classList.remove('dragging', 'tree-drag-before', 'tree-drag-after');
|
|
1077
|
+
document.querySelectorAll('.dragging, .tree-drag-before, .tree-drag-after, .tree-drag-into').forEach(element => {
|
|
1078
|
+
element.classList.remove('dragging', 'tree-drag-before', 'tree-drag-after', 'tree-drag-into');
|
|
1077
1079
|
delete element.dataset.dropPosition;
|
|
1078
1080
|
});
|
|
1079
1081
|
}
|
|
1080
1082
|
|
|
1081
1083
|
function clearTreeDropStyles() {
|
|
1082
|
-
document.querySelectorAll('.tree-drag-before, .tree-drag-after').forEach(element => {
|
|
1083
|
-
element.classList.remove('tree-drag-before', 'tree-drag-after');
|
|
1084
|
+
document.querySelectorAll('.tree-drag-before, .tree-drag-after, .tree-drag-into').forEach(element => {
|
|
1085
|
+
element.classList.remove('tree-drag-before', 'tree-drag-after', 'tree-drag-into');
|
|
1084
1086
|
delete element.dataset.dropPosition;
|
|
1085
1087
|
});
|
|
1086
1088
|
}
|
|
1087
1089
|
|
|
1088
|
-
function setupTreeDrag(element, parentKey, nodeKey) {
|
|
1090
|
+
function setupTreeDrag(element, parentKey, nodeKey, targetFolderKey) {
|
|
1089
1091
|
element.draggable = true;
|
|
1090
1092
|
element.dataset.parentKey = parentKey;
|
|
1091
1093
|
element.dataset.nodeKey = nodeKey;
|
|
1092
|
-
element.title = element.title || '拖动调整同级排序';
|
|
1094
|
+
element.title = element.title || (targetFolderKey ? '拖动调整同级排序,或将页面拖入此文件夹' : '拖动调整同级排序');
|
|
1093
1095
|
|
|
1094
1096
|
element.addEventListener('dragstart', event => {
|
|
1095
1097
|
if (treeSortingBlocked()) {
|
|
@@ -1097,7 +1099,12 @@ function setupTreeDrag(element, parentKey, nodeKey) {
|
|
|
1097
1099
|
showToast(reorderSaving ? '正在保存排序' : '请先清除搜索或版本筛选再排序');
|
|
1098
1100
|
return;
|
|
1099
1101
|
}
|
|
1100
|
-
dragState = {
|
|
1102
|
+
dragState = {
|
|
1103
|
+
parentKey,
|
|
1104
|
+
nodeKey,
|
|
1105
|
+
sourcePath: element.dataset.path || '',
|
|
1106
|
+
isPage: nodeKey.startsWith('file:')
|
|
1107
|
+
};
|
|
1101
1108
|
suppressTreeClickUntil = Date.now() + 400;
|
|
1102
1109
|
element.classList.add('dragging');
|
|
1103
1110
|
event.dataTransfer.effectAllowed = 'move';
|
|
@@ -1105,7 +1112,17 @@ function setupTreeDrag(element, parentKey, nodeKey) {
|
|
|
1105
1112
|
});
|
|
1106
1113
|
|
|
1107
1114
|
element.addEventListener('dragover', event => {
|
|
1108
|
-
if (!dragState
|
|
1115
|
+
if (!dragState) return;
|
|
1116
|
+
const isMoveIntoFolder = targetFolderKey && dragState.isPage && dragState.parentKey !== targetFolderKey;
|
|
1117
|
+
if (isMoveIntoFolder) {
|
|
1118
|
+
event.preventDefault();
|
|
1119
|
+
event.stopPropagation();
|
|
1120
|
+
clearTreeDropStyles();
|
|
1121
|
+
element.classList.add('tree-drag-into');
|
|
1122
|
+
event.dataTransfer.dropEffect = 'move';
|
|
1123
|
+
return;
|
|
1124
|
+
}
|
|
1125
|
+
if (dragState.parentKey !== parentKey || dragState.nodeKey === nodeKey) return;
|
|
1109
1126
|
event.preventDefault();
|
|
1110
1127
|
event.stopPropagation();
|
|
1111
1128
|
clearTreeDropStyles();
|
|
@@ -1115,11 +1132,22 @@ function setupTreeDrag(element, parentKey, nodeKey) {
|
|
|
1115
1132
|
});
|
|
1116
1133
|
|
|
1117
1134
|
element.addEventListener('drop', event => {
|
|
1118
|
-
if (!dragState
|
|
1135
|
+
if (!dragState) return;
|
|
1136
|
+
const currentDrag = dragState;
|
|
1137
|
+
const isMoveIntoFolder = targetFolderKey && currentDrag.isPage && currentDrag.parentKey !== targetFolderKey;
|
|
1138
|
+
if (isMoveIntoFolder) {
|
|
1139
|
+
event.preventDefault();
|
|
1140
|
+
event.stopPropagation();
|
|
1141
|
+
clearTreeDragStyles();
|
|
1142
|
+
dragState = null;
|
|
1143
|
+
movePageToFolder(currentDrag.sourcePath, targetFolderKey);
|
|
1144
|
+
return;
|
|
1145
|
+
}
|
|
1146
|
+
if (currentDrag.parentKey !== parentKey || currentDrag.nodeKey === nodeKey) return;
|
|
1119
1147
|
event.preventDefault();
|
|
1120
1148
|
event.stopPropagation();
|
|
1121
1149
|
const position = element.dataset.dropPosition || 'before';
|
|
1122
|
-
const sourceKey =
|
|
1150
|
+
const sourceKey = currentDrag.nodeKey;
|
|
1123
1151
|
clearTreeDragStyles();
|
|
1124
1152
|
dragState = null;
|
|
1125
1153
|
reorderTreeNodes(parentKey, sourceKey, nodeKey, position);
|
|
@@ -1131,6 +1159,50 @@ function setupTreeDrag(element, parentKey, nodeKey) {
|
|
|
1131
1159
|
});
|
|
1132
1160
|
}
|
|
1133
1161
|
|
|
1162
|
+
function movePageLocalState(sourcePath, targetPath) {
|
|
1163
|
+
if (Object.prototype.hasOwnProperty.call(versionCache, sourcePath)) {
|
|
1164
|
+
versionCache[targetPath] = versionCache[sourcePath];
|
|
1165
|
+
delete versionCache[sourcePath];
|
|
1166
|
+
saveVersionCache();
|
|
1167
|
+
}
|
|
1168
|
+
if (reviewStatus[sourcePath]) {
|
|
1169
|
+
reviewStatus[targetPath] = reviewStatus[sourcePath];
|
|
1170
|
+
delete reviewStatus[sourcePath];
|
|
1171
|
+
saveReviewStatus();
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
async function movePageToFolder(sourcePath, targetFolder) {
|
|
1176
|
+
if (!sourcePath || !targetFolder) return;
|
|
1177
|
+
const wasActive = !!(activeRow && activeRow.dataset.path === sourcePath);
|
|
1178
|
+
reorderSaving = true;
|
|
1179
|
+
try {
|
|
1180
|
+
const res = await fetch('/api/move-page', {
|
|
1181
|
+
method: 'POST',
|
|
1182
|
+
headers: { 'Content-Type': 'application/json' },
|
|
1183
|
+
body: JSON.stringify({ base: PAGE_BASE, sourcePath, targetFolder })
|
|
1184
|
+
});
|
|
1185
|
+
const data = await res.json().catch(() => ({}));
|
|
1186
|
+
if (!res.ok || !data.ok) throw new Error(data.error || '移动失败:' + res.status);
|
|
1187
|
+
movePageLocalState(sourcePath, data.path);
|
|
1188
|
+
await loadTree();
|
|
1189
|
+
renderTree();
|
|
1190
|
+
expandFolderTrail(targetFolder);
|
|
1191
|
+
if (wasActive) {
|
|
1192
|
+
const row = document.querySelector(`.file-row[data-path="${CSS.escape(data.path)}"]`);
|
|
1193
|
+
if (row) loadPreview(data.path, row);
|
|
1194
|
+
}
|
|
1195
|
+
fetchAllVersions();
|
|
1196
|
+
showToast('页面已移入:' + targetFolder);
|
|
1197
|
+
} catch (err) {
|
|
1198
|
+
try { await loadTree(); } catch {}
|
|
1199
|
+
renderTree();
|
|
1200
|
+
showToast(err.message);
|
|
1201
|
+
} finally {
|
|
1202
|
+
reorderSaving = false;
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1134
1206
|
async function reorderTreeNodes(parentKey, sourceKey, targetKey, position) {
|
|
1135
1207
|
const level = getTreeLevel(parentKey);
|
|
1136
1208
|
const beforeOrder = level.map(navNodeKey);
|
|
@@ -1177,12 +1249,13 @@ function renderNodes(nodes, depth, trail) {
|
|
|
1177
1249
|
const row = document.createElement('div');
|
|
1178
1250
|
row.className = 'file-row';
|
|
1179
1251
|
row.dataset.path = node.path;
|
|
1180
|
-
|
|
1252
|
+
const pageLabel = node.title || node.file;
|
|
1253
|
+
row.dataset.searchText = [pageLabel, node.file, node.path, breadcrumbMap[node.path] || ''].join(' ');
|
|
1181
1254
|
setupTreeDrag(row, trail, navNodeKey(node));
|
|
1182
1255
|
row.innerHTML = `
|
|
1183
1256
|
<div class="file-main">
|
|
1184
1257
|
<span class="file-icon">${I_FILE}</span>
|
|
1185
|
-
<span class="file-name" title="${node.file}">${
|
|
1258
|
+
<span class="file-name" title="${node.file}">${pageLabel}</span>
|
|
1186
1259
|
<span class="version-badge"></span>
|
|
1187
1260
|
<!-- review-btn:start (个人审核标记,本地开发专用;发布时可自动剥离) -->
|
|
1188
1261
|
${renderReviewButton(node.path, 'md', 'PRD')}
|
|
@@ -1212,7 +1285,7 @@ function renderNodes(nodes, depth, trail) {
|
|
|
1212
1285
|
|
|
1213
1286
|
const head = document.createElement('div');
|
|
1214
1287
|
head.className = 'folder-head';
|
|
1215
|
-
setupTreeDrag(head, trail, navNodeKey(node));
|
|
1288
|
+
setupTreeDrag(head, trail, navNodeKey(node), folderKey);
|
|
1216
1289
|
head.innerHTML = `<span class="folder-arrow">${I_ARROW}</span><span class="folder-icon">${I_FOLDER}</span><span class="folder-name">${node.name}</span><button type="button" class="tree-add-btn" data-create="page" title="在此文件夹新建页面">+页</button><button type="button" class="tree-add-btn" data-create="folder" title="在此文件夹新建子文件夹">+夹</button>`;
|
|
1217
1290
|
head.addEventListener('click', () => {
|
|
1218
1291
|
if (Date.now() >= suppressTreeClickUntil) folder.classList.toggle('collapsed');
|
|
@@ -1273,9 +1346,11 @@ function openCreateModal(type, parentPath) {
|
|
|
1273
1346
|
createModalState = { type, parentPath: parentPath || '' };
|
|
1274
1347
|
document.getElementById('createModalTitle').textContent = type === 'folder' ? '新建文件夹' : '新建页面';
|
|
1275
1348
|
document.getElementById('createModalLocation').textContent = '位置:' + (parentPath ? parentPath + '/' : '根目录');
|
|
1276
|
-
document.getElementById('
|
|
1349
|
+
document.getElementById('createNameLabel').textContent = type === 'folder'
|
|
1350
|
+
? '名称(作为文件夹名和左侧导航名称;支持中文、字母、数字、_ 和 -)'
|
|
1351
|
+
: '名称(用于文件名、左侧导航、页面 <title> 与 PRD;支持中文、字母、数字、_ 和 -)';
|
|
1352
|
+
document.getElementById('createNameInput').placeholder = type === 'folder' ? '如 customer' : '如 订单列表';
|
|
1277
1353
|
document.getElementById('createNameInput').value = '';
|
|
1278
|
-
document.getElementById('createTitleInput').value = '';
|
|
1279
1354
|
document.getElementById('createModalError').textContent = '';
|
|
1280
1355
|
document.getElementById('createModalMask').classList.add('show');
|
|
1281
1356
|
document.getElementById('createNameInput').focus();
|
|
@@ -1308,7 +1383,6 @@ async function submitCreateModal() {
|
|
|
1308
1383
|
errorEl.textContent = '';
|
|
1309
1384
|
try {
|
|
1310
1385
|
const payload = { base: PAGE_BASE, parent: parentPath, name };
|
|
1311
|
-
if (type === 'page') payload.title = document.getElementById('createTitleInput').value.trim();
|
|
1312
1386
|
const res = await fetch(type === 'folder' ? '/api/create-folder' : '/api/create-page', {
|
|
1313
1387
|
method: 'POST',
|
|
1314
1388
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -1431,7 +1505,7 @@ window.addEventListener('DOMContentLoaded', async () => {
|
|
|
1431
1505
|
document.getElementById('createModalMask').addEventListener('click', e => {
|
|
1432
1506
|
if (e.target === e.currentTarget) closeCreateModal();
|
|
1433
1507
|
});
|
|
1434
|
-
[document.getElementById('createNameInput')
|
|
1508
|
+
[document.getElementById('createNameInput')].forEach(input => {
|
|
1435
1509
|
input.addEventListener('keydown', e => {
|
|
1436
1510
|
if (e.key === 'Enter') { e.preventDefault(); submitCreateModal(); }
|
|
1437
1511
|
else if (e.key === 'Escape') closeCreateModal();
|
package/runtime/server.js
CHANGED
|
@@ -232,6 +232,99 @@ function navNodeKey(node) {
|
|
|
232
232
|
return node.file ? `file:${node.file}` : `folder:${node.name}`;
|
|
233
233
|
}
|
|
234
234
|
|
|
235
|
+
function resolvePageFile(rootDir, inputPath) {
|
|
236
|
+
const relPath = String(inputPath || '').replace(/^\/+|\/+$/g, '');
|
|
237
|
+
const segments = relPath.split('/').filter(Boolean);
|
|
238
|
+
const fileName = segments.pop();
|
|
239
|
+
if (!fileName || !fileName.toLowerCase().endsWith('.html')) {
|
|
240
|
+
throw new Error('仅允许移动 .html 页面');
|
|
241
|
+
}
|
|
242
|
+
const pageName = fileName.slice(0, -'.html'.length);
|
|
243
|
+
assertValidSegment(pageName, '页面名');
|
|
244
|
+
segments.forEach((seg) => assertValidSegment(seg, '页面目录名'));
|
|
245
|
+
const parent = segments.join('/');
|
|
246
|
+
const dir = path.join(rootDir, ...segments);
|
|
247
|
+
const file = path.join(dir, fileName);
|
|
248
|
+
if (file !== rootDir && !file.startsWith(rootDir + path.sep)) throw new Error('页面路径超出产品范围');
|
|
249
|
+
if (!fs.existsSync(file) || !fs.statSync(file).isFile()) throw new Error('源页面不存在');
|
|
250
|
+
return { dir, parent, file, fileName, pageName, relPath: [...segments, fileName].join('/') };
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function saveNavTreeAtomically(rootDir, tree) {
|
|
254
|
+
const file = path.join(rootDir, 'nav-tree.json');
|
|
255
|
+
const tempFile = path.join(rootDir, `.nav-tree-${process.pid}-${Date.now()}.tmp`);
|
|
256
|
+
try {
|
|
257
|
+
fs.writeFileSync(tempFile, JSON.stringify(tree, null, 2) + '\n');
|
|
258
|
+
fs.renameSync(tempFile, file);
|
|
259
|
+
} finally {
|
|
260
|
+
if (fs.existsSync(tempFile)) fs.unlinkSync(tempFile);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function handleMovePage(req, res) {
|
|
265
|
+
readJsonBody(req, 64 * 1024, (parseErr, data) => {
|
|
266
|
+
const moved = [];
|
|
267
|
+
try {
|
|
268
|
+
if (parseErr) throw parseErr;
|
|
269
|
+
const rootDir = resolveProductRootDir(data.base);
|
|
270
|
+
const source = resolvePageFile(rootDir, data.sourcePath);
|
|
271
|
+
const { dir: targetDir, rel: targetFolder } = resolveParentDir(rootDir, data.targetFolder);
|
|
272
|
+
if (source.parent === targetFolder) throw new Error('页面已在目标文件夹中');
|
|
273
|
+
|
|
274
|
+
const bundleNames = [`${source.pageName}.html`, `${source.pageName}.js`, `${source.pageName}.md`];
|
|
275
|
+
const conflicts = bundleNames.filter((name) => fs.existsSync(path.join(targetDir, name)));
|
|
276
|
+
if (conflicts.length) throw new Error(`目标文件夹已存在同名文件:${conflicts.join('、')}`);
|
|
277
|
+
|
|
278
|
+
const bundle = bundleNames
|
|
279
|
+
.map((name) => ({ source: path.join(source.dir, name), target: path.join(targetDir, name), name }))
|
|
280
|
+
.filter((item) => fs.existsSync(item.source) && fs.statSync(item.source).isFile());
|
|
281
|
+
if (!bundle.some((item) => item.name === source.fileName)) throw new Error('源页面不存在');
|
|
282
|
+
|
|
283
|
+
const tree = loadNavTree(rootDir);
|
|
284
|
+
const sourceLevel = getNavLevel(tree, source.parent);
|
|
285
|
+
const sourceIndex = sourceLevel.findIndex((node) => node.file === source.fileName && node.path === source.relPath);
|
|
286
|
+
if (sourceIndex < 0) throw new Error('导航树中不存在源页面,请刷新后重试');
|
|
287
|
+
const sourceNode = sourceLevel[sourceIndex];
|
|
288
|
+
const targetLevel = getNavLevel(tree, targetFolder);
|
|
289
|
+
const targetPath = targetFolder ? `${targetFolder}/${source.fileName}` : source.fileName;
|
|
290
|
+
|
|
291
|
+
bundle.forEach((item) => {
|
|
292
|
+
fs.renameSync(item.source, item.target);
|
|
293
|
+
moved.push(item);
|
|
294
|
+
});
|
|
295
|
+
sourceLevel.splice(sourceIndex, 1);
|
|
296
|
+
targetLevel.push({
|
|
297
|
+
file: source.fileName,
|
|
298
|
+
path: targetPath,
|
|
299
|
+
...(sourceNode.title ? { title: sourceNode.title } : {})
|
|
300
|
+
});
|
|
301
|
+
saveNavTreeAtomically(rootDir, tree);
|
|
302
|
+
|
|
303
|
+
console.log(`[200] POST /api/move-page -> ${source.relPath} => ${targetPath}`);
|
|
304
|
+
sendJson(res, 200, {
|
|
305
|
+
ok: true,
|
|
306
|
+
sourcePath: source.relPath,
|
|
307
|
+
path: targetPath,
|
|
308
|
+
movedFiles: moved.map((item) => targetFolder ? `${targetFolder}/${item.name}` : item.name)
|
|
309
|
+
});
|
|
310
|
+
} catch (err) {
|
|
311
|
+
const rollbackErrors = [];
|
|
312
|
+
moved.reverse().forEach((item) => {
|
|
313
|
+
try {
|
|
314
|
+
if (fs.existsSync(item.target) && !fs.existsSync(item.source)) fs.renameSync(item.target, item.source);
|
|
315
|
+
} catch (rollbackErr) {
|
|
316
|
+
rollbackErrors.push(rollbackErr.message);
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
const errorMessage = rollbackErrors.length
|
|
320
|
+
? `${err.message};回滚失败:${rollbackErrors.join('、')}`
|
|
321
|
+
: err.message;
|
|
322
|
+
console.log(`[400] POST /api/move-page -> ${errorMessage}`);
|
|
323
|
+
sendJson(res, 400, { ok: false, error: errorMessage });
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
|
|
235
328
|
function todayString() {
|
|
236
329
|
const now = new Date();
|
|
237
330
|
const pad = (n) => String(n).padStart(2, '0');
|
|
@@ -321,7 +414,7 @@ function handleCreatePage(req, res) {
|
|
|
321
414
|
const { dir: parentDir, rel: parentRel } = resolveParentDir(rootDir, data.parent);
|
|
322
415
|
const name = String(data.name || '').trim().replace(/\.html$/i, '');
|
|
323
416
|
assertValidSegment(name, '页面名');
|
|
324
|
-
const title =
|
|
417
|
+
const title = name;
|
|
325
418
|
const htmlFile = path.join(parentDir, `${name}.html`);
|
|
326
419
|
const mdFile = path.join(parentDir, `${name}.md`);
|
|
327
420
|
if (fs.existsSync(htmlFile)) throw new Error('同名页面已存在');
|
|
@@ -331,7 +424,7 @@ function handleCreatePage(req, res) {
|
|
|
331
424
|
const tree = loadNavTree(rootDir);
|
|
332
425
|
const children = ensureNavFolder(tree, parentRel);
|
|
333
426
|
if (!children.some((n) => n.file === `${name}.html`)) {
|
|
334
|
-
children.push({ file: `${name}.html`, path: relPath });
|
|
427
|
+
children.push({ file: `${name}.html`, path: relPath, title });
|
|
335
428
|
}
|
|
336
429
|
saveNavTree(rootDir, tree);
|
|
337
430
|
console.log(`[200] POST /api/create-page -> ${htmlFile}`);
|
|
@@ -857,6 +950,7 @@ const server = http.createServer(async (req, res) => {
|
|
|
857
950
|
if (req.method === 'POST' && urlPath === '/api/create-folder') return requireLoopback(req, res) && handleCreateFolder(req, res);
|
|
858
951
|
if (req.method === 'POST' && urlPath === '/api/create-page') return requireLoopback(req, res) && handleCreatePage(req, res);
|
|
859
952
|
if (req.method === 'POST' && urlPath === '/api/reorder-nav') return requireLoopback(req, res) && handleReorderNav(req, res);
|
|
953
|
+
if (req.method === 'POST' && urlPath === '/api/move-page') return requireLoopback(req, res) && handleMovePage(req, res);
|
|
860
954
|
if (req.method === 'POST' && urlPath === '/api/build-update-page-prompt') return requireLoopback(req, res) && handleBuildUpdatePagePrompt(req, res);
|
|
861
955
|
if (req.method === 'POST' && urlPath === '/api/update-page-from-prd') return requireLoopback(req, res) && handleUpdatePageFromPrd(req, res);
|
|
862
956
|
|
|
@@ -88,6 +88,7 @@ function preserveTreeOrder(nodes, previousNodes) {
|
|
|
88
88
|
(previousNodes || []).forEach((previousNode) => {
|
|
89
89
|
const node = currentByKey.get(nodeKey(previousNode));
|
|
90
90
|
if (!node) return;
|
|
91
|
+
if (node.file && previousNode.title) node.title = previousNode.title;
|
|
91
92
|
ordered.push(node);
|
|
92
93
|
currentByKey.delete(nodeKey(previousNode));
|
|
93
94
|
});
|
|
@@ -284,6 +284,11 @@ body.is-resizing-sidebar .preview-frame {
|
|
|
284
284
|
.file-row.tree-drag-before::before { top: -1px; }
|
|
285
285
|
.folder-head.tree-drag-after::after,
|
|
286
286
|
.file-row.tree-drag-after::after { bottom: -1px; }
|
|
287
|
+
.folder-head.tree-drag-into {
|
|
288
|
+
color: #0958d9;
|
|
289
|
+
background: #e6f4ff;
|
|
290
|
+
box-shadow: inset 0 0 0 1px #1677ff;
|
|
291
|
+
}
|
|
287
292
|
|
|
288
293
|
/* ── Folder ── */
|
|
289
294
|
.folder-head {
|
|
@@ -597,12 +602,8 @@ body.is-resizing-sidebar .preview-frame {
|
|
|
597
602
|
<div class="create-modal-title" id="createModalTitle">新建页面</div>
|
|
598
603
|
<div class="create-modal-location" id="createModalLocation"></div>
|
|
599
604
|
<div class="create-modal-field">
|
|
600
|
-
<label for="createNameInput"
|
|
601
|
-
<input id="createNameInput" type="text" placeholder="如
|
|
602
|
-
</div>
|
|
603
|
-
<div class="create-modal-field" id="createTitleField">
|
|
604
|
-
<label for="createTitleInput">页面标题(可选,用于页面 <title> 与 PRD)</label>
|
|
605
|
-
<input id="createTitleInput" type="text" placeholder="如 订单列表" autocomplete="off">
|
|
605
|
+
<label for="createNameInput" id="createNameLabel">名称</label>
|
|
606
|
+
<input id="createNameInput" type="text" placeholder="如 订单列表" autocomplete="off">
|
|
606
607
|
</div>
|
|
607
608
|
<div class="create-modal-error" id="createModalError"></div>
|
|
608
609
|
<div class="create-modal-actions">
|
|
@@ -822,7 +823,8 @@ const breadcrumbMap = {};
|
|
|
822
823
|
function buildBreadcrumbs(nodes, trail) {
|
|
823
824
|
nodes.forEach(n => {
|
|
824
825
|
if (n.file) {
|
|
825
|
-
|
|
826
|
+
const label = n.title || n.file;
|
|
827
|
+
breadcrumbMap[n.path] = trail ? trail + ' / ' + label : label;
|
|
826
828
|
} else {
|
|
827
829
|
buildBreadcrumbs(n.children || [], trail ? trail + ' / ' + n.name : n.name);
|
|
828
830
|
}
|
|
@@ -1072,24 +1074,24 @@ function treeSortingBlocked() {
|
|
|
1072
1074
|
}
|
|
1073
1075
|
|
|
1074
1076
|
function clearTreeDragStyles() {
|
|
1075
|
-
document.querySelectorAll('.dragging, .tree-drag-before, .tree-drag-after').forEach(element => {
|
|
1076
|
-
element.classList.remove('dragging', 'tree-drag-before', 'tree-drag-after');
|
|
1077
|
+
document.querySelectorAll('.dragging, .tree-drag-before, .tree-drag-after, .tree-drag-into').forEach(element => {
|
|
1078
|
+
element.classList.remove('dragging', 'tree-drag-before', 'tree-drag-after', 'tree-drag-into');
|
|
1077
1079
|
delete element.dataset.dropPosition;
|
|
1078
1080
|
});
|
|
1079
1081
|
}
|
|
1080
1082
|
|
|
1081
1083
|
function clearTreeDropStyles() {
|
|
1082
|
-
document.querySelectorAll('.tree-drag-before, .tree-drag-after').forEach(element => {
|
|
1083
|
-
element.classList.remove('tree-drag-before', 'tree-drag-after');
|
|
1084
|
+
document.querySelectorAll('.tree-drag-before, .tree-drag-after, .tree-drag-into').forEach(element => {
|
|
1085
|
+
element.classList.remove('tree-drag-before', 'tree-drag-after', 'tree-drag-into');
|
|
1084
1086
|
delete element.dataset.dropPosition;
|
|
1085
1087
|
});
|
|
1086
1088
|
}
|
|
1087
1089
|
|
|
1088
|
-
function setupTreeDrag(element, parentKey, nodeKey) {
|
|
1090
|
+
function setupTreeDrag(element, parentKey, nodeKey, targetFolderKey) {
|
|
1089
1091
|
element.draggable = true;
|
|
1090
1092
|
element.dataset.parentKey = parentKey;
|
|
1091
1093
|
element.dataset.nodeKey = nodeKey;
|
|
1092
|
-
element.title = element.title || '拖动调整同级排序';
|
|
1094
|
+
element.title = element.title || (targetFolderKey ? '拖动调整同级排序,或将页面拖入此文件夹' : '拖动调整同级排序');
|
|
1093
1095
|
|
|
1094
1096
|
element.addEventListener('dragstart', event => {
|
|
1095
1097
|
if (treeSortingBlocked()) {
|
|
@@ -1097,7 +1099,12 @@ function setupTreeDrag(element, parentKey, nodeKey) {
|
|
|
1097
1099
|
showToast(reorderSaving ? '正在保存排序' : '请先清除搜索或版本筛选再排序');
|
|
1098
1100
|
return;
|
|
1099
1101
|
}
|
|
1100
|
-
dragState = {
|
|
1102
|
+
dragState = {
|
|
1103
|
+
parentKey,
|
|
1104
|
+
nodeKey,
|
|
1105
|
+
sourcePath: element.dataset.path || '',
|
|
1106
|
+
isPage: nodeKey.startsWith('file:')
|
|
1107
|
+
};
|
|
1101
1108
|
suppressTreeClickUntil = Date.now() + 400;
|
|
1102
1109
|
element.classList.add('dragging');
|
|
1103
1110
|
event.dataTransfer.effectAllowed = 'move';
|
|
@@ -1105,7 +1112,17 @@ function setupTreeDrag(element, parentKey, nodeKey) {
|
|
|
1105
1112
|
});
|
|
1106
1113
|
|
|
1107
1114
|
element.addEventListener('dragover', event => {
|
|
1108
|
-
if (!dragState
|
|
1115
|
+
if (!dragState) return;
|
|
1116
|
+
const isMoveIntoFolder = targetFolderKey && dragState.isPage && dragState.parentKey !== targetFolderKey;
|
|
1117
|
+
if (isMoveIntoFolder) {
|
|
1118
|
+
event.preventDefault();
|
|
1119
|
+
event.stopPropagation();
|
|
1120
|
+
clearTreeDropStyles();
|
|
1121
|
+
element.classList.add('tree-drag-into');
|
|
1122
|
+
event.dataTransfer.dropEffect = 'move';
|
|
1123
|
+
return;
|
|
1124
|
+
}
|
|
1125
|
+
if (dragState.parentKey !== parentKey || dragState.nodeKey === nodeKey) return;
|
|
1109
1126
|
event.preventDefault();
|
|
1110
1127
|
event.stopPropagation();
|
|
1111
1128
|
clearTreeDropStyles();
|
|
@@ -1115,11 +1132,22 @@ function setupTreeDrag(element, parentKey, nodeKey) {
|
|
|
1115
1132
|
});
|
|
1116
1133
|
|
|
1117
1134
|
element.addEventListener('drop', event => {
|
|
1118
|
-
if (!dragState
|
|
1135
|
+
if (!dragState) return;
|
|
1136
|
+
const currentDrag = dragState;
|
|
1137
|
+
const isMoveIntoFolder = targetFolderKey && currentDrag.isPage && currentDrag.parentKey !== targetFolderKey;
|
|
1138
|
+
if (isMoveIntoFolder) {
|
|
1139
|
+
event.preventDefault();
|
|
1140
|
+
event.stopPropagation();
|
|
1141
|
+
clearTreeDragStyles();
|
|
1142
|
+
dragState = null;
|
|
1143
|
+
movePageToFolder(currentDrag.sourcePath, targetFolderKey);
|
|
1144
|
+
return;
|
|
1145
|
+
}
|
|
1146
|
+
if (currentDrag.parentKey !== parentKey || currentDrag.nodeKey === nodeKey) return;
|
|
1119
1147
|
event.preventDefault();
|
|
1120
1148
|
event.stopPropagation();
|
|
1121
1149
|
const position = element.dataset.dropPosition || 'before';
|
|
1122
|
-
const sourceKey =
|
|
1150
|
+
const sourceKey = currentDrag.nodeKey;
|
|
1123
1151
|
clearTreeDragStyles();
|
|
1124
1152
|
dragState = null;
|
|
1125
1153
|
reorderTreeNodes(parentKey, sourceKey, nodeKey, position);
|
|
@@ -1131,6 +1159,50 @@ function setupTreeDrag(element, parentKey, nodeKey) {
|
|
|
1131
1159
|
});
|
|
1132
1160
|
}
|
|
1133
1161
|
|
|
1162
|
+
function movePageLocalState(sourcePath, targetPath) {
|
|
1163
|
+
if (Object.prototype.hasOwnProperty.call(versionCache, sourcePath)) {
|
|
1164
|
+
versionCache[targetPath] = versionCache[sourcePath];
|
|
1165
|
+
delete versionCache[sourcePath];
|
|
1166
|
+
saveVersionCache();
|
|
1167
|
+
}
|
|
1168
|
+
if (reviewStatus[sourcePath]) {
|
|
1169
|
+
reviewStatus[targetPath] = reviewStatus[sourcePath];
|
|
1170
|
+
delete reviewStatus[sourcePath];
|
|
1171
|
+
saveReviewStatus();
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
async function movePageToFolder(sourcePath, targetFolder) {
|
|
1176
|
+
if (!sourcePath || !targetFolder) return;
|
|
1177
|
+
const wasActive = !!(activeRow && activeRow.dataset.path === sourcePath);
|
|
1178
|
+
reorderSaving = true;
|
|
1179
|
+
try {
|
|
1180
|
+
const res = await fetch('/api/move-page', {
|
|
1181
|
+
method: 'POST',
|
|
1182
|
+
headers: { 'Content-Type': 'application/json' },
|
|
1183
|
+
body: JSON.stringify({ base: PAGE_BASE, sourcePath, targetFolder })
|
|
1184
|
+
});
|
|
1185
|
+
const data = await res.json().catch(() => ({}));
|
|
1186
|
+
if (!res.ok || !data.ok) throw new Error(data.error || '移动失败:' + res.status);
|
|
1187
|
+
movePageLocalState(sourcePath, data.path);
|
|
1188
|
+
await loadTree();
|
|
1189
|
+
renderTree();
|
|
1190
|
+
expandFolderTrail(targetFolder);
|
|
1191
|
+
if (wasActive) {
|
|
1192
|
+
const row = document.querySelector(`.file-row[data-path="${CSS.escape(data.path)}"]`);
|
|
1193
|
+
if (row) loadPreview(data.path, row);
|
|
1194
|
+
}
|
|
1195
|
+
fetchAllVersions();
|
|
1196
|
+
showToast('页面已移入:' + targetFolder);
|
|
1197
|
+
} catch (err) {
|
|
1198
|
+
try { await loadTree(); } catch {}
|
|
1199
|
+
renderTree();
|
|
1200
|
+
showToast(err.message);
|
|
1201
|
+
} finally {
|
|
1202
|
+
reorderSaving = false;
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1134
1206
|
async function reorderTreeNodes(parentKey, sourceKey, targetKey, position) {
|
|
1135
1207
|
const level = getTreeLevel(parentKey);
|
|
1136
1208
|
const beforeOrder = level.map(navNodeKey);
|
|
@@ -1177,12 +1249,13 @@ function renderNodes(nodes, depth, trail) {
|
|
|
1177
1249
|
const row = document.createElement('div');
|
|
1178
1250
|
row.className = 'file-row';
|
|
1179
1251
|
row.dataset.path = node.path;
|
|
1180
|
-
|
|
1252
|
+
const pageLabel = node.title || node.file;
|
|
1253
|
+
row.dataset.searchText = [pageLabel, node.file, node.path, breadcrumbMap[node.path] || ''].join(' ');
|
|
1181
1254
|
setupTreeDrag(row, trail, navNodeKey(node));
|
|
1182
1255
|
row.innerHTML = `
|
|
1183
1256
|
<div class="file-main">
|
|
1184
1257
|
<span class="file-icon">${I_FILE}</span>
|
|
1185
|
-
<span class="file-name" title="${node.file}">${
|
|
1258
|
+
<span class="file-name" title="${node.file}">${pageLabel}</span>
|
|
1186
1259
|
<span class="version-badge"></span>
|
|
1187
1260
|
<!-- review-btn:start (个人审核标记,本地开发专用;发布时可自动剥离) -->
|
|
1188
1261
|
${renderReviewButton(node.path, 'md', 'PRD')}
|
|
@@ -1212,7 +1285,7 @@ function renderNodes(nodes, depth, trail) {
|
|
|
1212
1285
|
|
|
1213
1286
|
const head = document.createElement('div');
|
|
1214
1287
|
head.className = 'folder-head';
|
|
1215
|
-
setupTreeDrag(head, trail, navNodeKey(node));
|
|
1288
|
+
setupTreeDrag(head, trail, navNodeKey(node), folderKey);
|
|
1216
1289
|
head.innerHTML = `<span class="folder-arrow">${I_ARROW}</span><span class="folder-icon">${I_FOLDER}</span><span class="folder-name">${node.name}</span><button type="button" class="tree-add-btn" data-create="page" title="在此文件夹新建页面">+页</button><button type="button" class="tree-add-btn" data-create="folder" title="在此文件夹新建子文件夹">+夹</button>`;
|
|
1217
1290
|
head.addEventListener('click', () => {
|
|
1218
1291
|
if (Date.now() >= suppressTreeClickUntil) folder.classList.toggle('collapsed');
|
|
@@ -1273,9 +1346,11 @@ function openCreateModal(type, parentPath) {
|
|
|
1273
1346
|
createModalState = { type, parentPath: parentPath || '' };
|
|
1274
1347
|
document.getElementById('createModalTitle').textContent = type === 'folder' ? '新建文件夹' : '新建页面';
|
|
1275
1348
|
document.getElementById('createModalLocation').textContent = '位置:' + (parentPath ? parentPath + '/' : '根目录');
|
|
1276
|
-
document.getElementById('
|
|
1349
|
+
document.getElementById('createNameLabel').textContent = type === 'folder'
|
|
1350
|
+
? '名称(作为文件夹名和左侧导航名称;支持中文、字母、数字、_ 和 -)'
|
|
1351
|
+
: '名称(用于文件名、左侧导航、页面 <title> 与 PRD;支持中文、字母、数字、_ 和 -)';
|
|
1352
|
+
document.getElementById('createNameInput').placeholder = type === 'folder' ? '如 customer' : '如 订单列表';
|
|
1277
1353
|
document.getElementById('createNameInput').value = '';
|
|
1278
|
-
document.getElementById('createTitleInput').value = '';
|
|
1279
1354
|
document.getElementById('createModalError').textContent = '';
|
|
1280
1355
|
document.getElementById('createModalMask').classList.add('show');
|
|
1281
1356
|
document.getElementById('createNameInput').focus();
|
|
@@ -1308,7 +1383,6 @@ async function submitCreateModal() {
|
|
|
1308
1383
|
errorEl.textContent = '';
|
|
1309
1384
|
try {
|
|
1310
1385
|
const payload = { base: PAGE_BASE, parent: parentPath, name };
|
|
1311
|
-
if (type === 'page') payload.title = document.getElementById('createTitleInput').value.trim();
|
|
1312
1386
|
const res = await fetch(type === 'folder' ? '/api/create-folder' : '/api/create-page', {
|
|
1313
1387
|
method: 'POST',
|
|
1314
1388
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -1431,7 +1505,7 @@ window.addEventListener('DOMContentLoaded', async () => {
|
|
|
1431
1505
|
document.getElementById('createModalMask').addEventListener('click', e => {
|
|
1432
1506
|
if (e.target === e.currentTarget) closeCreateModal();
|
|
1433
1507
|
});
|
|
1434
|
-
[document.getElementById('createNameInput')
|
|
1508
|
+
[document.getElementById('createNameInput')].forEach(input => {
|
|
1435
1509
|
input.addEventListener('keydown', e => {
|
|
1436
1510
|
if (e.key === 'Enter') { e.preventDefault(); submitCreateModal(); }
|
|
1437
1511
|
else if (e.key === 'Escape') closeCreateModal();
|