feat: 病例列表联调
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
<text class="page-title">学习记录</text>
|
||||
</header>
|
||||
|
||||
<scroll-view class="records-scroll" scroll-y>
|
||||
<scroll-view class="records-scroll" scroll-y @scrolltolower="loadMoreRecords">
|
||||
<main class="records-main">
|
||||
<section class="stats-grid">
|
||||
<view
|
||||
@@ -38,11 +38,11 @@
|
||||
<text class="section-title">最近训练</text>
|
||||
<view class="record-list">
|
||||
<view
|
||||
v-for="record in filteredRecords"
|
||||
:key="record.title"
|
||||
v-for="record in recordItems"
|
||||
:key="record.id"
|
||||
class="record-card"
|
||||
:class="{ dimmed: record.dimmed }"
|
||||
@click="openReport"
|
||||
@click="openReport(record.id)"
|
||||
>
|
||||
<view class="case-icon-wrap" :class="record.tone">
|
||||
<text class="case-icon-text">{{ record.abbr }}</text>
|
||||
@@ -62,21 +62,21 @@
|
||||
<text class="score-value">{{ record.score }}</text>
|
||||
<text class="score-unit">分</text>
|
||||
</view>
|
||||
<button class="report-button" @click.stop="openReport">
|
||||
<button class="report-button" @click.stop="openReport(record.id)">
|
||||
<text>查看报告</text>
|
||||
<view class="small-chevron"></view>
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view v-if="filteredRecords.length === 0" class="empty-state">
|
||||
<text>没有找到匹配的训练记录</text>
|
||||
<view v-if="recordItems.length === 0" class="empty-state">
|
||||
<text>{{ emptyText }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</section>
|
||||
|
||||
<view class="bottom-hint">
|
||||
<text>已经到底啦</text>
|
||||
<text>{{ bottomHint }}</text>
|
||||
</view>
|
||||
</main>
|
||||
</scroll-view>
|
||||
@@ -87,72 +87,62 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onUnmounted, ref } from 'vue'
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
|
||||
import {
|
||||
fetchUserTrainingRecords,
|
||||
type TrainingRecord,
|
||||
type TrainingRecordSummary
|
||||
} from '../../api/profile'
|
||||
|
||||
const keyword = ref('')
|
||||
const toastMessage = ref('')
|
||||
const toastVisible = ref(false)
|
||||
const records = ref<TrainingRecord[]>([])
|
||||
const summary = ref<TrainingRecordSummary>({
|
||||
total_cases: 0,
|
||||
total_hours: 0,
|
||||
avg_accuracy: 0
|
||||
})
|
||||
const currentPage = ref(1)
|
||||
const totalCount = ref(0)
|
||||
const hasMore = ref(false)
|
||||
const loadingRecords = ref(false)
|
||||
const recordsLoaded = ref(false)
|
||||
const recordsFailed = ref(false)
|
||||
|
||||
let toastTimer: ReturnType<typeof setTimeout> | null = null
|
||||
let searchTimer: ReturnType<typeof setTimeout> | null = null
|
||||
let requestSeq = 0
|
||||
|
||||
const stats = [
|
||||
{ label: '总病例', value: '12' },
|
||||
{ label: '总时长', value: '128h' },
|
||||
{ label: '平均正确率', value: '92%', secondary: true }
|
||||
]
|
||||
const stats = computed(() => [
|
||||
{ label: '总病例', value: formatNumber(summary.value.total_cases) },
|
||||
{ label: '总时长', value: `${formatNumber(summary.value.total_hours)}h` },
|
||||
{ label: '平均正确率', value: `${formatNumber(summary.value.avg_accuracy)}%`, secondary: true }
|
||||
])
|
||||
|
||||
const records = [
|
||||
{
|
||||
title: '急性心肌梗死',
|
||||
department: '心内科',
|
||||
date: '2023-11-20',
|
||||
score: '98',
|
||||
abbr: '心',
|
||||
tone: 'primary'
|
||||
},
|
||||
{
|
||||
title: '缺血性脑卒中',
|
||||
department: '神经内科',
|
||||
date: '2023-11-18',
|
||||
score: '85',
|
||||
abbr: '神',
|
||||
tone: 'secondary'
|
||||
},
|
||||
{
|
||||
title: '重症肺炎伴呼吸衰竭',
|
||||
department: '呼吸科',
|
||||
date: '2023-11-15',
|
||||
score: '92',
|
||||
abbr: '肺',
|
||||
tone: 'tertiary'
|
||||
},
|
||||
{
|
||||
title: '急性胰腺炎',
|
||||
department: '消化内科',
|
||||
date: '2023-11-12',
|
||||
score: '78',
|
||||
abbr: '消',
|
||||
tone: 'primary',
|
||||
dimmed: true
|
||||
},
|
||||
{
|
||||
title: '糖尿病肾病五期',
|
||||
department: '肾内科',
|
||||
date: '2023-11-10',
|
||||
score: '95',
|
||||
abbr: '肾',
|
||||
tone: 'secondary',
|
||||
dimmed: true
|
||||
}
|
||||
]
|
||||
const recordItems = computed(() => {
|
||||
return records.value.map((record, index) => ({
|
||||
id: record.record_id,
|
||||
title: record.case_title || '未命名病例',
|
||||
department: record.department || '未标注科室',
|
||||
date: formatDate(record.trained_at),
|
||||
score: formatNumber(record.score),
|
||||
abbr: readRecordAbbr(record),
|
||||
tone: readTone(index),
|
||||
dimmed: index > 2
|
||||
}))
|
||||
})
|
||||
|
||||
const filteredRecords = computed(() => {
|
||||
const query = keyword.value.trim()
|
||||
if (!query) return records
|
||||
const emptyText = computed(() => {
|
||||
if (loadingRecords.value && !recordsLoaded.value) return '训练记录加载中...'
|
||||
if (recordsFailed.value) return '训练记录加载失败,请稍后重试'
|
||||
return keyword.value.trim() ? '没有找到匹配的训练记录' : '暂无训练记录'
|
||||
})
|
||||
|
||||
return records.filter(record => {
|
||||
return [record.title, record.department, record.date].some(value => value.includes(query))
|
||||
})
|
||||
const bottomHint = computed(() => {
|
||||
if (loadingRecords.value && recordsLoaded.value) return '加载更多...'
|
||||
if (hasMore.value) return '上拉加载更多'
|
||||
return records.value.length > 0 ? '已经到底啦' : ''
|
||||
})
|
||||
|
||||
function goBack() {
|
||||
@@ -166,12 +156,54 @@ function goBack() {
|
||||
})
|
||||
}
|
||||
|
||||
function openReport() {
|
||||
function openReport(evaluationId: number) {
|
||||
if (!evaluationId) {
|
||||
showToast('未找到报告 ID')
|
||||
return
|
||||
}
|
||||
uni.setStorageSync('clinical-thinking-current-evaluation-id', evaluationId)
|
||||
uni.navigateTo({
|
||||
url: '/pages/assessment/assessment'
|
||||
url: `/pages/assessment/assessment?evaluation_id=${encodeURIComponent(String(evaluationId))}`
|
||||
})
|
||||
}
|
||||
|
||||
async function loadRecords(page = 1, append = false) {
|
||||
const seq = ++requestSeq
|
||||
loadingRecords.value = true
|
||||
if (!append) {
|
||||
recordsFailed.value = false
|
||||
hasMore.value = false
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await fetchUserTrainingRecords({
|
||||
search: keyword.value.trim(),
|
||||
page
|
||||
})
|
||||
if (seq !== requestSeq) return
|
||||
|
||||
records.value = append ? records.value.concat(result.results || []) : result.results || []
|
||||
summary.value = result.summary || summary.value
|
||||
totalCount.value = result.count || records.value.length
|
||||
currentPage.value = page
|
||||
hasMore.value = Boolean(result.next) || records.value.length < totalCount.value
|
||||
recordsLoaded.value = true
|
||||
recordsFailed.value = false
|
||||
} catch (error) {
|
||||
if (seq !== requestSeq) return
|
||||
recordsFailed.value = true
|
||||
if (!append) records.value = []
|
||||
showToast(error instanceof Error ? error.message : '训练记录加载失败')
|
||||
} finally {
|
||||
if (seq === requestSeq) loadingRecords.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function loadMoreRecords() {
|
||||
if (!hasMore.value || loadingRecords.value) return
|
||||
void loadRecords(currentPage.value + 1, true)
|
||||
}
|
||||
|
||||
function showToast(message: string) {
|
||||
if (toastTimer) clearTimeout(toastTimer)
|
||||
toastMessage.value = message
|
||||
@@ -181,8 +213,44 @@ function showToast(message: string) {
|
||||
}, 2200)
|
||||
}
|
||||
|
||||
function formatDate(value: string) {
|
||||
if (!value) return '--'
|
||||
const date = new Date(value)
|
||||
if (Number.isNaN(date.getTime())) return value
|
||||
const month = `${date.getMonth() + 1}`.padStart(2, '0')
|
||||
const day = `${date.getDate()}`.padStart(2, '0')
|
||||
return `${date.getFullYear()}-${month}-${day}`
|
||||
}
|
||||
|
||||
function formatNumber(value: number) {
|
||||
if (!Number.isFinite(value)) return '0'
|
||||
return Number.isInteger(value) ? String(value) : value.toFixed(1)
|
||||
}
|
||||
|
||||
function readRecordAbbr(record: TrainingRecord) {
|
||||
const source = record.department || record.case_title || '训'
|
||||
return source.trim().slice(0, 1) || '训'
|
||||
}
|
||||
|
||||
function readTone(index: number) {
|
||||
const tones = ['primary', 'secondary', 'tertiary'] as const
|
||||
return tones[index % tones.length]
|
||||
}
|
||||
|
||||
watch(keyword, () => {
|
||||
if (searchTimer) clearTimeout(searchTimer)
|
||||
searchTimer = setTimeout(() => {
|
||||
void loadRecords(1)
|
||||
}, 350)
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
void loadRecords(1)
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
if (toastTimer) clearTimeout(toastTimer)
|
||||
if (searchTimer) clearTimeout(searchTimer)
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user