Skip to content

Commit f0c83ed

Browse files
author
linyuan.yang
committed
复用 ui-kit
1 parent 05e45e2 commit f0c83ed

1 file changed

Lines changed: 49 additions & 94 deletions

File tree

‎packages/app/src/tools/file/batch-rename/BatchRenameView.vue‎

Lines changed: 49 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -81,63 +81,8 @@ const canExecute = computed(() =>
8181
&& !executing.value,
8282
)
8383
84-
// ---- 列表拖拽排序(pointer 实现):Windows 上 Tauri 接管了 WebView2 的原生 drop 处理,
85-
// HTML5 DnD 的 drop 事件不会触发;规则使用 ui-kit 排序,文件行保留整行拖动 ----
86-
87-
const draggingFiles = ref(false)
88-
89-
/** 行内表单控件与按钮上的按下不启动拖拽 */
90-
function beginFileDrag(event: PointerEvent) {
91-
if (event.button !== 0) return
92-
if ((event.target as HTMLElement).closest('input, textarea, select, button, a, label')) return
93-
const rowEl = event.currentTarget as HTMLElement
94-
const container = rowEl.parentElement
95-
if (!container) return
96-
97-
draggingFiles.value = true
98-
rowEl.style.opacity = '0.5'
99-
document.body.style.userSelect = 'none'
100-
101-
let raf = 0
102-
let lastY = event.clientY
103-
104-
// rAF 中处理:Vue 的 DOM 重排是异步的,按帧读取行位置才能与列表状态同步
105-
const applyMove = () => {
106-
raf = 0
107-
// 拖到容器上下边缘时自动滚动
108-
const rect = container.getBoundingClientRect()
109-
if (lastY < rect.top + 32) container.scrollTop -= 14
110-
else if (lastY > rect.bottom - 32) container.scrollTop += 14
111-
112-
const rows = [...container.querySelectorAll<HTMLElement>('.preview-row:not(.head-row)')]
113-
const at = rows.findIndex(row => {
114-
const r = row.getBoundingClientRect()
115-
return lastY >= r.top && lastY < r.bottom
116-
})
117-
const from = rows.indexOf(rowEl)
118-
if (at < 0 || from < 0 || from === at) return
119-
const list = files.value
120-
const [item] = list.splice(from, 1)
121-
list.splice(at, 0, item)
122-
sortKey.value = null
123-
}
124-
125-
const onMove = (e: PointerEvent) => {
126-
lastY = e.clientY
127-
if (!raf) raf = requestAnimationFrame(applyMove)
128-
}
129-
const onUp = () => {
130-
draggingFiles.value = false
131-
rowEl.style.opacity = ''
132-
document.body.style.userSelect = ''
133-
window.removeEventListener('pointermove', onMove)
134-
window.removeEventListener('pointerup', onUp)
135-
window.removeEventListener('pointercancel', onUp)
136-
}
137-
window.addEventListener('pointermove', onMove)
138-
window.addEventListener('pointerup', onUp)
139-
window.addEventListener('pointercancel', onUp)
140-
}
84+
// ---- 文件行排序复用 ui-kit 的 SSortableList/SSortableItem:把手在行首,pointer 实现,
85+
// 不依赖 HTML5 DnD(Windows 上 Tauri 接管了 WebView2 的原生 drop 处理)并自带键盘调序 ----
14186
14287
function basename(p: string): string {
14388
return p.slice(Math.max(p.lastIndexOf('\\'), p.lastIndexOf('/')) + 1)
@@ -241,6 +186,12 @@ function sortBy(key: SortKey) {
241186
})
242187
}
243188
189+
/** 把手拖动/键盘调序后换成手动顺序,排序按钮的高亮随之失效 */
190+
function reorderFiles(items: FileEntry[]) {
191+
files.value = items
192+
sortKey.value = null
193+
}
194+
244195
async function chooseFiles() {
245196
const selection = await open({ title: '选择要重命名的文件', multiple: true })
246197
if (Array.isArray(selection)) await addFiles(selection)
@@ -404,7 +355,7 @@ onUnmounted(() => {
404355
class="sort-btn"
405356
:class="{ active: sortKey === opt.key }"
406357
@click="sortBy(opt.key)">{{ opt.label }}{{ sortKey === opt.key ? (sortAsc ? ' ↑' : ' ↓') : '' }}</SButton>
407-
<span class="sort-hint">拖动行可手动调整顺序</span>
358+
<span class="sort-hint">拖动左侧把手可手动调整顺序</span>
408359
</div>
409360
</div>
410361
<SEmpty v-if="!files.length" description="还没有文件。点击上方「添加文件」或直接把文件拖进窗口。" />
@@ -416,39 +367,41 @@ onUnmounted(() => {
416367
<span>状态</span>
417368
<span>操作</span>
418369
</div>
419-
<div
420-
v-for="(item, i) in preview"
421-
:key="files[i].path"
422-
class="preview-row"
423-
:class="[`status-${item.status}`, { dragging: draggingFiles }]"
424-
@pointerdown="beginFileDrag($event)"
425-
>
426-
<span class="name" :title="files[i].path">{{ item.originalName }}</span>
427-
<span class="name final">
428-
<ChevronRight class="arrow" :size="14" />
429-
{{ item.finalName }}
430-
</span>
431-
<SEllipsis class="folder-path">{{ parentDir(files[i].path) }}</SEllipsis>
432-
<span class="file-status" :title="item.statusDetail">{{ item.status === 'ok' ? '将重命名' : statusText(item) }}</span>
433-
<span class="row-actions">
434-
<SButton size="small" text v-if="item.steps.length"
435-
436-
437-
@click="toggleExpand(files[i].path)">{{ expanded.has(files[i].path) ? '收起' : '步骤' }}</SButton>
438-
<SButton size="small" text @click="removeFile(i)">移除</SButton>
439-
</span>
440-
<div v-if="expanded.has(files[i].path) && item.steps.length" class="steps">
441-
<div v-for="(step, s) in item.steps" :key="step.ruleId + s" class="step">
442-
<span class="step-name">{{ s + 1 }}. {{ step.ruleLabel }}</span>
443-
<code>{{ step.name }}</code>
370+
<SSortableList :items="files" label="文件" @reorder="reorderFiles">
371+
<SSortableItem
372+
v-for="(file, i) in files"
373+
:key="file.path"
374+
class="file-slot"
375+
:index="i"
376+
:label="`文件 ${file.name}`"
377+
>
378+
<div class="preview-row" :class="`status-${preview[i].status}`">
379+
<span class="name" :title="file.path">{{ preview[i].originalName }}</span>
380+
<span class="name final">
381+
<ChevronRight class="arrow" :size="14" />
382+
{{ preview[i].finalName }}
383+
</span>
384+
<SEllipsis class="folder-path">{{ parentDir(file.path) }}</SEllipsis>
385+
<span class="file-status" :title="preview[i].statusDetail">{{ preview[i].status === 'ok' ? '将重命名' : statusText(preview[i]) }}</span>
386+
<span class="row-actions">
387+
<SButton size="small" text v-if="preview[i].steps.length"
388+
@click="toggleExpand(file.path)">{{ expanded.has(file.path) ? '收起' : '步骤' }}</SButton>
389+
<SButton size="small" text @click="removeFile(i)">移除</SButton>
390+
</span>
391+
<div v-if="expanded.has(file.path) && preview[i].steps.length" class="steps">
392+
<div v-for="(step, s) in preview[i].steps" :key="step.ruleId + s" class="step">
393+
<span class="step-name">{{ s + 1 }}. {{ step.ruleLabel }}</span>
394+
<code>{{ step.name }}</code>
395+
</div>
396+
</div>
397+
<div v-if="results[file.path]" class="exec-result" :class="`exec-${results[file.path].status}`">
398+
<Check v-if="results[file.path].status === 'renamed'" :size="13" />
399+
<TriangleAlert v-else :size="13" />
400+
{{ execText(results[file.path]) }}
401+
</div>
444402
</div>
445-
</div>
446-
<div v-if="results[files[i].path]" class="exec-result" :class="`exec-${results[files[i].path].status}`">
447-
<Check v-if="results[files[i].path].status === 'renamed'" :size="13" />
448-
<TriangleAlert v-else :size="13" />
449-
{{ execText(results[files[i].path]) }}
450-
</div>
451-
</div>
403+
</SSortableItem>
404+
</SSortableList>
452405
</div>
453406
</div>
454407
</template>
@@ -494,9 +447,10 @@ h3 { margin: 0; font-size: 14px; }
494447
.rule-slot { margin-bottom: 6px; }
495448
.rule-slot :deep(> .sort-handle) { position: absolute; top: 10px; left: 8px; z-index: 1; }
496449
.preview-list { border: 1px solid var(--border); border-radius: 6px; overflow-y: auto; min-height: 0; flex: 1 1 auto; }
497-
.preview-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr) minmax(0, 1fr) minmax(80px, 0.4fr) 76px; gap: 10px; align-items: start; padding: 6px 12px; border-top: 1px solid var(--border); font-size: 13px; cursor: grab; }
498-
.preview-row:active { cursor: grabbing; }
499-
.preview-row.head-row { position: sticky; top: 0; z-index: 1; border-top: none; background: var(--bg); color: var(--fg-muted); font-size: 12px; cursor: default; }
450+
.file-slot :deep(> .sort-handle) { position: absolute; top: 5px; left: 6px; }
451+
.preview-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr) minmax(0, 1fr) minmax(80px, 0.4fr) 76px; gap: 10px; align-items: start; padding: 6px 12px 6px 36px; border-top: 1px solid var(--border); font-size: 13px; }
452+
/* 表头 sticky 层级要压过行内任何定位元素(把手、落点指示线),否则滚动时它们会透到表头上 */
453+
.preview-row.head-row { position: sticky; top: 0; z-index: 3; border-top: none; background: var(--bg); color: var(--fg-muted); font-size: 12px; }
500454
.name { overflow-wrap: anywhere; font: 12px ui-monospace, SFMono-Regular, Consolas, monospace; }
501455
.folder-path { color: var(--fg-muted); font: 12px ui-monospace, SFMono-Regular, Consolas, monospace; }
502456
.final { display: flex; gap: 4px; align-items: baseline; flex-wrap: wrap; }
@@ -519,7 +473,8 @@ h3 { margin: 0; font-size: 14px; }
519473
.footer-note { font-size: 13px; color: var(--fg-muted); }
520474
@media (max-width: 600px) {
521475
.rules-pane, .preview-pane { padding: 10px; }
522-
.preview-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 0.8fr) 64px 60px; gap: 6px; padding: 6px 8px; }
476+
.preview-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 0.8fr) 64px 60px; gap: 6px; padding: 6px 8px 6px 30px; }
477+
.file-slot :deep(> .sort-handle) { left: 3px; }
523478
.row-actions { gap: 4px; flex-wrap: wrap; }
524479
}
525480
</style>

0 commit comments

Comments
 (0)