Commit b78ff402 authored by liaozan's avatar liaozan 🏀

feat: add more options for generate

parent 9b4df313
......@@ -26,29 +26,21 @@
<groupId>com.schbrain.framework</groupId>
<artifactId>logger-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-embedder</artifactId>
<version>${maven-embedder.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>${maven-embedder.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-connector-basic</artifactId>
<version>${aether.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-transport-http</artifactId>
<version>${aether.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jgit</groupId>
......
package com.schbrain.archetype.initializer.param;
import lombok.Data;
import org.springframework.util.StringUtils;
import javax.validation.constraints.NotBlank;
......@@ -37,7 +38,7 @@ public class ArchetypeGenerateParam {
private String subModuleNamePrefix;
public String getSubModuleNamePrefix() {
if (this.subModuleNamePrefix == null) {
if (!StringUtils.hasText(this.subModuleNamePrefix)) {
if (this.artifactId.contains(DELIMITER)) {
this.subModuleNamePrefix = this.artifactId.split(DELIMITER)[1];
} else {
......@@ -48,7 +49,7 @@ public class ArchetypeGenerateParam {
}
public String getPackageName() {
if (this.packageName == null) {
if (!StringUtils.hasText(this.packageName)) {
this.packageName = String.format("%s.%s", this.groupId, this.getSubModuleNamePrefix());
}
return this.packageName;
......
......@@ -9,10 +9,8 @@
},
"dependencies": {
"axios": "^0.26.1",
"core-js": "^3.21.1",
"element-plus": "^2.1.4",
"vue": "^3.2.31",
"vue-router": "^4.0.14"
"element-plus": "^2.1.6",
"vue": "^3.2.31"
},
"devDependencies": {
"@babel/core": "^7.17.8",
......
<template>
<BackendStarter/>
<div id="form" class="form">
<p class="form-title">项目初始代码生成</p>
<div class="form-div">
<label class="form-label" for="input-group">GroupId</label>
<input id="input-group" v-model="form.groupId" class="form-input" type="text">
</div>
<div class="form-div">
<label class="form-label" for="input-artifact">ArtifactId</label>
<input id="input-artifact" v-model="form.artifactId" class="form-input" type="text">
</div>
<div class="form-div">
<label class="form-label" for="input-version">Version</label>
<input id="input-version" v-model="form.version" class="form-input" type="text">
</div>
<div class="form-div">
<label class="form-label" for="input-packageName">PackageName</label>
<input id="input-packageName" v-model="form.packageName" class="form-input" placeholder="默认为 GroupId" type="text">
</div>
<input class="form-submit" type="button" value="生成" @click="submit">
<input :disabled="this.id === null" class="form-submit" type="button" value="预览" @click="preview">
<input :disabled="this.id === null" class="form-submit" type="button" value="下载" @click="download">
<el-dialog v-model="dialogVisible" title="预览" width="30%">
<el-tree :data="treeData" :props="defaultProps" @node-click="handleNodeClick"/>
<template #footer>
<span class="dialog-footer">
<el-button type="primary" @click="dialogVisible = false">关闭</el-button>
</span>
</template>
</el-dialog>
</div>
</template>
<script>
import BackendStarter from './components/BackendStarter'
import axios from './util/request'
import {ElMessageBox} from 'element-plus'
export default {
components: {
BackendStarter
name: "BackendStarter",
data() {
return {
id: null,
dialogVisible: false,
fileContentDialogVisible: false,
fileContent: '',
defaultProps: {
children: 'children',
label: 'fileName',
},
treeData: [],
form: {
groupId: '',
artifactId: '',
version: '1.0.0-SNAPSHOT',
packageName: '',
}
}
},
methods: {
submit: function () {
axios.post('/archetype/generate', this.form).then(res => {
this.id = res.data.result
}, error => {
ElMessageBox.alert(error.data.message)
})
},
preview: function () {
axios.get(`/archetype/preview/${this.id}`, this.form).then(res => {
this.treeData = res.data.result
this.dialogVisible = true
}, error => {
ElMessageBox.alert(error.data.message)
})
},
download: function () {
axios.get(`/archetype/download/${this.id}`, {
responseType: 'blob'
}).then(res => {
const {headers, data} = res
const fileName = headers['content-disposition'].replace(/\w+;\sfilename="(.*)"/, '$1')
this.downloadGeneratedProject(data, fileName);
}, error => {
const reader = new FileReader();
reader.readAsText(error.data, 'utf-8');
reader.onload = function () {
ElMessageBox.alert(JSON.parse(reader.result).message, '提示', {confirmButtonText: '确定'})
}
})
},
handleNodeClick: function (data) {
const {file, fileContent} = data
if (!file) {
return
}
this.fileContentDialogVisible = true
this.fileContent = fileContent
},
downloadGeneratedProject: function (data, fileName) {
const blob = new Blob([data])
const link = document.createElement('a');
link.style.display = "none";
link.href = URL.createObjectURL(blob);
link.download = fileName;
document.body.appendChild(link);
link.click();
URL.revokeObjectURL(link.href);
document.body.removeChild(link);
}
}
}
</script>
<style scoped>
.form {
text-align: center;
margin: 80px auto;
max-width: 500px;
background: #FFF;
padding: 30px;
box-shadow: rgba(187, 187, 187, 1) 0 0 20px -1px;
-webkit-box-shadow: rgba(187, 187, 187, 1) 0 0 20px -1px;
font: 14px Arial, Helvetica, sans-serif;
border-radius: 10px;
-webkit-border-radius: 10px;
}
.form-title {
font-size: 20px;
margin-top: 0;
}
.form-div {
display: flex;
align-items: center;
margin-bottom: 10px;
}
.form-label {
width: 150px;
}
.form-input {
color: #555;
width: 100%;
padding: 3px 10px;
margin-top: 10px;
margin-right: 6px;
margin-bottom: 10px;
border: 1px solid #9a9191;
background: transparent;
height: 25px;
line-height: 15px;
outline: 0;
border-radius: 10px;
-webkit-border-radius: 10px;
}
.form-submit {
margin: 10px 5px 0 5px;
background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #ff5bb0), color-stop(1, #ef027d));
border-radius: 9px;
-webkit-border-radius: 9px;
border: 1px solid #ee1eb5;
display: inline-block;
color: #ffffff;
font-size: 15px;
font-weight: bold;
font-style: normal;
height: 35px;
line-height: 30px;
width: 60px;
text-decoration: none;
text-shadow: 1px 1px 0 #c70067;
cursor: pointer;
}
.form-submit:disabled {
background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #000000), color-stop(1, #000000));
border: 1px solid #000000;
text-shadow: 1px 1px 0 #000000;
cursor: not-allowed;
}
</style>
\ No newline at end of file
<!--suppress JSCheckFunctionSignatures -->
<template>
<div id="form" class="form">
<p class="form-title">项目初始代码生成</p>
<div class="form-div">
<label class="form-label" for="input-group">GroupId</label>
<input id="input-group" v-model="form.groupId" class="form-input" type="text">
</div>
<div class="form-div">
<label class="form-label" for="input-artifact">ArtifactId</label>
<input id="input-artifact" v-model="form.artifactId" class="form-input" type="text">
</div>
<input class="form-submit" type="button" value="生成" @click="submit">
<input :disabled="this.id === null" class="form-submit" type="button" value="预览" @click="preview">
<input :disabled="this.id === null" class="form-submit" type="button" value="下载" @click="download">
<el-dialog v-model="dialogVisible" title="预览" width="30%">
<el-tree :data="treeData" :props="defaultProps" @node-click="handleNodeClick"/>
<template #footer>
<span class="dialog-footer">
<el-button type="primary" @click="dialogVisible = false">关闭</el-button>
</span>
</template>
</el-dialog>
</div>
</template>
<script>
import axios from '../util/request'
import {ElMessageBox} from 'element-plus'
export default {
name: "BackendStarter",
data() {
return {
id: null,
dialogVisible: false,
fileContentDialogVisible: false,
fileContent: '',
defaultProps: {
children: 'children',
label: 'fileName',
},
treeData: [],
form: {
groupId: '',
artifactId: '',
}
}
},
methods: {
submit: function () {
axios.post('/archetype/generate', this.form).then(res => {
this.id = res.data.result
}, error => {
ElMessageBox.alert(error.data.message)
})
},
preview: function () {
axios.get(`/archetype/preview/${this.id}`, this.form).then(res => {
this.treeData = res.data.result
this.dialogVisible = true
}, error => {
ElMessageBox.alert(error.data.message)
})
},
download: function () {
axios.get(`/archetype/download/${this.id}`, {
responseType: 'blob'
}).then(res => {
const {headers, data} = res
const fileName = headers['content-disposition'].replace(/\w+;\sfilename="(.*)"/, '$1')
this.downloadGeneratedProject(data, fileName);
}, error => {
const reader = new FileReader();
reader.readAsText(error.data, 'utf-8');
reader.onload = function () {
ElMessageBox.alert(JSON.parse(reader.result).message, '提示', {confirmButtonText: '确定'})
}
})
},
handleNodeClick: function (data) {
const {file, fileContent} = data
if (!file) {
return
}
this.fileContentDialogVisible = true
this.fileContent = fileContent
},
downloadGeneratedProject: function (data, fileName) {
const blob = new Blob([data])
const link = document.createElement('a');
link.style.display = "none";
link.href = URL.createObjectURL(blob);
link.download = fileName;
document.body.appendChild(link);
link.click();
URL.revokeObjectURL(link.href);
document.body.removeChild(link);
}
}
}
</script>
<style scoped>
.form {
text-align: center;
margin-left: auto;
margin-right: auto;
margin-top: 50px;
max-width: 500px;
background: #FFF;
padding: 30px 30px 20px 30px;
box-shadow: rgba(187, 187, 187, 1) 0 0 20px -1px;
-webkit-box-shadow: rgba(187, 187, 187, 1) 0 0 20px -1px;
font: 14px Arial, Helvetica, sans-serif;
border-radius: 10px;
-webkit-border-radius: 10px;
}
.form-title {
font-size: 20px;
}
.form-div {
display: flex;
align-items: center;
margin-bottom: 10px;
}
.form-label {
width: 150px;
}
.form-input {
color: #555;
width: 100%;
padding: 3px 0 3px 5px;
margin-top: 10px;
margin-right: 6px;
margin-bottom: 10px;
border: 1px solid #9a9191;
background: transparent;
height: 25px;
line-height: 15px;
outline: 0;
border-radius: 10px;
-webkit-border-radius: 10px;
}
.form-submit {
margin: 10px 5px 0 5px;
background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #ff5bb0), color-stop(1, #ef027d));
border-radius: 9px;
-webkit-border-radius: 9px;
border: 1px solid #ee1eb5;
display: inline-block;
color: #ffffff;
font-size: 15px;
font-weight: bold;
font-style: normal;
height: 35px;
line-height: 30px;
width: 60px;
text-decoration: none;
text-shadow: 1px 1px 0 #c70067;
cursor: pointer;
}
.form-submit:disabled {
background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #000000), color-stop(1, #000000));
border: 1px solid #000000;
text-shadow: 1px 1px 0 #000000;
cursor: not-allowed;
}
</style>
\ No newline at end of file
import {createApp} from 'vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import vRouter from './router'
import App from './App.vue'
const app = createApp(App)
app.use(vRouter)
app.use(ElementPlus)
app.mount('#app')
\ No newline at end of file
import BackendStarter from "@/components/BackendStarter";
import {createRouter, createWebHistory} from 'vue-router'
const routes = [
{path: '/', component: BackendStarter},
]
const options = {
history: createWebHistory(),
routes,
}
const router = createRouter(options)
export default router
\ No newline at end of file
......@@ -40,6 +40,26 @@
<artifactId>initializer-backend</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-embedder</artifactId>
<version>${maven-embedder.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>${maven-embedder.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-connector-basic</artifactId>
<version>${aether.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-transport-http</artifactId>
<version>${aether.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment