mirror of
				https://github.com/YunaiV/ruoyi-vue-pro.git
				synced 2025-11-04 16:17:40 +08:00 
			
		
		
		
	perf: 重构代码生成 优化性能
This commit is contained in:
		@ -2,23 +2,42 @@
 | 
			
		||||
  <Form :rules="rules" @register="register" />
 | 
			
		||||
</template>
 | 
			
		||||
<script setup lang="ts">
 | 
			
		||||
import { PropType, reactive, watch } from 'vue'
 | 
			
		||||
import { onMounted, PropType, reactive, ref, watch } from 'vue'
 | 
			
		||||
import { required } from '@/utils/formRules'
 | 
			
		||||
import { useForm } from '@/hooks/web/useForm'
 | 
			
		||||
import { Form } from '@/components/Form'
 | 
			
		||||
import { FormSchema } from '@/types/form'
 | 
			
		||||
import { CodegenTableVO } from '@/api/infra/codegen/types'
 | 
			
		||||
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
 | 
			
		||||
import { listSimpleMenusApi } from '@/api/system/menu'
 | 
			
		||||
import { handleTree, defaultProps } from '@/utils/tree'
 | 
			
		||||
 | 
			
		||||
const props = defineProps({
 | 
			
		||||
  basicInfo: {
 | 
			
		||||
    type: Object as PropType<Nullable<CodegenTableVO>>,
 | 
			
		||||
    default: () => null
 | 
			
		||||
  }
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
const templateTypeOptions = getIntDictOptions(DICT_TYPE.INFRA_CODEGEN_TEMPLATE_TYPE)
 | 
			
		||||
const sceneOptions = getIntDictOptions(DICT_TYPE.INFRA_CODEGEN_SCENE)
 | 
			
		||||
const menuOptions = ref<any>([]) // 树形结构
 | 
			
		||||
const getTree = async () => {
 | 
			
		||||
  const res = await listSimpleMenusApi()
 | 
			
		||||
  menuOptions.value = handleTree(res)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const rules = reactive({
 | 
			
		||||
  tableName: [required],
 | 
			
		||||
  tableComment: [required],
 | 
			
		||||
  className: [required],
 | 
			
		||||
  author: [required]
 | 
			
		||||
  author: [required],
 | 
			
		||||
  templateType: [required],
 | 
			
		||||
  scene: [required],
 | 
			
		||||
  moduleName: [required],
 | 
			
		||||
  businessName: [required],
 | 
			
		||||
  businessPackage: [required],
 | 
			
		||||
  classComment: [required]
 | 
			
		||||
})
 | 
			
		||||
const schema = reactive<FormSchema[]>([
 | 
			
		||||
  {
 | 
			
		||||
@ -45,6 +64,79 @@ const schema = reactive<FormSchema[]>([
 | 
			
		||||
      span: 12
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    label: '生成模板',
 | 
			
		||||
    field: 'templateType',
 | 
			
		||||
    component: 'Select',
 | 
			
		||||
    componentProps: {
 | 
			
		||||
      options: templateTypeOptions
 | 
			
		||||
    },
 | 
			
		||||
    colProps: {
 | 
			
		||||
      span: 12
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    label: '生成场景',
 | 
			
		||||
    field: 'scene',
 | 
			
		||||
    component: 'Select',
 | 
			
		||||
    componentProps: {
 | 
			
		||||
      options: sceneOptions
 | 
			
		||||
    },
 | 
			
		||||
    colProps: {
 | 
			
		||||
      span: 12
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    label: '模块名',
 | 
			
		||||
    field: 'moduleName',
 | 
			
		||||
    component: 'Input',
 | 
			
		||||
    labelMessage: '模块名,即一级目录,例如 system、infra、tool 等等',
 | 
			
		||||
    colProps: {
 | 
			
		||||
      span: 12
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    label: '业务名',
 | 
			
		||||
    field: 'businessName',
 | 
			
		||||
    component: 'Input',
 | 
			
		||||
    labelMessage: '业务名,即二级目录,例如 user、permission、dict 等等',
 | 
			
		||||
    colProps: {
 | 
			
		||||
      span: 12
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    label: '类名称',
 | 
			
		||||
    field: 'className',
 | 
			
		||||
    component: 'Input',
 | 
			
		||||
    labelMessage: '类名称(首字母大写),例如SysUser、SysMenu、SysDictData 等等',
 | 
			
		||||
    colProps: {
 | 
			
		||||
      span: 12
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    label: '类描述',
 | 
			
		||||
    field: 'classComment',
 | 
			
		||||
    component: 'Input',
 | 
			
		||||
    labelMessage: '用作类描述,例如 用户',
 | 
			
		||||
    colProps: {
 | 
			
		||||
      span: 12
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    label: '上级菜单',
 | 
			
		||||
    field: 'parentMenuId',
 | 
			
		||||
    component: 'TreeSelect',
 | 
			
		||||
    componentProps: {
 | 
			
		||||
      data: menuOptions,
 | 
			
		||||
      props: defaultProps,
 | 
			
		||||
      checkStrictly: true,
 | 
			
		||||
      nodeKey: 'id'
 | 
			
		||||
    },
 | 
			
		||||
    labelMessage: '分配到指定菜单下,例如 系统管理',
 | 
			
		||||
    colProps: {
 | 
			
		||||
      span: 12
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    label: '作者',
 | 
			
		||||
    field: 'author',
 | 
			
		||||
@ -81,6 +173,10 @@ watch(
 | 
			
		||||
    immediate: true
 | 
			
		||||
  }
 | 
			
		||||
)
 | 
			
		||||
// ========== 初始化 ==========
 | 
			
		||||
onMounted(async () => {
 | 
			
		||||
  await getTree()
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
defineExpose({
 | 
			
		||||
  elFormRef,
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user