马宇豪
2024-11-05 1f26c30a8d1c5e3d9ab262b382284c8ea96f29b2
src/views/system/user/index.vue
@@ -44,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>
@@ -65,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;
@@ -87,6 +91,7 @@
}
interface TableDataState {
    isAdmin: boolean
    userTableData: {
        data: Array<TableDataRow>;
        total: number;
@@ -115,6 +120,7 @@
    setup() {
        const userRef = ref();
        const state = reactive<TableDataState>({
            isAdmin: false,
            userTableData: {
                data: [],
                total: 0,
@@ -168,6 +174,31 @@
      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 = () =>{
@@ -267,9 +298,15 @@
            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,