--添加前端自动生成代码 按钮启用、作废、数据日志
This commit is contained in:
@ -640,6 +640,62 @@
|
|||||||
const loading = ref(true);
|
const loading = ref(true);
|
||||||
const apiConfig = ref({});
|
const apiConfig = ref({});
|
||||||
|
|
||||||
|
|
||||||
|
const handlerEnableAndDisableButtonConfig = ()=>{
|
||||||
|
let hasValid = false;
|
||||||
|
let fields = generatorConfig?.tableStructureConfigs[0]?.tableFieldConfigs;
|
||||||
|
if(fields!=undefined){
|
||||||
|
for (const field of fields) {
|
||||||
|
if(field?.fieldName=='valid'){
|
||||||
|
hasValid = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(hasValid){
|
||||||
|
let hasBtn = false;
|
||||||
|
for (let i = 0; i < generatorConfig.listConfig.buttonConfigs.length; i++) {
|
||||||
|
let btn = generatorConfig.listConfig.buttonConfigs[i];
|
||||||
|
if(btn.code=='enable' || btn.code=='disable'){
|
||||||
|
hasBtn = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!hasBtn){
|
||||||
|
generatorConfig.listConfig.buttonConfigs.splice(2,0,{
|
||||||
|
isUse: true,
|
||||||
|
name: t('启用'),
|
||||||
|
code: 'enable',
|
||||||
|
icon: 'ant-design:form-outlined',
|
||||||
|
isDefault: true,
|
||||||
|
type: 'primary'
|
||||||
|
},{
|
||||||
|
isUse: true,
|
||||||
|
name: t('作废'),
|
||||||
|
code: 'disable',
|
||||||
|
icon: 'ant-design:stop-outlined',
|
||||||
|
isDefault: true,
|
||||||
|
type: 'dashed'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
let dIndex = -1;
|
||||||
|
do {
|
||||||
|
dIndex = -1;
|
||||||
|
for (let i = 0; i < generatorConfig.listConfig.buttonConfigs.length; i++) {
|
||||||
|
let btn = generatorConfig.listConfig.buttonConfigs[i];
|
||||||
|
if(btn.code=='enable' || btn.code=='disable'){
|
||||||
|
dIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(dIndex!=-1){
|
||||||
|
generatorConfig.listConfig.buttonConfigs.splice(dIndex,1);
|
||||||
|
}
|
||||||
|
} while (dIndex!=-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
//如果已经有按钮设置了 就不再添加默认值
|
//如果已经有按钮设置了 就不再添加默认值
|
||||||
if (
|
if (
|
||||||
@ -690,6 +746,13 @@
|
|||||||
icon: 'ant-design:delete-outlined',
|
icon: 'ant-design:delete-outlined',
|
||||||
isDefault: true,
|
isDefault: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
isUse: false,
|
||||||
|
name: t('数据日志'),
|
||||||
|
code: 'datalog',
|
||||||
|
icon: 'ant-design:profile-outlined',
|
||||||
|
isDefault: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
isUse: false,
|
isUse: false,
|
||||||
name: '复制数据',
|
name: '复制数据',
|
||||||
@ -747,6 +810,8 @@
|
|||||||
isDefault: true,
|
isDefault: true,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
handlerEnableAndDisableButtonConfig();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -947,6 +1012,8 @@
|
|||||||
generatorConfig.listConfig.columnConfigs.unshift(...columnConfigs);
|
generatorConfig.listConfig.columnConfigs.unshift(...columnConfigs);
|
||||||
generatorConfig.listConfig.queryConfigs.unshift(...queryConfigs);
|
generatorConfig.listConfig.queryConfigs.unshift(...queryConfigs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handlerEnableAndDisableButtonConfig();
|
||||||
};
|
};
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
|
|||||||
@ -99,6 +99,8 @@ export function buildApiCode(model: GeneratorConfig, _tableInfo: TableInfo[]): s
|
|||||||
const pascalMainTableName = upperFirst(camelCase(camelCaseMainTableName));
|
const pascalMainTableName = upperFirst(camelCase(camelCaseMainTableName));
|
||||||
const hasSetUserIdButton = hasButton(model.listConfig.buttonConfigs, 'batchSetUserId');
|
const hasSetUserIdButton = hasButton(model.listConfig.buttonConfigs, 'batchSetUserId');
|
||||||
const hasExportButton = hasButton(model.listConfig.buttonConfigs, 'export');
|
const hasExportButton = hasButton(model.listConfig.buttonConfigs, 'export');
|
||||||
|
const hasEnableButton = hasButton(model.listConfig.buttonConfigs, 'enable');
|
||||||
|
const hasDataLogButton = hasButton(model.listConfig.buttonConfigs, 'datalog');
|
||||||
|
|
||||||
const code = `
|
const code = `
|
||||||
import { ${pascalMainTableName}PageModel, ${pascalMainTableName}PageParams, ${pascalMainTableName}PageResult } from './model/${pascalClassName}Model';
|
import { ${pascalMainTableName}PageModel, ${pascalMainTableName}PageParams, ${pascalMainTableName}PageResult } from './model/${pascalClassName}Model';
|
||||||
@ -122,6 +124,19 @@ enum Api {
|
|||||||
Export = '/${model.outputConfig.outputValue}/${lowerFirstPascalClassName}/export',`
|
Export = '/${model.outputConfig.outputValue}/${lowerFirstPascalClassName}/export',`
|
||||||
: ''
|
: ''
|
||||||
}
|
}
|
||||||
|
${
|
||||||
|
hasEnableButton
|
||||||
|
? `
|
||||||
|
Enable = '/${model.outputConfig.outputValue}/${lowerFirstPascalClassName}/enable',
|
||||||
|
Disable= '/${model.outputConfig.outputValue}/${lowerFirstPascalClassName}/disable',`
|
||||||
|
: ''
|
||||||
|
}
|
||||||
|
${
|
||||||
|
hasDataLogButton
|
||||||
|
? `
|
||||||
|
DataLog = '/${model.outputConfig.outputValue}/${lowerFirstPascalClassName}/datalog',`
|
||||||
|
: ''
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -199,6 +214,62 @@ export async function delete${pascalMainTableName}(ids: string[], mode: ErrorMes
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
${
|
||||||
|
hasEnableButton
|
||||||
|
? `
|
||||||
|
/**
|
||||||
|
* @description: 启用数据${pascalMainTableName}
|
||||||
|
*/
|
||||||
|
export async function enable${pascalMainTableName}(ids: string[], mode: ErrorMessageMode = 'modal') {
|
||||||
|
return defHttp.post<boolean>(
|
||||||
|
{
|
||||||
|
url: Api.Enable,
|
||||||
|
data: ids,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
errorMessageMode: mode,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @description: 作废数据${pascalMainTableName}
|
||||||
|
*/
|
||||||
|
export async function disable${pascalMainTableName}(ids: string[], mode: ErrorMessageMode = 'modal') {
|
||||||
|
return defHttp.post<boolean>(
|
||||||
|
{
|
||||||
|
url: Api.Disable,
|
||||||
|
data: ids,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
errorMessageMode: mode,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
`
|
||||||
|
: ''
|
||||||
|
}
|
||||||
|
|
||||||
|
${
|
||||||
|
hasDataLogButton?
|
||||||
|
`
|
||||||
|
/**
|
||||||
|
* @description: 获取数据日志${pascalMainTableName}
|
||||||
|
*/
|
||||||
|
export async function getDataLog${pascalMainTableName}(id: string, mode: ErrorMessageMode = 'modal') {
|
||||||
|
return defHttp.post<boolean>(
|
||||||
|
{
|
||||||
|
url: Api.Datalog,
|
||||||
|
data: id,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
errorMessageMode: mode,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
`
|
||||||
|
:''
|
||||||
|
}
|
||||||
|
|
||||||
${
|
${
|
||||||
hasSetUserIdButton
|
hasSetUserIdButton
|
||||||
? `
|
? `
|
||||||
@ -469,6 +540,8 @@ export function buildListCode(model: GeneratorConfig): string {
|
|||||||
const hasCopyDataButton = hasButton(buttonConfigs, 'copyData');
|
const hasCopyDataButton = hasButton(buttonConfigs, 'copyData');
|
||||||
const hasTemplatePrint = hasButton(buttonConfigs, PrintButton.CODE);
|
const hasTemplatePrint = hasButton(buttonConfigs, PrintButton.CODE);
|
||||||
const isSetDataAuth = model.outputConfig.isDataAuth;
|
const isSetDataAuth = model.outputConfig.isDataAuth;
|
||||||
|
const hasEnableButton = hasButton(buttonConfigs, 'enable');
|
||||||
|
const hasDataLogButton = hasButton(buttonConfigs, 'datalog');
|
||||||
|
|
||||||
//判断是否有用到数据源数据字典的组件
|
//判断是否有用到数据源数据字典的组件
|
||||||
const code = `
|
const code = `
|
||||||
@ -777,7 +850,7 @@ ${hasTemplatePrint ? ' reactive ' : ''}
|
|||||||
//所有按钮
|
//所有按钮
|
||||||
const buttons = ref(${JSON.stringify(model.listConfig.buttonConfigs.filter((x) => x.isUse))});
|
const buttons = ref(${JSON.stringify(model.listConfig.buttonConfigs.filter((x) => x.isUse))});
|
||||||
//展示在列表内的按钮
|
//展示在列表内的按钮
|
||||||
const actionButtons = ref<string[]>(['view', 'edit', 'copyData', 'delete', 'startwork','flowRecord']);
|
const actionButtons = ref<string[]>(['view', 'edit','datalog', 'copyData', 'delete', 'startwork','flowRecord']);
|
||||||
const buttonConfigs = computed(()=>{
|
const buttonConfigs = computed(()=>{
|
||||||
return filterButtonAuth(buttons.value);
|
return filterButtonAuth(buttons.value);
|
||||||
})
|
})
|
||||||
@ -1108,6 +1181,66 @@ ${hasTemplatePrint ? ' reactive ' : ''}
|
|||||||
}`
|
}`
|
||||||
: ''
|
: ''
|
||||||
}
|
}
|
||||||
|
${
|
||||||
|
hasEnableButton?`
|
||||||
|
function handleEnable() {
|
||||||
|
if (!selectedKeys.value.length) {
|
||||||
|
notification.warning({
|
||||||
|
message: 'Tip',
|
||||||
|
description: t('请选择需要启用的数据'),
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let ids = selectedKeys.value;
|
||||||
|
Modal.confirm({
|
||||||
|
title: '提示信息',
|
||||||
|
icon: createVNode(ExclamationCircleOutlined),
|
||||||
|
content: '是否确认启用?',
|
||||||
|
okText: '确认',
|
||||||
|
cancelText: '取消',
|
||||||
|
onOk() {
|
||||||
|
enable${pascalMainTableName}(ids).then((_) => {
|
||||||
|
handleSuccess();
|
||||||
|
notification.success({
|
||||||
|
message: 'Tip',
|
||||||
|
description: t('启用成功!'),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onCancel() {},
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
function handleDisable() {
|
||||||
|
if (!selectedKeys.value.length) {
|
||||||
|
notification.warning({
|
||||||
|
message: 'Tip',
|
||||||
|
description: t('请选择需要禁用的数据'),
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let ids = selectedKeys.value;
|
||||||
|
Modal.confirm({
|
||||||
|
title: '提示信息',
|
||||||
|
icon: createVNode(ExclamationCircleOutlined),
|
||||||
|
content: '是否确认禁用?',
|
||||||
|
okText: '确认',
|
||||||
|
cancelText: '取消',
|
||||||
|
onOk() {
|
||||||
|
disable${pascalMainTableName}(ids).then((_) => {
|
||||||
|
handleSuccess();
|
||||||
|
notification.success({
|
||||||
|
message: 'Tip',
|
||||||
|
description: t('禁用成功!'),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onCancel() {},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
`: ''
|
||||||
|
}
|
||||||
${
|
${
|
||||||
hasBatchDeleteButton
|
hasBatchDeleteButton
|
||||||
? `
|
? `
|
||||||
|
|||||||
Reference in New Issue
Block a user