用户列表详情联调

This commit is contained in:
zhouyanli
2026-10-31 10:35:50 +08:00
parent 87089fd310
commit e93fb83bc1
9 changed files with 588 additions and 202 deletions

View File

@@ -1,4 +1,14 @@
import type { AppUserBindingVO, AppUserForm, AppUserQuery, AppUserVO } from '@/api/appUser/types'; import type {
AppUserBindingVO,
AppUserForm,
AppUserQuery,
AppUserReadingQuery,
AppUserReadingVO,
AppUserRechargeQuery,
AppUserRechargeVO,
AppUserResetVO,
AppUserVO
} from '@/api/appUser/types';
import type { PageResult } from '@/api/types'; import type { PageResult } from '@/api/types';
import type { AxiosPromise } from '@/utils/api-types'; import type { AxiosPromise } from '@/utils/api-types';
import request from '@/utils/request'; import request from '@/utils/request';
@@ -39,12 +49,57 @@ export const getAppUserDetail = (userId: string | number): AxiosPromise<AppUserV
}; };
/** /**
* 查询用户已绑定的设备列表 * 查询用户绑定记录(当前设备 / 历史设备共用一个接口)
* @param userId * @param userId
* @param history true:查历史设备,false:查当前绑定设备
*/ */
export const getAppUserBindings = (userId: string | number): AxiosPromise<PageResult<AppUserBindingVO>> => { export const getAppUserBindings = (userId: string | number, history = false): AxiosPromise<PageResult<AppUserBindingVO>> => {
return request({ return request({
url: '/userManage/appUser/bindings/' + userId, url: '/userManage/appUser/bindings/' + userId,
method: 'get',
params: { history }
});
};
/**
* 查询用户支付记录
* @param userId
* @param query 分页参数
*/
export const listAppUserRecharges = (
userId: string | number,
query?: AppUserRechargeQuery
): AxiosPromise<PageResult<AppUserRechargeVO>> => {
return request({
url: '/userManage/appUser/recharges/' + userId,
method: 'get',
params: query
});
};
/**
* 查询用户抄表记录
* @param userId
* @param query 抄表时间区间(beginTime / endTime)
*/
export const listAppUserReadings = (
userId: string | number,
query?: AppUserReadingQuery
): AxiosPromise<PageResult<AppUserReadingVO> | AppUserReadingVO[]> => {
return request({
url: '/userManage/appUser/readings/' + userId,
method: 'get',
params: query
});
};
/**
* 查询用户清零记录
* @param userId
*/
export const listAppUserResets = (userId: string | number): AxiosPromise<PageResult<AppUserResetVO> | AppUserResetVO[]> => {
return request({
url: '/userManage/appUser/resets/' + userId,
method: 'get' method: 'get'
}); });
}; };
@@ -73,6 +128,18 @@ export const bindAppUserDevices = (userId: string | number, deviceIds: Array<str
}); });
}; };
/**
* 解绑用户设备
* @param userId
* @param deviceId
*/
export const unbindAppUserDevice = (userId: string | number, deviceId: string | number) => {
return request({
url: '/userManage/appUser/bindingsHistory/' + userId + '/' + deviceId,
method: 'delete'
});
};
/** /**
* 新增小程序用户 * 新增小程序用户
* @param data * @param data
@@ -99,6 +166,18 @@ export const updateAppUser = (data: AppUserForm) => {
/**
* 修改小程序用户状态(启用 / 停用)
* @param userId
* @param status 状态(0正常 1停用)
*/
export const changeAppUserStatus = (userId: string | number, status: string) => {
return request({
url: '/userManage/appUser/status/' + userId + '/' + status,
method: 'put'
});
};
/** /**
* 删除小程序用户 * 删除小程序用户
* @param userId * @param userId

View File

@@ -149,6 +149,10 @@ export interface AppUserBindingVO {
* 支付时间 * 支付时间
*/ */
paidAt?: string; paidAt?: string;
/**
* 订单完成时间
*/
completedAt?: string;
/** /**
* 上次读数 * 上次读数
*/ */
@@ -187,6 +191,61 @@ export interface AppUserBindingVO {
roomNo?: string; roomNo?: string;
} }
/**
* 用户支付记录(后端 /userManage/appUser/recharges/{userId} 返回的行结构,字段与绑定记录一致)
*/
export type AppUserRechargeVO = AppUserBindingVO;
/**
* 用户支付记录查询参数
*/
export interface AppUserRechargeQuery extends PageQuery {
/**
* 设备类型(0:电表,1:水表)
*/
deviceType?: string;
/**
* 支付方式
*/
paymentMethod?: string;
/**
* 订单状态(0成功 1失败)
*/
orderStatus?: string;
/**
* 支付开始时间
*/
beginTime?: string;
/**
* 支付结束时间
*/
endTime?: string;
}
/**
* 用户抄表记录(后端 /userManage/appUser/readings/{userId} 返回的行结构)
*/
export type AppUserReadingVO = AppUserBindingVO;
/**
* 用户抄表记录查询参数
*/
export interface AppUserReadingQuery {
/**
* 抄表开始时间
*/
beginTime?: string;
/**
* 抄表结束时间
*/
endTime?: string;
}
/**
* 用户清零记录(后端 /userManage/appUser/resets/{userId} 返回的行结构)
*/
export type AppUserResetVO = AppUserBindingVO;
export interface AppUserForm extends BaseEntity { export interface AppUserForm extends BaseEntity {
/** /**
* 小程序用户ID * 小程序用户ID

View File

@@ -1,20 +1,29 @@
<template> <template>
<div v-if="historyDevices.length" class="record-list"> <div v-loading="loading" class="history-panel">
<div v-for="item in historyDevices" :key="item.id" class="record-row"> <div v-if="historyDevices.length" class="record-list">
<div class="record-main"> <div v-for="item in historyDevices" :key="item.id" class="record-row">
<div class="record-title">{{ item.deviceText }}</div> <div class="record-main">
<div class="record-sub">{{ item.roomNo }}</div> <div class="record-title">{{ item.deviceText }}</div>
</div> <div class="record-sub">{{ item.roomNo }}</div>
<div class="record-side"> </div>
<span class="unbound-tag">已解绑</span> <div class="record-side">
<div class="record-amount">解绑时间:{{ item.unboundAt }}</div> <span class="unbound-tag">已解绑</span>
<div class="record-amount">解绑时间:{{ item.unboundAt }}</div>
</div>
</div> </div>
</div> </div>
<el-empty v-else-if="!loading" description="暂无历史设备" />
</div> </div>
<el-empty v-else description="暂无历史设备" />
</template> </template>
<script setup name="HistoryTab" lang="ts"> <script setup name="HistoryTab" lang="ts">
import { getAppUserBindings } from '@/api/appUser';
import type { AppUserBindingVO } from '@/api/appUser/types';
import { useLoading } from '@/hooks/async/useLoading';
import { deviceLabel, normalizeRecordList, valueOrDash } from './helpers';
const props = defineProps<{ userId?: string | number }>();
/** 历史设备行 */ /** 历史设备行 */
interface HistoryDeviceItem { interface HistoryDeviceItem {
id: string | number; id: string | number;
@@ -23,20 +32,48 @@ interface HistoryDeviceItem {
unboundAt: string; unboundAt: string;
} }
/** TODO: 历史设备接口待接入,先用演示数据占位 */ const { loading, withLoading } = useLoading(false);
const historyDevices = ref<HistoryDeviceItem[]>([ const records = ref<AppUserBindingVO[]>([]);
{
id: 1, /** 后端记录 → 列表展示项 */
roomNo: '101室', const historyDevices = computed<HistoryDeviceItem[]>(() =>
deviceText: '蓝牙水表 · NO20260101', records.value.map(record => ({
unboundAt: '2026年9月18日 09:03:12' id: record.id,
roomNo: String(valueOrDash(record.roomNo)),
deviceText: deviceLabel(record),
unboundAt: record.unboundAt || '—'
}))
);
/** 查询历史设备:GET /userManage/appUser/bindings/{userId}?history=true */
const getList = async () => {
const currentUserId = props.userId;
if (currentUserId === undefined || currentUserId === null || currentUserId === '') {
records.value = [];
return;
} }
]); try {
await withLoading(async () => {
const res = await getAppUserBindings(currentUserId, true);
records.value = normalizeRecordList<AppUserBindingVO>(res.data, record => record.deviceId != null);
});
} catch {
// 请求异常已由 request 统一提示,这里保持上次渲染结果
}
};
onMounted(() => {
getList();
});
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@use '@/assets/styles/components/detail-panels' as panels; @use '@/assets/styles/components/detail-panels' as panels;
.history-panel {
min-height: 120px;
}
@include panels.record-list; @include panels.record-list;
@include panels.unbound-tag; @include panels.unbound-tag;
</style> </style>

View File

@@ -1,86 +1,191 @@
<template> <template>
<div v-if="paymentGroups.length" class="record-list"> <div class="payment-panel">
<div v-for="group in paymentGroups" :key="group.date" class="record-group"> <!-- 支付记录筛选 -->
<div class="record-date">{{ group.date }}</div> <el-form :model="queryParams" :inline="true" class="query-form payment-filter">
<div v-for="record in group.records" :key="record.id" class="record-row"> <el-form-item prop="deviceType">
<div class="record-main"> <el-select v-model="queryParams.deviceType" placeholder="请选择设备类型" clearable>
<div class="record-title">{{ record.deviceText }}</div> <el-option label="电表" value="0" />
<div class="record-sub">{{ record.typeText }}</div> <el-option label="水表" value="1" />
</div> </el-select>
<div class="record-side"> </el-form-item>
<div class="record-status" :class="record.success ? 'is-success' : 'is-failed'">{{ record.statusText }}</div> <el-form-item>
<div class="record-amount">¥{{ record.amount }}</div> <el-date-picker
</div> v-model="dateRange"
</div> type="daterange"
</div> value-format="YYYY-MM-DD"
range-separator="—"
start-placeholder="开始时间"
end-placeholder="结束时间"
clearable
/>
</el-form-item>
<el-form-item prop="orderStatus">
<el-select v-model="queryParams.orderStatus" placeholder="请选择支付状态" clearable>
<el-option label="支付成功" value="0" />
<el-option label="支付失败" value="1" />
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="Search" @click="handleQuery">查询</el-button>
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-table v-loading="loading" border :data="records" class="data-table payment-table" empty-text="暂无支付记录">
<el-table-column label="设备编号" align="center" min-width="140">
<template #default="scope">{{ scope.row.deviceNo || '—' }}</template>
</el-table-column>
<el-table-column label="设备类型" align="center" width="120">
<template #default="scope">{{ deviceTypeText(scope.row.deviceType) }}</template>
</el-table-column>
<el-table-column label="支付金额(¥)" align="center" width="140">
<template #default="scope">{{ formatAmount(scope.row.actualPaymentAmount) }}</template>
</el-table-column>
<el-table-column label="当前金额(¥)" align="center" width="140">
<template #default="scope">{{ formatAmount(scope.row. balanceAfter) }}</template>
</el-table-column>
<el-table-column label="支付时间" align="center" min-width="170">
<template #default="scope">{{ scope.row.paidAt || '—' }}</template>
</el-table-column>
<el-table-column label="支付状态" align="center" width="120">
<template #default="scope">
<span class="payment-status" :class="`is-${orderStatusMeta(scope.row.orderStatus).variant}`">
{{ orderStatusMeta(scope.row.orderStatus).text }}
</span>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total > 0"
v-model:page="queryParams.pageNum"
v-model:limit="queryParams.pageSize"
:total="total"
@pagination="getList"
/>
</div> </div>
<el-empty v-else description="暂无支付记录" />
</template> </template>
<script setup name="PaymentTab" lang="ts"> <script setup name="PaymentTab" lang="ts">
import { formatDate } from './helpers'; import { listAppUserRecharges } from '@/api/appUser';
import type { AppUserRechargeQuery, AppUserRechargeVO } from '@/api/appUser/types';
import { useLoading } from '@/hooks/async/useLoading';
import { normalizeRecordList } from './helpers';
/** 支付记录行 */ const props = defineProps<{ userId?: string | number }>();
interface PaymentRecordItem {
id: string | number;
deviceText: string;
typeText: string;
statusText: string;
success: boolean;
amount: number;
paidAt: string;
}
/** TODO: 支付记录接口待接入,先用演示数据占位 */ /** 订单状态映射:0成功 1失败 */
const paymentRecords = ref<PaymentRecordItem[]>([ const orderStatusMap: Record<string, { text: string; variant: 'success' | 'failed' }> = {
{ '0': { text: '支付成功', variant: 'success' },
id: 1, '1': { text: '支付失败', variant: 'failed' }
deviceText: '蓝牙电表 · NO20260101', };
typeText: '电费充值',
statusText: '支付成功', const { loading, withLoading } = useLoading(false);
success: true, const records = ref<AppUserRechargeVO[]>([]);
amount: 200, const total = ref(0);
paidAt: '2026-09-21 11:02:52' const queryParams = reactive<AppUserRechargeQuery>({
}, pageNum: 1,
{ pageSize: 10,
id: 2, deviceType: undefined,
deviceText: '蓝牙水表 · NO20260101', orderStatus: undefined
typeText: '水费充值', });
statusText: '支付失败', /** 支付时间筛选区间(YYYY-MM-DD),为空表示不筛选 */
success: false, const dateRange = ref<[string, string] | null>(null);
amount: 200,
paidAt: '2026-09-21 10:31:08' const orderStatusMeta = (status?: string): { text: string; variant: 'success' | 'failed' | 'default' } => {
}, const key = String(status ?? '').trim();
{ return orderStatusMap[key] || { text: '—', variant: 'default' };
id: 3, };
deviceText: '蓝牙电表 · NO20260101',
typeText: '电费充值', /** 设备类型:0电表 1水表 */
statusText: '支付成功', const deviceTypeText = (deviceType?: string) => {
success: true, if (String(deviceType) === '0') return '电表';
amount: 200, if (String(deviceType) === '1') return '水表';
paidAt: '2026-09-21 09:12:40' return '—';
};
/** 金额展示:保留两位小数 */
const formatAmount = (value?: number | null) => (value === undefined || value === null ? '—' : Number(value).toFixed(2));
/** 查询支付记录:GET /userManage/appUser/recharges/{userId} */
const getList = async () => {
const currentUserId = props.userId;
if (currentUserId === undefined || currentUserId === null || currentUserId === '') {
records.value = [];
total.value = 0;
return;
} }
]); const [beginTime, endTime] = dateRange.value || [];
const params: AppUserRechargeQuery = {
pageNum: queryParams.pageNum,
pageSize: queryParams.pageSize,
deviceType: queryParams.deviceType || undefined,
orderStatus: queryParams.orderStatus || undefined,
beginTime: beginTime || undefined,
endTime: endTime || undefined
};
try {
await withLoading(async () => {
const res = await listAppUserRecharges(currentUserId, params);
records.value = normalizeRecordList<AppUserRechargeVO>(res.data, record => record.id != null);
total.value = Number(res.data?.total ?? 0);
});
} catch {
// 请求异常已由 request 统一提示,这里保持上次渲染结果
}
};
/** 支付记录按日期分组 */ /** 条件查询:回到第 1 页 */
const paymentGroups = computed(() => { const handleQuery = () => {
const groups: Array<{ date: string; records: PaymentRecordItem[] }> = []; queryParams.pageNum = 1;
paymentRecords.value.forEach(record => { getList();
const date = formatDate(record.paidAt); };
const group = groups.find(item => item.date === date);
if (group) { /** 重置筛选条件后重新查询 */
group.records.push(record); const resetQuery = () => {
} else { queryParams.deviceType = undefined;
groups.push({ date, records: [record] }); queryParams.orderStatus = undefined;
} dateRange.value = null;
}); handleQuery();
return groups; };
onMounted(() => {
getList();
}); });
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@use '@/assets/styles/components/detail-panels' as panels; .payment-panel {
min-height: 120px;
}
@include panels.record-list; .payment-filter {
@include panels.record-status; margin-bottom: 16px;
:deep(.el-select) {
width: 180px;
}
:deep(.el-date-editor) {
width: 260px;
}
}
.payment-table {
width: 100%;
}
/* 支付状态:成功绿色,失败红色,未匹配到状态用中性色 */
.payment-status {
font-size: 14px;
color: var(--el-text-color-regular);
&.is-success {
color: var(--el-color-success);
}
&.is-failed {
color: var(--el-color-danger);
}
}
</style> </style>

View File

@@ -1,6 +1,6 @@
<template> <template>
<div class="reading-panel"> <div v-loading="loading" class="reading-panel">
<!-- 抄表记录按日期区间筛选 --> <!-- 抄表记录按日期区间筛选,区间变化后重新请求后端 -->
<div class="reading-toolbar"> <div class="reading-toolbar">
<span class="reading-toolbar__label">抄表时间</span> <span class="reading-toolbar__label">抄表时间</span>
<el-date-picker <el-date-picker
@@ -15,8 +15,8 @@
/> />
</div> </div>
<div v-if="filteredReadingRecords.length" class="card-list"> <div v-if="readingRecords.length" class="card-list">
<div v-for="record in filteredReadingRecords" :key="record.id" class="record-card"> <div v-for="record in readingRecords" :key="record.id" class="record-card">
<div class="card-head"> <div class="card-head">
<div class="card-room">{{ record.roomNo }}</div> <div class="card-room">{{ record.roomNo }}</div>
<div class="card-meta">{{ record.deviceText }}</div> <div class="card-meta">{{ record.deviceText }}</div>
@@ -24,77 +24,100 @@
<div class="card-metrics card-metrics--three"> <div class="card-metrics card-metrics--three">
<div class="metric-block"> <div class="metric-block">
<span class="metric-label">起始读数</span> <span class="metric-label">起始读数</span>
<span class="metric-value">{{ record.previousReading }}{{ record.unit }}</span> <span class="metric-value">{{ record.previousReading }}</span>
</div> </div>
<div class="metric-block"> <div class="metric-block">
<span class="metric-label">截止读数</span> <span class="metric-label">截止读数</span>
<span class="metric-value is-highlight">{{ record.reading }}{{ record.unit }}</span> <span class="metric-value is-highlight">{{ record.reading }}</span>
</div> </div>
<div class="metric-block"> <div class="metric-block">
<span class="metric-label">区间用量</span> <span class="metric-label">区间用量</span>
<span class="metric-value">{{ record.usage }}{{ record.unit }}</span> <span class="metric-value">{{ record.usage }}</span>
</div> </div>
</div> </div>
<!-- <div class="card-time">抄表时间:{{ record.readingTime }}</div> -->
</div> </div>
</div> </div>
<el-empty v-else :description="readingDateRange?.length ? '该时间段内暂无抄表记录' : '暂无抄表记录'" /> <el-empty v-else-if="!loading" :description="readingDateRange?.length ? '该时间段内暂无抄表记录' : '暂无抄表记录'" />
</div> </div>
</template> </template>
<script setup name="ReadingTab" lang="ts"> <script setup name="ReadingTab" lang="ts">
import { listAppUserReadings } from '@/api/appUser';
import type { AppUserReadingQuery, AppUserReadingVO } 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 ReadingRecordItem { interface ReadingRecordItem {
id: string | number; id: string | number;
roomNo: string; roomNo: string;
deviceText: string; deviceText: string;
previousReading: number; previousReading: string;
reading: number; reading: string;
usage: number; usage: string;
unit: string;
readingTime: string;
} }
/** TODO: 抄表记录接口待接入,先用演示数据占位 */ const { loading, withLoading } = useLoading(false);
const readingRecords = ref<ReadingRecordItem[]>([ const records = ref<AppUserReadingVO[]>([]);
{ /** 抄表时间筛选区间(YYYY-MM-DD),为空表示不筛选 */
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); const readingDateRange = ref<[string, string] | null>(null);
/** 抄表记录按所选时间区间过滤,接口接入后改为传 startTime / endTime 到后端 */ /** 后端记录 → 列表展示项:只展示上次读数 / 本次读数 / 本次用量 */
const filteredReadingRecords = computed(() => { const readingRecords = computed<ReadingRecordItem[]>(() =>
const [start, end] = readingDateRange.value || []; records.value.map(record => {
if (!start || !end) return readingRecords.value; const unit = quantityUnit(record);
return readingRecords.value.filter(record => { return {
const day = String(record.readingTime || '').slice(0, 10); id: record.id,
return !!day && day >= start && day <= end; roomNo: String(valueOrDash(record.roomNo)),
}); deviceText: deviceLabel(record),
previousReading: formatReading(record.previousReadingValue, unit),
reading: formatReading(record.readingValue, unit),
usage: formatReading(record.usageQuantity, unit)
};
})
);
/** 查询抄表记录:GET /userManage/appUser/readings/{userId} */
const getList = async () => {
const currentUserId = props.userId;
if (currentUserId === undefined || currentUserId === null || currentUserId === '') {
records.value = [];
return;
}
const params: AppUserReadingQuery = {};
const [beginTime, endTime] = readingDateRange.value || [];
if (beginTime) params.beginTime = beginTime;
if (endTime) params.endTime = endTime;
try {
await withLoading(async () => {
const res = await listAppUserReadings(currentUserId, params);
records.value = normalizeRecordList<AppUserReadingVO>(res.data, record => record.id != null);
});
} catch {
// 请求异常已由 request 统一提示,这里保持上次渲染结果
}
};
/** 时间区间变化后重新查询 */
watch(readingDateRange, () => {
getList();
});
onMounted(() => {
getList();
}); });
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@use '@/assets/styles/components/detail-panels' as panels; @use '@/assets/styles/components/detail-panels' as panels;
.reading-panel {
min-height: 120px;
}
@include panels.record-card-list; @include panels.record-card-list;
.reading-toolbar { .reading-toolbar {

View File

@@ -1,54 +1,92 @@
<template> <template>
<div v-if="resetRecords.length" class="card-list"> <div v-loading="loading" class="reset-panel">
<div v-for="record in resetRecords" :key="record.id" class="record-card"> <div v-if="resetRecords.length" class="card-list">
<div class="card-head"> <div v-for="record in resetRecords" :key="record.id" class="record-card">
<div class="card-room">{{ record.roomNo }}</div> <div class="card-head">
<div class="card-meta">{{ record.deviceText }}</div> <div class="card-room">{{ record.roomNo }}</div>
</div> <div class="card-meta">{{ record.deviceText }}</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>
<div class="metric-block"> <div class="card-metrics">
<span class="metric-label">清零后读数</span> <div class="metric-block">
<span class="metric-value is-highlight">{{ record.afterReading }}{{ record.unit }}</span> <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>
<div class="card-time">清零时间:{{ record.resetTime || '-'}}</div>
</div> </div>
<div class="card-time">清零时间:{{ record.resetTime }}</div>
</div> </div>
<el-empty v-else-if="!loading" description="暂无清零记录" />
</div> </div>
<el-empty v-else description="暂无清零记录" />
</template> </template>
<script setup name="ResetTab" lang="ts"> <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 { interface ResetRecordItem {
id: string | number; id: string | number;
roomNo: string; roomNo: string;
deviceText: string; deviceText: string;
beforeReading: number; beforeReading: string;
afterReading: number; afterReading: string;
unit: string;
resetTime: string; resetTime: string;
} }
/** TODO: 清零记录接口待接入,先用演示数据占位 */ const { loading, withLoading } = useLoading(false);
const resetRecords = ref<ResetRecordItem[]>([ const records = ref<AppUserResetVO[]>([]);
{
id: 1, /** 后端记录 → 列表展示项:只展示清零前后读数 / 清零时间 */
roomNo: '101室', const resetRecords = computed<ResetRecordItem[]>(() =>
deviceText: '蓝牙电表 · NO20260101', records.value.map(record => {
beforeReading: 1234, const unit = quantityUnit(record);
afterReading: 0, return {
unit: '度', id: record.id,
resetTime: '2026年9月21日 11:20:45' 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> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@use '@/assets/styles/components/detail-panels' as panels; @use '@/assets/styles/components/detail-panels' as panels;
.reset-panel {
min-height: 120px;
}
@include panels.record-card-list; @include panels.record-card-list;
</style> </style>

View File

@@ -1,5 +1,22 @@
import type { AppUserBindingVO } from '@/api/appUser/types'; import type { AppUserBindingVO } from '@/api/appUser/types';
/**
* 兼容后端返回:数组 / 分页对象 / 单个对象,统一取出记录列表
* @param data 后端返回的数据
* @param isSingle 判断分页对象本身是否为一条记录
*/
export const normalizeRecordList = <T>(data: unknown, isSingle: (record: Record<string, any>) => boolean = () => false): T[] => {
if (Array.isArray(data)) return data as T[];
if (data && typeof data === 'object') {
const record = data as Record<string, any>;
if (Array.isArray(record.rows)) return record.rows as T[];
if (Array.isArray(record.list)) return record.list as T[];
if (Array.isArray(record.records)) return record.records as T[];
if (isSingle(record)) return [record as T];
}
return [];
};
/** 空值统一显示占位符 */ /** 空值统一显示占位符 */
export const valueOrDash = (value?: string | number | null) => (value === undefined || value === null || value === '' ? '—' : value); export const valueOrDash = (value?: string | number | null) => (value === undefined || value === null || value === '' ? '—' : value);
@@ -10,6 +27,16 @@ export const formatDate = (value?: string) => {
return matched ? `${matched[1]}年${Number(matched[2])}月${Number(matched[3])}日` : String(value); return matched ? `${matched[1]}年${Number(matched[2])}月${Number(matched[3])}日` : String(value);
}; };
/** 设备展示:名称 + 编号,缺名称时按设备类型兜底 */
export const deviceLabel = (device: AppUserBindingVO) => {
const name = device.deviceName || (String(device.deviceType) === '1' ? '水表' : '电表');
return device.deviceNo ? `${name} · ${device.deviceNo}` : name;
};
/** 数值 + 单位展示,缺值时显示占位符 */
export const formatReading = (value: number | undefined | null, unit: string) =>
value === undefined || value === null ? '—' : `${value}${unit}`;
/** 计量单位:电表按度、水表按吨,优先后端 unitName */ /** 计量单位:电表按度、水表按吨,优先后端 unitName */
export const quantityUnit = (device: AppUserBindingVO) => { export const quantityUnit = (device: AppUserBindingVO) => {
if (String(device.unitName) === '0') return '度'; if (String(device.unitName) === '0') return '度';

View File

@@ -37,10 +37,10 @@
<div class="tab-content"> <div class="tab-content">
<DeviceTab v-if="activeTab === 'device'" :devices="devices" @unbind="handleUnbindDevice" /> <DeviceTab v-if="activeTab === 'device'" :devices="devices" @unbind="handleUnbindDevice" />
<PaymentTab v-else-if="activeTab === 'payment'" /> <PaymentTab v-else-if="activeTab === 'payment'" :user-id="userId" />
<ReadingTab v-else-if="activeTab === 'reading'" /> <ReadingTab v-else-if="activeTab === 'reading'" :user-id="userId" />
<ResetTab v-else-if="activeTab === 'reset'" /> <ResetTab v-else-if="activeTab === 'reset'" :user-id="userId" />
<HistoryTab v-else-if="activeTab === 'history'" /> <HistoryTab v-else-if="activeTab === 'history'" :user-id="userId" />
<el-empty v-else :description="`暂无${currentTabLabel}`" /> <el-empty v-else :description="`暂无${currentTabLabel}`" />
</div> </div>
</el-card> </el-card>
@@ -59,7 +59,7 @@
<script setup name="AppUserDetail" lang="ts"> <script setup name="AppUserDetail" lang="ts">
import { useRoute, useRouter } from 'vue-router'; import { useRoute, useRouter } from 'vue-router';
import { getAppUserBindings, getAppUserDetail } from '@/api/appUser'; import { getAppUserBindings, getAppUserDetail, unbindAppUserDevice } from '@/api/appUser';
import { AppUserBindingVO, AppUserVO } from '@/api/appUser/types'; import { AppUserBindingVO, AppUserVO } from '@/api/appUser/types';
import { useLoading } from '@/hooks/async/useLoading'; import { useLoading } from '@/hooks/async/useLoading';
import modal from '@/plugins/modal'; import modal from '@/plugins/modal';
@@ -69,11 +69,14 @@ import HistoryTab from './components/detail/HistoryTab.vue';
import PaymentTab from './components/detail/PaymentTab.vue'; import PaymentTab from './components/detail/PaymentTab.vue';
import ReadingTab from './components/detail/ReadingTab.vue'; import ReadingTab from './components/detail/ReadingTab.vue';
import ResetTab from './components/detail/ResetTab.vue'; import ResetTab from './components/detail/ResetTab.vue';
import { normalizeRecordList } from './components/detail/helpers';
import UserSummaryCard from './components/detail/UserSummaryCard.vue'; import UserSummaryCard from './components/detail/UserSummaryCard.vue';
const route = useRoute(); const route = useRoute();
const router = useRouter(); const router = useRouter();
const { loading, withLoading } = useLoading(true); const { loading, withLoading } = useLoading(true);
/** 当前用户ID(由用户列表跳转携带) */
const userId = computed(() => route.query.userId as string | undefined);
const user = ref<Partial<AppUserVO>>({}); const user = ref<Partial<AppUserVO>>({});
/** 已绑定设备:GET /userManage/appUser/bindings/{userId} */ /** 已绑定设备:GET /userManage/appUser/bindings/{userId} */
const devices = ref<AppUserBindingVO[]>([]); const devices = ref<AppUserBindingVO[]>([]);
@@ -102,43 +105,45 @@ const goBack = () => {
/** 打开绑定设备弹窗 */ /** 打开绑定设备弹窗 */
const handleBindDevice = () => { const handleBindDevice = () => {
const userId = route.query.userId as string | undefined; if (!userId.value) {
if (!userId) {
modal.msgError('缺少用户ID,请从用户列表进入'); modal.msgError('缺少用户ID,请从用户列表进入');
return; return;
} }
bindDeviceRef.value?.openDialog(userId); bindDeviceRef.value?.openDialog(userId.value);
}; };
/** TODO: 解绑设备接口待后端提供,先占位提示 */ /** 解绑设备:DELETE /userManage/appUser/bindingsHistory/{userId}/{deviceId} */
const handleUnbindDevice = (device: AppUserBindingVO) => { const handleUnbindDevice = async (device: AppUserBindingVO) => {
modal.msgWarning(`解绑设备「${device.deviceNo || device.deviceId}」的接口待接入`); if (!userId.value) {
modal.msgError('缺少用户ID,请从用户列表进入');
return;
}
try {
await modal.confirm(`是否确认解绑设备"${device.deviceNo || device.deviceId}"?解绑后可在历史设备中查看`);
} catch {
// 用户取消确认
return;
}
await unbindAppUserDevice(userId.value, device.deviceId);
modal.msgSuccess('解绑成功');
await getDetail();
}; };
/** 绑定列表兼容后端返回:数组 / 分页对象 / 单个对象 */ /** 绑定列表兼容后端返回:数组 / 分页对象 / 单个对象 */
const normalizeDevices = (data: unknown): AppUserBindingVO[] => { const normalizeDevices = (data: unknown): AppUserBindingVO[] =>
if (Array.isArray(data)) return data as AppUserBindingVO[]; normalizeRecordList<AppUserBindingVO>(data, record => record.deviceId != null);
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;
if (record.deviceId != null) return [record as AppUserBindingVO];
}
return [];
};
/** 查询用户详情 */ /** 查询用户详情 */
const getDetail = async () => { const getDetail = async () => {
const userId = route.query.userId as string | undefined; const currentUserId = userId.value;
if (!userId) { if (!currentUserId) {
modal.msgError('缺少用户ID,请从用户列表进入'); modal.msgError('缺少用户ID,请从用户列表进入');
loading.value = false; loading.value = false;
return; return;
} }
await withLoading(async () => { await withLoading(async () => {
// 头部概要信息 + 已绑定设备:GET /userManage/appUser/detail/{userId}、/bindings/{userId} // 头部概要信息 + 已绑定设备:GET /userManage/appUser/detail/{userId}、/bindings/{userId}
const [detailRes, bindingRes] = await Promise.allSettled([getAppUserDetail(userId), getAppUserBindings(userId)]); const [detailRes, bindingRes] = await Promise.allSettled([getAppUserDetail(currentUserId), getAppUserBindings(currentUserId)]);
if (detailRes.status === 'fulfilled') { if (detailRes.status === 'fulfilled') {
user.value = detailRes.value.data || {}; user.value = detailRes.value.data || {};
} }

View File

@@ -91,8 +91,8 @@
</template> </template>
<script setup name="AppUser" lang="ts"> <script setup name="AppUser" lang="ts">
import { delAppUser, listAppUser, updateAppUser } from '@/api/appUser'; import { changeAppUserStatus, delAppUser, listAppUser } from '@/api/appUser';
import { AppUserForm, AppUserQuery, AppUserVO } from '@/api/appUser/types'; import { AppUserQuery, AppUserVO } from '@/api/appUser/types';
import { useLoading } from '@/hooks/async/useLoading'; import { useLoading } from '@/hooks/async/useLoading';
import { useSearchReset } from '@/hooks/form/useSearchReset'; import { useSearchReset } from '@/hooks/form/useSearchReset';
import { useSearchToggle } from '@/hooks/form/useSearchToggle'; import { useSearchToggle } from '@/hooks/form/useSearchToggle';
@@ -122,7 +122,7 @@ const queryParams = ref<AppUserQuery>({
status: undefined status: undefined
}); });
const { ids, multiple, handleSelectionChange } = useTableSelection<AppUserVO>(item => item.userId); const { ids, multiple, handleSelectionChange, clearSelection } = useTableSelection<AppUserVO>(item => item.userId);
/** 查询小程序用户列表 */ /** 查询小程序用户列表 */
const getList = async () => { const getList = async () => {
@@ -155,22 +155,35 @@ const handleView = (row: Partial<AppUserVO>) => {
router.push({ path: '/appUser/detail', query: { userId: String(row.userId) } }); router.push({ path: '/appUser/detail', query: { userId: String(row.userId) } });
}; };
/** 启用 / 停用:正常(0) → 停用(1),停用(1) → 正常(0) */ /** 启用 / 停用:PUT /userManage/appUser/status/{userId}/{status},正常(0) → 停用(1),停用(1) → 正常(0) */
const handleToggleStatus = async (row: Partial<AppUserVO>) => { const handleToggleStatus = async (row: Partial<AppUserVO>) => {
if (row.userId == null) return;
const nextStatus = row.status === '0' ? '1' : '0'; const nextStatus = row.status === '0' ? '1' : '0';
const actionText = nextStatus === '0' ? '启用' : '停用'; const actionText = nextStatus === '0' ? '启用' : '停用';
await modal.confirm(`是否确认${actionText}用户"${row.nickName || row.phoneNumber || row.userId}"?`); try {
await updateAppUser({ userId: row.userId, status: nextStatus } as AppUserForm); await modal.confirm(`是否确认${actionText}用户"${row.nickName || row.phoneNumber || row.userId}"?`);
} catch {
// 用户取消确认
return;
}
await changeAppUserStatus(row.userId, nextStatus);
modal.msgSuccess(`${actionText}成功`); modal.msgSuccess(`${actionText}成功`);
await getList(); await getList();
}; };
/** 删除按钮操作 */ /** 删除按钮操作:DELETE /userManage/appUser/{userIds},批量时多个 ID 以逗号拼接 */
const handleDelete = async (row?: Partial<AppUserVO>) => { const handleDelete = async (row?: Partial<AppUserVO>) => {
const _userIds = row?.userId || ids.value; const userIds = row?.userId ?? ids.value;
await modal.confirm('是否确认删除小程序用户编号为"' + _userIds + '"的数据项?'); try {
await delAppUser(_userIds); await modal.confirm('是否确认删除小程序用户编号为"' + userIds + '"的数据项?');
} catch {
// 用户取消确认
return;
}
await delAppUser(userIds);
modal.msgSuccess('删除成功'); modal.msgSuccess('删除成功');
// 清掉勾选,避免列表刷新后批量删除按钮仍拿着已删除的 ID
clearSelection();
await getList(); await getList();
}; };