安装:npm install mockjs
官网:Mockjs
我这里简单mock了两个获取树型接口的数据
getTreeList
初始化获取树列表
function getTreeList(): Promise<string> {
return new Promise((resolve) => {
setTimeout(() => {
resolve(
Mock.mock({
'data|3': [
{
'code|+1': ['1', '2', '3'],//+1 自增
'name|+1': [
'架构域1',
'架构域2',
'架构域3',
],
'parentCode|1': ['0', '0', '0']
}
]
})
)
}, 200)
})
}
getChildrenNodes
根据父节点key获取该父节点下面的child
function getChildrenNodes(parentCode: string): Promise<string> {
return new Promise((resolve) => {
setTimeout(() => {
resolve(
Mock.mock({
'data|1-3': [
{
'code|+1': [
`${parentCode}-1`,
`${parentCode}-2`,
`${parentCode}-3`,
],
'name|+1': [
`架构域${parentCode}-1`,
`架构域${parentCode}-2`,
`架构域${parentCode}-3`,
],
parentCode: parentCode
}
]
})
)
}, 200)
})
}