feat: 替换mockjs

This commit is contained in:
kailong321200875 2023-11-29 16:14:48 +08:00
parent b8f9a9940d
commit 7c76d945be
9 changed files with 249 additions and 207 deletions

View File

@ -1,7 +1,7 @@
import config from '@/config/axios/config' import config from '@/config/axios/config'
import { toAnyString } from '@/utils' import { toAnyString } from '@/utils'
import Mock from 'mockjs' import { faker } from '@faker-js/faker'
const { code } = config const { code } = config
@ -14,65 +14,64 @@ for (let i = 0; i < 5; i++) {
// 部门名称 // 部门名称
departmentName: citys[i], departmentName: citys[i],
id: toAnyString(), id: toAnyString(),
createTime: '@datetime', createTime: faker.date.anytime(),
// 状态 status: faker.number.int({ min: 0, max: 1 }),
status: Mock.Random.integer(0, 1),
// 备注 // 备注
remark: '@cword(10, 15)', remark: faker.lorem.sentence(),
children: [ children: [
{ {
// 部门名称 // 部门名称
departmentName: '研发部', departmentName: '研发部',
createTime: '@datetime', createTime: faker.date.anytime(),
// 状态 // 状态
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: toAnyString(), id: toAnyString(),
remark: '@cword(10, 15)' remark: faker.lorem.sentence()
}, },
{ {
// 部门名称 // 部门名称
departmentName: '产品部', departmentName: '产品部',
createTime: '@datetime', createTime: faker.date.anytime(),
// 状态 // 状态
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: toAnyString(), id: toAnyString(),
remark: '@cword(10, 15)' remark: faker.lorem.sentence()
}, },
{ {
// 部门名称 // 部门名称
departmentName: '运营部', departmentName: '运营部',
createTime: '@datetime', createTime: faker.date.anytime(),
// 状态 // 状态
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: toAnyString(), id: toAnyString(),
remark: '@cword(10, 15)' remark: faker.lorem.sentence()
}, },
{ {
// 部门名称 // 部门名称
departmentName: '市场部', departmentName: '市场部',
createTime: '@datetime', createTime: faker.date.anytime(),
// 状态 // 状态
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: toAnyString(), id: toAnyString(),
remark: '@cword(10, 15)' remark: faker.lorem.sentence()
}, },
{ {
// 部门名称 // 部门名称
departmentName: '销售部', departmentName: '销售部',
createTime: '@datetime', createTime: faker.date.anytime(),
// 状态 // 状态
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: toAnyString(), id: toAnyString(),
remark: '@cword(10, 15)' remark: faker.lorem.sentence()
}, },
{ {
// 部门名称 // 部门名称
departmentName: '客服部', departmentName: '客服部',
createTime: '@datetime', createTime: faker.date.anytime(),
// 状态 // 状态
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: toAnyString(), id: toAnyString(),
remark: '@cword(10, 15)' remark: faker.lorem.sentence()
} }
] ]
}) })
@ -114,20 +113,18 @@ export default [
// 根据pageSize来创建数据 // 根据pageSize来创建数据
const mockList: any = [] const mockList: any = []
for (let i = 0; i < pageSize; i++) { for (let i = 0; i < pageSize; i++) {
mockList.push( mockList.push({
Mock.mock({ // 用户名
// 用户名 username: faker.person.firstName(),
username: '@cname', // 账号
// 账号 account: faker.person.lastName(),
account: '@first', // 邮箱
// 邮箱 email: faker.internet.email(),
email: '@EMAIL', // 创建时间
// 创建时间 createTime: faker.date.anytime(),
createTime: '@datetime', // 用户id
// 用户id id: toAnyString()
id: toAnyString() })
})
)
} }
return { return {
code: code, code: code,

View File

@ -1,6 +1,5 @@
import config from '@/config/axios/config' import config from '@/config/axios/config'
import { faker } from '@faker-js/faker'
import Mock from 'mockjs'
const { code } = config const { code } = config
@ -22,7 +21,7 @@ export default [
component: '#', component: '#',
redirect: '/dashboard/analysis', redirect: '/dashboard/analysis',
name: 'Dashboard', name: 'Dashboard',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 1, id: 1,
type: 0, type: 0,
parentId: undefined, parentId: undefined,
@ -37,7 +36,7 @@ export default [
path: 'analysis', path: 'analysis',
component: 'views/Dashboard/Analysis', component: 'views/Dashboard/Analysis',
name: 'Analysis', name: 'Analysis',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 2, id: 2,
type: 1, type: 1,
parentId: 1, parentId: 1,
@ -62,7 +61,7 @@ export default [
path: 'workplace', path: 'workplace',
component: 'views/Dashboard/Workplace', component: 'views/Dashboard/Workplace',
name: 'Workplace', name: 'Workplace',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 3, id: 3,
type: 1, type: 1,
parentId: 1, parentId: 1,
@ -96,7 +95,7 @@ export default [
icon: 'clarity:document-solid' icon: 'clarity:document-solid'
}, },
name: 'ExternalLink', name: 'ExternalLink',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 4, id: 4,
type: 0, type: 0,
parentId: undefined, parentId: undefined,
@ -105,7 +104,7 @@ export default [
{ {
path: 'https://element-plus-admin-doc.cn/', path: 'https://element-plus-admin-doc.cn/',
name: 'DocumentLink', name: 'DocumentLink',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 5, id: 5,
type: 1, type: 1,
parentId: 4, parentId: 4,
@ -121,7 +120,7 @@ export default [
component: '#', component: '#',
redirect: '/level/menu1/menu1-1/menu1-1-1', redirect: '/level/menu1/menu1-1/menu1-1-1',
name: 'Level', name: 'Level',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 6, id: 6,
type: 0, type: 0,
parentId: undefined, parentId: undefined,
@ -135,7 +134,7 @@ export default [
path: 'menu1', path: 'menu1',
name: 'Menu1', name: 'Menu1',
component: '##', component: '##',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 7, id: 7,
type: 0, type: 0,
parentId: 6, parentId: 6,
@ -149,7 +148,7 @@ export default [
path: 'menu1-1', path: 'menu1-1',
name: 'Menu11', name: 'Menu11',
component: '##', component: '##',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 8, id: 8,
type: 0, type: 0,
parentId: 7, parentId: 7,
@ -164,7 +163,7 @@ export default [
path: 'menu1-1-1', path: 'menu1-1-1',
name: 'Menu111', name: 'Menu111',
component: 'views/Level/Menu111', component: 'views/Level/Menu111',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 9, id: 9,
type: 1, type: 1,
parentId: 8, parentId: 8,
@ -179,7 +178,7 @@ export default [
path: 'menu1-2', path: 'menu1-2',
name: 'Menu12', name: 'Menu12',
component: 'views/Level/Menu12', component: 'views/Level/Menu12',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 10, id: 10,
type: 1, type: 1,
parentId: 7, parentId: 7,
@ -194,7 +193,7 @@ export default [
path: 'menu2', path: 'menu2',
name: 'Menu2Demo', name: 'Menu2Demo',
component: 'views/Level/Menu2', component: 'views/Level/Menu2',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 11, id: 11,
type: 1, type: 1,
parentId: 6, parentId: 6,
@ -210,7 +209,7 @@ export default [
component: '#', component: '#',
redirect: '/example/example-dialog', redirect: '/example/example-dialog',
name: 'Example', name: 'Example',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 12, id: 12,
type: 0, type: 0,
parentId: undefined, parentId: undefined,
@ -225,7 +224,7 @@ export default [
path: 'example-dialog', path: 'example-dialog',
component: 'views/Example/Dialog/ExampleDialog', component: 'views/Example/Dialog/ExampleDialog',
name: 'ExampleDialog', name: 'ExampleDialog',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 13, id: 13,
type: 1, type: 1,
parentId: 12, parentId: 12,
@ -256,7 +255,7 @@ export default [
path: 'example-page', path: 'example-page',
component: 'views/Example/Page/ExamplePage', component: 'views/Example/Page/ExamplePage',
name: 'ExamplePage', name: 'ExamplePage',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 14, id: 14,
type: 1, type: 1,
parentId: 12, parentId: 12,
@ -287,7 +286,7 @@ export default [
path: 'example-add', path: 'example-add',
component: 'views/Example/Page/ExampleAdd', component: 'views/Example/Page/ExampleAdd',
name: 'ExampleAdd', name: 'ExampleAdd',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 15, id: 15,
type: 1, type: 1,
parentId: 12, parentId: 12,
@ -305,7 +304,7 @@ export default [
path: 'example-edit', path: 'example-edit',
component: 'views/Example/Page/ExampleEdit', component: 'views/Example/Page/ExampleEdit',
name: 'ExampleEdit', name: 'ExampleEdit',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 16, id: 16,
type: 1, type: 1,
parentId: 12, parentId: 12,
@ -323,7 +322,7 @@ export default [
path: 'example-detail', path: 'example-detail',
component: 'views/Example/Page/ExampleDetail', component: 'views/Example/Page/ExampleDetail',
name: 'ExampleDetail', name: 'ExampleDetail',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 17, id: 17,
type: 1, type: 1,
parentId: 12, parentId: 12,

View File

@ -1,6 +1,6 @@
import config from '@/config/axios/config' import config from '@/config/axios/config'
import { faker } from '@faker-js/faker'
import Mock from 'mockjs'
import { toAnyString } from '@/utils' import { toAnyString } from '@/utils'
const { code } = config const { code } = config
@ -723,7 +723,7 @@ const menus = [
component: '#', component: '#',
redirect: '/dashboard/analysis', redirect: '/dashboard/analysis',
name: 'Dashboard', name: 'Dashboard',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 1, id: 1,
meta: { meta: {
title: '首页', title: '首页',
@ -735,7 +735,7 @@ const menus = [
path: 'analysis', path: 'analysis',
component: 'views/Dashboard/Analysis', component: 'views/Dashboard/Analysis',
name: 'Analysis', name: 'Analysis',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 2, id: 2,
meta: { meta: {
title: '分析页', title: '分析页',
@ -746,7 +746,7 @@ const menus = [
path: 'workplace', path: 'workplace',
component: 'views/Dashboard/Workplace', component: 'views/Dashboard/Workplace',
name: 'Workplace', name: 'Workplace',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 3, id: 3,
meta: { meta: {
title: '工作台', title: '工作台',
@ -763,13 +763,13 @@ const menus = [
icon: 'clarity:document-solid' icon: 'clarity:document-solid'
}, },
name: 'ExternalLink', name: 'ExternalLink',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 4, id: 4,
children: [ children: [
{ {
path: 'https://element-plus-admin-doc.cn/', path: 'https://element-plus-admin-doc.cn/',
name: 'DocumentLink', name: 'DocumentLink',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 5, id: 5,
meta: { meta: {
title: '文档' title: '文档'
@ -782,7 +782,7 @@ const menus = [
component: '#', component: '#',
redirect: '/level/menu1/menu1-1/menu1-1-1', redirect: '/level/menu1/menu1-1/menu1-1-1',
name: 'Level', name: 'Level',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 6, id: 6,
meta: { meta: {
title: '菜单', title: '菜单',
@ -793,7 +793,7 @@ const menus = [
path: 'menu1', path: 'menu1',
name: 'Menu1', name: 'Menu1',
component: '##', component: '##',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 7, id: 7,
redirect: '/level/menu1/menu1-1/menu1-1-1', redirect: '/level/menu1/menu1-1/menu1-1-1',
meta: { meta: {
@ -804,7 +804,7 @@ const menus = [
path: 'menu1-1', path: 'menu1-1',
name: 'Menu11', name: 'Menu11',
component: '##', component: '##',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 8, id: 8,
redirect: '/level/menu1/menu1-1/menu1-1-1', redirect: '/level/menu1/menu1-1/menu1-1-1',
meta: { meta: {
@ -816,7 +816,7 @@ const menus = [
path: 'menu1-1-1', path: 'menu1-1-1',
name: 'Menu111', name: 'Menu111',
component: 'views/Level/Menu111', component: 'views/Level/Menu111',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 9, id: 9,
permission: ['edit', 'add', 'delete'], permission: ['edit', 'add', 'delete'],
meta: { meta: {
@ -830,7 +830,7 @@ const menus = [
path: 'menu1-2', path: 'menu1-2',
name: 'Menu12', name: 'Menu12',
component: 'views/Level/Menu12', component: 'views/Level/Menu12',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 10, id: 10,
permission: ['edit', 'add', 'delete'], permission: ['edit', 'add', 'delete'],
meta: { meta: {
@ -844,7 +844,7 @@ const menus = [
path: 'menu2', path: 'menu2',
name: 'Menu2Demo', name: 'Menu2Demo',
component: 'views/Level/Menu2', component: 'views/Level/Menu2',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 11, id: 11,
permission: ['edit', 'add', 'delete'], permission: ['edit', 'add', 'delete'],
meta: { meta: {
@ -859,7 +859,7 @@ const menus = [
component: '#', component: '#',
redirect: '/example/example-dialog', redirect: '/example/example-dialog',
name: 'Example', name: 'Example',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 12, id: 12,
meta: { meta: {
title: '综合示例', title: '综合示例',
@ -871,7 +871,7 @@ const menus = [
path: 'example-dialog', path: 'example-dialog',
component: 'views/Example/Dialog/ExampleDialog', component: 'views/Example/Dialog/ExampleDialog',
name: 'ExampleDialog', name: 'ExampleDialog',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 13, id: 13,
permission: ['edit', 'add', 'delete'], permission: ['edit', 'add', 'delete'],
meta: { meta: {
@ -883,7 +883,7 @@ const menus = [
path: 'example-page', path: 'example-page',
component: 'views/Example/Page/ExamplePage', component: 'views/Example/Page/ExamplePage',
name: 'ExamplePage', name: 'ExamplePage',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 14, id: 14,
permission: ['edit', 'add', 'delete'], permission: ['edit', 'add', 'delete'],
meta: { meta: {
@ -895,7 +895,7 @@ const menus = [
path: 'example-add', path: 'example-add',
component: 'views/Example/Page/ExampleAdd', component: 'views/Example/Page/ExampleAdd',
name: 'ExampleAdd', name: 'ExampleAdd',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 15, id: 15,
permission: ['edit', 'add', 'delete'], permission: ['edit', 'add', 'delete'],
meta: { meta: {
@ -912,7 +912,7 @@ const menus = [
path: 'example-edit', path: 'example-edit',
component: 'views/Example/Page/ExampleEdit', component: 'views/Example/Page/ExampleEdit',
name: 'ExampleEdit', name: 'ExampleEdit',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 16, id: 16,
permission: ['edit', 'add', 'delete'], permission: ['edit', 'add', 'delete'],
meta: { meta: {
@ -929,7 +929,7 @@ const menus = [
path: 'example-detail', path: 'example-detail',
component: 'views/Example/Page/ExampleDetail', component: 'views/Example/Page/ExampleDetail',
name: 'ExampleDetail', name: 'ExampleDetail',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 17, id: 17,
permission: ['edit', 'add', 'delete'], permission: ['edit', 'add', 'delete'],
meta: { meta: {
@ -951,7 +951,7 @@ const menus = [
component: '#', component: '#',
redirect: '/dashboard/analysis', redirect: '/dashboard/analysis',
name: 'Dashboard', name: 'Dashboard',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 1, id: 1,
meta: { meta: {
title: '首页', title: '首页',
@ -963,7 +963,7 @@ const menus = [
path: 'analysis', path: 'analysis',
component: 'views/Dashboard/Analysis', component: 'views/Dashboard/Analysis',
name: 'Analysis', name: 'Analysis',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 2, id: 2,
meta: { meta: {
title: '分析页', title: '分析页',
@ -974,7 +974,7 @@ const menus = [
path: 'workplace', path: 'workplace',
component: 'views/Dashboard/Workplace', component: 'views/Dashboard/Workplace',
name: 'Workplace', name: 'Workplace',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 3, id: 3,
meta: { meta: {
title: '工作台', title: '工作台',
@ -993,13 +993,13 @@ const menus = [
icon: 'clarity:document-solid' icon: 'clarity:document-solid'
}, },
name: 'ExternalLink', name: 'ExternalLink',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 4, id: 4,
children: [ children: [
{ {
path: 'https://element-plus-admin-doc.cn/', path: 'https://element-plus-admin-doc.cn/',
name: 'DocumentLink', name: 'DocumentLink',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 5, id: 5,
meta: { meta: {
title: '文档' title: '文档'
@ -1012,7 +1012,7 @@ const menus = [
component: '#', component: '#',
redirect: '/level/menu1/menu1-1/menu1-1-1', redirect: '/level/menu1/menu1-1/menu1-1-1',
name: 'Level', name: 'Level',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 6, id: 6,
meta: { meta: {
title: '菜单', title: '菜单',
@ -1023,7 +1023,7 @@ const menus = [
path: 'menu1', path: 'menu1',
name: 'Menu1', name: 'Menu1',
component: '##', component: '##',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 7, id: 7,
redirect: '/level/menu1/menu1-1/menu1-1-1', redirect: '/level/menu1/menu1-1/menu1-1-1',
meta: { meta: {
@ -1034,7 +1034,7 @@ const menus = [
path: 'menu1-1', path: 'menu1-1',
name: 'Menu11', name: 'Menu11',
component: '##', component: '##',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 8, id: 8,
redirect: '/level/menu1/menu1-1/menu1-1-1', redirect: '/level/menu1/menu1-1/menu1-1-1',
meta: { meta: {
@ -1046,7 +1046,7 @@ const menus = [
path: 'menu1-1-1', path: 'menu1-1-1',
name: 'Menu111', name: 'Menu111',
component: 'views/Level/Menu111', component: 'views/Level/Menu111',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 9, id: 9,
permission: ['edit', 'add', 'delete'], permission: ['edit', 'add', 'delete'],
meta: { meta: {
@ -1060,7 +1060,7 @@ const menus = [
path: 'menu1-2', path: 'menu1-2',
name: 'Menu12', name: 'Menu12',
component: 'views/Level/Menu12', component: 'views/Level/Menu12',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 10, id: 10,
permission: ['edit', 'add', 'delete'], permission: ['edit', 'add', 'delete'],
meta: { meta: {
@ -1074,7 +1074,7 @@ const menus = [
path: 'menu2', path: 'menu2',
name: 'Menu2Demo', name: 'Menu2Demo',
component: 'views/Level/Menu2', component: 'views/Level/Menu2',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 11, id: 11,
permission: ['edit', 'add', 'delete'], permission: ['edit', 'add', 'delete'],
meta: { meta: {
@ -1091,7 +1091,7 @@ const menus = [
component: '#', component: '#',
redirect: '/example/example-dialog', redirect: '/example/example-dialog',
name: 'Example', name: 'Example',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 12, id: 12,
meta: { meta: {
title: '综合示例', title: '综合示例',
@ -1103,7 +1103,7 @@ const menus = [
path: 'example-detail', path: 'example-detail',
component: 'views/Example/Page/ExampleDetail', component: 'views/Example/Page/ExampleDetail',
name: 'ExampleDetail', name: 'ExampleDetail',
status: Mock.Random.integer(0, 1), status: faker.number.int({ min: 0, max: 1 }),
id: 17, id: 17,
permission: ['edit', 'add', 'delete'], permission: ['edit', 'add', 'delete'],
meta: { meta: {
@ -1122,18 +1122,16 @@ const menus = [
] ]
for (let i = 0; i < 4; i++) { for (let i = 0; i < 4; i++) {
List.push( List.push({
Mock.mock({ id: toAnyString(),
id: toAnyString(), // timestamp: +Mock.Random.date('T'),
// timestamp: +Mock.Random.date('T'), roleName: roleNames[i],
roleName: roleNames[i], role: faker.lorem.sentence(1),
role: '@first', status: faker.number.int({ min: 0, max: 1 }),
status: Mock.Random.integer(0, 1), createTime: faker.date.anytime(),
createTime: '@datetime', remark: faker.lorem.sentence(),
remark: '@cword(10, 15)', menu: menus[i]
menu: menus[i] })
})
)
} }
export default [ export default [

View File

@ -1,7 +1,7 @@
import config from '@/config/axios/config' import config from '@/config/axios/config'
import { faker } from '@faker-js/faker'
import { toAnyString } from '@/utils' import { toAnyString } from '@/utils'
import Mock from 'mockjs'
const { code } = config const { code } = config
@ -18,9 +18,10 @@ interface ListProps {
title: string title: string
content: string content: string
importance: number importance: number
display_time: string display_time: any
pageviews: number pageviews: number
image_uri: string image_uri: string
video_uri?: string
} }
interface TreeListProps { interface TreeListProps {
@ -29,111 +30,154 @@ interface TreeListProps {
title: string title: string
content: string content: string
importance: number importance: number
display_time: string display_time: any
image_uri: string
pageviews: number pageviews: number
children: TreeListProps[] video_uri?: string
children?: TreeListProps[]
} }
let List: ListProps[] = [] let List: ListProps[] = []
for (let i = 0; i < count; i++) { for (let i = 0; i < count; i++) {
List.push( List.push({
Mock.mock({ id: toAnyString(),
id: toAnyString(), // timestamp: +Mock.Random.date('T'),
// timestamp: +Mock.Random.date('T'), author: faker.person.firstName(),
author: '@first', title: faker.lorem.sentence(),
title: '@title(5, 10)', content: baseContent,
content: baseContent, importance: faker.number.int({ min: 1, max: 3 }),
importance: '@integer(1, 3)', display_time: faker.date.anytime(),
display_time: '@datetime', pageviews: faker.number.int({ min: 300, max: 5000 }),
pageviews: '@integer(100, 500)', image_uri: faker.image.url({
image_uri: Mock.Random.image('@integer(100, 500)x@integer(100, 500)'), width: faker.number.int({ min: 200, max: 400 }),
video_uri: height: faker.number.int({ min: 200, max: 400 })
'//sf1-cdn-tos.huoshanstatic.com/obj/media-fe/xgplayer_doc_video/mp4/xgplayer-demo-720p.mp4' }),
}) video_uri:
) '//sf1-cdn-tos.huoshanstatic.com/obj/media-fe/xgplayer_doc_video/mp4/xgplayer-demo-720p.mp4'
})
} }
const treeList: TreeListProps[] = [] const treeList: TreeListProps[] = []
for (let i = 0; i < count; i++) { for (let i = 0; i < count; i++) {
treeList.push( treeList.push({
Mock.mock({ id: toAnyString(),
id: toAnyString(), // timestamp: +Mock.Random.date('T'),
// timestamp: +Mock.Random.date('T'), author: faker.person.firstName(),
author: '@first', title: faker.lorem.sentence(),
title: '@title(5, 10)', content: baseContent,
content: baseContent, importance: faker.number.int({ min: 1, max: 3 }),
importance: '@integer(1, 3)', display_time: faker.date.anytime(),
display_time: '@datetime', pageviews: faker.number.int({ min: 300, max: 5000 }),
pageviews: '@integer(300, 5000)', image_uri: faker.image.url({
children: [ width: faker.number.int({ min: 200, max: 400 }),
{ height: faker.number.int({ min: 200, max: 400 })
id: toAnyString(), }),
// timestamp: +Mock.Random.date('T'), video_uri:
author: '@first', '//sf1-cdn-tos.huoshanstatic.com/obj/media-fe/xgplayer_doc_video/mp4/xgplayer-demo-720p.mp4',
title: '@title(5, 10)', children: [
content: baseContent, {
importance: '@integer(1, 3)', id: toAnyString(),
display_time: '@datetime', // timestamp: +Mock.Random.date('T'),
pageviews: '@integer(300, 5000)', author: faker.person.firstName(),
children: [ title: faker.lorem.sentence(),
{ content: baseContent,
id: toAnyString(), importance: faker.number.int({ min: 1, max: 3 }),
// timestamp: +Mock.Random.date('T'), display_time: faker.date.anytime(),
author: '@first', pageviews: faker.number.int({ min: 300, max: 5000 }),
title: '@title(5, 10)', image_uri: faker.image.url({
content: baseContent, width: faker.number.int({ min: 200, max: 400 }),
importance: '@integer(1, 3)', height: faker.number.int({ min: 200, max: 400 })
display_time: '@datetime', }),
pageviews: '@integer(300, 5000)' video_uri:
}, '//sf1-cdn-tos.huoshanstatic.com/obj/media-fe/xgplayer_doc_video/mp4/xgplayer-demo-720p.mp4',
{ children: [
id: toAnyString(), {
// timestamp: +Mock.Random.date('T'), id: toAnyString(),
author: '@first', // timestamp: +Mock.Random.date('T'),
title: '@title(5, 10)', author: faker.person.firstName(),
content: baseContent, title: faker.lorem.sentence(),
importance: '@integer(1, 3)', content: baseContent,
display_time: '@datetime', importance: faker.number.int({ min: 1, max: 3 }),
pageviews: '@integer(300, 5000)' display_time: faker.date.anytime(),
} pageviews: faker.number.int({ min: 300, max: 5000 }),
] image_uri: faker.image.url({
}, width: faker.number.int({ min: 200, max: 400 }),
{ height: faker.number.int({ min: 200, max: 400 })
id: toAnyString(), }),
// timestamp: +Mock.Random.date('T'), video_uri:
author: '@first', '//sf1-cdn-tos.huoshanstatic.com/obj/media-fe/xgplayer_doc_video/mp4/xgplayer-demo-720p.mp4'
title: '@title(5, 10)', },
content: baseContent, {
importance: '@integer(1, 3)', id: toAnyString(),
display_time: '@datetime', // timestamp: +Mock.Random.date('T'),
pageviews: '@integer(300, 5000)' author: faker.person.firstName(),
}, title: faker.lorem.sentence(),
{ content: baseContent,
id: toAnyString(), importance: faker.number.int({ min: 1, max: 3 }),
// timestamp: +Mock.Random.date('T'), display_time: faker.date.anytime(),
author: '@first', pageviews: faker.number.int({ min: 300, max: 5000 }),
title: '@title(5, 10)', image_uri: faker.image.url({
content: baseContent, width: faker.number.int({ min: 200, max: 400 }),
importance: '@integer(1, 3)', height: faker.number.int({ min: 200, max: 400 })
display_time: '@datetime', }),
pageviews: '@integer(300, 5000)' video_uri:
}, '//sf1-cdn-tos.huoshanstatic.com/obj/media-fe/xgplayer_doc_video/mp4/xgplayer-demo-720p.mp4'
{ }
id: toAnyString(), ]
// timestamp: +Mock.Random.date('T'), },
author: '@first', {
title: '@title(5, 10)', id: toAnyString(),
content: baseContent, // timestamp: +Mock.Random.date('T'),
importance: '@integer(1, 3)', author: faker.person.firstName(),
display_time: '@datetime', title: faker.lorem.sentence(),
pageviews: '@integer(300, 5000)' content: baseContent,
} importance: faker.number.int({ min: 1, max: 3 }),
] display_time: faker.date.anytime(),
// image_uri pageviews: faker.number.int({ min: 300, max: 5000 }),
}) image_uri: faker.image.url({
) width: faker.number.int({ min: 200, max: 400 }),
height: faker.number.int({ min: 200, max: 400 })
}),
video_uri:
'//sf1-cdn-tos.huoshanstatic.com/obj/media-fe/xgplayer_doc_video/mp4/xgplayer-demo-720p.mp4'
},
{
id: toAnyString(),
// timestamp: +Mock.Random.date('T'),
author: faker.person.firstName(),
title: faker.lorem.sentence(),
content: baseContent,
importance: faker.number.int({ min: 1, max: 3 }),
display_time: faker.date.anytime(),
pageviews: faker.number.int({ min: 300, max: 5000 }),
image_uri: faker.image.url({
width: faker.number.int({ min: 200, max: 400 }),
height: faker.number.int({ min: 200, max: 400 })
}),
video_uri:
'//sf1-cdn-tos.huoshanstatic.com/obj/media-fe/xgplayer_doc_video/mp4/xgplayer-demo-720p.mp4'
},
{
id: toAnyString(),
// timestamp: +Mock.Random.date('T'),
author: faker.person.firstName(),
title: faker.lorem.sentence(),
content: baseContent,
importance: faker.number.int({ min: 1, max: 3 }),
display_time: faker.date.anytime(),
pageviews: faker.number.int({ min: 300, max: 5000 }),
image_uri: faker.image.url({
width: faker.number.int({ min: 200, max: 400 }),
height: faker.number.int({ min: 200, max: 400 })
}),
video_uri:
'//sf1-cdn-tos.huoshanstatic.com/obj/media-fe/xgplayer_doc_video/mp4/xgplayer-demo-720p.mp4'
}
]
// image_uri
})
} }
export default [ export default [

View File

@ -43,7 +43,6 @@
"element-plus": "^2.4.3", "element-plus": "^2.4.3",
"lodash-es": "^4.17.21", "lodash-es": "^4.17.21",
"mitt": "^3.0.1", "mitt": "^3.0.1",
"mockjs": "^1.1.0",
"nprogress": "^0.2.0", "nprogress": "^0.2.0",
"pinia": "^2.1.7", "pinia": "^2.1.7",
"pinia-plugin-persist": "^1.0.0", "pinia-plugin-persist": "^1.0.0",
@ -60,6 +59,7 @@
"devDependencies": { "devDependencies": {
"@commitlint/cli": "^18.4.3", "@commitlint/cli": "^18.4.3",
"@commitlint/config-conventional": "^18.4.3", "@commitlint/config-conventional": "^18.4.3",
"@faker-js/faker": "^8.3.1",
"@iconify/json": "^2.2.149", "@iconify/json": "^2.2.149",
"@intlify/unplugin-vue-i18n": "^1.5.0", "@intlify/unplugin-vue-i18n": "^1.5.0",
"@purge-icons/generated": "^0.10.0", "@purge-icons/generated": "^0.10.0",

View File

@ -6,6 +6,7 @@ import {
} from './types' } from './types'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import qs from 'qs' import qs from 'qs'
// import router from '@/router'
import { useStorage } from '@/hooks/web/useStorage' import { useStorage } from '@/hooks/web/useStorage'
@ -75,6 +76,7 @@ const defaultResponseInterceptors = (response: AxiosResponse<any>) => {
// token过期 // token过期
clear() clear()
window.location.reload() window.location.reload()
// router.push('/login')
} }
} }
} }

View File

@ -106,6 +106,9 @@ export const isDark = (): boolean => {
// 是否是图片链接 // 是否是图片链接
export const isImgPath = (path: string): boolean => { export const isImgPath = (path: string): boolean => {
if (path.includes('picsum.photos') || path.includes('loremflickr.com')) {
return true
}
return /(https?:\/\/|data:image\/).*?\.(png|jpg|jpeg|gif|svg|webp|ico)/gi.test(path) return /(https?:\/\/|data:image\/).*?\.(png|jpg|jpeg|gif|svg|webp|ico)/gi.test(path)
} }

View File

@ -2,7 +2,7 @@
import { Waterfall } from '@/components/Waterfall' import { Waterfall } from '@/components/Waterfall'
import { ContentWrap } from '@/components/ContentWrap' import { ContentWrap } from '@/components/ContentWrap'
import { useI18n } from '@/hooks/web/useI18n' import { useI18n } from '@/hooks/web/useI18n'
import Mock from 'mockjs' import { faker } from '@faker-js/faker'
import { ref, unref } from 'vue' import { ref, unref } from 'vue'
import { toAnyString } from '@/utils' import { toAnyString } from '@/utils'
@ -12,17 +12,17 @@ const getList = () => {
const list: any = [] const list: any = []
for (let i = 0; i < 20; i++) { for (let i = 0; i < 20; i++) {
// 100, 500 // 100, 500
const height = Mock.Random.integer(100, 500) const height = faker.number.int({ min: 100, max: 500 })
const width = Mock.Random.integer(100, 500) const width = faker.number.int({ min: 100, max: 500 })
list.push( list.push({
Mock.mock({ width,
height,
id: toAnyString(),
image_uri: faker.image.url({
width, width,
height, height
id: toAnyString(),
// httphttps
image_uri: Mock.Random.image(`${width}x${height}`).replace('http://', 'https://')
}) })
) })
} }
data.value = [...unref(data), ...list] data.value = [...unref(data), ...list]
if (unref(data).length >= 60) { if (unref(data).length >= 60) {

View File

@ -156,7 +156,6 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
'vue-json-pretty', 'vue-json-pretty',
'@zxcvbn-ts/core', '@zxcvbn-ts/core',
'dayjs', 'dayjs',
'mockjs',
'cropperjs' 'cropperjs'
] ]
} }