index.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 (
  10. 'https://fastly.jsdelivr.net/gh/' +
  11. 'chuzh' +
  12. 'ixin/image' +
  13. `/table/vab-image-${Random.integer(1, 38)}.jpg`
  14. )
  15. }
  16. /**
  17. * @description 处理所有 controller 模块,npm run serve时在node环境中自动输出controller文件夹下Mock接口,请勿修改。
  18. * @returns {[]}
  19. */
  20. function handleMockArray() {
  21. const getFiles = (path, baseUrl = './controller') => {
  22. const files = fs.readdirSync(path)
  23. return files.flatMap((file) => {
  24. const fPath = `${path}/${file}`
  25. const stat = fs.statSync(fPath)
  26. return stat.isDirectory()
  27. ? getFiles(fPath, `${baseUrl}/${file}`)
  28. : `${baseUrl}/${file}`
  29. })
  30. }
  31. return getFiles('mock/controller')
  32. }
  33. module.exports = {
  34. handleRandomImage,
  35. handleMockArray,
  36. }