更新
This commit is contained in:
@@ -0,0 +1,504 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
export type Permission =
|
||||
| 'view'
|
||||
| 'analyze'
|
||||
| 'draftReply'
|
||||
| 'record'
|
||||
| 'adoptAction'
|
||||
| 'completeAction'
|
||||
| 'reviewQuality'
|
||||
| 'manageKnowledge'
|
||||
export type Scenario = 'initial' | 'followup' | 'revisit'
|
||||
export type Days = 7 | 30 | 90
|
||||
export type JobStatus = 'queued' | 'running' | 'ready' | 'failed' | 'needs_reconciliation' | 'stale'
|
||||
export interface Page<T> {
|
||||
lists: T[]
|
||||
count: number
|
||||
page_no: number
|
||||
page_size: number
|
||||
}
|
||||
export interface Capabilities {
|
||||
enabled: boolean
|
||||
ready: boolean
|
||||
reason: string
|
||||
schema_ready: boolean
|
||||
permissions: Permission[]
|
||||
scenarios: Array<{ value: Scenario; label: string }>
|
||||
limits: { max_manual_chars: number; max_source_chars: number }
|
||||
}
|
||||
export interface Patient {
|
||||
diagnosis_id: number
|
||||
patient_id: number
|
||||
patient_name: string
|
||||
phone_masked?: string
|
||||
assistant_id: number
|
||||
}
|
||||
export interface Staff {
|
||||
id: number
|
||||
name: string
|
||||
is_self: boolean
|
||||
assistant?: boolean
|
||||
role_name?: string
|
||||
}
|
||||
export interface StaffCase extends Patient {
|
||||
im_messages: number | null
|
||||
manual_records: number
|
||||
last_activity_at: number
|
||||
}
|
||||
export interface StaffQuality {
|
||||
key: string
|
||||
label: string
|
||||
met: number
|
||||
missed: number
|
||||
insufficient: number
|
||||
not_applicable: number
|
||||
confirmed: number
|
||||
dismissed: number
|
||||
unreviewed: number
|
||||
}
|
||||
export interface StaffOverview {
|
||||
staff: Staff
|
||||
days: Days
|
||||
metrics: {
|
||||
assigned_cases: number
|
||||
im_messages: number | null
|
||||
manual_records: number
|
||||
analyzed_cases: number
|
||||
pending_actions: number
|
||||
overdue_actions: number
|
||||
completed_actions: number
|
||||
}
|
||||
quality: StaffQuality[]
|
||||
coverage_notes: string[]
|
||||
}
|
||||
export type TeamFilter = 'all' | 'today_pending' | 'today_done' | 'issues' | 'overdue' | 'attention'
|
||||
export type DailyStatus = 'all' | 'pending' | 'reported' | 'contacted' | 'exempt'
|
||||
export interface DailyCounts {
|
||||
required: number | null
|
||||
contacted: number | null
|
||||
reported: number | null
|
||||
pending: number | null
|
||||
outstanding: number | null
|
||||
exempt: number | null
|
||||
state: 'no_tasks' | 'pending' | 'reported' | 'done' | 'unavailable'
|
||||
}
|
||||
export interface DailyMeta {
|
||||
business_date: string
|
||||
timezone: 'Asia/Shanghai'
|
||||
as_of: number
|
||||
state: 'ready' | 'waiting' | 'partial' | 'unavailable'
|
||||
reason: string
|
||||
last_scan_at: number
|
||||
rule_label: string
|
||||
coverage: Array<{
|
||||
source: string
|
||||
status: 'available' | 'empty' | 'unavailable' | 'not_connected'
|
||||
note: string
|
||||
}>
|
||||
}
|
||||
export interface DailyPatient {
|
||||
key: string
|
||||
patient_id: number
|
||||
patient_name: string
|
||||
diagnosis_id: number
|
||||
diagnosis_ids: number[]
|
||||
status: Exclude<DailyStatus, 'all'>
|
||||
reasons: Array<{ type: 'revisit' | 'action'; label: string; due_at: number; source_id: number }>
|
||||
last_contact_at: number
|
||||
evidence: Array<{
|
||||
type: 'im' | 'revisit_contact' | 'action_completed'
|
||||
id: number
|
||||
at: number
|
||||
label: string
|
||||
}>
|
||||
exempt_reason: string
|
||||
}
|
||||
export interface StaffDailyContacts extends Page<DailyPatient> {
|
||||
staff: Staff
|
||||
daily: DailyMeta
|
||||
summary: DailyCounts
|
||||
}
|
||||
export type StaffAnalysisState =
|
||||
| 'no_sources'
|
||||
| 'pending'
|
||||
| 'queued'
|
||||
| 'running'
|
||||
| 'ready'
|
||||
| 'attention'
|
||||
export interface TeamStaff {
|
||||
staff: Staff
|
||||
today_contact: DailyCounts
|
||||
metrics: StaffOverview['metrics']
|
||||
unreviewed_issues: number
|
||||
last_analyzed_at: number
|
||||
analysis_state: StaffAnalysisState
|
||||
queued_jobs: number
|
||||
running_jobs: number
|
||||
attention_jobs: number
|
||||
}
|
||||
export type AlertStatus = 'open' | 'confirmed' | 'false_positive' | 'followed'
|
||||
export type AlertSeverity = 'high' | 'medium' | 'low'
|
||||
export interface ServiceAlert {
|
||||
id: number
|
||||
staff: Staff
|
||||
patient_id: number
|
||||
patient_name: string
|
||||
diagnosis_id: number
|
||||
channel: 'im' | 'call' | 'wecom'
|
||||
rule_code: string
|
||||
rule_label: string
|
||||
rule_version: number
|
||||
severity: AlertSeverity
|
||||
snippet: string
|
||||
status: AlertStatus
|
||||
occurred_at: number
|
||||
review_note: string
|
||||
reviewed_at: number
|
||||
}
|
||||
export interface AlertPage extends Page<ServiceAlert> {
|
||||
schema_ready: boolean
|
||||
summary: {
|
||||
open: number
|
||||
high_open: number
|
||||
im_open: number
|
||||
call_open: number
|
||||
assistant_open: number
|
||||
doctor_open: number
|
||||
}
|
||||
scan: {
|
||||
enabled: boolean
|
||||
state: 'disabled' | 'ready' | 'waiting' | 'error' | 'unavailable'
|
||||
last_scan_at: number
|
||||
reason: string
|
||||
}
|
||||
coverage: Array<{ channel: string; status: string; note: string }>
|
||||
empty_reason: string
|
||||
}
|
||||
export interface TeamOverview extends Page<TeamStaff> {
|
||||
days: 30
|
||||
daily: DailyMeta
|
||||
daily_summary: DailyCounts
|
||||
summary: {
|
||||
staff_count: number
|
||||
active_staff: number
|
||||
analyzed_cases: number
|
||||
unreviewed_issues: number
|
||||
pending_actions: number
|
||||
overdue_actions: number
|
||||
queued_jobs: number
|
||||
running_jobs: number
|
||||
attention_jobs: number
|
||||
}
|
||||
automation: {
|
||||
enabled: boolean
|
||||
state: 'disabled' | 'running' | 'waiting' | 'error'
|
||||
last_scan_at: number
|
||||
next_scan_at: number
|
||||
interval_seconds: number
|
||||
quiet_seconds: number
|
||||
days: 30
|
||||
reason: string
|
||||
}
|
||||
}
|
||||
export interface StaffIssue {
|
||||
job_id: number
|
||||
version: number
|
||||
diagnosis_id: number
|
||||
patient_name: string
|
||||
item_key: string
|
||||
label: string
|
||||
status: string
|
||||
reason: string
|
||||
decision: '' | 'confirmed'
|
||||
created_at: number
|
||||
}
|
||||
export interface Source {
|
||||
id: string
|
||||
channel: string
|
||||
text: string
|
||||
occurred_at: number
|
||||
speaker: 'patient' | 'service' | 'unknown'
|
||||
actor_admin_id: number
|
||||
quality_eligible: boolean
|
||||
}
|
||||
export interface Coverage {
|
||||
channel: string
|
||||
status: string
|
||||
count: number
|
||||
note: string
|
||||
}
|
||||
export interface Claim {
|
||||
text: string
|
||||
evidence_ids: string[]
|
||||
}
|
||||
export interface SuggestedAction extends Claim {
|
||||
key: string
|
||||
}
|
||||
export interface QualityCheck {
|
||||
key: string
|
||||
label: string
|
||||
status: 'met' | 'missed' | 'not_applicable' | 'insufficient'
|
||||
reason: string
|
||||
evidence_ids: string[]
|
||||
actor_admin_id: number
|
||||
}
|
||||
export interface AnalysisResult {
|
||||
summary: Claim[]
|
||||
needs: Claim[]
|
||||
unresolved: Claim[]
|
||||
tags: Claim[]
|
||||
suggested_actions: SuggestedAction[]
|
||||
quality_checks: QualityCheck[]
|
||||
}
|
||||
export interface ReplyResult {
|
||||
reply: string
|
||||
knowledge_refs: Array<{ id: number; version: number }>
|
||||
evidence_ids: string[]
|
||||
needs_confirmation: boolean
|
||||
reason: string
|
||||
}
|
||||
export type ReviewDecision = 'confirmed' | 'dismissed' | 'not_applicable'
|
||||
export interface Review {
|
||||
id: number
|
||||
item_key: string
|
||||
reviewer_id: number
|
||||
decision: ReviewDecision
|
||||
note: string
|
||||
created_at: number
|
||||
}
|
||||
export interface Job {
|
||||
id: number
|
||||
subject_admin_id: number
|
||||
type: 'analysis' | 'reply'
|
||||
diagnosis_id: number
|
||||
scenario: Scenario
|
||||
status: JobStatus
|
||||
version: number
|
||||
created_at: number
|
||||
updated_at: number
|
||||
error_code: string
|
||||
error_message: string
|
||||
result: AnalysisResult | ReplyResult | null
|
||||
coverage: Coverage[]
|
||||
sources: Source[]
|
||||
reviews: Review[]
|
||||
stale: boolean
|
||||
}
|
||||
export interface Context {
|
||||
subject_admin_id: number
|
||||
patient: Patient
|
||||
sources: Source[]
|
||||
coverage: Coverage[]
|
||||
source_hash: string
|
||||
scope_hash: string
|
||||
days: Days
|
||||
latest_job: Job | null
|
||||
latest_analysis_job: Job | null
|
||||
}
|
||||
export type BusinessState = 'pending' | 'in_progress' | 'completed' | 'cancelled'
|
||||
export interface ServiceAction {
|
||||
id: number
|
||||
diagnosis_id: number
|
||||
patient_name: string
|
||||
content: string
|
||||
contact_required: boolean
|
||||
due_at: number
|
||||
business_state: BusinessState
|
||||
completed_at: number
|
||||
completion_note: string
|
||||
assignee_id: number
|
||||
notification_status: string | number | null
|
||||
}
|
||||
export type KnowledgeStatus = 'draft' | 'published' | 'disabled'
|
||||
export interface Knowledge {
|
||||
id: number
|
||||
question: string
|
||||
answer: string
|
||||
category: string
|
||||
status: KnowledgeStatus
|
||||
version: number
|
||||
source_note: string
|
||||
updated_at: number
|
||||
}
|
||||
export class AssistantServiceError extends Error {
|
||||
constructor(
|
||||
message: string,
|
||||
public readonly code = ''
|
||||
) {
|
||||
super(message)
|
||||
this.name = 'AssistantServiceError'
|
||||
}
|
||||
}
|
||||
interface Envelope<T> {
|
||||
code: number
|
||||
msg?: string
|
||||
data: T
|
||||
}
|
||||
// 异步提交不能因超时自动重发,也不能被相同 URL 的另一患者请求取消。
|
||||
const options = {
|
||||
isTransformResponse: false,
|
||||
ignoreCancelToken: true,
|
||||
isOpenRetry: false,
|
||||
retryCount: 0
|
||||
}
|
||||
const base = '/tcm.assistantService/'
|
||||
function unwrap<T>(response: Envelope<T>): T {
|
||||
if (response.code !== 1) {
|
||||
const data = response.data as { code?: string; error_code?: string } | null
|
||||
throw new AssistantServiceError(
|
||||
response.msg || '请求失败,请刷新后重试',
|
||||
data?.error_code || data?.code || ''
|
||||
)
|
||||
}
|
||||
return response.data
|
||||
}
|
||||
async function get<T>(action: string, params: object = {}, signal?: AbortSignal): Promise<T> {
|
||||
return unwrap(
|
||||
await request.get<Envelope<T>>(
|
||||
{ url: base + action, params, signal, timeout: 30000 },
|
||||
options
|
||||
)
|
||||
)
|
||||
}
|
||||
async function post<T>(action: string, data: object): Promise<T> {
|
||||
return unwrap(
|
||||
await request.post<Envelope<T>>({ url: base + action, data, timeout: 30000 }, options)
|
||||
)
|
||||
}
|
||||
type Paging = { page_no: number; page_size: number }
|
||||
type JobInput = { diagnosis_id: number; days: Days; scenario: Scenario; assistant_id?: number }
|
||||
export type StaffScope = { assistant_id: number; days: Days }
|
||||
export const assistantAlerts = (
|
||||
params: Partial<Paging> & {
|
||||
keyword?: string
|
||||
status?: AlertStatus | 'all'
|
||||
severity?: AlertSeverity | 'all'
|
||||
role?: 'all' | 'assistant' | 'doctor'
|
||||
} = {},
|
||||
signal?: AbortSignal
|
||||
) => get<AlertPage>('alerts', params, signal)
|
||||
export interface WecomDirectory {
|
||||
ready: boolean
|
||||
staff: Array<Staff & { conversations: number }>
|
||||
accounts: Array<{ external_id: string; name: string; conversations: number }>
|
||||
}
|
||||
export interface WecomConversation {
|
||||
id: string
|
||||
name: string
|
||||
conversation_type: string
|
||||
last_message_at: string
|
||||
message_count: number
|
||||
preview: string
|
||||
account: string
|
||||
}
|
||||
export interface WecomMessage {
|
||||
id: string
|
||||
sent_at: string
|
||||
direction: string
|
||||
message_type: string
|
||||
sender_name: string
|
||||
content: string
|
||||
}
|
||||
export const assistantWecomDirectory = (signal?: AbortSignal) =>
|
||||
get<WecomDirectory>('wecomDirectory', {}, signal)
|
||||
export const assistantWecomChats = (
|
||||
params: { assistant_id?: number; account?: string },
|
||||
signal?: AbortSignal
|
||||
) => get<{ conversations: WecomConversation[] }>('wecomChats', params, signal)
|
||||
export const assistantWecomMessages = (
|
||||
params: { assistant_id?: number; account?: string; conversation_id: string },
|
||||
signal?: AbortSignal
|
||||
) => get<{ messages: WecomMessage[] }>('wecomMessages', params, signal)
|
||||
export const assistantReviewAlert = (data: {
|
||||
id: number
|
||||
status: Exclude<AlertStatus, 'open'>
|
||||
note: string
|
||||
}) => post<{ id: number; status: string }>('reviewAlert', data)
|
||||
export const assistantTeamOverview = (
|
||||
params: Partial<Paging> & { keyword?: string; filter?: TeamFilter } = {},
|
||||
signal?: AbortSignal
|
||||
) => get<TeamOverview>('teamOverview', params, signal)
|
||||
export const assistantStaff = (
|
||||
params: Partial<Paging> & { keyword?: string } = {},
|
||||
signal?: AbortSignal
|
||||
) => get<Page<Staff>>('staff', params, signal)
|
||||
export const assistantStaffOverview = (params: StaffScope, signal?: AbortSignal) =>
|
||||
get<StaffOverview>('staffOverview', params, signal)
|
||||
export const assistantStaffDailyContacts = (
|
||||
params: Partial<Paging> & { assistant_id: number; status?: DailyStatus },
|
||||
signal?: AbortSignal
|
||||
) => get<StaffDailyContacts>('staffDailyContacts', params, signal)
|
||||
export const assistantStaffCases = (
|
||||
params: StaffScope & Partial<Paging> & { keyword?: string },
|
||||
signal?: AbortSignal
|
||||
) => get<Page<StaffCase>>('staffCases', params, signal)
|
||||
export const assistantStaffIssues = (params: StaffScope & Partial<Paging>, signal?: AbortSignal) =>
|
||||
get<Page<StaffIssue>>('staffIssues', params, signal)
|
||||
export const assistantAnalyzeStaff = (
|
||||
data: StaffScope & { scenario: Scenario; diagnosis_ids: number[] }
|
||||
) => post<{ jobs: Job[]; count: number }>('analyzeStaff', data)
|
||||
export const assistantCapabilities = (signal?: AbortSignal) =>
|
||||
get<Capabilities>('capabilities', {}, signal)
|
||||
export const assistantPatients = (params: Paging & { keyword?: string }, signal?: AbortSignal) =>
|
||||
get<Page<Patient>>('patients', params, signal)
|
||||
export const assistantContext = (
|
||||
params: { diagnosis_id: number; days: Days; assistant_id?: number },
|
||||
signal?: AbortSignal
|
||||
) => get<Context>('context', params, signal)
|
||||
export const assistantRecord = (data: {
|
||||
diagnosis_id: number
|
||||
content: string
|
||||
occurred_at: number
|
||||
record_type: 'service_note' | 'verified_transcript'
|
||||
speaker_confirmed: boolean
|
||||
}) => post<{ id: number }>('record', data)
|
||||
export const assistantAnalyze = (data: JobInput) => post<Job>('analyze', data)
|
||||
export const assistantDraftReply = (data: JobInput & { question: string }) =>
|
||||
post<Job>('draftReply', data)
|
||||
export const assistantJob = (id: number, signal?: AbortSignal) => get<Job>('job', { id }, signal)
|
||||
export const assistantJobs = (
|
||||
params: Paging & { diagnosis_id?: number; status?: JobStatus; assistant_id?: number },
|
||||
signal?: AbortSignal
|
||||
) => get<Page<Job>>('jobs', params, signal)
|
||||
export const assistantReviewQuality = (data: {
|
||||
job_id: number
|
||||
item_key: string
|
||||
decision: ReviewDecision
|
||||
note: string
|
||||
version: number
|
||||
}) => post<{ id: number }>('reviewQuality', data)
|
||||
export const assistantAdoptAction = (data: {
|
||||
job_id: number
|
||||
action_key: string
|
||||
version: number
|
||||
due_at: number
|
||||
content?: string
|
||||
contact_required?: boolean
|
||||
}) => post<{ id: number; todo_id: number }>('adoptAction', data)
|
||||
export const assistantActions = (
|
||||
params: Paging & { diagnosis_id?: number; state?: BusinessState; assistant_id?: number },
|
||||
signal?: AbortSignal
|
||||
) => get<Page<ServiceAction>>('actions', params, signal)
|
||||
export const assistantCompleteAction = (data: {
|
||||
id: number
|
||||
state: Exclude<BusinessState, 'pending'>
|
||||
note: string
|
||||
}) => post<{ id: number }>('completeAction', data)
|
||||
export const assistantKnowledge = (
|
||||
params: Paging & { keyword?: string; status?: KnowledgeStatus },
|
||||
signal?: AbortSignal
|
||||
) => get<Page<Knowledge>>('knowledge', params, signal)
|
||||
export const assistantSaveKnowledge = (data: {
|
||||
id?: number
|
||||
version?: number
|
||||
question: string
|
||||
answer: string
|
||||
category: string
|
||||
source_note: string
|
||||
}) => post<{ id: number; version: number }>('saveKnowledge', data)
|
||||
export const assistantPublishKnowledge = (data: {
|
||||
id: number
|
||||
version: number
|
||||
status: 'published' | 'disabled'
|
||||
}) => post<{ id: number; version: number }>('publishKnowledge', data)
|
||||
@@ -0,0 +1,879 @@
|
||||
<template>
|
||||
<section class="alert-inbox" aria-label="医助行为预警">
|
||||
<el-alert
|
||||
v-if="data?.scan.reason"
|
||||
:title="data.scan.reason"
|
||||
type="warning"
|
||||
:closable="false"
|
||||
show-icon
|
||||
class="scan-note"
|
||||
/>
|
||||
<div v-if="data" class="metric-strip" aria-label="预警汇总">
|
||||
<article class="metric" :class="{ 'metric--attention': data.summary.open > 0 }">
|
||||
<span>待处理</span>
|
||||
<strong>{{ data.summary.open }}</strong>
|
||||
<small>还没有人复核</small>
|
||||
</article>
|
||||
<article class="metric" :class="{ 'metric--high': data.summary.high_open > 0 }">
|
||||
<span>高风险</span>
|
||||
<strong>{{ data.summary.high_open }}</strong>
|
||||
<small>诊疗、承诺、脱离平台</small>
|
||||
</article>
|
||||
<article class="metric">
|
||||
<span>聊天命中</span>
|
||||
<strong>{{ data.summary.im_open }}</strong>
|
||||
<small>员工侧已归档文字</small>
|
||||
</article>
|
||||
<article class="metric" :class="{ 'metric--attention': callCoverage?.status === 'available' && data.summary.call_open > 0 }">
|
||||
<span>通话转写</span>
|
||||
<strong v-if="callCoverage?.status === 'available'">{{ data.summary.call_open }}</strong>
|
||||
<strong v-else class="metric-text">{{ callMetric }}</strong>
|
||||
<small>{{ callCoverage?.status === 'available' ? '员工侧转写命中' : callMetricNote }}</small>
|
||||
</article>
|
||||
</div>
|
||||
<div class="inbox-panel">
|
||||
<div class="table-heading">
|
||||
<div>
|
||||
<h2>命中记录</h2>
|
||||
<p class="muted">一条记录是一名员工、一条规则、一处原文。没有记录不等于今天没有沟通。</p>
|
||||
</div>
|
||||
<form class="search-form" @submit.prevent="search">
|
||||
<el-input
|
||||
v-model="keyword"
|
||||
aria-label="搜索预警"
|
||||
placeholder="搜索员工或患者"
|
||||
clearable
|
||||
@clear="search"
|
||||
/>
|
||||
<el-button native-type="submit">搜索</el-button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="role-switch" role="group" aria-label="按身份查看">
|
||||
<button
|
||||
type="button"
|
||||
:class="{ active: role === 'assistant' }"
|
||||
:aria-pressed="role === 'assistant'"
|
||||
@click="setRole('assistant')"
|
||||
>
|
||||
<span>医助</span>
|
||||
<strong>{{ data?.summary.assistant_open ?? 0 }}</strong>
|
||||
<small>待处理</small>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
:class="{ active: role === 'doctor' }"
|
||||
:aria-pressed="role === 'doctor'"
|
||||
@click="setRole('doctor')"
|
||||
>
|
||||
<span>医生</span>
|
||||
<strong>{{ data?.summary.doctor_open ?? 0 }}</strong>
|
||||
<small>待处理</small>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="role-switch__all"
|
||||
:class="{ active: role === 'all' }"
|
||||
:aria-pressed="role === 'all'"
|
||||
@click="setRole('all')"
|
||||
>
|
||||
全部身份
|
||||
</button>
|
||||
</div>
|
||||
<section v-if="role === 'assistant'" class="chat-workspace" aria-label="企微聊天">
|
||||
<aside class="people-pane">
|
||||
<p class="pane-label">企微账号</p>
|
||||
<button
|
||||
v-for="account in directory?.accounts || []"
|
||||
:key="account.external_id"
|
||||
type="button"
|
||||
:class="{ active: selected.account === account.external_id }"
|
||||
@click="choosePerson({ id: 0, name: account.name || '未命名账号', account: account.external_id })"
|
||||
>
|
||||
<strong>{{ account.name || '未命名账号' }}</strong>
|
||||
<small>{{ account.conversations }} 个会话</small>
|
||||
</button>
|
||||
<p class="pane-label">已关联医助</p>
|
||||
<button
|
||||
v-for="person in linkedStaff"
|
||||
:key="person.id"
|
||||
type="button"
|
||||
:class="{ active: selected.id === person.id && !selected.account }"
|
||||
@click="choosePerson({ id: person.id, name: person.name, account: '' })"
|
||||
>
|
||||
<strong>{{ person.name || '未命名医助' }}</strong>
|
||||
<small>{{ person.conversations }} 个会话</small>
|
||||
</button>
|
||||
<p v-if="!linkedStaff.length" class="pane-note">还没有医助和企微账号同名或绑定了同一个 UserId。</p>
|
||||
</aside>
|
||||
<div class="chat-pane">
|
||||
<h3>{{ selected.name || '选择左侧的人' }}</h3>
|
||||
<WecomThread
|
||||
v-if="selected.id || selected.account"
|
||||
:assistant-id="selected.id"
|
||||
:account="selected.account"
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
<div v-if="role !== 'assistant'" class="table-toolbar">
|
||||
<div class="filter-group" role="group" aria-label="筛选预警">
|
||||
<button
|
||||
v-for="item in filters"
|
||||
:key="item.value"
|
||||
type="button"
|
||||
:aria-pressed="filter === item.value"
|
||||
:class="{ active: filter === item.value }"
|
||||
@click="setFilter(item.value)"
|
||||
>
|
||||
{{ item.label }}
|
||||
</button>
|
||||
</div>
|
||||
<span class="muted">{{
|
||||
data?.scan.last_scan_at
|
||||
? `最近扫描 ${shanghaiTime(data.scan.last_scan_at)}`
|
||||
: '扫描时间待确认'
|
||||
}}</span>
|
||||
</div>
|
||||
<el-alert
|
||||
v-if="error"
|
||||
:title="error"
|
||||
type="error"
|
||||
:closable="false"
|
||||
show-icon
|
||||
class="table-error"
|
||||
/>
|
||||
<el-skeleton v-if="role !== 'assistant' && loading && !data" :rows="6" animated class="table-skeleton" />
|
||||
<ul v-else-if="role !== 'assistant' && data?.lists.length" v-loading="loading" class="feed">
|
||||
<li
|
||||
v-for="row in data.lists"
|
||||
:key="row.id"
|
||||
:class="['feed-item', `feed-item--${roleKind(row)}`]"
|
||||
>
|
||||
<div class="feed-main">
|
||||
<div class="feed-who">
|
||||
<span :class="['role-pill', `role-pill--${roleKind(row)}`]">{{
|
||||
row.staff.role_name || '员工'
|
||||
}}</span>
|
||||
<button
|
||||
v-if="row.staff.assistant"
|
||||
type="button"
|
||||
class="staff-link"
|
||||
@click="choosePerson({ id: row.staff.id, name: row.staff.name, account: '' })"
|
||||
>
|
||||
{{ row.staff.name || '未命名医助' }}
|
||||
</button>
|
||||
<strong v-else>{{ row.staff.name || '未命名员工' }}</strong>
|
||||
<span class="patient">{{ row.patient_name || '未命名患者' }}</span>
|
||||
<small v-if="row.diagnosis_id">诊单 #{{ row.diagnosis_id }}</small>
|
||||
</div>
|
||||
<p class="snippet">{{ row.snippet }}</p>
|
||||
<p v-if="row.review_note" class="review-note">复核:{{ row.review_note }}</p>
|
||||
<div class="feed-meta">
|
||||
<time class="number">{{ shanghaiTime(row.occurred_at) }}</time>
|
||||
<span :class="['severity', `severity--${row.severity}`]"
|
||||
>{{ severityLabels[row.severity] }} · {{ row.rule_label }}</span
|
||||
>
|
||||
<span>{{ channelLabel(row.channel) }}</span>
|
||||
<span>{{ statusLabels[row.status] }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="canReview" class="feed-actions">
|
||||
<div class="review-actions">
|
||||
<button
|
||||
type="button"
|
||||
:disabled="row.status === 'confirmed'"
|
||||
@click="review(row, 'confirmed')"
|
||||
>
|
||||
成立
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
:disabled="row.status === 'false_positive'"
|
||||
@click="review(row, 'false_positive')"
|
||||
>
|
||||
误报
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
:disabled="row.status === 'followed'"
|
||||
@click="review(row, 'followed')"
|
||||
>
|
||||
已跟进
|
||||
</button>
|
||||
</div>
|
||||
<form
|
||||
v-if="noteTarget === row.id"
|
||||
class="note-form"
|
||||
@submit.prevent="review(row, 'false_positive')"
|
||||
>
|
||||
<el-input
|
||||
v-model="note"
|
||||
aria-label="误报原因"
|
||||
maxlength="200"
|
||||
placeholder="填写误报原因"
|
||||
/>
|
||||
<el-button native-type="submit" link type="primary">提交</el-button>
|
||||
</form>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
<el-empty v-else-if="role !== 'assistant'" :image-size="80" :description="emptyDescription" />
|
||||
<footer v-if="role !== 'assistant'" class="table-footer">
|
||||
<span class="muted">{{ coverageText }}</span>
|
||||
<el-pagination
|
||||
v-if="data?.count"
|
||||
v-model:current-page="page"
|
||||
:total="data.count"
|
||||
:page-size="20"
|
||||
layout="total, prev, pager, next"
|
||||
@current-change="changePage"
|
||||
/>
|
||||
</footer>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { computed, onActivated, onBeforeUnmount, onDeactivated, onMounted, ref, watch } from 'vue'
|
||||
import {
|
||||
assistantAlerts,
|
||||
assistantReviewAlert,
|
||||
assistantWecomDirectory,
|
||||
type AlertPage,
|
||||
type AlertSeverity,
|
||||
type AlertStatus,
|
||||
type ServiceAlert,
|
||||
type Staff,
|
||||
type WecomDirectory
|
||||
} from '@/api/assistantService'
|
||||
import WecomThread from './WecomThread.vue'
|
||||
import { errorText, isCancelled, shanghaiTime } from '../shared'
|
||||
|
||||
const props = defineProps<{ refreshKey: number; canReview: boolean }>()
|
||||
const emit = defineEmits<{ 'open-staff': [staff: Staff] }>()
|
||||
const data = ref<AlertPage | null>(null)
|
||||
const loading = ref(false)
|
||||
const error = ref('')
|
||||
const keyword = ref('')
|
||||
const keywordApplied = ref('')
|
||||
const filter = ref('open')
|
||||
const role = ref<'all' | 'assistant' | 'doctor'>('all')
|
||||
const page = ref(1)
|
||||
const note = ref('')
|
||||
const noteTarget = ref(0)
|
||||
const directory = ref<WecomDirectory | null>(null)
|
||||
const selected = ref({ id: 0, name: '', account: '' })
|
||||
const linkedStaff = computed(() => (directory.value?.staff || []).filter((person) => person.conversations > 0))
|
||||
const filters: Array<{
|
||||
value: string
|
||||
label: string
|
||||
status: AlertStatus | 'all'
|
||||
severity: AlertSeverity | 'all'
|
||||
}> = [
|
||||
{ value: 'open', label: '待处理', status: 'open', severity: 'all' },
|
||||
{ value: 'high', label: '高风险', status: 'open', severity: 'high' },
|
||||
{ value: 'all', label: '全部', status: 'all', severity: 'all' },
|
||||
{ value: 'confirmed', label: '已成立', status: 'confirmed', severity: 'all' },
|
||||
{ value: 'false_positive', label: '误报', status: 'false_positive', severity: 'all' },
|
||||
{ value: 'followed', label: '已跟进', status: 'followed', severity: 'all' }
|
||||
]
|
||||
const statusLabels: Record<AlertStatus, string> = {
|
||||
open: '待处理',
|
||||
confirmed: '已成立',
|
||||
false_positive: '误报',
|
||||
followed: '已跟进'
|
||||
}
|
||||
const severityLabels: Record<AlertSeverity, string> = { high: '高', medium: '中', low: '低' }
|
||||
const activeFilter = computed(() => filters.find((item) => item.value === filter.value) || filters[0])
|
||||
const coverageText = computed(
|
||||
() => data.value?.coverage.map((item) => item.note).join(' · ') || '通话转写和企微尚未接入'
|
||||
)
|
||||
const callCoverage = computed(() => data.value?.coverage.find((item) => item.channel === 'call'))
|
||||
const callMetric = computed(() => {
|
||||
if (callCoverage.value?.status === 'no_transcript') return '无正文'
|
||||
if (callCoverage.value?.status === 'not_scanned') return '未检查'
|
||||
return '未接入'
|
||||
})
|
||||
const callMetricNote = computed(() => {
|
||||
if (callCoverage.value?.status === 'no_transcript') return '医助主叫没有可判定转写'
|
||||
if (callCoverage.value?.status === 'not_scanned') return '已有转写,尚未写入预警'
|
||||
return '有录音也不计为已检查'
|
||||
})
|
||||
const emptyDescription = computed(() => {
|
||||
if (error.value) return '暂时无法读取预警,请重试'
|
||||
if (data.value && !data.value.schema_ready) return '预警表尚未就绪'
|
||||
if (data.value?.scan.state === 'disabled') return '预警扫描尚未开启'
|
||||
if (data.value?.scan.state === 'waiting' && !data.value.scan.last_scan_at) return '尚未完成首次扫描'
|
||||
if (filter.value === 'open' && role.value === 'assistant') return '当前没有医助的待处理预警'
|
||||
if (filter.value === 'open' && role.value === 'doctor') return '当前没有医生的待处理预警'
|
||||
if (filter.value === 'open' && data.value?.empty_reason) return data.value.empty_reason
|
||||
if (filter.value === 'open') return '当前没有待处理预警'
|
||||
return '当前筛选下没有预警'
|
||||
})
|
||||
let disposed = false,
|
||||
activated = true,
|
||||
mounted = false,
|
||||
listening = false,
|
||||
revision = 0
|
||||
let request: AbortController | undefined
|
||||
let timer: ReturnType<typeof setTimeout> | undefined
|
||||
const visible = () =>
|
||||
activated && (typeof document === 'undefined' || document.visibilityState !== 'hidden')
|
||||
function roleKind(row: ServiceAlert) {
|
||||
if (row.staff.assistant || row.staff.role_name === '医助') return 'assistant'
|
||||
if (row.staff.role_name === '医生') return 'doctor'
|
||||
return 'other'
|
||||
}
|
||||
function channelLabel(channel: string) {
|
||||
if (channel === 'call') return '通话'
|
||||
if (channel === 'wecom') return '企微'
|
||||
if (channel === 'im') return '聊天'
|
||||
return '其他'
|
||||
}
|
||||
function stopTimer() {
|
||||
if (timer) clearTimeout(timer)
|
||||
timer = undefined
|
||||
}
|
||||
function schedule() {
|
||||
stopTimer()
|
||||
if (!disposed && mounted && visible()) timer = setTimeout(() => void load(true), 30000)
|
||||
}
|
||||
async function load(silent = false) {
|
||||
if (disposed || !visible()) return false
|
||||
const token = ++revision
|
||||
request?.abort()
|
||||
request = new AbortController()
|
||||
if (!silent) loading.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
const result = await assistantAlerts(
|
||||
{
|
||||
keyword: keywordApplied.value,
|
||||
status: activeFilter.value.status,
|
||||
severity: activeFilter.value.severity,
|
||||
role: role.value,
|
||||
page_no: page.value,
|
||||
page_size: 20
|
||||
},
|
||||
request.signal
|
||||
)
|
||||
if (disposed || token !== revision) return false
|
||||
if (!result.summary || !result.scan || !Array.isArray(result.lists)) {
|
||||
throw new Error('预警数据不完整,请刷新后重试')
|
||||
}
|
||||
data.value = result
|
||||
return true
|
||||
} catch (cause) {
|
||||
if (!disposed && token !== revision && !isCancelled(cause)) {
|
||||
if (!silent) data.value = null
|
||||
error.value = errorText(cause)
|
||||
}
|
||||
return false
|
||||
} finally {
|
||||
if (!disposed && token === revision) {
|
||||
loading.value = false
|
||||
schedule()
|
||||
}
|
||||
}
|
||||
}
|
||||
function search() {
|
||||
keywordApplied.value = keyword.value.trim()
|
||||
page.value = 1
|
||||
void load()
|
||||
}
|
||||
function setFilter(value: string) {
|
||||
if (filter.value === value) return
|
||||
filter.value = value
|
||||
page.value = 1
|
||||
noteTarget.value = 0
|
||||
void load()
|
||||
}
|
||||
let directoryTimer: ReturnType<typeof setTimeout> | undefined
|
||||
function stopDirectoryTimer() {
|
||||
if (directoryTimer) clearTimeout(directoryTimer)
|
||||
directoryTimer = undefined
|
||||
}
|
||||
function scheduleDirectory() {
|
||||
stopDirectoryTimer()
|
||||
if (!disposed && role.value === 'assistant') directoryTimer = setTimeout(() => void loadDirectory(true), 15000)
|
||||
}
|
||||
async function loadDirectory(silent = false) {
|
||||
try {
|
||||
const result = await assistantWecomDirectory()
|
||||
if (disposed) return
|
||||
directory.value = result
|
||||
const current = selected.value
|
||||
const stillAccount = result.accounts.some((item) => item.external_id === current.account)
|
||||
const stillStaff = result.staff.some((item) => item.id === current.id && !current.account)
|
||||
if (!stillAccount && !stillStaff) {
|
||||
const account = result.accounts.find((item) => item.conversations > 0) || result.accounts[0]
|
||||
if (account) {
|
||||
selected.value = { id: 0, name: account.name || '未命名账号', account: account.external_id }
|
||||
}
|
||||
}
|
||||
} catch (cause) {
|
||||
if (!disposed && !isCancelled(cause) && !silent) error.value = errorText(cause)
|
||||
} finally {
|
||||
scheduleDirectory()
|
||||
}
|
||||
}
|
||||
function choosePerson(target: { id: number; name: string; account: string }) {
|
||||
selected.value = target
|
||||
if (role.value !== 'assistant') {
|
||||
role.value = 'assistant'
|
||||
page.value = 1
|
||||
void load()
|
||||
}
|
||||
}
|
||||
function setRole(value: 'all' | 'assistant' | 'doctor') {
|
||||
if (role.value === value) return
|
||||
role.value = value
|
||||
page.value = 1
|
||||
noteTarget.value = 0
|
||||
if (value === 'assistant') void loadDirectory()
|
||||
else stopDirectoryTimer()
|
||||
void load()
|
||||
}
|
||||
function changePage() {
|
||||
void load()
|
||||
}
|
||||
function openStaff(row: ServiceAlert) {
|
||||
emit('open-staff', row.staff)
|
||||
}
|
||||
async function review(row: ServiceAlert, status: Exclude<AlertStatus, 'open'>) {
|
||||
if (!props.canReview || row.status === status) return
|
||||
if (status === 'false_positive' && note.value.trim() === '') {
|
||||
noteTarget.value = row.id
|
||||
note.value = ''
|
||||
return
|
||||
}
|
||||
try {
|
||||
await assistantReviewAlert({
|
||||
id: row.id,
|
||||
status,
|
||||
note: status === 'false_positive' ? note.value.trim() : ''
|
||||
})
|
||||
noteTarget.value = 0
|
||||
note.value = ''
|
||||
await load(true)
|
||||
} catch (cause) {
|
||||
if (!isCancelled(cause)) error.value = errorText(cause)
|
||||
}
|
||||
}
|
||||
function updateVisibility() {
|
||||
if (!visible()) {
|
||||
stopTimer()
|
||||
request?.abort()
|
||||
revision++
|
||||
loading.value = false
|
||||
return
|
||||
}
|
||||
void load(true)
|
||||
}
|
||||
watch(
|
||||
() => props.refreshKey,
|
||||
(_value, previous) => void load(previous !== undefined),
|
||||
{ immediate: true, flush: 'sync' }
|
||||
)
|
||||
onMounted(() => {
|
||||
mounted = true
|
||||
if (typeof document !== 'undefined') {
|
||||
document.addEventListener('visibilitychange', updateVisibility)
|
||||
listening = true
|
||||
}
|
||||
schedule()
|
||||
})
|
||||
onActivated(() => {
|
||||
activated = true
|
||||
})
|
||||
onDeactivated(() => {
|
||||
activated = false
|
||||
updateVisibility()
|
||||
})
|
||||
onBeforeUnmount(() => {
|
||||
disposed = true
|
||||
stopTimer()
|
||||
stopDirectoryTimer()
|
||||
request?.abort()
|
||||
revision++
|
||||
if (listening && typeof document !== 'undefined') {
|
||||
document.removeEventListener('visibilitychange', updateVisibility)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
<style scoped>
|
||||
.alert-inbox {
|
||||
color: var(--el-text-color-primary);
|
||||
}
|
||||
.scan-note {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.metric-strip {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
background: var(--el-bg-color);
|
||||
border: 1px solid var(--el-border-color-light);
|
||||
border-radius: 5px;
|
||||
padding: 20px 0;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.metric {
|
||||
padding: 0 22px;
|
||||
border-right: 1px solid var(--el-border-color-lighter);
|
||||
}
|
||||
.metric:last-child {
|
||||
border-right: 0;
|
||||
}
|
||||
.metric > span,
|
||||
.metric small {
|
||||
display: block;
|
||||
color: var(--el-text-color-secondary);
|
||||
font-size: 12px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.metric strong {
|
||||
display: block;
|
||||
margin: 6px 0 3px;
|
||||
font-size: 27px;
|
||||
line-height: 1.15;
|
||||
font-weight: 600;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.metric-text {
|
||||
font-size: 22px;
|
||||
font-variant-numeric: normal;
|
||||
}
|
||||
.metric--attention strong {
|
||||
color: var(--el-color-primary);
|
||||
}
|
||||
.metric--high strong {
|
||||
color: var(--el-color-danger);
|
||||
}
|
||||
.inbox-panel {
|
||||
background: var(--el-bg-color);
|
||||
border: 1px solid var(--el-border-color-light);
|
||||
border-radius: 5px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.table-heading,
|
||||
.table-toolbar,
|
||||
.table-footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.table-heading {
|
||||
padding: 22px 22px 14px;
|
||||
}
|
||||
.table-heading h2 {
|
||||
margin: 0;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.table-heading p,
|
||||
.muted,
|
||||
small {
|
||||
color: var(--el-text-color-secondary);
|
||||
font-size: 12px;
|
||||
line-height: 1.7;
|
||||
}
|
||||
.table-heading p {
|
||||
margin: 5px 0 0;
|
||||
}
|
||||
.search-form {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
width: 290px;
|
||||
max-width: 100%;
|
||||
}
|
||||
.role-switch {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr auto;
|
||||
gap: 10px;
|
||||
padding: 0 22px 16px;
|
||||
}
|
||||
.role-switch button {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 10px;
|
||||
padding: 14px 16px;
|
||||
border: 1px solid var(--el-border-color-light);
|
||||
border-radius: 8px;
|
||||
background: var(--el-fill-color-blank);
|
||||
cursor: pointer;
|
||||
text-align: left;
|
||||
color: var(--el-text-color-primary);
|
||||
}
|
||||
.role-switch button span {
|
||||
font-size: 14px;
|
||||
font-weight: 650;
|
||||
}
|
||||
.role-switch button strong {
|
||||
font-size: 26px;
|
||||
line-height: 1;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.role-switch button small {
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
.role-switch button:first-child strong {
|
||||
color: #0f766e;
|
||||
}
|
||||
.role-switch button:nth-child(2) strong {
|
||||
color: #1e4b8a;
|
||||
}
|
||||
.role-switch button.active:first-child {
|
||||
border-color: #0f766e;
|
||||
background: #f0fdfa;
|
||||
}
|
||||
.role-switch button.active:nth-child(2) {
|
||||
border-color: #1e4b8a;
|
||||
background: #eff6ff;
|
||||
}
|
||||
.role-switch__all {
|
||||
align-items: center;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.role-switch__all.active {
|
||||
border-color: var(--el-color-primary);
|
||||
color: var(--el-color-primary);
|
||||
}
|
||||
.chat-workspace {
|
||||
display: grid;
|
||||
grid-template-columns: 240px 1fr;
|
||||
gap: 16px;
|
||||
min-height: 560px;
|
||||
padding: 0 16px 16px;
|
||||
}
|
||||
.people-pane,
|
||||
.chat-pane {
|
||||
min-width: 0;
|
||||
}
|
||||
.people-pane {
|
||||
padding: 8px;
|
||||
border: 1px solid var(--el-border-color-lighter);
|
||||
border-radius: 10px;
|
||||
background: var(--el-fill-color-blank);
|
||||
}
|
||||
.pane-label,
|
||||
.pane-note {
|
||||
margin: 8px 8px 6px;
|
||||
color: var(--el-text-color-secondary);
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.people-pane button {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
justify-content: space-between;
|
||||
align-items: baseline;
|
||||
gap: 8px;
|
||||
margin-bottom: 6px;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 8px;
|
||||
background: transparent;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
}
|
||||
.people-pane button.active {
|
||||
border-color: #1e4b8a;
|
||||
background: #eff6ff;
|
||||
}
|
||||
.people-pane strong {
|
||||
font-size: 14px;
|
||||
}
|
||||
.people-pane small {
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
.chat-pane {
|
||||
padding: 8px 8px 8px 4px;
|
||||
}
|
||||
.chat-pane h3 {
|
||||
margin: 0 0 12px;
|
||||
font-size: 18px;
|
||||
}
|
||||
@media (max-width: 900px) {
|
||||
.chat-workspace {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
.feed {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0 12px 8px;
|
||||
}
|
||||
.feed-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 18px;
|
||||
margin-bottom: 10px;
|
||||
padding: 14px 16px 14px 14px;
|
||||
border: 1px solid var(--el-border-color-lighter);
|
||||
border-left-width: 4px;
|
||||
border-radius: 8px;
|
||||
background: var(--el-bg-color);
|
||||
}
|
||||
.feed-item--assistant {
|
||||
border-left-color: #0f766e;
|
||||
}
|
||||
.feed-item--doctor {
|
||||
border-left-color: #1e4b8a;
|
||||
}
|
||||
.feed-item--other {
|
||||
border-left-color: var(--el-border-color);
|
||||
}
|
||||
.feed-main {
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
}
|
||||
.feed-who {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
.role-pill {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
height: 22px;
|
||||
padding: 0 8px;
|
||||
border-radius: 999px;
|
||||
font-size: 12px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.04em;
|
||||
}
|
||||
.role-pill--assistant {
|
||||
color: #0f766e;
|
||||
background: #ccfbf1;
|
||||
}
|
||||
.role-pill--doctor {
|
||||
color: #1e4b8a;
|
||||
background: #dbeafe;
|
||||
}
|
||||
.role-pill--other {
|
||||
color: var(--el-text-color-regular);
|
||||
background: var(--el-fill-color);
|
||||
}
|
||||
.patient {
|
||||
color: var(--el-text-color-regular);
|
||||
}
|
||||
.feed-who small {
|
||||
margin: 0;
|
||||
}
|
||||
.snippet {
|
||||
margin: 8px 0 0;
|
||||
font-size: 14px;
|
||||
line-height: 1.65;
|
||||
}
|
||||
.review-note {
|
||||
margin: 4px 0 0;
|
||||
color: var(--el-text-color-secondary);
|
||||
font-size: 12px;
|
||||
}
|
||||
.feed-meta {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px 14px;
|
||||
margin-top: 8px;
|
||||
color: var(--el-text-color-secondary);
|
||||
font-size: 12px;
|
||||
}
|
||||
.feed-actions {
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
.table-toolbar {
|
||||
padding: 0 22px 16px;
|
||||
}
|
||||
.filter-group {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
padding: 3px;
|
||||
border-radius: 4px;
|
||||
background: var(--el-fill-color-light);
|
||||
}
|
||||
.filter-group button,
|
||||
.review-actions button {
|
||||
cursor: pointer;
|
||||
border: 0;
|
||||
padding: 7px 12px;
|
||||
border-radius: 3px;
|
||||
font-size: 12px;
|
||||
background: transparent;
|
||||
color: var(--el-text-color-regular);
|
||||
}
|
||||
.filter-group button.active {
|
||||
background: var(--el-bg-color);
|
||||
color: var(--el-color-primary);
|
||||
font-weight: 600;
|
||||
}
|
||||
.review-actions {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
}
|
||||
.review-actions button:disabled {
|
||||
cursor: default;
|
||||
color: var(--el-text-color-placeholder);
|
||||
}
|
||||
.note-form {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
margin-top: 8px;
|
||||
}
|
||||
.table-error {
|
||||
margin: 0 22px 16px;
|
||||
width: auto;
|
||||
}
|
||||
.table-skeleton {
|
||||
padding: 22px;
|
||||
}
|
||||
.alert-table small {
|
||||
display: block;
|
||||
margin-top: 2px;
|
||||
}
|
||||
.staff-link {
|
||||
border: 0;
|
||||
background: transparent;
|
||||
padding: 0;
|
||||
cursor: pointer;
|
||||
color: var(--el-color-primary);
|
||||
font-size: 13px;
|
||||
}
|
||||
.severity {
|
||||
display: inline-block;
|
||||
margin-right: 6px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.severity--high {
|
||||
color: var(--el-color-danger);
|
||||
}
|
||||
.severity--medium {
|
||||
color: var(--el-color-warning);
|
||||
}
|
||||
.snippet {
|
||||
quotes: none;
|
||||
font-style: normal;
|
||||
}
|
||||
.number {
|
||||
font-variant-numeric: tabular-nums;
|
||||
font-size: 13px;
|
||||
}
|
||||
.table-footer {
|
||||
padding: 16px 22px;
|
||||
}
|
||||
@media (max-width: 720px) {
|
||||
.metric-strip {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 18px 0;
|
||||
}
|
||||
.metric:nth-child(2) {
|
||||
border-right: 0;
|
||||
}
|
||||
.search-form {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,730 @@
|
||||
<template>
|
||||
<div class="case-detail">
|
||||
<el-button class="mb-4" @click="emit('back')">返回医助详情</el-button>
|
||||
<p class="muted">关联沟通核查 · 医助 #{{ assistantId }} · 患者信息仅用于定位服务证据</p>
|
||||
|
||||
<el-card shadow="never" class="patient-header">
|
||||
<div class="patient-summary">
|
||||
<div>
|
||||
<h2>{{ selected.patient_name || '未命名患者' }}</h2>
|
||||
<span
|
||||
>诊单 #{{ selected.diagnosis_id }} ·
|
||||
{{ selected.phone_masked || '当前授权患者' }}</span
|
||||
>
|
||||
</div>
|
||||
<div class="patient-controls">
|
||||
<span class="muted">最近 {{ days }} 天</span>
|
||||
<el-button :loading="contextLoading" @click="reloadContext">刷新来源</el-button
|
||||
><el-button
|
||||
v-if="can('record') && assistantId === actorId"
|
||||
:disabled="contextLoading || !!contextError"
|
||||
type="primary"
|
||||
plain
|
||||
@click="recordOpened = true"
|
||||
>录入服务记录</el-button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
<el-alert
|
||||
v-if="contextError"
|
||||
:title="contextError"
|
||||
type="error"
|
||||
:closable="false"
|
||||
show-icon
|
||||
class="mb-4"
|
||||
/>
|
||||
<el-card shadow="never" v-loading="contextLoading" class="content-card">
|
||||
<el-tabs v-model="activeTab">
|
||||
<el-tab-pane label="来源时间线" name="sources"
|
||||
><SourceTimeline
|
||||
v-if="context"
|
||||
:sources="context.sources"
|
||||
:coverage="context.coverage" /><el-empty
|
||||
v-else-if="!contextLoading"
|
||||
description="来源尚未加载,请刷新来源"
|
||||
/></el-tab-pane>
|
||||
<el-tab-pane label="医助服务分析" name="analysis">
|
||||
<div v-if="!automatic" class="generation-toolbar">
|
||||
<el-select v-model="scenario" aria-label="分析场景" style="width: 170px"
|
||||
><el-option
|
||||
v-for="item in capabilities.scenarios"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value" /></el-select
|
||||
><el-button
|
||||
v-if="can('analyze')"
|
||||
type="primary"
|
||||
:loading="submitting.analysis"
|
||||
:disabled="
|
||||
!canGenerate || busy('analysis') || unknownSubmission.analysis
|
||||
"
|
||||
@click="generate('analysis')"
|
||||
>生成服务分析</el-button
|
||||
>
|
||||
</div>
|
||||
<p v-if="!context?.sources.length" class="muted">
|
||||
当前医助在此范围无可用来源,可由医助补录本人服务记录。
|
||||
</p>
|
||||
<p v-else-if="automatic" class="muted">
|
||||
系统自动分析更新后的沟通记录,结果仍需结合原文核查。
|
||||
</p>
|
||||
<el-alert
|
||||
v-if="newAnalysisAvailable"
|
||||
title="已有更新的分析结果。完成当前核查后可查看最新结果。"
|
||||
type="info"
|
||||
:closable="false"
|
||||
class="mb-4"
|
||||
><el-button link type="primary" @click="showLatestAnalysis"
|
||||
>查看最新结果</el-button
|
||||
></el-alert
|
||||
>
|
||||
<el-alert
|
||||
v-if="submitErrors.analysis"
|
||||
:title="submitErrors.analysis"
|
||||
type="error"
|
||||
:closable="false"
|
||||
class="mb-4"
|
||||
/>
|
||||
<el-button v-if="unknownSubmission.analysis" class="mb-4" @click="reloadContext"
|
||||
>查询已提交任务</el-button
|
||||
>
|
||||
<JobResult
|
||||
v-if="analysisState.job"
|
||||
:key="analysisState.job.id"
|
||||
:job="analysisState.job"
|
||||
:permissions="capabilities.permissions"
|
||||
:error="analysisState.error"
|
||||
:checking="analysisState.checking"
|
||||
:disabled="contextLoading || !!contextError"
|
||||
@refresh="refreshAnalysis"
|
||||
@adopted="handleAdopted"
|
||||
@evidence="showEvidence"
|
||||
/>
|
||||
<el-empty
|
||||
v-else-if="!contextLoading"
|
||||
:description="
|
||||
automatic
|
||||
? '尚无分析结果,系统会自动分析可用沟通记录'
|
||||
: '尚无服务分析,选择场景后生成'
|
||||
"
|
||||
:image-size="90"
|
||||
/>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="回复草稿" name="reply">
|
||||
<el-form label-position="top"
|
||||
><el-form-item label="需要回复的服务问题"
|
||||
><el-input
|
||||
v-model="question"
|
||||
type="textarea"
|
||||
:rows="3"
|
||||
:maxlength="1000"
|
||||
show-word-limit
|
||||
placeholder="例如:患者询问复诊预约流程。请录入实际问题,答复将依据已发布的服务知识。" /></el-form-item
|
||||
></el-form>
|
||||
<div class="generation-toolbar">
|
||||
<el-select v-model="scenario" aria-label="回复场景" style="width: 170px"
|
||||
><el-option
|
||||
v-for="item in capabilities.scenarios"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value" /></el-select
|
||||
><el-button
|
||||
v-if="can('draftReply')"
|
||||
type="primary"
|
||||
:loading="submitting.reply"
|
||||
:disabled="
|
||||
!canGenerate ||
|
||||
!question.trim() ||
|
||||
busy('reply') ||
|
||||
unknownSubmission.reply
|
||||
"
|
||||
@click="generate('reply')"
|
||||
>生成回复草稿</el-button
|
||||
><span class="muted">人工核对与编辑后复制</span>
|
||||
</div>
|
||||
<el-alert
|
||||
v-if="submitErrors.reply"
|
||||
:title="submitErrors.reply"
|
||||
type="error"
|
||||
:closable="false"
|
||||
class="mb-4"
|
||||
/>
|
||||
<el-button v-if="unknownSubmission.reply" class="mb-4" @click="reloadContext"
|
||||
>查询已提交任务</el-button
|
||||
>
|
||||
<JobResult
|
||||
v-if="replyState.job"
|
||||
:key="replyState.job.id"
|
||||
:job="replyState.job"
|
||||
:permissions="capabilities.permissions"
|
||||
:error="replyState.error"
|
||||
:checking="replyState.checking"
|
||||
:disabled="contextLoading || !!contextError"
|
||||
@refresh="replyTracker.refresh"
|
||||
@adopted="handleAdopted"
|
||||
@evidence="showEvidence"
|
||||
/>
|
||||
<el-empty
|
||||
v-else-if="!contextLoading"
|
||||
description="输入实际服务问题,生成有知识依据的回复草稿"
|
||||
:image-size="90"
|
||||
/>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="服务待办" name="actions"
|
||||
><ServiceActions
|
||||
v-if="context"
|
||||
:key="selected.diagnosis_id"
|
||||
:diagnosis-id="selected.diagnosis_id"
|
||||
:assistant-id="assistantId"
|
||||
:actor-id="actorId"
|
||||
:can-complete="can('completeAction')"
|
||||
:can-review="can('reviewQuality')"
|
||||
:refresh-key="actionsRefresh"
|
||||
@changed="emit('changed')"
|
||||
/></el-tab-pane>
|
||||
<el-tab-pane label="分析与复核记录" name="history">
|
||||
<el-alert
|
||||
v-if="historyError"
|
||||
:title="historyError"
|
||||
type="error"
|
||||
:closable="false"
|
||||
class="mb-4"
|
||||
/>
|
||||
<el-table
|
||||
v-loading="historyLoading"
|
||||
:data="history"
|
||||
empty-text="该医助在此诊单暂无分析记录"
|
||||
><el-table-column prop="id" label="任务" width="90" /><el-table-column
|
||||
label="类型"
|
||||
width="110"
|
||||
><template #default="{ row }">{{
|
||||
row.type === 'reply' ? '回复草稿' : '服务分析'
|
||||
}}</template></el-table-column
|
||||
><el-table-column label="创建时间" min-width="170"
|
||||
><template #default="{ row }">{{
|
||||
formatTime(row.created_at)
|
||||
}}</template></el-table-column
|
||||
><el-table-column label="状态" min-width="170"
|
||||
><template #default="{ row }">{{
|
||||
jobLabels[row.status as JobStatus]
|
||||
}}</template></el-table-column
|
||||
><el-table-column label="操作" width="90"
|
||||
><template #default="{ row }"
|
||||
><el-button link type="primary" @click="openHistory(row)"
|
||||
>查看</el-button
|
||||
></template
|
||||
></el-table-column
|
||||
></el-table
|
||||
>
|
||||
<el-pagination
|
||||
v-if="historyTotal"
|
||||
v-model:current-page="historyPage"
|
||||
class="mt-4"
|
||||
:total="historyTotal"
|
||||
:page-size="10"
|
||||
layout="total, prev, pager, next"
|
||||
@current-change="loadHistory"
|
||||
/>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</el-card>
|
||||
<RecordDialog
|
||||
v-if="assistantId === actorId"
|
||||
:key="selected.diagnosis_id"
|
||||
v-model="recordOpened"
|
||||
:diagnosis-id="selected.diagnosis_id"
|
||||
:max-chars="capabilities.limits.max_manual_chars"
|
||||
@saved="reloadContext"
|
||||
/>
|
||||
|
||||
<el-drawer
|
||||
v-model="evidenceOpened"
|
||||
title="原文依据 · 生成时的来源快照"
|
||||
size="min(620px, 96vw)"
|
||||
append-to-body
|
||||
>
|
||||
<SourceTimeline :sources="evidenceSources" :coverage="[]" />
|
||||
</el-drawer>
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
computed,
|
||||
onActivated,
|
||||
onBeforeUnmount,
|
||||
onDeactivated,
|
||||
onMounted,
|
||||
reactive,
|
||||
ref,
|
||||
watch
|
||||
} from 'vue'
|
||||
import {
|
||||
assistantAnalyze,
|
||||
assistantContext,
|
||||
assistantDraftReply,
|
||||
assistantJob,
|
||||
assistantJobs,
|
||||
type Capabilities,
|
||||
type Context,
|
||||
type Days,
|
||||
type Job,
|
||||
type JobStatus,
|
||||
type Patient,
|
||||
type Permission,
|
||||
type Scenario,
|
||||
type Source
|
||||
} from '@/api/assistantService'
|
||||
import useUserStore from '@/stores/modules/user'
|
||||
import SourceTimeline from './SourceTimeline.vue'
|
||||
import RecordDialog from './RecordDialog.vue'
|
||||
import JobResult from './JobResult.vue'
|
||||
import ServiceActions from './ServiceActions.vue'
|
||||
import { createJobTracker } from '../workbench/jobTracker'
|
||||
import { errorText, formatTime, isCancelled, jobLabels } from '../shared'
|
||||
const props = defineProps<{
|
||||
patient: Patient
|
||||
assistantId: number
|
||||
days: Days
|
||||
capabilities: Capabilities
|
||||
initialJobId?: number
|
||||
automatic?: boolean
|
||||
refreshKey?: number
|
||||
}>()
|
||||
const emit = defineEmits<{ (event: 'back'): void; (event: 'changed'): void }>()
|
||||
const capabilities = computed(() => props.capabilities)
|
||||
const selected = ref<Patient>(props.patient),
|
||||
context = ref<Context | null>(null),
|
||||
days = computed(() => props.days),
|
||||
scenario = ref<Scenario>('followup'),
|
||||
question = ref(''),
|
||||
activeTab = ref('analysis')
|
||||
const contextLoading = ref(false),
|
||||
contextError = ref(''),
|
||||
recordOpened = ref(false),
|
||||
actionsRefresh = ref(0)
|
||||
const user = useUserStore(),
|
||||
actorId = computed(() => Number(user.userInfo.id || user.userInfo.admin_id || 0))
|
||||
const can = (permission: Permission) =>
|
||||
capabilities.value?.permissions.includes(permission) || false
|
||||
const canGenerate = computed(
|
||||
() =>
|
||||
!!capabilities.value?.ready &&
|
||||
!!context.value?.sources.length &&
|
||||
!contextLoading.value &&
|
||||
!contextError.value
|
||||
)
|
||||
const analysisTracker = createJobTracker({ read: assistantJob }),
|
||||
replyTracker = createJobTracker({ read: assistantJob })
|
||||
const analysisState = analysisTracker.state,
|
||||
replyState = replyTracker.state
|
||||
const trackers = { analysis: analysisTracker, reply: replyTracker }
|
||||
const submitting = reactive({ analysis: false, reply: false }),
|
||||
unknownSubmission = reactive({ analysis: false, reply: false }),
|
||||
submitErrors = reactive({ analysis: '', reply: '' })
|
||||
const busy = (type: 'analysis' | 'reply') =>
|
||||
['queued', 'running', 'needs_reconciliation'].includes(trackers[type].state.job?.status || '')
|
||||
const inFlight = new Set<string>()
|
||||
const history = ref<Job[]>([]),
|
||||
historyPage = ref(1),
|
||||
historyTotal = ref(0),
|
||||
historyLoading = ref(false),
|
||||
historyError = ref('')
|
||||
const evidenceOpened = ref(false),
|
||||
evidenceSources = ref<Source[]>([])
|
||||
const newAnalysisAvailable = computed(
|
||||
() =>
|
||||
!!context.value?.latest_analysis_job &&
|
||||
!!analysisState.job &&
|
||||
context.value.latest_analysis_job.id > analysisState.job.id
|
||||
)
|
||||
let revision = 0,
|
||||
historyRevision = 0,
|
||||
disposed = false,
|
||||
activated = true
|
||||
let contextRequest: AbortController | undefined,
|
||||
historyRequest: AbortController | undefined,
|
||||
automaticRequest: AbortController | undefined
|
||||
let automaticRevision = 0
|
||||
function clearPatient() {
|
||||
revision++
|
||||
historyRevision++
|
||||
contextRequest?.abort()
|
||||
historyRequest?.abort()
|
||||
automaticRequest?.abort()
|
||||
automaticRevision++
|
||||
context.value = null
|
||||
history.value = []
|
||||
historyTotal.value = 0
|
||||
analysisTracker.setJob(null)
|
||||
replyTracker.setJob(null)
|
||||
evidenceOpened.value = false
|
||||
evidenceSources.value = []
|
||||
recordOpened.value = false
|
||||
}
|
||||
function selectPatient(patient: Patient) {
|
||||
clearPatient()
|
||||
selected.value = patient
|
||||
activeTab.value = 'analysis'
|
||||
question.value = ''
|
||||
historyPage.value = 1
|
||||
submitting.analysis = false
|
||||
submitting.reply = false
|
||||
submitErrors.analysis = ''
|
||||
submitErrors.reply = ''
|
||||
unknownSubmission.analysis = false
|
||||
unknownSubmission.reply = false
|
||||
void reloadContext()
|
||||
}
|
||||
async function reloadContext(preferLatest: unknown = false) {
|
||||
if (!selected.value) return
|
||||
const token = ++revision,
|
||||
id = selected.value.diagnosis_id
|
||||
contextRequest?.abort()
|
||||
automaticRequest?.abort()
|
||||
automaticRevision++
|
||||
contextRequest = new AbortController()
|
||||
contextLoading.value = true
|
||||
contextError.value = ''
|
||||
context.value = null
|
||||
history.value = []
|
||||
historyTotal.value = 0
|
||||
analysisTracker.setJob(null)
|
||||
replyTracker.setJob(null)
|
||||
evidenceOpened.value = false
|
||||
evidenceSources.value = []
|
||||
try {
|
||||
const data = await assistantContext(
|
||||
{ diagnosis_id: id, days: days.value, assistant_id: props.assistantId },
|
||||
contextRequest.signal
|
||||
)
|
||||
if (disposed || token !== revision) return
|
||||
assertContext(data, id)
|
||||
context.value = data
|
||||
analysisTracker.setJob(data.latest_analysis_job)
|
||||
if (data.latest_job?.type === 'reply') replyTracker.setJob(data.latest_job)
|
||||
await loadHistory(true)
|
||||
if (disposed || token !== revision) return
|
||||
for (const tracker of Object.values(trackers)) if (tracker.state.job) void tracker.refresh()
|
||||
if (!historyError.value) {
|
||||
unknownSubmission.analysis = false
|
||||
unknownSubmission.reply = false
|
||||
submitErrors.analysis = ''
|
||||
submitErrors.reply = ''
|
||||
}
|
||||
if (props.initialJobId && preferLatest !== true) {
|
||||
const target = await assistantJob(props.initialJobId, contextRequest.signal)
|
||||
if (disposed || token !== revision) return
|
||||
if (target.diagnosis_id !== id || target.subject_admin_id !== props.assistantId)
|
||||
throw new Error('质检问题与当前医助或诊单不一致')
|
||||
trackers[target.type].setJob(target)
|
||||
activeTab.value = target.type
|
||||
}
|
||||
if (preferLatest === true) activeTab.value = 'analysis'
|
||||
actionsRefresh.value++
|
||||
} catch (cause) {
|
||||
if (!disposed && token === revision && !isCancelled(cause))
|
||||
contextError.value = errorText(cause)
|
||||
} finally {
|
||||
if (!disposed && token === revision) contextLoading.value = false
|
||||
}
|
||||
}
|
||||
function showLatestAnalysis() {
|
||||
void reloadContext(true)
|
||||
}
|
||||
function assertContext(data: Context, diagnosisId: number) {
|
||||
if (
|
||||
data.patient.diagnosis_id !== diagnosisId ||
|
||||
data.subject_admin_id !== props.assistantId ||
|
||||
[data.latest_job, data.latest_analysis_job].some(
|
||||
(job) =>
|
||||
job &&
|
||||
(job.subject_admin_id !== props.assistantId || job.diagnosis_id !== diagnosisId)
|
||||
) ||
|
||||
(data.latest_analysis_job && data.latest_analysis_job.type !== 'analysis')
|
||||
)
|
||||
throw new Error('返回的来源与当前医助或关联诊单不一致')
|
||||
}
|
||||
async function loadHistory(restore: unknown = false) {
|
||||
if (!selected.value) return
|
||||
// el-pagination 传入页码;只有显式 true 才恢复回复,最新分析由 context 独立提供。
|
||||
const shouldRestore = restore === true
|
||||
if (shouldRestore) historyPage.value = 1
|
||||
const token = ++historyRevision,
|
||||
patientToken = revision,
|
||||
id = selected.value.diagnosis_id
|
||||
historyRequest?.abort()
|
||||
historyRequest = new AbortController()
|
||||
historyLoading.value = true
|
||||
historyError.value = ''
|
||||
try {
|
||||
const data = await assistantJobs(
|
||||
{
|
||||
diagnosis_id: id,
|
||||
assistant_id: props.assistantId,
|
||||
page_no: historyPage.value,
|
||||
page_size: 10
|
||||
},
|
||||
historyRequest.signal
|
||||
)
|
||||
if (disposed || token !== historyRevision || patientToken !== revision) return
|
||||
if (
|
||||
data.lists.some(
|
||||
(job) => job.subject_admin_id !== props.assistantId || job.diagnosis_id !== id
|
||||
)
|
||||
)
|
||||
throw new Error('历史记录与当前医助或诊单不一致')
|
||||
history.value = data.lists
|
||||
historyTotal.value = data.count
|
||||
if (shouldRestore && !replyState.job) {
|
||||
const job = data.lists.find((item) => item.type === 'reply')
|
||||
if (job) replyTracker.setJob(job)
|
||||
}
|
||||
} catch (cause) {
|
||||
if (
|
||||
!disposed &&
|
||||
token === historyRevision &&
|
||||
patientToken === revision &&
|
||||
!isCancelled(cause)
|
||||
) {
|
||||
historyError.value = errorText(cause)
|
||||
history.value = []
|
||||
historyTotal.value = 0
|
||||
}
|
||||
} finally {
|
||||
if (!disposed && token === historyRevision) historyLoading.value = false
|
||||
}
|
||||
}
|
||||
async function generate(type: 'analysis' | 'reply') {
|
||||
if (props.automatic && type === 'analysis') return
|
||||
if (
|
||||
!selected.value ||
|
||||
!canGenerate.value ||
|
||||
submitting[type] ||
|
||||
busy(type) ||
|
||||
unknownSubmission[type]
|
||||
)
|
||||
return
|
||||
if (!can(type === 'analysis' ? 'analyze' : 'draftReply')) return
|
||||
if (type === 'reply' && !question.value.trim()) return
|
||||
const token = revision,
|
||||
diagnosis_id = selected.value.diagnosis_id,
|
||||
key = `${props.assistantId}:${days.value}:${diagnosis_id}:${type}`
|
||||
if (inFlight.has(key)) return
|
||||
inFlight.add(key)
|
||||
submitting[type] = true
|
||||
submitErrors[type] = ''
|
||||
const data = {
|
||||
diagnosis_id,
|
||||
assistant_id: props.assistantId,
|
||||
days: days.value,
|
||||
scenario: scenario.value
|
||||
}
|
||||
try {
|
||||
const job = await (type === 'analysis'
|
||||
? assistantAnalyze(data)
|
||||
: assistantDraftReply({ ...data, question: question.value.trim() }))
|
||||
if (disposed || token !== revision) return
|
||||
if (
|
||||
job.diagnosis_id !== diagnosis_id ||
|
||||
job.type !== type ||
|
||||
job.subject_admin_id !== props.assistantId
|
||||
)
|
||||
throw new Error('任务与当前医助或关联诊单不一致')
|
||||
trackers[type].setJob(job)
|
||||
void loadHistory()
|
||||
} catch (cause) {
|
||||
if (!disposed && token === revision) {
|
||||
submitErrors[type] = `${errorText(cause)}。请先查询已提交任务,确认状态后再操作。`
|
||||
unknownSubmission[type] = true
|
||||
}
|
||||
} finally {
|
||||
inFlight.delete(key)
|
||||
if (!disposed && token === revision) submitting[type] = false
|
||||
}
|
||||
}
|
||||
function handleAdopted() {
|
||||
actionsRefresh.value++
|
||||
emit('changed')
|
||||
}
|
||||
async function refreshAnalysis() {
|
||||
await analysisTracker.refresh()
|
||||
if (!disposed) emit('changed')
|
||||
}
|
||||
watch(
|
||||
() => [props.patient.diagnosis_id, props.assistantId, props.days],
|
||||
() => selectPatient(props.patient),
|
||||
{ flush: 'sync' }
|
||||
)
|
||||
function openHistory(job: Job) {
|
||||
trackers[job.type].setJob({ ...job, result: null })
|
||||
activeTab.value = job.type
|
||||
void trackers[job.type].refresh()
|
||||
}
|
||||
function showEvidence(sources: Source[]) {
|
||||
evidenceSources.value = sources
|
||||
evidenceOpened.value = true
|
||||
}
|
||||
async function refreshAutomatic() {
|
||||
if (
|
||||
!props.automatic ||
|
||||
disposed ||
|
||||
!activated ||
|
||||
document.visibilityState === 'hidden' ||
|
||||
contextLoading.value
|
||||
)
|
||||
return
|
||||
const token = revision,
|
||||
readToken = ++automaticRevision,
|
||||
id = selected.value.diagnosis_id
|
||||
automaticRequest?.abort()
|
||||
automaticRequest = new AbortController()
|
||||
try {
|
||||
const data = await assistantContext(
|
||||
{ diagnosis_id: id, days: days.value, assistant_id: props.assistantId },
|
||||
automaticRequest.signal
|
||||
)
|
||||
if (disposed || token !== revision || readToken !== automaticRevision) return
|
||||
assertContext(data, id)
|
||||
context.value = data
|
||||
contextError.value = ''
|
||||
if (!analysisState.job && data.latest_analysis_job)
|
||||
analysisTracker.setJob(data.latest_analysis_job)
|
||||
// 保持当前核查和输入;仅更新当前结果的有效性,不自动切换到另一份分析。
|
||||
if (analysisState.job) void analysisTracker.refresh()
|
||||
if (replyState.job) void replyTracker.refresh()
|
||||
void loadHistory()
|
||||
actionsRefresh.value++
|
||||
} catch (cause) {
|
||||
if (
|
||||
!disposed &&
|
||||
token === revision &&
|
||||
readToken === automaticRevision &&
|
||||
!isCancelled(cause)
|
||||
) {
|
||||
contextError.value = errorText(cause)
|
||||
context.value = null
|
||||
analysisTracker.setJob(null)
|
||||
replyTracker.setJob(null)
|
||||
evidenceOpened.value = false
|
||||
evidenceSources.value = []
|
||||
}
|
||||
}
|
||||
}
|
||||
watch(
|
||||
() => props.refreshKey,
|
||||
() => void refreshAutomatic()
|
||||
)
|
||||
function updateVisibility() {
|
||||
const visible = activated && document.visibilityState !== 'hidden'
|
||||
analysisTracker.setActive(visible)
|
||||
replyTracker.setActive(visible)
|
||||
if (!visible) {
|
||||
automaticRequest?.abort()
|
||||
automaticRevision++
|
||||
}
|
||||
}
|
||||
onMounted(() => {
|
||||
document.addEventListener('visibilitychange', updateVisibility)
|
||||
updateVisibility()
|
||||
selectPatient(props.patient)
|
||||
})
|
||||
onActivated(() => {
|
||||
activated = true
|
||||
updateVisibility()
|
||||
})
|
||||
onDeactivated(() => {
|
||||
activated = false
|
||||
updateVisibility()
|
||||
})
|
||||
onBeforeUnmount(() => {
|
||||
disposed = true
|
||||
revision++
|
||||
historyRevision++
|
||||
contextRequest?.abort()
|
||||
historyRequest?.abort()
|
||||
automaticRequest?.abort()
|
||||
automaticRevision++
|
||||
analysisTracker.dispose()
|
||||
replyTracker.dispose()
|
||||
document.removeEventListener('visibilitychange', updateVisibility)
|
||||
})
|
||||
</script>
|
||||
<style scoped>
|
||||
.assistant-workbench {
|
||||
padding: 4px;
|
||||
}
|
||||
.page-heading {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
margin-bottom: 20px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
h1 {
|
||||
font-size: 22px;
|
||||
font-weight: 600;
|
||||
margin: 0 0 8px;
|
||||
}
|
||||
.page-heading p,
|
||||
.patient-summary span,
|
||||
.muted {
|
||||
font-size: 13px;
|
||||
color: var(--el-text-color-secondary);
|
||||
line-height: 1.6;
|
||||
}
|
||||
.page-heading p {
|
||||
margin: 0;
|
||||
}
|
||||
.workspace-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 260px minmax(0, 1fr);
|
||||
gap: 16px;
|
||||
align-items: start;
|
||||
}
|
||||
.workspace-main {
|
||||
min-width: 0;
|
||||
}
|
||||
.patient-header {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.patient-summary,
|
||||
.patient-controls,
|
||||
.generation-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.patient-summary {
|
||||
justify-content: space-between;
|
||||
}
|
||||
h2 {
|
||||
margin: 0 0 5px;
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.generation-toolbar {
|
||||
margin: 0 0 18px;
|
||||
}
|
||||
.content-card {
|
||||
min-height: 380px;
|
||||
}
|
||||
@media (max-width: 1100px) {
|
||||
.workspace-grid {
|
||||
grid-template-columns: 220px minmax(0, 1fr);
|
||||
}
|
||||
}
|
||||
@media (max-width: 760px) {
|
||||
.workspace-grid {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
}
|
||||
.patient-controls {
|
||||
width: 100%;
|
||||
}
|
||||
.content-card :deep(.el-card__body) {
|
||||
padding: 14px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,459 @@
|
||||
<template>
|
||||
<section class="daily-contacts" aria-label="今日维护名单">
|
||||
<header class="daily-heading">
|
||||
<div>
|
||||
<h3>
|
||||
今日维护 <span>{{ businessDate || '日期待确认' }} · 上海时间</span>
|
||||
</h3>
|
||||
<p>按患者合并到期任务;人工登记需要核实,不计入已联系。</p>
|
||||
</div>
|
||||
<el-button :loading="loading" @click="load()">刷新名单</el-button>
|
||||
</header>
|
||||
<el-alert v-if="error" :title="error" type="error" :closable="false" show-icon />
|
||||
<el-alert
|
||||
v-else-if="data && data.daily.state !== 'ready'"
|
||||
:title="data.daily.reason || '今日计划尚未完整生成,暂不能确认维护完成情况'"
|
||||
type="warning"
|
||||
:closable="false"
|
||||
show-icon
|
||||
/>
|
||||
<div v-if="data" class="daily-counts" aria-label="该医助今日患者小计">
|
||||
<span
|
||||
>应维护 <b>{{ data.summary.required ?? '—' }}</b></span
|
||||
>
|
||||
<span
|
||||
>已联系 <b>{{ data.summary.contacted ?? '—' }}</b></span
|
||||
>
|
||||
<span
|
||||
>待维护 <b>{{ data.summary.pending ?? '—' }}</b></span
|
||||
>
|
||||
<span
|
||||
>人工登记待核实 <b>{{ data.summary.reported ?? '—' }}</b></span
|
||||
>
|
||||
<span class="muted">豁免 {{ data.summary.exempt ?? '—' }}</span>
|
||||
</div>
|
||||
<div class="status-filter" role="group" aria-label="今日名单状态">
|
||||
<button
|
||||
v-for="item in statuses"
|
||||
:key="item.value"
|
||||
type="button"
|
||||
:aria-pressed="status === item.value"
|
||||
:class="{ active: status === item.value }"
|
||||
@click="setStatus(item.value)"
|
||||
>
|
||||
{{ item.label }}
|
||||
</button>
|
||||
</div>
|
||||
<el-skeleton v-if="loading && !data" :rows="5" animated />
|
||||
<template v-else>
|
||||
<p
|
||||
v-if="data && data.daily.state === 'ready' && data.summary.state === 'done'"
|
||||
class="completion-note"
|
||||
>
|
||||
今日应维护患者均有联系记录。联系记录不代表患者已回复或服务质量已达标。
|
||||
</p>
|
||||
<ul v-if="data?.lists.length" class="patient-list" :aria-busy="loading">
|
||||
<li v-for="patient in data.lists" :key="patient.key" class="patient-row">
|
||||
<div class="patient-name">
|
||||
<strong>{{ patient.patient_name || '未命名患者' }}</strong>
|
||||
<small>诊单 #{{ patient.diagnosis_ids.join('、#') }}</small>
|
||||
</div>
|
||||
<div class="patient-reasons">
|
||||
<p
|
||||
v-for="reason in patient.reasons"
|
||||
:key="`${reason.type}:${reason.source_id}`"
|
||||
>
|
||||
{{ reason.label
|
||||
}}<small v-if="reason.due_at"
|
||||
>到期 {{ shanghaiTime(reason.due_at) }}</small
|
||||
>
|
||||
</p>
|
||||
<p v-if="patient.exempt_reason" class="muted">
|
||||
豁免原因:{{ patient.exempt_reason }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="patient-state">
|
||||
<strong
|
||||
:class="{
|
||||
attention:
|
||||
patient.status === 'pending' || patient.status === 'reported'
|
||||
}"
|
||||
>
|
||||
{{ statusLabels[patient.status] }}
|
||||
</strong>
|
||||
<small v-if="patient.status === 'pending'">未发现今日联系记录</small>
|
||||
<small v-if="patient.last_contact_at"
|
||||
>联系 {{ shanghaiTime(patient.last_contact_at) }}</small
|
||||
>
|
||||
<small
|
||||
v-for="evidence in patient.evidence"
|
||||
:key="`${evidence.type}:${evidence.id}`"
|
||||
>
|
||||
{{ evidence.label }} · {{ shanghaiTime(evidence.at) }}
|
||||
</small>
|
||||
</div>
|
||||
<div class="record-links">
|
||||
<el-button
|
||||
v-for="(diagnosisId, index) in patient.diagnosis_ids"
|
||||
:key="diagnosisId"
|
||||
link
|
||||
type="primary"
|
||||
@click="openPatient(patient, diagnosisId)"
|
||||
>
|
||||
{{ index === 0 ? '查看记录' : `诊单 #${diagnosisId}` }}
|
||||
</el-button>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
<el-empty v-else :description="emptyDescription" :image-size="70" />
|
||||
</template>
|
||||
<footer class="daily-footer">
|
||||
<p>已联系仅依据该医助账号今日已归档的文字记录。电话、外部企微尚未接入。</p>
|
||||
<el-pagination
|
||||
v-if="data?.count"
|
||||
v-model:current-page="page"
|
||||
:total="data.count"
|
||||
:page-size="10"
|
||||
layout="total, prev, pager, next"
|
||||
@current-change="load()"
|
||||
/>
|
||||
</footer>
|
||||
<details v-if="data" class="coverage">
|
||||
<summary>纳入规则与资料范围</summary>
|
||||
<p>{{ data.daily.rule_label }}</p>
|
||||
<p>
|
||||
最近生成 {{ shanghaiTime(data.daily.last_scan_at) }} · 数据截至
|
||||
{{ shanghaiTime(data.daily.as_of) }}
|
||||
</p>
|
||||
<p v-for="source in data.daily.coverage" :key="source.source">{{ source.note }}</p>
|
||||
</details>
|
||||
</section>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { computed, onActivated, onBeforeUnmount, onDeactivated, onMounted, ref, watch } from 'vue'
|
||||
import {
|
||||
assistantStaffDailyContacts,
|
||||
type DailyPatient,
|
||||
type DailyStatus,
|
||||
type Patient,
|
||||
type StaffDailyContacts
|
||||
} from '@/api/assistantService'
|
||||
import { errorText, isCancelled, shanghaiTime } from '../shared'
|
||||
const props = defineProps<{
|
||||
assistantId: number
|
||||
businessDate: string
|
||||
refreshKey: number
|
||||
initialStatus?: DailyStatus
|
||||
entryKey?: number
|
||||
allowed: boolean
|
||||
}>()
|
||||
const emit = defineEmits<{
|
||||
(event: 'open', patient: Patient): void
|
||||
(event: 'date-change', date: string): void
|
||||
(event: 'unavailable'): void
|
||||
}>()
|
||||
const data = ref<StaffDailyContacts | null>(null),
|
||||
error = ref(''),
|
||||
loading = ref(false),
|
||||
page = ref(1),
|
||||
status = ref<DailyStatus>(props.initialStatus || 'pending')
|
||||
const statuses: Array<{ value: DailyStatus; label: string }> = [
|
||||
{ value: 'pending', label: '待维护' },
|
||||
{ value: 'reported', label: '人工登记待核实' },
|
||||
{ value: 'contacted', label: '已联系' },
|
||||
{ value: 'all', label: '全部' },
|
||||
{ value: 'exempt', label: '已豁免' }
|
||||
]
|
||||
const statusLabels = {
|
||||
pending: '待维护',
|
||||
reported: '人工登记待核实',
|
||||
contacted: '有联系记录',
|
||||
exempt: '已豁免'
|
||||
}
|
||||
const emptyDescription = computed(() => {
|
||||
if (error.value) return '名单读取失败,请重试'
|
||||
if (
|
||||
!data.value ||
|
||||
data.value.daily.state !== 'ready' ||
|
||||
data.value.summary.state === 'unavailable'
|
||||
)
|
||||
return '今日计划尚不可确认,请查看资料状态'
|
||||
if (data.value.summary.state === 'no_tasks') return '今日暂无应维护患者'
|
||||
return `当前筛选暂无患者${page.value > 1 ? ',可返回上一页查看' : ''}`
|
||||
})
|
||||
let disposed = false,
|
||||
activated = true,
|
||||
revision = 0
|
||||
let request: AbortController | undefined
|
||||
const visible = () =>
|
||||
activated && (typeof document === 'undefined' || document.visibilityState !== 'hidden')
|
||||
function clear() {
|
||||
revision++
|
||||
request?.abort()
|
||||
data.value = null
|
||||
error.value = ''
|
||||
loading.value = false
|
||||
}
|
||||
async function load(silent = false) {
|
||||
if (disposed || !visible() || !props.allowed || !props.businessDate) return
|
||||
const token = ++revision,
|
||||
assistantId = props.assistantId,
|
||||
businessDate = props.businessDate
|
||||
request?.abort()
|
||||
request = new AbortController()
|
||||
if (!silent) {
|
||||
loading.value = true
|
||||
data.value = null
|
||||
}
|
||||
error.value = ''
|
||||
try {
|
||||
const result = await assistantStaffDailyContacts(
|
||||
{ assistant_id: assistantId, status: status.value, page_no: page.value, page_size: 10 },
|
||||
request.signal
|
||||
)
|
||||
if (disposed || token !== revision || !props.allowed) return
|
||||
if (
|
||||
result.staff.id !== assistantId ||
|
||||
result.daily.timezone !== 'Asia/Shanghai' ||
|
||||
!/^\d{4}-\d{2}-\d{2}$/.test(result.daily.business_date)
|
||||
)
|
||||
throw new Error('名单与当前医助或业务日期不一致,请刷新后重试')
|
||||
if (result.daily.business_date !== businessDate) {
|
||||
data.value = null
|
||||
if (result.daily.business_date > businessDate)
|
||||
emit('date-change', result.daily.business_date)
|
||||
else {
|
||||
error.value = '已忽略旧业务日期的名单,请刷新后重试'
|
||||
emit('unavailable')
|
||||
}
|
||||
return
|
||||
}
|
||||
data.value = result
|
||||
} catch (cause) {
|
||||
if (!disposed && token === revision && !isCancelled(cause)) {
|
||||
data.value = null
|
||||
error.value = errorText(cause)
|
||||
emit('unavailable')
|
||||
}
|
||||
} finally {
|
||||
if (!disposed && token === revision) loading.value = false
|
||||
}
|
||||
}
|
||||
function setStatus(value: DailyStatus) {
|
||||
if (value === status.value) return
|
||||
status.value = value
|
||||
page.value = 1
|
||||
void load()
|
||||
}
|
||||
function openPatient(patient: DailyPatient, diagnosisId: number) {
|
||||
if (
|
||||
!props.allowed ||
|
||||
!data.value?.lists.some(
|
||||
(item) => item.key === patient.key && item.diagnosis_ids.includes(diagnosisId)
|
||||
)
|
||||
)
|
||||
return
|
||||
emit('open', {
|
||||
diagnosis_id: diagnosisId,
|
||||
patient_id: patient.patient_id,
|
||||
patient_name: patient.patient_name,
|
||||
assistant_id: props.assistantId
|
||||
})
|
||||
}
|
||||
watch(
|
||||
() => [props.assistantId, props.businessDate, props.allowed],
|
||||
() => {
|
||||
clear()
|
||||
page.value = 1
|
||||
void load()
|
||||
},
|
||||
{ immediate: true, flush: 'sync' }
|
||||
)
|
||||
watch(
|
||||
() => props.entryKey,
|
||||
() => {
|
||||
status.value = props.initialStatus || 'pending'
|
||||
page.value = 1
|
||||
void load()
|
||||
}
|
||||
)
|
||||
watch(
|
||||
() => props.refreshKey,
|
||||
() => void load(true)
|
||||
)
|
||||
function updateVisibility() {
|
||||
if (!visible()) {
|
||||
revision++
|
||||
request?.abort()
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
onMounted(() => {
|
||||
if (typeof document !== 'undefined')
|
||||
document.addEventListener('visibilitychange', updateVisibility)
|
||||
updateVisibility()
|
||||
})
|
||||
onActivated(() => {
|
||||
activated = true
|
||||
})
|
||||
onDeactivated(() => {
|
||||
activated = false
|
||||
updateVisibility()
|
||||
})
|
||||
onBeforeUnmount(() => {
|
||||
disposed = true
|
||||
clear()
|
||||
if (typeof document !== 'undefined')
|
||||
document.removeEventListener('visibilitychange', updateVisibility)
|
||||
})
|
||||
</script>
|
||||
<style scoped>
|
||||
.daily-heading {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: start;
|
||||
gap: 16px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
h3 {
|
||||
margin: 0;
|
||||
font-size: 17px;
|
||||
font-weight: 600;
|
||||
}
|
||||
h3 span,
|
||||
small,
|
||||
.muted,
|
||||
.daily-heading p,
|
||||
.daily-footer,
|
||||
.coverage {
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-secondary);
|
||||
line-height: 1.7;
|
||||
}
|
||||
h3 span {
|
||||
display: block;
|
||||
margin-top: 5px;
|
||||
font-weight: 400;
|
||||
}
|
||||
.daily-heading p {
|
||||
margin: 5px 0 0;
|
||||
}
|
||||
.daily-counts {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px 24px;
|
||||
padding: 18px 0;
|
||||
font-size: 13px;
|
||||
}
|
||||
.daily-counts b {
|
||||
margin-left: 6px;
|
||||
font-size: 21px;
|
||||
font-weight: 600;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.status-filter {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 5px;
|
||||
border-bottom: 1px solid var(--el-border-color-light);
|
||||
padding-bottom: 12px;
|
||||
}
|
||||
.status-filter button {
|
||||
border: 0;
|
||||
background: var(--el-fill-color-light);
|
||||
padding: 8px 12px;
|
||||
border-radius: 3px;
|
||||
cursor: pointer;
|
||||
color: var(--el-text-color-regular);
|
||||
transition:
|
||||
background-color 0.18s,
|
||||
color 0.18s;
|
||||
}
|
||||
.status-filter button.active,
|
||||
.status-filter button:hover {
|
||||
background: var(--el-color-primary-light-9);
|
||||
color: var(--el-color-primary);
|
||||
}
|
||||
.status-filter button:focus-visible,
|
||||
summary:focus-visible {
|
||||
outline: 2px solid var(--el-color-primary);
|
||||
outline-offset: 3px;
|
||||
}
|
||||
.patient-list {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
list-style: none;
|
||||
}
|
||||
.patient-row {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(100px, 0.8fr) minmax(140px, 1.4fr) minmax(130px, 1.2fr) 84px;
|
||||
gap: 20px;
|
||||
padding: 20px 0;
|
||||
border-bottom: 1px solid var(--el-border-color-lighter);
|
||||
font-size: 13px;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.patient-row strong {
|
||||
font-weight: 500;
|
||||
}
|
||||
.patient-row small,
|
||||
.record-links .el-button {
|
||||
display: block;
|
||||
margin: 4px 0 0;
|
||||
}
|
||||
.patient-reasons p {
|
||||
margin: 0 0 8px;
|
||||
}
|
||||
.patient-reasons p:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.attention {
|
||||
color: var(--el-color-primary);
|
||||
}
|
||||
.completion-note {
|
||||
background: var(--el-fill-color-light);
|
||||
padding: 12px;
|
||||
font-size: 13px;
|
||||
line-height: 1.7;
|
||||
}
|
||||
.daily-footer {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
justify-content: space-between;
|
||||
margin-top: 16px;
|
||||
}
|
||||
.daily-footer p {
|
||||
max-width: 48ch;
|
||||
margin: 0;
|
||||
}
|
||||
.coverage {
|
||||
margin-top: 20px;
|
||||
}
|
||||
.coverage summary {
|
||||
cursor: pointer;
|
||||
}
|
||||
@media (max-width: 700px) {
|
||||
.patient-row {
|
||||
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
|
||||
gap: 12px 18px;
|
||||
}
|
||||
.patient-reasons {
|
||||
grid-column: 1;
|
||||
grid-row: 2;
|
||||
}
|
||||
.patient-state {
|
||||
grid-column: 2;
|
||||
grid-row: 1 / span 2;
|
||||
}
|
||||
.record-links {
|
||||
grid-column: 1 / -1;
|
||||
display: flex;
|
||||
gap: 14px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.daily-counts {
|
||||
gap: 10px 18px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,524 @@
|
||||
<template>
|
||||
<div class="job-result">
|
||||
<div class="job-header">
|
||||
<el-tag :type="job.status === 'ready' && !job.stale ? 'success' : 'warning'">{{
|
||||
jobLabels[job.status]
|
||||
}}</el-tag
|
||||
><span
|
||||
>任务 #{{ job.id }} · {{ scenarioLabels[job.scenario] }} ·
|
||||
{{ formatTime(job.created_at) }}</span
|
||||
><el-button link type="primary" :loading="checking" @click="$emit('refresh')"
|
||||
>查询状态</el-button
|
||||
>
|
||||
</div>
|
||||
<el-alert
|
||||
v-if="job.stale || job.status === 'stale'"
|
||||
title="来源、知识或授权范围已变化,此结果仅供历史查看。请刷新来源后重新生成。"
|
||||
type="warning"
|
||||
:closable="false"
|
||||
class="mb-4"
|
||||
/>
|
||||
<el-alert
|
||||
v-if="error || job.error_message"
|
||||
:title="error || job.error_message"
|
||||
type="error"
|
||||
:closable="false"
|
||||
class="mb-4"
|
||||
/>
|
||||
<el-alert
|
||||
v-if="job.status === 'needs_reconciliation'"
|
||||
title="上游调用状态尚未核实,系统不会自动重试。请联系管理员核实后再处理。"
|
||||
type="warning"
|
||||
:closable="false"
|
||||
/>
|
||||
<div
|
||||
v-if="job.status === 'queued' || job.status === 'running'"
|
||||
class="waiting"
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
>
|
||||
{{ job.status === 'queued' ? '任务已提交,等待后台处理。' : '正在根据来源生成结果。'
|
||||
}}{{ error ? '自动查询已暂停,请点击“查询状态”。' : '页面会自动查询进度。' }}
|
||||
</div>
|
||||
<template v-if="analysis">
|
||||
<el-tabs v-model="perspective">
|
||||
<el-tab-pane label="员工服务视角" name="service">
|
||||
<p class="muted">
|
||||
AI 初筛不等于考核结论;说话人或资料不足时不可评价。请逐项查看原文。
|
||||
</p>
|
||||
<article
|
||||
v-for="item in analysis.quality_checks"
|
||||
:key="item.key"
|
||||
class="quality-item"
|
||||
>
|
||||
<div class="quality-heading">
|
||||
<strong>{{ item.label }}</strong
|
||||
><el-tag :type="qualityType(item.status)" size="small">{{
|
||||
qualityLabels[item.status]
|
||||
}}</el-tag
|
||||
><span class="muted">{{
|
||||
item.actor_admin_id
|
||||
? `员工 #${item.actor_admin_id}`
|
||||
: '员工身份未核实'
|
||||
}}</span>
|
||||
</div>
|
||||
<p>{{ item.reason }}</p>
|
||||
<el-button
|
||||
v-if="item.evidence_ids.length"
|
||||
link
|
||||
type="primary"
|
||||
@click="evidence(item.evidence_ids)"
|
||||
>定位原文</el-button
|
||||
>
|
||||
<el-button
|
||||
v-if="permissions.includes('reviewQuality')"
|
||||
link
|
||||
type="primary"
|
||||
:disabled="!actionable"
|
||||
@click="openReview(item)"
|
||||
>人工复核</el-button
|
||||
>
|
||||
<p v-if="latestReview(item.key)" class="review-note">
|
||||
人工复核:{{ decisionLabels[latestReview(item.key)!.decision] }} ·
|
||||
{{ latestReview(item.key)!.note || '无备注' }} ·
|
||||
{{ formatTime(latestReview(item.key)!.created_at) }}
|
||||
</p>
|
||||
</article>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="关联患者诉求" name="patient">
|
||||
<section
|
||||
v-for="section in claimSections"
|
||||
:key="section.key"
|
||||
class="claim-section"
|
||||
>
|
||||
<h3>{{ section.label }}</h3>
|
||||
<p v-if="!analysis[section.key].length" class="muted">
|
||||
当前来源暂无可支持的信息
|
||||
</p>
|
||||
<div
|
||||
v-for="(claim, index) in analysis[section.key]"
|
||||
:key="index"
|
||||
class="claim"
|
||||
>
|
||||
<p>{{ claim.text }}</p>
|
||||
<el-button
|
||||
v-if="claim.evidence_ids.length"
|
||||
link
|
||||
type="primary"
|
||||
@click="evidence(claim.evidence_ids)"
|
||||
>查看 {{ claim.evidence_ids.length }} 条依据</el-button
|
||||
>
|
||||
</div>
|
||||
</section>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
<section class="suggestions">
|
||||
<h3>建议跟进事项</h3>
|
||||
<p v-if="!analysis.suggested_actions.length" class="muted">暂无有依据的建议事项</p>
|
||||
<div v-for="item in analysis.suggested_actions" :key="item.key" class="claim">
|
||||
<p>{{ item.text }}</p>
|
||||
<div>
|
||||
<el-button link type="primary" @click="evidence(item.evidence_ids)"
|
||||
>查看依据</el-button
|
||||
><el-button
|
||||
v-if="canAdopt"
|
||||
link
|
||||
type="primary"
|
||||
:disabled="!actionable"
|
||||
@click="openAdopt(item)"
|
||||
>{{
|
||||
job.subject_admin_id ? '分配给该医助' : '采纳为我的待办'
|
||||
}}</el-button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
<template v-if="reply">
|
||||
<el-alert
|
||||
v-if="reply.needs_confirmation || reply.reason"
|
||||
:title="reply.reason || '请人工核对后使用此草稿'"
|
||||
type="warning"
|
||||
:closable="false"
|
||||
class="mb-4"
|
||||
/>
|
||||
<el-input
|
||||
v-model="draft"
|
||||
aria-label="可编辑回复草稿"
|
||||
type="textarea"
|
||||
:rows="9"
|
||||
:maxlength="12000"
|
||||
show-word-limit
|
||||
:disabled="!actionable"
|
||||
/>
|
||||
<div class="draft-tools">
|
||||
<el-button
|
||||
type="primary"
|
||||
:disabled="!actionable || !draft.trim()"
|
||||
@click="copyDraft"
|
||||
>复制草稿</el-button
|
||||
><el-button :disabled="!actionable" @click="draft = reply!.reply"
|
||||
>恢复生成内容</el-button
|
||||
><el-button
|
||||
v-if="reply.evidence_ids.length"
|
||||
link
|
||||
type="primary"
|
||||
@click="evidence(reply.evidence_ids)"
|
||||
>查看患者来源</el-button
|
||||
>
|
||||
</div>
|
||||
<p class="muted">
|
||||
已发布知识依据:<span
|
||||
v-for="(ref, index) in reply.knowledge_refs"
|
||||
:key="`${ref.id}-${ref.version}`"
|
||||
>{{ index ? '、' : '' }}条目 #{{ ref.id }} / v{{ ref.version }}</span
|
||||
>。复制前请核对时效与具体适用条件。
|
||||
</p>
|
||||
</template>
|
||||
<el-dialog
|
||||
v-model="adoptOpened"
|
||||
:title="
|
||||
job.subject_admin_id
|
||||
? `分配跟进给医助 #${job.subject_admin_id}`
|
||||
: '采纳为我的服务待办'
|
||||
"
|
||||
width="min(580px, 94vw)"
|
||||
:close-on-click-modal="false"
|
||||
:show-close="!saving"
|
||||
:close-on-press-escape="!saving"
|
||||
>
|
||||
<el-form label-position="top" :disabled="saving">
|
||||
<el-form-item label="待办内容(最多 500 字)" required
|
||||
><el-input
|
||||
v-model="actionContent"
|
||||
type="textarea"
|
||||
:rows="4"
|
||||
:maxlength="500"
|
||||
show-word-limit
|
||||
/></el-form-item>
|
||||
<el-form-item label="截止时间(本地时间)" required
|
||||
><el-date-picker v-model="dueAt" type="datetime" placeholder="选择截止时间"
|
||||
/></el-form-item>
|
||||
<el-form-item>
|
||||
<el-checkbox v-model="contactRequired"
|
||||
>需要联系患者,计入到期联系任务</el-checkbox
|
||||
>
|
||||
</el-form-item>
|
||||
<p class="muted">
|
||||
{{
|
||||
job.subject_admin_id
|
||||
? `负责人为医助 #${job.subject_admin_id}`
|
||||
: '负责人为当前登录人'
|
||||
}}。采纳后创建关联待办,提醒状态与业务完成状态分别记录。
|
||||
</p>
|
||||
<el-alert
|
||||
v-if="mutationError"
|
||||
:title="mutationError"
|
||||
type="error"
|
||||
:closable="false"
|
||||
/>
|
||||
</el-form>
|
||||
<template #footer
|
||||
><el-button :disabled="saving" @click="adoptOpened = false">取消</el-button
|
||||
><el-button type="primary" :loading="saving" :disabled="!actionable" @click="adopt"
|
||||
>确认采纳</el-button
|
||||
></template
|
||||
>
|
||||
</el-dialog>
|
||||
<el-dialog
|
||||
v-model="reviewOpened"
|
||||
:title="`人工复核 · ${reviewItem?.label || ''}`"
|
||||
width="min(580px, 94vw)"
|
||||
:close-on-click-modal="false"
|
||||
:show-close="!saving"
|
||||
:close-on-press-escape="!saving"
|
||||
>
|
||||
<p>{{ reviewItem?.reason }}</p>
|
||||
<el-button
|
||||
v-if="reviewItem?.evidence_ids.length"
|
||||
link
|
||||
type="primary"
|
||||
@click="evidence(reviewItem.evidence_ids)"
|
||||
>查看原文依据</el-button
|
||||
>
|
||||
<el-form label-position="top" class="mt-4" :disabled="saving"
|
||||
><el-form-item label="复核结论"
|
||||
><el-radio-group v-model="decision"
|
||||
><el-radio value="confirmed">确认判断</el-radio
|
||||
><el-radio value="dismissed">驳回判断</el-radio
|
||||
><el-radio value="not_applicable">不适用</el-radio></el-radio-group
|
||||
></el-form-item
|
||||
><el-form-item label="复核说明" required
|
||||
><el-input
|
||||
v-model="reviewNote"
|
||||
type="textarea"
|
||||
:rows="4"
|
||||
:maxlength="1000"
|
||||
show-word-limit /></el-form-item
|
||||
></el-form>
|
||||
<el-alert v-if="mutationError" :title="mutationError" type="error" :closable="false" />
|
||||
<template #footer
|
||||
><el-button :disabled="saving" @click="reviewOpened = false">取消</el-button
|
||||
><el-button type="primary" :loading="saving" :disabled="!actionable" @click="review"
|
||||
>保存复核</el-button
|
||||
></template
|
||||
>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, ref, watch } from 'vue'
|
||||
import useClipboard from 'vue-clipboard3'
|
||||
import {
|
||||
assistantAdoptAction,
|
||||
assistantReviewQuality,
|
||||
type AnalysisResult,
|
||||
type Job,
|
||||
type Permission,
|
||||
type QualityCheck,
|
||||
type ReplyResult,
|
||||
type ReviewDecision,
|
||||
type Source,
|
||||
type SuggestedAction
|
||||
} from '@/api/assistantService'
|
||||
import feedback from '@/utils/feedback'
|
||||
import useUserStore from '@/stores/modules/user'
|
||||
import { errorText, formatTime, jobLabels } from '../shared'
|
||||
const props = defineProps<{
|
||||
job: Job
|
||||
permissions: Permission[]
|
||||
checking: boolean
|
||||
error: string
|
||||
disabled: boolean
|
||||
}>()
|
||||
const emit = defineEmits<{
|
||||
(event: 'refresh'): void
|
||||
(event: 'adopted'): void
|
||||
(event: 'evidence', sources: Source[]): void
|
||||
}>()
|
||||
const analysis = computed(() =>
|
||||
props.job.type === 'analysis' ? (props.job.result as AnalysisResult | null) : null
|
||||
)
|
||||
const reply = computed(() =>
|
||||
props.job.type === 'reply' ? (props.job.result as ReplyResult | null) : null
|
||||
)
|
||||
const actionable = computed(
|
||||
() =>
|
||||
!props.disabled &&
|
||||
!props.checking &&
|
||||
!props.error &&
|
||||
props.job.status === 'ready' &&
|
||||
!props.job.stale
|
||||
)
|
||||
const user = useUserStore()
|
||||
const canAdopt = computed(
|
||||
() =>
|
||||
props.permissions.includes('adoptAction') &&
|
||||
(!props.job.subject_admin_id ||
|
||||
props.job.subject_admin_id ===
|
||||
Number(user.userInfo.id || user.userInfo.admin_id || 0) ||
|
||||
props.permissions.includes('reviewQuality'))
|
||||
)
|
||||
const perspective = ref('service'),
|
||||
draft = ref('')
|
||||
const scenarioLabels = { initial: '初次服务', followup: '日常随访', revisit: '复诊服务' }
|
||||
const qualityLabels = {
|
||||
met: '已覆盖',
|
||||
missed: '疑似遗漏',
|
||||
not_applicable: '不适用',
|
||||
insufficient: '证据不足'
|
||||
}
|
||||
const decisionLabels = { confirmed: '已确认', dismissed: '已驳回', not_applicable: '不适用' }
|
||||
const claimSections = [
|
||||
{ key: 'summary', label: '沟通摘要' },
|
||||
{ key: 'needs', label: '患者诉求' },
|
||||
{ key: 'unresolved', label: '待解决问题' },
|
||||
{ key: 'tags', label: '服务标签候选(仅作参考)' }
|
||||
] as const
|
||||
const qualityType = (status: QualityCheck['status']) =>
|
||||
status === 'met' ? 'success' : status === 'missed' ? 'warning' : 'info'
|
||||
function latestReview(key: string) {
|
||||
return [...props.job.reviews].reverse().find((item) => item.item_key === key)
|
||||
}
|
||||
function evidence(ids: string[]) {
|
||||
const sources = ids
|
||||
.map((id) => props.job.sources.find((source) => source.id === id))
|
||||
.filter((source): source is Source => !!source)
|
||||
if (!sources.length) {
|
||||
feedback.msgWarning('此任务未返回可定位的原文,请刷新任务状态')
|
||||
return
|
||||
}
|
||||
emit('evidence', sources)
|
||||
}
|
||||
watch(
|
||||
[() => props.job.id, () => reply.value?.reply],
|
||||
() => {
|
||||
draft.value = reply.value?.reply || ''
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
const { toClipboard } = useClipboard()
|
||||
async function copyDraft() {
|
||||
if (!actionable.value) return
|
||||
try {
|
||||
await toClipboard(draft.value)
|
||||
feedback.msgSuccess('草稿已复制,请核对后使用')
|
||||
} catch {
|
||||
feedback.msgError('复制失败,请选中文本后手动复制')
|
||||
}
|
||||
}
|
||||
const adoptOpened = ref(false),
|
||||
reviewOpened = ref(false),
|
||||
saving = ref(false),
|
||||
mutationError = ref('')
|
||||
const actionItem = ref<SuggestedAction | null>(null),
|
||||
actionContent = ref(''),
|
||||
contactRequired = ref(false),
|
||||
dueAt = ref<Date | null>(null)
|
||||
const reviewItem = ref<QualityCheck | null>(null),
|
||||
decision = ref<ReviewDecision>('confirmed'),
|
||||
reviewNote = ref('')
|
||||
let disposed = false
|
||||
function openAdopt(item: SuggestedAction) {
|
||||
actionItem.value = item
|
||||
actionContent.value = item.text
|
||||
dueAt.value = null
|
||||
contactRequired.value = false
|
||||
mutationError.value = ''
|
||||
adoptOpened.value = true
|
||||
}
|
||||
function openReview(item: QualityCheck) {
|
||||
reviewItem.value = item
|
||||
decision.value = 'confirmed'
|
||||
reviewNote.value = ''
|
||||
mutationError.value = ''
|
||||
reviewOpened.value = true
|
||||
}
|
||||
async function adopt() {
|
||||
if (saving.value || !actionable.value || !canAdopt.value || !actionItem.value) return
|
||||
if (!actionContent.value.trim() || !dueAt.value || dueAt.value.getTime() <= Date.now()) {
|
||||
mutationError.value = '请填写待办内容,并选择未来的截止时间'
|
||||
return
|
||||
}
|
||||
if (Array.from(actionContent.value.trim()).length > 500) {
|
||||
mutationError.value = '待办内容不能超过 500 字,请核对后精简'
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
mutationError.value = ''
|
||||
try {
|
||||
await assistantAdoptAction({
|
||||
job_id: props.job.id,
|
||||
version: props.job.version,
|
||||
action_key: actionItem.value.key,
|
||||
content: actionContent.value.trim(),
|
||||
contact_required: contactRequired.value,
|
||||
due_at: Math.floor(dueAt.value.getTime() / 1000)
|
||||
})
|
||||
if (disposed) return
|
||||
adoptOpened.value = false
|
||||
feedback.msgSuccess(props.job.subject_admin_id ? '已分配给该医助' : '已采纳为我的待办')
|
||||
emit('adopted')
|
||||
} catch (cause) {
|
||||
if (!disposed) {
|
||||
mutationError.value = errorText(cause)
|
||||
emit('refresh')
|
||||
}
|
||||
} finally {
|
||||
if (!disposed) saving.value = false
|
||||
}
|
||||
}
|
||||
async function review() {
|
||||
if (saving.value || !actionable.value || !reviewItem.value) return
|
||||
if (!reviewNote.value.trim()) {
|
||||
mutationError.value = '请填写复核说明'
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
mutationError.value = ''
|
||||
try {
|
||||
await assistantReviewQuality({
|
||||
job_id: props.job.id,
|
||||
version: props.job.version,
|
||||
item_key: reviewItem.value.key,
|
||||
decision: decision.value,
|
||||
note: reviewNote.value.trim()
|
||||
})
|
||||
if (disposed) return
|
||||
reviewOpened.value = false
|
||||
feedback.msgSuccess('复核已保存')
|
||||
emit('refresh')
|
||||
} catch (cause) {
|
||||
if (!disposed) {
|
||||
mutationError.value = `${errorText(cause)}。请刷新查看已有复核后再提交。`
|
||||
emit('refresh')
|
||||
}
|
||||
} finally {
|
||||
if (!disposed) saving.value = false
|
||||
}
|
||||
}
|
||||
onBeforeUnmount(() => {
|
||||
disposed = true
|
||||
})
|
||||
</script>
|
||||
<style scoped>
|
||||
.job-header,
|
||||
.quality-heading,
|
||||
.draft-tools {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.job-header {
|
||||
font-size: 12px;
|
||||
margin-bottom: 16px;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
.claim-section {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
h3 {
|
||||
margin: 0 0 8px;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.claim,
|
||||
.quality-item {
|
||||
padding: 12px 0;
|
||||
border-bottom: 1px solid var(--el-border-color-lighter);
|
||||
}
|
||||
.claim p,
|
||||
.quality-item p {
|
||||
margin: 0 0 7px;
|
||||
line-height: 1.7;
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.quality-heading {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.quality-item .review-note {
|
||||
margin-top: 8px;
|
||||
color: var(--el-color-primary);
|
||||
font-size: 12px;
|
||||
}
|
||||
.suggestions {
|
||||
margin-top: 20px;
|
||||
padding: 16px;
|
||||
background: var(--el-fill-color-light);
|
||||
border-radius: 4px;
|
||||
}
|
||||
.muted,
|
||||
.waiting {
|
||||
color: var(--el-text-color-secondary);
|
||||
font-size: 13px;
|
||||
line-height: 1.7;
|
||||
}
|
||||
.waiting {
|
||||
padding: 28px 0;
|
||||
}
|
||||
.draft-tools {
|
||||
margin-top: 14px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,145 @@
|
||||
<template>
|
||||
<el-card shadow="never" class="patient-picker">
|
||||
<template #header
|
||||
><strong>授权患者</strong><span class="count">{{ total }} 位</span></template
|
||||
>
|
||||
<el-input
|
||||
v-model="keyword"
|
||||
clearable
|
||||
placeholder="搜索患者姓名 / 手机号"
|
||||
aria-label="搜索授权患者"
|
||||
@keyup.enter="search"
|
||||
@clear="search"
|
||||
>
|
||||
<template #append
|
||||
><el-button :loading="loading" @click="search">搜索</el-button></template
|
||||
>
|
||||
</el-input>
|
||||
<el-alert
|
||||
v-if="error"
|
||||
class="mt-3"
|
||||
:title="error"
|
||||
type="error"
|
||||
:closable="false"
|
||||
show-icon
|
||||
/>
|
||||
<el-button v-if="error" link type="primary" @click="load">重新加载</el-button>
|
||||
<div v-loading="loading" class="patient-list">
|
||||
<button
|
||||
v-for="patient in rows"
|
||||
:key="patient.diagnosis_id"
|
||||
type="button"
|
||||
class="patient-row"
|
||||
:class="{ selected: selectedId === patient.diagnosis_id }"
|
||||
:aria-pressed="selectedId === patient.diagnosis_id"
|
||||
@click="$emit('select', patient)"
|
||||
>
|
||||
<strong>{{ patient.patient_name || '未命名患者' }}</strong>
|
||||
<span>{{ patient.phone_masked || '未提供手机号' }}</span>
|
||||
<small>诊单 #{{ patient.diagnosis_id }}</small>
|
||||
</button>
|
||||
<el-empty
|
||||
v-if="!loading && !rows.length && !error"
|
||||
description="当前范围内暂无匹配患者"
|
||||
:image-size="70"
|
||||
/>
|
||||
</div>
|
||||
<el-pagination
|
||||
v-if="total"
|
||||
v-model:current-page="page"
|
||||
small
|
||||
layout="prev, pager, next"
|
||||
:pager-count="5"
|
||||
:total="total"
|
||||
:page-size="10"
|
||||
@current-change="load"
|
||||
/>
|
||||
</el-card>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
import { assistantPatients, type Patient } from '@/api/assistantService'
|
||||
import { errorText, isCancelled } from '../shared'
|
||||
defineProps<{ selectedId: number }>()
|
||||
defineEmits<{ (event: 'select', patient: Patient): void }>()
|
||||
const keyword = ref(''),
|
||||
page = ref(1),
|
||||
total = ref(0),
|
||||
rows = ref<Patient[]>([]),
|
||||
loading = ref(false),
|
||||
error = ref('')
|
||||
let revision = 0,
|
||||
request: AbortController | undefined
|
||||
async function load() {
|
||||
const token = ++revision
|
||||
request?.abort()
|
||||
request = new AbortController()
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
const data = await assistantPatients(
|
||||
{ keyword: keyword.value.trim(), page_no: page.value, page_size: 10 },
|
||||
request.signal
|
||||
)
|
||||
if (token !== revision) return
|
||||
rows.value = data.lists
|
||||
total.value = data.count
|
||||
} catch (cause) {
|
||||
if (token !== revision || isCancelled(cause)) return
|
||||
rows.value = []
|
||||
total.value = 0
|
||||
error.value = errorText(cause)
|
||||
} finally {
|
||||
if (token === revision) loading.value = false
|
||||
}
|
||||
}
|
||||
function search() {
|
||||
page.value = 1
|
||||
void load()
|
||||
}
|
||||
onMounted(load)
|
||||
onBeforeUnmount(() => {
|
||||
revision++
|
||||
request?.abort()
|
||||
})
|
||||
</script>
|
||||
<style scoped>
|
||||
.patient-picker {
|
||||
height: fit-content;
|
||||
min-width: 0;
|
||||
}
|
||||
.count {
|
||||
float: right;
|
||||
color: var(--el-text-color-secondary);
|
||||
font-size: 13px;
|
||||
}
|
||||
.patient-list {
|
||||
min-height: 180px;
|
||||
margin: 14px -8px;
|
||||
}
|
||||
.patient-row {
|
||||
width: 100%;
|
||||
text-align: left;
|
||||
display: grid;
|
||||
gap: 5px;
|
||||
padding: 12px;
|
||||
background: transparent;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
color: var(--el-text-color-primary);
|
||||
}
|
||||
.patient-row + .patient-row {
|
||||
border-top-color: var(--el-border-color-lighter);
|
||||
}
|
||||
.patient-row:hover,
|
||||
.patient-row.selected {
|
||||
background: var(--el-color-primary-light-9);
|
||||
border-color: var(--el-color-primary-light-7);
|
||||
}
|
||||
.patient-row span,
|
||||
.patient-row small {
|
||||
color: var(--el-text-color-secondary);
|
||||
font-size: 12px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,118 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
v-model="opened"
|
||||
title="录入服务记录"
|
||||
width="min(640px, 94vw)"
|
||||
:close-on-click-modal="false"
|
||||
:close-on-press-escape="!saving"
|
||||
:show-close="!saving"
|
||||
>
|
||||
<el-alert
|
||||
title="记录将作为本患者的服务分析来源,请核对时间与说话人。"
|
||||
type="info"
|
||||
:closable="false"
|
||||
class="mb-4"
|
||||
/>
|
||||
<el-form label-position="top" :disabled="saving" @submit.prevent="save">
|
||||
<el-form-item label="记录类型"
|
||||
><el-radio-group v-model="form.record_type"
|
||||
><el-radio value="service_note">人工服务记录</el-radio
|
||||
><el-radio value="verified_transcript">已核对转写</el-radio></el-radio-group
|
||||
></el-form-item
|
||||
>
|
||||
<el-form-item label="实际发生时间(本地时间)" required
|
||||
><el-date-picker
|
||||
v-model="occurredAt"
|
||||
type="datetime"
|
||||
placeholder="选择发生时间"
|
||||
:disabled-date="futureDate"
|
||||
/></el-form-item>
|
||||
<el-form-item label="服务内容" required
|
||||
><el-input
|
||||
v-model="form.content"
|
||||
type="textarea"
|
||||
:rows="8"
|
||||
:maxlength="maxChars"
|
||||
show-word-limit
|
||||
placeholder="记录服务诉求、已沟通事项和后续约定;转写请逐段标明实际说话人。"
|
||||
/></el-form-item>
|
||||
<el-checkbox
|
||||
v-if="form.record_type === 'verified_transcript'"
|
||||
v-model="form.speaker_confirmed"
|
||||
>我已对照原始材料核对文字、患者身份与说话人</el-checkbox
|
||||
>
|
||||
<p
|
||||
v-if="form.record_type === 'verified_transcript'"
|
||||
class="text-xs text-tx-secondary mt-2"
|
||||
>
|
||||
上传者不会自动认定为原对话的服务员工;此记录仅表示素材已核对,不直接用于员工评分。
|
||||
</p>
|
||||
<el-alert v-if="error" :title="error" type="error" :closable="false" class="mt-4" />
|
||||
</el-form>
|
||||
<template #footer
|
||||
><el-button :disabled="saving" @click="opened = false">取消</el-button
|
||||
><el-button type="primary" :loading="saving" @click="save"
|
||||
>保存记录</el-button
|
||||
></template
|
||||
>
|
||||
</el-dialog>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref, onBeforeUnmount } from 'vue'
|
||||
import { assistantRecord } from '@/api/assistantService'
|
||||
import feedback from '@/utils/feedback'
|
||||
import { errorText } from '../shared'
|
||||
const props = defineProps<{ diagnosisId: number; maxChars: number }>()
|
||||
const emit = defineEmits<{ (event: 'saved'): void }>()
|
||||
const opened = defineModel<boolean>({ default: false })
|
||||
const form = reactive({
|
||||
record_type: 'service_note' as 'service_note' | 'verified_transcript',
|
||||
content: '',
|
||||
speaker_confirmed: false
|
||||
})
|
||||
const occurredAt = ref<Date | null>(new Date()),
|
||||
saving = ref(false),
|
||||
error = ref('')
|
||||
let disposed = false
|
||||
const futureDate = (date: Date) => date.getTime() > Date.now()
|
||||
async function save() {
|
||||
if (saving.value) return
|
||||
error.value = ''
|
||||
if (!form.content.trim() || !occurredAt.value) {
|
||||
error.value = '请填写内容和实际发生时间'
|
||||
return
|
||||
}
|
||||
if (occurredAt.value.getTime() > Date.now()) {
|
||||
error.value = '发生时间不能晚于现在'
|
||||
return
|
||||
}
|
||||
if (form.record_type === 'verified_transcript' && !form.speaker_confirmed) {
|
||||
error.value = '请先核对并确认转写内容与说话人'
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
await assistantRecord({
|
||||
...form,
|
||||
content: form.content.trim(),
|
||||
diagnosis_id: props.diagnosisId,
|
||||
occurred_at: Math.floor(occurredAt.value.getTime() / 1000),
|
||||
speaker_confirmed: form.record_type === 'verified_transcript' && form.speaker_confirmed
|
||||
})
|
||||
if (disposed) return
|
||||
feedback.msgSuccess('服务记录已保存')
|
||||
opened.value = false
|
||||
form.content = ''
|
||||
form.speaker_confirmed = false
|
||||
emit('saved')
|
||||
} catch (cause) {
|
||||
if (!disposed)
|
||||
error.value = `${errorText(cause)}。若连接中断,请先关闭弹窗刷新来源,确认是否已保存,避免重复录入。`
|
||||
} finally {
|
||||
if (!disposed) saving.value = false
|
||||
}
|
||||
}
|
||||
onBeforeUnmount(() => {
|
||||
disposed = true
|
||||
})
|
||||
</script>
|
||||
@@ -0,0 +1,283 @@
|
||||
<template>
|
||||
<div>
|
||||
<div class="actions-toolbar">
|
||||
<el-select
|
||||
v-model="state"
|
||||
clearable
|
||||
placeholder="全部执行状态"
|
||||
style="width: 180px"
|
||||
@change="search"
|
||||
><el-option
|
||||
v-for="(label, value) in labels"
|
||||
:key="value"
|
||||
:label="label"
|
||||
:value="value" /></el-select
|
||||
><el-button :loading="loading" @click="load">刷新待办</el-button>
|
||||
</div>
|
||||
<el-alert v-if="error" :title="error" type="error" :closable="false" class="mb-4" />
|
||||
<el-table v-loading="loading" :data="rows" empty-text="当前范围内暂无服务待办">
|
||||
<el-table-column v-if="!diagnosisId" label="关联患者 / 诊单" min-width="150">
|
||||
<template #default="{ row }"
|
||||
>{{ row.patient_name || '未命名患者'
|
||||
}}<small>诊单 #{{ row.diagnosis_id }}</small></template
|
||||
>
|
||||
</el-table-column>
|
||||
<el-table-column label="待办事项" min-width="230"
|
||||
><template #default="{ row }"
|
||||
><div class="action-text">{{ row.content }}</div>
|
||||
<small v-if="row.contact_required">需联系患者 · 纳入到期联系任务</small>
|
||||
<small v-if="row.completion_note"
|
||||
>执行备注:{{ row.completion_note }}</small
|
||||
></template
|
||||
></el-table-column
|
||||
>
|
||||
<el-table-column label="截止 / 完成时间" min-width="175"
|
||||
><template #default="{ row }"
|
||||
><span :class="{ overdue: isOverdue(row) }">{{ formatTime(row.due_at) }}</span
|
||||
><small v-if="row.completed_at"
|
||||
>完成:{{ formatTime(row.completed_at) }}</small
|
||||
></template
|
||||
></el-table-column
|
||||
>
|
||||
<el-table-column label="业务状态" width="110"
|
||||
><template #default="{ row }"
|
||||
><el-tag :type="row.business_state === 'completed' ? 'success' : 'info'">{{
|
||||
labels[row.business_state as BusinessState]
|
||||
}}</el-tag></template
|
||||
></el-table-column
|
||||
>
|
||||
<el-table-column label="提醒状态" width="115"
|
||||
><template #default="{ row }">{{
|
||||
notificationLabel(row.notification_status)
|
||||
}}</template></el-table-column
|
||||
>
|
||||
<el-table-column label="负责人" width="95"
|
||||
><template #default="{ row }">#{{ row.assignee_id }}</template></el-table-column
|
||||
>
|
||||
<el-table-column v-if="canComplete" label="操作" width="105" fixed="right"
|
||||
><template #default="{ row }"
|
||||
><el-button v-if="canUpdate(row)" link type="primary" @click="edit(row)"
|
||||
>更新执行</el-button
|
||||
><span v-else class="muted">—</span></template
|
||||
></el-table-column
|
||||
>
|
||||
</el-table>
|
||||
<el-pagination
|
||||
v-if="total"
|
||||
class="mt-4"
|
||||
v-model:current-page="page"
|
||||
:total="total"
|
||||
:page-size="10"
|
||||
layout="total, prev, pager, next"
|
||||
@current-change="load"
|
||||
/>
|
||||
<el-dialog
|
||||
v-model="opened"
|
||||
title="更新服务待办"
|
||||
width="min(560px, 94vw)"
|
||||
:close-on-click-modal="false"
|
||||
:close-on-press-escape="!saving"
|
||||
:show-close="!saving"
|
||||
>
|
||||
<p class="action-text">{{ selected?.content }}</p>
|
||||
<el-form label-position="top"
|
||||
><el-form-item label="执行状态"
|
||||
><el-radio-group v-model="nextState"
|
||||
><el-radio value="in_progress">进行中</el-radio
|
||||
><el-radio value="completed">已完成</el-radio
|
||||
><el-radio value="cancelled">已取消</el-radio></el-radio-group
|
||||
></el-form-item
|
||||
><el-form-item
|
||||
:label="
|
||||
nextState === 'in_progress' ? '执行备注' : '完成结果 / 取消原因(必填)'
|
||||
"
|
||||
><el-input
|
||||
v-model="note"
|
||||
type="textarea"
|
||||
:rows="4"
|
||||
:maxlength="1000"
|
||||
show-word-limit /></el-form-item
|
||||
></el-form>
|
||||
<el-alert v-if="mutationError" :title="mutationError" type="error" :closable="false" />
|
||||
<template #footer
|
||||
><el-button :disabled="saving" @click="opened = false">取消</el-button
|
||||
><el-button type="primary" :loading="saving" @click="save"
|
||||
>保存执行状态</el-button
|
||||
></template
|
||||
>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { onBeforeUnmount, ref, watch } from 'vue'
|
||||
import {
|
||||
assistantActions,
|
||||
assistantCompleteAction,
|
||||
type BusinessState,
|
||||
type ServiceAction
|
||||
} from '@/api/assistantService'
|
||||
import feedback from '@/utils/feedback'
|
||||
import { errorText, formatTime, isCancelled } from '../shared'
|
||||
const props = defineProps<{
|
||||
diagnosisId?: number
|
||||
assistantId?: number
|
||||
actorId: number
|
||||
canComplete: boolean
|
||||
canReview: boolean
|
||||
refreshKey: number
|
||||
}>()
|
||||
const emit = defineEmits<{ (event: 'changed'): void }>()
|
||||
const rows = ref<ServiceAction[]>([]),
|
||||
total = ref(0),
|
||||
page = ref(1),
|
||||
state = ref<BusinessState | ''>(''),
|
||||
loading = ref(false),
|
||||
error = ref('')
|
||||
const labels: Record<BusinessState, string> = {
|
||||
pending: '待执行',
|
||||
in_progress: '进行中',
|
||||
completed: '已完成',
|
||||
cancelled: '已取消'
|
||||
}
|
||||
let revision = 0,
|
||||
disposed = false,
|
||||
request: AbortController | undefined
|
||||
const terminal = (row: ServiceAction) =>
|
||||
row.business_state === 'completed' || row.business_state === 'cancelled'
|
||||
const canUpdate = (row: ServiceAction) =>
|
||||
props.canComplete && !terminal(row) && (props.canReview || row.assignee_id === props.actorId)
|
||||
const isOverdue = (row: ServiceAction) => !terminal(row) && row.due_at * 1000 < Date.now()
|
||||
const notificationLabels: Record<string, string> = {
|
||||
'0': '待发送',
|
||||
'1': '已发送',
|
||||
'2': '已取消',
|
||||
'3': '发送失败',
|
||||
pending: '待发送',
|
||||
sent: '已发送',
|
||||
cancelled: '已取消',
|
||||
failed: '发送失败'
|
||||
}
|
||||
const notificationLabel = (value: string | number | null) =>
|
||||
notificationLabels[String(value)] || String(value ?? '未安排')
|
||||
async function load(silent: unknown = false) {
|
||||
const token = ++revision
|
||||
request?.abort()
|
||||
request = new AbortController()
|
||||
if (silent !== true) loading.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
const data = await assistantActions(
|
||||
{
|
||||
...(props.diagnosisId ? { diagnosis_id: props.diagnosisId } : {}),
|
||||
...(props.assistantId ? { assistant_id: props.assistantId } : {}),
|
||||
page_no: page.value,
|
||||
page_size: 10,
|
||||
...(state.value ? { state: state.value } : {})
|
||||
},
|
||||
request.signal
|
||||
)
|
||||
if (token !== revision || disposed) return
|
||||
rows.value = data.lists
|
||||
total.value = data.count
|
||||
if (selected.value) {
|
||||
const current = data.lists.find((row) => row.id === selected.value?.id)
|
||||
if (current) selected.value = current
|
||||
}
|
||||
} catch (cause) {
|
||||
if (token === revision && !disposed && !isCancelled(cause)) {
|
||||
error.value = errorText(cause)
|
||||
rows.value = []
|
||||
total.value = 0
|
||||
}
|
||||
} finally {
|
||||
if (token === revision && !disposed) loading.value = false
|
||||
}
|
||||
}
|
||||
function search() {
|
||||
page.value = 1
|
||||
rows.value = []
|
||||
total.value = 0
|
||||
opened.value = false
|
||||
selected.value = null
|
||||
void load()
|
||||
}
|
||||
const opened = ref(false),
|
||||
selected = ref<ServiceAction | null>(null),
|
||||
nextState = ref<Exclude<BusinessState, 'pending'>>('in_progress'),
|
||||
note = ref(''),
|
||||
mutationError = ref(''),
|
||||
saving = ref(false)
|
||||
function edit(row: ServiceAction) {
|
||||
selected.value = row
|
||||
nextState.value = 'in_progress'
|
||||
note.value = ''
|
||||
mutationError.value = ''
|
||||
opened.value = true
|
||||
}
|
||||
async function save() {
|
||||
if (saving.value || !selected.value || !canUpdate(selected.value)) return
|
||||
if (nextState.value !== 'in_progress' && !note.value.trim()) {
|
||||
mutationError.value = '完成或取消必须填写执行结果 / 原因'
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
const scope = `${props.assistantId || 0}:${props.diagnosisId || 0}`
|
||||
mutationError.value = ''
|
||||
try {
|
||||
await assistantCompleteAction({
|
||||
id: selected.value.id,
|
||||
state: nextState.value,
|
||||
note: note.value.trim()
|
||||
})
|
||||
if (disposed || scope !== `${props.assistantId || 0}:${props.diagnosisId || 0}`) return
|
||||
feedback.msgSuccess('执行状态已更新')
|
||||
opened.value = false
|
||||
emit('changed')
|
||||
await load()
|
||||
} catch (cause) {
|
||||
if (!disposed && scope === `${props.assistantId || 0}:${props.diagnosisId || 0}`) {
|
||||
mutationError.value = `${errorText(cause)}。请刷新待办确认当前状态。`
|
||||
void load()
|
||||
}
|
||||
} finally {
|
||||
if (!disposed) saving.value = false
|
||||
}
|
||||
}
|
||||
watch(() => [props.diagnosisId, props.assistantId], search, {
|
||||
immediate: true,
|
||||
flush: 'sync'
|
||||
})
|
||||
watch(
|
||||
() => props.refreshKey,
|
||||
() => void load(true)
|
||||
)
|
||||
onBeforeUnmount(() => {
|
||||
disposed = true
|
||||
revision++
|
||||
request?.abort()
|
||||
})
|
||||
</script>
|
||||
<style scoped>
|
||||
.actions-toolbar {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.action-text {
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
line-height: 1.6;
|
||||
}
|
||||
small {
|
||||
display: block;
|
||||
color: var(--el-text-color-secondary);
|
||||
margin-top: 6px;
|
||||
}
|
||||
.overdue {
|
||||
color: var(--el-color-danger);
|
||||
}
|
||||
.muted {
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,104 @@
|
||||
<template>
|
||||
<div>
|
||||
<div class="coverage">
|
||||
<div v-for="item in coverage" :key="item.channel" class="coverage-item">
|
||||
<strong>{{ channelLabel(item.channel) }}</strong>
|
||||
<span>{{ coverageStatus(item.status) }} · {{ item.count }} 条</span>
|
||||
<small>{{ item.note }}</small>
|
||||
</div>
|
||||
</div>
|
||||
<el-empty
|
||||
v-if="!sources.length"
|
||||
description="此时间范围内暂无可用来源,可录入服务记录或调整范围"
|
||||
:image-size="80"
|
||||
/>
|
||||
<div v-else class="timeline" aria-label="患者沟通来源">
|
||||
<article v-for="source in ordered" :key="source.id" class="source">
|
||||
<div class="source-meta">
|
||||
<strong>{{ channelLabel(source.channel) }}</strong
|
||||
><span>{{ formatTime(source.occurred_at) }}</span
|
||||
><el-tag size="small" type="info">{{ speakerLabels[source.speaker] }}</el-tag>
|
||||
</div>
|
||||
<p>{{ source.text }}</p>
|
||||
<small
|
||||
>{{ source.id
|
||||
}}<span v-if="source.actor_admin_id"> · 员工 #{{ source.actor_admin_id }}</span>
|
||||
·
|
||||
{{
|
||||
source.quality_eligible
|
||||
? '可作为质检素材,仍需人工核对'
|
||||
: '仅作上下文,不据此评价员工'
|
||||
}}</small
|
||||
>
|
||||
</article>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import type { Coverage, Source } from '@/api/assistantService'
|
||||
import { channelLabel, formatTime } from '../shared'
|
||||
const props = defineProps<{ sources: Source[]; coverage: Coverage[] }>()
|
||||
const ordered = computed(() => [...props.sources].sort((a, b) => b.occurred_at - a.occurred_at))
|
||||
const speakerLabels = { patient: '患者', service: '服务员工', unknown: '说话人未核实' }
|
||||
const coverageLabels: Record<string, string> = {
|
||||
available: '已覆盖',
|
||||
ready: '已覆盖',
|
||||
partial: '部分覆盖',
|
||||
empty: '暂无记录',
|
||||
not_connected: '尚未接入',
|
||||
not_integrated: '尚未接入',
|
||||
unavailable: '暂不可用',
|
||||
unsupported: '尚未接入',
|
||||
truncated: '超出范围'
|
||||
}
|
||||
function coverageStatus(status: string) {
|
||||
return coverageLabels[status] || status
|
||||
}
|
||||
</script>
|
||||
<style scoped>
|
||||
.coverage {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
|
||||
gap: 10px;
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
.coverage-item {
|
||||
display: grid;
|
||||
gap: 5px;
|
||||
background: var(--el-fill-color-light);
|
||||
border-radius: 4px;
|
||||
padding: 12px;
|
||||
font-size: 13px;
|
||||
}
|
||||
.coverage-item small,
|
||||
.source small {
|
||||
color: var(--el-text-color-secondary);
|
||||
line-height: 1.6;
|
||||
}
|
||||
.timeline {
|
||||
max-height: 520px;
|
||||
overflow: auto;
|
||||
padding-right: 8px;
|
||||
}
|
||||
.source {
|
||||
padding: 16px 0;
|
||||
border-bottom: 1px solid var(--el-border-color-lighter);
|
||||
}
|
||||
.source-meta {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
font-size: 12px;
|
||||
}
|
||||
.source-meta span {
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
.source p {
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
line-height: 1.7;
|
||||
margin: 9px 0;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,628 @@
|
||||
<template>
|
||||
<section class="staff-detail">
|
||||
<template v-if="can('view')">
|
||||
<div v-show="!detail">
|
||||
<div class="detail-heading">
|
||||
<div>
|
||||
<h2>{{ staff.name }}</h2>
|
||||
<p>今日维护与近 30 天服务质检</p>
|
||||
</div>
|
||||
<el-button :loading="overviewLoading" @click="refresh">刷新详情</el-button>
|
||||
</div>
|
||||
<div v-if="overview && activeTab !== 'daily'" class="detail-metrics">
|
||||
<div>
|
||||
<span>沟通发言</span
|
||||
><strong>{{ overview.metrics.im_messages ?? '未接入' }}</strong>
|
||||
</div>
|
||||
<div>
|
||||
<span>已分析诊单</span
|
||||
><strong>{{ overview.metrics.analyzed_cases }}</strong>
|
||||
</div>
|
||||
<div>
|
||||
<span>待跟进</span><strong>{{ overview.metrics.pending_actions }}</strong>
|
||||
</div>
|
||||
<div>
|
||||
<span>已逾期</span
|
||||
><strong :class="{ attention: overview.metrics.overdue_actions > 0 }">{{
|
||||
overview.metrics.overdue_actions
|
||||
}}</strong>
|
||||
</div>
|
||||
</div>
|
||||
<el-tabs v-model="activeTab" class="detail-tabs">
|
||||
<el-tab-pane label="今日维护" name="daily">
|
||||
<DailyContacts
|
||||
:assistant-id="staff.id"
|
||||
:business-date="businessDate || ''"
|
||||
:refresh-key="dailyRefresh"
|
||||
:initial-status="initialStatus"
|
||||
:entry-key="entryKey"
|
||||
:allowed="can('view')"
|
||||
@open="openDaily"
|
||||
@date-change="emit('date-change', $event)"
|
||||
@unavailable="dailyUnavailable"
|
||||
/>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="服务质检 · 30 天" name="issues">
|
||||
<el-alert
|
||||
v-if="overviewError"
|
||||
:title="overviewError"
|
||||
type="error"
|
||||
:closable="false"
|
||||
class="mb-4"
|
||||
/>
|
||||
<p class="section-note">
|
||||
疑似遗漏需核查原文后复核;已确认的问题仍可在这里继续查看。
|
||||
</p>
|
||||
<el-alert
|
||||
v-if="issuesError"
|
||||
:title="issuesError"
|
||||
type="error"
|
||||
:closable="false"
|
||||
class="mb-4"
|
||||
/>
|
||||
<el-table
|
||||
v-loading="issuesLoading"
|
||||
:data="issues"
|
||||
empty-text="暂无待核查问题;没有分析结果不代表已达标"
|
||||
>
|
||||
<el-table-column label="问题 / 关联患者" min-width="180"
|
||||
><template #default="{ row }"
|
||||
><strong class="issue-label">{{ row.label }}</strong
|
||||
><small
|
||||
>{{ row.patient_name || '未命名患者' }} · 诊单 #{{
|
||||
row.diagnosis_id
|
||||
}}</small
|
||||
></template
|
||||
></el-table-column
|
||||
>
|
||||
<el-table-column prop="reason" label="需要核查的内容" min-width="240" />
|
||||
<el-table-column label="复核状态" width="100"
|
||||
><template #default="{ row }">{{
|
||||
row.decision === 'confirmed' ? '已确认' : '待复核'
|
||||
}}</template></el-table-column
|
||||
>
|
||||
<el-table-column label="操作" width="100" fixed="right"
|
||||
><template #default="{ row }"
|
||||
><el-button link type="primary" @click="openIssue(row)"
|
||||
>核查记录</el-button
|
||||
></template
|
||||
></el-table-column
|
||||
>
|
||||
</el-table>
|
||||
<el-pagination
|
||||
v-if="issuesTotal"
|
||||
v-model:current-page="issuesPage"
|
||||
class="pagination"
|
||||
:total="issuesTotal"
|
||||
:page-size="10"
|
||||
layout="total, prev, pager, next"
|
||||
@current-change="loadIssues(false)"
|
||||
/>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="跟进执行" name="actions">
|
||||
<p class="section-note">该医助负责的全部未结与历史事项,可更新执行情况。</p>
|
||||
<ServiceActions
|
||||
:assistant-id="staff.id"
|
||||
:actor-id="actorId"
|
||||
:can-complete="can('completeAction')"
|
||||
:can-review="can('reviewQuality')"
|
||||
:refresh-key="actionsRefresh"
|
||||
@changed="changed"
|
||||
/>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="关联沟通记录" name="cases">
|
||||
<form class="case-search" @submit.prevent="searchCases">
|
||||
<el-input
|
||||
v-model="caseKeyword"
|
||||
placeholder="搜索关联患者 / 诊单"
|
||||
aria-label="搜索关联记录"
|
||||
clearable
|
||||
@clear="searchCases"
|
||||
/><el-button native-type="submit">搜索记录</el-button>
|
||||
</form>
|
||||
<el-alert
|
||||
v-if="casesError"
|
||||
:title="casesError"
|
||||
type="error"
|
||||
:closable="false"
|
||||
class="mb-4"
|
||||
/>
|
||||
<el-table
|
||||
v-loading="casesLoading"
|
||||
:data="cases"
|
||||
row-key="diagnosis_id"
|
||||
empty-text="最近 30 天暂无关联沟通记录"
|
||||
>
|
||||
<el-table-column label="关联患者 / 诊单" min-width="150"
|
||||
><template #default="{ row }"
|
||||
>{{ row.patient_name || '未命名患者'
|
||||
}}<small>诊单 #{{ row.diagnosis_id }}</small></template
|
||||
></el-table-column
|
||||
>
|
||||
<el-table-column label="沟通发言" width="100" align="right"
|
||||
><template #default="{ row }">{{
|
||||
row.im_messages ?? '未接入'
|
||||
}}</template></el-table-column
|
||||
>
|
||||
<el-table-column
|
||||
prop="manual_records"
|
||||
label="登记记录"
|
||||
width="100"
|
||||
align="right"
|
||||
/>
|
||||
<el-table-column label="最近沟通" min-width="170"
|
||||
><template #default="{ row }">{{
|
||||
formatTime(row.last_activity_at)
|
||||
}}</template></el-table-column
|
||||
>
|
||||
<el-table-column label="操作" width="100" fixed="right"
|
||||
><template #default="{ row }"
|
||||
><el-button link type="primary" @click="openCase(row)"
|
||||
>核查记录</el-button
|
||||
></template
|
||||
></el-table-column
|
||||
>
|
||||
</el-table>
|
||||
<el-pagination
|
||||
v-if="casesTotal"
|
||||
v-model:current-page="casesPage"
|
||||
class="pagination"
|
||||
:total="casesTotal"
|
||||
:page-size="10"
|
||||
layout="total, prev, pager, next"
|
||||
@current-change="loadCases(false)"
|
||||
/>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
<details v-if="overview" class="quality-summary">
|
||||
<summary>服务质检汇总与资料说明</summary>
|
||||
<el-table
|
||||
:data="overview.quality"
|
||||
empty-text="尚无有效分析结果,系统会自动分析可用沟通记录"
|
||||
>
|
||||
<el-table-column prop="label" label="质检项" min-width="150" />
|
||||
<el-table-column prop="met" label="已覆盖" min-width="80" align="right" />
|
||||
<el-table-column
|
||||
prop="missed"
|
||||
label="疑似遗漏"
|
||||
min-width="95"
|
||||
align="right"
|
||||
/>
|
||||
<el-table-column
|
||||
prop="insufficient"
|
||||
label="证据不足"
|
||||
min-width="95"
|
||||
align="right"
|
||||
/>
|
||||
<el-table-column
|
||||
prop="confirmed"
|
||||
label="已确认"
|
||||
min-width="85"
|
||||
align="right"
|
||||
/>
|
||||
<el-table-column
|
||||
prop="dismissed"
|
||||
label="已驳回"
|
||||
min-width="85"
|
||||
align="right"
|
||||
/>
|
||||
<el-table-column
|
||||
prop="not_applicable"
|
||||
label="不适用"
|
||||
min-width="85"
|
||||
align="right"
|
||||
/>
|
||||
<el-table-column
|
||||
prop="unreviewed"
|
||||
label="待复核"
|
||||
min-width="85"
|
||||
align="right"
|
||||
/>
|
||||
</el-table>
|
||||
<ul v-if="overview.coverage_notes.length" class="coverage-notes">
|
||||
<li v-for="note in overview.coverage_notes" :key="note">{{ note }}</li>
|
||||
</ul>
|
||||
</details>
|
||||
</div>
|
||||
<CaseDetail
|
||||
v-if="detail"
|
||||
:key="`${staff.id}:${detail.patient.diagnosis_id}:${detail.jobId || 0}`"
|
||||
:patient="detail.patient"
|
||||
:assistant-id="staff.id"
|
||||
:days="30"
|
||||
:capabilities="capabilities"
|
||||
:initial-job-id="detail.jobId"
|
||||
:refresh-key="caseRefresh"
|
||||
automatic
|
||||
@back="closeDetail"
|
||||
@changed="changed"
|
||||
/>
|
||||
</template>
|
||||
</section>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, ref, watch } from 'vue'
|
||||
import {
|
||||
assistantStaffOverview,
|
||||
assistantStaffCases,
|
||||
assistantStaffIssues,
|
||||
type Capabilities,
|
||||
type Permission,
|
||||
type Patient,
|
||||
type Staff,
|
||||
type StaffCase,
|
||||
type StaffIssue,
|
||||
type StaffOverview
|
||||
} from '@/api/assistantService'
|
||||
import useUserStore from '@/stores/modules/user'
|
||||
import CaseDetail from './CaseDetail.vue'
|
||||
import ServiceActions from './ServiceActions.vue'
|
||||
import DailyContacts from './DailyContacts.vue'
|
||||
import { errorText, formatTime, isCancelled } from '../shared'
|
||||
const props = defineProps<{
|
||||
staff: Staff
|
||||
capabilities: Capabilities
|
||||
refreshKey: number
|
||||
businessDate?: string
|
||||
initialView?: 'daily' | 'issues'
|
||||
initialStatus?: import('@/api/assistantService').DailyStatus
|
||||
entryKey?: number
|
||||
}>()
|
||||
const emit = defineEmits<{
|
||||
(event: 'changed'): void
|
||||
(event: 'date-change', date: string): void
|
||||
}>()
|
||||
const user = useUserStore(),
|
||||
actorId = computed(() => Number(user.userInfo.id || user.userInfo.admin_id || 0))
|
||||
const can = (permission: Permission) => props.capabilities.permissions.includes(permission)
|
||||
const overview = ref<StaffOverview | null>(null),
|
||||
overviewLoading = ref(false),
|
||||
overviewError = ref('')
|
||||
const cases = ref<StaffCase[]>([]),
|
||||
casesPage = ref(1),
|
||||
casesTotal = ref(0),
|
||||
casesLoading = ref(false),
|
||||
casesError = ref(''),
|
||||
caseKeyword = ref(''),
|
||||
caseKeywordApplied = ref('')
|
||||
const issues = ref<StaffIssue[]>([]),
|
||||
issuesPage = ref(1),
|
||||
issuesTotal = ref(0),
|
||||
issuesLoading = ref(false),
|
||||
issuesError = ref('')
|
||||
const detail = ref<{ patient: Patient; jobId?: number; daily?: boolean } | null>(null),
|
||||
activeTab = ref<string>(props.initialView || 'daily'),
|
||||
dailyRefresh = ref(0),
|
||||
actionsRefresh = ref(0),
|
||||
caseRefresh = ref(0)
|
||||
let disposed = false,
|
||||
revision = 0,
|
||||
overviewRevision = 0,
|
||||
casesRevision = 0,
|
||||
issuesRevision = 0
|
||||
let overviewRequest: AbortController | undefined,
|
||||
casesRequest: AbortController | undefined,
|
||||
issuesRequest: AbortController | undefined
|
||||
const currentScope = () => ({ assistant_id: props.staff.id, days: 30 as const })
|
||||
function clearScope() {
|
||||
revision++
|
||||
overviewRevision++
|
||||
casesRevision++
|
||||
issuesRevision++
|
||||
overviewRequest?.abort()
|
||||
casesRequest?.abort()
|
||||
issuesRequest?.abort()
|
||||
overview.value = null
|
||||
cases.value = []
|
||||
issues.value = []
|
||||
detail.value = null
|
||||
casesPage.value = 1
|
||||
issuesPage.value = 1
|
||||
casesTotal.value = 0
|
||||
issuesTotal.value = 0
|
||||
caseKeyword.value = ''
|
||||
caseKeywordApplied.value = ''
|
||||
activeTab.value = props.initialView || 'daily'
|
||||
overviewError.value = ''
|
||||
casesError.value = ''
|
||||
issuesError.value = ''
|
||||
overviewLoading.value = false
|
||||
casesLoading.value = false
|
||||
issuesLoading.value = false
|
||||
}
|
||||
async function loadOverview(silent = false) {
|
||||
const scope = currentScope(),
|
||||
token = revision,
|
||||
requestToken = ++overviewRevision
|
||||
overviewRequest?.abort()
|
||||
overviewRequest = new AbortController()
|
||||
if (!silent) overviewLoading.value = true
|
||||
try {
|
||||
const data = await assistantStaffOverview(scope, overviewRequest.signal)
|
||||
if (disposed || token !== revision || requestToken !== overviewRevision) return
|
||||
if (data.staff.id !== scope.assistant_id || data.days !== 30)
|
||||
throw new Error('概览与当前医助或时间范围不一致')
|
||||
overview.value = data
|
||||
overviewError.value = ''
|
||||
} catch (cause) {
|
||||
if (
|
||||
!disposed &&
|
||||
token === revision &&
|
||||
requestToken === overviewRevision &&
|
||||
!isCancelled(cause)
|
||||
) {
|
||||
overviewError.value = errorText(cause)
|
||||
overview.value = null
|
||||
if (!detail.value?.daily) detail.value = null
|
||||
}
|
||||
} finally {
|
||||
if (!disposed && token === revision && requestToken === overviewRevision)
|
||||
overviewLoading.value = false
|
||||
}
|
||||
}
|
||||
async function loadCases(silent = false) {
|
||||
const scope = currentScope(),
|
||||
token = revision,
|
||||
requestToken = ++casesRevision
|
||||
casesRequest?.abort()
|
||||
casesRequest = new AbortController()
|
||||
if (!silent) {
|
||||
casesLoading.value = true
|
||||
cases.value = []
|
||||
}
|
||||
casesError.value = ''
|
||||
try {
|
||||
const data = await assistantStaffCases(
|
||||
{
|
||||
...scope,
|
||||
keyword: caseKeywordApplied.value,
|
||||
page_no: casesPage.value,
|
||||
page_size: 10
|
||||
},
|
||||
casesRequest.signal
|
||||
)
|
||||
if (disposed || token !== revision || requestToken !== casesRevision) return
|
||||
cases.value = data.lists
|
||||
casesTotal.value = data.count
|
||||
} catch (cause) {
|
||||
if (
|
||||
!disposed &&
|
||||
token === revision &&
|
||||
requestToken === casesRevision &&
|
||||
!isCancelled(cause)
|
||||
) {
|
||||
casesError.value = errorText(cause)
|
||||
cases.value = []
|
||||
casesTotal.value = 0
|
||||
}
|
||||
} finally {
|
||||
if (!disposed && token === revision && requestToken === casesRevision)
|
||||
casesLoading.value = false
|
||||
}
|
||||
}
|
||||
async function loadIssues(silent = false) {
|
||||
const scope = currentScope(),
|
||||
token = revision,
|
||||
requestToken = ++issuesRevision
|
||||
issuesRequest?.abort()
|
||||
issuesRequest = new AbortController()
|
||||
if (!silent) {
|
||||
issuesLoading.value = true
|
||||
issues.value = []
|
||||
}
|
||||
issuesError.value = ''
|
||||
try {
|
||||
const data = await assistantStaffIssues(
|
||||
{ ...scope, page_no: issuesPage.value, page_size: 10 },
|
||||
issuesRequest.signal
|
||||
)
|
||||
if (disposed || token !== revision || requestToken !== issuesRevision) return
|
||||
issues.value = data.lists
|
||||
issuesTotal.value = data.count
|
||||
} catch (cause) {
|
||||
if (
|
||||
!disposed &&
|
||||
token === revision &&
|
||||
requestToken === issuesRevision &&
|
||||
!isCancelled(cause)
|
||||
) {
|
||||
issuesError.value = errorText(cause)
|
||||
issues.value = []
|
||||
issuesTotal.value = 0
|
||||
}
|
||||
} finally {
|
||||
if (!disposed && token === revision && requestToken === issuesRevision)
|
||||
issuesLoading.value = false
|
||||
}
|
||||
}
|
||||
async function refresh(silent: unknown = false) {
|
||||
if (disposed || !can('view')) return
|
||||
dailyRefresh.value++
|
||||
const token = revision
|
||||
await Promise.all([
|
||||
loadOverview(silent === true),
|
||||
loadCases(silent === true),
|
||||
loadIssues(silent === true)
|
||||
])
|
||||
if (!disposed && token === revision) {
|
||||
actionsRefresh.value++
|
||||
caseRefresh.value++
|
||||
}
|
||||
}
|
||||
function searchCases() {
|
||||
caseKeywordApplied.value = caseKeyword.value.trim()
|
||||
casesPage.value = 1
|
||||
void loadCases()
|
||||
}
|
||||
function openCase(patient: Patient, jobId?: number) {
|
||||
if (overview.value && !overviewError.value) detail.value = { patient, jobId }
|
||||
}
|
||||
function openDaily(patient: Patient) {
|
||||
if (can('view') && patient.assistant_id === props.staff.id)
|
||||
detail.value = { patient, daily: true }
|
||||
}
|
||||
function dailyUnavailable() {
|
||||
if (detail.value?.daily) detail.value = null
|
||||
}
|
||||
function openIssue(issue: StaffIssue) {
|
||||
openCase(
|
||||
{
|
||||
diagnosis_id: issue.diagnosis_id,
|
||||
patient_id: 0,
|
||||
patient_name: issue.patient_name,
|
||||
assistant_id: props.staff.id
|
||||
},
|
||||
issue.job_id
|
||||
)
|
||||
}
|
||||
function closeDetail() {
|
||||
detail.value = null
|
||||
void refresh(true)
|
||||
}
|
||||
function changed() {
|
||||
void refresh(true)
|
||||
emit('changed')
|
||||
}
|
||||
watch(
|
||||
() => props.staff.id,
|
||||
() => {
|
||||
clearScope()
|
||||
void refresh()
|
||||
},
|
||||
{ immediate: true, flush: 'sync' }
|
||||
)
|
||||
watch(
|
||||
() => props.refreshKey,
|
||||
() => void refresh(true)
|
||||
)
|
||||
watch(
|
||||
() => props.entryKey,
|
||||
() => {
|
||||
activeTab.value = props.initialView || 'daily'
|
||||
detail.value = null
|
||||
}
|
||||
)
|
||||
watch(
|
||||
() => can('view'),
|
||||
(allowed) => {
|
||||
if (!allowed) clearScope()
|
||||
},
|
||||
{ flush: 'sync' }
|
||||
)
|
||||
onBeforeUnmount(() => {
|
||||
disposed = true
|
||||
clearScope()
|
||||
})
|
||||
</script>
|
||||
<style scoped>
|
||||
.staff-detail {
|
||||
min-width: 0;
|
||||
}
|
||||
.detail-heading {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
align-items: center;
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
h2 {
|
||||
font-size: 21px;
|
||||
font-weight: 600;
|
||||
margin: 0;
|
||||
}
|
||||
.detail-heading p,
|
||||
.section-note {
|
||||
font-size: 12px;
|
||||
line-height: 1.7;
|
||||
color: var(--el-text-color-secondary);
|
||||
margin: 7px 0 0;
|
||||
}
|
||||
.detail-metrics {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
padding: 18px 0;
|
||||
margin-bottom: 20px;
|
||||
background: var(--el-fill-color-light);
|
||||
border-radius: 4px;
|
||||
}
|
||||
.detail-metrics > div {
|
||||
border-right: 1px solid var(--el-border-color-light);
|
||||
padding: 0 18px;
|
||||
}
|
||||
.detail-metrics > div:last-child {
|
||||
border: 0;
|
||||
}
|
||||
.detail-metrics span {
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-secondary);
|
||||
display: block;
|
||||
}
|
||||
.detail-metrics strong {
|
||||
display: block;
|
||||
font-size: 23px;
|
||||
font-weight: 600;
|
||||
font-variant-numeric: tabular-nums;
|
||||
margin-top: 5px;
|
||||
}
|
||||
.attention {
|
||||
color: var(--el-color-primary);
|
||||
}
|
||||
.section-note {
|
||||
margin: 2px 0 16px;
|
||||
}
|
||||
.issue-label {
|
||||
font-weight: 500;
|
||||
}
|
||||
small {
|
||||
display: block;
|
||||
margin-top: 4px;
|
||||
color: var(--el-text-color-secondary);
|
||||
font-size: 12px;
|
||||
}
|
||||
.pagination {
|
||||
margin-top: 16px;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
.case-search {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
max-width: 380px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.quality-summary {
|
||||
border-top: 1px solid var(--el-border-color-light);
|
||||
margin-top: 28px;
|
||||
padding-top: 18px;
|
||||
}
|
||||
.quality-summary summary {
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
.quality-summary summary:focus-visible {
|
||||
outline: 2px solid var(--el-color-primary);
|
||||
outline-offset: 4px;
|
||||
}
|
||||
.coverage-notes {
|
||||
padding-left: 18px;
|
||||
font-size: 12px;
|
||||
line-height: 1.8;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
.detail-tabs :deep(.el-table__cell) {
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
@media (max-width: 600px) {
|
||||
.detail-metrics {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 20px 0;
|
||||
}
|
||||
.detail-metrics > div:nth-child(2) {
|
||||
border: 0;
|
||||
}
|
||||
.detail-heading {
|
||||
align-items: flex-start;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,202 @@
|
||||
<template>
|
||||
<section class="wecom-thread" aria-label="企业微信聊天记录">
|
||||
<p class="freshness">{{ freshness }}</p>
|
||||
<el-skeleton v-if="loading && !conversations.length" :rows="5" animated />
|
||||
<el-alert v-else-if="error && !conversations.length" :title="error" type="error" :closable="false" show-icon />
|
||||
<p v-else-if="!conversations.length" class="empty">
|
||||
这个账号还没有会话。页面每 15 秒自动检查一次,新消息进来后会出现在这里。
|
||||
</p>
|
||||
<div v-else class="split">
|
||||
<ul class="conversations">
|
||||
<li v-for="item in conversations" :key="item.id">
|
||||
<button
|
||||
type="button"
|
||||
:class="{ active: selected === item.id }"
|
||||
@click="openConversation(item.id)"
|
||||
>
|
||||
<strong>{{ item.name || '未命名会话' }}</strong>
|
||||
<small>{{ item.message_count }} 条 · {{ item.preview || '没有文字预览' }}</small>
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
<ol v-if="selected" class="messages">
|
||||
<li
|
||||
v-for="item in messages"
|
||||
:key="item.id"
|
||||
:class="item.direction === 'outbound' ? 'outbound' : 'inbound'"
|
||||
>
|
||||
<span>{{ item.direction === 'outbound' ? '员工' : '对方' }} · {{ item.sender_name || '未署名' }}</span>
|
||||
<p>{{ item.content || `[${item.message_type}]` }}</p>
|
||||
</li>
|
||||
</ol>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, ref, watch } from 'vue'
|
||||
import { assistantWecomChats, assistantWecomMessages, type WecomConversation, type WecomMessage } from '@/api/assistantService'
|
||||
import { errorText, isCancelled } from '../shared'
|
||||
|
||||
const props = defineProps<{ assistantId: number; account: string }>()
|
||||
const conversations = ref<WecomConversation[]>([])
|
||||
const messages = ref<WecomMessage[]>([])
|
||||
const selected = ref('')
|
||||
const loading = ref(false)
|
||||
const error = ref('')
|
||||
const refreshedAt = ref(0)
|
||||
const freshness = computed(() =>
|
||||
refreshedAt.value
|
||||
? `自动更新于 ${new Date(refreshedAt.value).toLocaleTimeString('zh-CN', { hour12: false })}`
|
||||
: '正在读取会话'
|
||||
)
|
||||
let disposed = false
|
||||
let request: AbortController | undefined
|
||||
let timer: ReturnType<typeof setTimeout> | undefined
|
||||
|
||||
function stopTimer() {
|
||||
if (timer) clearTimeout(timer)
|
||||
timer = undefined
|
||||
}
|
||||
function schedule() {
|
||||
stopTimer()
|
||||
if (!disposed) timer = setTimeout(() => void loadConversations(true), 15000)
|
||||
}
|
||||
async function loadConversations(silent = false) {
|
||||
const current = selected.value
|
||||
request?.abort()
|
||||
request = new AbortController()
|
||||
if (!silent) {
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
conversations.value = []
|
||||
messages.value = []
|
||||
selected.value = ''
|
||||
}
|
||||
try {
|
||||
const result = await assistantWecomChats(
|
||||
{ assistant_id: props.assistantId, account: props.account },
|
||||
request.signal
|
||||
)
|
||||
if (disposed) return
|
||||
conversations.value = result.conversations
|
||||
refreshedAt.value = Date.now()
|
||||
const stillThere = result.conversations.some((item) => item.id === current)
|
||||
const next = stillThere ? current : result.conversations[0]?.id || ''
|
||||
if (next) await openConversation(next, silent && stillThere)
|
||||
else messages.value = []
|
||||
} catch (cause) {
|
||||
if (!disposed && !isCancelled(cause) && !silent) error.value = errorText(cause)
|
||||
} finally {
|
||||
if (!disposed) {
|
||||
loading.value = false
|
||||
schedule()
|
||||
}
|
||||
}
|
||||
}
|
||||
async function openConversation(id: string, keepVisible = false) {
|
||||
selected.value = id
|
||||
if (!keepVisible) messages.value = []
|
||||
try {
|
||||
const result = await assistantWecomMessages({
|
||||
assistant_id: props.assistantId,
|
||||
account: props.account,
|
||||
conversation_id: id
|
||||
})
|
||||
if (!disposed && selected.value === id) messages.value = result.messages
|
||||
} catch (cause) {
|
||||
if (!disposed && !isCancelled(cause) && !keepVisible) error.value = errorText(cause)
|
||||
}
|
||||
}
|
||||
watch(
|
||||
() => [props.assistantId, props.account],
|
||||
() => void loadConversations(false),
|
||||
{ immediate: true }
|
||||
)
|
||||
onBeforeUnmount(() => {
|
||||
disposed = true
|
||||
stopTimer()
|
||||
request?.abort()
|
||||
})
|
||||
</script>
|
||||
<style scoped>
|
||||
.wecom-thread {
|
||||
min-height: 240px;
|
||||
}
|
||||
.freshness,
|
||||
.empty {
|
||||
color: var(--el-text-color-secondary);
|
||||
line-height: 1.7;
|
||||
}
|
||||
.freshness {
|
||||
margin: 0 0 8px;
|
||||
font-size: 12px;
|
||||
}
|
||||
.split {
|
||||
display: grid;
|
||||
grid-template-columns: 220px 1fr;
|
||||
gap: 12px;
|
||||
min-height: 420px;
|
||||
}
|
||||
.conversations,
|
||||
.messages {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
overflow: auto;
|
||||
max-height: 70vh;
|
||||
}
|
||||
.conversations button {
|
||||
width: 100%;
|
||||
margin-bottom: 6px;
|
||||
padding: 8px 10px;
|
||||
border: 1px solid var(--el-border-color-lighter);
|
||||
border-radius: 8px;
|
||||
background: var(--el-bg-color);
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
}
|
||||
.conversations button.active {
|
||||
border-color: #0f766e;
|
||||
background: #f0fdfa;
|
||||
}
|
||||
.conversations strong,
|
||||
.conversations small {
|
||||
display: block;
|
||||
}
|
||||
.conversations small {
|
||||
color: var(--el-text-color-secondary);
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.messages li {
|
||||
margin-bottom: 10px;
|
||||
max-width: 92%;
|
||||
}
|
||||
.messages li span {
|
||||
display: block;
|
||||
margin-bottom: 3px;
|
||||
color: var(--el-text-color-secondary);
|
||||
font-size: 12px;
|
||||
}
|
||||
.messages p {
|
||||
margin: 0;
|
||||
padding: 8px 10px;
|
||||
border-radius: 8px;
|
||||
line-height: 1.6;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
.outbound {
|
||||
margin-left: auto;
|
||||
}
|
||||
.outbound p {
|
||||
background: #dbeafe;
|
||||
}
|
||||
.inbound p {
|
||||
background: var(--el-fill-color);
|
||||
}
|
||||
@media (max-width: 720px) {
|
||||
.split {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,516 @@
|
||||
<template>
|
||||
<div class="knowledge-page">
|
||||
<div class="page-heading">
|
||||
<div>
|
||||
<h1>服务知识维护</h1>
|
||||
<p>维护就诊流程、服务规则与常见问题。仅已发布的知识参与回复草稿生成。</p>
|
||||
</div>
|
||||
<el-button
|
||||
v-if="canManage && capabilities?.schema_ready"
|
||||
type="primary"
|
||||
@click="openEditor()"
|
||||
>新增知识</el-button
|
||||
>
|
||||
</div>
|
||||
<el-alert
|
||||
v-if="bootError"
|
||||
:title="bootError"
|
||||
type="error"
|
||||
:closable="false"
|
||||
class="mb-4"
|
||||
/><el-button v-if="bootError" @click="initialize">重新加载权限</el-button>
|
||||
<el-alert
|
||||
v-if="capabilities && !capabilities.schema_ready"
|
||||
:title="capabilities.reason || '服务知识尚未完成初始化,请联系管理员'"
|
||||
type="warning"
|
||||
:closable="false"
|
||||
/>
|
||||
<el-alert
|
||||
v-else-if="capabilities && !canManage"
|
||||
title="当前账号没有知识管理权限,请联系管理员授权。"
|
||||
type="warning"
|
||||
:closable="false"
|
||||
/>
|
||||
<el-card v-if="canManage && capabilities?.schema_ready" shadow="never" v-loading="booting">
|
||||
<el-form inline class="search-form" @submit.prevent="search"
|
||||
><el-form-item label="关键词"
|
||||
><el-input
|
||||
v-model="keyword"
|
||||
placeholder="搜索问题或分类"
|
||||
clearable
|
||||
@keyup.enter="search"
|
||||
@clear="search" /></el-form-item
|
||||
><el-form-item label="发布状态"
|
||||
><el-select
|
||||
v-model="status"
|
||||
clearable
|
||||
placeholder="全部"
|
||||
style="width: 150px"
|
||||
@change="search"
|
||||
><el-option
|
||||
v-for="(label, value) in labels"
|
||||
:key="value"
|
||||
:label="label"
|
||||
:value="value" /></el-select></el-form-item
|
||||
><el-form-item
|
||||
><el-button type="primary" :loading="loading" @click="search"
|
||||
>查询</el-button
|
||||
></el-form-item
|
||||
></el-form
|
||||
>
|
||||
<el-alert v-if="error" :title="error" type="error" :closable="false" class="mb-4" />
|
||||
<el-table
|
||||
:data="rows"
|
||||
v-loading="loading"
|
||||
empty-text="暂无服务知识,请新增并核对后发布"
|
||||
>
|
||||
<el-table-column label="问题 / 答案" min-width="300"
|
||||
><template #default="{ row }"
|
||||
><strong>{{ row.question }}</strong>
|
||||
<p class="answer-preview">{{ row.answer }}</p></template
|
||||
></el-table-column
|
||||
>
|
||||
<el-table-column prop="category" label="分类" width="120" />
|
||||
<el-table-column label="状态" width="100"
|
||||
><template #default="{ row }"
|
||||
><el-tag :type="row.status === 'published' ? 'success' : 'info'">{{
|
||||
labels[row.status as KnowledgeStatus]
|
||||
}}</el-tag></template
|
||||
></el-table-column
|
||||
>
|
||||
<el-table-column label="版本" width="75"
|
||||
><template #default="{ row }">v{{ row.version }}</template></el-table-column
|
||||
>
|
||||
<el-table-column label="更新时间" min-width="175"
|
||||
><template #default="{ row }">{{
|
||||
formatTime(row.updated_at)
|
||||
}}</template></el-table-column
|
||||
>
|
||||
<el-table-column label="操作" width="100" fixed="right"
|
||||
><template #default="{ row }"
|
||||
><el-button link type="primary" @click="openEditor(row)"
|
||||
>查看 / 编辑</el-button
|
||||
></template
|
||||
></el-table-column
|
||||
>
|
||||
</el-table>
|
||||
<el-pagination
|
||||
v-if="total"
|
||||
class="mt-4"
|
||||
v-model:current-page="page"
|
||||
:total="total"
|
||||
:page-size="15"
|
||||
layout="total, prev, pager, next"
|
||||
@current-change="load"
|
||||
/>
|
||||
</el-card>
|
||||
<el-skeleton v-else-if="booting" :rows="6" animated />
|
||||
<el-dialog
|
||||
v-model="editorOpened"
|
||||
:title="form.id ? `知识 #${form.id} · v${form.version}` : '新增服务知识'"
|
||||
width="min(760px, 96vw)"
|
||||
:close-on-click-modal="false"
|
||||
:close-on-press-escape="!saving"
|
||||
:show-close="!saving"
|
||||
:before-close="beforeClose"
|
||||
>
|
||||
<el-alert
|
||||
v-if="form.id"
|
||||
:title="`当前状态:${labels[editorStatus]}。修改正文并保存后将回到草稿,需要重新发布。`"
|
||||
type="info"
|
||||
:closable="false"
|
||||
class="mb-4"
|
||||
/>
|
||||
<el-form label-position="top" :disabled="saving" @submit.prevent="saveDraft">
|
||||
<el-form-item label="常见问题" required
|
||||
><el-input v-model="form.question" :maxlength="300" show-word-limit
|
||||
/></el-form-item>
|
||||
<el-form-item label="权威服务答案" required
|
||||
><el-input
|
||||
v-model="form.answer"
|
||||
type="textarea"
|
||||
:rows="9"
|
||||
placeholder="填写已经核实的服务规则、适用范围与必要限制。"
|
||||
/></el-form-item>
|
||||
<el-form-item label="分类"
|
||||
><el-input
|
||||
v-model="form.category"
|
||||
:maxlength="64"
|
||||
placeholder="例如:预约流程、物流服务"
|
||||
/></el-form-item>
|
||||
<el-form-item label="来源 / 核实说明" required
|
||||
><el-input
|
||||
v-model="form.source_note"
|
||||
type="textarea"
|
||||
:rows="3"
|
||||
:maxlength="1000"
|
||||
show-word-limit
|
||||
placeholder="注明制度、文件、负责人或核实时间,方便后续复核。"
|
||||
/></el-form-item>
|
||||
</el-form>
|
||||
<el-alert
|
||||
v-if="editorError"
|
||||
:title="editorError"
|
||||
type="error"
|
||||
:closable="false"
|
||||
class="mb-4"
|
||||
/>
|
||||
<el-alert
|
||||
v-if="conflicted"
|
||||
title="此条目已被其他人修改。本地编辑已保留,请复制需要保留的内容,再加载最新版本并重新核对。"
|
||||
type="warning"
|
||||
:closable="false"
|
||||
class="mb-4"
|
||||
/>
|
||||
<div v-if="conflicted" class="conflict-tools">
|
||||
<el-button @click="copyLocal">复制本地编辑</el-button
|
||||
><el-button :loading="saving" @click="reloadLatest">加载最新版本</el-button>
|
||||
</div>
|
||||
<template #footer
|
||||
><div class="editor-footer">
|
||||
<el-button :disabled="saving" @click="closeEditor">关闭</el-button
|
||||
><el-button
|
||||
v-if="form.id && editorStatus === 'published'"
|
||||
type="danger"
|
||||
plain
|
||||
:disabled="saving || conflicted || dirty"
|
||||
@click="publish('disabled')"
|
||||
>停用当前版本</el-button
|
||||
><el-button
|
||||
type="primary"
|
||||
plain
|
||||
:loading="saving"
|
||||
:disabled="conflicted"
|
||||
@click="saveDraft"
|
||||
>保存草稿</el-button
|
||||
><el-button
|
||||
v-if="form.id && editorStatus !== 'published'"
|
||||
type="primary"
|
||||
:disabled="saving || conflicted || dirty"
|
||||
@click="publish('published')"
|
||||
>确认发布</el-button
|
||||
>
|
||||
</div>
|
||||
<p v-if="dirty && form.id" class="footer-note">
|
||||
有未保存编辑,请先保存草稿再发布或停用。
|
||||
</p></template
|
||||
>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, onMounted, reactive, ref } from 'vue'
|
||||
import useClipboard from 'vue-clipboard3'
|
||||
import {
|
||||
assistantCapabilities,
|
||||
assistantKnowledge,
|
||||
assistantPublishKnowledge,
|
||||
assistantSaveKnowledge,
|
||||
type Capabilities,
|
||||
type Knowledge,
|
||||
type KnowledgeStatus
|
||||
} from '@/api/assistantService'
|
||||
import feedback from '@/utils/feedback'
|
||||
import { errorText, formatTime, isCancelled } from '../shared'
|
||||
const capabilities = ref<Capabilities | null>(null),
|
||||
booting = ref(false),
|
||||
bootError = ref(''),
|
||||
canManage = computed(
|
||||
() =>
|
||||
capabilities.value?.permissions.includes('view') &&
|
||||
capabilities.value?.permissions.includes('manageKnowledge')
|
||||
)
|
||||
const rows = ref<Knowledge[]>([]),
|
||||
page = ref(1),
|
||||
total = ref(0),
|
||||
keyword = ref(''),
|
||||
status = ref<KnowledgeStatus | ''>(''),
|
||||
loading = ref(false),
|
||||
error = ref('')
|
||||
const labels: Record<KnowledgeStatus, string> = {
|
||||
draft: '草稿',
|
||||
published: '已发布',
|
||||
disabled: '已停用'
|
||||
}
|
||||
let disposed = false,
|
||||
revision = 0,
|
||||
bootRevision = 0,
|
||||
request: AbortController | undefined,
|
||||
bootRequest: AbortController | undefined
|
||||
async function initialize() {
|
||||
const token = ++bootRevision
|
||||
bootRequest?.abort()
|
||||
bootRequest = new AbortController()
|
||||
booting.value = true
|
||||
bootError.value = ''
|
||||
try {
|
||||
const data = await assistantCapabilities(bootRequest.signal)
|
||||
if (!disposed && token === bootRevision) {
|
||||
capabilities.value = data
|
||||
if (canManage.value && data.schema_ready) await load()
|
||||
}
|
||||
} catch (cause) {
|
||||
if (!disposed && token === bootRevision && !isCancelled(cause))
|
||||
bootError.value = errorText(cause)
|
||||
} finally {
|
||||
if (!disposed && token === bootRevision) booting.value = false
|
||||
}
|
||||
}
|
||||
async function load() {
|
||||
if (!canManage.value) return
|
||||
const token = ++revision
|
||||
request?.abort()
|
||||
request = new AbortController()
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
const data = await assistantKnowledge(
|
||||
{
|
||||
page_no: page.value,
|
||||
page_size: 15,
|
||||
keyword: keyword.value.trim(),
|
||||
...(status.value ? { status: status.value } : {})
|
||||
},
|
||||
request.signal
|
||||
)
|
||||
if (disposed || token !== revision) return
|
||||
rows.value = data.lists
|
||||
total.value = data.count
|
||||
} catch (cause) {
|
||||
if (!disposed && token === revision && !isCancelled(cause)) {
|
||||
error.value = errorText(cause)
|
||||
rows.value = []
|
||||
}
|
||||
} finally {
|
||||
if (!disposed && token === revision) loading.value = false
|
||||
}
|
||||
}
|
||||
function search() {
|
||||
page.value = 1
|
||||
void load()
|
||||
}
|
||||
const editorOpened = ref(false),
|
||||
saving = ref(false),
|
||||
editorError = ref(''),
|
||||
conflicted = ref(false),
|
||||
editorStatus = ref<KnowledgeStatus>('draft')
|
||||
const form = reactive({
|
||||
id: 0,
|
||||
version: 0,
|
||||
question: '',
|
||||
answer: '',
|
||||
category: '',
|
||||
source_note: ''
|
||||
})
|
||||
const snapshot = ref(''),
|
||||
serialize = () => JSON.stringify(form),
|
||||
dirty = computed(() => serialize() !== snapshot.value)
|
||||
function openEditor(row?: Knowledge) {
|
||||
Object.assign(form, {
|
||||
id: row?.id || 0,
|
||||
version: row?.version || 0,
|
||||
question: row?.question || '',
|
||||
answer: row?.answer || '',
|
||||
category: row?.category || '',
|
||||
source_note: row?.source_note || ''
|
||||
})
|
||||
editorStatus.value = row?.status || 'draft'
|
||||
snapshot.value = serialize()
|
||||
editorError.value = ''
|
||||
conflicted.value = false
|
||||
editorOpened.value = true
|
||||
}
|
||||
async function beforeClose(done: () => void) {
|
||||
if (saving.value) return
|
||||
if (dirty.value) {
|
||||
try {
|
||||
await feedback.confirm('尚有未保存的编辑,确认关闭并放弃这些编辑?')
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
}
|
||||
done()
|
||||
}
|
||||
function closeEditor() {
|
||||
void beforeClose(() => {
|
||||
editorOpened.value = false
|
||||
})
|
||||
}
|
||||
function mutationFailed(cause: unknown) {
|
||||
editorError.value = errorText(cause)
|
||||
const code = (cause as { code?: string })?.code || ''
|
||||
conflicted.value = /version|conflict|stale|版本|冲突|已被.*修改/i.test(
|
||||
`${code} ${editorError.value}`
|
||||
)
|
||||
if (!conflicted.value)
|
||||
editorError.value += '。连接中断时请先刷新列表确认是否已保存,再重新操作。'
|
||||
}
|
||||
async function saveDraft() {
|
||||
if (saving.value || conflicted.value || !canManage.value) return
|
||||
if (!form.question.trim() || !form.answer.trim() || !form.source_note.trim()) {
|
||||
editorError.value = '请填写问题、权威答案和来源说明'
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
editorError.value = ''
|
||||
try {
|
||||
const data = await assistantSaveKnowledge({
|
||||
...form,
|
||||
question: form.question.trim(),
|
||||
answer: form.answer.trim(),
|
||||
category: form.category.trim(),
|
||||
source_note: form.source_note.trim()
|
||||
})
|
||||
if (disposed) return
|
||||
form.id = data.id
|
||||
form.version = data.version
|
||||
editorStatus.value = 'draft'
|
||||
snapshot.value = serialize()
|
||||
feedback.msgSuccess('草稿已保存,请核对后显式发布')
|
||||
await load()
|
||||
} catch (cause) {
|
||||
if (!disposed) mutationFailed(cause)
|
||||
} finally {
|
||||
if (!disposed) saving.value = false
|
||||
}
|
||||
}
|
||||
async function publish(nextStatus: 'published' | 'disabled') {
|
||||
if (saving.value || conflicted.value || dirty.value || !form.id || !canManage.value) return
|
||||
saving.value = true
|
||||
editorError.value = ''
|
||||
try {
|
||||
try {
|
||||
await feedback.confirm(
|
||||
nextStatus === 'published'
|
||||
? '确认内容与来源已经核实?发布后此版本将用于生成服务回复草稿。'
|
||||
: '确认停用此知识?停用后将不再作为新回复的知识依据。'
|
||||
)
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (disposed) return
|
||||
const data = await assistantPublishKnowledge({
|
||||
id: form.id,
|
||||
version: form.version,
|
||||
status: nextStatus
|
||||
})
|
||||
if (disposed) return
|
||||
form.version = data.version
|
||||
editorStatus.value = nextStatus
|
||||
snapshot.value = serialize()
|
||||
feedback.msgSuccess(nextStatus === 'published' ? '知识已发布' : '知识已停用')
|
||||
await load()
|
||||
} catch (cause) {
|
||||
if (!disposed) mutationFailed(cause)
|
||||
} finally {
|
||||
if (!disposed) saving.value = false
|
||||
}
|
||||
}
|
||||
const { toClipboard } = useClipboard()
|
||||
async function copyLocal() {
|
||||
try {
|
||||
await toClipboard(
|
||||
`问题:${form.question}\n答案:${form.answer}\n分类:${form.category}\n来源:${form.source_note}`
|
||||
)
|
||||
feedback.msgSuccess('本地编辑已复制')
|
||||
} catch {
|
||||
feedback.msgError('复制失败,请手动选中文本复制')
|
||||
}
|
||||
}
|
||||
async function reloadLatest() {
|
||||
if (saving.value || !form.id) return
|
||||
saving.value = true
|
||||
try {
|
||||
try {
|
||||
await feedback.confirm(
|
||||
'加载最新版本将覆盖编辑框,请先复制需要保留的本地内容。确认继续?'
|
||||
)
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
// 契约没有 detail 接口;逐页定位条目,不猜测新版本号。
|
||||
let cursor = 1,
|
||||
found: Knowledge | undefined,
|
||||
count = 0
|
||||
do {
|
||||
const data = await assistantKnowledge({ page_no: cursor, page_size: 100, keyword: '' })
|
||||
if (disposed) return
|
||||
found = data.lists.find((item) => item.id === form.id)
|
||||
count = data.count
|
||||
if (found || !data.lists.length) break
|
||||
cursor++
|
||||
} while ((cursor - 1) * 100 < count)
|
||||
if (!found) {
|
||||
editorError.value = '未找到该条目,可能已失去访问权限;本地编辑仍保留。'
|
||||
return
|
||||
}
|
||||
openEditor(found)
|
||||
await load()
|
||||
} catch (cause) {
|
||||
if (!disposed) editorError.value = errorText(cause)
|
||||
} finally {
|
||||
if (!disposed) saving.value = false
|
||||
}
|
||||
}
|
||||
onMounted(initialize)
|
||||
onBeforeUnmount(() => {
|
||||
disposed = true
|
||||
revision++
|
||||
bootRevision++
|
||||
request?.abort()
|
||||
bootRequest?.abort()
|
||||
})
|
||||
</script>
|
||||
<style scoped>
|
||||
.knowledge-page {
|
||||
padding: 4px;
|
||||
}
|
||||
.page-heading {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
h1 {
|
||||
font-size: 22px;
|
||||
font-weight: 600;
|
||||
margin: 0 0 8px;
|
||||
}
|
||||
.page-heading p,
|
||||
.footer-note {
|
||||
color: var(--el-text-color-secondary);
|
||||
margin: 0;
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.answer-preview {
|
||||
margin: 8px 0 0;
|
||||
color: var(--el-text-color-secondary);
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.editor-footer,
|
||||
.conflict-tools {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
}
|
||||
.editor-footer .el-button {
|
||||
margin-left: 0;
|
||||
}
|
||||
.footer-note {
|
||||
margin-top: 10px;
|
||||
}
|
||||
@media (max-width: 600px) {
|
||||
.search-form :deep(.el-form-item) {
|
||||
display: flex;
|
||||
margin-right: 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,44 @@
|
||||
import type { JobStatus } from '@/api/assistantService'
|
||||
|
||||
export function errorText(error: unknown): string {
|
||||
if (error instanceof Error) return error.message
|
||||
if (typeof error === 'string') return error
|
||||
const value = error as {
|
||||
msg?: string
|
||||
message?: string
|
||||
response?: { data?: { msg?: string } }
|
||||
} | null
|
||||
return value?.response?.data?.msg || value?.msg || value?.message || '请求失败,请刷新后重试'
|
||||
}
|
||||
export function isCancelled(error: unknown) {
|
||||
return (error as { code?: string })?.code === 'ERR_CANCELED'
|
||||
}
|
||||
export function formatTime(value: number) {
|
||||
return value ? new Date(value * 1000).toLocaleString('zh-CN', { hour12: false }) : '—'
|
||||
}
|
||||
export function shanghaiTime(value: number) {
|
||||
return value
|
||||
? new Date(value * 1000).toLocaleString('zh-CN', {
|
||||
timeZone: 'Asia/Shanghai',
|
||||
hour12: false
|
||||
})
|
||||
: '—'
|
||||
}
|
||||
export const jobLabels: Record<JobStatus, string> = {
|
||||
queued: '等待处理',
|
||||
running: '分析中',
|
||||
ready: '已生成 · 待人工核对',
|
||||
failed: '生成失败',
|
||||
needs_reconciliation: '调用状态待核实',
|
||||
stale: '结果已过期'
|
||||
}
|
||||
const channelLabels: Record<string, string> = {
|
||||
manual: '人工服务记录',
|
||||
im: '腾讯 IM',
|
||||
tracking: '跟踪备注',
|
||||
tracking_note: '跟踪备注',
|
||||
wecom: '企业微信',
|
||||
qywx: '企业微信',
|
||||
audio: '录音 / 转写'
|
||||
}
|
||||
export const channelLabel = (channel: string) => channelLabels[channel] || channel
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,111 @@
|
||||
import { reactive } from 'vue'
|
||||
import type { Job } from '@/api/assistantService'
|
||||
import { errorText, isCancelled } from '../shared'
|
||||
|
||||
/** 单个患者会话的任务跟踪;计时器与请求版本均由实例持有。 */
|
||||
export function createJobTracker(deps: {
|
||||
read: (id: number, signal: AbortSignal) => Promise<Job>
|
||||
now?: () => number
|
||||
setTimer?: (fn: () => void, delay: number) => ReturnType<typeof setTimeout>
|
||||
clearTimer?: (id: ReturnType<typeof setTimeout>) => void
|
||||
}) {
|
||||
const state = reactive<{ job: Job | null; error: string; paused: boolean; checking: boolean }>({
|
||||
job: null,
|
||||
error: '',
|
||||
paused: false,
|
||||
checking: false
|
||||
})
|
||||
const now = deps.now || Date.now
|
||||
const schedule = deps.setTimer || setTimeout
|
||||
const unschedule = deps.clearTimer || clearTimeout
|
||||
let timer: ReturnType<typeof setTimeout> | undefined
|
||||
let request: AbortController | undefined
|
||||
let revision = 0,
|
||||
startedAt = 0,
|
||||
active = true,
|
||||
disposed = false
|
||||
const pending = () => state.job?.status === 'queued' || state.job?.status === 'running'
|
||||
function stop() {
|
||||
if (timer !== undefined) unschedule(timer)
|
||||
timer = undefined
|
||||
request?.abort()
|
||||
request = undefined
|
||||
revision++
|
||||
state.checking = false
|
||||
}
|
||||
function next() {
|
||||
if (disposed || !active || !pending()) return
|
||||
if (now() - startedAt >= 360000) {
|
||||
state.paused = true
|
||||
state.error =
|
||||
'等待超过 6 分钟,已暂停自动查询。任务可能仍在执行,请查询状态;不要重复提交。'
|
||||
return
|
||||
}
|
||||
timer = schedule(() => {
|
||||
timer = undefined
|
||||
void refresh()
|
||||
}, 3000)
|
||||
}
|
||||
async function refresh() {
|
||||
if (!state.job || disposed || !active || state.checking) return
|
||||
if (timer !== undefined) unschedule(timer)
|
||||
timer = undefined
|
||||
const token = revision,
|
||||
id = state.job.id,
|
||||
diagnosisId = state.job.diagnosis_id,
|
||||
subjectId = state.job.subject_admin_id || 0
|
||||
request = new AbortController()
|
||||
state.checking = true
|
||||
try {
|
||||
const job = await deps.read(id, request.signal)
|
||||
if (disposed || token !== revision) return
|
||||
if (
|
||||
job.id !== id ||
|
||||
job.diagnosis_id !== diagnosisId ||
|
||||
(job.subject_admin_id || 0) !== subjectId
|
||||
)
|
||||
throw new Error('任务与当前医助或关联诊单不一致,请重新核查')
|
||||
state.job = job
|
||||
state.error = ''
|
||||
state.paused = false
|
||||
next()
|
||||
} catch (error) {
|
||||
if (disposed || token !== revision || isCancelled(error)) return
|
||||
// 查询失败时隐藏旧结果,避免撤权或来源变更后继续采纳。
|
||||
if (state.job) state.job = { ...state.job, result: null }
|
||||
state.error = errorText(error)
|
||||
state.paused = true
|
||||
} finally {
|
||||
if (token === revision) state.checking = false
|
||||
}
|
||||
}
|
||||
return {
|
||||
state,
|
||||
setJob(job: Job | null) {
|
||||
stop()
|
||||
state.job = job
|
||||
state.error = ''
|
||||
state.paused = false
|
||||
startedAt = now()
|
||||
next()
|
||||
},
|
||||
refresh() {
|
||||
startedAt = now()
|
||||
return refresh()
|
||||
},
|
||||
setActive(value: boolean) {
|
||||
if (active === value) return
|
||||
active = value
|
||||
if (!active) stop()
|
||||
else if (state.job) {
|
||||
startedAt = now()
|
||||
void refresh()
|
||||
}
|
||||
},
|
||||
dispose() {
|
||||
disposed = true
|
||||
stop()
|
||||
state.job = null
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user