1 Star 1 Fork 0

jixule/michong

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
template-d.js 1.59 KB
一键复制 编辑 原始数据 按行查看 历史
jixule 提交于 2020-04-23 22:04 . 米虫
/**
* pages模版快速生成脚本,执行命令 npm run tep-d `文件名`
*/
const fs = require('fs')
const dirName = process.argv[2]
if (!dirName) {
console.log('文件夹名称不能为空!')
console.log('示例:npm run tep test')
process.exit(0)
}
// 页面模版
const indexTep = `<template>
<div></div>
</template>
<script>
export default {
name: '${dirName}',
data () {
return {
data: {}
}
},
methods: {
init () {}
},
activated () {
this.init()
},
mounted () {
this.init()
}
}
</script>
<style lang="less">
</style>
`
// api请求模版
const apiTep = `import {
getRequest,
postRequest,
deleteRequest,
putRequest
} from '@/libs/request'
export const ${dirName}List = params => {
return getRequest('/${dirName}', params)
}
export const ${dirName} = (id, params) => {
return getRequest('/${dirName}/' + id, params)
}
export const ${dirName}Create = params => {
return postRequest('/${dirName}/', params)
}
export const ${dirName}Delete = (id, params) => {
return deleteRequest('/${dirName}/' + id, params)
}
export const ${dirName}Deletes = params => {
return deleteRequest('/${dirName}/delete/', params)
}
export const ${dirName}Edit = (id, params) => {
return putRequest('/${dirName}/' + id, params)
}
`
fs.mkdirSync(`./src/view/${dirName}`) // mkdir $1
process.chdir(`./src/view/${dirName}`) // cd $1
fs.writeFileSync('index.vue', indexTep)
fs.writeFileSync('add.vue', indexTep)
process.chdir('../../') // cd $1
process.chdir('api')
fs.writeFileSync(`${dirName}.js`, apiTep)
console.log(`模版${dirName}已创建`)
process.exit(0)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/jixule/michong.git
git@gitee.com:jixule/michong.git
jixule
michong
michong
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385