From 7b6048096661d8cbcdb17f0ecfda667ae5716d69 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期二, 10 九月 2024 10:49:15 +0800
Subject: [PATCH] #

---
 zy-acs-flow/src/page/user/UserCreate.jsx                                              |   80 ++++++++++++++++----------
 zy-acs-manager/src/main/java/com/zy/acs/manager/system/controller/UserController.java |   22 ++++---
 zy-acs-flow/src/page/user/RolesSelect.jsx                                             |   29 +++++++++
 3 files changed, 90 insertions(+), 41 deletions(-)

diff --git a/zy-acs-flow/src/page/user/RolesSelect.jsx b/zy-acs-flow/src/page/user/RolesSelect.jsx
new file mode 100644
index 0000000..c5cdf4e
--- /dev/null
+++ b/zy-acs-flow/src/page/user/RolesSelect.jsx
@@ -0,0 +1,29 @@
+import * as React from 'react';
+import { SelectArrayInput } from 'react-admin';
+import request from '@/utils/request'
+
+const RolesSelect = (props) => {
+    const [arr, setArr] = React.useState([]);
+
+    React.useEffect(() => {
+        request.post('/role/list', {}).then(res => {
+            if (res?.data?.code === 200) {
+                setArr(res.data.data.map(item => {
+                    return {
+                        id: item.id,
+                        name: item.name
+                    }
+                }))
+            }
+        })
+    }, [])
+
+    return (
+        <SelectArrayInput
+            {...props}
+            choices={arr}
+        />
+    )
+};
+
+export default RolesSelect;
diff --git a/zy-acs-flow/src/page/user/UserCreate.jsx b/zy-acs-flow/src/page/user/UserCreate.jsx
index 04e888d..1790c3f 100644
--- a/zy-acs-flow/src/page/user/UserCreate.jsx
+++ b/zy-acs-flow/src/page/user/UserCreate.jsx
@@ -13,10 +13,11 @@
     AutocompleteInput,
     Toolbar,
     required,
-    useDataProvider,
+    PasswordInput,
     useNotify,
     Form,
     useCreateController,
+    email,
 } from 'react-admin';
 import {
     Dialog,
@@ -31,6 +32,7 @@
 import StatusSelectInput from "../components/StatusSelectInput";
 import MemoInput from "../components/MemoInput";
 import TreeSelectInput from "../components/TreeSelectInput";
+import RolesSelect from './RolesSelect'
 
 const UserCreate = (props) => {
     const { open, setOpen } = props;
@@ -70,7 +72,29 @@
                     disableRestoreFocus
                     maxWidth="md"   // 'xs' | 'sm' | 'md' | 'lg' | 'xl'
                 >
-                    <Form>
+                    <Form validate={values => {
+                        const errors = {};
+                        if (!values.username) {
+                            errors.username = 'ra.validation.required';
+                        }
+                        if (!values.nickname) {
+                            errors.nickname = 'ra.validation.required';
+                        }
+                        if (!values.roleIds) {
+                            errors.roleIds = 'ra.validation.required';
+                        }
+                        if (!values.email) {
+                        } else {
+                            const error = email()(values.email);
+                            if (error) {
+                                errors.email = error;
+                            }
+                        }
+                        if (values.password && values.password !== values.confirmPassword) {
+                            errors.confirmPassword = 'resources.customers.errors.password_mismatch';
+                        }
+                        return errors;
+                    }}>
                         <DialogTitle id="form-dialog-title" sx={{
                             position: 'sticky',
                             top: 0,
@@ -102,11 +126,23 @@
                                     />
                                 </Grid>
                                 <Grid item xs={6} display="flex" gap={1}>
-                                    <TextInput
-                                        label="table.field.user.code"
-                                        source="code"
-                                        parse={v => v}
+                                    <TreeSelectInput
+                                        resource="dept"
+                                        label="table.field.user.deptId"
+                                        source="deptId"
                                     />
+                                </Grid>
+                                <Grid item xs={6} display="flex" gap={1}>
+                                    <RolesSelect
+                                        label="table.field.user.role"
+                                        source="roleIds"
+                                    />
+                                </Grid>
+                                <Grid item xs={6} display="flex" gap={1}>
+                                    <PasswordInput source="password" />
+                                </Grid>
+                                <Grid item xs={6} display="flex" gap={1}>
+                                    <PasswordInput source="confirmPassword" />
                                 </Grid>
                                 <Grid item xs={6} display="flex" gap={1}>
                                     <SelectInput
@@ -117,6 +153,13 @@
                                             { id: 1, name: '鐢�' },
                                             { id: 2, name: '濂�' },
                                         ]}
+                                    />
+                                </Grid>
+                                <Grid item xs={6} display="flex" gap={1}>
+                                    <TextInput
+                                        label="table.field.user.code"
+                                        source="code"
+                                        parse={v => v}
                                     />
                                 </Grid>
                                 <Grid item xs={6} display="flex" gap={1}>
@@ -134,13 +177,6 @@
                                     />
                                 </Grid>
                                 <Grid item xs={6} display="flex" gap={1}>
-                                    <TreeSelectInput
-                                        resource="dept"
-                                        label="table.field.user.deptId"
-                                        source="deptId"
-                                    />
-                                </Grid>
-                                <Grid item xs={6} display="flex" gap={1}>
                                     <TextInput
                                         label="table.field.user.realName"
                                         source="realName"
@@ -153,24 +189,6 @@
                                         source="idCard"
                                         parse={v => v}
                                     />
-                                </Grid>
-                                <Grid item xs={6} display="flex" gap={1}>
-                                    <TextInput
-                                        label="table.field.user.birthday"
-                                        source="birthday"
-                                        parse={v => v}
-                                    />
-                                </Grid>
-                                <Grid item xs={6} display="flex" gap={1}>
-                                    <TextInput
-                                        label="table.field.user.introduction"
-                                        source="introduction"
-                                        parse={v => v}
-                                    />
-                                </Grid>
-
-                                <Grid item xs={6} display="flex" gap={1}>
-                                    <StatusSelectInput />
                                 </Grid>
                                 <Grid item xs={12} display="flex" gap={1}>
                                     <Stack direction="column" spacing={1} width={'100%'}>
diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/system/controller/UserController.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/system/controller/UserController.java
index 64fa4b2..dc86572 100644
--- a/zy-acs-manager/src/main/java/com/zy/acs/manager/system/controller/UserController.java
+++ b/zy-acs-manager/src/main/java/com/zy/acs/manager/system/controller/UserController.java
@@ -83,7 +83,9 @@
             return R.error("the phone already exist");
         }
 
-        user.setPassword(userService.encodePassword(COMMON_PASSWORD));
+        if (Cools.isEmpty(user.getPassword())) {
+            user.setPassword(userService.encodePassword(COMMON_PASSWORD));
+        }
 
         user.setCreateBy(getLoginUserId());
         user.setCreateTime(new Date());
@@ -95,13 +97,15 @@
         }
 
         userRoleService.remove(new LambdaQueryWrapper<UserRole>().eq(UserRole::getUserId, user.getId()));
-        for (Long roleId : user.getRoleIds()) {
-            if (!userRoleService.save(new UserRole(user.getId(), roleId))) {
-                throw new CoolException("Internal Server Error");
+        if (!Cools.isEmpty((Object) user.getRoleIds())) {
+            for (Long roleId : user.getRoleIds()) {
+                if (!userRoleService.save(new UserRole(user.getId(), roleId))) {
+                    throw new CoolException("Internal Server Error");
+                }
             }
         }
 
-        return R.ok("Save Success");
+        return R.ok("Save Success").add(user);
     }
 
     @PreAuthorize("hasAuthority('system:user:update')")
@@ -145,7 +149,7 @@
             }
         }
 
-        return R.ok("Update Success");
+        return R.ok("Update Success").add(user);
     }
 
     @PreAuthorize("hasAuthority('system:user:remove')")
@@ -157,11 +161,9 @@
             if (!userService.removeById(userId)) {
                 throw new CoolException("Internal Server Error");
             }
-            if (!userRoleService.remove(new LambdaQueryWrapper<UserRole>().eq(UserRole::getUserId, userId))) {
-                throw new CoolException("Internal Server Error");
-            }
+            userRoleService.remove(new LambdaQueryWrapper<UserRole>().eq(UserRole::getUserId, userId));
         }
-        return R.ok("Delete Success");
+        return R.ok("Delete Success").add(ids);
     }
 
     @PreAuthorize("hasAuthority('system:user:list')")

--
Gitblit v1.9.1