2024-10-23 20:53:58 +08:00
|
|
|
|
<template>
|
2024-11-07 19:25:45 +08:00
|
|
|
|
<div class='table-box' ref='popupBaseView'>
|
2024-10-23 20:53:58 +08:00
|
|
|
|
<ProTable
|
|
|
|
|
|
ref='proTable'
|
|
|
|
|
|
:columns='columns'
|
2024-11-01 13:49:32 +08:00
|
|
|
|
:request-api="getTableList"
|
2024-10-23 20:53:58 +08:00
|
|
|
|
>
|
2024-11-01 13:49:32 +08:00
|
|
|
|
<!-- :data='userData' -->
|
2024-10-23 20:53:58 +08:00
|
|
|
|
<!-- 表格 header 按钮 -->
|
|
|
|
|
|
<template #tableHeader='scope'>
|
2024-11-20 15:13:50 +08:00
|
|
|
|
<el-button type='primary' :icon='CirclePlus' @click="openDialog('add')">新增</el-button>
|
|
|
|
|
|
<el-button type='danger' :icon='Delete' plain :disabled='!scope.isSelected'
|
2024-10-23 20:53:58 +08:00
|
|
|
|
@click='batchDelete(scope.selectedListIds)'>
|
2024-10-24 13:24:54 +08:00
|
|
|
|
批量删除
|
2024-10-23 20:53:58 +08:00
|
|
|
|
</el-button>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<!-- 表格操作 -->
|
|
|
|
|
|
<template #operation='scope'>
|
2024-11-07 19:25:45 +08:00
|
|
|
|
<el-button type='primary' link :icon='EditPen' @click="openDialog('edit', scope.row)">编辑</el-button>
|
|
|
|
|
|
<el-button type='primary' link :icon='Delete' @click='handleDelete(scope.row)'>删除</el-button>
|
2024-11-12 18:56:33 +08:00
|
|
|
|
<el-button type='primary' link :icon='Delete' @click='EditPassWord(scope.row)'>修改密码</el-button>
|
2024-10-23 20:53:58 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
</ProTable>
|
|
|
|
|
|
</div>
|
2024-11-07 19:25:45 +08:00
|
|
|
|
<UserPopup :refresh-table='proTable?.getTableList' ref='userPopup' />
|
2024-11-12 18:56:33 +08:00
|
|
|
|
|
|
|
|
|
|
<PassWordPopup :refresh-table='proTable?.getTableList' ref='passWordPopup' />
|
|
|
|
|
|
|
2024-10-23 20:53:58 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup lang='tsx' name='useRole'>
|
2024-11-07 19:25:45 +08:00
|
|
|
|
import TimeControl from '@/components/TimeControl/index.vue'
|
2024-11-18 09:02:57 +08:00
|
|
|
|
import { type User } from '@/api/user/interface/user'
|
2024-10-23 20:53:58 +08:00
|
|
|
|
import { useHandleData } from '@/hooks/useHandleData'
|
|
|
|
|
|
import ProTable from '@/components/ProTable/index.vue'
|
2024-11-07 19:25:45 +08:00
|
|
|
|
import UserPopup from './components/userPopup.vue'
|
2024-11-12 18:56:33 +08:00
|
|
|
|
import PassWordPopup from './components/passWordPopup.vue'
|
2024-11-07 19:25:45 +08:00
|
|
|
|
import ImportExcel from '@/components/ImportExcel/index.vue'
|
|
|
|
|
|
import { type ProTableInstance, type ColumnProps } from '@/components/ProTable/interface'
|
|
|
|
|
|
import { CirclePlus, Delete, EditPen} from '@element-plus/icons-vue'
|
2024-10-23 20:53:58 +08:00
|
|
|
|
import { useDictStore } from '@/stores/modules/dict'
|
2024-11-12 18:56:33 +08:00
|
|
|
|
import {getUserList, deleteUser,getRoleList} from '@/api/user/user'
|
|
|
|
|
|
import { onMounted, reactive, ref } from 'vue'
|
2024-11-18 09:02:57 +08:00
|
|
|
|
import { type Role } from '@/api/user/interface/role'
|
2024-11-12 18:56:33 +08:00
|
|
|
|
const roleList = ref<Role.RoleBO[]>([])
|
2024-10-23 20:53:58 +08:00
|
|
|
|
const dictStore = useDictStore()
|
2024-11-07 19:25:45 +08:00
|
|
|
|
const userPopup = ref()
|
2024-11-12 18:56:33 +08:00
|
|
|
|
const passWordPopup = ref()
|
2024-10-23 20:53:58 +08:00
|
|
|
|
// ProTable 实例
|
|
|
|
|
|
const proTable = ref<ProTableInstance>()
|
|
|
|
|
|
|
2024-11-12 18:56:33 +08:00
|
|
|
|
|
|
|
|
|
|
// 初始化时获取角色列表
|
|
|
|
|
|
onMounted(async () => {
|
|
|
|
|
|
const response = await getRoleList()
|
|
|
|
|
|
roleList.value = response.data as unknown as Role.RoleBO[]
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2024-10-23 20:53:58 +08:00
|
|
|
|
// 如果你想在请求之前对当前请求参数做一些操作,可以自定义如下函数:params 为当前所有的请求参数(包括分页),最后返回请求列表接口
|
|
|
|
|
|
// 默认不做操作就直接在 ProTable 组件上绑定 :requestApi="getUserList"
|
|
|
|
|
|
const getTableList = (params: any) => {
|
2024-11-07 19:25:45 +08:00
|
|
|
|
let newParams = JSON.parse(JSON.stringify(params))
|
|
|
|
|
|
newParams.searchEndTime = endDate.value
|
|
|
|
|
|
newParams.searchBeginTime = startDate.value
|
|
|
|
|
|
return getUserList(newParams)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-23 20:53:58 +08:00
|
|
|
|
// 表格配置项
|
2024-11-07 19:25:45 +08:00
|
|
|
|
const columns = reactive<ColumnProps<User.ResUser>[]>([
|
2024-10-23 20:53:58 +08:00
|
|
|
|
{ type: 'selection', fixed: 'left', width: 70 },
|
|
|
|
|
|
{ type: 'index', fixed: 'left', width: 70, label: '序号' },
|
|
|
|
|
|
{
|
2024-11-01 13:49:32 +08:00
|
|
|
|
prop: 'name',
|
2024-10-23 20:53:58 +08:00
|
|
|
|
label: '用户名',
|
|
|
|
|
|
search: { el: 'input' },
|
|
|
|
|
|
minWidth: 150,
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
2024-11-01 13:49:32 +08:00
|
|
|
|
prop: 'loginName',
|
|
|
|
|
|
label: '登录名',
|
2024-11-12 18:56:33 +08:00
|
|
|
|
minWidth: 150,
|
2024-11-01 13:49:32 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
2024-11-12 18:56:33 +08:00
|
|
|
|
prop: 'roleNames',
|
|
|
|
|
|
label: '角色',
|
|
|
|
|
|
minWidth: 250,
|
|
|
|
|
|
render: (scope) => {
|
|
|
|
|
|
const roleNames = scope.row.roleNames;
|
|
|
|
|
|
const roleArray = Array.isArray(roleNames) ? roleNames : [roleNames];
|
|
|
|
|
|
if (roleArray.length > 1) {
|
|
|
|
|
|
return roleArray.join(', ');
|
|
|
|
|
|
}
|
|
|
|
|
|
return roleArray[0] || ''; // 添加默认值
|
2024-10-23 20:53:58 +08:00
|
|
|
|
},
|
2024-11-12 18:56:33 +08:00
|
|
|
|
},
|
2024-10-23 20:53:58 +08:00
|
|
|
|
{
|
2024-11-01 13:49:32 +08:00
|
|
|
|
prop: 'phone',
|
|
|
|
|
|
label: '手机号',
|
2024-11-12 18:56:33 +08:00
|
|
|
|
minWidth: 150,
|
2024-10-23 20:53:58 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
2024-11-01 13:49:32 +08:00
|
|
|
|
prop: 'email',
|
|
|
|
|
|
label: '邮箱',
|
2024-11-12 18:56:33 +08:00
|
|
|
|
minWidth: 150,
|
2024-11-01 13:49:32 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
prop: 'loginTime',
|
|
|
|
|
|
label: '最后一次登录时间',
|
|
|
|
|
|
minWidth: 180,
|
2024-11-07 19:25:45 +08:00
|
|
|
|
search: {
|
|
|
|
|
|
render: () => {
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div class='flx-flex-start'>
|
|
|
|
|
|
<TimeControl
|
|
|
|
|
|
include={['日', '周', '月', '自定义']}
|
|
|
|
|
|
default={'月'}
|
|
|
|
|
|
onUpdate-dates={handleDateChange}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
2024-11-01 13:49:32 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
2024-11-12 18:56:33 +08:00
|
|
|
|
prop: 'state',
|
|
|
|
|
|
label: '状态',
|
|
|
|
|
|
minWidth: 100,
|
|
|
|
|
|
enum: dictStore.getDictData('state'),
|
|
|
|
|
|
fieldNames: { label: 'label', value: 'code' },
|
|
|
|
|
|
render: (scope: { row: { state: any } }) => {
|
|
|
|
|
|
const { tagType, tagText } = getTagTypeAndText(scope.row.state);
|
|
|
|
|
|
return (<el-tag type={tagType}>{tagText}</el-tag>);
|
|
|
|
|
|
}
|
2024-10-23 20:53:58 +08:00
|
|
|
|
},
|
2024-11-14 11:34:25 +08:00
|
|
|
|
{ prop: 'operation', label: '操作', fixed: 'right', width: 250 },
|
2024-10-23 20:53:58 +08:00
|
|
|
|
])
|
|
|
|
|
|
|
2024-11-07 19:25:45 +08:00
|
|
|
|
|
2024-11-12 18:56:33 +08:00
|
|
|
|
// 提取出生成 tag 的逻辑
|
|
|
|
|
|
const getTagTypeAndText = (state: number) => {
|
|
|
|
|
|
let tagType = 'danger'; // 默认标签类型为 'danger'
|
|
|
|
|
|
let tagText = '';
|
|
|
|
|
|
|
|
|
|
|
|
switch(state) {
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
tagType = 'success'; // 正常
|
|
|
|
|
|
tagText = '正常';
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
tagType = 'warning'; // 锁定
|
|
|
|
|
|
tagText = '锁定';
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
tagType = 'info'; // 待审核
|
|
|
|
|
|
tagText = '待审核';
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 4:
|
|
|
|
|
|
tagType = 'default'; // 休眠
|
|
|
|
|
|
tagText = '休眠';
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 5:
|
|
|
|
|
|
tagType = 'warning'; // 密码过期
|
|
|
|
|
|
tagText = '密码过期';
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
default:
|
|
|
|
|
|
tagType = 'danger'; // 删除
|
|
|
|
|
|
tagText = '删除';
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return { tagType, tagText };
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-07 19:25:45 +08:00
|
|
|
|
// 处理日期变化的回调函数
|
|
|
|
|
|
const startDate = ref('')
|
|
|
|
|
|
const endDate = ref('')
|
|
|
|
|
|
const handleDateChange = (startDateTemp: string, endDateTemp: string) => {
|
|
|
|
|
|
startDate.value = startDateTemp
|
|
|
|
|
|
endDate.value = endDateTemp
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 打开 drawer(新增、编辑)
|
|
|
|
|
|
const openDialog = (titleType: string, row: Partial<User.ResUser> = {}) => {
|
2024-11-12 18:56:33 +08:00
|
|
|
|
userPopup.value?.open(titleType, row,roleList.value)
|
2024-11-07 19:25:45 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-01 13:49:32 +08:00
|
|
|
|
// 删除用户信息
|
2024-11-07 19:25:45 +08:00
|
|
|
|
const handleDelete = async (params: User.ResUser) => {
|
2024-11-12 18:56:33 +08:00
|
|
|
|
await useHandleData(deleteUser, [params.id] , `删除【${params.name}】用户`)
|
2024-10-23 20:53:58 +08:00
|
|
|
|
proTable.value?.getTableList()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-12 18:56:33 +08:00
|
|
|
|
// 批量删除用户信息
|
2024-10-23 20:53:58 +08:00
|
|
|
|
const batchDelete = async (id: string[]) => {
|
2024-11-14 11:34:25 +08:00
|
|
|
|
await useHandleData(deleteUser, id , '删除所选用户信息')
|
2024-10-23 20:53:58 +08:00
|
|
|
|
proTable.value?.clearSelection()
|
|
|
|
|
|
proTable.value?.getTableList()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-11-12 18:56:33 +08:00
|
|
|
|
// 修改密码
|
|
|
|
|
|
const EditPassWord = async (row: User.ResPassWordUser) => {
|
|
|
|
|
|
passWordPopup.value?.open(row)
|
2024-10-23 20:53:58 +08:00
|
|
|
|
|
2024-11-12 18:56:33 +08:00
|
|
|
|
}
|
2024-11-07 19:25:45 +08:00
|
|
|
|
|
|
|
|
|
|
|
2024-10-23 20:53:58 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|