提交 7909745b 编写于 作者: Mosher's avatar Mosher

update:新增表格新建默认值和更新默认值支持

上级 3a16cf7b
......@@ -15,6 +15,13 @@ export interface GridControlState extends MDControlState {
*/
columnsModel: IParam[];
/**
* @description 新建默认值编辑项
* @type {IParam[]}
* @memberof GridControlState
*/
createDefaultItems: IParam[];
/**
* @description 表格操作列行为模型
* @type {IParam}
......@@ -44,4 +51,11 @@ export interface GridControlState extends MDControlState {
*/
gridAgg: IParam;
/**
* @description 更新默认值编辑项
* @type {IParam[]}
* @memberof GridControlState
*/
updateDefaultItems: IParam[];
}
import { deepCopy, GridControlState, IActionParam, IParam, MDControl } from "@core";
import { DataTypes, dateFormat, deepCopy, GridControlState, IActionParam, IParam, MDControl } from "@core";
import { createUUID } from "qx-util";
import schema, { ErrorList, FieldErrorList } from 'async-validator';
/**
......@@ -493,6 +493,140 @@ export class GridControl extends MDControl {
}
}
/**
* 新建默认值
*
* @protected
* @param {IParam} [row={}]
* @memberof GridControl
*/
protected setCreateDefault(row: IParam = {}): void {
const { createDefaultItems, viewParams, context, items } = this.state;
if (createDefaultItems.length === 0) {
return;
}
createDefaultItems.forEach((item: IParam) => {
const { createDVT, createDV, property, valueFormat, fieldType } = item;
if (createDVT && row.hasOwnProperty(property)) {
switch (createDVT) {
case "CONTEXT":
if (createDV) {
row[property] = viewParams[createDV];
}
break;
case "SESSION":
case "APPDATA":
if (createDV) {
row[property] = context[createDV];
}
break;
case "OPERATORNAME":
row[property] = context["srfusername"];
break;
case "OPERATOR":
row[property] = context["srfuserid"];
break;
case "CURTIME":
row[property] = valueFormat ? dateFormat(new Date(), valueFormat) : new Date();
break;
case "PARAM":
if (item.createDV) {
row[property] = this.computeDefaultValueWithParam("CREATE", item.createDV, row);
}
break;
}
} else if (createDV && row.hasOwnProperty(property)) {
row[property] = fieldType && DataTypes.isNumber(fieldType) ? Number(createDV) : createDV;
}
});
}
/**
* 设置更新默认值
*
* @protected
* @return {*} {void}
* @memberof GridControl
*/
protected setUpdateDefault(): void {
const { updateDefaultItems, viewParams, context, items, controlService } = this.state;
if (updateDefaultItems.length === 0 || items.length === 0) {
return;
}
const setDefault = (row: IParam = {}) => {
updateDefaultItems.forEach((item: IParam) => {
const { updateDV, updateDVT, property, valueFormat, fieldType } = item;
if (updateDVT && row.hasOwnProperty(property)) {
switch (updateDVT) {
case "CONTEXT":
if (updateDV) {
row[property] = viewParams[updateDV];
}
break;
case "SESSION":
case "APPDATA":
if (updateDV) {
row[property] = context[updateDV];
}
break;
case "OPERATORNAME":
row[property] = context["srfusername"];
break;
case "OPERATOR":
row[property] = context["srfuserid"];
break;
case "CURTIME":
row[property] = valueFormat ? dateFormat(new Date(), valueFormat) : new Date();
break;
case "PARAM":
if (item.createDV) {
row[property] = this.computeDefaultValueWithParam("UPDATE", updateDV, row);
}
break;
}
} else if (updateDV && row.hasOwnProperty(property)) {
row[property] = fieldType && DataTypes.isNumber(fieldType) ? Number(updateDV) : updateDV;
}
});
}
items.forEach((item: IParam) => {
if (item.rowDataState == 'update') {
setDefault(item);
}
});
}
/**
* 计算数据对象类型的默认值
* @private
* @param {('UPDATE' | 'CREATE')} action
* @param {string} param
* @param {IParam} row
* @return {*}
* @memberof GridControl
*/
private computeDefaultValueWithParam(action: 'UPDATE' | 'CREATE', param: string, row: IParam) {
const { controlService, appDeKeyFieldName } = this.state;
if (Object.is(action, "UPDATE")) {
const nativeData: any = controlService.getCopynativeData();
if (nativeData && (nativeData instanceof Array) && nativeData.length > 0) {
const targetData: any = nativeData.find((item: any) => {
return item[appDeKeyFieldName.toLowerCase()] === row.srfkey;
});
if (targetData) {
return targetData[param] ? targetData[param] : null;
} else {
return null;
}
} else {
return null;
}
} else {
const remoteData = controlService.getRemoteCopyData()[param];
return remoteData ? remoteData : null;
}
}
/**
* @description 安装部件所有功能模块的方法
* @return {*}
......
......@@ -131,6 +131,7 @@ export class MDControl extends MainControl {
const save = async (opt: any = {}) => {
try {
const { controlService, context, viewParams, showBusyIndicator, items, controlAction } = this.state;
this.setUpdateDefault();
// TODO 值规则校验处理
for (const item of items) {
const { updateAction, createAction } = controlAction;
......@@ -287,6 +288,7 @@ export class MDControl extends MainControl {
action: controlAction.loadDraftAction,
isLoading: showBusyIndicator,
});
this.setCreateDefault(response.data);
if (response.status || response.status == 200) {
items.value = [...items.value, [response.data]];
}
......@@ -400,6 +402,23 @@ export class MDControl extends MainControl {
*/
protected codeListGroupData() { }
/**
* 新建默认值
*
* @protected
* @param {IParam} [row={}]
* @memberof MDControl
*/
protected setCreateDefault(row: IParam = {}): void { }
/**
* 更新默认值
*
* @protected
* @memberof MDControl
*/
protected setUpdateDefault(): void { }
/**
* 获取当前激活数据
*
......
......@@ -24,6 +24,22 @@ export const ctrlState = {
controlName: '{{ctrl.name}}',
appEntityCodeName:'{{ctrl.appEntity.codeName}}',
controlService: new GridService<ControlVO>(ControlVO, new {{pascalCase ctrl.psAppDataEntity.codeName}}Service() ),
// 新建默认值
createDefaultItems: [
{{#each ctrl.psDEGridEditItems as | editItem |}}
{{#if (and editItem.codeName (or editItem.createDV editItem.createDVT))}}
{
createDV: "{{editItem.createDV}}",
createDVT: "{{editItem.createDVT}}",
property: "{{lowerCase editItem.codeName}}",
{{#if editItem.psAppDEField}}
valueFormat: "{{editItem.psAppDEField.valueFormat}}",
fieldType: "{{editItem.psAppDEField.stdDataType}}"
{{/if}}
}{{#unless @last}},{{/unless}}
{{/if}}
{{/each}}
],
items: [],
selectedRowKeys: [],
// 多数据部件分组
......@@ -97,6 +113,22 @@ export const ctrlState = {
],
// 是否单选
isSingleSelect:{{#if ctrl.singleSelect}}{{ctrl.singleSelect}}{{else}}false{{/if}},
// 更新默认值
updateDefaultItems: [
{{#each ctrl.psDEGridEditItems as | editItem |}}
{{#if (and editItem.codeName (or editItem.updateDV editItem.updateDVT))}}
{
updateDV: "{{editItem.updateDV}}",
updateDVT: "{{editItem.updateDVT}}",
property: "{{lowerCase editItem.codeName}}",
{{#if editItem.psAppDEField}}
valueFormat: "{{editItem.psAppDEField.valueFormat}}",
fieldType: "{{editItem.psAppDEField.stdDataType}}"
{{/if}}
}{{#unless @last}},{{/unless}}
{{/if}}
{{/each}}
],
rules:{
{{#each ctrl.psDEGridEditItemVRs as | ruleItem |}}
{{#if (eq ruleItem.valueRuleType 'SYSVALUERULE')}}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册