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

update: 表格更新项

上级 c772e4e1
...@@ -41,6 +41,22 @@ ...@@ -41,6 +41,22 @@
{{#if editColumn.valueItemName}} {{#if editColumn.valueItemName}}
valueItemName: "{{editColumn.valueItemName}}", valueItemName: "{{editColumn.valueItemName}}",
{{/if}} {{/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}} {{/if}}
{{/each}} {{/each}}
{{/if}} {{/if}}
......
...@@ -133,6 +133,9 @@ export class GridControl extends MDControl { ...@@ -133,6 +133,9 @@ export class GridControl extends MDControl {
if (pagination) { if (pagination) {
this.load(); this.load();
} }
if (sorter) {
this.load({ sort: `${sorter.field},${sorter.order == 'descend' ? 'desc' : 'asc'}` });
}
} }
return { return {
useScrollOption, useScrollOption,
...@@ -154,16 +157,28 @@ export class GridControl extends MDControl { ...@@ -154,16 +157,28 @@ export class GridControl extends MDControl {
const { tag, action, data } = actionParam; const { tag, action, data } = actionParam;
switch (action) { switch (action) {
case "valueChange": case "valueChange":
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); const { items } = toRefs(this.state);
if (items.value[rowIndex][tag] !== data) { if (items.value[rowIndex][tag] !== data) {
items.value[rowIndex][tag] = data; items.value[rowIndex][tag] = data;
items.value[rowIndex]["rowDataState"] = "update"; items.value[rowIndex]["rowDataState"] = "update";
this.resetGridData(tag,data,rowIndex); this.resetGridData(tag, data, rowIndex);
this.validateField(tag, data, rowIndex); this.validateField(tag, data, rowIndex);
} this.updateGridEditItem(tag, data, rowIndex);
break;
default:
break;
} }
} }
...@@ -179,9 +194,9 @@ export class GridControl extends MDControl { ...@@ -179,9 +194,9 @@ export class GridControl extends MDControl {
if (columnsModel && columnsModel.length > 0) { if (columnsModel && columnsModel.length > 0) {
columnsModel.forEach((column: any) => { columnsModel.forEach((column: any) => {
if (column.resetItemName && Object.is(name, column.resetItemName)) { if (column.resetItemName && Object.is(name, column.resetItemName)) {
this.onEditorEvent({tag: column.dataIndex, action: 'valueChange', data: null},rowIndex); this.handleGridItemValueChange(rowIndex, column.dataIndex, null);
if (column.valueItemName) { if (column.valueItemName) {
this.onEditorEvent({tag: column.valueItemName, action: 'valueChange', data: null},rowIndex); this.handleGridItemValueChange(rowIndex, column.valueItemName, null);
} }
} }
}) })
...@@ -213,6 +228,44 @@ export class GridControl extends MDControl { ...@@ -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 操作列事件触发 * @description 操作列事件触发
* @param {IActionParam} actionParam * @param {IActionParam} actionParam
......
...@@ -98,4 +98,24 @@ export class GridService<T extends ControlVOBase> extends ControlServiceBase<T> ...@@ -98,4 +98,24 @@ export class GridService<T extends ControlVOBase> extends ControlServiceBase<T>
response.data = this.newControlVO(response.data); response.data = this.newControlVO(response.data);
return this.handleResponse(response, opts); 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 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册