const {
notEmpty
} = require('../utils.js')
module.exports = {
description: '创建Table查询页面',
prompts: [{
type: 'input',
name: 'folderName',
message: '请输入目录名',
// validate: notEmpty('folderName')
},
{
type: 'input',
name: 'name',
message: '请输入文件名',
validate: notEmpty('name')
},
{
type: 'input',
name: 'pagelist_api',
message: '请输入分页查询接口命名',
// validate: notEmpty('pagelist_api')
},
{
type: 'input',
name: 'delete_api',
message: '请输入信息删除接口命名(非必填)',
// validate: notEmpty('delete_api')
},
{
type: 'confirm',
name: 'wantRouter',
message: '是否生成路由? ',
default: true
},
{
type: 'confirm',
name: 'wantModal',
message: '是否生成新增修改组件',
default: false
},
{
type: 'input',
name: 'add_api',
message: '请输入新增接口命名(非必填)',
when: (data) => {
return (data.wantModal)
}
},
{
type: 'input',
name: 'update_api',
message: '请输入修改接口命名(非必填)',
when: (data) => {
return (data.wantModal)
}
},
{
type: 'confirm',
name: 'ifForm',
message: '是否渲染form表单?',
default: false,
when: (data) => {
return (data.wantModal)
}
},
{
type: 'input',
name: 'formList',
message: 'form数组',
default: [],
when: (data) => {
return (data.ifForm)
},
filter(input) {
if (typeof input === 'string') {
return new Promise((resolve, reject) => {
try {
resolve(JSON.parse(input))
} catch (error) {
reject('请输入有效数据')
}
})
} else {
return []
}
},
},
],
actions: data => {
console.log(data)
const folderName = '{{folderName}}'
const name = '{{name}}';
const modalName = '{{properCase name}}CUModal'
let action = []
if (data.name) {
action.push({
type: 'add',
path: `src/views/${folderName ? folderName+ '/' : ''}${name}/index.vue`,
templateFile: 'plop-templates/tableView/index.hbs',
data: {}
})
}
if (data.wantRouter) {
action.push({
type: 'modify',
path: 'src/router/index.js',
pattern: /(\/\/ append router by plop)/gi,
templateFile: 'plop-templates/tableView/router.hbs',
})
}
if (data.wantModal) {
action.push({
type: 'add',
path: `src/views/${folderName ? folderName + '/' : ''}${name}/components/${modalName}.vue`,
templateFile: 'plop-templates/tableView/component.hbs',
data: {}
})
}
return action
}
}
评论0