提交 d126eec2 编写于 作者: RedPig97's avatar RedPig97

update: 表格更新项

上级 c772e4e1
......@@ -41,6 +41,22 @@
{{#if editColumn.valueItemName}}
valueItemName: "{{editColumn.valueItemName}}",
{{/if}}
{{#each ctrl.psDEGridEditItemUpdates as | updateItem | }}
{{#if (eq updateItem.codeName editColumn.codeName)}}
updateItem: {
name: "{{updateItem.name}}",
codeName: "{{updateItem.codeName}}",
{{#if updateItem.customCode}}
customCode: {{updateItem.customCode}},
scriptCode: `{{updateItem.scriptCode}}`,
{{else}}
showBusyIndicator: {{updateItem.showBusyIndicator}},
appDEMethod: "{{updateItem.psAppDEMethod.id}}",
updateDetails: [{{#each updateItem.psDEGEIUpdateDetails as | updateDetails | }}"{{updateDetails.name}}",{{/each}}],
{{/if}}
},
{{/if}}
{{/each}}
{{/if}}
{{/each}}
{{/if}}
......
......@@ -133,6 +133,9 @@ export class GridControl extends MDControl {
if (pagination) {
this.load();
}
if (sorter) {
this.load({ sort: `${sorter.field},${sorter.order == 'descend' ? 'desc' : 'asc'}` });
}
}
return {
useScrollOption,
......@@ -154,19 +157,31 @@ export class GridControl extends MDControl {
const { tag, action, data } = actionParam;
switch (action) {
case "valueChange":
const { items } = toRefs(this.state);
if (items.value[rowIndex][tag] !== data) {
items.value[rowIndex][tag] = data;
items.value[rowIndex]["rowDataState"] = "update";
this.resetGridData(tag,data,rowIndex);
this.validateField(tag, data, rowIndex);
}
this.handleGridItemValueChange(rowIndex, tag, data);
break;
default:
break;
}
}
/**
* @description 表格项值改变
* @param {*} data
* @param {number} rowIndex
* @param {string} tag
* @memberof GridControl
*/
public handleGridItemValueChange(rowIndex: number, tag: string, data: any) {
const { items } = toRefs(this.state);
if (items.value[rowIndex][tag] !== data) {
items.value[rowIndex][tag] = data;
items.value[rowIndex]["rowDataState"] = "update";
this.resetGridData(tag, data, rowIndex);
this.validateField(tag, data, rowIndex);
this.updateGridEditItem(tag, data, rowIndex);
}
}
/**
* @description 重置表格数据
* @param {string} name
......@@ -175,17 +190,17 @@ export class GridControl extends MDControl {
* @memberof GridControl
*/
public resetGridData(name: string, data: any, rowIndex: number) {
const { columnsModel } = this.state;
if (columnsModel && columnsModel.length > 0) {
columnsModel.forEach((column: any) => {
if (column.resetItemName && Object.is(name, column.resetItemName)) {
this.onEditorEvent({tag: column.dataIndex, action: 'valueChange', data: null},rowIndex);
if (column.valueItemName) {
this.onEditorEvent({tag: column.valueItemName, action: 'valueChange', data: null},rowIndex);
}
}
})
}
const { columnsModel } = this.state;
if (columnsModel && columnsModel.length > 0) {
columnsModel.forEach((column: any) => {
if (column.resetItemName && Object.is(name, column.resetItemName)) {
this.handleGridItemValueChange(rowIndex, column.dataIndex, null);
if (column.valueItemName) {
this.handleGridItemValueChange(rowIndex, column.valueItemName, null);
}
}
})
}
}
/**
......@@ -213,6 +228,44 @@ export class GridControl extends MDControl {
})
}
/**
* @description 更新表格编辑项
* @param {string} name
* @param {*} data
* @param {number} rowIndex
* @memberof GridControl
*/
public async updateGridEditItem(name: string, data: any, rowIndex: number) {
const { items, columnsModel, context, viewParams, controlService, appDeCodeName, appDeKeyFieldName } = this.state;
if (columnsModel && columnsModel.length > 0) {
columnsModel.forEach(async (column: any) => {
if (column.updateItem) {
const updateItem: any = column.updateItem;
if (updateItem.customCode) {
if (updateItem.scriptCode) {
eval(updateItem.scriptCode);
}
} else {
const arg = Object.assign(deepCopy(viewParams), items[rowIndex]);
const tempContext = Object.assign(deepCopy(context), { [appDeCodeName?.toLowerCase()]: items[rowIndex][appDeKeyFieldName] || items[rowIndex].srfkey });
const response = await controlService.frontLogic(
tempContext,
{ viewParams: arg },
{ action: updateItem.appDEMethod, isLoading: updateItem.showBusyIndicator },
);
if (response.status && response.status == 200) {
updateItem.updateDetails?.forEach((detailName: string) => {
if (detailName && items[rowIndex].hasOwnProperty(detailName)) {
items[rowIndex][detailName] = response.data[detailName];
}
});
}
}
}
})
}
}
/**
* @description 操作列事件触发
* @param {IActionParam} actionParam
......
......@@ -98,4 +98,24 @@ export class GridService<T extends ControlVOBase> extends ControlServiceBase<T>
response.data = this.newControlVO(response.data);
return this.handleResponse(response, opts);
}
/**
* 前台逻辑
*
* @param [context={}] 上下文参数
* @param [data={}] 视图参数
* @param opts
* @return {*}
*/
public async frontLogic(context: any, data: any, opts: { action: string; isLoading?: boolean }): Promise<any> {
let _entityService: any = this.entityService;
const { context: Context, data: Data } = this.handleRequestData(context, data, opts);
if (hasFunction(_entityService, opts.action)) {
const response = await _entityService[opts.action](Context, Data, opts.isLoading);
response.data = this.newControlVO(response.data);
return this.handleResponse(response, opts);
} else {
return null;
}
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册