开发指南
开发环境搭建
系统要求
- 操作系统: macOS / Windows / Linux
- Node.js: >= 18.0.0
- 包管理器: npm >= 9.0.0 或 pnpm >= 8.0.0
- Git: >= 2.30.0
推荐工具
- IDE: VSCode / WebStorm
- 浏览器: Chrome / Edge / Safari(最新版)
- 移动端调试: Chrome DevTools / Safari DevTools
项目架构
技术栈
| 层级 | 技术 |
|---|---|
| 前端框架 | Vue 3 + TypeScript |
| 状态管理 | Pinia |
| 路由 | Vue Router |
| UI 组件 | Ant Design Vue + 自研组件库 |
| 构建工具 | Vite |
| 移动端 | UniApp / Taro |
| 桌面端 | Electron |
| 服务端 | Node.js / Java (Spring Boot) |
| 数据库 | MySQL / Redis / Elasticsearch |
| 消息队列 | RabbitMQ / Kafka |
| AI 引擎 | OpenAI / DeepSeek / Qwen |
目录结构
solinkcrm/
├── apps/ # 应用层
│ ├── mobile/ # 移动端(UniApp)
│ ├── desktop/ # 桌面端(Electron)
│ ├── web/ # Web 端
│ └── miniapp/ # 小程序
├── packages/ # 共享包
│ ├── sdk/ # CRM SDK
│ ├── ui/ # UI 组件库
│ ├── shared/ # 共享工具
│ └── types/ # 类型定义
├── server/ # 服务端
│ ├── gateway/ # API 网关
│ ├── crm/ # CRM 核心服务
│ ├── social/ # 社交连接服务
│ ├── ai/ # AI 智能引擎
│ └── message/ # 消息服务
├── docs/ # 文档
└── scripts/ # 脚本工具开发规范
代码规范
- 使用 ESLint + Prettier 进行代码格式化
- 遵循 Vue 3 组合式 API 风格
- TypeScript 严格模式启用
- 组件命名使用 PascalCase
- 函数命名使用 camelCase
Git 规范
类型(scope): 简短描述
详细描述(可选)
Footer(可选)类型说明:
feat: 新功能fix: 修复docs: 文档style: 格式refactor: 重构perf: 性能优化test: 测试chore: 构建/工具
示例:
feat(crm): 添加社交客户画像功能
- 支持社交标签自动打标
- 支持社交影响力评分
- 添加社交关系图谱可视化
Closes #123分支管理
main: 主分支,稳定版本develop: 开发分支feature/*: 功能分支hotfix/*: 紧急修复release/*: 发布分支
模块开发
SDK 开发
typescript
// packages/sdk/src/core/client.ts
export class CrmClient {
private http: HttpClient
private options: ClientOptions
private eventEmitter: EventEmitter
constructor(options: ClientOptions) {
this.options = options
this.http = new HttpClient(options.apiBaseUrl)
this.eventEmitter = new EventEmitter()
}
async connect(): Promise<void> {
const token = await this.http.post('/auth/login', {
appKey: this.options.appKey
})
this.http.setToken(token)
this.eventEmitter.emit('connect')
}
async createLead(data: LeadData): Promise<Lead> {
return this.http.post('/leads', data)
}
async queryLeads(params: LeadQueryParams): Promise<Lead[]> {
return this.http.get('/leads', params)
}
}UI 组件开发
vue
<!-- packages/ui/src/components/CustomerCard.vue -->
<template>
<div class="customer-card" :class="{ 'is-vip': isVip }">
<Avatar :src="avatar" />
<div class="info">
<div class="name">{{ name }}</div>
<div class="tags">
<Tag v-for="tag in tags" :key="tag" size="small">{{ tag }}</Tag>
</div>
<div class="meta">
<span>{{ industry }}</span>
<span>{{ level }}</span>
</div>
</div>
<div class="actions">
<slot name="actions" />
</div>
</div>
</template>
<script setup lang="ts">
interface Props {
name: string
avatar: string
tags: string[]
industry: string
level: string
isVip: boolean
}
defineProps<Props>()
</script>页面开发
vue
<!-- apps/web/src/views/customer/detail.vue -->
<template>
<div class="customer-detail">
<PageHeader :title="customer.name" />
<CustomerProfile :customer="customer" />
<SocialTimeline :activities="socialActivities" />
<OpportunityList :opportunities="opportunities" />
<FollowUpHistory :records="followUpRecords" />
</div>
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import { useCustomerStore } from '@/stores/customer'
const route = useRoute()
const customerStore = useCustomerStore()
const customer = ref<Customer>({})
const socialActivities = ref([])
const opportunities = ref([])
const followUpRecords = ref([])
onMounted(async () => {
const id = route.params.id as string
await customerStore.loadCustomer(id)
customer.value = customerStore.current
socialActivities.value = await customerStore.loadSocialActivities(id)
opportunities.value = await customerStore.loadOpportunities(id)
followUpRecords.value = await customerStore.loadFollowUpRecords(id)
})
</script>调试技巧
Web 端调试
- Vue DevTools: 安装浏览器扩展
- Network: 查看 API 请求与响应
- Console: 查看 SDK 日志输出
移动端调试
bash
# H5 调试
npm run dev:h5
# 微信小程序调试
npm run dev:mp-weixin
# APP 调试
npm run dev:app桌面端调试
bash
# 开发模式
npm run dev:desktop
# 调试主进程
npm run debug:main
# 调试渲染进程
npm run debug:renderer测试
单元测试
bash
# 运行所有测试
npm run test
# 运行指定模块测试
npm run test -- packages/sdk
# 覆盖率报告
npm run test:coverageE2E 测试
bash
# 运行 E2E 测试
npm run test:e2e
# headed 模式
npm run test:e2e -- --headed性能优化
前端优化
- 虚拟列表: 大数据量客户列表使用虚拟滚动
- 图片懒加载: 客户头像和社交动态图片懒加载
- 数据分页: 列表数据分页加载
- 缓存策略: 客户详情等热点数据本地缓存
服务端优化
- 连接池: 数据库连接池管理
- 缓存策略: Redis 缓存热点数据
- 消息队列: 社交消息异步处理
- 分库分表: 大数据量水平拆分
部署
Docker 部署
bash
# 构建镜像
docker build -t solinkcrm:latest .
# 运行容器
docker run -d -p 8080:8080 solinkcrm:latestKubernetes 部署
bash
# 应用配置
kubectl apply -f k8s/
# 查看状态
kubectl get pods -n solinkcrm常见问题
Q: 微信生态接入配置失败?
A: 检查:
- AppID 和 AppSecret 是否正确
- 回调地址是否已配置白名单
- 服务器 IP 是否已加入公众号安全域名
Q: AI 大模型调用超时?
A: 检查:
- API Key 是否有效
- 网络是否可访问模型服务
- 请求参数是否超出模型限制
Q: 社交消息同步延迟?
A: 检查:
- Webhook 回调是否正常
- 消息队列是否积压
- 社交平台 API 限流情况