Skip to content

Commit

Permalink
perf: 还原mock.js
Browse files Browse the repository at this point in the history
  • Loading branch information
kailong321200875 committed Dec 25, 2023
1 parent a18bc64 commit 83de387
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 246 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Online examples do not apply to menu filtering by default, but directly use Stat
- [Es6+](http://es6.ruanyifeng.com/) - Familiar with es6 basic syntax
- [Vue-Router-Next](https://next.router.vuejs.org/) - Familiar with the basic use of vue-router
- [Element-Plus](https://element-plus.org/) - Familiar with the basic use of element-plus
- [Faker.js](https://github.com/faker-js/faker#readme) - Generate massive amounts of fake contextual data
- [Mock.js](https://github.com/nuysoft/Mock) - mockjs basic syntax

## Install and use

Expand Down
2 changes: 1 addition & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ vue-element-plus-admin 的定位是后台集成方案,不太适合当基础模
- [Es6+](http://es6.ruanyifeng.com/) - 熟悉 es6 基本语法
- [Vue-Router-Next](https://next.router.vuejs.org/) - 熟悉 vue-router 基本使用
- [Element-Plus](https://element-plus.org/) - element-plus 基本使用
- [Faker.js](https://github.com/faker-js/faker#readme) - 生成大量伪造的上下文数据
- [Mock.js](https://github.com/nuysoft/Mock) - mockjs 基本语法

## 安装和使用

Expand Down
89 changes: 49 additions & 40 deletions mock/department/index.mock.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { toAnyString } from '@/utils'
import { faker } from '@faker-js/faker'
import Mock from 'mockjs'
import { SUCCESS_CODE } from '@/constants'

const departmentList: any = []
Expand All @@ -11,64 +11,71 @@ for (let i = 0; i < 5; i++) {
// 部门名称
departmentName: citys[i],
id: toAnyString(),
createTime: faker.date.anytime(),
status: faker.number.int({ min: 0, max: 1 }),
createTime: '@datetime',
// 状态
status: Mock.Random.integer(0, 1),
// 备注
remark: faker.lorem.sentence(),
remark: '@cword(10, 15)',
children: [
{
// 部门名称
departmentName: '研发部',
createTime: faker.date.anytime(),
// 状态
status: faker.number.int({ min: 0, max: 1 }),
id: toAnyString(),
remark: faker.lorem.sentence()
createTime: '@datetime',
// 状态
status: Mock.Random.integer(0, 1),
// 备注
remark: '@cword(10, 15)'
},
{
// 部门名称
departmentName: '产品部',
createTime: faker.date.anytime(),
// 状态
status: faker.number.int({ min: 0, max: 1 }),
id: toAnyString(),
remark: faker.lorem.sentence()
createTime: '@datetime',
// 状态
status: Mock.Random.integer(0, 1),
// 备注
remark: '@cword(10, 15)'
},
{
// 部门名称
departmentName: '运营部',
createTime: faker.date.anytime(),
// 状态
status: faker.number.int({ min: 0, max: 1 }),
id: toAnyString(),
remark: faker.lorem.sentence()
createTime: '@datetime',
// 状态
status: Mock.Random.integer(0, 1),
// 备注
remark: '@cword(10, 15)'
},
{
// 部门名称
departmentName: '市场部',
createTime: faker.date.anytime(),
// 状态
status: faker.number.int({ min: 0, max: 1 }),
id: toAnyString(),
remark: faker.lorem.sentence()
createTime: '@datetime',
// 状态
status: Mock.Random.integer(0, 1),
// 备注
remark: '@cword(10, 15)'
},
{
// 部门名称
departmentName: '销售部',
createTime: faker.date.anytime(),
// 状态
status: faker.number.int({ min: 0, max: 1 }),
id: toAnyString(),
remark: faker.lorem.sentence()
createTime: '@datetime',
// 状态
status: Mock.Random.integer(0, 1),
// 备注
remark: '@cword(10, 15)'
},
{
// 部门名称
departmentName: '客服部',
createTime: faker.date.anytime(),
// 状态
status: faker.number.int({ min: 0, max: 1 }),
id: toAnyString(),
remark: faker.lorem.sentence()
createTime: '@datetime',
// 状态
status: Mock.Random.integer(0, 1),
// 备注
remark: '@cword(10, 15)'
}
]
})
Expand Down Expand Up @@ -110,18 +117,20 @@ export default [
// 根据pageSize来创建数据
const mockList: any = []
for (let i = 0; i < pageSize; i++) {
mockList.push({
// 用户名
username: faker.person.firstName(),
// 账号
account: faker.person.lastName(),
// 邮箱
email: faker.internet.email(),
// 创建时间
createTime: faker.date.anytime(),
// 用户id
id: toAnyString()
})
mockList.push(
Mock.mock({
// 用户名
username: '@cname',
// 账号
account: '@first',
// 邮箱
email: '@EMAIL',
// 创建时间
createTime: '@datetime',
// 用户id
id: toAnyString()
})
)
}
return {
code: SUCCESS_CODE,
Expand Down
36 changes: 18 additions & 18 deletions mock/menu/index.mock.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { faker } from '@faker-js/faker'
import Mock from 'mockjs'
import { SUCCESS_CODE } from '@/constants'

const timeout = 1000
Expand All @@ -19,7 +19,7 @@ export default [
component: '#',
redirect: '/dashboard/analysis',
name: 'Dashboard',
status: faker.number.int({ min: 0, max: 1 }),
status: Mock.Random.integer(0, 1),
id: 1,
type: 0,
parentId: undefined,
Expand All @@ -34,7 +34,7 @@ export default [
path: 'analysis',
component: 'views/Dashboard/Analysis',
name: 'Analysis',
status: faker.number.int({ min: 0, max: 1 }),
status: Mock.Random.integer(0, 1),
id: 2,
type: 1,
parentId: 1,
Expand All @@ -59,7 +59,7 @@ export default [
path: 'workplace',
component: 'views/Dashboard/Workplace',
name: 'Workplace',
status: faker.number.int({ min: 0, max: 1 }),
status: Mock.Random.integer(0, 1),
id: 3,
type: 1,
parentId: 1,
Expand Down Expand Up @@ -93,7 +93,7 @@ export default [
icon: 'clarity:document-solid'
},
name: 'ExternalLink',
status: faker.number.int({ min: 0, max: 1 }),
status: Mock.Random.integer(0, 1),
id: 4,
type: 0,
parentId: undefined,
Expand All @@ -102,7 +102,7 @@ export default [
{
path: 'https://element-plus-admin-doc.cn/',
name: 'DocumentLink',
status: faker.number.int({ min: 0, max: 1 }),
status: Mock.Random.integer(0, 1),
id: 5,
type: 1,
parentId: 4,
Expand All @@ -118,7 +118,7 @@ export default [
component: '#',
redirect: '/level/menu1/menu1-1/menu1-1-1',
name: 'Level',
status: faker.number.int({ min: 0, max: 1 }),
status: Mock.Random.integer(0, 1),
id: 6,
type: 0,
parentId: undefined,
Expand All @@ -132,7 +132,7 @@ export default [
path: 'menu1',
name: 'Menu1',
component: '##',
status: faker.number.int({ min: 0, max: 1 }),
status: Mock.Random.integer(0, 1),
id: 7,
type: 0,
parentId: 6,
Expand All @@ -146,7 +146,7 @@ export default [
path: 'menu1-1',
name: 'Menu11',
component: '##',
status: faker.number.int({ min: 0, max: 1 }),
status: Mock.Random.integer(0, 1),
id: 8,
type: 0,
parentId: 7,
Expand All @@ -161,7 +161,7 @@ export default [
path: 'menu1-1-1',
name: 'Menu111',
component: 'views/Level/Menu111',
status: faker.number.int({ min: 0, max: 1 }),
status: Mock.Random.integer(0, 1),
id: 9,
type: 1,
parentId: 8,
Expand All @@ -176,7 +176,7 @@ export default [
path: 'menu1-2',
name: 'Menu12',
component: 'views/Level/Menu12',
status: faker.number.int({ min: 0, max: 1 }),
status: Mock.Random.integer(0, 1),
id: 10,
type: 1,
parentId: 7,
Expand All @@ -191,7 +191,7 @@ export default [
path: 'menu2',
name: 'Menu2Demo',
component: 'views/Level/Menu2',
status: faker.number.int({ min: 0, max: 1 }),
status: Mock.Random.integer(0, 1),
id: 11,
type: 1,
parentId: 6,
Expand All @@ -207,7 +207,7 @@ export default [
component: '#',
redirect: '/example/example-dialog',
name: 'Example',
status: faker.number.int({ min: 0, max: 1 }),
status: Mock.Random.integer(0, 1),
id: 12,
type: 0,
parentId: undefined,
Expand All @@ -222,7 +222,7 @@ export default [
path: 'example-dialog',
component: 'views/Example/Dialog/ExampleDialog',
name: 'ExampleDialog',
status: faker.number.int({ min: 0, max: 1 }),
status: Mock.Random.integer(0, 1),
id: 13,
type: 1,
parentId: 12,
Expand Down Expand Up @@ -253,7 +253,7 @@ export default [
path: 'example-page',
component: 'views/Example/Page/ExamplePage',
name: 'ExamplePage',
status: faker.number.int({ min: 0, max: 1 }),
status: Mock.Random.integer(0, 1),
id: 14,
type: 1,
parentId: 12,
Expand Down Expand Up @@ -284,7 +284,7 @@ export default [
path: 'example-add',
component: 'views/Example/Page/ExampleAdd',
name: 'ExampleAdd',
status: faker.number.int({ min: 0, max: 1 }),
status: Mock.Random.integer(0, 1),
id: 15,
type: 1,
parentId: 12,
Expand All @@ -302,7 +302,7 @@ export default [
path: 'example-edit',
component: 'views/Example/Page/ExampleEdit',
name: 'ExampleEdit',
status: faker.number.int({ min: 0, max: 1 }),
status: Mock.Random.integer(0, 1),
id: 16,
type: 1,
parentId: 12,
Expand All @@ -320,7 +320,7 @@ export default [
path: 'example-detail',
component: 'views/Example/Page/ExampleDetail',
name: 'ExampleDetail',
status: faker.number.int({ min: 0, max: 1 }),
status: Mock.Random.integer(0, 1),
id: 17,
type: 1,
parentId: 12,
Expand Down
Loading

0 comments on commit 83de387

Please sign in to comment.