index.js 1021 B

12345678910111213141516171819202122232425262728293031323334353637
  1. const fs = require('fs')
  2. const { Random } = require('mockjs')
  3. /**
  4. * @description 随机生成图片url。
  5. * @returns {string}
  6. */
  7. function handleRandomImage(/* width = 50, height = 50 */) {
  8. //return `https://picsum.photos/${width}/${height}?random=${Random.guid()}`
  9. return `https://gitee.com/chu1204505056/image/raw/master/table/vab-image-${Random.integer(
  10. 1,
  11. 38
  12. )}.jpg`
  13. }
  14. /**
  15. * @description 处理所有 controller 模块,npm run serve时在node环境中自动输出controller文件夹下Mock接口,请勿修改。
  16. * @returns {[]}
  17. */
  18. function handleMockArray() {
  19. const getFiles = (path, baseUrl = './controller') => {
  20. const files = fs.readdirSync(path)
  21. return files.flatMap((file) => {
  22. const fPath = `${path}/${file}`
  23. const stat = fs.statSync(fPath)
  24. return stat.isDirectory()
  25. ? getFiles(fPath, `${baseUrl}/${file}`)
  26. : `${baseUrl}/${file}`
  27. })
  28. }
  29. return getFiles('mock/controller')
  30. }
  31. module.exports = {
  32. handleRandomImage,
  33. handleMockArray,
  34. }