fix(admin): 收回一诊患者表空操作列并修正零值排行

This commit is contained in:
2026-12-02 10:38:55 +08:00
parent 52d5215673
commit 6d72d6abe7
5 changed files with 283 additions and 57 deletions
@@ -20,7 +20,7 @@
<el-tab-pane label="医生排班" name="paiban" />
</el-tabs>
<div v-show="activeWorkspace === 'patients'">
<div v-show="activeWorkspace === 'patients'" ref="patientsPanel">
<div class="filter-panel">
<div class="filter-row filter-row-main">
<el-input
@@ -97,13 +97,14 @@
</div>
<el-table
ref="patientTable"
v-loading="pager.loading"
:data="pager.lists"
class="patient-table"
:row-class-name="tableRowClassName"
@row-dblclick="openDiagnosis"
>
<el-table-column label="患者" min-width="190" fixed="left">
<el-table-column label="患者" min-width="190" :fixed="actionLayout.fixPatient ? 'left' : false">
<template #default="{ row }">
<div class="patient-cell">
<span class="patient-avatar">{{ patientInitial(row.patient_name) }}</span>
@@ -152,44 +153,44 @@
<el-table-column label="诊单日期" width="118">
<template #default="{ row }">{{ row.diagnosis_date_text || '—' }}</template>
</el-table-column>
<el-table-column label="操作" min-width="430" fixed="right">
<el-table-column
v-if="!isV2 || actionLayout.width > 0"
:key="settings.adminUi"
label="操作"
:width="isV2 ? actionLayout.width : undefined"
:min-width="isV2 ? undefined : 430"
:fixed="actionLayout.fixActions ? 'right' : false"
>
<template #default="{ row }">
<div class="row-actions">
<el-button v-if="canEditDiagnosis" type="primary" link @click="openDiagnosis(row)">诊单</el-button>
<el-button v-else-if="canReadDiagnosis" type="primary" link @click="openReadonlyDiagnosis(row)">查看</el-button>
<el-button v-if="canBookAppointment" type="primary" link @click="openAppointment(row)">预约</el-button>
<div
class="row-actions"
:class="{ 'row-actions-compact': isV2 }"
@dblclick="isV2 && $event.stopPropagation()"
>
<el-button
v-if="canAssignPatient"
type="warning"
v-for="action in actionLayout.byRow.get(row)?.inline"
:key="action.key"
:type="action.type"
link
@click="openAssignDialog(row)"
>
{{ Number(row.assistant_id) > 0 ? '重新指派' : '指派' }}
</el-button>
<el-button
v-if="canFillIdCard && !Number(row.has_id_card)"
type="warning"
link
@click="openFillIdCardDialog(row)"
>
补全身份证
</el-button>
<el-button
v-if="canShowDiagnosisQRCode(row)"
type="primary"
link
@click="openDiagnosisQRCode(row)"
>
诊单二维码
</el-button>
<el-button
v-if="canBookAppointment && canCancelAppointment(row)"
type="danger"
link
@click="cancelAppointmentForRow(row)"
>
取消挂号
</el-button>
@click="actionHandlers[action.key](row)"
>{{ action.label }}</el-button>
<el-dropdown v-if="actionLayout.byRow.get(row)?.more.length" trigger="click">
<el-button type="primary" link :aria-label="`${row.patient_name || '患者'}的更多操作`">
更多<el-icon class="el-icon--right"><ArrowDown /></el-icon>
</el-button>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item
v-for="action in actionLayout.byRow.get(row)?.more"
:key="action.key"
:divided="action.key === 'cancel'"
@click="actionHandlers[action.key](row)"
>
<span :class="{ 'cancel-action': action.key === 'cancel' }">{{ action.label }}</span>
</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
</template>
</el-table-column>
@@ -331,10 +332,14 @@
<script setup lang="ts">
import { appointmentTypeDescription } from '@/utils/appointment-type'
import { computed, defineAsyncComponent, onMounted, reactive, ref } from 'vue'
import { computed, defineAsyncComponent, onMounted, reactive, ref, watch } from 'vue'
import { useElementSize } from '@vueuse/core'
import type { TableInstance } from 'element-plus'
import { useSettingStore } from '@/stores/modules/setting'
import { canCancelAppointment, hasQRCodeAppointment, patientActionLayout } from './patient-actions'
import { useRouter } from 'vue-router'
import dayjs from 'dayjs'
import { Calendar, Clock, Loading, Lock, Refresh, Search } from '@element-plus/icons-vue'
import { ArrowDown, Calendar, Clock, Loading, Lock, Refresh, Search } from '@element-plus/icons-vue'
import { usePaging } from '@/hooks/usePaging'
import { hasPermission } from '@/utils/perm'
import feedback from '@/utils/feedback'
@@ -360,7 +365,15 @@ type DateType = 'all' | 'yesterday' | 'today' | 'tomorrow' | 'day_after' | 'last
const router = useRouter()
const userStore = useUserStore()
const settings = useSettingStore()
const isV2 = computed(() => settings.adminUi === 'v2')
const patientsPanel = ref<HTMLElement>()
const patientTable = ref<TableInstance>()
const { width: tableWidth } = useElementSize(patientsPanel)
const activeWorkspace = ref('patients')
watch(activeWorkspace, (tab) => {
if (tab === 'patients') patientTable.value?.doLayout()
}, { flush: 'post' })
const activeDateType = ref<DateType>('all')
const customDateRange = ref<string[]>([])
const editRef = ref<any>()
@@ -433,7 +446,14 @@ const canEditDiagnosis = computed(() => hasPermission(['tcm.diagnosis/edit']))
const canReadDiagnosis = computed(() => hasPermission(['tcm.diagnosis/readonlyDetail']))
const canBookAppointment = computed(() => hasPermission(['tcm.diagnosis/guahao']))
const canAssignPatient = computed(() => hasPermission(['tcm.diagnosis/assign']))
const canFillIdCard = computed(() => hasPermission(['tcm.diagnosis/edit']))
const actionHandlers = {
edit: openDiagnosis, read: openReadonlyDiagnosis, book: openAppointment, assign: openAssignDialog,
fillId: openFillIdCardDialog, qr: openDiagnosisQRCode, cancel: cancelAppointmentForRow
}
const actionLayout = computed(() => patientActionLayout(pager.lists || [], {
edit: canEditDiagnosis.value, read: canReadDiagnosis.value,
book: canBookAppointment.value, assign: canAssignPatient.value
}, tableWidth.value, isV2.value))
const workspaceLoading = computed(() => {
if (activeWorkspace.value === 'orders') return Boolean(orderPanelRef.value?.loading)
if (activeWorkspace.value === 'progress') return Boolean(progressPanelRef.value?.loading)
@@ -646,15 +666,8 @@ async function submitFillIdCard() {
}
}
function canShowDiagnosisQRCode(row: any) {
return canBookAppointment.value
&& Number(row.appointment_id) > 0
&& Number(row.appointment_status) === 1
&& Number(row.appointment_doctor_id) > 0
}
async function openDiagnosisQRCode(row: any) {
if (!canShowDiagnosisQRCode(row)) {
if (!canBookAppointment.value || !hasQRCodeAppointment(row)) {
feedback.msgWarning('仅已挂号患者可以生成诊单二维码')
return
}
@@ -697,10 +710,6 @@ function regenerateDiagnosisQRCode() {
}
}
function canCancelAppointment(row: any) {
return Number(row.appointment_id) > 0 && [1, 4].includes(Number(row.appointment_status))
}
async function cancelAppointmentForRow(row: any) {
if (!canCancelAppointment(row)) return
try {
@@ -1097,6 +1106,18 @@ onMounted(() => {
}
}
.row-actions-compact {
gap: 8px;
:deep(.el-button + .el-button) {
margin-left: 0;
}
}
.cancel-action {
color: var(--el-color-danger-dark-2);
}
.dialog-full-width {
width: 100%;
}
@@ -0,0 +1,51 @@
// Keep action visibility, order and sizing together so the column reflects the actual page of rows.
type Patient = Partial<Record<'assistant_id' | 'has_id_card' | 'appointment_id' | 'appointment_status' | 'appointment_doctor_id', string | number | null>>
type Permissions = { edit: boolean; read: boolean; book: boolean; assign: boolean }
type Action = {
key: 'edit' | 'read' | 'book' | 'assign' | 'fillId' | 'qr' | 'cancel'
label: string
type: 'primary' | 'warning' | 'danger'
}
type ActionGroup = { inline: Action[]; more: Action[] }
export function hasQRCodeAppointment(row: Patient) {
return Number(row.appointment_id) > 0 && Number(row.appointment_status) === 1 && Number(row.appointment_doctor_id) > 0
}
export function canCancelAppointment(row: Patient) {
return Number(row.appointment_id) > 0 && [1, 4].includes(Number(row.appointment_status))
}
function actionsForPatient(row: Patient, access: Permissions): Action[] {
const actions: Action[] = []
if (access.edit) actions.push({ key: 'edit', label: '诊单', type: 'primary' })
else if (access.read) actions.push({ key: 'read', label: '查看', type: 'primary' })
if (access.book) actions.push({ key: 'book', label: '预约', type: 'primary' })
if (access.assign) actions.push({ key: 'assign', label: Number(row.assistant_id) > 0 ? '重新指派' : '指派', type: 'warning' })
if (access.edit && !Number(row.has_id_card)) actions.push({ key: 'fillId', label: '补全身份证', type: 'warning' })
if (access.book && hasQRCodeAppointment(row)) actions.push({ key: 'qr', label: '诊单二维码', type: 'primary' })
if (access.book && canCancelAppointment(row)) actions.push({ key: 'cancel', label: '取消挂号', type: 'danger' })
return actions
}
export function patientActionLayout<T extends Patient>(rows: T[], access: Permissions, tableWidth: number, v2: boolean) {
const byRow = new Map<T, ActionGroup>()
let width = 0
for (const row of rows) {
const actions = actionsForPatient(row, access)
const limit = v2 && actions.length > 2 ? (tableWidth >= 720 ? 2 : 1) : actions.length
const inline = actions.slice(0, limit)
const more = actions.slice(limit)
byRow.set(row, { inline, more })
if (v2 && inline.length > 0) {
// Cell insets (24px), link buttons (16px per CJK character + 6px trim),
// gaps (8px) and the optional 更多 trigger including its chevron.
const buttons = inline.reduce((sum, action) => sum + action.label.length * 16 + 6, 0)
width = Math.max(width, 24 + buttons + (inline.length - 1) * 8 + (more.length ? 66 : 0))
}
}
// Leave at least an appointment-time field (165px) available between sticky columns.
const fixPatient = !v2 || tableWidth >= 190 + 165
const fixActions = !v2 || tableWidth >= 190 + width + 165
return { byRow, width, fixPatient, fixActions }
}
@@ -331,9 +331,9 @@ const timeOptions = [
]
const deptTreeProps = { label: 'name', value: 'id', children: 'children' }
const maxPerformance = computed(() => Math.max(0, ...dashboard.rankings.performance.map((item: any) => Number(item.value) || 0)))
const maxRegistrations = computed(() => Math.max(0, ...dashboard.rankings.registrations.map((item: any) => Number(item.value) || 0)))
const maxAppointments = computed(() => Math.max(0, ...dashboard.rankings.appointments.map((item: any) => Number(item.value) || 0)))
const maxPerformance = computed(() => rankMax(dashboard.rankings.performance))
const maxRegistrations = computed(() => rankMax(dashboard.rankings.registrations))
const maxAppointments = computed(() => rankMax(dashboard.rankings.appointments))
const targetChartOption = computed(() => ({
animationDuration: 450,
grid: { left: 18, right: 18, top: 18, bottom: 12, containLabel: true },
@@ -430,9 +430,18 @@ function compareClass(value: unknown) {
return Number(value) > 0 ? 'is-up' : 'is-down'
}
function rankValue(value: unknown) {
if (typeof value !== 'number' && typeof value !== 'string') return 0
const number = Number(value)
return Number.isFinite(number) && number > 0 ? number : 0
}
function rankMax(rows: Array<{ value: unknown }>) {
return rows.reduce((max, row) => Math.max(max, rankValue(row.value)), 0)
}
function rankWidth(value: unknown, max: number) {
if (max <= 0) return '0%'
return `${Math.max(4, Math.min(100, Number(value || 0) / max * 100))}%`
return max > 0 ? `${Math.min(rankValue(value), max) / max * 100}%` : '0%'
}
function avatarText(name: unknown) {
@@ -0,0 +1,76 @@
const assert = require('node:assert/strict')
const path = require('node:path')
const test = require('node:test')
const { buildSync } = require('esbuild')
const { outputFiles } = buildSync({
entryPoints: [path.join(__dirname, '../src/views/first_visit/my_patients/patient-actions.ts')],
write: false, format: 'cjs', platform: 'node'
})
const mod = { exports: {} }
new Function('module', 'exports', outputFiles[0].text)(mod, mod.exports)
const { patientActionLayout } = mod.exports
const none = { edit: false, read: false, book: false, assign: false }
const all = { edit: true, read: true, book: true, assign: true }
const booked = { assistant_id: '12', appointment_id: '82', appointment_status: '1', appointment_doctor_id: '7', has_id_card: '0' }
const unbooked = { assistant_id: 0, appointment_id: 0, has_id_card: '1' }
const keys = actions => actions.map(a => a.key)
const allKeys = group => keys([...group.inline, ...group.more])
test('an empty list or a scope-only role does not reserve an action column', () => {
assert.equal(patientActionLayout([], all, 857, true).width, 0)
const layout = patientActionLayout([booked, unbooked], none, 857, true)
assert.equal(layout.width, 0)
assert.deepEqual(allKeys(layout.byRow.get(booked)), [])
})
test('read-only and assignment roles get compact direct actions; use the longest real row in either order', () => {
const access = { ...none, assign: true }
const widthFor = rows => patientActionLayout(rows, access, 857, true).width
const small = widthFor([unbooked])
const large = widthFor([booked])
assert.ok(small > 0 && small < large && large < 120)
for (const rows of [[unbooked, booked], [booked, unbooked]]) assert.equal(widthFor(rows), large)
const layout = patientActionLayout([booked, unbooked], { ...access, read: true }, 601, true)
assert.deepEqual(layout.byRow.get(booked).inline.map(a => a.label), ['查看', '重新指派'])
assert.deepEqual(layout.byRow.get(unbooked).inline.map(a => a.label), ['查看', '指派'])
assert.deepEqual(layout.byRow.get(booked).more, [])
})
test('high-frequency actions stay direct, and every authorized row action stays reachable at all widths', () => {
const expected = ['edit', 'book', 'assign', 'fillId', 'qr', 'cancel']
for (const width of [0, 280, 390, 601, 857, 1017]) {
const layout = patientActionLayout([unbooked, booked], all, width, true)
const group = layout.byRow.get(booked)
assert.deepEqual(keys(group.inline), width >= 720 ? ['edit', 'book'] : ['edit'])
assert.deepEqual(allKeys(group), expected)
assert.deepEqual(allKeys(layout.byRow.get(unbooked)), ['edit', 'book', 'assign'])
assert.ok(layout.width < 200)
if (width < 355) assert.equal(layout.fixPatient, false)
if (layout.fixActions) assert.ok(width - layout.width - 190 >= 165)
if (width === 601) assert.ok(layout.fixActions && layout.fixPatient)
}
})
test('booking menus follow row status; no QR or cancel action leaks through other permissions', () => {
const access = { ...none, book: true }
for (const [overrides, wanted] of [
[{}, ['book', 'qr', 'cancel']],
[{ appointment_doctor_id: 0 }, ['book', 'cancel']],
[{ appointment_status: '4' }, ['book', 'cancel']],
[{ appointment_status: '3' }, ['book']],
[{ appointment_id: '0' }, ['book']]
]) {
const row = { ...booked, ...overrides }
assert.deepEqual(allKeys(patientActionLayout([row], access, 857, true).byRow.get(row)), wanted)
assert.deepEqual(allKeys(patientActionLayout([row], { ...none, edit: true, read: true }, 857, true).byRow.get(row)), ['edit', 'fillId'])
}
})
test('classic keeps both pinned columns and every eligible action inline even on narrow screens', () => {
const layout = patientActionLayout([booked], all, 280, false)
assert.deepEqual(keys(layout.byRow.get(booked).inline), ['edit', 'book', 'assign', 'fillId', 'qr', 'cancel'])
assert.deepEqual(layout.byRow.get(booked).more, [])
assert.equal(layout.fixActions && layout.fixPatient, true)
})
@@ -0,0 +1,69 @@
const assert = require('node:assert/strict')
const fs = require('node:fs')
const path = require('node:path')
const test = require('node:test')
const { parse, compileScript } = require('@vue/compiler-sfc')
const ts = require('typescript')
const vue = require('vue')
const { renderToString } = require('vue/server-renderer')
const filename = path.join(__dirname, '../src/views/first_visit/registration_stats/index.vue')
const { descriptor, errors } = parse(fs.readFileSync(filename, 'utf8'), { filename })
assert.deepEqual(errors, [])
const { content } = compileScript(descriptor, { id: 'a05', inlineTemplate: true, templateOptions: { ssr: true } })
const { outputText } = ts.transpileModule(content, { compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022 } })
const groups = ['performance', 'registrations', 'appointments']
// Render the real page, replacing its HTTP response and running the mount fetch before SSR.
async function rankings(samples) {
const rankings = Object.fromEntries(groups.map((key, i) => [key, samples[i].map((value, j) =>
({ admin_id: j + 1, name: '员工' + j, count: 1, value }))]))
const stub = { render: () => null }
const imports = {
vue: { ...vue, onMounted: vue.onServerPrefetch },
'@/api/first_visit': { firstVisitRegistrationStatsOverview: async () => ({ rankings }) },
'@element-plus/icons-vue': new Proxy({}, { get: () => stub }),
'element-plus': {}, 'vue-echarts': { default: stub }
}
const mod = { exports: {} }
new Function('require', 'module', 'exports', outputText)(id => imports[id] || require(id), mod, mod.exports)
const app = vue.createSSRApp(mod.exports.default)
for (const [tag] of descriptor.template.content.matchAll(/<el-[\w-]+/g)) {
const name = tag.slice(1)
if (!app.component(name)) app.component(name, stub)
}
app.directive('loading', {})
const html = await renderToString(app)
const panels = [...html.matchAll(/<article class="panel ranking-panel"[^>]*>([\s\S]*?)<\/article>/g)]
assert.equal(panels.length, 3)
return panels.map(([, panel]) => [...panel.matchAll(/<div class="ranking-row"[^>]*><b[^>]*>(\d+)<\/b>.*?<i style="width:([^;"]+);?"[^>]*><\/i><\/div><strong[^>]*>([^<]+)<\/strong>/gs)]
.map(([, rank, width, label]) => ({ rank: Number(rank), width, label })))
}
const cases = [
[[2, 1, 0], ['100%', '50%', '0%']],
[[100, 1, 0], ['100%', '1%', '0%']],
[[0, 0, 0], ['0%', '0%', '0%']]
]
for (const [values, expected] of cases) {
test(`three rankings: ${values.join('/')} retains rank and label with proportional fill`, async () => {
const panels = await rankings(groups.map(() => values))
for (let i = 0; i < panels.length; i++) {
assert.deepEqual(panels[i], values.map((value, j) => ({
rank: j + 1, width: expected[j],
label: [`¥${value.toFixed(2)}`, `${value} 笔`, `${value} 个`][i]
})), groups[i])
}
})
}
test('each group ignores invalid and non-positive values and scales independently without overflow', async () => {
const panels = await rankings([
[Number.MAX_VALUE, Number.MAX_VALUE / 2, 0],
['4', '1', 'n/a', -2, true, [4], null, '1e999'],
[Infinity, 0, '0.25', 1]
])
assert.deepEqual(panels.map(panel => panel.map(row => row.width)), [
['100%', '50%', '0%'], ['100%', '25%', '0%', '0%', '0%', '0%', '0%', '0%'], ['0%', '0%', '25%', '100%']
])
})