Skip to content

开发指南

开发环境搭建

系统要求

  • 操作系统: 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 端调试

  1. Vue DevTools: 安装浏览器扩展
  2. Network: 查看 API 请求与响应
  3. 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:coverage

E2E 测试

bash
# 运行 E2E 测试
npm run test:e2e

# headed 模式
npm run test:e2e -- --headed

性能优化

前端优化

  1. 虚拟列表: 大数据量客户列表使用虚拟滚动
  2. 图片懒加载: 客户头像和社交动态图片懒加载
  3. 数据分页: 列表数据分页加载
  4. 缓存策略: 客户详情等热点数据本地缓存

服务端优化

  1. 连接池: 数据库连接池管理
  2. 缓存策略: Redis 缓存热点数据
  3. 消息队列: 社交消息异步处理
  4. 分库分表: 大数据量水平拆分

部署

Docker 部署

bash
# 构建镜像
docker build -t solinkcrm:latest .

# 运行容器
docker run -d -p 8080:8080 solinkcrm:latest

Kubernetes 部署

bash
# 应用配置
kubectl apply -f k8s/

# 查看状态
kubectl get pods -n solinkcrm

常见问题

Q: 微信生态接入配置失败?

A: 检查:

  1. AppID 和 AppSecret 是否正确
  2. 回调地址是否已配置白名单
  3. 服务器 IP 是否已加入公众号安全域名

Q: AI 大模型调用超时?

A: 检查:

  1. API Key 是否有效
  2. 网络是否可访问模型服务
  3. 请求参数是否超出模型限制

Q: 社交消息同步延迟?

A: 检查:

  1. Webhook 回调是否正常
  2. 消息队列是否积压
  3. 社交平台 API 限流情况

相关资源