Linux Command命令速查
这是一个使用 Vue 3 + Vite + TypeScript 构建的 ZTools 插件。
-
Hello - 基础功能指令示例
- 触发指令:
你好/hello - 展示简单的 Vue 组件界面
- 触发指令:
-
读文件 - 文件读取功能示例
- 功能指令:
读文件 - 匹配指令:支持拖拽文件触发
- 演示如何使用 Node.js 能力读取文件内容
- 功能指令:
-
保存为文件 - 文件写入功能示例
- 匹配指令:任意文本/图片 →
保存为文件 - 演示如何将剪贴板内容保存为文件
- 匹配指令:任意文本/图片 →
.
├── public/
│ ├── logo.png # 插件图标
│ ├── plugin.json # 插件配置文件
│ └── preload/ # Preload 脚本目录
│ ├── package.json # Preload 依赖配置
│ └── services.js # Node.js 能力扩展
├── src/
│ ├── main.ts # 入口文件
│ ├── main.css # 全局样式
│ ├── App.vue # 根组件
│ ├── env.d.ts # 类型声明
│ ├── Hello/ # Hello 功能组件
│ │ └── index.vue
│ ├── Read/ # 读文件功能组件
│ │ └── index.vue
│ └── Write/ # 写文件功能组件
│ └── index.vue
├── index.html # HTML 模板
├── vite.config.js # Vite 配置
├── tsconfig.json # TypeScript 配置
├── package.json # 项目依赖
└── README.md # 项目文档
npm installnpm run dev开发服务器将在 http://localhost:5173 启动。ZTools 会自动加载开发版本。
npm run build构建产物将输出到 dist/ 目录。
编辑 public/plugin.json 文件:
{
"name": "你的插件名称",
"description": "插件描述",
"author": "作者名称",
"version": "1.0.0",
"features": [
// 添加你的功能配置
]
}在 src/ 目录下创建新的功能组件:
<!-- src/MyFeature/index.vue -->
<template>
<div class="my-feature">
<h1>{{ title }}</h1>
<!-- 你的组件内容 -->
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const title = ref('我的新功能')
</script>
<style scoped>
.my-feature {
padding: 20px;
}
</style>在 src/App.vue 中添加路由:
<script setup lang="ts">
import MyFeature from './MyFeature/index.vue'
const routes = {
hello: Hello,
read: Read,
write: Write,
myfeature: MyFeature // 添加新路由
}
</script>在 plugin.json 中添加功能配置:
{
"code": "myfeature",
"explain": "我的新功能",
"icon": "logo.png",
"cmds": ["触发指令"]
}编辑 public/preload/services.js:
const fs = require('fs')
const path = require('path')
module.exports = {
// 示例:读取文件
readFile: (filePath) => {
return fs.readFileSync(filePath, 'utf-8')
},
// 添加你的服务
myService: (params) => {
// 实现你的逻辑
return result
}
}<script setup lang="ts">
const handleRead = async () => {
try {
const content = await window.services.readFile('/path/to/file')
console.log(content)
} catch (error) {
console.error('读取失败:', error)
}
}
</script><script setup lang="ts">
// 获取剪贴板内容
const text = await window.ztools.getClipboardContent()
// 隐藏主窗口
window.ztools.hideMainWindow()
// 显示提示
window.ztools.showTip('操作成功')
// 更多 API 请参考官方文档
</script>ZTools 提供了一套 CSS 变量用于主题适配:
.my-component {
background: var(--bg-color);
color: var(--text-color);
border: 1px solid var(--border-color);
}@media (prefers-color-scheme: dark) {
.my-component {
/* 暗色模式样式 */
}
}npm run build将 dist/ 目录中的所有文件复制到 ZTools 插件目录进行测试。
- 确保
plugin.json中的信息完整准确 - 准备好插件截图和详细说明
- 访问 ZTools 插件市场提交插件
A: 使用 npm run dev 启动开发服务器,在插件界面中点击插件头像图标,在弹出的菜单中选择"打开开发者工具"进行调试。
A: 通过 public/preload/services.js 文件扩展服务,然后在组件中使用 window.services 调用。
A: 确保 public/logo.png 文件存在,且在 plugin.json 中正确配置了 logo 字段。
A: 建议使用 Node.js 流式处理,在 preload 脚本中实现文件分块处理逻辑。
MIT License