From 62b57a97cba78146063a4f4292ac955f0b4be463 Mon Sep 17 00:00:00 2001 From: chenghongxing <1126263215@qq.com> Date: Tue, 12 Jan 2021 11:38:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=20Mock=20=E7=99=BB=E5=BD=95=E7=94=A8=E6=88=B7=E8=A7=92?= =?UTF-8?q?=E8=89=B2=20test=EF=BC=9B=20feat:=20add=20new=20role=20for=20lo?= =?UTF-8?q?gin=20user;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mock/user/login.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/mock/user/login.js b/src/mock/user/login.js index c8b0279..97db1a1 100644 --- a/src/mock/user/login.js +++ b/src/mock/user/login.js @@ -8,21 +8,32 @@ const user = Mock.mock({ position: '@POSITION' }) Mock.mock(`${process.env.VUE_APP_API_BASE_URL}/login`, 'post', ({body}) => { - let result = {} + let result = {data: {}} const {name, password} = JSON.parse(body) - if (name !== 'admin' || password !== '888888') { - result.code = -1 - result.message = '账户名或密码错误(admin/888888)' + let success = false + + if (name === 'admin' && password === '888888') { + success = true + result.data.permissions = [{id: 'queryForm', operation: ['add', 'edit']}] + result.data.roles = [{id: 'admin', operation: ['add', 'edit', 'delete']}] + } else if (name === 'test' || password === '888888') { + success = true + result.data.permissions = [{id: 'queryForm', operation: ['add', 'edit']}] + result.data.roles = [{id: 'test', operation: ['add', 'edit', 'delete']}] } else { + success = false + } + + if (success) { result.code = 0 result.message = Mock.mock('@TIMEFIX').CN + ',欢迎回来' - result.data = {} result.data.user = user result.data.token = 'Authorization:' + Math.random() result.data.expireAt = new Date(new Date().getTime() + 30 * 60 * 1000) - result.data.permissions = [{id: 'queryForm', operation: ['add', 'edit']}] - result.data.roles = [{id: 'admin', operation: ['add', 'edit', 'delete']}] + } else { + result.code = -1 + result.message = '账户名或密码错误(admin/888888 or test/888888)' } return result })