首次提交
This commit is contained in:
11
cdtestplant/src/mock/index.ts
Normal file
11
cdtestplant/src/mock/index.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import Mock from 'mockjs'
|
||||
|
||||
import './user'
|
||||
import './message-box'
|
||||
import './userAbout'
|
||||
|
||||
import '@/views/dashboard/workplace/mock'
|
||||
|
||||
Mock.setup({
|
||||
timeout: '600-1000',
|
||||
})
|
||||
82
cdtestplant/src/mock/message-box.ts
Normal file
82
cdtestplant/src/mock/message-box.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
import Mock from 'mockjs'
|
||||
import setupMock, { successResponseWrap } from '@/utils/setup-mock'
|
||||
|
||||
const haveReadIds: number[] = []
|
||||
const getMessageList = () => {
|
||||
return [
|
||||
{
|
||||
id: 1,
|
||||
type: 'message',
|
||||
title: '郑曦月',
|
||||
subTitle: '的私信',
|
||||
avatar: '//p1-arco.byteimg.com/tos-cn-i-uwbnlip3yd/8361eeb82904210b4f55fab888fe8416.png~tplv-uwbnlip3yd-webp.webp',
|
||||
content: '审批请求已发送,请查收',
|
||||
time: '今天 12:30:01',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
type: 'message',
|
||||
title: '宁波',
|
||||
subTitle: '的回复',
|
||||
avatar: '//p1-arco.byteimg.com/tos-cn-i-uwbnlip3yd/3ee5f13fb09879ecb5185e440cef6eb9.png~tplv-uwbnlip3yd-webp.webp',
|
||||
content: '此处 bug 已经修复',
|
||||
time: '今天 12:30:01',
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
type: 'message',
|
||||
title: '宁波',
|
||||
subTitle: '的回复',
|
||||
avatar: '//p1-arco.byteimg.com/tos-cn-i-uwbnlip3yd/3ee5f13fb09879ecb5185e440cef6eb9.png~tplv-uwbnlip3yd-webp.webp',
|
||||
content: '此处 bug 已经修复',
|
||||
time: '今天 12:20:01',
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
type: 'notice',
|
||||
title: '续费通知',
|
||||
subTitle: '',
|
||||
avatar: '',
|
||||
content: '您的产品使用期限即将截止,如需继续使用产品请前往购…',
|
||||
time: '今天 12:20:01',
|
||||
messageType: 3,
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
type: 'notice',
|
||||
title: '规则开通成功',
|
||||
subTitle: '',
|
||||
avatar: '',
|
||||
content: '内容屏蔽规则于 2021-12-01 开通成功并生效',
|
||||
time: '今天 12:20:01',
|
||||
messageType: 1,
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
type: 'todo',
|
||||
title: '质检队列变更',
|
||||
subTitle: '',
|
||||
avatar: '',
|
||||
content: '内容质检队列于 2021-12-01 19:50:23 进行变更,请重新…',
|
||||
time: '今天 12:20:01',
|
||||
messageType: 0,
|
||||
},
|
||||
].map((item) => ({
|
||||
...item,
|
||||
status: haveReadIds.indexOf(item.id) === -1 ? 0 : 1,
|
||||
}))
|
||||
}
|
||||
|
||||
setupMock({
|
||||
setup: () => {
|
||||
Mock.mock(new RegExp('/api/message/list'), () => {
|
||||
return successResponseWrap(getMessageList())
|
||||
})
|
||||
|
||||
Mock.mock(new RegExp('/api/message/read'), (params: { body: string }) => {
|
||||
const { ids } = JSON.parse(params.body)
|
||||
haveReadIds.push(...(ids || []))
|
||||
return successResponseWrap(true)
|
||||
})
|
||||
},
|
||||
})
|
||||
100
cdtestplant/src/mock/user.ts
Normal file
100
cdtestplant/src/mock/user.ts
Normal file
@@ -0,0 +1,100 @@
|
||||
import Mock from 'mockjs'
|
||||
import setupMock, { successResponseWrap, failResponseWrap } from '@/utils/setup-mock'
|
||||
|
||||
import { MockParams } from '@/types/mock'
|
||||
import { isLogin } from '@/utils/auth'
|
||||
|
||||
setupMock({
|
||||
setup() {
|
||||
// Mock.XHR.prototype.withCredentials = true;
|
||||
// 用户信息
|
||||
Mock.mock(new RegExp('/api/user/info'), () => {
|
||||
if (isLogin()) {
|
||||
const role = window.localStorage.getItem('userRole') || 'admin'
|
||||
return successResponseWrap({
|
||||
name: '王立群',
|
||||
avatar: '//lf1-xgcdn-tos.pstatp.com/obj/vcloud/vadmin/start.8e0e4855ee346a46ccff8ff3e24db27b.png',
|
||||
email: 'wangliqun@email.com',
|
||||
job: 'frontend',
|
||||
jobName: '前端艺术家',
|
||||
organization: 'Frontend',
|
||||
organizationName: '前端',
|
||||
location: 'beijing',
|
||||
locationName: '北京',
|
||||
introduction: '人潇洒,性温存',
|
||||
personalWebsite: 'https://www.arco.design',
|
||||
phone: '150****0000',
|
||||
registrationDate: '2013-05-10 12:10:00',
|
||||
accountId: '15012312300',
|
||||
certification: 1,
|
||||
role,
|
||||
})
|
||||
}
|
||||
return failResponseWrap(null, '未登录', 50008)
|
||||
})
|
||||
|
||||
// 登录
|
||||
Mock.mock(new RegExp('/api/user/login'), (params: MockParams) => {
|
||||
const { username, password } = JSON.parse(params.body)
|
||||
if (!username) {
|
||||
return failResponseWrap(null, '用户名不能为空', 50000)
|
||||
}
|
||||
if (!password) {
|
||||
return failResponseWrap(null, '密码不能为空', 50000)
|
||||
}
|
||||
if (username === 'admin' && password === 'admin') {
|
||||
window.localStorage.setItem('userRole', 'admin')
|
||||
return successResponseWrap({
|
||||
token: '12345',
|
||||
})
|
||||
}
|
||||
if (username === 'user' && password === 'user') {
|
||||
window.localStorage.setItem('userRole', 'user')
|
||||
return successResponseWrap({
|
||||
token: '54321',
|
||||
})
|
||||
}
|
||||
return failResponseWrap(null, '账号或者密码错误', 50000)
|
||||
})
|
||||
|
||||
// 登出
|
||||
Mock.mock(new RegExp('/api/user/logout'), () => {
|
||||
return successResponseWrap(null)
|
||||
})
|
||||
|
||||
// 用户的服务端菜单
|
||||
Mock.mock(new RegExp('/api/user/menu'), () => {
|
||||
const menuList = [
|
||||
{
|
||||
path: '/dashboard',
|
||||
name: 'dashboard',
|
||||
meta: {
|
||||
locale: 'menu.server.dashboard',
|
||||
requiresAuth: true,
|
||||
icon: 'icon-dashboard',
|
||||
order: 1,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: 'workplace',
|
||||
name: 'Workplace',
|
||||
meta: {
|
||||
locale: 'menu.server.workplace',
|
||||
requiresAuth: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'https://arco.design',
|
||||
name: 'arcoWebsite',
|
||||
meta: {
|
||||
locale: 'menu.arcoWebsite',
|
||||
requiresAuth: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
return successResponseWrap(menuList)
|
||||
})
|
||||
},
|
||||
})
|
||||
68
cdtestplant/src/mock/userAbout.ts
Normal file
68
cdtestplant/src/mock/userAbout.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import Mock from 'mockjs'
|
||||
import setupMock, { successResponseWrap } from '@/utils/setup-mock'
|
||||
|
||||
const userListMock = Mock.mock({
|
||||
'data|52': [
|
||||
{
|
||||
'index|+1': 1,
|
||||
'name': '@cname',
|
||||
'status': '@integer(0,1)',
|
||||
'updateDate': '@datetime(yyyy-MM-dd)',
|
||||
'cellphone': '18782947123',
|
||||
'role': "@pick(['admin','user'])",
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
// 取get的查询参数,传入url解析出东西
|
||||
const getParams = (url: any) => {
|
||||
const urlp = url.split('?')[1]
|
||||
// 解析参数
|
||||
const queryStr = new URLSearchParams(urlp)
|
||||
const current: any = queryStr.get('current')
|
||||
const pageSize: any = queryStr.get('pageSize')
|
||||
return [current, pageSize]
|
||||
}
|
||||
|
||||
setupMock({
|
||||
setup() {
|
||||
Mock.mock(new RegExp('/api/user/list'), (params: any) => {
|
||||
const [current, pageSize] = getParams(params.url)
|
||||
const fyUerList = userListMock.data.slice((current - 1) * pageSize, current * pageSize)
|
||||
return successResponseWrap({ data: [...fyUerList], total: userListMock.data.length })
|
||||
})
|
||||
Mock.mock(new RegExp('/api/user/delete'), (payload) => {
|
||||
// 在mock中删除
|
||||
const id = payload.body
|
||||
const index = userListMock.data.findIndex((item: any) => item.index === id)
|
||||
userListMock.data.splice(index, 1)
|
||||
return successResponseWrap({ data: [], msg: '成功' })
|
||||
})
|
||||
Mock.mock(new RegExp('/api/user/all'), (payload) => {
|
||||
const option = JSON.parse(payload.body)
|
||||
// 根据name查询
|
||||
let newUserList = userListMock.data.filter((item: any) => item.name.includes(option.name))
|
||||
if (option.status) {
|
||||
newUserList = newUserList.filter((item: any) => item.status === option.status)
|
||||
}
|
||||
newUserList = newUserList.filter((item: any) => item.cellphone.includes(option.cellphone))
|
||||
newUserList = newUserList.filter((item: any) => {
|
||||
const updateDate1 = option.updateDate[0]
|
||||
const updateDate2 = option.updateDate[1]
|
||||
if (item.updateDate < updateDate1) {
|
||||
return false
|
||||
}
|
||||
if (item.updateDate > updateDate2) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
newUserList = newUserList.filter((item: any) => item.role.includes(option.role))
|
||||
const fyUerList = newUserList.slice(
|
||||
(option.current - 1) * option.pageSize,
|
||||
option.current * option.pageSize
|
||||
)
|
||||
return successResponseWrap({ data: [...fyUerList], total: newUserList.length })
|
||||
})
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user