work-order-monitor/.claude/CLAUDE.md

125 lines
4.3 KiB
Markdown
Raw Normal View History

2026-03-31 17:08:30 +08:00
# CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
## 项目概述
这是一个基于 **Tauri 2.x + Vue 3** 的工单监测桌面应用,用于监测 CRM 系统crm.yunvip123.com的待处理工单并发送系统通知。
## 常用命令
项目使用 **pnpm** 作为包管理器。
```bash
# 启动开发模式(前端 + Tauri
pnpm run tauri-dev
# 仅启动前端开发服务器
pnpm run dev
# 前端类型检查 + 构建
pnpm run build
# 构建 Tauri 生产版本(含签名/安装包)
pnpm run tauri-build
# 构建并发布
pnpm run deploy
# 版本号管理(默认 patch
pnpm run version # patch
pnpm run version:minor
pnpm run version:major
# 代码检查
pnpm run lint
pnpm run lint:fix
# 规范提交commitizen + cz-git
pnpm run commit
# Rust 后端检查
cd src-tauri && cargo check
cd src-tauri && cargo clippy
```
## 架构概述
**前端驱动架构**所有业务逻辑API 调用、定时任务、通知)都在 Vue 前端实现Rust 后端仅负责系统级功能(窗口管理、插件注册)。
### 前端分层src/
**StoresPinia**
- `stores/monitor.ts` — 核心业务:登录、轮询检查工单、推迟/暂停逻辑、托盘联动
- `stores/app.ts` — 全局配置(轮询间隔、自启动、静默启动等),配置持久化到 `localStorage`key: `crm_config`
- `stores/log.ts` — 运行日志管理
- `stores/network.ts` — 网络状态检测
**Composables**
- `composables/useNotification.ts` — 系统通知封装(`tauri-plugin-notification`
- `composables/useTray.ts` — 系统托盘创建、图标/菜单动态更新
- `composables/useUpdater.ts` — 应用自动更新(`tauri-plugin-updater`
- `composables/useMonitor.ts` — 监测相关辅助逻辑
**Constants**
- `constants/api.ts` — 所有 API URL 集中定义(`LOGIN_URL`、`CHECK_URL`、`WORK_ORDER_URL`
- `constants/app.ts` — 应用级常量
**Utils**
- `utils/storage.ts` — localStorage 读写封装
- `utils/common.ts` — 通用工具函数(`formatTime` 等)
### Rust 后端src-tauri/src/
- `lib.rs` — 应用初始化、插件注册、窗口关闭事件处理(关闭→隐藏到托盘,发出 `close-requested` 事件)
### 关键数据流
1. `App.vue` 初始化:加载配置 → 加载凭据 → 初始化托盘 → 监听通知动作事件 + 关闭事件
2. `monitorStore.startMonitoring()` 执行登录(密码或 Token 模式),成功后启动 `setInterval` 轮询
3. 工单有待处理项时调用 `useNotification.notify()`,通知动作(推迟/去处理)通过 Tauri 事件回传
4. 托盘图标/菜单通过 `watch([isMonitoring, isPostponed, ticketCounts])` 自动同步
### API 集成
- 登录:`POST https://crm.yunvip123.com/api/SystemUser/Login`
- 工单查询:`GET https://crm.yunvip123.com/api/DemandManage/QueryIndexCount`
- 认证方式:登录响应 `set-cookie` 中提取 `ASP.NET_SessionId`,后续请求携带
- HTTP 白名单配置在 `src-tauri/capabilities/default.json`
### 通知触发条件
`PendingCount`(待处理)、`StaycloseCount`(待关闭)、`ConfirmCount`(待确认)任意 > 0 时触发。
## 代码规范
- Vue 组件使用 `<script setup lang="ts">` + `<style lang="scss" scoped>`
- 方法定义优先使用 `function` 关键字(而非箭头函数赋值)
- `props` 尽量提供 `default` 默认值;在 `script` 中使用 `props` 时通过 `toRefs(props)` 解构
- 新增成员变量和方法须加注释
## 关键配置文件
- `src-tauri/capabilities/default.json` — Tauri 权限配置HTTP 白名单、插件权限)
- `src-tauri/tauri.conf.json` — 应用配置窗口、图标、bundle、updater 端点)
- `.env` / `.env.development` / `.env.production` — 环境变量
- `vite.config.ts` — Vite 配置,开发服务器端口 1420HMR 端口 1421
## 依赖的 Tauri 插件
- `tauri-plugin-http` — HTTP 请求
- `tauri-plugin-notification` — 系统通知
- `tauri-plugin-autostart` — 开机自启动
- `tauri-plugin-opener` — 打开外部链接
- `tauri-plugin-updater` — 应用自动更新
- `tauri-plugin-store` — 持久化存储
- `tauri-plugin-process` — 进程控制
## Windows 编译要求
需要安装 Visual Studio Build Tools包含 C++ 工具链)才能编译 Rust 后端。