【ai极速编码】支持自定义修改内容

This commit is contained in:
神仙都没用 2024-10-24 17:18:07 +08:00
parent d72dd5410d
commit 57cfaeaa5b
3 changed files with 90 additions and 53 deletions

View File

@ -20,7 +20,8 @@ export default defineComponent({
setup(props) { setup(props) {
const style = reactive({ const style = reactive({
fontSize: parsePx(props.size!) fontSize: parsePx(props.size!),
fill: props.color
}); });
const iconName = computed(() => `#icon-${props.name}`); const iconName = computed(() => `#icon-${props.name}`);

View File

@ -6,7 +6,7 @@
}" }"
> >
<el-image <el-image
:src="urls[0]" :src="url"
:fit="fit" :fit="fit"
:lazy="lazy" :lazy="lazy"
:preview-src-list="urls" :preview-src-list="urls"
@ -49,7 +49,8 @@ export default defineComponent({
fit: { fit: {
type: String as PropType<'' | 'contain' | 'cover' | 'none' | 'fill' | 'scale-down'>, type: String as PropType<'' | 'contain' | 'cover' | 'none' | 'fill' | 'scale-down'>,
default: 'cover' default: 'cover'
} },
compress: String as PropType<'oss' | 'none'>
}, },
setup(props) { setup(props) {
@ -76,7 +77,20 @@ export default defineComponent({
}; };
}); });
const url = computed(() => {
const v = urls.value[0];
if (props.compress == 'oss') {
return (
v + `?x-oss-process=image/resize,m_fill,h_${style.value.h},w_${style.value.w}`
);
}
return v;
});
return { return {
url,
urls, urls,
style style
}; };

View File

@ -168,7 +168,7 @@
</div> </div>
<div class="btns"> <div class="btns">
<el-button class="btn-primary" @click="code.create()"> <el-button class="btn-primary" @click="code.create(true)">
生成代码 生成代码
<cl-svg name="code" /> <cl-svg name="code" />
</el-button> </el-button>
@ -204,11 +204,17 @@
} }
" "
> >
{{ item.label }} <span>{{ item.label }}</span>
<el-switch
class="lock"
size="small"
v-model="code.lock[item.value]"
v-if="item.value != 'vue' && !code.loading"
/>
</div> </div>
<div v-if="!isEmpty(code.list) && !code.loading" class="op"> <div v-if="!isEmpty(code.list) && !code.loading" class="op">
<el-tooltip v-if="code.active == 'vue'" content="重新生成"> <el-tooltip content="重新生成">
<el-icon @click="code.refresh()"> <el-icon @click="code.refresh()">
<refresh /> <refresh />
</el-icon> </el-icon>
@ -287,7 +293,7 @@ import {
QuestionFilled, QuestionFilled,
Refresh Refresh
} from '@element-plus/icons-vue'; } from '@element-plus/icons-vue';
import { ElMessage, ElMessageBox } from 'element-plus'; import { ElMessage, ElMessageBox, ElNotification } from 'element-plus';
import { assign, isEmpty } from 'lodash-es'; import { assign, isEmpty } from 'lodash-es';
import { useMenu, useAi } from '../hooks'; import { useMenu, useAi } from '../hooks';
import { config, isDev } from '/@/config'; import { config, isDev } from '/@/config';
@ -398,6 +404,9 @@ const code = reactive({
// //
list: [] as CodeItem[], list: [] as CodeItem[],
//
lock: {} as { [key: string]: boolean },
// //
data: { data: {
router: '', router: '',
@ -460,7 +469,6 @@ const code = reactive({
clear() { clear() {
code.list = []; code.list = [];
code.logs = []; code.logs = [];
code.req = null;
code.loading = false; code.loading = false;
}, },
@ -482,12 +490,10 @@ const code = reactive({
// Node // Node
async createNode() { async createNode() {
code.tips('Entity 代码生成中');
// entity // entity
const entity = await code.setContent('Entity 实体', 'node-entity'); const entity = await code.setContent('Entity 实体', 'node-entity');
code.tips('Entity 生成成功,开始解析'); code.tips('Entity 开始解析');
// entity // entity
const entityData = await ai.invokeFlow('comm-parse-entity', { const entityData = await ai.invokeFlow('comm-parse-entity', {
@ -504,15 +510,13 @@ const code = reactive({
// //
code.parseColumn(); code.parseColumn();
code.tips('Service 代码生成中');
// service // service
const service = await code.setContent('Service 服务', 'node-service', { const service = await code.setContent('Service 服务', 'node-service', {
...entityData, ...entityData,
entity entity
}); });
code.tips('Service 生成成功,开始解析'); code.tips('Service 开始解析');
// service // service
const serviceData = await ai.invokeFlow('comm-parse-service', { const serviceData = await ai.invokeFlow('comm-parse-service', {
@ -521,8 +525,6 @@ const code = reactive({
code.tips(`Service 解析成功,${JSON.stringify(serviceData)}`); code.tips(`Service 解析成功,${JSON.stringify(serviceData)}`);
code.tips('Controller 代码生成中');
// controller // controller
const controller = await code.setContent('Controller 控制器', 'node-controller', { const controller = await code.setContent('Controller 控制器', 'node-controller', {
...serviceData, ...serviceData,
@ -531,7 +533,7 @@ const code = reactive({
entity entity
}); });
code.tips('Controller 生成成功,开始解析'); code.tips('Controller 开始解析');
// controller // controller
const controllerData = await ai.invokeFlow('comm-parse-controller', { const controllerData = await ai.invokeFlow('comm-parse-controller', {
@ -547,12 +549,10 @@ const code = reactive({
// Java // Java
async createJava() { async createJava() {
code.tips('Entity 代码生成中');
// entity // entity
const entity = await code.setContent('Entity 实体', 'java-entity'); const entity = await code.setContent('Entity 实体', 'java-entity');
code.tips('Entity 生成成功,开始解析'); code.tips('Entity 开始解析');
// entity // entity
const entityData = await ai.invokeFlow('comm-parse-entity', { const entityData = await ai.invokeFlow('comm-parse-entity', {
@ -569,51 +569,41 @@ const code = reactive({
// //
code.parseColumn(); code.parseColumn();
code.tips('Mapper 代码生成中');
// mapper // mapper
await code.setContent('Mapper 映射', 'java-mapper', { await code.setContent('Mapper 映射', 'java-mapper', {
...entityData, ...entityData,
entity entity
}); });
code.tips('Mapper 生成成功');
code.tips('Service 代码生成中');
// service // service
const _service = await code.setContent('Service 接口类', 'java-service', { const serviceInterface = await code.setContent('Service 接口类', 'java-service', {
...entityData, ...entityData,
entity entity
}); });
// service // service
const service = await code.setContent('Service 实现类', 'java-service-impl', { const serviceImpl = await code.setContent('Service 实现类', 'java-service-impl', {
...entityData, ...entityData,
entity, entity,
service: _service service: serviceInterface
}); });
code.tips('Service 生成成功,开始解析');
// service // service
const serviceData = await ai.invokeFlow('comm-parse-service', { const serviceData = await ai.invokeFlow('comm-parse-service', {
service service: serviceImpl
}); });
code.tips(`Service 解析成功,${JSON.stringify(serviceData)}`); code.tips(`Service 解析成功,${JSON.stringify(serviceData)}`);
code.tips('Controller 代码生成中');
// controller // controller
const controller = await code.setContent('Controller 控制器', 'java-controller', { const controller = await code.setContent('Controller 控制器', 'java-controller', {
...serviceData, ...serviceData,
...entityData, ...entityData,
service, service: serviceImpl,
entity entity
}); });
code.tips('Controller 生成成功,开始解析'); code.tips('Controller 开始解析');
// controller // controller
const controllerData = await ai.invokeFlow('comm-parse-controller', { const controllerData = await ai.invokeFlow('comm-parse-controller', {
@ -627,7 +617,7 @@ const code = reactive({
}, },
// //
async create() { async create(isNew?: boolean) {
if (!form.entity) { if (!form.entity) {
return ElMessage.warning('请填写实体名称'); return ElMessage.warning('请填写实体名称');
} }
@ -640,19 +630,21 @@ const code = reactive({
return ElMessage.warning('请填写字段'); return ElMessage.warning('请填写字段');
} }
code.loading = true; if (isNew) {
// //
code.clear(); code.clear();
// //
step.next(); step.next();
}
code.loading = true;
code.req = null;
code.tips('AI 开始编码'); code.tips('AI 开始编码');
await sleep(300); await sleep(300);
// @ts-ignore
await code[`create${lang.value}`](); await code[`create${lang.value}`]();
await code.createVue(); await code.createVue();
@ -779,16 +771,24 @@ const code = reactive({
}, },
// //
async setContent(label: string, flow: string, data?: any) { async setContent(label: string, flow: string, data?: any): Promise<string> {
return new Promise(resolve => { return new Promise(resolve => {
const item = code.add(label, flow); const item = code.add(label, flow);
//
if (code.lock[flow]) {
resolve(item.content);
return;
}
// //
let isEnd = false; let isEnd = false;
// //
let content = ''; let content = '';
code.tips(`${label}生成中`);
ai.invokeFlow(flow, { ...form, ...data }, res => { ai.invokeFlow(flow, { ...form, ...data }, res => {
isEnd = res.isEnd; isEnd = res.isEnd;
@ -815,7 +815,8 @@ const code = reactive({
if (!v) { if (!v) {
clearInterval(timer); clearInterval(timer);
resolve(item.content); resolve(item.content);
return false; code.tips(`${label}生成成功`);
return;
} }
} }
@ -841,11 +842,16 @@ const code = reactive({
}, },
// //
async refresh() { refresh() {
code.loading = true; //
code.req = null; code.list.forEach(e => {
await code.createVue(); if (!code.lock[e.value]) {
code.loading = false; e.content = '';
}
});
//
code.create();
} }
}); });
@ -1095,6 +1101,13 @@ onMounted(() => {
assign(form, storage.get('ai-code.form')); assign(form, storage.get('ai-code.form'));
} }
} }
//
ElNotification({
title: '新功能提示',
message: '支持自定义修改内容,开启后跳过生成',
duration: 5000
});
}); });
</script> </script>
@ -1556,8 +1569,17 @@ $color: #41d1ff;
cursor: pointer; cursor: pointer;
color: var(--el-color-info); color: var(--el-color-info);
& > span {
line-height: 1;
user-select: none;
}
.lock {
margin-left: 10px;
}
&.active { &.active {
background-color: #0f151e; background-color: #1d1f24;
color: #fff; color: #fff;
} }
@ -1581,7 +1603,7 @@ $color: #41d1ff;
border-radius: 5px; border-radius: 5px;
&:hover { &:hover {
background-color: #0f151e; background-color: #1d1f24;
} }
} }
} }