commit
07ce8df451
@ -55,15 +55,17 @@
|
||||
</span>
|
||||
<span slot="action" slot-scope="text, record">
|
||||
<span v-if="record.generateType === '1'">
|
||||
<a v-if="hasPerm('codeGenerate:runDown')" @click="runDownCodeGenerate(record)">开始生成</a>
|
||||
<a v-if="hasPerm('codeGenerate:runDown')" @click="runDownCodeGenerate(record)">生成</a>
|
||||
</span>
|
||||
<span v-else>
|
||||
<a-popconfirm v-if="hasPerm('codeGenerate:runLocal')" placement="topRight" title="确定生成代码到本项目?" @confirm="() => runLocalCodeGenerate(record)">
|
||||
<a>开始生成</a>
|
||||
<a>生成</a>
|
||||
</a-popconfirm>
|
||||
</span>
|
||||
<a-divider type="vertical" v-if="hasPerm('codeGenerate:config') & hasPerm('codeGenerate:runLocal') || hasPerm('codeGenerate:runDown') "/>
|
||||
<a v-if="hasPerm('codeGenerate:config')" @click="indexConfigOpen(record)">配置</a>
|
||||
<a-divider type="vertical" v-if="hasPerm('codeGenerate:config') & hasPerm('codeGenerate:runLocal') || hasPerm('codeGenerate:runDown') "/>
|
||||
<a v-if="hasPerm('codeGenerate:config')" @click="indexCodePreviewOpen(record)">预览</a>
|
||||
<a-divider type="vertical" v-if="hasPerm('codeGenerate:config') & hasPerm('codeGenerate:edit')"/>
|
||||
<a v-if="hasPerm('codeGenerate:edit')" @click="$refs.editForm.edit(record)">编辑</a>
|
||||
<a-divider type="vertical" v-if="hasPerm('codeGenerate:edit') & hasPerm('codeGenerate:delete')"/>
|
||||
@ -77,6 +79,7 @@
|
||||
</a-spin>
|
||||
</a-card>
|
||||
<index-config ref="indexConfig" @ok="handleResetOpen" v-if="hasPerm('codeGenerate:config')"/>
|
||||
<index-code-preview ref="indexCodePreview" @ok="handleResetOpen" v-if="hasPerm('codeGenerate:config')"/>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
@ -85,10 +88,12 @@
|
||||
import addForm from './addForm'
|
||||
import editForm from './editForm'
|
||||
import indexConfig from './indexConfig'
|
||||
import indexCodePreview from './indexCodePreview'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
indexConfig,
|
||||
indexCodePreview,
|
||||
STable,
|
||||
Ellipsis,
|
||||
addForm,
|
||||
@ -233,6 +238,13 @@
|
||||
this.indexOpenShow = false
|
||||
this.$refs.indexConfig.open(record)
|
||||
},
|
||||
/**
|
||||
* 打开预览界面
|
||||
*/
|
||||
indexCodePreviewOpen (record) {
|
||||
this.indexOpenShow = false
|
||||
this.$refs.indexCodePreview.open(record)
|
||||
},
|
||||
/**
|
||||
* 详细配置界面返回
|
||||
*/
|
||||
|
64
_web/src/views/gen/codeGenerate/indexCodePreview.vue
Normal file
64
_web/src/views/gen/codeGenerate/indexCodePreview.vue
Normal file
@ -0,0 +1,64 @@
|
||||
<template>
|
||||
<a-card :bordered="false" v-show="indexCodeViewShow">
|
||||
<div class="table-operator">
|
||||
<a-button class="but_item" type="dashed" @click="handleCancel" icon="rollback">返回</a-button>
|
||||
</div>
|
||||
<a-tabs v-model="activeKey" tab-position="left" hide-add type="card" >
|
||||
<a-tab-pane v-for="pane in panes" :key="pane.key" :tab="pane.title" closable="closable" >
|
||||
<div>
|
||||
<a-button type="primary" class="but_item" @click="copyContentCode(pane.content)" icon="copy">复制代码</a-button>
|
||||
</div>
|
||||
<a-textarea v-model="pane.content" autosize="true" ref="inputText" />
|
||||
</a-tab-pane>
|
||||
</a-tabs>
|
||||
</a-card>
|
||||
</template>
|
||||
<script>
|
||||
import { codeGenerateRunFileContent } from '@/api/modular/gen/codeGenerateManage'
|
||||
export default {
|
||||
data () {
|
||||
return {
|
||||
activeKey: 'null',
|
||||
panes: [],
|
||||
indexCodeViewShow: false,
|
||||
tableLoading: false,
|
||||
visible: false
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* 打开界面
|
||||
*/
|
||||
open (data) {
|
||||
this.indexCodeViewShow = true
|
||||
this.tableLoading = true
|
||||
codeGenerateRunFileContent(data).then((res) => {
|
||||
if (res.success) {
|
||||
let tabi = 1
|
||||
this.loadData = res.data
|
||||
this.loadData.forEach(item => {
|
||||
this.panes.push({ title: item.fileName, content: item.fileContent, key: 'tab' + tabi++ })
|
||||
this.code = item.fileContent
|
||||
})
|
||||
}
|
||||
this.activeKey = this.panes[0].key
|
||||
this.tableLoading = false
|
||||
})
|
||||
},
|
||||
copyContentCode (code) {
|
||||
var input = document.createElement('textarea')
|
||||
input.value = code
|
||||
document.body.appendChild(input)
|
||||
input.select()
|
||||
document.execCommand('Copy')
|
||||
document.body.removeChild(input)
|
||||
},
|
||||
handleCancel () {
|
||||
this.$emit('ok')
|
||||
this.loadData = []
|
||||
this.panes = []
|
||||
this.indexCodeViewShow = false
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
@ -157,4 +157,24 @@ public class CodeGenerateController {
|
||||
}
|
||||
this.codeGenerateService.runDown(codeGenerateParam, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 代码生成基础配置生成返回预览
|
||||
*
|
||||
* @author Sam
|
||||
* @date 2022-02-11 01:55:48
|
||||
*/
|
||||
@Permission
|
||||
@GetMapping("/codeGenerate/runFileContent")
|
||||
@BusinessLog(title = "代码生成_返回预览", opType = LogAnnotionOpTypeEnum.QUERY)
|
||||
public ResponseData runFileContent(@Validated(CodeGenerateParam.detail.class) CodeGenerateParam codeGenerateParam) {
|
||||
|
||||
// 演示环境开启,则不允许操作
|
||||
if (ConstantContextHolder.getDemoEnvFlag()) {
|
||||
throw new DemoException();
|
||||
}
|
||||
|
||||
return ResponseData.success(this.codeGenerateService.runFileContent(codeGenerateParam));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
Copyright [2020] [https://www.xiaonuo.vip]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
|
||||
|
||||
1.请不要删除和修改根目录下的LICENSE文件。
|
||||
2.请不要删除和修改Snowy源码头部的版权声明。
|
||||
3.请保留源码和相关描述文件的项目出处,作者声明等。
|
||||
4.分发源码时候,请注明软件出处 https://gitee.com/xiaonuobase/snowy
|
||||
5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/snowy
|
||||
6.若您的项目无法满足以上几点,可申请商业授权,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
|
||||
*/
|
||||
package vip.xiaonuo.generate.modular.result;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 文件内容返回对象
|
||||
*
|
||||
* @author Sam
|
||||
* @datetime 2022年02月07日20:01:56
|
||||
*/
|
||||
@Data
|
||||
public class FileContentResult {
|
||||
|
||||
/**
|
||||
* 文件名称(字母形式的)
|
||||
*/
|
||||
public String fileName;
|
||||
|
||||
/**
|
||||
* 文件内容
|
||||
*/
|
||||
public String fileContent;
|
||||
|
||||
public FileContentResult() {
|
||||
|
||||
}
|
||||
|
||||
public FileContentResult(String name, String content) {
|
||||
fileName = name;
|
||||
fileContent = content;
|
||||
}
|
||||
|
||||
}
|
@ -28,6 +28,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import vip.xiaonuo.core.pojo.page.PageResult;
|
||||
import vip.xiaonuo.generate.modular.entity.CodeGenerate;
|
||||
import vip.xiaonuo.generate.modular.param.CodeGenerateParam;
|
||||
import vip.xiaonuo.generate.modular.result.FileContentResult;
|
||||
import vip.xiaonuo.generate.modular.result.InformationResult;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@ -104,4 +105,12 @@ public interface CodeGenerateService extends IService<CodeGenerate> {
|
||||
* @date 2020年12月16日21:03:15
|
||||
*/
|
||||
void runDown(CodeGenerateParam codeGenerateParam, HttpServletResponse response);
|
||||
|
||||
/**
|
||||
* 获取文件内容
|
||||
*
|
||||
* @author Sam
|
||||
* @datetime 2022年02月07日20:01:56
|
||||
*/
|
||||
List<FileContentResult> runFileContent(CodeGenerateParam codeGenerateParam);
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ import vip.xiaonuo.generate.modular.enums.CodeGenerateExceptionEnum;
|
||||
import vip.xiaonuo.generate.modular.mapper.CodeGenerateMapper;
|
||||
import vip.xiaonuo.generate.modular.param.CodeGenerateParam;
|
||||
import vip.xiaonuo.generate.modular.param.SysCodeGenerateConfigParam;
|
||||
import vip.xiaonuo.generate.modular.result.FileContentResult;
|
||||
import vip.xiaonuo.generate.modular.result.InforMationColumnsResult;
|
||||
import vip.xiaonuo.generate.modular.result.InformationResult;
|
||||
import vip.xiaonuo.generate.modular.service.CodeGenerateService;
|
||||
@ -57,6 +58,7 @@ import vip.xiaonuo.generate.modular.service.SysCodeGenerateConfigService;
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
@ -180,6 +182,12 @@ public class CodeGenerateServiceImpl extends ServiceImpl<CodeGenerateMapper, Cod
|
||||
downloadCode(xnCodeGenParam, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FileContentResult> runFileContent(CodeGenerateParam codeGenerateParam) {
|
||||
XnCodeGenParam xnCodeGenParam = copyParams(codeGenerateParam);
|
||||
return fileContentCode(xnCodeGenParam);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验表中是否包含主键
|
||||
*
|
||||
@ -216,6 +224,36 @@ public class CodeGenerateServiceImpl extends ServiceImpl<CodeGenerateMapper, Cod
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件内容化代码基础
|
||||
*
|
||||
* @author yubaoshan
|
||||
* @date 2020年12月23日 00点32分
|
||||
*/
|
||||
private List<FileContentResult> fileContentCode(XnCodeGenParam xnCodeGenParam) {
|
||||
Util.initVelocity();
|
||||
XnVelocityContext context = new XnVelocityContext();
|
||||
|
||||
List<FileContentResult> reList = new ArrayList<>();
|
||||
String[] filePath = GenConstant.xnCodeGenFilePath(xnCodeGenParam.getBusName(), xnCodeGenParam.getPackageName());
|
||||
for (int a = 0; a < filePath.length; a++) {
|
||||
String templateName = GenConstant.xnCodeGenTempFile[a];
|
||||
String fileBaseName = ResetFileBaseName(xnCodeGenParam.getClassName(),
|
||||
templateName.substring(templateName.indexOf(GenConstant.FILE_SEP) + 1, templateName.lastIndexOf(TEMP_SUFFIX)));
|
||||
|
||||
VelocityContext velContext = context.createVelContext(xnCodeGenParam);
|
||||
String tempName = GenConstant.templatePath + templateName;
|
||||
StringWriter sw = new StringWriter();
|
||||
Template tpl = Velocity.getTemplate(tempName, ENCODED);
|
||||
tpl.merge(velContext, sw);
|
||||
|
||||
FileContentResult fcResult = new FileContentResult(fileBaseName, sw.toString());
|
||||
reList.add(fcResult);
|
||||
}
|
||||
|
||||
return reList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表中所有字段集合
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user