index.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const { Random } = require('mockjs')
  2. const { join } = require('path')
  3. const fs = require('fs')
  4. const accessTokens = {
  5. admin: 'admin-accessToken',
  6. editor: 'editor-accessToken',
  7. test: 'test-accessToken',
  8. zhangsan: 'zhangsan-accessToken',
  9. }
  10. /**
  11. * @author https://vue-admin-beautiful.com (不想保留author可删除)
  12. * @description 随机生成图片url。
  13. * @param width
  14. * @param height
  15. * @returns {string}
  16. */
  17. function handleRandomImage(width = 50, height = 50) {
  18. return `https://picsum.photos/${width}/${height}?random=${Random.guid()}`
  19. }
  20. /**
  21. * @author https://vue-admin-beautiful.com (不想保留author可删除)
  22. * @description 处理所有 controller 模块,npm run serve时在node环境中自动输出controller文件夹下Mock接口,请勿修改。
  23. * @returns {[]}
  24. */
  25. function handleMockArray() {
  26. const mockArray = []
  27. const getFiles = (jsonPath) => {
  28. const jsonFiles = []
  29. const findJsonFile = (path) => {
  30. const files = fs.readdirSync(path)
  31. files.forEach((item) => {
  32. const fPath = join(path, item)
  33. const stat = fs.statSync(fPath)
  34. if (stat.isDirectory() === true) findJsonFile(item)
  35. if (stat.isFile() === true) jsonFiles.push(item)
  36. })
  37. }
  38. findJsonFile(jsonPath)
  39. jsonFiles.forEach((item) => mockArray.push(`./controller/${item}`))
  40. }
  41. getFiles('mock/controller')
  42. return mockArray
  43. }
  44. function handleToken(accessToken) {
  45. let arr = Object.keys(accessTokens)
  46. }
  47. module.exports = {
  48. handleRandomImage,
  49. handleMockArray,
  50. handleToken,
  51. }