2024-10-04 17:10:24 +08:00
|
|
|
<script lang="ts" setup>
|
2024-10-09 15:02:47 +08:00
|
|
|
import { onMounted, ref } from 'vue';
|
2024-10-08 10:44:31 +08:00
|
|
|
import {
|
2025-04-07 14:48:04 +08:00
|
|
|
auth,
|
|
|
|
columns,
|
2024-10-08 10:44:31 +08:00
|
|
|
deleteIds,
|
2024-10-09 15:02:47 +08:00
|
|
|
deptList,
|
2024-10-08 10:44:31 +08:00
|
|
|
onAdd,
|
|
|
|
onAssignRolesToUser,
|
|
|
|
onDelete,
|
|
|
|
onDeleteBatch,
|
|
|
|
onForcedOffline,
|
|
|
|
onResetPassword,
|
|
|
|
onSearch,
|
2024-10-09 15:02:47 +08:00
|
|
|
onTreeSelect,
|
2024-10-08 10:44:31 +08:00
|
|
|
onUpdate,
|
|
|
|
onUploadAvatar,
|
2024-10-09 15:02:47 +08:00
|
|
|
switchLoadMap,
|
2024-10-08 10:44:31 +08:00
|
|
|
updateUserStatus,
|
2025-04-07 14:48:04 +08:00
|
|
|
} from '@/views/system/adminUser/utils';
|
|
|
|
import PureTableBar from '@/components/TableBar/src/bar';
|
|
|
|
import AddFill from '@iconify-icons/ri/add-circle-line';
|
|
|
|
import PureTable from '@pureadmin/table';
|
2024-10-03 20:36:26 +08:00
|
|
|
import Delete from '@iconify-icons/ep/delete';
|
|
|
|
import EditPen from '@iconify-icons/ep/edit-pen';
|
|
|
|
import Refresh from '@iconify-icons/ep/refresh';
|
|
|
|
import { selectUserinfo } from '@/components/Table/Userinfo/columns';
|
|
|
|
import { $t } from '@/plugins/i18n';
|
|
|
|
import { useRenderIcon } from '@/components/CommonIcon/src/hooks';
|
|
|
|
import Upload from '@iconify-icons/ri/upload-line';
|
|
|
|
import Role from '@iconify-icons/ri/admin-line';
|
|
|
|
import Password from '@iconify-icons/ri/lock-password-line';
|
|
|
|
import More from '@iconify-icons/ep/more-filled';
|
2024-10-04 17:10:24 +08:00
|
|
|
import { useAdminUserStore } from '@/store/system/adminUser';
|
2024-11-04 17:30:17 +08:00
|
|
|
import { sexConstant, tableSelectButtonClass, UserAvatar, userStatus } from '@/enums/baseConstant';
|
2024-10-09 15:02:47 +08:00
|
|
|
import { deviceDetection } from '@pureadmin/utils';
|
2024-10-05 15:20:48 +08:00
|
|
|
import Tree from '@/views/system/adminUser/tree.vue';
|
|
|
|
import Airplane from '@/assets/svg/airplane.svg';
|
2024-10-06 20:48:49 +08:00
|
|
|
import { useDeptStore } from '@/store/system/dept';
|
2024-10-08 10:44:31 +08:00
|
|
|
import { FormInstance } from 'element-plus';
|
2024-10-09 15:02:47 +08:00
|
|
|
import { usePublicHooks } from '@/views/hooks';
|
2024-11-05 02:07:20 +08:00
|
|
|
import { hasAuth } from '@/router/utils';
|
2024-10-03 20:36:26 +08:00
|
|
|
|
|
|
|
const adminUserStore = useAdminUserStore();
|
2024-10-06 20:48:49 +08:00
|
|
|
const deptStore = useDeptStore();
|
2024-10-09 15:02:47 +08:00
|
|
|
// 用户是否停用样式
|
|
|
|
const { switchStyle } = usePublicHooks();
|
|
|
|
const tableRef = ref();
|
|
|
|
const formRef = ref();
|
2024-10-03 20:36:26 +08:00
|
|
|
|
2024-10-12 16:57:13 +08:00
|
|
|
/** 加载部门列表 */
|
2024-10-08 10:44:31 +08:00
|
|
|
const onSearchDept = async () => {
|
|
|
|
deptStore.loading = true;
|
|
|
|
await deptStore.getAllDeptList();
|
|
|
|
deptStore.loading = false;
|
|
|
|
};
|
|
|
|
|
2024-10-12 16:57:13 +08:00
|
|
|
/** 当前页改变时 */
|
2024-10-04 17:10:24 +08:00
|
|
|
const onCurrentPageChange = async (value: number) => {
|
|
|
|
adminUserStore.pagination.currentPage = value;
|
|
|
|
await onSearch();
|
2024-10-04 16:50:43 +08:00
|
|
|
};
|
2024-10-03 20:36:26 +08:00
|
|
|
|
2024-10-12 16:57:13 +08:00
|
|
|
/** 当分页发生变化 */
|
2024-10-04 17:10:24 +08:00
|
|
|
const onPageSizeChange = async (value: number) => {
|
|
|
|
adminUserStore.pagination.pageSize = value;
|
|
|
|
await onSearch();
|
2024-10-04 16:50:43 +08:00
|
|
|
};
|
2024-10-03 20:36:26 +08:00
|
|
|
|
2024-10-12 16:57:13 +08:00
|
|
|
/** 重置表单 */
|
2024-10-08 10:44:31 +08:00
|
|
|
const resetForm = async (formEl: FormInstance) => {
|
2024-10-03 20:36:26 +08:00
|
|
|
if (!formEl) return;
|
|
|
|
formEl.resetFields();
|
2024-10-09 15:02:47 +08:00
|
|
|
adminUserStore.form.deptIds = undefined;
|
2024-10-03 20:36:26 +08:00
|
|
|
await onSearch();
|
|
|
|
};
|
|
|
|
|
2024-10-12 16:57:13 +08:00
|
|
|
/** 选择多行 */
|
2024-10-08 10:44:31 +08:00
|
|
|
const onSelectionChange = (rows: Array<any>) => {
|
|
|
|
deleteIds.value = rows.map((row: any) => row.id);
|
2024-10-06 20:48:49 +08:00
|
|
|
};
|
|
|
|
|
2024-10-03 20:36:26 +08:00
|
|
|
onMounted(() => {
|
|
|
|
onSearch();
|
2024-10-06 20:48:49 +08:00
|
|
|
onSearchDept();
|
2024-10-03 20:36:26 +08:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2024-10-05 15:20:48 +08:00
|
|
|
<div :class="['flex', 'justify-between', deviceDetection() && 'flex-wrap']">
|
2024-10-06 20:48:49 +08:00
|
|
|
<tree ref="treeRef" :class="['mr-2', deviceDetection() ? 'w-full' : 'min-w-[200px]']" :treeData="deptList" :treeLoading="deptStore.loading" @tree-select="onTreeSelect" />
|
2024-10-05 15:20:48 +08:00
|
|
|
<div :class="[deviceDetection() ? ['w-full', 'mt-2'] : 'w-[calc(100%-200px)]']">
|
2024-11-05 02:07:20 +08:00
|
|
|
<Auth :value="auth.search">
|
|
|
|
<el-form ref="formRef" :inline="true" :model="adminUserStore.form" class="search-form bg-bg_color w-[99/100] pl-8 pt-[12px] overflow-auto">
|
|
|
|
<!-- 查询用户名 -->
|
|
|
|
<el-form-item :label="$t('adminUser_username')" prop="username">
|
|
|
|
<el-input v-model="adminUserStore.form.username" :placeholder="`${$t('input')}${$t('adminUser_username')}`" class="!w-[180px]" clearable />
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
<!-- 查询昵称 -->
|
|
|
|
<el-form-item :label="$t('adminUser_nickname')" prop="nickname">
|
|
|
|
<el-input v-model="adminUserStore.form.nickname" :placeholder="`${$t('input')}${$t('adminUser_nickname')}`" class="!w-[180px]" clearable />
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
<!-- 查询邮箱 -->
|
|
|
|
<el-form-item :label="$t('adminUser_email')" prop="email">
|
|
|
|
<el-input v-model="adminUserStore.form.email" :placeholder="`${$t('input')}${$t('adminUser_email')}`" class="!w-[180px]" clearable />
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
<!-- 查询手机号 -->
|
|
|
|
<el-form-item :label="$t('adminUser_phone')" prop="phone">
|
|
|
|
<el-input v-model="adminUserStore.form.phone" :placeholder="`${$t('input')}${$t('adminUser_phone')}`" class="!w-[180px]" clearable />
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
<!-- 查询性别 -->
|
|
|
|
<el-form-item :label="$t('adminUser_sex')" prop="sex">
|
|
|
|
<el-select v-model="adminUserStore.form.sex" :placeholder="`${$t('input')}${$t('adminUser_sex')}`" class="!w-[180px]" clearable filterable>
|
|
|
|
<el-option v-for="(item, index) in sexConstant" :key="index" :label="item.label" :navigationBar="false" :value="item.value" />
|
|
|
|
</el-select>
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
<!-- 查询简介 -->
|
|
|
|
<el-form-item :label="$t('adminUser_summary')" prop="summary">
|
|
|
|
<el-input v-model="adminUserStore.form.summary" :placeholder="`${$t('input')}${$t('adminUser_summary')}`" class="!w-[180px]" clearable />
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
<!-- 查询状态 -->
|
|
|
|
<el-form-item :label="$t('adminUser_status')" prop="status">
|
|
|
|
<el-select v-model="adminUserStore.form.status" :placeholder="`${$t('input')}${$t('adminUser_status')}`" class="!w-[180px]" clearable filterable>
|
|
|
|
<el-option v-for="(item, index) in userStatus" :key="index" :label="item.label" :navigationBar="false" :value="item.value" />
|
|
|
|
</el-select>
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
<el-form-item>
|
|
|
|
<el-button :icon="useRenderIcon('ri:search-line')" :loading="adminUserStore.loading" type="primary" @click="onSearch"> {{ $t('search') }} </el-button>
|
|
|
|
<el-button :icon="useRenderIcon(Refresh)" @click="resetForm(formRef)"> {{ $t('buttons.reset') }}</el-button>
|
|
|
|
</el-form-item>
|
|
|
|
</el-form>
|
|
|
|
</Auth>
|
2024-10-05 15:20:48 +08:00
|
|
|
|
2024-10-11 10:44:16 +08:00
|
|
|
<PureTableBar :columns="columns" :title="$t('userinfo')" @fullscreen="tableRef.setAdaptive()" @refresh="onSearch">
|
2024-10-05 15:20:48 +08:00
|
|
|
<template #buttons>
|
2024-11-05 02:07:20 +08:00
|
|
|
<el-button v-if="hasAuth(auth.add)" :icon="useRenderIcon(AddFill)" type="primary" @click="onAdd">
|
|
|
|
{{ $t('addNew') }}
|
|
|
|
</el-button>
|
2024-10-08 10:44:31 +08:00
|
|
|
|
|
|
|
<!-- 批量删除按钮 -->
|
2024-11-05 02:07:20 +08:00
|
|
|
<el-button v-if="hasAuth(auth.deleted)" :disabled="!(deleteIds.length > 0)" :icon="useRenderIcon(Delete)" type="danger" @click="onDeleteBatch">
|
2024-11-04 01:41:49 +08:00
|
|
|
{{ $t('deleteBatches') }}
|
2024-10-08 10:44:31 +08:00
|
|
|
</el-button>
|
2024-10-05 15:20:48 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<template v-slot="{ size, dynamicColumns }">
|
|
|
|
<pure-table
|
|
|
|
ref="tableRef"
|
2024-10-06 20:48:49 +08:00
|
|
|
:adaptiveConfig="{ offsetBottom: 96 }"
|
2024-10-05 15:20:48 +08:00
|
|
|
:columns="dynamicColumns"
|
|
|
|
:data="adminUserStore.datalist"
|
|
|
|
:header-cell-style="{ background: 'var(--el-fill-color-light)', color: 'var(--el-text-color-primary)' }"
|
|
|
|
:loading="adminUserStore.loading"
|
|
|
|
:pagination="adminUserStore.pagination"
|
|
|
|
:size="size"
|
|
|
|
adaptive
|
|
|
|
align-whole="center"
|
|
|
|
border
|
|
|
|
highlight-current-row
|
|
|
|
row-key="id"
|
|
|
|
showOverflowTooltip
|
|
|
|
table-layout="auto"
|
|
|
|
@page-size-change="onPageSizeChange"
|
2024-10-08 10:44:31 +08:00
|
|
|
@selection-change="onSelectionChange"
|
2024-10-05 15:20:48 +08:00
|
|
|
@page-current-change="onCurrentPageChange"
|
|
|
|
>
|
|
|
|
<!-- 显示头像 -->
|
|
|
|
<template #avatar="{ row }">
|
2024-11-04 17:30:17 +08:00
|
|
|
<el-image :preview-src-list="Array.of(row.avatar || UserAvatar)" :src="row.avatar || UserAvatar" class="w-[24px] h-[24px] rounded-full align-middle" fit="cover" preview-teleported>
|
2024-10-12 16:57:13 +08:00
|
|
|
<template #error>
|
|
|
|
<div class="image-slot">
|
2024-11-04 17:30:17 +08:00
|
|
|
<img :src="UserAvatar" alt="" />
|
2024-10-12 16:57:13 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</el-image>
|
2024-10-05 15:20:48 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<!-- 显示用户状态 -->
|
2024-10-09 15:02:47 +08:00
|
|
|
<template #status="{ row, index }">
|
2024-10-05 15:20:48 +08:00
|
|
|
<el-switch
|
|
|
|
v-model="row.status"
|
2024-10-11 10:44:16 +08:00
|
|
|
:active-text="$t('enable')"
|
2024-10-09 15:02:47 +08:00
|
|
|
:active-value="false"
|
2024-10-11 10:44:16 +08:00
|
|
|
:inactive-text="$t('disable')"
|
2024-10-09 15:02:47 +08:00
|
|
|
:inactive-value="true"
|
|
|
|
:loading="switchLoadMap[index]?.loading"
|
|
|
|
:style="switchStyle"
|
2024-10-05 15:20:48 +08:00
|
|
|
inline-prompt
|
2024-10-09 15:02:47 +08:00
|
|
|
@click="updateUserStatus(row, index)"
|
2024-10-05 15:20:48 +08:00
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<!-- 用户性别 -->
|
|
|
|
<template #sex="{ row }">
|
2024-10-11 10:44:16 +08:00
|
|
|
<el-tag :type="row.sex === 0 ? 'danger' : null" effect="plain">
|
|
|
|
{{ row.sex === 1 ? $t('man') : $t('female') }}
|
|
|
|
</el-tag>
|
2024-10-05 15:20:48 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<template #createUser="{ row }">
|
2024-10-19 03:20:30 +08:00
|
|
|
<el-button v-show="row.createUser" link type="primary" @click="selectUserinfo(row.createUser)">
|
2024-10-30 23:52:58 +08:00
|
|
|
{{ row.createUsername }}
|
2024-10-19 03:20:30 +08:00
|
|
|
</el-button>
|
2024-10-05 15:20:48 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<template #updateUser="{ row }">
|
2024-10-19 03:20:30 +08:00
|
|
|
<el-button v-show="row.updateUser" link type="primary" @click="selectUserinfo(row.updateUser)">
|
2024-10-30 23:52:58 +08:00
|
|
|
{{ row.updateUsername }}
|
2024-10-19 03:20:30 +08:00
|
|
|
</el-button>
|
2024-10-05 15:20:48 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<template #operation="{ row }">
|
|
|
|
<!-- 修改 -->
|
2024-11-05 02:07:20 +08:00
|
|
|
<el-button v-if="hasAuth(auth.update)" :icon="useRenderIcon(EditPen)" :size="size" class="reset-margin" link type="primary" @click="onUpdate(row)"> {{ $t('modify') }} </el-button>
|
2024-10-05 15:20:48 +08:00
|
|
|
|
|
|
|
<!-- 删除 -->
|
2024-11-05 02:07:20 +08:00
|
|
|
<el-popconfirm v-if="hasAuth(auth.deleted)" :title="`${$t('delete')} ${row.username}?`" @confirm="onDelete(row)">
|
2024-10-05 15:20:48 +08:00
|
|
|
<template #reference>
|
|
|
|
<el-button :icon="useRenderIcon(Delete)" :size="size" class="reset-margin" link type="primary">
|
|
|
|
{{ $t('delete') }}
|
|
|
|
</el-button>
|
|
|
|
</template>
|
|
|
|
</el-popconfirm>
|
|
|
|
|
|
|
|
<!-- 更多操作 -->
|
|
|
|
<el-dropdown>
|
|
|
|
<el-button :icon="useRenderIcon(More)" :size="size" class="ml-3 mt-[2px]" link type="primary" />
|
|
|
|
<template #dropdown>
|
|
|
|
<el-dropdown-menu>
|
2024-11-05 02:07:20 +08:00
|
|
|
<!-- 上传头像 -->
|
|
|
|
<el-dropdown-item v-if="hasAuth(auth.uploadAvatarByAdmin)">
|
2024-10-11 10:44:16 +08:00
|
|
|
<el-button :class="tableSelectButtonClass" :icon="useRenderIcon(Upload)" :size="size" link type="primary" @click="onUploadAvatar(row)"> {{ $t('upload_avatar') }} </el-button>
|
2024-10-05 15:20:48 +08:00
|
|
|
</el-dropdown-item>
|
2024-11-05 02:07:20 +08:00
|
|
|
<!-- 重置密码 -->
|
|
|
|
<el-dropdown-item v-if="hasAuth(auth.updateUserPasswordByAdmin)">
|
2024-10-11 10:44:16 +08:00
|
|
|
<el-button :class="tableSelectButtonClass" :icon="useRenderIcon(Password)" :size="size" link type="primary" @click="onResetPassword(row)"> {{ $t('reset_passwords') }} </el-button>
|
2024-10-05 15:20:48 +08:00
|
|
|
</el-dropdown-item>
|
2024-11-05 02:07:20 +08:00
|
|
|
<!-- 分配角色 -->
|
|
|
|
<el-dropdown-item v-if="hasAuth(auth.updateUserPasswordByAdmin)">
|
2024-10-11 10:44:16 +08:00
|
|
|
<el-button :class="tableSelectButtonClass" :icon="useRenderIcon(Role)" :size="size" link type="primary" @click="onAssignRolesToUser(row)"> {{ $t('assign_roles') }} </el-button>
|
2024-10-05 15:20:48 +08:00
|
|
|
</el-dropdown-item>
|
2024-11-05 02:07:20 +08:00
|
|
|
<!-- 强制下线 -->
|
|
|
|
<el-dropdown-item v-if="hasAuth(auth.forcedOffline)">
|
2024-10-11 10:44:16 +08:00
|
|
|
<el-button :class="tableSelectButtonClass" :icon="useRenderIcon(Airplane)" :size="size" link type="primary" @click="onForcedOffline(row)"> {{ $t('forced_offline') }} </el-button>
|
2024-10-05 15:20:48 +08:00
|
|
|
</el-dropdown-item>
|
|
|
|
</el-dropdown-menu>
|
|
|
|
</template>
|
|
|
|
</el-dropdown>
|
|
|
|
</template>
|
|
|
|
</pure-table>
|
|
|
|
</template>
|
|
|
|
</PureTableBar>
|
|
|
|
</div>
|
2024-10-03 20:36:26 +08:00
|
|
|
</div>
|
|
|
|
</template>
|