Skip to content

Commit 0bbdc12

Browse files
author
linyuan.yang
committed
批量重命名
1 parent e015342 commit 0bbdc12

5 files changed

Lines changed: 268 additions & 50 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
- 新增批量重命名工具:可添加文件(支持拖入窗口与选择文件夹),按顺序叠加多条规则(搜索替换、插入文本、序号编号、大小写转换、删除)实时预览最终文件名,支持逐步预览、规则拖拽排序与冲突检测后一键执行。
88
- 批量重命名添加文件夹时支持「包含子文件夹」,勾选后递归收集所有子文件夹中的文件。
9+
- 批量重命名规则支持独立折叠,收起后保留规则摘要及启用、删除操作,隐藏参数和校验提示。
10+
- 批量重命名规则点击标题行即可折叠/展开,拖动排序仅通过左侧图标触发。
11+
- 批量重命名参考 ReNamer 调整为上方规则、下方文件预览的布局,规则摘要合并至标题行,预览增加独立状态列和固定表头。
12+
- 批量重命名文件预览增加「所在文件夹」列,长路径省略显示,悬停可查看完整路径。
13+
- 批量重命名插入规则支持元数据标签,可混合文字插入原始文件名、扩展名、文件夹名、路径、大小、创建/修改时间、当前时间及剪贴板文本;缺失元数据会在预览中提示并阻止执行。
914

1015
### 优化
1116

‎packages/app/src-tauri/capabilities/default.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"clipboard-manager:allow-write-image",
2929
"clipboard-manager:allow-read-image",
3030
"clipboard-manager:allow-write-text",
31+
"clipboard-manager:allow-read-text",
3132
"log:default"
3233
]
3334
}

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

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { computed, onMounted, onUnmounted, ref } from 'vue'
33
import { open } from '@tauri-apps/plugin-dialog'
44
import { getCurrentWebview } from '@tauri-apps/api/webview'
5+
import { readText } from '@tauri-apps/plugin-clipboard-manager'
56
import { toast } from '@qingfeng346/ui-kit/composables/message'
67
import { Check, ChevronRight, FolderOpen, Plus, TriangleAlert, X } from 'lucide-vue-next'
78
import {
@@ -32,8 +33,24 @@ const adding = ref(false)
3233
/** 添加文件夹时是否递归收集子文件夹中的文件 */
3334
const recursive = ref(false)
3435
const executing = ref(false)
36+
const clipboard = ref<string>()
37+
const readingClipboard = ref(false)
38+
const usesClipboard = computed(() => rules.value.some(rule => rule.enabled && rule.type === 'insert' && rule.text.includes('{Clipboard}')))
3539
36-
const preview = computed(() => previewRename(rules.value, files.value.map(f => f.name)))
40+
const preview = computed(() => previewRename(rules.value, files.value, { clipboard: clipboard.value }))
41+
42+
async function refreshClipboard() {
43+
if (readingClipboard.value) return
44+
readingClipboard.value = true
45+
clipboard.value = undefined
46+
try {
47+
clipboard.value = await readText()
48+
} catch (error) {
49+
toast.show('error', `读取剪贴板失败:${String(error)}`)
50+
} finally {
51+
readingClipboard.value = false
52+
}
53+
}
3754
3855
const counts = computed(() => {
3956
let willRename = 0
@@ -69,6 +86,7 @@ const ROW_SELECTOR: Record<DragList, string> = {
6986
/** 行内表单控件与按钮上的按下不启动拖拽 */
7087
function beginListDrag(event: PointerEvent, kind: DragList) {
7188
if (event.button !== 0) return
89+
if (kind === 'rule' && !(event.target as Element).closest('.grip')) return
7290
if ((event.target as HTMLElement).closest('input, textarea, select, button, a, label')) return
7391
const rowEl = event.currentTarget as HTMLElement
7492
const container = rowEl.parentElement
@@ -319,7 +337,7 @@ onUnmounted(() => {
319337
<template>
320338
<div class="batch-rename">
321339
<h2>批量重命名</h2>
322-
<p class="lead">添加文件,按顺序叠加规则(搜索替换、插入、序号、大小写、删除),实时预览最终文件名后一次性执行。文件可直接拖入窗口。</p>
340+
<p class="lead">添加或拖入文件,在上方配置规则,在下方预览结果后执行重命名。</p>
323341

324342
<section class="card">
325343
<div class="toolbar">
@@ -340,7 +358,7 @@ onUnmounted(() => {
340358
</section>
341359

342360
<section class="card workbench">
343-
<div class="columns">
361+
<div class="panes">
344362
<div class="rules-pane">
345363
<div class="pane-head">
346364
<h3>规则(按顺序执行)</h3>
@@ -362,6 +380,7 @@ onUnmounted(() => {
362380
@update="fields => Object.assign(rule, fields)"
363381
@change-type="(type: RuleType) => changeType(rule, type)"
364382
@remove="removeRule(index)"
383+
@read-clipboard="refreshClipboard"
365384
/>
366385
</div>
367386
</div>
@@ -370,6 +389,7 @@ onUnmounted(() => {
370389
<div class="pane-head stacked">
371390
<div class="head-line">
372391
<h3>预览</h3>
392+
<button v-if="usesClipboard" type="button" class="link-btn" :disabled="readingClipboard" @click="refreshClipboard">{{ readingClipboard ? '正在读取…' : '重新读取剪贴板' }}</button>
373393
<span class="summary">
374394
{{ files.length }} 个文件 · {{ counts.willRename }} 将重命名 · {{ counts.unchanged }} 无变化 · {{ counts.conflict }} 冲突
375395
</span>
@@ -392,7 +412,9 @@ onUnmounted(() => {
392412
<div class="preview-row head-row">
393413
<span>原始文件名</span>
394414
<span>新文件名</span>
395-
<span />
415+
<span>所在文件夹</span>
416+
<span>状态</span>
417+
<span>操作</span>
396418
</div>
397419
<div
398420
v-for="(item, i) in preview"
@@ -405,8 +427,9 @@ onUnmounted(() => {
405427
<span class="name final">
406428
<ChevronRight class="arrow" :size="14" />
407429
{{ item.finalName }}
408-
<span v-if="item.status !== 'ok'" class="status-tag">{{ statusText(item) }}</span>
409430
</span>
431+
<span class="folder-path" :title="parentDir(files[i].path)">{{ parentDir(files[i].path) }}</span>
432+
<span class="file-status" :title="item.statusDetail">{{ item.status === 'ok' ? '将重命名' : statusText(item) }}</span>
410433
<span class="row-actions">
411434
<button
412435
v-if="item.steps.length"
@@ -448,20 +471,21 @@ onUnmounted(() => {
448471
</template>
449472

450473
<style scoped>
451-
/* 参考 JSON 查看器:整页占满窗口高度,工具栏/底栏固定,双栏各自内部滚动 */
452-
.batch-rename { max-width: 92%; margin: 0 auto; height: 100%; display: flex; flex-direction: column; }
453-
.lead { margin: 0 0 16px; color: var(--fg-muted); flex: 0 0 auto; }
454-
.card { padding: 16px 20px; margin-bottom: 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); }
474+
/* 上方规则、下方文件预览,两个区域独立滚动,工具栏和执行栏固定。 */
475+
.batch-rename { max-width: 96%; margin: 0 auto; height: 100%; display: flex; flex-direction: column; }
476+
.lead { margin: 0 0 12px; color: var(--fg-muted); flex: 0 0 auto; font-size: 13px; }
477+
.card { padding: 12px 16px; margin-bottom: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); }
455478
h3 { margin: 0; font-size: 14px; }
456479
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; flex: 0 0 auto; }
457480
.btn { display: inline-flex; gap: 6px; align-items: center; }
458481
.toolbar-note { color: var(--fg-muted); font-size: 13px; }
459482
.check-inline { display: inline-flex; gap: 5px; align-items: center; font-size: 13px; color: var(--fg-muted); cursor: pointer; user-select: none; }
460483
.btn-outline.danger:hover { border-color: var(--danger); color: var(--danger); }
461-
.workbench { flex: 1 1 auto; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
462-
.columns { display: grid; grid-template-columns: minmax(280px, 2fr) minmax(0, 3fr); gap: 20px; flex: 1 1 auto; min-height: 0; }
463-
.rules-pane { min-width: 0; min-height: 220px; overflow-y: auto; }
464-
.preview-pane { min-width: 0; min-height: 220px; overflow-y: auto; }
484+
.workbench { flex: 1 1 auto; min-height: 0; overflow: hidden; display: flex; flex-direction: column; padding: 0; }
485+
.panes { display: grid; grid-template-rows: minmax(100px, 2fr) minmax(0, 3fr); flex: 1 1 auto; min-height: 0; }
486+
.rules-pane { min-width: 0; min-height: 0; overflow-y: auto; padding: 12px 16px; }
487+
.preview-pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; border-top: 1px solid var(--border); padding: 12px 16px; }
488+
.preview-pane > .pane-head { flex: 0 0 auto; }
465489
.pane-head { position: sticky; top: 0; z-index: 1; display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; padding-bottom: 10px; background: var(--card); }
466490
.pane-head.stacked { flex-direction: column; align-items: stretch; gap: 8px; }
467491
.head-line { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
@@ -471,19 +495,20 @@ h3 { margin: 0; font-size: 14px; }
471495
.sort-btn.active { font-weight: 600; }
472496
.summary { color: var(--fg-muted); font-size: 12px; }
473497
.empty { margin: 8px 0; font-size: 13px; color: var(--fg-muted); }
474-
.rule-slot { margin-bottom: 10px; }
475-
.rule-slot:active { cursor: grabbing; }
476-
.preview-list { border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
477-
.preview-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr) auto; gap: 10px; align-items: start; padding: 8px 12px; border-top: 1px solid var(--border); font-size: 13px; cursor: grab; }
498+
.rule-slot { margin-bottom: 6px; }
499+
.preview-list { border: 1px solid var(--border); border-radius: 6px; overflow-y: auto; min-height: 0; flex: 1 1 auto; }
500+
.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; }
478501
.preview-row:active { cursor: grabbing; }
479-
.preview-row.head-row { border-top: none; background: var(--bg); color: var(--fg-muted); font-size: 12px; cursor: default; }
502+
.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; }
480503
.name { overflow-wrap: anywhere; font: 12px ui-monospace, SFMono-Regular, Consolas, monospace; }
504+
.folder-path { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--fg-muted); font: 12px ui-monospace, SFMono-Regular, Consolas, monospace; }
481505
.final { display: flex; gap: 4px; align-items: baseline; flex-wrap: wrap; }
482506
.arrow { flex: 0 0 auto; align-self: center; color: var(--fg-muted); }
483507
.status-unchanged .final { color: var(--fg-muted); }
484508
.status-conflict-duplicate .final, .status-conflict-exists .final, .status-invalid .final { color: var(--danger); }
485-
.status-tag { padding: 0 6px; border: 1px solid var(--danger); border-radius: 999px; font-size: 11px; }
486-
.status-unchanged .status-tag { border-color: var(--border); }
509+
.file-status { color: var(--fg-muted); font-size: 12px; overflow-wrap: anywhere; }
510+
.status-ok .file-status { color: var(--success); }
511+
.status-conflict-duplicate .file-status, .status-conflict-exists .file-status, .status-invalid .file-status { color: var(--danger); }
487512
.row-actions { display: flex; gap: 8px; }
488513
.link-btn { padding: 0; border: none; background: none; color: var(--primary); font-size: 12px; cursor: pointer; }
489514
.link-btn:hover { text-decoration: underline; }
@@ -497,7 +522,9 @@ h3 { margin: 0; font-size: 14px; }
497522
.exec-error { color: var(--danger); }
498523
.footer-bar { display: flex; gap: 16px; align-items: center; justify-content: space-between; flex: 0 0 auto; margin-bottom: 0; }
499524
.footer-note { font-size: 13px; color: var(--fg-muted); }
500-
@media (max-width: 860px) {
501-
.columns { grid-template-columns: 1fr; }
525+
@media (max-width: 600px) {
526+
.rules-pane, .preview-pane { padding: 10px; }
527+
.preview-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 0.8fr) 64px 60px; gap: 6px; padding: 6px 8px; }
528+
.row-actions { gap: 4px; flex-wrap: wrap; }
502529
}
503530
</style>

0 commit comments

Comments
 (0)