Files
pqs-9100_client/frontend/src/views/authority/user/index.vue

153 lines
4.6 KiB
Vue
Raw Normal View History

<template>
2024-11-07 19:25:45 +08:00
<div class='table-box' ref='popupBaseView'>
<ProTable
ref='proTable'
:columns='columns'
2024-11-01 13:49:32 +08:00
:request-api="getTableList"
>
2024-11-01 13:49:32 +08:00
<!-- :data='userData' -->
<!-- 表格 header 按钮 -->
<template #tableHeader='scope'>
2024-11-07 19:25:45 +08:00
<el-button type='primary' :icon='CirclePlus' @click="openDialog('add')">新增</el-button>
<el-button type='danger' :icon='Delete' plain :disabled='!scope.isSelected'
@click='batchDelete(scope.selectedListIds)'>
批量删除
</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>
</template>
</ProTable>
</div>
2024-11-07 19:25:45 +08:00
<UserPopup :refresh-table='proTable?.getTableList' ref='userPopup' />
</template>
<script setup lang='tsx' name='useRole'>
2024-11-07 19:25:45 +08:00
import TimeControl from '@/components/TimeControl/index.vue'
import { type User } from '@/api/user/interface'
import { useHandleData } from '@/hooks/useHandleData'
import { useDownload } from '@/hooks/useDownload'
import { useAuthButtons } from '@/hooks/useAuthButtons'
import ProTable from '@/components/ProTable/index.vue'
2024-11-07 19:25:45 +08:00
import UserPopup from './components/userPopup.vue'
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'
import { useDictStore } from '@/stores/modules/dict'
2024-11-07 19:25:45 +08:00
import {getUserList, deleteUser,} from '@/api/user/user'
import { reactive, ref } from 'vue'
const dictStore = useDictStore()
2024-11-07 19:25:45 +08:00
const userPopup = ref()
// ProTable 实例
const proTable = ref<ProTableInstance>()
// 如果你想在请求之前对当前请求参数做一些操作可以自定义如下函数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-11-07 19:25:45 +08:00
const columns = reactive<ColumnProps<User.ResUser>[]>([
{ type: 'selection', fixed: 'left', width: 70 },
{ type: 'index', fixed: 'left', width: 70, label: '序号' },
{
2024-11-01 13:49:32 +08:00
prop: 'name',
label: '用户名',
search: { el: 'input' },
minWidth: 150,
},
{
2024-11-01 13:49:32 +08:00
prop: 'loginName',
label: '登录名',
minWidth: 180,
},
{
prop: 'password',
label: '密码',
minWidth: 180,
},
{
2024-11-01 13:49:32 +08:00
prop: 'phone',
label: '手机号',
minWidth: 180,
},
{
2024-11-01 13:49:32 +08:00
prop: 'email',
label: '邮箱',
minWidth: 180,
},
{
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
},
{
prop: 'loginErrorTimes',
label: '登录错误次数',
minWidth: 180,
},
{
prop: 'lockTime',
label: '用户密码错误锁定时间',
minWidth: 180,
},
{ prop: 'operation', label: '操作', fixed: 'right', width: 330 },
])
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> = {}) => {
userPopup.value?.open(titleType, row)
}
2024-11-01 13:49:32 +08:00
// 删除用户信息
2024-11-07 19:25:45 +08:00
const handleDelete = async (params: User.ResUser) => {
2024-11-01 13:49:32 +08:00
await useHandleData(deleteUser, { id: [params.id] }, `删除【${params.name}】用户`)
proTable.value?.getTableList()
}
// 批量删除角色信息
const batchDelete = async (id: string[]) => {
2024-11-01 13:49:32 +08:00
await useHandleData(deleteUser, { id }, '删除所选用户信息')
proTable.value?.clearSelection()
proTable.value?.getTableList()
}
2024-11-07 19:25:45 +08:00
</script>