types.ts

4.2 KB v1.0
export type Role = 'self' | 'dept' | 'all'
export type Action = 'view' | 'create' | 'edit' | 'delete' | 'export' | 'manage'
export type CustomerStatus = 'lead' | 'contacted' | 'won' | 'lost'
export type FieldType = 'text' | 'number' | 'date' | 'select' | 'textarea'

export interface User {
  id: string
  username: string
  display_name: string
  email: string | null
  phone: string | null
  department_id: string | null
  department_name: string | null
  role_id: string | null
  role_name: string | null
  role_code: string | null
  is_super: boolean
  must_change_pwd: boolean
  data_scope: Role
  permissions: Action[]
  status?: string
  last_login_at?: string | null
  created_at?: string
  pool_ids?: string[]
}

export interface Pool {
  id: string
  name: string
  description: string | null
  color: string
  sort_order: number
  enabled: boolean
  customer_count: number
}

export interface Department {
  id: string
  name: string
  parent_id: string | null
  sort_order: number
}

export interface RoleItem {
  id: string
  name: string
  code: string
  data_scope: Role
  permissions: Action[]
  is_system: boolean
  description: string | null
}

export interface CustomField {
  id: string
  field_key: string
  label: string
  field_type: FieldType
  options: string[]
  required: boolean
  enabled: boolean
  sort_order: number
}

export interface Customer {
  id: number
  name: string
  company: string | null
  phone: string | null
  email: string | null
  status: CustomerStatus
  source: string | null
  industry: string | null
  level: string | null
  region: string | null
  notes: string | null
  custom_data: Record<string, string>
  owner_id: string | null
  owner_name: string | null
  pool_id: string | null
  department_id: string | null
  last_follow_at: string | null
  follow_count: number
  created_by_name: string | null
  created_at: string
  updated_at: string
  deleted_at?: string | null
}

export interface FollowUp {
  id: number
  customer_id: number
  author_id: string
  author_name: string
  method: string
  content: string
  follow_at: string
  created_at: string
}

export interface OperationLog {
  id: number
  operator_id: string | null
  operator_name: string
  action: string
  target_type: string | null
  target_id: string | null
  target_name: string | null
  detail: string | null
  ip: string | null
  created_at: string
}

export interface Stats {
  total: number
  pool: number
  mine: number
  lead: number
  contacted: number
  won: number
  lost: number
  never_followed: number
  followed: number
}

export const STATUS_META: Record<CustomerStatus, { label: string; cls: string }> = {
  lead: { label: '潜在客户', cls: 'st-lead' },
  contacted: { label: '跟进中', cls: 'st-contacted' },
  won: { label: '已成交', cls: 'st-won' },
  lost: { label: '已流失', cls: 'st-lost' },
}

export const ACTION_LABELS: { key: Action; label: string }[] = [
  { key: 'view', label: '查看' },
  { key: 'create', label: '新增' },
  { key: 'edit', label: '编辑' },
  { key: 'delete', label: '删除' },
  { key: 'export', label: '导出' },
  { key: 'manage', label: '管理' },
]

export const SCOPE_LABELS: Record<Role, string> = {
  self: '本人可见', dept: '本部门可见', all: '全部数据可见',
}

export const METHOD_LABELS: Record<string, string> = {
  phone: '电话', wechat: '微信', email: '邮件', meeting: '面谈', other: '其他',
}

export const LOG_ACTION_LABELS: Record<string, string> = {
  login: '登录', logout: '登出', create: '新增客户', edit: '编辑客户', delete: '删除客户',
  claim: '认领客户', recycle: '回收公海', assign: '分配客户', followup: '添加跟进',
  followup_delete: '删除跟进', import: '导入客户', export: '导出客户',
  reset_pwd: '重置密码', user_create: '新建成员', user_edit: '编辑成员',
  user_delete: '删除成员', role_create: '新建角色', role_edit: '编辑角色',
  role_delete: '删除角色', dept_create: '新建部门', dept_edit: '编辑部门',
  dept_delete: '删除部门', field_create: '新建字段', field_edit: '编辑字段',
  field_delete: '删除字段', settings_edit: '修改设置',
  pool_create: '新建资源池', pool_edit: '编辑资源池', pool_delete: '删除资源池',
  restore_customer: '还原客户', purge: '永久删除',
}