Skip to content

Commit d8b4688

Browse files
author
linyuan.yang
committed
引入 uikit
1 parent ca7223d commit d8b4688

13 files changed

Lines changed: 328 additions & 89 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@
55
### 新增
66

77
- 新增批量重命名工具:可添加文件(支持拖入窗口与选择文件夹),按顺序叠加多条规则(搜索替换、插入文本、序号编号、大小写转换、删除)实时预览最终文件名,支持逐步预览、规则拖拽排序与冲突检测后一键执行。
8+
- 批量重命名添加文件夹时支持「包含子文件夹」,勾选后递归收集所有子文件夹中的文件。
9+
10+
### 优化
11+
12+
- 引入 @qingfeng346/ui-kit 组件库(65 个组件,零第三方依赖,link 引用 e:/ui-kit 仓库):提供设计令牌、明暗主题、表单 / 列表 / 表格 / 拖拽排序 / toast / 确认弹窗等基础组件;主题变量已与现有页面桥接,主界面挂载全局反馈宿主,后续工具页逐步迁移复用。
13+
- 优化批量重命名页面布局:参考 JSON 查看器自适应窗口高度,工具栏与底部执行栏固定,规则区和预览区在窗口内独立滚动,不再整页拉伸。
14+
- 批量重命名文件列表支持拖动行手动调整顺序,并可按名称、大小、创建时间、修改时间一键排序(再次点击切换升 / 降序)。
15+
16+
### 修复
17+
18+
- 修复批量重命名规则卡片拖拽排序失效的问题:Windows 上 Tauri 接管了 WebView2 的原生拖放处理导致 HTML5 拖放的放置事件不触发,现改为 pointer 事件手动换位实现,规则与文件行拖拽排序均不受影响。
19+
20+
### 修复
21+
22+
- 修复批量重命名搜索替换勾选「同时作用于扩展名」时,查找内容带前导点(如 `.js`)无法命中扩展名的问题。
823

924
## 0.0.9
1025

‎packages/app/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"linux:build": "tauri build"
1313
},
1414
"dependencies": {
15+
"@qingfeng346/ui-kit": "link:../../../ui-kit/ui-kit",
1516
"@sbox/tools-core": "workspace:*",
1617
"@tauri-apps/api": "^2.11.0",
1718
"@tauri-apps/plugin-clipboard-manager": "^2.3.2",

‎packages/app/src-tauri/src/lib.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ pub fn run() {
6666
tools::file_locks::file_locks_check,
6767
tools::batch_rename::batch_rename_list_dir,
6868
tools::batch_rename::batch_rename_is_dir,
69+
tools::batch_rename::batch_rename_stat,
6970
tools::batch_rename::batch_rename_execute,
7071
tools::port_check::port_check_list,
7172
tools::port_check::port_check_kill,

‎packages/app/src-tauri/src/tools/batch_rename/mod.rs‎

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,54 @@ pub struct RenameBatchResult {
3434
pub failed: usize,
3535
}
3636

37+
/// 文件元数据,供前端按大小/时间排序。时间戳为 Unix 毫秒,取不到(平台不支持等)为 null。
38+
#[derive(Serialize)]
39+
#[serde(rename_all = "camelCase")]
40+
pub struct FileMeta {
41+
pub size: u64,
42+
pub created_ms: Option<i64>,
43+
pub modified_ms: Option<i64>,
44+
}
45+
46+
/// 批量获取文件元数据,与入参顺序一一对应,单个失败对应项为 null。
47+
#[tauri::command(rename_all = "camelCase")]
48+
pub async fn batch_rename_stat(paths: Vec<String>) -> Result<Vec<Option<FileMeta>>, String> {
49+
tauri::async_runtime::spawn_blocking(move || {
50+
Ok(paths.iter().map(|path| stat_one(path)).collect())
51+
})
52+
.await
53+
.map_err(|error| format!("读取文件信息任务失败: {error}"))?
54+
}
55+
56+
fn stat_one(path: &str) -> Option<FileMeta> {
57+
let meta = std::fs::metadata(path).ok()?;
58+
let to_ms = |time: std::io::Result<std::time::SystemTime>| {
59+
time.ok()?
60+
.duration_since(std::time::UNIX_EPOCH)
61+
.ok()
62+
.map(|d| d.as_millis() as i64)
63+
};
64+
Some(FileMeta {
65+
size: meta.len(),
66+
created_ms: to_ms(meta.created()),
67+
modified_ms: to_ms(meta.modified()),
68+
})
69+
}
70+
3771
/// 判断路径是否为文件夹(拖拽进来的路径需要过滤掉目录)。
3872
#[tauri::command(rename_all = "camelCase")]
3973
pub async fn batch_rename_is_dir(path: String) -> Result<bool, String> {
4074
Ok(std::path::Path::new(&path).is_dir())
4175
}
4276

43-
/// 列出文件夹的直接子项(含子目录,不递归),按文件名排序。
77+
/// 列出文件夹的直接子项(recursive=true 时递归收集所有文件,不含子目录),按路径排序。
4478
#[tauri::command(rename_all = "camelCase")]
45-
pub async fn batch_rename_list_dir(path: String) -> Result<Vec<DirEntry>, String> {
46-
tauri::async_runtime::spawn_blocking(move || list_dir(path))
47-
.await
48-
.map_err(|error| format!("读取文件夹任务失败: {error}"))?
79+
pub async fn batch_rename_list_dir(path: String, recursive: bool) -> Result<Vec<DirEntry>, String> {
80+
tauri::async_runtime::spawn_blocking(move || {
81+
if recursive { walk_dir(path) } else { list_dir(path) }
82+
})
83+
.await
84+
.map_err(|error| format!("读取文件夹任务失败: {error}"))?
4985
}
5086

5187
fn list_dir(path: String) -> Result<Vec<DirEntry>, String> {
@@ -67,6 +103,37 @@ fn list_dir(path: String) -> Result<Vec<DirEntry>, String> {
67103
Ok(items)
68104
}
69105

106+
/// 递归收集文件夹下所有文件(不含子目录条目)。DirEntry::file_type 不跟随符号链接,
107+
/// 因此软链目录不会被展开,天然避免循环。
108+
fn walk_dir(path: String) -> Result<Vec<DirEntry>, String> {
109+
let mut items: Vec<DirEntry> = Vec::new();
110+
let mut stack = vec![std::path::PathBuf::from(&path)];
111+
while let Some(dir) = stack.pop() {
112+
let entries = match std::fs::read_dir(&dir) {
113+
Ok(entries) => entries,
114+
// 单个子目录读取失败(权限等)不中断整体,跳过继续
115+
Err(_) => continue,
116+
};
117+
for entry in entries.flatten() {
118+
let is_dir = entry.file_type().map(|t| t.is_dir()).unwrap_or(false);
119+
if is_dir {
120+
stack.push(entry.path());
121+
} else {
122+
items.push(DirEntry {
123+
path: entry.path().to_string_lossy().to_string(),
124+
name: entry.file_name().to_string_lossy().to_string(),
125+
is_dir,
126+
});
127+
}
128+
}
129+
}
130+
if items.is_empty() {
131+
return Err(format!("文件夹为空或无法读取内容: {path}"));
132+
}
133+
items.sort_by(|a, b| a.path.to_lowercase().cmp(&b.path.to_lowercase()));
134+
Ok(items)
135+
}
136+
70137
/// 批量执行重命名。逐项独立处理,单项失败不中断批次;整体只在参数为空时报错。
71138
#[tauri::command(rename_all = "camelCase")]
72139
pub async fn batch_rename_execute(items: Vec<RenameRequestItem>) -> Result<RenameBatchResult, String> {

‎packages/app/src/App.vue‎

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { listen } from '@tauri-apps/api/event'
1010
import { getCurrentWindow } from '@tauri-apps/api/window'
1111
import { UpdaterDialog } from '@while-coder/tauri-updater-vue'
1212
import { toolNavGroups } from '@sbox/tools-core'
13+
// 深路径按需导入:从包入口导入会把全部组件拖进主包(SFC tree-shake 不可靠)
14+
import SMessageHost from '@qingfeng346/ui-kit/components/SMessageHost.vue'
1315
import { ALL_TOOLS } from './shell/registry'
1416
import { loadSettings } from './shell/settings'
1517
import { setupCloseToTray, applyBossKey, watchBossKey, refreshAutostart } from './shell/system'
@@ -120,35 +122,12 @@ onUnmounted(() => {
120122
</main>
121123
</section>
122124
<UpdaterDialog />
125+
<!-- toast / confirm / loading 的全局渲染宿主(@qingfeng346/ui-kit 的反馈类组合式函数) -->
126+
<SMessageHost />
123127
</div>
124128
</template>
125129

126130
<style>
127-
:root {
128-
--fg: #1a1a1a;
129-
--fg-muted: #666;
130-
--bg: #f8f8f8;
131-
--card: #fff;
132-
--border: #e5e5e5;
133-
--primary: #2d6cdf;
134-
--primary-hover: #1f56b8;
135-
--success: #2da44e;
136-
--danger: #cf222e;
137-
--radius: 8px;
138-
}
139-
@media (prefers-color-scheme: dark) {
140-
:root {
141-
--fg: #e5e5e5;
142-
--fg-muted: #999;
143-
--bg: #1a1a1a;
144-
--card: #242424;
145-
--border: #333;
146-
}
147-
}
148-
* { box-sizing: border-box; }
149-
html, body, #app { height: 100%; margin: 0; }
150-
body { font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif; color: var(--fg); background: var(--bg); }
151-
152131
.app-shell { display: flex; height: 100%; min-width: 0; overflow: hidden; }
153132
.sidebar {
154133
display: flex; flex: 0 0 252px; flex-direction: column; min-width: 0;

‎packages/app/src/main.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createApp } from 'vue'
22
import { setPlatform } from '@sbox/tools-core'
3+
import '@qingfeng346/ui-kit/style.css'
34
import '@sbox/tools-core/theme.css'
45
import App from './App.vue'
56
import router from './shell/router'
@@ -8,6 +9,14 @@ import { tauriPlatform } from './platform/platform-tauri'
89

910
setupLogger()
1011

12+
// ui-kit 暗色令牌跟随系统(theme-dark.css 以 html[data-theme="dark"] 生效)
13+
const applyColorScheme = () => {
14+
document.documentElement.dataset.theme
15+
= window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
16+
}
17+
applyColorScheme()
18+
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', applyColorScheme)
19+
1120
// 注入 Tauri 平台实现(落盘 = 保存对话框 + Rust 写文件)
1221
setPlatform(tauriPlatform)
1322

0 commit comments

Comments
 (0)