Files
wer-admin/src/views/biz/appUser/components/detail/ResetTab.vue
2026-10-31 10:35:50 +08:00

93 lines
2.9 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div v-loading="loading" class="reset-panel">
<div v-if="resetRecords.length" class="card-list">
<div v-for="record in resetRecords" :key="record.id" class="record-card">
<div class="card-head">
<div class="card-room">{{ record.roomNo }}</div>
<div class="card-meta">{{ record.deviceText }}</div>
</div>
<div class="card-metrics">
<div class="metric-block">
<span class="metric-label">清零前读数</span>
<span class="metric-value">{{ record.beforeReading || '-'}}</span>
</div>
<div class="metric-block">
<span class="metric-label">清零后读数</span>
<span class="metric-value is-highlight">{{ record.afterReading || '-' }}</span>
</div>
</div>
<div class="card-time">清零时间:{{ record.resetTime || '-'}}</div>
</div>
</div>
<el-empty v-else-if="!loading" description="暂无清零记录" />
</div>
</template>
<script setup name="ResetTab" lang="ts">
import { listAppUserResets } from '@/api/appUser';
import type { AppUserResetVO } from '@/api/appUser/types';
import { useLoading } from '@/hooks/async/useLoading';
import { deviceLabel, formatReading, normalizeRecordList, quantityUnit, valueOrDash } from './helpers';
const props = defineProps<{ userId?: string | number }>();
/** 清零记录行 */
interface ResetRecordItem {
id: string | number;
roomNo: string;
deviceText: string;
beforeReading: string;
afterReading: string;
resetTime: string;
}
const { loading, withLoading } = useLoading(false);
const records = ref<AppUserResetVO[]>([]);
/** 后端记录 → 列表展示项:只展示清零前后读数 / 清零时间 */
const resetRecords = computed<ResetRecordItem[]>(() =>
records.value.map(record => {
const unit = quantityUnit(record);
return {
id: record.id,
roomNo: String(valueOrDash(record.roomNo)),
deviceText: deviceLabel(record),
beforeReading: formatReading(record.beforeReadingValue, unit),
afterReading: formatReading(record.afterReadingValue, unit),
resetTime: record.resetTime || '—'
};
})
);
/** 查询清零记录:GET /userManage/appUser/resets/{userId} */
const getList = async () => {
const currentUserId = props.userId;
if (currentUserId === undefined || currentUserId === null || currentUserId === '') {
records.value = [];
return;
}
try {
await withLoading(async () => {
const res = await listAppUserResets(currentUserId);
records.value = normalizeRecordList<AppUserResetVO>(res.data, record => record.id != null);
});
} catch {
// 请求异常已由 request 统一提示,这里保持上次渲染结果
}
};
onMounted(() => {
getList();
});
</script>
<style lang="scss" scoped>
@use '@/assets/styles/components/detail-panels' as panels;
.reset-panel {
min-height: 120px;
}
@include panels.record-card-list;
</style>