start
This commit is contained in:
@@ -0,0 +1,261 @@
|
||||
<template>
|
||||
<PageBreadcrumb title="用户管理" subtitle="业务管理" />
|
||||
|
||||
<div class="container-xxl">
|
||||
<BCard no-body>
|
||||
<BCardHeader class="border-light d-flex flex-wrap justify-content-between align-items-center gap-2">
|
||||
<div class="d-flex flex-wrap align-items-center gap-2">
|
||||
<div class="app-search">
|
||||
<input
|
||||
v-model="filters.keyword"
|
||||
type="search"
|
||||
class="form-control"
|
||||
placeholder="昵称、手机号、邮箱"
|
||||
@keyup.enter="search"
|
||||
/>
|
||||
<Icon icon="search" class="app-search-icon text-muted" />
|
||||
</div>
|
||||
<BFormSelect v-model="filters.accountStatus" class="form-select" style="width: 130px">
|
||||
<option value="">全部状态</option>
|
||||
<option value="normal">正常</option>
|
||||
<option value="lock">已锁定</option>
|
||||
</BFormSelect>
|
||||
<BButton variant="primary" @click="search">
|
||||
<Icon icon="search" class="me-1" />
|
||||
查询
|
||||
</BButton>
|
||||
<BButton variant="light" @click="reset">重置</BButton>
|
||||
</div>
|
||||
|
||||
<div class="text-muted fs-12">
|
||||
共 <span class="fw-semibold">{{ total }}</span> 位用户
|
||||
</div>
|
||||
</BCardHeader>
|
||||
|
||||
<BCardBody class="border-bottom border-light py-3">
|
||||
<BRow class="g-2">
|
||||
<BCol md="3">
|
||||
<label class="form-label fs-12 mb-1">注册开始日期</label>
|
||||
<BFormInput v-model="filters.startDate" type="date" />
|
||||
</BCol>
|
||||
<BCol md="3">
|
||||
<label class="form-label fs-12 mb-1">注册结束日期</label>
|
||||
<BFormInput v-model="filters.endDate" type="date" />
|
||||
</BCol>
|
||||
</BRow>
|
||||
</BCardBody>
|
||||
|
||||
<div v-if="loading" class="text-center py-5">
|
||||
<BSpinner variant="primary" />
|
||||
</div>
|
||||
|
||||
<BTable
|
||||
v-else
|
||||
show-empty
|
||||
empty-text="没有符合条件的用户"
|
||||
:items="users"
|
||||
:fields="fields"
|
||||
thead-class="bg-light align-middle bg-opacity-25 thead-sm"
|
||||
hover
|
||||
responsive
|
||||
class="table table-custom table-nowrap table-centered mb-0 w-100"
|
||||
>
|
||||
<template #head()="data">
|
||||
<span class="text-uppercase fs-xxs">{{ data.label }}</span>
|
||||
</template>
|
||||
|
||||
<template #cell(user)="{ item }">
|
||||
<div class="d-flex align-items-center">
|
||||
<span class="avatar-md d-flex align-items-center justify-content-center rounded-circle bg-primary-subtle text-primary fw-semibold me-2">
|
||||
{{ (item.profile?.name || item.profile?.mobile || '用').slice(0, 1) }}
|
||||
</span>
|
||||
<div>
|
||||
<RouterLink :to="`/users/${item._id}`" class="fw-semibold link-reset">
|
||||
{{ item.profile?.name || '未填写昵称' }}
|
||||
</RouterLink>
|
||||
<p class="text-muted mb-0 fs-12">{{ item.profile?.mobile || '-' }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #cell(email)="{ item }">
|
||||
{{ item.profile?.email || '-' }}
|
||||
</template>
|
||||
|
||||
<template #cell(apps)="{ item }">
|
||||
<template v-if="item.apps?.length">
|
||||
<span
|
||||
v-for="app in item.apps"
|
||||
:key="app.appId"
|
||||
class="badge badge-soft-secondary me-1"
|
||||
:class="{ 'badge-soft-danger': app.status !== 'active' }"
|
||||
>
|
||||
{{ appLabel(app.appId) }}
|
||||
<span v-if="app.roles?.length"> / {{ app.roles.map(roleLabel).join(',') }}</span>
|
||||
</span>
|
||||
</template>
|
||||
<span v-else class="text-muted">-</span>
|
||||
</template>
|
||||
|
||||
<template #cell(account)="{ item }">
|
||||
<span
|
||||
class="badge fs-xxs"
|
||||
:class="item.status?.account === 'lock' ? 'badge-soft-danger' : 'badge-soft-success'"
|
||||
>
|
||||
{{ ACCOUNT_STATUS_LABELS[item.status?.account || 'normal'] || '正常' }}
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<template #cell(createdAt)="{ item }">
|
||||
{{ formatDateTime(item.meta?.createtime) }}
|
||||
</template>
|
||||
|
||||
<template #cell(action)="{ item }">
|
||||
<div class="d-flex justify-content-center gap-1">
|
||||
<RouterLink :to="`/users/${item._id}`" class="btn btn-light btn-icon btn-sm rounded-circle" title="查看详情">
|
||||
<Icon icon="eye" class="fs-lg" />
|
||||
</RouterLink>
|
||||
<BButton
|
||||
v-if="item._id !== auth.user?._id"
|
||||
:variant="item.status?.account === 'lock' ? 'success' : 'danger'"
|
||||
class="btn btn-icon btn-sm rounded-circle"
|
||||
:title="item.status?.account === 'lock' ? '解锁账号' : '锁定账号'"
|
||||
@click="openLock(item)"
|
||||
>
|
||||
<Icon :icon="item.status?.account === 'lock' ? 'lock-open' : 'lock'" class="fs-lg" />
|
||||
</BButton>
|
||||
</div>
|
||||
</template>
|
||||
</BTable>
|
||||
|
||||
<BCardFooter v-if="!loading" class="border-0">
|
||||
<TablePagination v-model:currentPage="page" :per-page="pageSize" :total-items="total" label="位用户" />
|
||||
</BCardFooter>
|
||||
</BCard>
|
||||
|
||||
<ConfirmModal
|
||||
v-model="lockVisible"
|
||||
:title="lockTarget?.status?.account === 'lock' ? '解锁账号' : '锁定账号'"
|
||||
:ok-title="lockTarget?.status?.account === 'lock' ? '确认解锁' : '确认锁定'"
|
||||
:ok-variant="lockTarget?.status?.account === 'lock' ? 'success' : 'danger'"
|
||||
@confirm="confirmLock"
|
||||
>
|
||||
<p class="mb-1">
|
||||
确定{{ lockTarget?.status?.account === 'lock' ? '解锁' : '锁定' }}用户
|
||||
<strong>{{ lockTarget?.profile?.name || lockTarget?.profile?.mobile || lockTarget?._id }}</strong>
|
||||
吗?
|
||||
</p>
|
||||
<p v-if="lockTarget?.status?.account !== 'lock'" class="text-muted mb-0 fs-12">
|
||||
锁定后该账号将无法登录,已登录会话也会失效。
|
||||
</p>
|
||||
</ConfirmModal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref, watch } from 'vue'
|
||||
import { userApi } from '~/api/user'
|
||||
import ConfirmModal from '~/components/ConfirmModal.vue'
|
||||
import PageBreadcrumb from '~/components/PageBreadcrumb.vue'
|
||||
import TablePagination from '~/components/TablePagination.vue'
|
||||
import Icon from '~/components/wrappers/Icon.vue'
|
||||
import { useAuthStore } from '~/stores/auth'
|
||||
import type { UserView } from '~/types/api'
|
||||
import { ACCOUNT_STATUS_LABELS, ROLE_LABELS, formatDateTime } from '~/utils/format'
|
||||
import { notify } from '~/utils/notify'
|
||||
|
||||
const auth = useAuthStore()
|
||||
|
||||
const APP_LABELS: Record<string, string> = {
|
||||
'wxapp-escort': 'C端用户',
|
||||
'wxapp-escort-admin': '陪诊小程序',
|
||||
'web-escort-admin': 'Web后台',
|
||||
}
|
||||
|
||||
const appLabel = (appId: string) => APP_LABELS[appId] || appId
|
||||
const roleLabel = (role: string) => ROLE_LABELS[role] || role
|
||||
|
||||
const filters = reactive({
|
||||
keyword: '',
|
||||
accountStatus: '',
|
||||
startDate: '',
|
||||
endDate: '',
|
||||
})
|
||||
|
||||
const fields = [
|
||||
{ key: 'user', label: '用户' },
|
||||
{ key: 'email', label: '邮箱' },
|
||||
{ key: 'apps', label: '应用与角色' },
|
||||
{ key: 'account', label: '账号状态' },
|
||||
{ key: 'createdAt', label: '注册时间' },
|
||||
{ key: 'action', label: '操作' },
|
||||
]
|
||||
|
||||
const users = ref<UserView[]>([])
|
||||
const total = ref(0)
|
||||
const page = ref(1)
|
||||
const pageSize = ref(20)
|
||||
const loading = ref(false)
|
||||
|
||||
const lockVisible = ref(false)
|
||||
const lockTarget = ref<UserView | null>(null)
|
||||
|
||||
const load = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const data = await userApi.list({
|
||||
page: page.value,
|
||||
pageSize: pageSize.value,
|
||||
keyword: filters.keyword.trim() || undefined,
|
||||
accountStatus: filters.accountStatus || undefined,
|
||||
startDate: filters.startDate || undefined,
|
||||
endDate: filters.endDate || undefined,
|
||||
})
|
||||
users.value = data.users
|
||||
total.value = data.total
|
||||
const maxPage = Math.max(1, Math.ceil(data.total / pageSize.value))
|
||||
if (page.value > maxPage) {
|
||||
page.value = maxPage
|
||||
return
|
||||
}
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const search = () => {
|
||||
if (page.value === 1) load()
|
||||
else page.value = 1
|
||||
}
|
||||
|
||||
const reset = () => {
|
||||
filters.keyword = ''
|
||||
filters.accountStatus = ''
|
||||
filters.startDate = ''
|
||||
filters.endDate = ''
|
||||
search()
|
||||
}
|
||||
|
||||
const openLock = (user: UserView) => {
|
||||
lockTarget.value = user
|
||||
lockVisible.value = true
|
||||
}
|
||||
|
||||
const confirmLock = async () => {
|
||||
const target = lockTarget.value
|
||||
lockVisible.value = false
|
||||
if (!target) return
|
||||
const locked = target.status?.account !== 'lock'
|
||||
try {
|
||||
await userApi.lock(target._id, locked)
|
||||
notify.success(locked ? '账号已锁定' : '账号已解锁')
|
||||
await load()
|
||||
} catch {
|
||||
// 错误提示由请求层统一弹出
|
||||
}
|
||||
}
|
||||
|
||||
watch(page, () => load())
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
Reference in New Issue
Block a user