ai-manus/chat-client/mock/utils/index.js

40 lines
1.0 KiB
JavaScript
Raw Permalink Normal View History

2025-07-18 16:38:18 +08:00
const fs = require('fs')
const { Random } = require('mockjs')
/**
* @description 随机生成图片url
* @returns {string}
*/
function handleRandomImage(/* width = 50, height = 50 */) {
//return `https://picsum.photos/${width}/${height}?random=${Random.guid()}`
return (
'https://fastly.jsdelivr.net/gh/' +
'chuzh' +
'ixin/image' +
`/table/vab-image-${Random.integer(1, 38)}.jpg`
)
}
/**
* @description 处理所有 controller 模块npm run serve时在node环境中自动输出controller文件夹下Mock接口请勿修改
* @returns {[]}
*/
function handleMockArray() {
const getFiles = (path, baseUrl = './controller') => {
const files = fs.readdirSync(path)
return files.flatMap((file) => {
const fPath = `${path}/${file}`
const stat = fs.statSync(fPath)
return stat.isDirectory()
? getFiles(fPath, `${baseUrl}/${file}`)
: `${baseUrl}/${file}`
})
}
return getFiles('mock/controller')
}
module.exports = {
handleRandomImage,
handleMockArray,
}