feat(tauri): 添加自定义标题栏和窗口控制功能
- 在布局中引入 Header 组件并渲染 - 设置页面 SSR 为 false 并启用预渲染 - 更新应用 CSS 样式,设置背景色和尺寸- 配置 Tauri 权限以支持窗口操作 - 新增 Header 组件实现窗口最小化、最大化和关闭功能- 安装 @tauri-apps/api 依赖并更新 package.json 和 lock 文件 - 修改 README 内容为 IT Tools项目简介 - 更新 Tauri 配置文件中的产品标识和构建路径
This commit is contained in:
38
README.md
38
README.md
@@ -1,38 +1,2 @@
|
|||||||
# sv
|
# IT Tools
|
||||||
|
|
||||||
Everything you need to build a Svelte project, powered by [`sv`](https://github.com/sveltejs/cli).
|
|
||||||
|
|
||||||
## Creating a project
|
|
||||||
|
|
||||||
If you're seeing this, you've probably already done this step. Congrats!
|
|
||||||
|
|
||||||
```sh
|
|
||||||
# create a new project in the current directory
|
|
||||||
npx sv create
|
|
||||||
|
|
||||||
# create a new project in my-app
|
|
||||||
npx sv create my-app
|
|
||||||
```
|
|
||||||
|
|
||||||
## Developing
|
|
||||||
|
|
||||||
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
npm run dev
|
|
||||||
|
|
||||||
# or start the server and open the app in a new browser tab
|
|
||||||
npm run dev -- --open
|
|
||||||
```
|
|
||||||
|
|
||||||
## Building
|
|
||||||
|
|
||||||
To create a production version of your app:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
npm run build
|
|
||||||
```
|
|
||||||
|
|
||||||
You can preview the production build with `npm run preview`.
|
|
||||||
|
|
||||||
> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.
|
|
||||||
|
|||||||
13
package-lock.json
generated
13
package-lock.json
generated
@@ -7,6 +7,9 @@
|
|||||||
"": {
|
"": {
|
||||||
"name": "it-tools",
|
"name": "it-tools",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
|
"dependencies": {
|
||||||
|
"@tauri-apps/api": "^2.9.0"
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@sveltejs/adapter-static": "^3.0.10",
|
"@sveltejs/adapter-static": "^3.0.10",
|
||||||
"@sveltejs/kit": "^2.47.1",
|
"@sveltejs/kit": "^2.47.1",
|
||||||
@@ -1209,6 +1212,16 @@
|
|||||||
"vite": "^5.2.0 || ^6 || ^7"
|
"vite": "^5.2.0 || ^6 || ^7"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@tauri-apps/api": {
|
||||||
|
"version": "2.9.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/@tauri-apps/api/-/api-2.9.0.tgz",
|
||||||
|
"integrity": "sha512-qD5tMjh7utwBk9/5PrTA/aGr3i5QaJ/Mlt7p8NilQ45WgbifUNPyKWsA63iQ8YfQq6R8ajMapU+/Q8nMcPRLNw==",
|
||||||
|
"license": "Apache-2.0 OR MIT",
|
||||||
|
"funding": {
|
||||||
|
"type": "opencollective",
|
||||||
|
"url": "https://opencollective.com/tauri"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@tauri-apps/cli": {
|
"node_modules/@tauri-apps/cli": {
|
||||||
"version": "2.9.2",
|
"version": "2.9.2",
|
||||||
"resolved": "https://registry.npmmirror.com/@tauri-apps/cli/-/cli-2.9.2.tgz",
|
"resolved": "https://registry.npmmirror.com/@tauri-apps/cli/-/cli-2.9.2.tgz",
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"tauri": "tauri",
|
"tauri": "tauri",
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
@@ -28,5 +28,8 @@
|
|||||||
"tailwindcss": "^4.1.14",
|
"tailwindcss": "^4.1.14",
|
||||||
"typescript": "^5.9.3",
|
"typescript": "^5.9.3",
|
||||||
"vite": "^7.1.10"
|
"vite": "^7.1.10"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@tauri-apps/api": "^2.9.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,12 @@
|
|||||||
"main"
|
"main"
|
||||||
],
|
],
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"core:default"
|
"core:default",
|
||||||
|
"core:window:allow-close",
|
||||||
|
"core:window:allow-minimize",
|
||||||
|
"core:window:allow-maximize",
|
||||||
|
"core:window:allow-unmaximize",
|
||||||
|
"core:window:allow-toggle-maximize",
|
||||||
|
"core:window:allow-start-dragging"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
"$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
|
"$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
|
||||||
"productName": "it-tools",
|
"productName": "it-tools",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"identifier": "com.tauri.dev",
|
"identifier": "cn.nopj.ittools",
|
||||||
"build": {
|
"build": {
|
||||||
"frontendDist": "../public",
|
"frontendDist": "../src",
|
||||||
"devUrl": "http://localhost:5173",
|
"devUrl": "http://localhost:5173",
|
||||||
"beforeDevCommand": "npm run dev",
|
"beforeDevCommand": "npm run dev",
|
||||||
"beforeBuildCommand": "npm run build"
|
"beforeBuildCommand": "npm run build"
|
||||||
@@ -35,4 +35,5 @@
|
|||||||
"icons/icon.ico"
|
"icons/icon.ico"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1,10 @@
|
|||||||
@import 'tailwindcss';
|
@import 'tailwindcss';
|
||||||
|
|
||||||
|
|
||||||
|
:global(body) {
|
||||||
|
|
||||||
|
background-color: #1f1f1f; /* 示例:一个深灰色 */
|
||||||
|
min-height: 100vh;
|
||||||
|
min-width: 100vw;
|
||||||
|
margin: 0; /* 移除浏览器默认的 body 边距 */
|
||||||
|
}
|
||||||
1
src/lib/assets/icon/close.svg
Normal file
1
src/lib/assets/icon/close.svg
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" d="m13.414 12l3.293-3.293a1 1 0 0 0-1.414-1.414L12 10.586L8.707 7.293a1 1 0 0 0-1.414 1.414L10.586 12l-3.293 3.293a1 1 0 0 0 1.414 1.414L12 13.414l3.293 3.293a1 1 0 0 0 1.414-1.414Z"/><path fill="currentColor" d="M19.07 4.93A10 10 0 1 0 4.93 19.07A10 10 0 1 0 19.07 4.93m-2.363 10.363a1 1 0 1 1-1.414 1.414L12 13.414l-3.293 3.293a1 1 0 0 1-1.414-1.414L10.586 12L7.293 8.707a1 1 0 0 1 1.414-1.414L12 10.586l3.293-3.293a1 1 0 0 1 1.414 1.414L13.414 12Z" opacity="0.5"/></svg>
|
||||||
|
After Width: | Height: | Size: 582 B |
59
src/lib/components/layout/Header.svelte
Normal file
59
src/lib/components/layout/Header.svelte
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { getCurrentWindow } from '@tauri-apps/api/window';
|
||||||
|
import {onMount} from 'svelte';
|
||||||
|
|
||||||
|
const win = getCurrentWindow();
|
||||||
|
|
||||||
|
let isMax = false;
|
||||||
|
|
||||||
|
|
||||||
|
const minimize = () => win.minimize();
|
||||||
|
const closeWindow = () => win.close();
|
||||||
|
const maximize = () => win.toggleMaximize();
|
||||||
|
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
// 1. 获取初始状态
|
||||||
|
isMax = await win.isMaximized();
|
||||||
|
|
||||||
|
// 2. 使用 onResized 更稳定(而不是 tauri://resize)
|
||||||
|
const unlisten = await win.onResized(async () => {
|
||||||
|
isMax = await win.isMaximized();
|
||||||
|
});
|
||||||
|
|
||||||
|
// 3. 返回清理函数
|
||||||
|
return () => unlisten();
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<header class="custom-titlebar" data-tauri-drag-region>
|
||||||
|
<div class="app-title" data-tauri-drag-region>
|
||||||
|
🎉 我的Tauri Svelte应用
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="window-controls">
|
||||||
|
<button data-tauri-drag-region="false" class="h-btn" on:click={minimize}>最小化</button>
|
||||||
|
<button data-tauri-drag-region="false" class="h-btn" on:click={maximize}>{ isMax?'取消最大化':'最大化'}</button>
|
||||||
|
<button data-tauri-drag-region="false" class="h-btn btn-close" on:click={closeWindow}>关闭</button>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.custom-titlebar {
|
||||||
|
height: 30px;
|
||||||
|
background-color: #333;
|
||||||
|
color: white;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: 0 10px;
|
||||||
|
user-select: none;
|
||||||
|
position: sticky;
|
||||||
|
top: 0;
|
||||||
|
z-index: 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</style>
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import '../app.css';
|
import '../app.css';
|
||||||
import favicon from '$lib/assets/favicon.svg';
|
import favicon from '$lib/assets/favicon.svg';
|
||||||
|
import Header from '$lib/components/layout/Header.svelte';
|
||||||
|
|
||||||
let { children } = $props();
|
let { children } = $props();
|
||||||
</script>
|
</script>
|
||||||
@@ -8,5 +9,6 @@
|
|||||||
<svelte:head>
|
<svelte:head>
|
||||||
<link rel="icon" href={favicon} />
|
<link rel="icon" href={favicon} />
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
<Header/>
|
||||||
|
|
||||||
{@render children()}
|
{@render children()}
|
||||||
|
|||||||
2
src/routes/+layout.ts
Normal file
2
src/routes/+layout.ts
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
export const ssr = false;
|
||||||
|
export const prerender = true;
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<div>
|
<div>
|
||||||
<h1>123{title}</h1>
|
<h1>112323{title}</h1>
|
||||||
<p>{description}</p>
|
<p>{description}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user