设备管理和用户管理相关功能页面

This commit is contained in:
zhouyanli
2026-10-30 14:16:09 +08:00
parent febbb83dad
commit 87089fd310
30 changed files with 5429 additions and 233 deletions

View File

@@ -0,0 +1,237 @@
<template>
<el-dialog v-model="open" title="绑定设备" width="440px" append-to-body class="bind-device-dialog">
<el-input v-model="keyword" class="bind-search" placeholder="请输入设备编号/名称搜索" clearable>
<template #prefix><el-icon><Search /></el-icon></template>
</el-input>
<div v-loading="loading" class="bind-list">
<div
v-for="device in filteredDevices"
:key="String(device.deviceId)"
class="bind-row"
:class="{ 'is-selected': isSelected(device) }"
@click="selectDevice(device)"
>
<el-radio
:model-value="selectedDeviceId"
:value="String(device.deviceId)"
class="bind-radio"
@click.stop
@change="selectDevice(device)"
/>
<span class="bind-icon">
<el-icon :size="16"><component :is="deviceIcon(device)" /></el-icon>
</span>
<div class="bind-info">
<div class="bind-room">{{ device.roomNo || '—' }}</div>
<div class="bind-meta">{{ deviceTypeText(device) }}·{{ device.deviceNo || '—' }}</div>
</div>
<!-- 接口只返回可绑定设备,列表内均为未绑定 -->
<span class="bind-tag">未绑定</span>
</div>
<el-empty v-if="!loading && !filteredDevices.length" description="暂无可绑定设备" :image-size="72" />
</div>
<template #footer>
<div class="bind-footer">
<el-button @click="open = false">取 消</el-button>
<el-button type="primary" :loading="submitting" :disabled="!selectedDeviceId" @click="handleConfirm">确定绑定</el-button>
</div>
</template>
</el-dialog>
</template>
<script setup name="BindDeviceDialog" lang="ts">
import { bindAppUserDevices, getBindableDevices } from '@/api/appUser';
import { AppUserBindingVO } from '@/api/appUser/types';
import { useLoading } from '@/hooks/async/useLoading';
import modal from '@/plugins/modal';
import { getDeviceTypeLabel, useDeviceTypeDict } from '../../device/constants';
const emit = defineEmits<{
success: [];
}>();
const open = ref(false);
const keyword = ref('');
/** 当前查看的用户ID,打开弹窗时由父组件传入 */
const userId = ref<string | number>('');
const deviceList = ref<AppUserBindingVO[]>([]);
/** 单选的设备ID */
const selectedDeviceId = ref('');
const submitting = ref(false);
const { loading, withLoading } = useLoading(false);
const deviceTypeDict = useDeviceTypeDict();
/** 本地按设备编号 / 名称 / 房间过滤 */
const filteredDevices = computed(() => {
const kw = keyword.value.trim();
if (!kw) return deviceList.value;
return deviceList.value.filter(device =>
[device.deviceNo, device.deviceName, device.roomNo].some(field => String(field ?? '').includes(kw))
);
});
/** 电表、水表分别用不同图标,其余统一用采集器图标 */
const deviceIcon = (device: AppUserBindingVO) => {
if (String(device.deviceType) === '0') return 'Lightning';
if (String(device.deviceType) === '1') return 'Drizzling';
return 'Monitor';
};
const deviceTypeText = (device: AppUserBindingVO) => getDeviceTypeLabel(deviceTypeDict.value, device.deviceType);
const isSelected = (device: AppUserBindingVO) => selectedDeviceId.value === String(device.deviceId);
/** 单选:再次点击同一行保持选中 */
const selectDevice = (device: AppUserBindingVO) => {
selectedDeviceId.value = String(device.deviceId);
};
/** 兼容后端返回数组 / 分页对象 */
const normalizeDevices = (data: unknown): AppUserBindingVO[] => {
if (Array.isArray(data)) return data as AppUserBindingVO[];
if (data && typeof data === 'object') {
const record = data as Record<string, any>;
if (Array.isArray(record.rows)) return record.rows;
if (Array.isArray(record.list)) return record.list;
if (Array.isArray(record.records)) return record.records;
}
return [];
};
/** 加载可绑定设备:GET /userManage/appUser/bindableDevices/{userId} */
const loadDevices = async () => {
if (!userId.value) {
deviceList.value = [];
return;
}
await withLoading(async () => {
try {
const res = await getBindableDevices(userId.value);
deviceList.value = normalizeDevices(res.data);
} catch {
// 请求层已统一提示错误,这里只需保证弹窗可用
deviceList.value = [];
}
});
};
/** 打开绑定弹窗 */
const openDialog = async (currentUserId: string | number) => {
userId.value = currentUserId;
keyword.value = '';
selectedDeviceId.value = '';
open.value = true;
await loadDevices();
};
/** 绑定选中设备:POST /userManage/appUser/bindings/{userId} */
const handleConfirm = async () => {
if (!selectedDeviceId.value) return;
submitting.value = true;
try {
await bindAppUserDevices(userId.value, [selectedDeviceId.value]);
modal.msgSuccess('绑定成功');
open.value = false;
emit('success');
} finally {
submitting.value = false;
}
};
defineExpose({
openDialog
});
</script>
<style lang="scss" scoped>
.bind-search {
margin-bottom: 16px;
}
.bind-list {
display: flex;
flex-direction: column;
gap: 12px;
min-height: 120px;
}
.bind-row {
display: flex;
align-items: center;
gap: 12px;
padding: 12px 14px;
cursor: pointer;
border: 1px solid var(--app-surface-border);
border-radius: 8px;
transition:
border-color 0.2s,
background-color 0.2s;
&:hover {
border-color: var(--el-color-primary-light-5);
}
&.is-selected {
background: var(--app-accent-soft);
border-color: var(--el-color-primary-light-3);
}
}
.bind-radio {
flex: 0 0 auto;
height: auto;
margin-right: 0;
/* 单选只留圆点,文字由右侧信息展示 */
:deep(.el-radio__label) {
display: none;
}
}
.bind-icon {
display: inline-flex;
align-items: center;
justify-content: center;
flex: 0 0 34px;
width: 34px;
height: 34px;
color: var(--el-color-primary);
background: var(--app-accent-soft);
border-radius: 8px;
}
.bind-info {
flex: 1 1 auto;
min-width: 0;
}
.bind-room {
font-size: 15px;
font-weight: 600;
color: var(--el-text-color-primary);
}
.bind-meta {
margin-top: 4px;
font-size: 12px;
color: var(--el-text-color-secondary);
}
.bind-tag {
flex: 0 0 auto;
padding: 2px 12px;
font-size: 12px;
color: var(--el-text-color-regular);
border: 1px solid var(--app-surface-border);
border-radius: 999px;
}
.bind-footer {
display: flex;
justify-content: center;
gap: 12px;
}
</style>

View File

@@ -0,0 +1,158 @@
<template>
<div v-if="devices.length" class="device-grid">
<div v-for="device in devices" :key="String(device.deviceId)" class="device-card">
<div class="device-head">
<span class="device-icon">
<el-icon :size="18"><component :is="deviceIcon(device)" /></el-icon>
</span>
<div class="device-title">
<div class="device-room">{{ device.roomNo || '—' }}</div>
<div class="device-no">{{ deviceTypeText(device) }}:{{ valueOrDash(device.deviceNo) }}</div>
</div>
<el-tag :type="switchStatusTagType(device)" effect="light" round size="small">
{{ getSwitchStatusLabel(device.switchStatus) }}
</el-tag>
</div>
<div class="device-metrics">
<div class="metric">
<span class="metric-label">剩余量</span>
<span class="metric-value">{{ formatQuantity(device) }}</span>
</div>
<div class="metric">
<span class="metric-label">单价</span>
<span class="metric-value">{{ formatPrice(device) }}</span>
</div>
</div>
<div class="device-actions">
<el-button link type="danger" @click="emit('unbind', device)">解绑设备</el-button>
</div>
</div>
</div>
<el-empty v-else description="暂无绑定设备" />
</template>
<script setup name="DeviceTab" lang="ts">
import type { AppUserBindingVO } from '@/api/appUser/types';
import { getDeviceTypeLabel, getSwitchStatusLabel, getSwitchStatusOption, useDeviceTypeDict } from '../../../device/constants';
import { deviceIcon, formatPrice, formatQuantity, valueOrDash } from './helpers';
defineProps<{
/** 已绑定设备列表 */
devices: AppUserBindingVO[];
}>();
const emit = defineEmits<{
/** 解绑设备(由父组件统一处理) */
unbind: [device: AppUserBindingVO];
}>();
const deviceTypeDict = useDeviceTypeDict();
/** 设备类型文案,字典未加载时回退原始值 */
const deviceTypeText = (device: AppUserBindingVO) => getDeviceTypeLabel(deviceTypeDict.value, device.deviceType);
/** 控制状态标签配色 */
const switchStatusTagType = (device: AppUserBindingVO) => {
return (getSwitchStatusOption(device.switchStatus)?.elTagType as 'success' | 'danger' | 'warning' | 'info' | 'primary') || 'info';
};
</script>
<style lang="scss" scoped>
.device-grid {
display: flex;
flex-wrap: wrap;
gap: 24px;
}
.device-card {
display: flex;
flex-direction: column;
width: 384px;
max-width: 100%;
padding: 18px 20px 12px;
border: 1px solid var(--app-surface-border);
border-radius: 10px;
}
.device-head {
display: flex;
align-items: flex-start;
gap: 10px;
}
.device-icon {
display: inline-flex;
align-items: center;
justify-content: center;
flex: 0 0 34px;
width: 34px;
height: 34px;
color: var(--el-color-primary);
background: var(--app-accent-soft);
border-radius: 8px;
}
.device-title {
flex: 1 1 auto;
min-width: 0;
}
.device-room {
font-size: 15px;
font-weight: 700;
color: var(--el-text-color-primary);
}
.device-no {
margin-top: 4px;
font-size: 12px;
color: var(--el-text-color-secondary);
}
.device-metrics {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 12px;
margin-top: 20px;
}
.metric {
display: flex;
flex-direction: column;
gap: 6px;
}
.metric-label {
font-size: 13px;
font-weight: 700;
color: var(--el-text-color-primary);
}
.metric-value {
font-size: 14px;
color: var(--el-text-color-regular);
}
.device-actions {
display: flex;
justify-content: flex-end;
margin-top: 10px;
/* 全局给表格里的 link 按钮加了底色,这里只保留纯文字 */
:deep(.el-button.is-link) {
width: auto !important;
min-width: auto !important;
height: auto !important;
padding: 0 !important;
background: transparent !important;
}
}
@media (max-width: 960px) {
.device-card {
width: 100%;
}
}
</style>

View File

@@ -0,0 +1,42 @@
<template>
<div v-if="historyDevices.length" class="record-list">
<div v-for="item in historyDevices" :key="item.id" class="record-row">
<div class="record-main">
<div class="record-title">{{ item.deviceText }}</div>
<div class="record-sub">{{ item.roomNo }}</div>
</div>
<div class="record-side">
<span class="unbound-tag">已解绑</span>
<div class="record-amount">解绑时间:{{ item.unboundAt }}</div>
</div>
</div>
</div>
<el-empty v-else description="暂无历史设备" />
</template>
<script setup name="HistoryTab" lang="ts">
/** 历史设备行 */
interface HistoryDeviceItem {
id: string | number;
roomNo: string;
deviceText: string;
unboundAt: string;
}
/** TODO: 历史设备接口待接入,先用演示数据占位 */
const historyDevices = ref<HistoryDeviceItem[]>([
{
id: 1,
roomNo: '101室',
deviceText: '蓝牙水表 · NO20260101',
unboundAt: '2026年9月18日 09:03:12'
}
]);
</script>
<style lang="scss" scoped>
@use '@/assets/styles/components/detail-panels' as panels;
@include panels.record-list;
@include panels.unbound-tag;
</style>

View File

@@ -0,0 +1,86 @@
<template>
<div v-if="paymentGroups.length" class="record-list">
<div v-for="group in paymentGroups" :key="group.date" class="record-group">
<div class="record-date">{{ group.date }}</div>
<div v-for="record in group.records" :key="record.id" class="record-row">
<div class="record-main">
<div class="record-title">{{ record.deviceText }}</div>
<div class="record-sub">{{ record.typeText }}</div>
</div>
<div class="record-side">
<div class="record-status" :class="record.success ? 'is-success' : 'is-failed'">{{ record.statusText }}</div>
<div class="record-amount">¥{{ record.amount }}</div>
</div>
</div>
</div>
</div>
<el-empty v-else description="暂无支付记录" />
</template>
<script setup name="PaymentTab" lang="ts">
import { formatDate } from './helpers';
/** 支付记录行 */
interface PaymentRecordItem {
id: string | number;
deviceText: string;
typeText: string;
statusText: string;
success: boolean;
amount: number;
paidAt: string;
}
/** TODO: 支付记录接口待接入,先用演示数据占位 */
const paymentRecords = ref<PaymentRecordItem[]>([
{
id: 1,
deviceText: '蓝牙电表 · NO20260101',
typeText: '电费充值',
statusText: '支付成功',
success: true,
amount: 200,
paidAt: '2026-09-21 11:02:52'
},
{
id: 2,
deviceText: '蓝牙水表 · NO20260101',
typeText: '水费充值',
statusText: '支付失败',
success: false,
amount: 200,
paidAt: '2026-09-21 10:31:08'
},
{
id: 3,
deviceText: '蓝牙电表 · NO20260101',
typeText: '电费充值',
statusText: '支付成功',
success: true,
amount: 200,
paidAt: '2026-09-21 09:12:40'
}
]);
/** 支付记录按日期分组 */
const paymentGroups = computed(() => {
const groups: Array<{ date: string; records: PaymentRecordItem[] }> = [];
paymentRecords.value.forEach(record => {
const date = formatDate(record.paidAt);
const group = groups.find(item => item.date === date);
if (group) {
group.records.push(record);
} else {
groups.push({ date, records: [record] });
}
});
return groups;
});
</script>
<style lang="scss" scoped>
@use '@/assets/styles/components/detail-panels' as panels;
@include panels.record-list;
@include panels.record-status;
</style>

View File

@@ -0,0 +1,116 @@
<template>
<div class="reading-panel">
<!-- 抄表记录按日期区间筛选 -->
<div class="reading-toolbar">
<span class="reading-toolbar__label">抄表时间</span>
<el-date-picker
v-model="readingDateRange"
type="daterange"
value-format="YYYY-MM-DD"
range-separator="-"
start-placeholder="开始日期"
end-placeholder="结束日期"
clearable
class="reading-date-picker"
/>
</div>
<div v-if="filteredReadingRecords.length" class="card-list">
<div v-for="record in filteredReadingRecords" :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 card-metrics--three">
<div class="metric-block">
<span class="metric-label">起始读数</span>
<span class="metric-value">{{ record.previousReading }}{{ record.unit }}</span>
</div>
<div class="metric-block">
<span class="metric-label">截止读数</span>
<span class="metric-value is-highlight">{{ record.reading }}{{ record.unit }}</span>
</div>
<div class="metric-block">
<span class="metric-label">区间用量</span>
<span class="metric-value">{{ record.usage }}{{ record.unit }}</span>
</div>
</div>
</div>
</div>
<el-empty v-else :description="readingDateRange?.length ? '该时间段内暂无抄表记录' : '暂无抄表记录'" />
</div>
</template>
<script setup name="ReadingTab" lang="ts">
/** 抄表记录行 */
interface ReadingRecordItem {
id: string | number;
roomNo: string;
deviceText: string;
previousReading: number;
reading: number;
usage: number;
unit: string;
readingTime: string;
}
/** TODO: 抄表记录接口待接入,先用演示数据占位 */
const readingRecords = ref<ReadingRecordItem[]>([
{
id: 1,
roomNo: '101室',
deviceText: '蓝牙电表 · NO20260101',
previousReading: 1234,
reading: 1250,
usage: 16,
unit: '度',
readingTime: '2026-09-21 11:02:52'
},
{
id: 2,
roomNo: '101室',
deviceText: '蓝牙水表 · NO20260101',
previousReading: 156,
reading: 168.6,
usage: 12.6,
unit: '吨',
readingTime: '2026-09-18 09:03:12'
}
]);
/** 抄表记录时间筛选区间(YYYY-MM-DD),为空表示不筛选 */
const readingDateRange = ref<[string, string] | null>(null);
/** 抄表记录按所选时间区间过滤,接口接入后改为传 startTime / endTime 到后端 */
const filteredReadingRecords = computed(() => {
const [start, end] = readingDateRange.value || [];
if (!start || !end) return readingRecords.value;
return readingRecords.value.filter(record => {
const day = String(record.readingTime || '').slice(0, 10);
return !!day && day >= start && day <= end;
});
});
</script>
<style lang="scss" scoped>
@use '@/assets/styles/components/detail-panels' as panels;
@include panels.record-card-list;
.reading-toolbar {
display: flex;
justify-self: start;
align-items: center;
gap: 10px;
margin-bottom: 16px;
}
.reading-toolbar__label {
font-size: 13px;
color: var(--el-text-color-regular);
}
.reading-date-picker {
width: 260px;
}
</style>

View File

@@ -0,0 +1,54 @@
<template>
<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 }}{{ record.unit }}</span>
</div>
<div class="metric-block">
<span class="metric-label">清零后读数</span>
<span class="metric-value is-highlight">{{ record.afterReading }}{{ record.unit }}</span>
</div>
</div>
<div class="card-time">清零时间:{{ record.resetTime }}</div>
</div>
</div>
<el-empty v-else description="暂无清零记录" />
</template>
<script setup name="ResetTab" lang="ts">
/** 清零记录行 */
interface ResetRecordItem {
id: string | number;
roomNo: string;
deviceText: string;
beforeReading: number;
afterReading: number;
unit: string;
resetTime: string;
}
/** TODO: 清零记录接口待接入,先用演示数据占位 */
const resetRecords = ref<ResetRecordItem[]>([
{
id: 1,
roomNo: '101室',
deviceText: '蓝牙电表 · NO20260101',
beforeReading: 1234,
afterReading: 0,
unit: '度',
resetTime: '2026年9月21日 11:20:45'
}
]);
</script>
<style lang="scss" scoped>
@use '@/assets/styles/components/detail-panels' as panels;
@include panels.record-card-list;
</style>

View File

@@ -0,0 +1,102 @@
<template>
<el-card shadow="hover" class="summary-card">
<div class="summary-row">
<div class="summary-identity">
<el-avatar :size="48" :src="user.avatarUrl" class="user-avatar">{{ avatarText }}</el-avatar>
<div class="identity-text">
<div class="identity-name">{{ userName }}</div>
<div class="identity-line">用户ID:{{ user.userId }}</div>
<div class="identity-line">注册时间:{{ formatDate(user.createTime) }}</div>
</div>
</div>
<div class="summary-group">
<div class="summary-line">手机号:{{ user.phoneNumber || '—' }}</div>
<div class="summary-line">房间号:{{ user.roomNo || user.roomName || '—' }}</div>
</div>
<div class="summary-group">
<div class="summary-line">绑定设备:{{ deviceCountText }}</div>
<div class="summary-line">最近缴费:{{ user.lastRechargeTime || '—' }}</div>
</div>
</div>
</el-card>
</template>
<script setup name="UserSummaryCard" lang="ts">
import type { AppUserVO } from '@/api/appUser/types';
import { formatDate } from './helpers';
const props = defineProps<{
/** 用户概要信息 */
user: Partial<AppUserVO>;
/** 已绑定设备数量 */
deviceCount: number;
}>();
/** 姓名优先昵称,其次实名姓名 */
const userName = computed(() => props.user.nickName || props.user.realName || '—');
/** 无头像时用姓名首字兜底 */
const avatarText = computed(() => (userName.value === '—' ? 'U' : userName.value.slice(0, 1)));
const deviceCountText = computed(() => (props.deviceCount ? `${props.deviceCount}台` : '0台'));
</script>
<style lang="scss" scoped>
.summary-card {
:deep(.el-card__body) {
padding: 22px 26px;
}
}
.summary-row {
display: grid;
grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr) minmax(0, 1fr);
gap: 24px;
align-items: center;
}
.summary-identity {
display: flex;
align-items: center;
gap: 14px;
min-width: 0;
}
.user-avatar {
flex: 0 0 48px;
color: #fff;
background: #b9dcff;
}
.identity-name {
font-size: 20px;
font-weight: 700;
color: var(--el-text-color-primary);
}
.identity-line {
margin-top: 4px;
font-size: 13px;
color: var(--el-text-color-regular);
}
.summary-group {
display: flex;
flex-direction: column;
gap: 10px;
min-width: 0;
}
.summary-line {
font-size: 13px;
color: var(--el-text-color-regular);
word-break: break-all;
}
@media (max-width: 960px) {
.summary-row {
grid-template-columns: minmax(0, 1fr);
gap: 18px;
}
}
</style>

View File

@@ -0,0 +1,33 @@
import type { AppUserBindingVO } from '@/api/appUser/types';
/** 空值统一显示占位符 */
export const valueOrDash = (value?: string | number | null) => (value === undefined || value === null || value === '' ? '—' : value);
/** 日期展示成「2026年9月21日」 */
export const formatDate = (value?: string) => {
if (!value) return '—';
const matched = String(value).match(/^(\d{4})-(\d{1,2})-(\d{1,2})/);
return matched ? `${matched[1]}年${Number(matched[2])}月${Number(matched[3])}日` : String(value);
};
/** 计量单位:电表按度、水表按吨,优先后端 unitName */
export const quantityUnit = (device: AppUserBindingVO) => {
if (String(device.unitName) === '0') return '度';
if (String(device.unitName) === '1') return '吨';
return String(device.deviceType) === '1' ? '吨' : '度';
};
export const formatQuantity = (device: AppUserBindingVO) =>
device.currentQuantity === undefined || device.currentQuantity === null ? '—' : `${device.currentQuantity}${quantityUnit(device)}`;
export const formatPrice = (device: AppUserBindingVO) =>
device.currentUnitPrice === undefined || device.currentUnitPrice === null
? '—'
: `${device.currentUnitPrice}元/${quantityUnit(device)}`;
/** 电表、水表分别用不同图标,其余统一用采集器图标 */
export const deviceIcon = (device: AppUserBindingVO) => {
if (String(device.deviceType) === '0') return 'Lightning';
if (String(device.deviceType) === '1') return 'Drizzling';
return 'Monitor';
};