2022-07-18 19:06:37 +08:00
|
|
|
|
<script setup lang="ts">
|
2022-09-21 16:17:53 +08:00
|
|
|
|
import { onMounted, PropType, reactive, ref, watch } from 'vue'
|
2022-07-18 19:06:37 +08:00
|
|
|
|
import { required } from '@/utils/formRules'
|
|
|
|
|
import { Form } from '@/components/Form'
|
2022-09-21 16:17:53 +08:00
|
|
|
|
import { handleTree } from '@/utils/tree'
|
|
|
|
|
import { ElTreeSelect } from 'element-plus'
|
2022-07-18 19:06:37 +08:00
|
|
|
|
import { useForm } from '@/hooks/web/useForm'
|
2022-07-28 21:40:15 +08:00
|
|
|
|
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
|
2022-09-21 16:17:53 +08:00
|
|
|
|
import { listSimpleMenusApi } from '@/api/system/menu'
|
|
|
|
|
import { CodegenTableVO } from '@/api/infra/codegen/types'
|
2022-10-11 16:02:28 +08:00
|
|
|
|
import { FormSchema } from '@/types/form'
|
2022-07-18 19:06:37 +08:00
|
|
|
|
const props = defineProps({
|
2022-07-28 21:40:15 +08:00
|
|
|
|
genInfo: {
|
2022-07-18 19:06:37 +08:00
|
|
|
|
type: Object as PropType<Nullable<CodegenTableVO>>,
|
|
|
|
|
default: () => null
|
|
|
|
|
}
|
|
|
|
|
})
|
2022-09-21 16:17:53 +08:00
|
|
|
|
const defaultProps = {
|
|
|
|
|
children: 'children',
|
|
|
|
|
label: 'name',
|
|
|
|
|
value: 'id'
|
|
|
|
|
}
|
2022-07-18 19:06:37 +08:00
|
|
|
|
const rules = reactive({
|
|
|
|
|
templateType: [required],
|
|
|
|
|
scene: [required],
|
|
|
|
|
moduleName: [required],
|
|
|
|
|
businessName: [required],
|
|
|
|
|
businessPackage: [required],
|
|
|
|
|
className: [required],
|
|
|
|
|
classComment: [required]
|
|
|
|
|
})
|
2022-07-28 21:40:15 +08:00
|
|
|
|
const templateTypeOptions = getIntDictOptions(DICT_TYPE.INFRA_CODEGEN_TEMPLATE_TYPE)
|
|
|
|
|
const sceneOptions = getIntDictOptions(DICT_TYPE.INFRA_CODEGEN_SCENE)
|
2022-09-21 16:17:53 +08:00
|
|
|
|
const parentMenuId = ref()
|
|
|
|
|
const treeRef = ref<InstanceType<typeof ElTreeSelect>>()
|
|
|
|
|
const menuOptions = ref<any>([]) // 树形结构
|
|
|
|
|
const getTree = async () => {
|
|
|
|
|
const res = await listSimpleMenusApi()
|
|
|
|
|
menuOptions.value = handleTree(res)
|
|
|
|
|
}
|
2022-07-18 19:06:37 +08:00
|
|
|
|
const schema = reactive<FormSchema[]>([
|
|
|
|
|
{
|
|
|
|
|
label: '生成模板',
|
|
|
|
|
field: 'templateType',
|
|
|
|
|
component: 'Select',
|
|
|
|
|
componentProps: {
|
2022-07-28 21:40:15 +08:00
|
|
|
|
options: templateTypeOptions
|
2022-07-18 19:06:37 +08:00
|
|
|
|
},
|
|
|
|
|
colProps: {
|
|
|
|
|
span: 12
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: '生成场景',
|
|
|
|
|
field: 'scene',
|
|
|
|
|
component: 'Select',
|
|
|
|
|
componentProps: {
|
2022-07-28 21:40:15 +08:00
|
|
|
|
options: sceneOptions
|
2022-07-18 19:06:37 +08:00
|
|
|
|
},
|
|
|
|
|
colProps: {
|
|
|
|
|
span: 12
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: '模块名',
|
|
|
|
|
field: 'moduleName',
|
|
|
|
|
component: 'Input',
|
2022-07-25 16:53:36 +08:00
|
|
|
|
labelMessage: '模块名,即一级目录,例如 system、infra、tool 等等',
|
2022-07-18 19:06:37 +08:00
|
|
|
|
colProps: {
|
|
|
|
|
span: 12
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: '业务名',
|
|
|
|
|
field: 'businessName',
|
|
|
|
|
component: 'Input',
|
2022-07-25 16:53:36 +08:00
|
|
|
|
labelMessage: '业务名,即二级目录,例如 user、permission、dict 等等',
|
2022-07-18 19:06:37 +08:00
|
|
|
|
colProps: {
|
|
|
|
|
span: 12
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: '类名称',
|
|
|
|
|
field: 'className',
|
|
|
|
|
component: 'Input',
|
2022-07-25 16:53:36 +08:00
|
|
|
|
labelMessage: '类名称(首字母大写),例如SysUser、SysMenu、SysDictData 等等',
|
2022-07-18 19:06:37 +08:00
|
|
|
|
colProps: {
|
|
|
|
|
span: 12
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: '类描述',
|
|
|
|
|
field: 'classComment',
|
|
|
|
|
component: 'Input',
|
2022-07-25 16:53:36 +08:00
|
|
|
|
labelMessage: '用作类描述,例如 用户',
|
2022-07-18 19:06:37 +08:00
|
|
|
|
colProps: {
|
|
|
|
|
span: 12
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: '上级菜单',
|
|
|
|
|
field: 'parentMenuId',
|
2022-09-21 16:17:53 +08:00
|
|
|
|
componentProps: {
|
|
|
|
|
optionsSlot: true
|
|
|
|
|
},
|
2022-07-25 16:53:36 +08:00
|
|
|
|
labelMessage: '分配到指定菜单下,例如 系统管理',
|
2022-07-18 19:06:37 +08:00
|
|
|
|
colProps: {
|
|
|
|
|
span: 12
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
])
|
|
|
|
|
const { register, methods, elFormRef } = useForm({
|
|
|
|
|
schema
|
|
|
|
|
})
|
2022-09-21 16:17:53 +08:00
|
|
|
|
const handleNodeClick = () => {
|
|
|
|
|
console.log(parentMenuId.value)
|
|
|
|
|
}
|
|
|
|
|
// ========== 初始化 ==========
|
|
|
|
|
onMounted(async () => {
|
|
|
|
|
await getTree()
|
|
|
|
|
})
|
2022-07-18 19:06:37 +08:00
|
|
|
|
watch(
|
2022-07-28 21:40:15 +08:00
|
|
|
|
() => props.genInfo,
|
|
|
|
|
(genInfo) => {
|
|
|
|
|
if (!genInfo) return
|
2022-07-18 19:06:37 +08:00
|
|
|
|
const { setValues } = methods
|
2022-07-28 21:40:15 +08:00
|
|
|
|
setValues(genInfo)
|
2022-07-18 19:06:37 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
deep: true,
|
|
|
|
|
immediate: true
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
defineExpose({
|
|
|
|
|
elFormRef,
|
|
|
|
|
getFormData: methods.getFormData
|
|
|
|
|
})
|
|
|
|
|
</script>
|
|
|
|
|
<template>
|
2022-09-21 16:17:53 +08:00
|
|
|
|
<Form :rules="rules" @register="register">
|
|
|
|
|
<template #parentMenuId>
|
|
|
|
|
<el-tree-select
|
|
|
|
|
v-model="parentMenuId"
|
|
|
|
|
ref="treeRef"
|
|
|
|
|
node-key="id"
|
|
|
|
|
check-on-click-node
|
|
|
|
|
expand-on-click-node="false"
|
|
|
|
|
:props="defaultProps"
|
|
|
|
|
:data="menuOptions"
|
|
|
|
|
@node-click="handleNodeClick"
|
|
|
|
|
/>
|
|
|
|
|
</template>
|
|
|
|
|
</Form>
|
2022-07-18 19:06:37 +08:00
|
|
|
|
</template>
|