| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- const { Random } = require('mockjs')
- const { join } = require('path')
- const fs = require('fs')
- /**
- * 随机生成图片url
- * @param {*} width
- * @param {*} height
- * @returns
- */
- function handleRandomImage(width = 50, height = 50) {
- return `https://picsum.photos/${width}/${height}?random=${Random.guid()}`
- }
- /**
- * 处理所有 controller 模块,npm run serve时在node环境中自动输出controller文件夹下Mock接口。
- * @returns
- */
- function handleMockArray() {
- const mockArray = []
- const getFiles = (jsonPath) => {
- const jsonFiles = []
- const findJsonFile = (path) => {
- const files = fs.readdirSync(path)
- files.forEach((item) => {
- const fPath = join(path, item)
- const stat = fs.statSync(fPath)
- if (stat.isDirectory() === true) findJsonFile(item)
- if (stat.isFile() === true) jsonFiles.push(item)
- })
- }
- findJsonFile(jsonPath)
- jsonFiles.forEach((item) => mockArray.push(`./controller/${item}`))
- }
- getFiles('mock/controller')
- return mockArray
- }
- // 图标数组
- const icons = [
- 'ad',
- 'address-book',
- 'arrow',
- 'ban',
- 'balance',
- 'bell',
- 'book',
- 'bookmark',
- 'bug',
- 'bullhorn',
- 'calc',
- 'circle',
- 'cloud-sun',
- 'close',
- 'checkbox',
- 'coffee',
- 'copyright',
- 'component',
- 'compress',
- 'expand',
- 'eye',
- 'eye-slash',
- 'form',
- 'ganged',
- 'gift',
- 'home',
- 'hotent',
- 'info',
- 'laptop',
- 'lock',
- 'move',
- 'more',
- 'search',
- 'setting',
- 'simple-collapse',
- 'simple-expand',
- 'table',
- 'user',
- 'users',
- 'upload',
- 'video',
- 'palette',
- 'plan',
- 'refresh',
- 'time',
- 'typography',
- 'dialog',
- 'duration',
- 'attachment',
- 'radio',
- 'select',
- 'tree',
- ]
- module.exports = {
- handleRandomImage,
- handleMockArray,
- icons,
- }
|