!31 【代码生成】添加【预览】

代码生成加入预览功能
pull/34/head
小诺 2022-02-15 09:52:01 +00:00 committed by Gitee
commit 07ce8df451
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 202 additions and 2 deletions

View File

@ -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)
},
/**
* 详细配置界面返回
*/

View 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>

View File

@ -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));
}
}

View File

@ -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.
SnowyAPACHE 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 2022020720:01:56
*/
@Data
public class FileContentResult {
/**
*
*/
public String fileName;
/**
*
*/
public String fileContent;
public FileContentResult() {
}
public FileContentResult(String name, String content) {
fileName = name;
fileContent = content;
}
}

View File

@ -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 2020121621:03:15
*/
void runDown(CodeGenerateParam codeGenerateParam, HttpServletResponse response);
/**
*
*
* @author Sam
* @datetime 2022020720:01:56
*/
List<FileContentResult> runFileContent(CodeGenerateParam codeGenerateParam);
}

View File

@ -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 20201223 0032
*/
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;
}
/**
*
*