create-tauri-vue-app 0.0.8 → 0.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
CHANGED
package/template/CLAUDE.md
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
# 前端编码规范
|
|
2
|
+
|
|
2
3
|
1. 尽量复用 element plus 组件进行 UI 开发
|
|
3
4
|
2. 页面开发要尽量分模块,不要全部写到一个 Vue 文件里面
|
|
4
5
|
|
|
5
6
|
# 后端编码规范
|
|
7
|
+
|
|
6
8
|
1. 写 Tauri Command 的时候要根据功能的相关性拆分到不同的文件里面,不要全部写到 lib.rs
|
|
7
|
-
2.
|
|
8
|
-
3.
|
|
9
|
+
2. 每次完成一个后端功能后,都要写相关的 rust 单元测试
|
|
10
|
+
3. 每次的所有 SQL 修改放到一个 version 里面,不要一张表一个 version
|
|
11
|
+
4. 在写 Tauri Command 的时候,都采用 async 的写法,防止阻塞主线程
|
|
12
|
+
5. 每个功能都要添加对应的日志输出
|
|
13
|
+
|
|
14
|
+
# 表设计
|
|
15
|
+
|
|
16
|
+
1. 时间字段默认用 datetime
|
|
17
|
+
|
|
18
|
+
# 跨平台
|
|
19
|
+
|
|
20
|
+
1. 后端开发尽量不要使用平台相关的命令行工具,而应该使用 Rust 跨平台的库来实现对应的逻辑
|
|
21
|
+
2. 指定目录时不要用 `~` 指定用户目录,用 path.homeDir() 进行拼接
|
package/template/src/utils/db.js
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import Database from '@tauri-apps/plugin-sql'
|
|
2
|
+
import { path } from '@tauri-apps/api'
|
|
2
3
|
|
|
3
4
|
let db = null
|
|
4
5
|
|
|
5
6
|
export async function getDb() {
|
|
6
7
|
if (!db) {
|
|
7
|
-
|
|
8
|
+
const home = await path.homeDir();
|
|
9
|
+
// 分层拼接,自动适配 / 和 \
|
|
10
|
+
const dbDir = await path.join(home, '.{{PROJECT_NAME}}');
|
|
11
|
+
const dbFilePath = await path.join(dbDir, 'app.db');
|
|
12
|
+
// sqlite 连接串格式:sqlite:完整本地路径
|
|
13
|
+
const dbUrl = `sqlite:${dbFilePath}`;
|
|
14
|
+
db = await Database.load(dbUrl);
|
|
8
15
|
}
|
|
9
|
-
return db
|
|
16
|
+
return db;
|
|
10
17
|
}
|
|
11
18
|
|
|
12
19
|
// CRUD operations for tasks
|
|
@@ -42,4 +49,4 @@ export async function toggleTask(id, completed) {
|
|
|
42
49
|
'UPDATE tasks SET completed = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?',
|
|
43
50
|
[completed ? 1 : 0, id]
|
|
44
51
|
)
|
|
45
|
-
}
|
|
52
|
+
}
|
|
@@ -1,18 +1,34 @@
|
|
|
1
1
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
|
2
2
|
use tauri_plugin_sql::{Migration, MigrationKind};
|
|
3
|
+
use tauri_plugin_log::{Target, TargetKind};
|
|
3
4
|
|
|
4
5
|
pub fn run() {
|
|
6
|
+
|
|
7
|
+
let app_dir = {
|
|
8
|
+
let home = dirs::home_dir().expect("failed to get home directory");
|
|
9
|
+
let dir = home.join(".{{PROJECT_NAME}}").join("app");
|
|
10
|
+
std::fs::create_dir_all(&dir).expect("failed to create app directory");
|
|
11
|
+
dir
|
|
12
|
+
};
|
|
13
|
+
let log_path = app_dir.join("app.log").to_string_lossy().to_string();
|
|
14
|
+
let db_path = format!("sqlite:{}", app_dir.join("app.db").to_string_lossy());
|
|
15
|
+
|
|
5
16
|
tauri::Builder::default()
|
|
6
17
|
.plugin(
|
|
7
18
|
tauri_plugin_log::Builder::default()
|
|
8
|
-
|
|
9
|
-
|
|
19
|
+
.level(log::LevelFilter::Info)
|
|
20
|
+
.targets([
|
|
21
|
+
Target::new(TargetKind::Stdout),
|
|
22
|
+
Target::new(TargetKind::LogDir { file_name: Some(log_path)}),
|
|
23
|
+
Target::new(TargetKind::Webview),
|
|
24
|
+
])
|
|
25
|
+
.build(),
|
|
10
26
|
)
|
|
11
27
|
.plugin(tauri_plugin_shell::init())
|
|
12
28
|
.plugin(
|
|
13
29
|
tauri_plugin_sql::Builder::default()
|
|
14
30
|
.add_migrations(
|
|
15
|
-
|
|
31
|
+
&db_path,
|
|
16
32
|
vec![
|
|
17
33
|
Migration {
|
|
18
34
|
version: 1,
|