wip: vite版重构中

This commit is contained in:
kailong321200875
2021-10-16 09:40:39 +08:00
parent 41ca05dce2
commit a8163874dc
165 changed files with 15146 additions and 145 deletions

131
src/mock/example/index.ts Normal file
View File

@@ -0,0 +1,131 @@
import Mock from 'mockjs'
import { toAnyString } from '@/utils'
let List: any[] = []
const count = 100
const baseContent =
'<p>I am testing data, I am testing data.</p><p><img src="https://wpimg.wallstcn.com/4c69009c-0fd4-4153-b112-6cb53d1cf943"></p>'
for (let i = 0; i < count; i++) {
List.push(
Mock.mock({
id: toAnyString(),
// timestamp: +Mock.Random.date('T'),
author: '@first',
title: '@title(5, 10)',
content: baseContent,
importance: '@integer(1, 3)',
display_time: '@datetime',
pageviews: '@integer(300, 5000)'
// image_uri
})
)
}
export default [
// 列表接口
{
url: 'http://mockjs.test.cn/example/list',
type: 'get',
response: (config: any) => {
const { title, pageIndex, pageSize } = config.query
const mockList = List.filter((item) => {
if (title && item.title.indexOf(title) < 0) return false
return true
})
const pageList = mockList.filter(
(_, index) => index < pageSize * pageIndex && index >= pageSize * (pageIndex - 1)
)
return {
code: '0000',
data: {
total: mockList.length,
list: pageList
}
}
}
},
// 删除接口
{
url: 'http://mockjs.test.cn/example/delete',
type: 'post',
response: (config: any) => {
const ids = config.body.ids
if (!ids) {
return {
code: '500',
message: '请选择需要删除的数据'
}
} else {
let i = List.length
while (i--) {
if (ids.indexOf(List[i].id) !== -1) {
List.splice(i, 1)
}
}
return {
code: '0000',
data: 'success'
}
}
}
},
// 详情接口
{
url: 'http://mockjs.test.cn/example/detail',
type: 'get',
response: (config: any) => {
const { id } = config.query
for (const example of List) {
if (example.id === id) {
return {
code: '0000',
data: example
}
}
}
}
},
// 保存接口
{
url: 'http://mockjs.test.cn/example/save',
type: 'post',
response: (config: any) => {
const data = config.body
if (!data.id) {
List = [
Object.assign(data, {
id: toAnyString(),
importance: Number(data.importance)
})
].concat(List)
return {
code: '0000',
data: 'success'
}
} else {
List.map((item) => {
if (item.id === data.id) {
for (const key in item) {
if (key === 'importance') {
item[key] = Number(data[key])
} else {
item[key] = data[key]
}
}
}
})
return {
code: '0000',
data: 'success'
}
}
}
}
]

64
src/mock/index.ts Normal file
View File

@@ -0,0 +1,64 @@
import Mock from 'mockjs'
import { param2Obj } from '@/utils'
import example from './example'
import user from './user'
import role from './role'
const mocks = [...example, ...user, ...role]
// for front mock
// please use it cautiously, it will redefine XMLHttpRequest,
// which will cause many of your third-party libraries to be invalidated(like progress event).
export function mockXHR() {
const MockJs: any = Mock
MockJs.XHR.prototype.proxy_send = MockJs.XHR.prototype.send
MockJs.XHR.prototype.send = function () {
if (this.custom.xhr) {
this.custom.xhr.withCredentials = this.withCredentials || false
if (this.responseType) {
this.custom.xhr.responseType = this.responseType
}
}
/* eslint-disable */
this.proxy_send(...arguments)
}
function XHR2ExpressReqWrap(respond: any) {
return function (options: any) {
let result = null
if (respond instanceof Function) {
const { body, type, url } = options
// https://expressjs.com/en/4x/api.html#req
result = respond({
method: type,
body: JSON.parse(body),
query: param2Obj(url)
})
} else {
result = respond
}
return Mock.mock(result)
}
}
for (const i of mocks) {
Mock.mock(new RegExp(i.url), i.type || 'get', XHR2ExpressReqWrap(i.response))
}
}
// for mock server
const responseFake = (url: string, type: string, respond: any) => {
return {
url: new RegExp(`${url}`),
type: type || 'get',
response(req: any, res: any) {
res.json(Mock.mock(respond instanceof Function ? respond(req, res) : respond))
}
}
}
export default mocks.map((route) => {
return responseFake(route.url, route.type, route.response)
})

668
src/mock/role/admin-role.ts Normal file
View File

@@ -0,0 +1,668 @@
export const checkedNodes = [
{
path: '/components-demo',
title: '功能组件',
name: 'ComponentsDemo',
children: [
{
path: '/components-demo/echarts',
title: '图表',
name: 'EchartsDemo'
},
{
path: '/components-demo/preview',
title: '图片预览',
name: 'PreviewDemo'
},
{
path: '/components-demo/button',
title: '按钮',
name: 'ButtonDemo'
},
{
path: '/components-demo/message',
title: '消息提示',
name: 'MessageDemo'
},
{
path: '/components-demo/count-to',
title: '数字动画',
name: 'CountToDemo'
},
{
path: '/components-demo/search',
title: '查询',
name: 'SearchDemo'
},
{
path: '/components-demo/editor',
title: '富文本编辑器',
name: 'EditorDemo'
},
{
path: '/components-demo/markdown',
title: 'markdown编辑器',
name: 'MarkdownDemo'
},
{
path: '/components-demo/dialog',
title: '弹窗',
name: 'DialogDemo'
},
{
path: '/components-demo/more',
title: '显示更多',
name: 'MoreDemo'
},
{
path: '/components-demo/detail',
title: '详情组件',
name: 'DetailDemo'
},
{
path: '/components-demo/qrcode',
title: '二维码组件',
name: 'QrcodeDemo'
},
{
path: '/components-demo/avatars',
title: '头像组',
name: 'AvatarsDemo'
},
{
path: '/components-demo/highlight',
title: '文字高亮',
name: 'HighlightDemo'
},
{
path: '/components-demo/watermark',
name: 'WatermarkDemo',
title: '水印'
},
{
path: '/components-demo/timer',
name: 'TimerDemo',
title: '计时器'
},
{
path: '/components-demo/marquee',
name: 'MarqueeDemo',
title: '无缝滚动'
},
{
path: '/components-demo/water-fall',
name: 'WaterFallDemo',
title: '瀑布流'
},
{
path: '/components-demo/tree-select',
name: 'TreeSelectDemo',
title: '瀑布流'
},
{
path: '/components-demo/ellipsis',
name: 'Ellipsis',
title: '省略号'
}
]
},
{
path: '/components-demo/echarts',
title: '图表',
name: 'EchartsDemo'
},
{
path: '/components-demo/preview',
title: '图片预览',
name: 'PreviewDemo'
},
{
path: '/components-demo/button',
title: '按钮',
name: 'ButtonDemo'
},
{
path: '/components-demo/message',
title: '消息提示',
name: 'MessageDemo'
},
{
path: '/components-demo/count-to',
title: '数字动画',
name: 'CountToDemo'
},
{
path: '/components-demo/search',
title: '查询',
name: 'SearchDemo'
},
{
path: '/components-demo/editor',
title: '富文本编辑器',
name: 'EditorDemo'
},
{
path: '/components-demo/markdown',
title: 'markdown编辑器',
name: 'MarkdownDemo'
},
{
path: '/components-demo/dialog',
title: '弹窗',
name: 'DialogDemo'
},
{
path: '/components-demo/more',
title: '显示更多',
name: 'MoreDemo'
},
{
path: '/components-demo/detail',
title: '详情组件',
name: 'DetailDemo'
},
{
path: '/components-demo/qrcode',
title: '二维码组件',
name: 'QrcodeDemo'
},
{
path: '/components-demo/avatars',
title: '头像组',
name: 'AvatarsDemo'
},
{
path: '/components-demo/highlight',
title: '文字高亮',
name: 'HighlightDemo'
},
{
path: '/components-demo/watermark',
name: 'WatermarkDemo',
title: '水印'
},
{
path: '/components-demo/timer',
name: 'TimerDemo',
title: '计时器'
},
{
path: '/components-demo/marquee',
name: 'MarqueeDemo',
title: '无缝滚动'
},
{
path: '/components-demo/water-fall',
name: 'WaterFallDemo',
title: '瀑布流'
},
{
path: '/components-demo/tree-select',
name: 'TreeSelectDemo',
title: '瀑布流'
},
{
path: '/components-demo/ellipsis',
name: 'Ellipsis',
title: '瀑布流'
},
{
path: '/table-demo',
title: '表格',
name: 'TableDemo',
children: [
{
path: '/table-demo/basic-table',
title: '基础表格',
name: 'BasicTable'
},
{
path: '/table-demo/page-table',
title: '分页表格',
name: 'PageTable'
},
{
path: '/table-demo/stripe-table',
title: '带斑马纹表格',
name: 'StripeTable'
},
{
path: '/table-demo/border-table',
title: '带边框表格',
name: 'BorderTable'
},
{
path: '/table-demo/state-table',
title: '带状态表格',
name: 'StateTable'
},
{
path: '/table-demo/fixed-header',
title: '固定表头',
name: 'FixedHeader'
},
{
path: '/table-demo/fixed-column',
title: '固定列',
name: 'FixedColumn'
},
{
path: '/table-demo/fixed-column-header',
title: '固定列和表头',
name: 'FixedColumnHeader'
},
{
path: '/table-demo/fluid-height',
title: '流体高度',
name: 'FluidHeight'
},
{
path: '/table-demo/multi-header',
title: '多级表头',
name: 'MultiHeader'
},
{
path: '/table-demo/single-choice',
title: '单选',
name: 'SingleChoice'
},
{
path: '/table-demo/multiple-choice',
title: '多选',
name: 'MultipleChoice'
},
{
path: '/table-demo/sort-table',
title: '排序',
name: 'SortTable'
},
{
path: '/table-demo/screen-table',
title: '筛选',
name: 'ScreenTable'
},
{
path: '/table-demo/expand-row',
title: '展开行',
name: 'ExpandRow'
},
{
path: '/table-demo/tree-and-load',
title: '树形数据与懒加载',
name: 'TreeAndLoad'
},
{
path: '/table-demo/custom-header',
title: '自定义表头',
name: 'CustomHeader'
},
{
path: '/table-demo/total-table',
title: '表尾合计行',
name: 'TotalTable'
},
{
path: '/table-demo/merge-table',
title: '合并行或列',
name: 'MergeTable'
},
{
path: '/table-demo/custom-index',
title: '自定义索引',
name: 'CustomIndex'
}
]
},
{
path: '/table-demo/basic-table',
title: '基础表格',
name: 'BasicTable'
},
{
path: '/table-demo/page-table',
title: '分页表格',
name: 'PageTable'
},
{
path: '/table-demo/stripe-table',
title: '带斑马纹表格',
name: 'StripeTable'
},
{
path: '/table-demo/border-table',
title: '带边框表格',
name: 'BorderTable'
},
{
path: '/table-demo/state-table',
title: '带状态表格',
name: 'StateTable'
},
{
path: '/table-demo/fixed-header',
title: '固定表头',
name: 'FixedHeader'
},
{
path: '/table-demo/fixed-column',
title: '固定列',
name: 'FixedColumn'
},
{
path: '/table-demo/fixed-column-header',
title: '固定列和表头',
name: 'FixedColumnHeader'
},
{
path: '/table-demo/fluid-height',
title: '流体高度',
name: 'FluidHeight'
},
{
path: '/table-demo/multi-header',
title: '多级表头',
name: 'MultiHeader'
},
{
path: '/table-demo/single-choice',
title: '单选',
name: 'SingleChoice'
},
{
path: '/table-demo/multiple-choice',
title: '多选',
name: 'MultipleChoice'
},
{
path: '/table-demo/sort-table',
title: '排序',
name: 'SortTable'
},
{
path: '/table-demo/screen-table',
title: '筛选',
name: 'ScreenTable'
},
{
path: '/table-demo/expand-row',
title: '展开行',
name: 'ExpandRow'
},
{
path: '/table-demo/tree-and-load',
title: '树形数据与懒加载',
name: 'TreeAndLoad'
},
{
path: '/table-demo/custom-header',
title: '自定义表头',
name: 'CustomHeader'
},
{
path: '/table-demo/total-table',
title: '表尾合计行',
name: 'TotalTable'
},
{
path: '/table-demo/merge-table',
title: '合并行或列',
name: 'MergeTable'
},
{
path: '/table-demo/custom-index',
title: '自定义索引',
name: 'CustomIndex'
},
{
path: '/directives-demo',
title: '自定义指令',
name: 'DirectivesDemo',
children: [
{
path: '/directives-demo/clipboard',
title: 'Clipboard',
name: 'ClipboardDemo'
}
]
},
{
path: '/directives-demo/clipboard',
title: 'Clipboard',
name: 'ClipboardDemo'
},
{
path: '/hooks-demo',
title: 'Hooks',
name: 'HooksDemo',
children: [
{
path: '/hooks-demo/watermark',
title: 'UseWaterMark',
name: 'UseWatermarkDemo'
},
{
path: '/hooks-demo/useScrollTo',
title: 'UseScrollTo',
name: 'UseScrollToDemo'
}
]
},
{
path: '/hooks-demo/watermark',
title: 'UseWaterMark',
name: 'UseWatermarkDemo'
},
{
path: '/hooks-demo/useScrollTo',
title: 'UseScrollTo',
name: 'UseScrollToDemo'
},
{
path: '/icon/index',
title: '图标',
name: 'Icons'
},
{
path: '/level',
title: '多级菜单缓存',
name: 'Level',
children: [
{
path: '/level/menu1',
title: 'Menu1',
name: 'Menu1Demo',
children: [
{
path: '/level/menu1/menu1-1',
title: 'Menu1-1',
name: 'Menu11Demo',
children: [
{
path: '/level/menu1/menu1-1/menu1-1-1',
title: 'Menu1-1-1',
name: 'Menu111Demo'
}
]
},
{
path: '/level/menu1/menu1-2',
title: 'Menu1-2',
name: 'Menu12Demo'
}
]
},
{
path: '/level/menu2',
title: 'Menu2',
name: 'Menu2Demo'
}
]
},
{
path: '/level/menu1',
title: 'Menu1',
name: 'Menu1Demo',
children: [
{
path: '/level/menu1/menu1-1',
title: 'Menu1-1',
name: 'Menu11Demo',
children: [
{
path: '/level/menu1/menu1-1/menu1-1-1',
title: 'Menu1-1-1',
name: 'Menu111Demo'
}
]
},
{
path: '/level/menu1/menu1-2',
title: 'Menu1-2',
name: 'Menu12Demo'
}
]
},
{
path: '/level/menu1/menu1-1',
title: 'Menu1-1',
name: 'Menu11Demo',
children: [
{
path: '/level/menu1/menu1-1/menu1-1-1',
title: 'Menu1-1-1',
name: 'Menu111Demo'
}
]
},
{
path: '/level/menu1/menu1-1/menu1-1-1',
title: 'Menu1-1-1',
name: 'Menu111Demo'
},
{
path: '/level/menu1/menu1-2',
title: 'Menu1-2',
name: 'Menu12Demo'
},
{
path: '/level/menu2',
title: 'Menu2',
name: 'Menu2Demo'
},
{
path: '/example-demo',
title: '综合实例',
name: 'ExampleDemo',
children: [
{
path: '/example-demo/example-dialog',
title: '列表综合实例-弹窗',
name: 'ExampleDialog'
},
{
path: '/example-demo/example-page',
title: '列表综合实例-页面',
name: 'ExamplePage'
}
]
},
{
path: '/example-demo/example-dialog',
title: '列表综合实例-弹窗',
name: 'ExampleDialog'
},
{
path: '/example-demo/example-page',
title: '列表综合实例-页面',
name: 'ExamplePage'
},
{
path: '/role-demo',
title: '权限管理',
name: 'RoleDemo',
children: [
{
path: '/role-demo/user',
title: '用户管理',
name: 'User'
},
{
path: '/role-demo/role',
title: '角色管理',
name: 'Role'
}
]
},
{
path: '/role-demo/user',
title: '用户管理',
name: 'User'
},
{
path: '/role-demo/role',
title: '角色管理',
name: 'Role'
}
]
export const checkedkeys = [
'/components-demo',
'/components-demo/echarts',
'/components-demo/preview',
'/components-demo/button',
'/components-demo/message',
'/components-demo/count-to',
'/components-demo/search',
'/components-demo/editor',
'/components-demo/markdown',
'/components-demo/dialog',
'/components-demo/more',
'/components-demo/detail',
'/components-demo/qrcode',
'/components-demo/avatars',
'/components-demo/watermark',
'/components-demo/timer',
'/components-demo/marquee',
'/components-demo/water-fall',
'/components-demo/tree-select',
'/components-demo/ellipsis',
'/table-demo',
'/table-demo/basic-table',
'/table-demo/page-table',
'/table-demo/stripe-table',
'/table-demo/border-table',
'/table-demo/state-table',
'/table-demo/fixed-header',
'/table-demo/fixed-column',
'/table-demo/fixed-column-header',
'/table-demo/fluid-height',
'/table-demo/multi-header',
'/table-demo/single-choice',
'/table-demo/multiple-choice',
'/table-demo/sort-table',
'/table-demo/screen-table',
'/table-demo/expand-row',
'/table-demo/tree-and-load',
'/table-demo/custom-header',
'/table-demo/total-table',
'/table-demo/merge-table',
'/table-demo/custom-index',
'/directives-demo',
'/directives-demo/clipboard',
'/hooks-demo',
'/hooks-demo/watermark',
'/hooks-demo/useScrollTo',
'/icon/index',
'/level',
'/level/menu1',
'/level/menu1/menu1-1',
'/level/menu1/menu1-1/menu1-1-1',
'/level/menu1/menu1-2',
'/level/menu2',
'/example-demo',
'/example-demo/example-dialog',
'/example-demo/example-page',
'/role-demo',
'/role-demo/user',
'/role-demo/role'
]

100
src/mock/role/index.ts Normal file
View File

@@ -0,0 +1,100 @@
import { useCache } from '@/hooks/web/useCache'
const { wsCache } = useCache()
import { checkedNodes, checkedkeys } from './admin-role'
import { checkedRoleNodes } from './test-role'
let List: {
roleName: string
id: string
checkedNodes: any[]
checkedkeys: any[]
}[] = wsCache.get('roleList') || [
{
roleName: 'admin',
id: '1',
checkedNodes: checkedNodes,
checkedkeys: checkedkeys
},
{
roleName: 'test',
id: '2',
checkedNodes: checkedRoleNodes,
checkedkeys: []
}
]
export default [
// 列表接口
{
url: 'http://mockjs.test.cn/role/list',
type: 'get',
response: (config: any) => {
const { roleName, pageIndex, pageSize } = config.query
const mockList = List.filter((item) => {
if (roleName && item.roleName.indexOf(roleName) < 0) return false
return true
})
const pageList = mockList.filter(
(_, index) => index < pageSize * pageIndex && index >= pageSize * (pageIndex - 1)
)
return {
code: '0000',
data: {
total: mockList.length,
list: pageList
}
}
}
},
// 详情接口
{
url: 'http://mockjs.test.cn/role/detail',
type: 'get',
response: (config: any) => {
const { id } = config.query
for (const role of List) {
if (role.id === id) {
return {
code: '0000',
data: role
}
}
}
}
},
// 保存接口
{
url: 'http://mockjs.test.cn/role/save',
type: 'post',
response: (config: any) => {
const data = config.body
if (!data.id) {
List = [data].concat(List)
return {
code: '0000',
data: 'success'
}
} else {
List.map((item) => {
if (item.id === data.id) {
for (const key in item) {
item[key] = data[key]
}
}
})
// 存在缓存中,避免刷新没有掉
wsCache.set('roleList', List)
return {
code: '0000',
data: 'success'
}
}
}
}
]

500
src/mock/role/test-role.ts Normal file
View File

@@ -0,0 +1,500 @@
export const checkedRoleNodes = [
{
path: '/components-demo',
component: '#',
redirect: '/components-demo/echarts',
name: 'ComponentsDemo',
meta: {
title: '功能组件',
icon: 'component',
alwaysShow: true
},
children: [
{
path: 'echarts',
component: 'views/components-demo/echarts/index',
name: 'EchartsDemo',
meta: {
title: '图表'
}
},
{
path: 'preview',
component: 'views/components-demo/preview/index',
name: 'PreviewDemo',
meta: {
title: '图片预览'
}
},
{
path: 'message',
component: 'views/components-demo/message/index',
name: 'MessageDemo',
meta: {
title: '消息提示'
}
},
{
path: 'search',
component: 'views/components-demo/search/index',
name: 'SearchDemo',
meta: {
title: '查询'
}
},
{
path: 'editor',
component: 'views/components-demo/editor/index',
name: 'EditorDemo',
meta: {
title: '富文本编辑器'
}
},
// {
// path: 'markdown',
// component: 'views/components-demo/markdown/index',
// name: 'MarkdownDemo',
// meta: {
// title: 'markdown编辑器'
// }
// },
{
path: 'dialog',
component: 'views/components-demo/dialog/index',
name: 'DialogDemo',
meta: {
title: '弹窗'
}
},
{
path: 'detail',
component: 'views/components-demo/detail/index',
name: 'DetailDemo',
meta: {
title: '详情组件'
}
},
{
path: 'qrcode',
component: 'views/components-demo/qrcode/index',
name: 'QrcodeDemo',
meta: {
title: '二维码组件'
}
},
{
path: 'avatars',
component: 'views/components-demo/avatars/index',
name: 'AvatarsDemo',
meta: {
title: '头像组'
}
},
{
path: 'highlight',
component: 'views/components-demo/highlight/index',
name: 'HighlightDemo',
meta: {
title: '文字高亮'
}
},
{
path: 'watermark',
component: 'views/components-demo/watermark/index',
name: 'WatermarkDemo',
meta: {
title: '水印'
}
},
{
path: 'timer',
component: 'views/components-demo/timer/index',
name: 'TimerDemo',
meta: {
title: '计时器'
}
},
{
path: 'marquee',
component: 'views/components-demo/marquee/index',
name: 'MarqueeDemo',
meta: {
title: '无缝滚动'
}
},
{
path: 'water-fall',
component: 'views/components-demo/water-fall/index',
name: 'WaterFallDemo',
meta: {
title: '瀑布流'
}
},
{
path: 'tree-select',
component: 'views/components-demo/tree-select/index',
name: 'TreeSelectDemo',
meta: {
title: '下拉树'
}
},
{
path: 'ellipsis',
component: 'views/components-demo/ellipsis/index',
name: 'Ellipsis',
meta: {
title: '省略号'
}
}
]
},
{
path: '/table-demo',
component: '#',
redirect: '/table-demo/basic-usage',
name: 'TableDemo',
meta: {
title: '表格',
icon: 'table',
alwaysShow: true
},
children: [
{
path: 'basic-table',
component: 'views/table-demo/basic-table/index',
name: 'BasicTable',
meta: {
title: '基础表格'
}
},
{
path: 'page-table',
component: 'views/table-demo/page-table/index',
name: 'PageTable',
meta: {
title: '分页表格'
}
},
{
path: 'stripe-table',
component: 'views/table-demo/stripe-table/index',
name: 'StripeTable',
meta: {
title: '带斑马纹表格'
}
},
{
path: 'border-table',
component: 'views/table-demo/border-table/index',
name: 'BorderTable',
meta: {
title: '带边框表格'
}
},
{
path: 'state-table',
component: 'views/table-demo/state-table/index',
name: 'StateTable',
meta: {
title: '带状态表格'
}
},
{
path: 'fixed-header',
component: 'views/table-demo/fixed-header/index',
name: 'FixedHeader',
meta: {
title: '固定表头'
}
},
{
path: 'fixed-column',
component: 'views/table-demo/fixed-column/index',
name: 'FixedColumn',
meta: {
title: '固定列'
}
},
{
path: 'fixed-column-header',
component: 'views/table-demo/fixed-column-header/index',
name: 'FixedColumnHeader',
meta: {
title: '固定列和表头'
}
},
{
path: 'fluid-height',
component: 'views/table-demo/fluid-height/index',
name: 'FluidHeight',
meta: {
title: '流体高度'
}
},
{
path: 'multi-header',
component: 'views/table-demo/multi-header/index',
name: 'MultiHeader',
meta: {
title: '多级表头'
}
},
{
path: 'single-choice',
component: 'views/table-demo/single-choice/index',
name: 'SingleChoice',
meta: {
title: '单选'
}
},
{
path: 'multiple-choice',
component: 'views/table-demo/multiple-choice/index',
name: 'MultipleChoice',
meta: {
title: '多选'
}
},
{
path: 'sort-table',
component: 'views/table-demo/sort-table/index',
name: 'SortTable',
meta: {
title: '排序'
}
},
{
path: 'screen-table',
component: 'views/table-demo/screen-table/index',
name: 'ScreenTable',
meta: {
title: '筛选'
}
},
{
path: 'expand-row',
component: 'views/table-demo/expand-row/index',
name: 'ExpandRow',
meta: {
title: '展开行'
}
},
{
path: 'tree-and-load',
component: 'views/table-demo/tree-and-load/index',
name: 'TreeAndLoad',
meta: {
title: '树形数据与懒加载'
}
},
{
path: 'custom-header',
component: 'views/table-demo/custom-header/index',
name: 'CustomHeader',
meta: {
title: '自定义表头'
}
},
{
path: 'total-table',
component: 'views/table-demo/total-table/index',
name: 'TotalTable',
meta: {
title: '表尾合计行'
}
},
{
path: 'merge-table',
component: 'views/table-demo/merge-table/index',
name: 'MergeTable',
meta: {
title: '合并行或列'
}
},
{
path: 'custom-index',
component: 'views/table-demo/custom-index/index',
name: 'CustomIndex',
meta: {
title: '自定义索引'
}
}
]
},
{
path: '/icon',
component: '#',
name: 'IconsDemo',
meta: {
title: '图标',
icon: 'icon'
},
children: [
{
path: 'index',
component: 'views/icons/index',
name: 'Icons',
meta: {
title: '图标',
icon: 'icon'
}
}
]
},
{
path: '/level',
component: '#',
redirect: '/level/menu1/menu1-1/menu1-1-1',
name: 'Level',
meta: {
title: '多级菜单缓存',
icon: 'nested'
},
children: [
{
path: 'menu1',
name: 'Menu1Demo',
component: '##Menu1Demo',
redirect: '/level/menu1/menu1-1/menu1-1-1',
meta: {
title: 'Menu1'
},
children: [
{
path: 'menu1-1',
name: 'Menu11Demo',
component: '##Menu11Demo',
redirect: '/level/menu1/menu1-1/menu1-1-1',
meta: {
title: 'Menu1-1',
alwaysShow: true
},
children: [
{
path: 'menu1-1-1',
name: 'Menu111Demo',
component: 'views/level/menu111',
meta: {
title: 'Menu1-1-1'
}
}
]
},
{
path: 'menu1-2',
name: 'Menu12Demo',
component: 'views/level/menu12',
meta: {
title: 'Menu1-2'
}
}
]
},
{
path: 'menu2',
name: 'Menu2Demo',
component: 'views/level/menu2',
meta: {
title: 'Menu2'
}
}
]
},
{
path: '/example-demo',
component: '#',
name: 'ExampleDemo',
redirect: '/example-demo/example-dialog',
meta: {
alwaysShow: true,
icon: 'example',
title: '综合实例'
},
children: [
{
path: 'example-dialog',
component: 'views/example-demo/example-dialog/index',
name: 'ExampleDialog',
meta: {
title: '列表综合实例-弹窗'
}
},
{
path: 'example-page',
component: 'views/example-demo/example-page/index',
name: 'ExamplePage',
meta: {
title: '列表综合实例-页面'
}
},
{
path: 'example-add',
component: 'views/example-demo/example-page/example-add',
name: 'ExampleAdd',
meta: {
title: '列表综合实例-新增',
noTagsView: true,
noCache: true,
hidden: true,
showMainRoute: true,
activeMenu: '/example-demo/example-page'
}
},
{
path: 'example-edit',
component: 'views/example-demo/example-page/example-edit',
name: 'ExampleEdit',
meta: {
title: '列表综合实例-编辑',
noTagsView: true,
noCache: true,
hidden: true,
showMainRoute: true,
activeMenu: '/example-demo/example-page'
}
},
{
path: 'example-detail',
component: 'views/example-demo/example-page/example-detail',
name: 'ExampleDetail',
meta: {
title: '列表综合实例-详情',
noTagsView: true,
noCache: true,
hidden: true,
showMainRoute: true,
activeMenu: '/example-demo/example-page'
}
}
]
},
{
path: '/role-demo',
component: '#',
redirect: '/role-demo/user',
name: 'RoleDemo',
meta: {
title: '权限管理',
icon: 'user',
alwaysShow: true
},
children: [
{
path: 'user',
component: 'views/role-demo/user/index',
name: 'User',
meta: {
title: '用户管理'
}
},
{
path: 'role',
component: 'views/role-demo/role/index',
name: 'Role',
meta: {
title: '角色管理'
}
}
]
}
]

71
src/mock/user/index.ts Normal file
View File

@@ -0,0 +1,71 @@
const List: {
userName: string
password: string
role: string
roleId: string
}[] = [
{
userName: 'admin',
password: 'admin',
role: 'admin',
roleId: '1'
},
{
userName: 'test',
password: 'test',
role: 'test',
roleId: '2'
}
]
export default [
// 列表接口
{
url: 'http://mockjs.test.cn/user/list',
type: 'get',
response: (config: any) => {
const { userName, pageIndex, pageSize } = config.query
const mockList = List.filter((item) => {
if (userName && item.userName.indexOf(userName) < 0) return false
return true
})
const pageList = mockList.filter(
(_, index) => index < pageSize * pageIndex && index >= pageSize * (pageIndex - 1)
)
return {
code: '0000',
data: {
total: mockList.length,
list: pageList
}
}
}
},
// 登录接口
{
url: 'http://mockjs.test.cn/user/login',
type: 'post',
response: (config: any) => {
const data = config.body
let hasUser = false
for (const user of List) {
if (user.userName === data.userName && user.password === data.passWord) {
hasUser = true
return {
code: '0000',
data: user
}
}
}
if (!hasUser) {
return {
code: '500',
message: '账号或密码错误'
}
}
}
}
]