diff --git a/src/mock/Login.js b/src/mock/Login.js index 299b4410e48efa168ca9b2a711b9563e3b559859..a24668347fa948f08a1a082530c395979a552464 100644 --- a/src/mock/Login.js +++ b/src/mock/Login.js @@ -8,11 +8,11 @@ if (localStorage.getItem("user_info")) { } else { // 生成数据 data = Mock.mock({ - "list|1": [ + "list|2": [ { "id": '@increment()', - // 'phone|13000000000-19000000000': 1, - phone: 'admin', + 'phone|13000000000-19000000000': 1, + // phone: 'admin', name: '@name', pass: 123456, roles: [] @@ -34,7 +34,13 @@ Mock.mock('/api/user/login', "post", (req) => { var { phone, pass } = JSON.parse(req.body); console.log(phone, pass); if (phone != undefined && pass != undefined) { - if (data.list.pass == pass) { + console.log("data.list", data.list); + let index = data.list.findIndex((item) => { + return item.phone == phone + }) + console.log(index); + if (data.list[index].pass == pass) { + tokendata = Mock.mock({ 'tokenarr': [ { @@ -42,29 +48,29 @@ Mock.mock('/api/user/login', "post", (req) => { } ] }) - return { code: 200, msg: "登录成功", token: tokendata.tokenarr[0].token, name: data.list.name }; + return { code: 200, msg: "登录成功", token: tokendata.tokenarr[0].token }; + + } else { return { code: 500, msg: "用户名或密码错误" }; } + } else { - return { code: 500, msg: "用户名或密码错误" }; + return { code: 500, msg: "用户名或密码没有输入" }; } }); // 添加管理员 Mock.mock('/api/user/add', "post", (req) => { - var { phone, pass } = JSON.parse(req.body); + var { phone, pass, name } = JSON.parse(req.body); var index = data.list.findIndex((item) => { return item.phone == phone; }); if (index == -1) { - data.list.unshift({ id: data.list.length + 1, phone, pass, }); + data.list.unshift({ id: data.list.length + 1, phone, pass, name }); localStorage.setItem("user_info", JSON.stringify(data)); - phone = ""; - pass = ""; - return { code: 200, msg: "注册成功", list: data.list }; - } else { - return { code: 500, msg: "该账号已被注册", list: data.list }; + + return { code: 200, msg: "添加成功", list: data.list }; } }) diff --git a/src/views/SystemSettings/RoleManagement/AddMan.tsx b/src/views/SystemSettings/RoleManagement/AddMan.tsx index 8960b79c3cf9db83f438c22ea1fcf02b13bec5d7..85d4b6a81ee4d6f1affcb9e76446ae4bcdd007da 100644 --- a/src/views/SystemSettings/RoleManagement/AddMan.tsx +++ b/src/views/SystemSettings/RoleManagement/AddMan.tsx @@ -17,7 +17,7 @@ interface Props { const PubText: React.FC = () => { const [form] = Form.useForm() const push = useNavigate() - const [data, setData] = useState([]) + const [data, setData] = useState() //接受路由跳转传递过来的值search var [params, setParams] = useSearchParams() var val = params.get('data') @@ -55,9 +55,9 @@ const PubText: React.FC = () => { onFinish={onFinish} style={{ maxWidth: 600, paddingTop: 20 }} > -