马宇豪
2025-05-09 cbb23429b8beed72b58cbb57f9b3c56a0fb2b5d2
src/views/system/user/index.vue
@@ -2,7 +2,10 @@
    <div class="system-user-container">
        <el-card shadow="hover">
            <div class="system-user-search mb15">
                <el-input size="default" v-model.trim="searchName" placeholder="真实姓名" style="max-width: 180px"> </el-input>
                <el-input size="default" v-model.trim="userTableData.listQuery.searchParams.realName" placeholder="真实姓名" style="max-width: 180px;margin-right: 10px"> </el-input>
                <el-select v-model="userTableData.listQuery.searchParams.roleId" placeholder="角色类型" clearable class="w100" style="max-width: 180px" size="default">
                  <el-option v-for="item in roleList" :key="item.id" :label="item.name" :value="item.id"> </el-option>
                </el-select>
                <el-button size="default" type="primary" class="ml10" @click="searchByName()">
                    <el-icon>
                        <ele-Search />
@@ -41,8 +44,9 @@
                <el-table-column prop="idSerial" label="证件号码"></el-table-column>
                <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 style="color: red" :disabled="scope.row.userName === 'admin'" size="small" text type="primary" @click="onRowDel(scope.row)">删除</el-button>
                        <el-button :disabled="scope.row.name === 'admin'" size="small" text type="primary" @click="onOpenUserDialog('修改', scope.row)">修改</el-button>
                        <el-button style="color: red" :disabled="scope.row.name === 'admin'" size="small" text type="primary" @click="onRowDel(scope.row)">删除</el-button>
                        <el-button v-if="scope.row.name !== 'admin'" style="color: red" :disabled="!isAdmin" size="small" text type="primary" @click="onResetPwd(scope.row)">重置密码</el-button>
                    </template>
                </el-table-column>
            </el-table>
@@ -62,7 +66,10 @@
import { userApi } from '/@/api/systemManage/user';
import { departmentApi } from '/@/api/systemManage/department';
import { useRoleApi } from '/@/api/systemManage/role';
import {useUserInfo} from "/@/stores/userInfo";
import {storeToRefs} from "pinia";
const userInfo = useUserInfo();
const { userInfos } = storeToRefs(userInfo);
// 定义接口来定义对象的类型
interface TableDataRow {
    userName: string;
@@ -84,6 +91,7 @@
}
interface TableDataState {
    isAdmin: boolean
    userTableData: {
        data: Array<TableDataRow>;
        total: number;
@@ -95,13 +103,15 @@
              roleId: number | null;
              name: string
              realName: string
              userIndentityId: number | null;
            }
        };
    };
    idTypeList: Array<idType>
    depList: [];
    roleList: [];
    searchName:string
    expList: [];
    searchType: null | number
}
export default defineComponent({
@@ -110,6 +120,7 @@
    setup() {
        const userRef = ref();
        const state = reactive<TableDataState>({
            isAdmin: false,
            userTableData: {
                data: [],
                total: 0,
@@ -120,7 +131,8 @@
                  searchParams:{
                    roleId: null,
                    name: '',
                    realName: ''
                    realName: '',
                    userIndentityId: null
                  }
                }
            },
@@ -132,12 +144,13 @@
            ],
            depList: [],
            roleList: [],
            searchName: ''
            expList: [],
            searchType:null
        });
        // 初始化表格数据
        const initUserTableData = async () => {
            let res = await userApi().getUserList(state.userTableData.listQuery);
            if (res.data.code === 200) {
            if (res.data.code === 100) {
                state.userTableData.data = res.data.data;
                state.userTableData.total = res.data.total;
            } else {
@@ -147,28 +160,58 @@
                });
            }
        };
        const searchByName = async () =>{
          if(state.searchName == ''){
        const initRoleTableData = async () => {
          let res = await useRoleApi().getRoleList();
          if (res.data.code === 100) {
            state.roleList = res.data.data;
          } else {
            ElMessage({
              type: 'warning',
              message: '请输入搜索内容'
              message: res.data.msg
            });
          }else{
            let res = await userApi().getUserLByRealName(state.searchName);
            if (res.data.code === 100) {
              state.userTableData.data = res.data.data
            } else {
              ElMessage({
                type: 'warning',
                message: res.data.msg
              });
            }
          }
        }
        };
      const searchByName = ()=>{
        initUserTableData()
      }
      const onResetPwd = (row: TableDataRow)=>{
        ElMessageBox.confirm(`此操作将重置:“${row.name}”的密码,是否继续?`, '提示', {
          confirmButtonText: '确认',
          cancelButtonText: '取消',
          type: 'warning'
        })
            .then(async () => {
              let res = await userApi().resetPwd({uid: row.id});
              if (res.data.code === 100) {
                ElMessage({
                  type: 'success',
                  duration: 2000,
                  message: '密码重置成功'
                });
                await initUserTableData();
              } else {
                ElMessage({
                  type: 'warning',
                  message: res.data.msg
                });
              }
            })
            .catch(() => {});
      }
        const reset = () =>{
          state.searchName = ''
          state.userTableData.listQuery = {
            pageIndex: 1,
                pageSize: 10,
                searchParams:{
                  roleId: null,
                  name: '',
                  realName: '',
                  userIndentityId: null
                }
          }
          initUserTableData()
        }
@@ -196,10 +239,21 @@
            }
        };
        const getExpertsData = async () => {
          let res = await useRoleApi().getExpList();
          if (res.data.code === 100) {
            state.expList = res.data.data;
          } else {
            ElMessage({
              type: 'warning',
              message: res.data.msg
            });
          }
        };
        // 打开新增修改用户弹窗
        const onOpenUserDialog = (type: string, value: any) => {
          console.log('打开',state.depList, state.roleList)
            userRef.value.openDialog(type, value, state.depList, state.roleList);
            userRef.value.openDialog(type, value, state.depList, state.roleList, state.expList);
        };
        // 删除用户
@@ -240,11 +294,19 @@
        // 页面加载时
        onMounted(() => {
            initUserTableData();
            initRoleTableData();
            getRoleData();
            getExpertsData();
            getDepList()
            if(userInfos.value.roles.find(i=>i.roleId == 6 || i.roleId == 7)){
              state.isAdmin = true
            }else{
              state.isAdmin = false
            }
        });
        return {
            userRef,
          onResetPwd,
            reset,
            onOpenUserDialog,
            onRowDel,