yxh
9 天以前 97f4e581af58ca03ff4c39210fd4b2f3ae11f8ff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
<template>
  <el-container>
    <el-main class="room-setting-main">
      <div class="rs-columns">
        <!-- ============ ① 工位开诊状态 ============ -->
        <el-card class="rs-section rs-section--status" shadow="never">
          <template #header>
            <div class="rs-section__head">
              <span class="rs-section__title">① 工位开诊状态</span>
              <span class="rs-section__hint">请点击工位的「开诊 / 闭诊」图片,切换开诊状态</span>
            </div>
          </template>
 
          <!-- 图例:把三种图片和状态文字对应起来 -->
          <div class="rs-legend">
            <span class="rs-legend__item">
              <img :src="closeImg" alt="已闭诊" />
              <b class="is-closed">已闭诊</b>
              <span>点图片 → 开诊</span>
            </span>
            <span class="rs-legend__item">
              <img :src="openImg" alt="已开诊" />
              <b class="is-open">已开诊</b>
              <span>点图片 → 闭诊</span>
            </span>
            <span class="rs-legend__item">
              <img :src="doctorImg" alt="医生在座" />
              <b class="is-doctor">医生在座</b>
              <span>需先在医生工作台「离座」才能闭诊</span>
            </span>
          </div>
 
          <div class="rs-cards">
            <RoomStatus
              v-for="(value, key) in bedMap"
              :key="key"
              :title="key"
              :bedList="value"
              @refresh="onBedRefresh"
            />
          </div>
        </el-card>
 
        <div class="rs-side">
          <!-- ============ ② 全局操作 ============ -->
          <el-card class="rs-section" shadow="never">
            <template #header>
              <div class="rs-section__head">
                <span class="rs-section__title">② 全局操作</span>
              </div>
            </template>
            <div class="rs-btns">
              <el-button size="small" type="primary" plain @click="startBiz">手动开诊</el-button>
              <el-button size="small" type="warning" plain @click="closeBiz">手动闭诊</el-button>
              <el-button size="small" @click="resetRoom">重置诊室</el-button>
              <el-button size="small" @click="resetSchedule">重置定时任务</el-button>
              <el-button size="small" @click="refresh">刷新</el-button>
            </div>
            <div class="rs-note">
              手动开诊 / 闭诊是<b>自动补人的总闸</b>:闭诊后「排队中」的患者不会被自动搬进各工位的候诊区。
              <br />「重置诊室」会清空当班工位与队列,请在无患者时使用。
            </div>
          </el-card>
 
          <!-- ============ ③ 选择工位模式 ============ -->
          <el-card class="rs-section" shadow="never">
            <template #header>
              <div class="rs-section__head">
                <span class="rs-section__title">③ 选择工位模式</span>
              </div>
            </template>
            <el-select v-model="roomSelectMode" size="small" style="width: 100%" @change="saveRoomSelectMode">
              <el-option :value="0" label="0 - 按需要强制选择工位" />
              <el-option :value="1" label="1 - 登录IP匹配工位" />
              <el-option :value="2" label="2 - 登录时手动选择工位(写入本机IP)" />
              <el-option :value="3" label="3 - 按系统默认处理" />
            </el-select>
            <div class="rs-note">
              0=每次都要选;1=按IP自动匹配,匹配不到才让选;2=每次都要选并把本机IP写到该工位;
              3=该IP首次选一次并记住,之后按 1 自动匹配
            </div>
            <div class="rs-warn" v-if="unboundIpBeds.length > 0">
              以下工位未绑定有效的 IPv4 地址(本系统工位绑定仅采用 IPv4),模式 1、3 将无法自动匹配到它们:{{ unboundIpBeds.join('、') }}
            </div>
          </el-card>
 
          <!-- ============ ④ 运行概况 ============ -->
          <el-card class="rs-section" shadow="never">
            <template #header>
              <div class="rs-section__head">
                <span class="rs-section__title">④ 运行概况</span>
              </div>
            </template>
 
            <div class="rs-kv">
              <span class="rs-kv__k">开诊时间</span>
              <span class="rs-kv__v">{{ openingPeriod || '—' }}</span>
            </div>
            <div class="rs-kv">
              <span class="rs-kv__k">开诊状态</span>
              <el-tag :type="monitorInfo?.openingFlag === 1 ? 'success' : 'info'" size="small">
                {{ monitorInfo?.openingFlag === 1 ? '开诊中(会自动补人)' : '已闭诊(不会自动补人)' }}
              </el-tag>
            </div>
            <div class="rs-kv">
              <span class="rs-kv__k">工位</span>
              <span class="rs-kv__v">
                开通 {{ monitorInfo?.openingBedNum ?? 0 }} ·
                在座 {{ monitorInfo?.docBedNum ?? 0 }}(医生 {{ monitorInfo?.docNum ?? 0 }} 人)·
                参与分流 {{ monitorInfo?.routingBedNum ?? 0 }}
              </span>
            </div>
 
            <!-- 各检查项目的工位分布(原来是一行行裸文本,看不出四个数字分别是什么) -->
            <el-table :data="checkTypeRows" size="small" border class="rs-table">
              <el-table-column prop="name" label="检查项目" min-width="96" show-overflow-tooltip />
              <el-table-column label="开通(检查/安装)" align="center" width="116">
                <template #default="{ row }">{{ row.openMain }} / {{ row.openInstall }}</template>
              </el-table-column>
              <el-table-column label="在座(检查/安装)" align="center" width="116">
                <template #default="{ row }">{{ row.docMain }} / {{ row.docInstall }}</template>
              </el-table-column>
            </el-table>
          </el-card>
        </div>
      </div>
    </el-main>
  </el-container>
</template>
 
<script setup lang="ts">
import { RoomStatus } from '@/components/RoomStatus'
import { RoomApi, RoomVO, MonitorInfo, isUsableSeatIp } from '@/api/ecg/room'
import { QueueApi } from '@/api/ecg/queue'
import { getConfigKey, getConfigPage, createConfig, updateConfig } from '@/api/infra/config'
import { useCheckTypeStore } from '@/store/modules/checkType'
import { getCheckTypeName } from '../../../utils/checkTypeFormatter'
// 图例用的三张状态图(与 RoomStatus 卡片内保持一致)
import closeImg from '@/assets/room/close.jpg'
import openImg from '@/assets/room/open.jpg'
import doctorImg from '@/assets/room/desk-doctor.jpg'
 
defineOptions({ name: 'RoomSetting' })
 
const bedMap = ref() // 列表的数据
 
const openingPeriod = ref<string>('')
/**
 * 「选择工位模式」参数(ecg.room.select.mode):
 * 0=按需要强制选择工位(默认,原行为) 1=登录IP匹配工位 2=登录时手动选择工位(写入本机IP) 3=按系统默认处理
 */
const roomSelectMode = ref<number>(0)
const roomSelectModeConfigId = ref<number | undefined>(undefined)
const monitorInfo = ref<MonitorInfo>({
  openingBedNum: 0,
  docBedNum: 0,
  routingBedNum: 0,
  openingFlag: 0,
  checkTypeBedInfo: {}
})
 
const checkTypeStore = useCheckTypeStore()
 
/** 该IP能否用于自动匹配工位(支持 IPv4/IPv6;空、0.0.0.0、::、127.x、::1 都是无效占位/回环值) */
const isIpUsable = (ip?: string | null) => isUsableSeatIp(ip)
 
/** 未绑定有效IP的工位(模式 1、3 匹配不到它们,管理页给出提醒) */
const unboundIpBeds = computed<string[]>(() => {
  const map: any = bedMap.value || {}
  const list: string[] = []
  Object.keys(map).forEach((roomName) => {
    ;(map[roomName] as RoomVO[]).forEach((bed) => {
      if (!isIpUsable(bed.ip)) {
        list.push(`${roomName}/${bed.bedNo ?? ''}`)
      }
    })
  })
  return list
})
 
/**
 * 【本需求·布局整理】把后端 `checkTypeBedInfo` 的"空格拼串"解析成表格行。
 *
 * 后端拼的是:`开通(检查/领用) 开通(安装) 在座(检查/领用) 在座(安装) `,
 * 原来直接在页面上一行行输出这四个数字,没人看得懂哪个是哪个。
 */
const checkTypeRows = computed(() => {
  const map: Record<string, string> = (monitorInfo.value?.checkTypeBedInfo as any) || {}
  return Object.keys(map).map((key) => {
    const parts = String(map[key] || '').trim().split(/\s+/)
    const num = (i: number) => {
      const n = Number(parts[i])
      return Number.isFinite(n) ? n : 0
    }
    return {
      key: Number(key),
      name: getCheckTypeName(Number(key)),
      openMain: num(0),
      openInstall: num(1),
      docMain: num(2),
      docInstall: num(3)
    }
  })
})
 
const getOpeningPeriod = async () => {
  const data = await getConfigKey('ecg.openingtime')
  openingPeriod.value = data
}
 
/** 读取「选择工位模式」参数(参数不存在时保持 0) */
const ROOM_SELECT_MODE_KEY = 'ecg.room.select.mode'
const getRoomSelectMode = async () => {
  try {
    const page: any = await getConfigPage({ key: ROOM_SELECT_MODE_KEY, pageNo: 1, pageSize: 10 })
    const hit = (page?.list || []).find((c: any) => c.key === ROOM_SELECT_MODE_KEY)
    if (hit) {
      roomSelectModeConfigId.value = hit.id
      const n = Number(hit.value)
      roomSelectMode.value = [0, 1, 2, 3].includes(n) ? n : 0
    } else {
      // 参数还没建:按缺省 0 显示,保存时再创建
      roomSelectMode.value = 0
      roomSelectModeConfigId.value = undefined
    }
  } catch (e) {
    console.warn('[getRoomSelectMode] 读取选择工位模式失败,按 0 处理', e)
  }
}
 
/** 保存「选择工位模式」:已有参数则更新,没有则创建(ConfigSaveReqVO 没有 type 字段,别传) */
const saveRoomSelectMode = async () => {
  const payload: any = {
    category: 'biz',
    name: '选择工位模式',
    key: ROOM_SELECT_MODE_KEY,
    value: String(roomSelectMode.value),
    visible: true,
    remark:
      '0=按需要强制选择工位;1=登录IP匹配工位(匹配不到按0);2=登录时手动选择工位并写入本机IP;3=按系统默认处理(首次选并记IP,之后按1)'
  }
  try {
    if (roomSelectModeConfigId.value) {
      payload.id = roomSelectModeConfigId.value
      await updateConfig(payload)
    } else {
      const id: any = await createConfig(payload)
      roomSelectModeConfigId.value = id ?? undefined
      await getRoomSelectMode()
    }
    ElMessage.success('选择工位模式已保存为 ' + roomSelectMode.value)
  } catch (e: any) {
    ElMessage.error('保存失败:' + (e?.message || e))
  }
}
 
const getMonitorInfo = async () => {
  const data = await RoomApi.getMonitorInfo()
  monitorInfo.value = data as MonitorInfo
}
 
/** 查询列表 */
const getList = async () => {
  const data = await RoomApi.getAllBedMap()
  bedMap.value = data as Map<string, RoomVO[]>
}
 
/** 开/闭某个工位后:既要刷新卡片,也要刷新右侧概况(原来只刷卡片,数字停留在旧值) */
const onBedRefresh = () => {
  getList()
  getMonitorInfo()
}
 
const startBiz = async () => {
  await RoomApi.startBiz()
  getMonitorInfo()
}
 
const closeBiz = async () => {
  await RoomApi.closeBiz()
  getMonitorInfo()
}
 
const resetRoom = async () => {
  await RoomApi.resetRoom()
  getList()
}
 
const resetSchedule = async () => {
  await QueueApi.resetSchedule()
}
 
const refresh = () => {
  getList()
  getOpeningPeriod()
  getMonitorInfo()
}
 
/** 初始化 **/
onMounted(() => {
  getList()
  getOpeningPeriod()
  getRoomSelectMode()
  getMonitorInfo()
})
</script>
 
<style scoped lang="scss">
/* ==========================================================================
   【本需求·布局整理】按功能拆成 4 块,页面不再是一堆东西平铺:
 
     ① 工位开诊状态(左,主区)  图例 + 各诊室工位卡片
     ② 全局操作(右上)          开诊/闭诊/重置/刷新
     ③ 选择工位模式(右中)      模式下拉 + 说明 + 未绑定IP提醒
     ④ 运行概况(右下)          开诊时间/状态/工位统计 + 各检查项目分布表
 
   窄屏(<1000px)时右侧自动折到下方,不会横向溢出。
   ========================================================================== */
.room-setting-main {
  padding: 8px 12px;
}
 
.rs-columns {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 10px;
}
 
/* ---------- 分区卡片通用 ---------- */
.rs-section {
  :deep(.el-card__header) {
    padding: 8px 12px;
  }
 
  :deep(.el-card__body) {
    padding: 10px 12px;
  }
 
  &__head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 8px;
  }
 
  &__title {
    font-size: 14px;
    font-weight: 600;
    color: var(--el-text-color-primary);
  }
 
  &__hint {
    font-size: 12px;
    font-weight: 600;
    color: var(--el-color-primary);
  }
}
 
/* 左侧主区(工位状态):占满剩余宽度 */
.rs-section--status {
  flex: 1 1 560px;
  min-width: 0;
}
 
/* 右侧一列:三块功能卡片纵向排列 */
.rs-side {
  display: flex;
  flex: 0 0 380px;
  flex-direction: column;
  gap: 10px;
}
 
/* ---------- ① 图例 ---------- */
.rs-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
  padding: 6px 10px;
  margin-bottom: 8px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--el-text-color-secondary);
  background: var(--el-fill-color-lighter);
  border-radius: 4px;
 
  &__item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
 
    img {
      width: 40px;
      height: 30px;
      object-fit: contain;
    }
 
    b {
      font-size: 12px;
      font-weight: 600;
    }
  }
}
 
.rs-legend .is-open {
  color: var(--el-color-success);
}
 
.rs-legend .is-closed {
  color: var(--el-text-color-secondary);
}
 
.rs-legend .is-doctor {
  color: var(--el-color-primary);
}
 
/* 工位卡片区 */
.rs-cards {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
}
 
/* ---------- ② 全局操作 ---------- */
.rs-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
 
  :deep(.el-button + .el-button) {
    margin-left: 0;
  }
}
 
/* ---------- 说明文字 ---------- */
.rs-note {
  margin-top: 8px;
  font-size: 12px;
  line-height: 18px;
  color: var(--el-text-color-secondary);
}
 
.rs-warn {
  margin-top: 8px;
  font-size: 12px;
  line-height: 18px;
  color: var(--el-color-warning);
}
 
/* ---------- ④ 运行概况 ---------- */
.rs-kv {
  display: flex;
  gap: 8px;
  font-size: 12px;
  line-height: 20px;
 
  & + & {
    margin-top: 2px;
  }
 
  &__k {
    flex: none;
    min-width: 56px;
    color: var(--el-text-color-secondary);
  }
 
  &__v {
    color: var(--el-text-color-regular);
  }
}
 
.rs-table {
  margin-top: 8px;
}
</style>