字段调整
This commit is contained in:
@@ -3,12 +3,14 @@
|
||||
<ProTable
|
||||
ref='proTable'
|
||||
:columns='columns'
|
||||
:data='userData'
|
||||
:request-api="getTableList"
|
||||
:data-callback="dataCallback"
|
||||
>
|
||||
<!-- :data='userData' -->
|
||||
<!-- 表格 header 按钮 -->
|
||||
<template #tableHeader='scope'>
|
||||
<el-button type='primary' :icon='CirclePlus' @click="openDrawer('新增用户')">新增</el-button>
|
||||
<el-button type='primary' :icon='Download' plain @click='downloadFile'>导出数据</el-button>
|
||||
<el-button type='primary' :icon='Download' plain >导出数据</el-button>
|
||||
<el-button type='danger' :icon='Delete' plain :disabled='!scope.isSelected'
|
||||
@click='batchDelete(scope.selectedListIds)'>
|
||||
批量删除
|
||||
@@ -23,11 +25,13 @@
|
||||
|
||||
</ProTable>
|
||||
</div>
|
||||
<userUnit
|
||||
:dialogVisible = userUnitVisible
|
||||
:title = userUnitTitle
|
||||
:data = userUnitData
|
||||
@update:visible="userUnitVisible = $event"
|
||||
<userPopup
|
||||
:dialogVisible = userPopupVisible
|
||||
:title = userPopupTitle
|
||||
:data = userPopupData
|
||||
:openType=openType
|
||||
:getTableList="proTable?.getTableList || (() => {})"
|
||||
@update:visible="userPopupVisible = $event"
|
||||
/>
|
||||
</template>
|
||||
|
||||
@@ -37,7 +41,7 @@
|
||||
import { useDownload } from '@/hooks/useDownload'
|
||||
import { useAuthButtons } from '@/hooks/useAuthButtons'
|
||||
import ProTable from '@/components/ProTable/index.vue'
|
||||
import userUnit from './components/userUnit.vue'
|
||||
import userPopup from './components/userPopup.vue'
|
||||
import ImportExcel from '@/components/ImportExcel/index.vue'
|
||||
import { ProTableInstance, ColumnProps } from '@/components/ProTable/interface'
|
||||
|
||||
@@ -50,28 +54,25 @@
|
||||
BatchAddUser,
|
||||
editUser,
|
||||
deleteUser,
|
||||
changeUserStatus,
|
||||
exportUserInfo,
|
||||
getUserStatus,
|
||||
} from '@/api/user/user'
|
||||
|
||||
const {userUnitVisible,userUnitTitle,userUnitData} = useCount();
|
||||
const {userPopupVisible,userPopupTitle,userPopupData} = useCount();
|
||||
function useCount() {
|
||||
const userUnitVisible = ref(false)
|
||||
const userUnitTitle = ref()
|
||||
const userUnitData = ref<User.ResUserList>({} as User.ResUserList)
|
||||
return {userUnitVisible,userUnitTitle,userUnitData};
|
||||
const userPopupVisible = ref(false)
|
||||
const userPopupTitle = ref()
|
||||
const userPopupData = ref<User.UserBO>({} as User.UserBO)
|
||||
return {userPopupVisible,userPopupTitle,userPopupData};
|
||||
}
|
||||
|
||||
const dictStore = useDictStore()
|
||||
|
||||
const userData = userDataList
|
||||
let openType = ''
|
||||
// const userData = userDataList
|
||||
|
||||
// ProTable 实例
|
||||
const proTable = ref<ProTableInstance>()
|
||||
|
||||
// 如果表格需要初始化请求参数,直接定义传给 ProTable (之后每次请求都会自动带上该参数,此参数更改之后也会一直带上,改变此参数会自动刷新表格数据)
|
||||
const initParam = reactive({ type: 1 })
|
||||
// const initParam = reactive({ type: 1 })
|
||||
|
||||
// dataCallback 是对于返回的表格数据做处理,如果你后台返回的数据不是 list && total 这些字段,可以在这里进行处理成这些字段
|
||||
// 或者直接去 hooks/useTable.ts 文件中把字段改为你后端对应的就行
|
||||
@@ -79,6 +80,8 @@
|
||||
return {
|
||||
list: data.list,
|
||||
total: data.total,
|
||||
pageNum: data.pageNum,
|
||||
pageSize: data.pageSize,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,102 +99,116 @@
|
||||
const { BUTTONS } = useAuthButtons()
|
||||
|
||||
// 表格配置项
|
||||
const columns = reactive<ColumnProps<User.ResUserList>[]>([
|
||||
const columns = reactive<ColumnProps<User.UserBO>[]>([
|
||||
{ type: 'selection', fixed: 'left', width: 70 },
|
||||
{ type: 'index', fixed: 'left', width: 70, label: '序号' },
|
||||
{
|
||||
prop: 'username',
|
||||
prop: 'name',
|
||||
label: '用户名',
|
||||
search: { el: 'input' },
|
||||
minWidth: 150,
|
||||
},
|
||||
{
|
||||
prop: 'realname',
|
||||
label: '真实姓名',
|
||||
prop: 'loginName',
|
||||
label: '登录名',
|
||||
search: { el: 'input' },
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
prop: 'rolename',
|
||||
label: '角色类型',
|
||||
prop: 'password',
|
||||
label: '密码',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
prop: 'status',
|
||||
|
||||
label: '状态',
|
||||
enum: dictStore.getDictData('status'),
|
||||
search: { el: 'tree-select', props: { filterable: true } },
|
||||
minWidth: 100,
|
||||
fieldNames: { label: 'label', value: 'code' },
|
||||
render: scope => {
|
||||
return (
|
||||
<el-tag type={scope.row.status ? 'success' : 'danger'}>{scope.row.status ? '启用' : '禁用'}</el-tag>
|
||||
)
|
||||
},
|
||||
prop: 'phone',
|
||||
label: '手机号',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
prop: 'email',
|
||||
label: '邮箱',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
prop: 'loginTime',
|
||||
label: '最后一次登录时间',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
prop: 'loginErrorTimes',
|
||||
label: '登录错误次数',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
prop: 'lockTime',
|
||||
label: '用户密码错误锁定时间',
|
||||
minWidth: 180,
|
||||
},
|
||||
{ prop: 'operation', label: '操作', fixed: 'right', width: 330 },
|
||||
])
|
||||
|
||||
// 删除角色信息
|
||||
const deleteAccount = async (params: User.ResUserList) => {
|
||||
await useHandleData(deleteUser, { id: [params.id] }, `删除【${params.rolename}】角色`)
|
||||
// 删除用户信息
|
||||
const deleteAccount = async (params: User.UserBO) => {
|
||||
await useHandleData(deleteUser, { id: [params.id] }, `删除【${params.name}】用户`)
|
||||
proTable.value?.getTableList()
|
||||
}
|
||||
|
||||
// 批量删除角色信息
|
||||
const batchDelete = async (id: string[]) => {
|
||||
await useHandleData(deleteUser, { id }, '删除所选角色信息')
|
||||
await useHandleData(deleteUser, { id }, '删除所选用户信息')
|
||||
proTable.value?.clearSelection()
|
||||
proTable.value?.getTableList()
|
||||
}
|
||||
|
||||
// 切换角色状态
|
||||
const changeStatus = async (row: User.ResUserList) => {
|
||||
await useHandleData(changeUserStatus, {
|
||||
id: row.id,
|
||||
status: row.status == 1 ? 0 : 1,
|
||||
}, `切换【${row.rolename}】角色状态`)
|
||||
proTable.value?.getTableList()
|
||||
}
|
||||
|
||||
// 导出角色列表
|
||||
const downloadFile = async () => {
|
||||
ElMessageBox.confirm('确认导出角色数据?', '温馨提示', { type: 'warning' }).then(() =>
|
||||
useDownload(exportUserInfo, '角色列表', proTable.value?.searchParam),
|
||||
)
|
||||
}
|
||||
// const downloadFile = async () => {
|
||||
// ElMessageBox.confirm('确认导出角色数据?', '温馨提示', { type: 'warning' }).then(() =>
|
||||
// useDownload(exportUserInfo, '角色列表', proTable.value?.searchParam),
|
||||
// )
|
||||
// }
|
||||
|
||||
// 批量添加角色
|
||||
const dialogRef = ref<InstanceType<typeof ImportExcel> | null>(null)
|
||||
const batchAdd = () => {
|
||||
const params = {
|
||||
title: '角色',
|
||||
tempApi: exportUserInfo,
|
||||
importApi: BatchAddUser,
|
||||
getTableList: proTable.value?.getTableList,
|
||||
}
|
||||
dialogRef.value?.acceptParams(params)
|
||||
// const params = {
|
||||
// title: '角色',
|
||||
// tempApi: exportUserInfo,
|
||||
// importApi: BatchAddUser,
|
||||
// getTableList: proTable.value?.getTableList,
|
||||
// }
|
||||
// dialogRef.value?.acceptParams(params)
|
||||
}
|
||||
|
||||
// 打开 drawer(新增、查看、编辑)
|
||||
const openDrawer = (title: string, row: Partial<User.ResUserList> = {}) => {
|
||||
const openDrawer = (title: string, row: Partial<User.UserBO> = {}) => {
|
||||
if(title === "查看用户" ||title === "新增用户" || title === '编辑用户' )
|
||||
{
|
||||
userUnitVisible.value = true
|
||||
userUnitTitle.value = title
|
||||
if (title === '查看用户')
|
||||
openType = 'view'
|
||||
else if (title === '新增用户')
|
||||
openType = 'add'
|
||||
else if (title === '编辑用户')
|
||||
openType = 'edit'
|
||||
|
||||
userPopupVisible.value = true
|
||||
userPopupTitle.value = title
|
||||
|
||||
if (row) {
|
||||
// 确保 row 的所有属性都符合 User.ResUserList 的要求
|
||||
const safeRow: User.ResUserList = {
|
||||
const safeRow: User.UserBO = {
|
||||
id: row.id || '',
|
||||
username: row.username || '',
|
||||
name: row.name || '',
|
||||
loginName: row.loginName || '',
|
||||
password: row.password || '',
|
||||
realname: row.realname || '',
|
||||
status: row.status || 0,
|
||||
rolename: row.rolename || '',
|
||||
phone: row.phone || '',
|
||||
email: row.email || '',
|
||||
loginTime: row.loginTime || '',
|
||||
loginErrorTimes: row.loginErrorTimes || 0,
|
||||
lockTime: row.lockTime || '',
|
||||
};
|
||||
|
||||
userUnitData.value = safeRow;
|
||||
userPopupData.value = safeRow;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user