211 lines
8.1 KiB
Vue
211 lines
8.1 KiB
Vue
<template>
|
||
<div class="p-2 page-shell userManage-appUser-page">
|
||
<div class="search-wrap">
|
||
<el-card shadow="hover" class="search-panel" :class="{ 'is-collapsed': !showSearch }">
|
||
<template #header>
|
||
<div class="panel-heading search-panel-toggle" @click.stop="showSearch = !showSearch">
|
||
<div><h3>筛选条件</h3></div>
|
||
</div>
|
||
</template>
|
||
<el-form ref="queryFormRef" :model="queryParams" :inline="true" class="query-form">
|
||
<el-form-item label="手机号" prop="phoneNumber">
|
||
<el-input v-model="queryParams.phoneNumber" placeholder="请输入手机号" clearable @keyup.enter="handleQuery" />
|
||
</el-form-item>
|
||
<el-form-item label="姓名" prop="keyword">
|
||
<el-input v-model="queryParams.keyword" placeholder="请输入姓名或昵称" clearable @keyup.enter="handleQuery" />
|
||
</el-form-item>
|
||
<el-form-item label="状态" prop="status">
|
||
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
|
||
<el-option v-for="dict in ur_app_user_status" :key="dict.value" :label="dict.label" :value="dict.value" />
|
||
</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-card>
|
||
</div>
|
||
|
||
<el-card shadow="hover" class="table-panel">
|
||
<template #header>
|
||
<div class="toolbar-shell">
|
||
<div class="table-heading">
|
||
<h3>用户列表</h3>
|
||
</div>
|
||
<div class="toolbar-actions">
|
||
<el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['userManage:appUser:remove']">删除</el-button>
|
||
<right-toolbar v-model:show-search="showSearch" :search="false" @query-table="getList"></right-toolbar>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<el-table v-loading="loading" border class="data-table" :data="appUserList" @selection-change="handleSelectionChange">
|
||
<el-table-column type="selection" width="55" align="center" />
|
||
<el-table-column label="用户ID" align="center" prop="userId" />
|
||
<el-table-column label="用户姓名" align="center" show-overflow-tooltip>
|
||
<template #default="scope">{{ scope.row.nickName}}</template>
|
||
</el-table-column>
|
||
<el-table-column label="手机号" align="center" prop="phoneNumber" />
|
||
<el-table-column label="房间号" align="center" show-overflow-tooltip>
|
||
<template #default="scope">{{ scope.row.roomNo}}</template>
|
||
</el-table-column>
|
||
<el-table-column label="最近缴费" align="center" >
|
||
<template #default="scope">{{ scope.row.recentRechargeAmount }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="绑定设备数" align="center" >
|
||
<!-- 后端暂未返回绑定设备数,先占位 -->
|
||
<template #default="scope">{{ scope.row.bindingDeviceCount }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="状态" align="center" prop="status" width="100">
|
||
<template #default="scope">
|
||
<dict-tag :options="ur_app_user_status" :value="scope.row.status" />
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="190">
|
||
<template #default="scope">
|
||
<div class="table-actions">
|
||
<el-button link type="primary" @click="handleView(scope.row)">详情</el-button>
|
||
<!-- 正常显示停用,停用显示启用 -->
|
||
<el-button
|
||
v-if="scope.row.status === '0'"
|
||
link
|
||
type="warning"
|
||
@click="handleToggleStatus(scope.row)"
|
||
v-hasPermi="['userManage:appUser:edit']"
|
||
>
|
||
停用
|
||
</el-button>
|
||
<el-button v-else link type="success" @click="handleToggleStatus(scope.row)" v-hasPermi="['userManage:appUser:edit']">
|
||
启用
|
||
</el-button>
|
||
<el-button link type="danger" @click="handleDelete(scope.row)" v-hasPermi="['userManage:appUser:remove']">删除</el-button>
|
||
</div>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
|
||
<pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
|
||
</el-card>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup name="AppUser" lang="ts">
|
||
import { delAppUser, listAppUser, updateAppUser } from '@/api/appUser';
|
||
import { AppUserForm, AppUserQuery, AppUserVO } from '@/api/appUser/types';
|
||
import { useLoading } from '@/hooks/async/useLoading';
|
||
import { useSearchReset } from '@/hooks/form/useSearchReset';
|
||
import { useSearchToggle } from '@/hooks/form/useSearchToggle';
|
||
import { useTableSelection } from '@/hooks/table/useTableSelection';
|
||
import modal from '@/plugins/modal';
|
||
import { useDict } from '@/utils/dict';
|
||
import { useRouter } from 'vue-router';
|
||
|
||
/** 用户状态字典(后端 ur_app_user_status 维护) */
|
||
const { ur_app_user_status } = toRefs<any>(useDict('ur_app_user_status'));
|
||
|
||
const router = useRouter();
|
||
|
||
const appUserList = ref<AppUserVO[]>([]);
|
||
const { loading, withLoading } = useLoading(true);
|
||
const { showSearch } = useSearchToggle();
|
||
const total = ref(0);
|
||
|
||
const queryFormRef = ref<ElFormInstance>();
|
||
|
||
const queryParams = ref<AppUserQuery>({
|
||
pageNum: 1,
|
||
pageSize: 10,
|
||
phoneNumber: undefined,
|
||
// 后端 keyword 同时匹配手机号、昵称、实名姓名
|
||
keyword: undefined,
|
||
status: undefined
|
||
});
|
||
|
||
const { ids, multiple, handleSelectionChange } = useTableSelection<AppUserVO>(item => item.userId);
|
||
|
||
/** 查询小程序用户列表 */
|
||
const getList = async () => {
|
||
await withLoading(async () => {
|
||
const res = await listAppUser(queryParams.value);
|
||
appUserList.value = res.data?.rows;
|
||
total.value = res.data?.total;
|
||
});
|
||
};
|
||
|
||
/** 搜索按钮操作 */
|
||
const handleQuery = () => {
|
||
queryParams.value.pageNum = 1;
|
||
getList();
|
||
};
|
||
|
||
const { resetQuery } = useSearchReset({
|
||
queryFormRef,
|
||
queryParams,
|
||
pageNumKey: 'pageNum',
|
||
pageSizeKey: 'pageSize',
|
||
initialPageSize: 10,
|
||
afterReset: () => {
|
||
handleQuery();
|
||
}
|
||
});
|
||
|
||
/** 详情按钮操作:跳转到用户详情页 */
|
||
const handleView = (row: Partial<AppUserVO>) => {
|
||
router.push({ path: '/appUser/detail', query: { userId: String(row.userId) } });
|
||
};
|
||
|
||
/** 启用 / 停用:正常(0) → 停用(1),停用(1) → 正常(0) */
|
||
const handleToggleStatus = async (row: Partial<AppUserVO>) => {
|
||
const nextStatus = row.status === '0' ? '1' : '0';
|
||
const actionText = nextStatus === '0' ? '启用' : '停用';
|
||
await modal.confirm(`是否确认${actionText}用户"${row.nickName || row.phoneNumber || row.userId}"?`);
|
||
await updateAppUser({ userId: row.userId, status: nextStatus } as AppUserForm);
|
||
modal.msgSuccess(`${actionText}成功`);
|
||
await getList();
|
||
};
|
||
|
||
/** 删除按钮操作 */
|
||
const handleDelete = async (row?: Partial<AppUserVO>) => {
|
||
const _userIds = row?.userId || ids.value;
|
||
await modal.confirm('是否确认删除小程序用户编号为"' + _userIds + '"的数据项?');
|
||
await delAppUser(_userIds);
|
||
modal.msgSuccess('删除成功');
|
||
await getList();
|
||
};
|
||
|
||
onMounted(() => {
|
||
getList();
|
||
});
|
||
</script>
|
||
|
||
|
||
<style lang="scss" scoped>
|
||
/*
|
||
* 全局 _search-panel.scss 给 .data-table 里的 link 按钮加了 28x28 的圆角底色(带 !important),
|
||
* 操作列是纯文字按钮,这里用同等优先级覆盖掉底色与固定尺寸
|
||
*/
|
||
.table-actions {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
align-items: center;
|
||
justify-content: center;
|
||
gap: 4px 10px;
|
||
|
||
:deep(.el-button.is-link) {
|
||
width: auto !important;
|
||
min-width: auto !important;
|
||
height: auto !important;
|
||
padding: 0 !important;
|
||
border-radius: 0 !important;
|
||
background: transparent !important;
|
||
font-size: 13px;
|
||
font-weight: 500;
|
||
}
|
||
|
||
:deep(.el-button.is-link + .el-button.is-link) {
|
||
margin-left: 0 !important;
|
||
}
|
||
}
|
||
</style>
|