马宇豪
2023-03-22 22bf644b3fc85763be3ad0c5e348d2bee38e2444
src/views/system/user/index.vue
@@ -2,8 +2,18 @@
    <div class="system-user-container">
        <el-card shadow="hover">
            <div class="system-user-search mb15">
                <el-input size="default" placeholder="请输入用户名称" style="max-width: 180px"> </el-input>
                <el-button size="default" type="primary" class="ml10">
                <el-cascader
                    v-model="userTableData.listQuery.searchParams.depId"
                    :props="props"
                    :options="departmentList"
                    :show-all-levels="false"
                    placeholder="请选择部门"
                    clearable
                    size="default"
                ></el-cascader>
                <el-input size="default" v-model.trim="userTableData.listQuery.searchParams.username" placeholder="请输入用户名" style="max-width: 180px;margin-left: 10px;margin-right: 10px"> </el-input>
                <el-input size="default" v-model.trim="userTableData.listQuery.searchParams.realName" placeholder="请输入真实姓名" style="max-width: 180px"> </el-input>
                <el-button size="default" type="primary" class="ml10" @click="initUserTableData">
                    <el-icon>
                        <ele-Search />
                    </el-icon>
@@ -18,11 +28,25 @@
            </div>
            <el-table :data="userTableData.data" style="width: 100%">
                <el-table-column type="index" label="序号" width="60" />
                <el-table-column prop="username" label="账户名称" show-overflow-tooltip></el-table-column>
                <el-table-column prop="realName" label="用户昵称" show-overflow-tooltip></el-table-column>
                <el-table-column prop="sex" label="性别" show-overflow-tooltip></el-table-column>
                <el-table-column prop="role.name" label="关联角色" show-overflow-tooltip></el-table-column>
                <el-table-column prop="department.name" label="部门" show-overflow-tooltip></el-table-column>
                <el-table-column prop="username" label="用户名" show-overflow-tooltip></el-table-column>
                <el-table-column prop="realName" label="真实姓名" show-overflow-tooltip></el-table-column>
                <el-table-column prop="gender" label="性别" show-overflow-tooltip>
                    <template #default="scope">
                        <el-tag type="success" v-if="scope.row.gender == 1">男</el-tag>
                        <el-tag type="success" v-else-if="scope.row.gender == 0">女</el-tag>
                    </template>
                </el-table-column>
                <el-table-column prop="positionId" label="职务" show-overflow-tooltip>
                    <template #default="scope">
                        {{ parseNumber(scope.row.positionId) }}
                    </template>
                </el-table-column>
<!--                <el-table-column prop="type" label="职务" show-overflow-tooltip>-->
<!--                    <template #default="scope">-->
<!--                        {{ `${userTypeList.find(item => item.id === scope.row.type)?.name}` }}-->
<!--                    </template>-->
<!--                </el-table-column>-->
                <el-table-column prop="department.depName" label="部门" show-overflow-tooltip></el-table-column>
                <el-table-column prop="phone" label="手机号" show-overflow-tooltip></el-table-column>
                <el-table-column prop="email" label="邮箱" show-overflow-tooltip></el-table-column>
                <el-table-column prop="status" label="用户状态" show-overflow-tooltip>
@@ -35,7 +59,7 @@
                <el-table-column label="操作" width="100">
                    <template #default="scope">
                        <el-button :disabled="scope.row.userName === 'admin'" size="small" text type="primary" @click="onOpenUserDialog('修改', scope.row)">修改</el-button>
                        <el-button :disabled="scope.row.userName === 'admin'" size="small" text type="primary" @click="onRowDel(scope.row)">删除</el-button>
                        <el-button style="color: red" :disabled="scope.row.userName === 'admin'" size="small" text type="primary" @click="onRowDel(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
@@ -53,6 +77,7 @@
import { ElMessageBox, ElMessage } from 'element-plus';
import userDialog from '/@/views/system/user/component/userDialog.vue';
import { userApi } from '/@/api/systemManage/user';
import { dutyApi } from '/@/api/systemManage/duty';
import { departmentApi } from '/@/api/systemManage/department';
import { useRoleApi } from '/@/api/systemManage/role';
@@ -79,8 +104,9 @@
        loading: boolean;
        listQuery: {
            searchParams: {
                username: string;
                realName: string;
                depId: string | null;
                username: string | null;
                realName: string | null;
            };
            pageIndex: number;
            pageSize: number;
@@ -88,6 +114,9 @@
    };
    departmentList: [];
    roleList: [];
    dutyList: [];
    userTypeList: Array<{id:number,name:string}>;
    props:{}
}
export default defineComponent({
@@ -102,15 +131,28 @@
                loading: false,
                listQuery: {
                    searchParams: {
                        username: '',
                        realName: ''
                        depId: null,
                        username: null,
                        realName: null
                    },
                    pageIndex: 1,
                    pageSize: 10
                }
            },
            departmentList: [],
            roleList: []
            roleList: [],
            dutyList: [],
            props: {
                label: 'depName',
                value: 'depId',
                checkStrictly: true,
                emitPath: false
            },
            userTypeList: [
                { id: 1, name: '超级管理员' },
                { id: 2, name: '管理员' },
                { id: 3, name: '普通员工' }
            ]
        });
        // 初始化表格数据
        const initUserTableData = async () => {
@@ -126,6 +168,10 @@
            }
        };
        // 回显职务信息
        const parseNumber = (value: number) => {
            return state.dutyList.find((i) => i.positionId === value)?.positionName;
        };
        const getDepartmentData = async () => {
            let res = await departmentApi().getDepartmentList();
            if (res.data.code === '200') {
@@ -150,20 +196,45 @@
            }
        };
        const getDutyData = async () => {
            let res = await dutyApi().getAllList({positionName: '',positionCode: ''});
            if (res.data.code === '200') {
                state.dutyList = res.data.data;
            } else {
                ElMessage({
                    type: 'warning',
                    message: res.data.msg
                });
            }
        };
        // 打开新增修改用户弹窗
        const onOpenUserDialog = (type: string, value: any) => {
            userRef.value.openDialog(type, value, state.departmentList, state.roleList);
            userRef.value.openDialog(type, value, state.departmentList, state.roleList, state.dutyList);
        };
        // 删除用户
        const onRowDel = (row: TableDataRow) => {
            ElMessageBox.confirm(`此操作将永久删除账户名称:“${row.userName}”,是否继续?`, '提示', {
            ElMessageBox.confirm(`此操作将永久删除账户名称:“${row.realName}”,是否继续?`, '提示', {
                confirmButtonText: '确认',
                cancelButtonText: '取消',
                type: 'warning'
            })
                .then(() => {
                    ElMessage.success('删除成功');
                .then(async () => {
                    let res = await userApi().deleteUser({ uid: row.uid });
                    if (res.data.code === '200') {
                        ElMessage({
                            type: 'success',
                            duration: 2000,
                            message: '删除成功'
                        });
                        await initUserTableData();
                    } else {
                        ElMessage({
                            type: 'warning',
                            message: res.data.msg
                        });
                    }
                })
                .catch(() => {});
        };
@@ -182,11 +253,13 @@
            initUserTableData();
            getDepartmentData();
            getRoleData();
            getDutyData()
        });
        return {
            userRef,
            onOpenUserDialog,
            onRowDel,
            parseNumber,
            onHandleSizeChange,
            initUserTableData,
            onHandleCurrentChange,
@@ -195,3 +268,15 @@
    }
});
</script>
<style  scoped>
:deep(.el-textarea.is-disabled .el-textarea__inner) {
    background-color: var(--el-card-bg-color);
    color: var(--el-input-text-color, var(--el-text-color-regular));
}
:deep(.el-input.is-disabled .el-input__inner) {
    color: var(--el-input-text-color, var(--el-text-color-regular));
}
:deep(.el-input.is-disabled .el-input__wrapper) {
    background-color: var(--el-card-bg-color);
}
</style>