-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
641 additions
and
258 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,122 +1,69 @@ | ||
import { definePostMock } from "../config"; | ||
import Mock from 'mockjs' | ||
export const menu = [ | ||
{ | ||
id: 1, | ||
name: '控制台', | ||
route_path: "/console", | ||
parent_id: 0, | ||
icon: "mingcute:confused-fill" | ||
}, | ||
{ | ||
id: 2, | ||
name: '工单管理', | ||
route_path: "/console", | ||
parent_id: 0, | ||
icon: "mingcute:confused-fill" | ||
}, | ||
{ | ||
id: 3, | ||
name: '企业管理', | ||
route_path: "/system/user", | ||
parent_id: 0, | ||
icon: "mingcute:confused-fill" | ||
}, | ||
{ | ||
id: 4, | ||
name: '角色管理', | ||
route_path: "/system/role", | ||
parent_id: 3, | ||
icon: "mingcute:confused-fill" | ||
}, | ||
{ | ||
id: 5, | ||
name: '测试', | ||
route_path: "/system/role", | ||
parent_id: 3, | ||
icon: "mingcute:confused-fill" | ||
} | ||
] | ||
const findItem = <T extends object>(where: T) => { | ||
return menu.find((item) => { | ||
return Object.keys(where).every((key) => { | ||
return item[key] === where[key] | ||
}) | ||
}) | ||
} | ||
const findList = <T extends object>(where: T) => { | ||
return menu.filter((item) => { | ||
return Object.keys(where).every((key) => { | ||
return item[key] === where[key] | ||
}) | ||
}) | ||
} | ||
export const user = Mock.mock({ | ||
"total|1-1000": 1, | ||
'list|10': [ | ||
{ | ||
'id|+1': 1, | ||
name: "@cname", | ||
created_at: "@datetime", | ||
updated_at: "@datetime", | ||
} | ||
] | ||
}) | ||
import Mock from "mockjs"; | ||
import { page, where } from "../utils"; | ||
import { menu } from "../database/auth"; | ||
w; | ||
export default definePostMock([ | ||
{ | ||
url: '/system/menu', | ||
method: "GET", | ||
delay: 1000, | ||
body(request) { | ||
const { page, limit } = request.query; | ||
const start = (page - 1) * limit; | ||
const end = start + parseInt(limit);; | ||
return { | ||
total: user.list.length, | ||
list: user.list.slice(start, end) | ||
} | ||
} | ||
{ | ||
url: "/system/menu", | ||
method: "GET", | ||
delay: 500, | ||
body(request) { | ||
let parent_id: number = request.query.parent_id || 0; | ||
parent_id = | ||
typeof parent_id === "string" ? parseInt(parent_id) : parent_id; | ||
const result = where(menu, { parent_id }); | ||
if (parent_id) { | ||
return { | ||
list: result, | ||
}; | ||
} | ||
return { | ||
total: result.length, | ||
list: page(result, request.query.page, request.query.limit), | ||
}; | ||
}, | ||
{ | ||
url: '/system/menu/:id', | ||
method: "GET", | ||
body(request) { | ||
const id = request.params.id as number | ||
if (id && user.list[id - 1]) return user.list[id - 1] | ||
return { | ||
error_code: 400, | ||
msg: 'author not found', | ||
} | ||
|
||
} | ||
}, | ||
{ | ||
url: "/system/menu/:id", | ||
method: "GET", | ||
body(request) { | ||
const id = request.params.id as number; | ||
if (id && menu[id - 1]) return menu[id - 1]; | ||
return { | ||
error_code: 400, | ||
msg: "author not found", | ||
}; | ||
}, | ||
{ | ||
url: '/system/menu', | ||
method: "POST", | ||
body(request) { | ||
request.body.id = Mock.Random.integer(); | ||
user.list.push(request.body); | ||
return request.body | ||
} | ||
}, | ||
{ | ||
url: "/system/menu", | ||
method: "POST", | ||
body(request) { | ||
request.body.id = Mock.Random.integer(); | ||
menu.push(request.body); | ||
|
||
return request.body; | ||
}, | ||
{ | ||
url: '/system/menu/:id', | ||
method: "PUT", | ||
body(request) { | ||
// user.list[] | ||
const id = request.params.id as number | ||
user.list[id - 1] = Object.assign(user.list[id - 1], request.body) | ||
return user.list[id - 1] | ||
} | ||
}, | ||
{ | ||
url: "/system/menu/:id", | ||
method: "PUT", | ||
body(request) { | ||
// menu[] | ||
const id = request.params.id as number; | ||
menu[id - 1] = Object.assign(menu[id - 1], request.body); | ||
return menu[id - 1]; | ||
}, | ||
{ | ||
url: '/system/menu/:id', | ||
method: "DELETE", | ||
body(request) { | ||
// user.list[] | ||
const id = request.params.id as number | ||
user.list.splice(id - 1, 1); | ||
return user.list[id - 1]; | ||
} | ||
}, | ||
{ | ||
url: "/system/menu/:id", | ||
method: "DELETE", | ||
body(request) { | ||
// menu[] | ||
const id = request.params.id as number; | ||
menu.splice(id - 1, 1); | ||
return menu[id - 1]; | ||
}, | ||
]) | ||
}, | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,71 @@ | ||
import { definePostMock } from "../config"; | ||
import Mock from 'mockjs' | ||
import Mock from "mockjs"; | ||
import { page } from "../utils"; | ||
export const user = Mock.mock({ | ||
"total|100-1000": 1, | ||
'list|100': [ | ||
{ | ||
'id|+1': 1, | ||
"name": "@name", | ||
"system_menu_ids": '@range(1, 10, 3)', | ||
"desc": "@paragraph", | ||
created_at: "@datetime", | ||
updated_at: "@datetime", | ||
} | ||
] | ||
}) | ||
export default definePostMock([ | ||
"total|100-1000": 1, | ||
"list|100": [ | ||
{ | ||
url: '/system/role', | ||
method: "GET", | ||
delay: 1000, | ||
body(request) { | ||
const { page: start, limit } = request.query; | ||
return { | ||
total: user.list.length, | ||
list: page(user.list, start, limit) | ||
} | ||
} | ||
"id|+1": 1, | ||
name: "@name", | ||
system_menu_ids: "@range(1, 10, 3)", | ||
desc: "@paragraph", | ||
created_at: "@datetime", | ||
updated_at: "@datetime", | ||
}, | ||
{ | ||
url: '/system/role/:id', | ||
method: "GET", | ||
body(request) { | ||
const id = request.params.id as number | ||
if (id && user.list[id - 1]) return user.list[id - 1] | ||
return { | ||
error_code: 400, | ||
msg: 'author not found', | ||
} | ||
|
||
} | ||
], | ||
}); | ||
export default definePostMock([ | ||
{ | ||
url: "/system/role", | ||
method: "GET", | ||
delay: 1000, | ||
body(request) { | ||
const { page: start, limit } = request.query; | ||
return { | ||
total: user.list.length, | ||
list: page(user.list, start, limit), | ||
}; | ||
}, | ||
{ | ||
url: '/system/role', | ||
method: "POST", | ||
body(request) { | ||
request.body.id = Mock.Random.integer(); | ||
user.list.push(request.body); | ||
return request.body | ||
} | ||
}, | ||
{ | ||
url: "/system/role/:id", | ||
method: "GET", | ||
body(request) { | ||
const id = request.params.id as number; | ||
if (id && user.list[id - 1]) return user.list[id - 1]; | ||
return { | ||
error_code: 400, | ||
msg: "author not found", | ||
}; | ||
}, | ||
{ | ||
url: '/system/role/:id', | ||
method: "PUT", | ||
body(request) { | ||
// user.list[] | ||
const id = request.params.id as number | ||
user.list[id - 1] = Object.assign(user.list[id - 1], request.body) | ||
return user.list[id - 1] | ||
} | ||
}, | ||
{ | ||
url: "/system/role", | ||
method: "POST", | ||
body(request) { | ||
request.body.id = Mock.Random.integer(); | ||
user.list.push(request.body); | ||
return request.body; | ||
}, | ||
{ | ||
url: '/system/role/:id', | ||
method: "DELETE", | ||
body(request) { | ||
// user.list[] | ||
const id = request.params.id as number | ||
user.list.splice(id - 1, 1); | ||
return user.list[id - 1]; | ||
} | ||
}, | ||
{ | ||
url: "/system/role/:id", | ||
method: "PUT", | ||
body(request) { | ||
// user.list[] | ||
const id = request.params.id as number; | ||
user.list[id - 1] = Object.assign(user.list[id - 1], request.body); | ||
return user.list[id - 1]; | ||
}, | ||
}, | ||
{ | ||
url: "/system/role/:id", | ||
method: "DELETE", | ||
body(request) { | ||
// user.list[] | ||
const id = request.params.id as number; | ||
user.list.splice(id - 1, 1); | ||
return user.list[id - 1]; | ||
}, | ||
]) | ||
}, | ||
]); |
Oops, something went wrong.