|
|
|
@ -1,4 +1,5 @@
@@ -1,4 +1,5 @@
|
|
|
|
|
<template> |
|
|
|
|
<div> |
|
|
|
|
<BasicModal |
|
|
|
|
v-bind="$attrs" |
|
|
|
|
defaultFullscreen |
|
|
|
@ -7,21 +8,84 @@
@@ -7,21 +8,84 @@
|
|
|
|
|
@ok="handleSubmit" |
|
|
|
|
> |
|
|
|
|
<BasicForm @register="registerForm"/> |
|
|
|
|
<AceEditor v-model:value="state.content" @register="registerAceEditor"/> |
|
|
|
|
<ATabs v-model:activeKey="state.typeActiveKey" type="card"> |
|
|
|
|
<ATabPane key="1" tab="主表"> |
|
|
|
|
<div class="tool-bar"> |
|
|
|
|
<a-button type="primary" @click="handleAddTab">新增</a-button> |
|
|
|
|
<a-button type="primary" @click="handleEditTab">编辑</a-button> |
|
|
|
|
</div> |
|
|
|
|
<ADivider/> |
|
|
|
|
<ATabs v-show="mainTemplateObjs.length > 0" |
|
|
|
|
v-model:activeKey="state.mainActiveKey" |
|
|
|
|
type="editable-card" |
|
|
|
|
hideAdd |
|
|
|
|
@edit="handleRemoveTab" |
|
|
|
|
> |
|
|
|
|
<ATabPane v-for="mainTemplateObj in mainTemplateObjs" :key="mainTemplateObj.index || mainTemplateObj.id" :tab="mainTemplateObj.name"> |
|
|
|
|
<AceEditor v-model:value="mainTemplateObj.contents" |
|
|
|
|
class="vue-ace-editor" |
|
|
|
|
@register="registerAceEditor" |
|
|
|
|
/> |
|
|
|
|
</ATabPane> |
|
|
|
|
</ATabs> |
|
|
|
|
</ATabPane> |
|
|
|
|
<ATabPane key="2" tab="附表"> |
|
|
|
|
<div class="tool-bar"> |
|
|
|
|
<a-button type="primary" @click="handleAddTab">新增</a-button> |
|
|
|
|
<a-button type="primary" @click="handleEditTab">编辑</a-button> |
|
|
|
|
</div> |
|
|
|
|
<ADivider/> |
|
|
|
|
<ATabs v-show="childTemplateObjs.length > 0" |
|
|
|
|
v-model:activeKey="state.childActiveKey" |
|
|
|
|
type="editable-card" |
|
|
|
|
hideAdd |
|
|
|
|
@edit="handleRemoveTab" |
|
|
|
|
> |
|
|
|
|
<ATabPane v-for="childTemplateObj in childTemplateObjs" :key="childTemplateObj.index || childTemplateObj.id" :tab="childTemplateObj.name"> |
|
|
|
|
<AceEditor v-model:value="childTemplateObj.contents" @register="registerAceEditor"/> |
|
|
|
|
</ATabPane> |
|
|
|
|
</ATabs> |
|
|
|
|
</ATabPane> |
|
|
|
|
</ATabs> |
|
|
|
|
</BasicModal> |
|
|
|
|
<TemplatePromptModal @register="registerPromptModal" @success="handlePrompt"/> |
|
|
|
|
</div> |
|
|
|
|
</template> |
|
|
|
|
<script lang="ts" setup> |
|
|
|
|
import { reactive } from 'vue'; |
|
|
|
|
import { reactive, computed } from 'vue'; |
|
|
|
|
import { BasicForm, useForm } from '/@/components/Form/index'; |
|
|
|
|
import { formSchema } from './template.data'; |
|
|
|
|
import { getGenCodeTemplateGroup, saveAndGencodeTemplateObj } from '/@/api/platform/system/controller/gencodeTemplateGroup'; |
|
|
|
|
import { BasicModal, ModalProps, useModalInner } from '/@/components/Modal'; |
|
|
|
|
import type { GencodeTemplateObj } from '/@/api/platform/system/entity/gencodeTemplateObj'; |
|
|
|
|
import { BasicModal, ModalProps, useModalInner, useModal } from '/@/components/Modal'; |
|
|
|
|
import { AceEditor, useAceEditor } from '/@/components/AceEditor'; |
|
|
|
|
import { Tabs, Divider } from 'ant-design-vue'; |
|
|
|
|
import TemplatePromptModal from './TemplatePromptModal.vue'; |
|
|
|
|
|
|
|
|
|
const ATabs = Tabs; |
|
|
|
|
const ATabPane = Tabs.TabPane; |
|
|
|
|
const ADivider = Divider; |
|
|
|
|
|
|
|
|
|
type templateTypePartial = Partial<GencodeTemplateObj>; |
|
|
|
|
interface WindowState { |
|
|
|
|
tag: string; |
|
|
|
|
templateObjs: templateTypePartial[]; |
|
|
|
|
mainActiveKey: string; |
|
|
|
|
childActiveKey: string; |
|
|
|
|
typeActiveKey: string; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const state = reactive({ |
|
|
|
|
const state = reactive<WindowState>({ |
|
|
|
|
tag: '', |
|
|
|
|
content: '' |
|
|
|
|
templateObjs: [], |
|
|
|
|
mainActiveKey: '', |
|
|
|
|
childActiveKey: '', |
|
|
|
|
typeActiveKey: '' |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const mainTemplateObjs = computed(() => state.templateObjs.filter(item => item.isChild === '0')); |
|
|
|
|
const childTemplateObjs = computed(() => state.templateObjs.filter(item => item.isChild === '1')); |
|
|
|
|
const [registerPromptModal, { openModal: openPromptModal }] = useModal(); |
|
|
|
|
/** https://v3.cn.vuejs.org/api/options-data.html#emits */ |
|
|
|
|
const emit = defineEmits(['success', 'register']); |
|
|
|
|
const [registerForm, { resetFields, setFieldsValue, validate, clearValidate, setProps, updateSchema }] = useForm({ |
|
|
|
@ -31,7 +95,7 @@
@@ -31,7 +95,7 @@
|
|
|
|
|
baseColProps: { span: 24 } |
|
|
|
|
}); |
|
|
|
|
const [registerAceEditor, { setProps: setAceEditorProps }] = useAceEditor({ |
|
|
|
|
lang: 'javascript', |
|
|
|
|
lang: 'velocity', |
|
|
|
|
options: { |
|
|
|
|
useWorker: true, |
|
|
|
|
enableBasicAutocompletion: true, |
|
|
|
@ -58,18 +122,76 @@
@@ -58,18 +122,76 @@
|
|
|
|
|
await setFieldsValue(await getGenCodeTemplateGroup(id)); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
// 尾部:设置处理后的最终配置数据 |
|
|
|
|
setModalProps(props); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
function handleAddTab() { |
|
|
|
|
openPromptModal(true, { _tag: 'add' }); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function handleEditTab() { |
|
|
|
|
openPromptModal(true, { _tag: 'edit' }); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function handleRemoveTab(targetKey: string) { |
|
|
|
|
let lastIndex = 0; |
|
|
|
|
(state.typeActiveKey == '1' ? mainTemplateObjs : childTemplateObjs).value.forEach((item, i) => { |
|
|
|
|
if ((item.index || item.id) == targetKey) { |
|
|
|
|
lastIndex = i - 1; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
state.templateObjs = state.templateObjs.filter(item => (item.index || item.id) != targetKey); |
|
|
|
|
// 当前选择需要删除的tab时候设置自动选择上一个tab |
|
|
|
|
if (state.typeActiveKey == '1') { |
|
|
|
|
if (mainTemplateObjs.value.length && state.mainActiveKey === targetKey) { |
|
|
|
|
if (lastIndex >= 0) { |
|
|
|
|
const mainTemplate = mainTemplateObjs.value[lastIndex]; |
|
|
|
|
state.mainActiveKey = (mainTemplate.index || mainTemplate.id)!; |
|
|
|
|
} else { |
|
|
|
|
const mainTemplate = mainTemplateObjs.value[0]; |
|
|
|
|
state.mainActiveKey = (mainTemplate.index || mainTemplate.id)!; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if (childTemplateObjs.value.length && state.childActiveKey === targetKey) { |
|
|
|
|
if (lastIndex >= 0) { |
|
|
|
|
const childTemplate = childTemplateObjs.value[lastIndex]; |
|
|
|
|
state.childActiveKey = (childTemplate.index || childTemplate.id)!; |
|
|
|
|
} else { |
|
|
|
|
const childTemplate = childTemplateObjs.value[0]; |
|
|
|
|
state.childActiveKey = (childTemplate.index || childTemplate.id)!; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function handlePrompt({ name }) { |
|
|
|
|
const index = state.templateObjs.findIndex(item => (item.index || item.id) == (state.typeActiveKey == '1' ? state.mainActiveKey : state.childActiveKey)); |
|
|
|
|
let template: templateTypePartial = { |
|
|
|
|
name, |
|
|
|
|
contents: '', |
|
|
|
|
isChild: state.typeActiveKey == '1' ? '0' : '1', |
|
|
|
|
index: `t${Date.now()}` |
|
|
|
|
}; |
|
|
|
|
if (index != -1) { |
|
|
|
|
template = Object.assign({}, state.templateObjs[index], { name }); |
|
|
|
|
state.templateObjs.splice(index, 1, template); |
|
|
|
|
} else state.templateObjs.push(template); |
|
|
|
|
// 设置自动选择tab |
|
|
|
|
if (state.typeActiveKey == '1'){ |
|
|
|
|
state.mainActiveKey = (template.index || template.id)!; |
|
|
|
|
} else state.childActiveKey = (template.index || template.id)!; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** 处理弹出框提交 */ |
|
|
|
|
async function handleSubmit() { |
|
|
|
|
try { |
|
|
|
|
// 提取验证数据 |
|
|
|
|
const formData = await validate(); |
|
|
|
|
formData.genCodeTemplateObjList = state.templateObjs; |
|
|
|
|
// 处理提交之前逻辑 |
|
|
|
|
setModalProps({ confirmLoading: true }); |
|
|
|
|
|
|
|
|
|
await saveAndGencodeTemplateObj(formData); |
|
|
|
|
// 处理提交完成之后逻辑 |
|
|
|
|
closeModal(); |
|
|
|
|
emit('success'); |
|
|
|
@ -78,3 +200,35 @@
@@ -78,3 +200,35 @@
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
</script> |
|
|
|
|
<style lang="less" scoped> |
|
|
|
|
.ant-tabs-card { |
|
|
|
|
border: 1px solid #E4E7ED; |
|
|
|
|
|
|
|
|
|
:deep(.ant-tabs-content) { |
|
|
|
|
padding: 0 10px; |
|
|
|
|
min-height: 50px; |
|
|
|
|
|
|
|
|
|
.tool-bar { |
|
|
|
|
margin-bottom: 20px; |
|
|
|
|
.ant-btn { |
|
|
|
|
margin-right: 10px; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
.vue-ace-editor { |
|
|
|
|
min-height: 500px; |
|
|
|
|
font-size: 12px; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
.ant-divider-horizontal { |
|
|
|
|
margin: 10px; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[data-theme='dark'] { |
|
|
|
|
.ant-tabs-card { |
|
|
|
|
border-color: #424242; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
</style> |
|
|
|
|