提交 4bbf7cb6 编写于 作者: zhangkang's avatar zhangkang

update:前后台界面行为细化

上级 0ec8cff4
......@@ -69,6 +69,8 @@ public class AppEntityModel extends BaseModel{
}
// 初始化界面行为
keyField = getAppDataEntity().getPSDataEntity().getKeyPSDEField().getCodeName();
majorField = getAppDataEntity().getPSDataEntity().getMajorPSDEField().getCodeName();
if(getAppDataEntity().getAllPSAppDEUIActions() != null){
getAppDataEntity().getAllPSAppDEUIActions().forEach(appDEUIAction ->{
JSONObject actionJson = new JSONObject();
......@@ -81,6 +83,24 @@ public class AppEntityModel extends BaseModel{
actionJson.put("htmlPageUrl",appDEUIAction.getHtmlPageUrl());
actionJson.put("refreshMode",appDEUIAction.getRefreshMode());
actionJson.put("uILogicAttachMode",appDEUIAction.getUILogicAttachMode());
StringBuffer navContexts = new StringBuffer();
navContexts.append("{");
if(appDEUIAction.getPSNavigateContexts() != null){
appDEUIAction.getPSNavigateContexts().forEach(context ->{
navContexts.append(context.getName().toLowerCase() + ":'"+(context.isRawValue()?"":"%") +context.getValue()+(context.isRawValue()?"":"%")+"',");
});
}
navContexts.append("}");
actionJson.put("navContexts",navContexts);
StringBuffer navParams = new StringBuffer();
navParams.append("{");
if(appDEUIAction.getPSNavigateParams() != null){
appDEUIAction.getPSNavigateParams().forEach(param ->{
navParams.append(param.getName().toLowerCase() + ":'"+(param.isRawValue()?"":"%")+param.getValue()+(param.isRawValue()?"":"%")+"',");
});
}
navParams.append("}");
actionJson.put("navParams",navParams);
if(appDEUIAction.getPSAppDEMethod() != null){
actionJson.put("methodCodeName",appDEUIAction.getPSAppDEMethod().getCodeName());
}
......@@ -95,6 +115,10 @@ public class AppEntityModel extends BaseModel{
});
}
}
// 主键属性名称
public String keyField = "";
// 主信息属性名称
public String majorField = "";
public IPSAppDataEntity getAppDataEntity()
{
......
......@@ -2,7 +2,7 @@ import { Environment } from "@/environments/environment";
import { OpenViewService } from "@/utils";
import { AppBase, IParam, ViewDetail, IApp, IOpenViewService, deepCopy, getSessionStorage, Http, AppUtil } from "@core";
import { SyncSeriesHook } from "qx-util";
import { AppFuncConfig, AppViewConfig } from './config';
import { AppFuncConfig, AppViewConfig, AppEntityConfig } from './config';
import { DataServiceRegister, UIServiceRegister } from "./register";
export class App extends AppBase implements IApp {
......@@ -125,10 +125,21 @@ export class App extends AppBase implements IApp {
*
* @static
* @param codeName 视图codeName
* @return {*}
* @return {*}
*/
public getViewInfo(codeName: string): ViewDetail | undefined {
return AppViewConfig[codeName] ? (deepCopy(AppViewConfig[codeName]) as ViewDetail) : undefined;;
}
/**
* 获取实体信息
*
* @static
* @param codeName 实体codeName
* @return {*}
*/
public getEntityInfo(codeName: string): any {
return AppEntityConfig[codeName] ? deepCopy(AppEntityConfig[codeName]) : undefined;;
}
}
\ No newline at end of file
import { IParam } from "@core";
export const AppEntityConfig:IParam = {
{{#each app.appEntitiesMap as |appEntity|}}
"{{appEntity.codeName}}":{
"name": "{{appEntity.name}}",
"codeName": "{{appEntity.codeName}}",
"majorField":"{{appEntity.majorField}}",
"keyField":"{{appEntity.keyField}}"
}{{#unless @last}},{{/unless}}
{{/each}}
}
\ No newline at end of file
export { AppFuncConfig } from './app-func-config';
export { AppViewConfig } from './app-view-config';
export { AppCodeListConfig } from './app-code-list-config';
\ No newline at end of file
export { AppCodeListConfig } from './app-code-list-config';
export { AppEntityConfig } from './app-entity-config';
\ No newline at end of file
......@@ -72,6 +72,17 @@ export interface IApp {
*/
getViewInfo(codeName: string): ViewDetail | undefined;
/**
* 获取实体信息
*
* @static
* @param codeName 实体codeName
* @return {*}
*/
getEntityInfo(codeName: string): any;
/**
* 获取应用数据
*
......@@ -86,6 +97,6 @@ export interface IApp {
* @param {IParam} opt
* @memberof IApp
*/
setAppData(opt:IParam): void;
setAppData(opt: IParam): void;
}
\ No newline at end of file
import { AppActionService, IContext, IParam } from "@core";
import { AppActionService, IContext, IParam, UIActionUtil } from "@core";
export interface ActionParams {
/**
......@@ -60,7 +60,7 @@ export class AppActionBase {
* @memberof AppActionBase
*/
public static async getUIService(actionEnvironment: IParam) {
const entityName = actionEnvironment?.viewState?.appEntityName;
const entityName = actionEnvironment?.state?.appEntityName;
if (!entityName) {
console.log("实体名称不存在");
return;
......@@ -76,13 +76,48 @@ export class AppActionBase {
/**
* 根据数据目标处理行为参数
*
* @param {string} ActionTarget
* @param {string} action
* @param { context: IContext, viewParams: IParam, data: IParam, event: MouseEvent, actionEnvironment: IParam } params
* @memberof AppFrontAction
*/
public static handleActionTarget(ActionTarget: string, params: { context: IContext, viewParams: IParam, data: IParam, event: MouseEvent, actionEnvironment: IParam }): IParam {
// todo
return {};
public static handleActionTarget(action: IParam, params: { context: IContext, viewParams: IParam, data: IParam, event: MouseEvent, actionEnvironment: IParam }): ActionParams {
const { actionTarget, entityCodeName } = action;
const { data } = params;
// 数据目标值
let resultData: ActionParams = {
context: {},
viewParams: {},
data: {}
};
switch (actionTarget) {
case 'SINGLEKEY':
case 'MULTIKEY':
// 多数据主键和单数据主键,合并实体的主键参数和主信息参数 到上下文 后续统一合并进数据目标值
if (!entityCodeName) {
console.log("实体名称不存在");
break;
}
const entity = App.getEntityInfo(entityCodeName);
if (!entity) {
console.log("实体不存在");
break;
}
const entityName = entityCodeName.toLowerCase();
const keyField = entity.keyField.toLowerCase();
const majorField = entity.majorField.toLowerCase();
if (data?.[0]?.[keyField]) {
Object.assign(resultData.context, { [entityName]: `%${keyField}%` });
} else {
Object.assign(resultData.context, { [entityName]: `%${entityName}%` });
}
Object.assign(resultData.viewParams, { [keyField]: `%${keyField}%` });
Object.assign(resultData.viewParams, { [majorField]: `%${majorField}%` });
break;
case 'SINGLEDATA':
resultData.data = data?.[0]?data?.[0]:{};
break;
}
return resultData;
}
/**
......@@ -93,9 +128,39 @@ export class AppActionBase {
* @param { context: IContext, viewParams: IParam, data: IParam, event: MouseEvent, actionEnvironment: IParam } params
* @memberof AppFrontAction
*/
public static handleActionParam(uiAction: IParam, params: { context: IContext, viewParams: IParam, data: IParam, event: MouseEvent, actionEnvironment: IParam }, data: IParam): ActionParams {
// todo
return { context: {}, viewParams: {}, data: {} };
public static handleActionParam(uiAction: IParam, params: { context: IContext, viewParams: IParam, data: IParam, event: MouseEvent, actionEnvironment: IParam }, data: ActionParams): ActionParams {
const { navContexts, navParams, actionTarget } = uiAction;
const { viewParams, context, data: _data } = params;
const { context: tempContext, viewParams: tempViewParams, } = data;
let { data: resultData } = data;
// 合并导航参数和导航上下文至数据目标处理后的参数
Object.assign(tempContext, navContexts);
Object.assign(tempViewParams, navParams);
// 根据上下文和导航参数,解析参数
const _context = UIActionUtil.formatDataActionData(actionTarget, _data, context, viewParams, tempContext);
const _viewParams = UIActionUtil.formatDataActionData(actionTarget, _data, context, viewParams, tempViewParams);
if (Object.is(actionTarget, 'SINGLEDATA')) {
Object.assign(resultData, _viewParams);
} else {
resultData = _viewParams;
}
// 多项数据主键转换数据
if (Object.is(actionTarget, 'MULTIKEY')) {
let tempDataArray: Array<any> = [];
if (_data.length > 1 && Object.keys(data).length > 0) {
for (let i = 0; i < _data.length; i++) {
let tempObject: any = {};
Object.keys(resultData).forEach((key: string) => {
Object.assign(tempObject, { [key]: resultData[key].split(',')[i] });
});
tempDataArray.push(tempObject);
}
} else {
tempDataArray.push(data);
}
resultData = tempDataArray;
}
return { context: _context, viewParams: _viewParams, data: resultData };
}
/**
......
......@@ -16,14 +16,14 @@ export class AppBackendAction extends AppActionBase {
*/
public static async doBackendAction(uiAction: IParam, params: { context: IContext, viewParams: IParam, data: IParam, event: MouseEvent, actionEnvironment: IParam }, actionParams: ActionParams): Promise<UIActionResult> {
try {
const { context, actionEnvironment } = params;
const entityName = actionEnvironment?.viewState?.appEntityName;
const { actionEnvironment } = params;
const { context } = actionParams;
const entityName = actionEnvironment?.state?.appEntityName;
if (!entityName) {
console.log("实体名称不存在");
return { ok: false, result: null };
}
const methodCodeName: string = uiAction.methodCodeName;
if (!methodCodeName) {
console.log("实体行为不存在");
return { ok: false, result: null };
......@@ -31,7 +31,7 @@ export class AppBackendAction extends AppActionBase {
// 获取实体服务
const dataService = await App.getDataService(entityName.toLowerCase(), context)
// 获取实体行为名称
const response = await dataService[methodCodeName](context, actionParams);
const response = await dataService[methodCodeName](context, actionParams.data);
return new Promise((resolve: any, reject: any) => {
if (response && response.ok) {
this.doSuccessMessage(uiAction);
......@@ -112,7 +112,7 @@ export class AppBackendAction extends AppActionBase {
/**
* 执行台行为
* 执行台行为
*
* @param {IParam} uiAction
* @memberof AppFrontAction
......@@ -125,7 +125,7 @@ export class AppBackendAction extends AppActionBase {
// 消息确认提示
this.doConfirmMessage(uiAction);
// 根据行为目标 合并行为参数
const data = this.handleActionTarget(uiAction.actionTarget, params);
const data = this.handleActionTarget(uiAction, params);
// 处理行为参数 导航参数、数据项、信息项、参数项
const actionParams = this.handleActionParam(uiAction, params, data);
// 执行行为
......
......@@ -19,8 +19,8 @@ export class AppFrontAction extends AppActionBase {
*/
public static openView(uiAction: IParam, params: { context: IContext, viewParams: IParam, data: IParam, event: MouseEvent, actionEnvironment: IParam }, actionParams: ActionParams): Promise<UIActionResult> {
return new Promise((resolve: any, reject: any) => {
const { context, viewParams } = params;
const { frontPSAppView } = uiAction;
const { context, viewParams, data } = actionParams;
if (!frontPSAppView) {
console.log("模型视图名称不存在");
return reject({ ok: false, result: null });
......@@ -103,7 +103,7 @@ export class AppFrontAction extends AppActionBase {
return this.executeUILogic(uiAction, params);
}
// 根据行为目标 合并行为参数
const data = this.handleActionTarget(uiAction.actionTarget, params);
const data = this.handleActionTarget(uiAction, params);
// 处理行为参数 导航参数、数据项、信息项、参数项
const actionParams = this.handleActionParam(uiAction, params, data);
// 执行行为
......
import { isEmpty } from "ramda";
export class UIActionUtil {
/**
* 格式化数据
*
......@@ -17,11 +18,14 @@ export class UIActionUtil {
public static formatDataActionData(actionTarget: any, args: any, parentContext: any, parentParams: any, _params: any): any {
const _data: any = {};
if (
Object.is(actionTarget, 'SINGLEKEY') ||
Object.is(actionTarget, 'NONE') ||
Object.is(actionTarget, 'SINGLEDATA')
Object.is(actionTarget, 'SINGLEKEY') ||
Object.is(actionTarget, 'NONE') ||
Object.is(actionTarget, 'SINGLEDATA')
) {
const [arg] = args;
let arg:any = {};
if(!isEmpty(args)){
[arg] = args;
}
Object.keys(_params).forEach((name: string) => {
let hasProperty = true;
if (!name) {
......@@ -31,11 +35,11 @@ export class UIActionUtil {
if (value && typeof value === 'string' && value.startsWith('%') && value.endsWith('%')) {
const key = value.substring(1, value.length - 1);
if (
arg &&
arg.hasOwnProperty(key) &&
(Object.is(actionTarget, 'SINGLEKEY') ||
Object.is(actionTarget, 'SINGLEDATA') ||
Object.is(actionTarget, 'NONE'))
arg &&
arg.hasOwnProperty(key) &&
(Object.is(actionTarget, 'SINGLEKEY') ||
Object.is(actionTarget, 'SINGLEDATA') ||
Object.is(actionTarget, 'NONE'))
) {
value = arg[key] !== null && arg[key] !== undefined ? arg[key] : null;
} else if (parentContext && parentContext.hasOwnProperty(key)) {
......
......@@ -31,13 +31,15 @@ export class {{pascalCase appEntity.codeName}}UIServiceBase extends UIServiceBas
uIActionTag:'{{upperCase appDEUIAction.uIActionTag}}',
frontPSAppView:'{{appDEUIAction.frontPSAppView}}',
caption:'{{appDEUIAction.caption}}',
entityCodeName:'{{appDEUIAction.entityCodeName}}',
entityCodeName:'{{appEntity.codeName}}',
methodCodeName:'{{appDEUIAction.methodCodeName}}',
frontProcessType:'{{appDEUIAction.frontProcessType}}',
refreshMode:'{{appDEUIAction.refreshMode}}',
htmlPageUrl:'{{appDEUIAction.htmlPageUrl}}',
uILogicAttachMode:'{{appDEUIAction.uILogicAttachMode}}',
nextActionCodeName:'{{appDEUIAction.nextActionCodeName}}',
navContexts:{{appDEUIAction.navContexts}},
navParams:{{appDEUIAction.navParams}}
},
{{/each}}
};
......@@ -49,7 +51,7 @@ export class {{pascalCase appEntity.codeName}}UIServiceBase extends UIServiceBas
* @param {*} params
* @memberof {{pascalCase appEntity.codeName}}UIServiceBase
*/
public async {{appDEUIAction.codeName}}(params:any){
public async {{appDEUIAction.codeName}}(uiAction:any, params:any){
const actionModel = this.getUIActionModel('{{appDEUIAction.codeName}}');
{{#eq appDEUIAction.UIActionMode 'FRONT'}}
AppFrontAction.doAction(actionModel, params);
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册