yxh
2026-10-18 1446994d504819c367e1ff667360eadb314f9ac6
src/api/ecg/room/index.ts
@@ -6,12 +6,81 @@
  roomId: number | null // 诊室编号
  roomName: string | null // 诊室名称
  bedNo: string | null // 诊疗床编号
  ip: string | null // 诊室IP
  ip: string | null // 诊室工位IP
  status: number | null //开诊状态  0-关闭 1-关闭中 10-已开通 20-有医生 30-暂停
  docId: number | null
  docName: string | null
  checkTypes: number[] | null
  opType: number | null
  occupied?: boolean | null // 该工位是否已被医生占用(按IP匹配工位时用)
}
// 「选择工位模式」- 按本机IP匹配工位的候选工位
export interface RoomSelectBedItem {
  id: number // 工位主键 clinic_room.id
  roomId: number | null
  roomName: string | null
  bedNo: string | null
  ip: string | null
  docId: number | null
  docName: string | null
  opType: number | null
  checkTypes: number[] | null
  status: number | null
  occupied: boolean | null
  mine: boolean | null
}
// 「选择工位模式」- 按本机IP匹配工位的结果
export interface RoomSelectBedResp {
  clientIp: string | null // 后端实际识别到的来访IP(已规范化)
  ipValid: boolean | null // 该IP是否可用于绑定
  ipLoopback: boolean | null // 该IP是否是本机回环(127.x / ::1)→ 说明浏览器与服务在同一台机器
  ipv6: boolean | null // 该IP是否是 IPv6(本系统工位绑定仅采用 IPv4)
  ipBound: boolean | null // 该IP是否已绑定工位
  matched: boolean | null // 是否有可直接入座的工位
  beds: RoomSelectBedItem[]
}
/**
 * 该IP能否用于自动匹配/绑定工位。
 * **本系统工位绑定只采用 IPv4**:IPv6(含 ::1、fe80::、2408:: 等)一律不可用。
 * 空值、0.0.0.0、127.x 同样不可用;`::ffff:32.88.65.208` 由后端还原成 IPv4 后可用。
 */
export const isUsableSeatIp = (ip?: string | null): boolean => {
  const v = (ip || '').trim()
  if (!v || v === '0.0.0.0' || v.startsWith('127.')) return false
  if (v.includes(':')) return false // IPv6 不采用
  if (!/^(\d{1,3}\.){3}\d{1,3}$/.test(v)) return false
  return v.split('.').every((seg) => Number(seg) <= 255)
}
/**
 * 「工位入座」结果(自动入座 / 查询我的工位 共用)。
 *
 * reason 取值:
 *  - ip_invalid 本机IP不可用(回环/IPv6/未指定/非法)
 *  - nomatch    该IP没匹配到工位(工位没录IP 或 已关闭)
 *  - multi      该IP对应多个空闲工位,需人工点选
 *  - occupied   匹配到的工位已被**他人**占用(不挤掉)
 *  - error      入座写库未生效
 */
export interface RoomSeatResp {
  seated: boolean
  reason?: string | null
  clientIp?: string | null
  ownerName?: string | null
  id?: number | null
  roomId?: number | null
  roomName?: string | null
  bedNo?: string | null
  ip?: string | null
  status?: number | null
  docId?: number | null
  docName?: string | null
  checkTypes?: number[] | null
  opType?: number | null
}
export interface MonitorInfo {
@@ -96,6 +165,57 @@
  // 手动闭诊
  closeBiz: async () => {
    return await request.get({ url: `/clinic/room/close-biz` })
  },
  /** 「选择工位模式」按本机IP匹配工位(模式 1/3):返回后端识别到的IP + 候选工位(已排序) */
  getIpBed: async () => {
    return await request.get({ url: `/clinic/room/get-ip-bed` })
  },
  /**
   * 一键自动入座(模式 1/3):后端按来访IP匹配工位并直接落座。
   *
   * 相比原来「getIpBed → bindIpToBed → bedDoctorOn」三步拼装,这里只失败一次即可排查:
   * 返回体带 clientIp 与 reason(ip_invalid / nomatch / multi / occupied / error)。
   * 服务端同时保证:一个用户只占一个工位(入座成功后释放其其它工位)。
   */
  autoSeat: async () => {
    return await request.post({ url: `/clinic/room/auto-seat` })
  },
  /** 查询当前登录人已入座的工位(系统顶栏"当前工位"标签用) */
  getMySeat: async () => {
    return await request.get({ url: `/clinic/room/my-seat` })
  },
  /**
   * 客户端 IP 识别诊断:返回各代理头、直连地址、规范化结果、是否服务器自身地址、服务器网卡列表与结论。
   * 现场排查"工位绑定的 IP 不对"用(选工位页的「IP 诊断」按钮)。
   */
  ipDebug: async () => {
    return await request.get({ url: `/clinic/room/ip-debug` })
  },
  /**
   * 工位状态诊断:返回该工位**库内原始行**(含 bed_no 长度/HEX、status、doc_id、deleted)与结论。
   * 用于排查"工位明明空闲却入座失败(报状态异常)"。
   */
  bedState: async (params: { id?: number | null; roomId?: number | null; bedNo?: string | null }) => {
    const query: string[] = []
    if (params?.id != null) query.push(`id=${params.id}`)
    if (params?.roomId != null) query.push(`roomId=${params.roomId}`)
    if (params?.bedNo != null) query.push(`bedNo=${encodeURIComponent(params.bedNo)}`)
    return await request.get({ url: `/clinic/room/bed-state?${query.join('&')}` })
  },
  /**
   * 「选择工位模式」把本机IP绑定到指定工位(模式 2/3)。
   * force=false 时若该IP已绑在别的工位,返回 code=409 + 冲突工位信息,由界面确认后再带 force=true 覆盖。
   */
  bindIpToBed: async (id: number, force = false) => {
    return await request.post({
      url: `/clinic/room/bind-ip?id=${id}&force=${force}`
    })
  }
}