``javascript
const fs = require("fs");
const path = require("path");
function import2(str) {
return str;
}
// 路由配置
const routes = [
{

path: "business/index",
name: `businessindex`,
meta: {
  auth: ["admin-taxes-business-index"],
  title: "业务员管理",
  keepAlive: true,
},
component: () => import2("@/pages/taxes/business/index"),

},
];
routes.forEach((item) => {
console.log(item);
});

// 递归创建文件
function createFiles(route, basePath) {
const fullPath = path.join(basePath, route.path);

// 创建文件夹
fs.mkdirSync(fullPath, { recursive: true });

// 如果有子路由,递归创建
if (route.children) {

route.children.forEach((child) => {
  createFiles(child, fullPath);
});

}

// 创建组件文件
const componentFilePath = path.join(fullPath, "index.vue");
fs.writeFileSync(

componentFilePath,
`<!-- eslint-disable vue/multi-word-component-names -->

<template>
<div>
${route.meta.title}
</div>
</template>
<script>
export default {
data() {

return { 

indexList: [],

}

},
methods: {

// 定义函数

},
}
</script>

<style scoped>
</style>`
);
}

// 创建路由中的所有文件
routes.forEach((route) =>
createFiles(route, path.join(__dirname, "src/pages/taxes"))
);

console.log("Files created successfully!");

Last modification:October 18, 2024
反正也没人会打赏