const fs = require('fs') const os = require('os') const path = require('path') const axios = require('axios') const host = 'http://120.25.146.52:3090/api/open/plugin/export-full?type=json&pid=18&status=all&token=0badd469d66bec93d28d3bb9ac053ddd9eacb3ebe53a446576fb0fa0ce2ca63c' const code = [] axios.get(host).then(response => { response.data.forEach(item => { if (item.desc == 'scene-edit') { code.push(`import { http } from '@/utils/request'`) item.list.forEach(item => { if (item.path.indexOf('/api/scene/') != -1) { generate(item, 'edit') } }) if (code.length) { fs.writeFileSync(path.resolve(__dirname, `../src/apis/${item.desc}.js`), code.join(os.EOL)) } } code.length = 0 }) }) function generate(scheme, split) { scheme.method = scheme.method.toLowerCase() if (scheme.method == 'get' || scheme.method == 'post') { code.push(`/**`) code.push(`* ${scheme.title}`) code.push(`* @param {object} data 传入的对象参数`) if (scheme.req_body_other) { let req_body = JSON.parse(scheme.req_body_other) if (req_body.properties) { for (let key in req_body.properties) { code.push(`* @param {${req_body.properties[key].type}} data.${key} ${req_body.properties[key].description || ''}`) if (req_body.properties[key].properties) { let properties = req_body.properties[key].properties for (let subKey in properties) { code.push(`* @param {${properties[subKey].type}} data.${key}.${subKey} ${properties[subKey].description}`) } } } } } else if (scheme.req_body_form) { scheme.req_body_form.forEach(item => { code.push(`* @param {${item.type}} data.${item.name} ${item.desc || ''}`) }) } code.push(`* @returns {Promise}`) code.push(`**/`) code.push(`export const ${scheme.path.split(split)[1].substring(1).replace(/\//g, '_')} = data => {`) if (scheme.req_body_type == 'form') { code.push(` return http.postFile('${scheme.path}', data)`) } else { code.push(` return http.${scheme.method}('${scheme.path}', data)`) } code.push(`}`) } }