个性化配置:1.代码生成器跟个性化配置相关的代码优化
2.进入表单详情页时,改成通过菜单的组件路径获取formId。
This commit is contained in:
@ -11,6 +11,7 @@ enum Api {
|
||||
SimpleTree = '/system/menu/simple-tree',
|
||||
TenantSimpleTree = '/system/menu/tenant-auth-tree',
|
||||
Menu = '/system/menu',
|
||||
MenuInfoByComponentPath = '/system/menu/info-by-component-path',
|
||||
Button = '/system/menu/button',
|
||||
Column = '/system/menu-colum/list',
|
||||
Form = '/system/menu-form/list',
|
||||
@ -197,3 +198,21 @@ export async function getMenuFormById(params, mode: ErrorMessageMode = 'modal')
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 根据组件路径查询菜单
|
||||
*/
|
||||
export async function getMenuByIdComponentPath(componentPath:String, mode: ErrorMessageMode = 'modal') {
|
||||
return defHttp.get<MenuModel[]>(
|
||||
{
|
||||
url: Api.MenuInfoByComponentPath,
|
||||
params:{componentPath}
|
||||
},
|
||||
{
|
||||
errorMessageMode: mode,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
import { FormSchema } from '/@/components/Form';
|
||||
import { BasicColumn } from "/@/components/Table";
|
||||
import { getFormTemplateUsingCache } from '/@/api/form/design';
|
||||
import { getMenuByIdComponentPath } from '/@/api/system/menu';
|
||||
import { deepMerge } from '/@/utils';
|
||||
import { useI18n } from '/@/hooks/web/useI18n';
|
||||
import { useMessage } from '/@/hooks/web/useMessage';
|
||||
@ -10,9 +11,9 @@ const { t } = useI18n();
|
||||
const { notification } = useMessage();
|
||||
|
||||
export function useFormConfig() {
|
||||
async function mergeFormSchemas(formSchema: FormSchema[],formId:String){
|
||||
async function mergeFormSchemas(formSchema: FormSchema[],formPath:String){
|
||||
try{
|
||||
const formProps=await queryConfig(formId,'formProps');
|
||||
const formProps=await queryConfigByFormPath(formPath,'formProps');
|
||||
let fschemas=formProps?.schemas;
|
||||
if(fschemas&&fschemas.length>0){
|
||||
return deepMerge(formSchema,fschemas);
|
||||
@ -20,14 +21,20 @@ export function useFormConfig() {
|
||||
return formSchema;
|
||||
}
|
||||
}catch(e){
|
||||
notification.error({
|
||||
message: t('提示'),
|
||||
description: '解析表单渲染覆盖配置出错[解析formProps发生异常]',
|
||||
});
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
async function mergeFormEventConfigs(formEventConfigs,componentPath:String){
|
||||
try{
|
||||
const fEConfigs=await queryConfigByFormPath(componentPath,'formEventConfigs');
|
||||
return deepMerge(formEventConfigs,fEConfigs);
|
||||
}catch(e){
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function mergeColumns(columns: BasicColumn[],formId:String){
|
||||
try{
|
||||
const cols=await queryConfig(formId,'columns');
|
||||
@ -40,10 +47,6 @@ export function useFormConfig() {
|
||||
return columns;
|
||||
}
|
||||
}catch(e){
|
||||
notification.error({
|
||||
message: t('提示'),
|
||||
description: '解析表单渲染覆盖配置出错[解析columns发生异常]',
|
||||
});
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@ -60,10 +63,6 @@ export function useFormConfig() {
|
||||
return searchFormSchema;
|
||||
}
|
||||
}catch(e){
|
||||
notification.error({
|
||||
message: t('提示'),
|
||||
description: '解析表单渲染覆盖配置出错[解析searchFormSchema发生异常]',
|
||||
});
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@ -77,14 +76,31 @@ export function useFormConfig() {
|
||||
return buttons;
|
||||
}
|
||||
}catch(e){
|
||||
notification.error({
|
||||
message: t('提示'),
|
||||
description: '解析表单渲染覆盖配置出错[解析buttons发生异常]',
|
||||
});
|
||||
return[];
|
||||
}
|
||||
}
|
||||
|
||||
async function queryConfigByFormPath(componentPath:String,configName:String){
|
||||
if(componentPath==null){
|
||||
notification.error({
|
||||
message: t('提示'),
|
||||
description: `发生异常,组件路径不能为空!`,
|
||||
});
|
||||
throw new Error('发生异常,组件路径不能为空!');
|
||||
}
|
||||
const menu=await getMenuByIdComponentPath("/"+componentPath+"/index");
|
||||
if(menu==null){
|
||||
notification.error({
|
||||
message: t('提示'),
|
||||
description: `发生异常,根据组件路径找不到菜单!`,
|
||||
});
|
||||
throw new Error('发生异常,根据组件路径找不到菜单!');
|
||||
}
|
||||
const formId=menu.formId;
|
||||
|
||||
return await queryConfig(formId,configName);
|
||||
|
||||
}
|
||||
|
||||
async function queryConfig(formId:String,configName:String){
|
||||
const formTemplate = await getFormTemplateUsingCache(formId);
|
||||
@ -100,6 +116,10 @@ export function useFormConfig() {
|
||||
return value;
|
||||
} catch (e) {
|
||||
console.error(`Failed to parse ${varName}:`, e);
|
||||
notification.error({
|
||||
message: t('提示'),
|
||||
description: `解析表单渲染覆盖配置出错[解析${configName}发生异常]`,
|
||||
});
|
||||
throw new Error('解析表单渲染覆盖配置出错,请联系管理员处理');
|
||||
}
|
||||
}
|
||||
@ -111,6 +131,7 @@ export function useFormConfig() {
|
||||
mergeFormSchemas,
|
||||
mergeColumns,
|
||||
mergeSearchFormSchema,
|
||||
mergeButtons
|
||||
mergeButtons,
|
||||
mergeFormEventConfigs
|
||||
};
|
||||
}
|
||||
|
||||
@ -1453,9 +1453,9 @@ ${hasTemplatePrint ? ' reactive ' : ''}
|
||||
} else {
|
||||
bus.on(FORM_LIST_MODIFIED, handleRefresh);
|
||||
}
|
||||
setCustomConfigColumns();
|
||||
setCustomSearchFormSchema();
|
||||
setCustomButtons();
|
||||
|
||||
// 合并渲染覆盖配置中的列表配置,包括展示字段配置、搜索字段配置、按钮配置
|
||||
mergeCustomListRenderConfig();
|
||||
});
|
||||
onUnmounted(() => {
|
||||
if (schemaIdComputedRef.value) {
|
||||
@ -1604,26 +1604,20 @@ ${hasTemplatePrint ? ' reactive ' : ''}
|
||||
: ''
|
||||
}
|
||||
|
||||
async function setCustomConfigColumns(){
|
||||
async function mergeCustomListRenderConfig(){
|
||||
if (formConfig.useCustomConfig) {
|
||||
const cols= await mergeColumns(customConfigColums.value,currentRoute.value.meta.formId);
|
||||
customConfigColums.value=cols;
|
||||
let formId=currentRoute.value.meta.formId;
|
||||
//1.合并展示字段配置
|
||||
let cols= await mergeColumns(customConfigColums.value,formId);
|
||||
customConfigColums.value=cols;
|
||||
//2.合并搜索字段配置
|
||||
let sFormSchema= await mergeSearchFormSchema(customSearchFormSchema.value,formId);
|
||||
customSearchFormSchema.value=sFormSchema;
|
||||
//3.合并按钮配置
|
||||
let btns= await mergeButtons(buttons.value,formId);
|
||||
buttons.value=btns;
|
||||
}
|
||||
};
|
||||
|
||||
async function setCustomSearchFormSchema(){
|
||||
if (formConfig.useCustomConfig) {
|
||||
const cols= await mergeSearchFormSchema(customSearchFormSchema.value,currentRoute.value.meta.formId);
|
||||
customSearchFormSchema.value=cols;
|
||||
}
|
||||
};
|
||||
|
||||
async function setCustomButtons(){
|
||||
if (formConfig.useCustomConfig) {
|
||||
const btns= await mergeButtons(buttons.value,currentRoute.value.meta.formId);
|
||||
buttons.value=btns;
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<style lang="less" scoped>
|
||||
:deep(.ant-table-selection-col) {
|
||||
@ -1694,7 +1688,7 @@ export function buildSimpleFormCode(model: GeneratorConfig, _tableInfo: TableInf
|
||||
import { useRouter } from 'vue-router';
|
||||
|
||||
const { filterFormSchemaAuth } = usePermission();
|
||||
const { mergeFormSchemas } = useFormConfig();
|
||||
const { mergeFormSchemas,mergeFormEventConfigs } = useFormConfig();
|
||||
const { currentRoute } = useRouter();
|
||||
|
||||
const RowKey = '${mainTable.pkField ? camelCase(mainTable.pkField) : 'id'}';
|
||||
@ -1713,16 +1707,19 @@ export function buildSimpleFormCode(model: GeneratorConfig, _tableInfo: TableInf
|
||||
formModel: {},
|
||||
});
|
||||
|
||||
let customFormEventConfigs=[];
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
await setCustomFormSchemas();
|
||||
// 合并渲染覆盖配置中的字段配置、表单事件配置
|
||||
await mergeCustomFormRenderConfig();
|
||||
|
||||
if (props.fromPage == FromPageType.MENU) {
|
||||
setMenuPermission();
|
||||
await createFormEvent(formEventConfigs, state.formModel,
|
||||
await createFormEvent(customFormEventConfigs, state.formModel,
|
||||
systemFormRef.value,
|
||||
formProps.schemas); //表单事件:初始化表单
|
||||
await loadFormEvent(formEventConfigs, state.formModel,
|
||||
await loadFormEvent(customFormEventConfigs, state.formModel,
|
||||
systemFormRef.value,
|
||||
formProps.schemas); //表单事件:加载表单
|
||||
} else if (props.fromPage == FromPageType.FLOW) {
|
||||
@ -1733,10 +1730,10 @@ export function buildSimpleFormCode(model: GeneratorConfig, _tableInfo: TableInf
|
||||
} else if (props.fromPage == FromPageType.DESKTOP) {
|
||||
// 桌面设计 表单事件需要执行
|
||||
emits('loadingCompleted'); //告诉系统表单已经加载完毕
|
||||
await createFormEvent(formEventConfigs, state.formModel,
|
||||
await createFormEvent(customFormEventConfigs, state.formModel,
|
||||
systemFormRef.value,
|
||||
formProps.schemas); //表单事件:初始化表单
|
||||
await loadFormEvent(formEventConfigs, state.formModel,
|
||||
await loadFormEvent(customFormEventConfigs, state.formModel,
|
||||
systemFormRef.value,
|
||||
formProps.schemas); //表单事件:加载表单
|
||||
}
|
||||
@ -1746,16 +1743,21 @@ export function buildSimpleFormCode(model: GeneratorConfig, _tableInfo: TableInf
|
||||
}
|
||||
});
|
||||
|
||||
// 根据渲染覆盖配置设置表单属性
|
||||
async function setCustomFormSchemas() {
|
||||
const cloneProps=cloneDeep(formProps);
|
||||
|
||||
async function mergeCustomFormRenderConfig() {
|
||||
let cloneProps=cloneDeep(formProps);
|
||||
let fEventConfigs=cloneDeep(formEventConfigs);
|
||||
if (formConfig.useCustomConfig) {
|
||||
let formId=currentRoute.value.query.formId;
|
||||
if(props.fromPage !== FromPageType.FLOW){
|
||||
cloneProps.schemas=await mergeFormSchemas(cloneProps.schemas!,currentRoute.value.query.formId);
|
||||
let formPath=currentRoute.value.query.formPath;
|
||||
//1.合并字段配置
|
||||
cloneProps.schemas=await mergeFormSchemas(cloneProps.schemas!,formPath);
|
||||
//2.合并表单事件配置
|
||||
fEventConfigs=await mergeFormEventConfigs(fEventConfigs,formPath);
|
||||
}
|
||||
}
|
||||
data.formDataProps=cloneProps;
|
||||
customFormEventConfigs=fEventConfigs;
|
||||
}
|
||||
|
||||
// 根据菜单页面权限,设置表单属性(必填,禁用,显示)
|
||||
@ -1787,7 +1789,7 @@ export function buildSimpleFormCode(model: GeneratorConfig, _tableInfo: TableInf
|
||||
}
|
||||
setFieldsValue(record);
|
||||
state.formModel = record;
|
||||
await getFormDataEvent(formEventConfigs, state.formModel, systemFormRef.value, formProps.schemas); //表单事件:获取表单数据
|
||||
await getFormDataEvent(customFormEventConfigs, state.formModel, systemFormRef.value, formProps.schemas); //表单事件:获取表单数据
|
||||
return record;
|
||||
} catch (error) {
|
||||
|
||||
@ -1815,7 +1817,7 @@ export function buildSimpleFormCode(model: GeneratorConfig, _tableInfo: TableInf
|
||||
values[RowKey] = rowId;
|
||||
state.formModel = values;
|
||||
let saveVal = await update${pascalMainTableName}(values);
|
||||
await submitFormEvent(formEventConfigs, state.formModel,
|
||||
await submitFormEvent(customFormEventConfigs, state.formModel,
|
||||
systemFormRef.value,
|
||||
formProps.schemas); //表单事件:提交表单
|
||||
return saveVal;
|
||||
@ -1826,7 +1828,7 @@ export function buildSimpleFormCode(model: GeneratorConfig, _tableInfo: TableInf
|
||||
try {
|
||||
state.formModel = values;
|
||||
let saveVal = await add${pascalMainTableName}(values);
|
||||
await submitFormEvent(formEventConfigs, state.formModel,
|
||||
await submitFormEvent(customFormEventConfigs, state.formModel,
|
||||
systemFormRef.value,
|
||||
formProps.schemas); //表单事件:提交表单
|
||||
return saveVal;
|
||||
@ -1836,10 +1838,12 @@ export function buildSimpleFormCode(model: GeneratorConfig, _tableInfo: TableInf
|
||||
async function setWorkFlowForm(obj: WorkFlowFormParams) {
|
||||
try {
|
||||
const cloneProps=cloneDeep(formProps);
|
||||
customFormEventConfigs=cloneDeep(formEventConfigs);
|
||||
if (formConfig.useCustomConfig) {
|
||||
const parts = obj.formConfigKey.split('_');
|
||||
const formId=parts[1];
|
||||
cloneProps.schemas=await mergeFormSchemas(cloneProps.schemas!,formId);
|
||||
customFormEventConfigs=await mergeFormEventConfigs(customFormEventConfigs,formId);
|
||||
}
|
||||
|
||||
let flowData = changeWorkFlowForm(cloneProps, obj);
|
||||
@ -1856,10 +1860,10 @@ export function buildSimpleFormCode(model: GeneratorConfig, _tableInfo: TableInf
|
||||
setFieldsValue(formModels)
|
||||
}
|
||||
} catch (error) {}
|
||||
await createFormEvent(formEventConfigs, state.formModel,
|
||||
await createFormEvent(customFormEventConfigs, state.formModel,
|
||||
systemFormRef.value,
|
||||
formProps.schemas); //表单事件:初始化表单
|
||||
await loadFormEvent(formEventConfigs, state.formModel,
|
||||
await loadFormEvent(customFormEventConfigs, state.formModel,
|
||||
systemFormRef.value,
|
||||
formProps.schemas); //表单事件:加载表单
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user