提交 e0cc3ec1 编写于 作者: Shine-zwj's avatar Shine-zwj

update:更新表单逻辑

上级 b78dc23c
{{#each items as | formDetail |}}
{{#if (and (eq formDetail.detailType "BUTTON") (formDetail.psUIAction))}}
{{#formDetail.psUIAction}}
{{uIActionTag}}: { disabled: false, visible: true, noPrivDisplayMode: {{noPrivDisplayMode}}, dataAccessAction: '{{dataAccessAction}}', actionTarget: '{{actionTarget}}' },
{{/formDetail.psUIAction}}
{{/if}}
{{#if (and (eq formDetail.detailType "GROUPPANEL") (formDetail.psSUIActionGroup.psUIActionGroupDetails))}}
{{#each formDetail.psSUIActionGroup.psUIActionGroupDetails as | detail | }}
{{#detail.psUIAction}}
{{uIActionTag}}: { disabled: false, visible: true, noPrivDisplayMode: {{noPrivDisplayMode}}, dataAccessAction: '{{dataAccessAction}}', actionTarget: '{{actionTarget}}' },
{{/detail.psUIAction}}
{{/each}}
{{/if}}
{{#if formDetail.psDEFormDetails}}
{{>(lookup 'FORMACTIONMODEL') items=formDetail.psDEFormDetails}}
{{/if}}
{{/each}}
......@@ -2,6 +2,7 @@
<div style="flex-grow: {{#if item.psLayoutPos.grow}}{{item.psLayoutPos.grow}}{{else}}0{{/if}};">
<a-button
type="primary"
v-show="state.detailsModel.{{item.codeName}}.visible"
class="ibiz-form-button{{#if item.psSysCss}}{{item.psSysCss.cssName}}{{/if}}"
style="{{#if item.width}}width: {{item.width}}px;{{/if}}{{#if item.height}}height: {{item.height}}px;{{/if}}">
{{#if item.psSysImage}}
......@@ -19,6 +20,7 @@
{{> @macro/front-end/ctrl/common/layoutPos.hbs item=item.psLayoutPos}} >
<a-button
type="primary"
v-show="state.detailsModel.{{item.codeName}}.visible"
class="ibiz-form-button{{#if item.psSysCss}}{{item.psSysCss.cssName}}{{/if}}"
style="{{#if item.width}}width: {{item.width}}px;{{/if}}{{#if item.height}}height: {{item.height}}px;{{/if}}">
{{#if item.psSysImage}}
......
......@@ -9,6 +9,8 @@
showCaption: {{#if formDetail.showCaption}}true{{else}}false{{/if}},
{{#if (eq formDetail.detailType "FORMITEM")}}
dataType: '{{formDetail.dataType}}',
required: {{#if formDetail.allowEmpty}}false{{else}}true{{/if}},
enableCond: {{formDetail.enableCond}},
{{#if formDetail.resetItemName}}
resetItemName: '{{formDetail.resetItemName}}',
{{/if}}
......@@ -16,32 +18,38 @@
valueItemName: '{{formDetail.valueItemName}}',
{{/if}}
{{/if}}
{{#if (and (eq formDetail.detailType "BUTTON") formDetail.psUIAction)}}
{{#formDetail.psUIAction}}
uIAction: {
uIActionType: '{{uIActionType}}',
uIActionTag: '{{uIActionTag}}',
}
{{/formDetail.psUIAction}}
{{#if (and (eq formDetail.detailType "BUTTON") (formDetail.psUIAction))}}
uIActionTag: '{{formDetail.psUIAction.uIActionTag}}',
{{/if}}
{{#if (eq formDetail.detailType "GROUPPANEL")}}
{{/if}}
{{#each formDetail.psDEFDGroupLogics as | groupLogic |}}
groupLogics: {
name: '{{groupLogic.name}}',
groupOP: '{{groupLogic.groupOP}}',
relatedDetailNames: '{{groupLogic.relatedDetailNames}}',
logicCat: '{{groupLogic.logicCat}}',
logicType: '{{groupLogic.logicType}}',
notMode: '{{groupLogic.notMode}}',
Logics: [
{{#each groupLogic.psDEFDLogics as | logic |}}
{condOP: '{{logic.condOP}}',dEFDName: '{{logic.dEFDName}}',logicType: '{{logic.logicType}}',name: '{{logic.name}}'},
{{#if (and (eq formDetail.detailType "GROUPPANEL") (formDetail.psUIActionGroup))}}
uIActionGroup: {
extractMode: '{{formDetail.psUIActionGroup.actionGroupExtractMode}}',
details: [
{{#each formDetail.psUIActionGroup.psUIActionGroupDetails as | detail | }}
{ caption: '{{detail.caption}}', disabled: false, visible: true, uIActionTag: '{{detail.psUIAction.uIActionTag}}', showCaption: {{detail.showCaption}}, showIcon: {{detail.showIcon}}, {{#if detail.psUIAction.psSysImage}}{{#if detail.psUIAction.psSysImage.imagePath}} imgPath: "{{detail.psUIAction.psSysImage.imagePath}}",{{/if}}{{#if detail.psUIAction.psSysImage.cssClass}} iconClass: "{{detail.psUIAction.psSysImage.cssClass}}",{{/if}}{{/if}} },
{{/each}}
],
}
{{/each}}
},
{{/if}}
{{#if formDetail.psDEFDGroupLogics}}
groupLogics: [
{{#each formDetail.psDEFDGroupLogics as | groupLogic |}}
{
name: '{{groupLogic.name}}',
groupOP: '{{groupLogic.groupOP}}',
relatedDetailNames: '{{groupLogic.relatedDetailNames}}',
logicCat: '{{groupLogic.logicCat}}',
logicType: '{{groupLogic.logicType}}',
notMode: '{{groupLogic.notMode}}',
Logics: [
{{#each groupLogic.psDEFDLogics as | logic |}}
{condOP: '{{logic.condOP}}',dEFDName: '{{logic.dEFDName}}',logicType: '{{logic.logicType}}',name: '{{logic.name}}'},
{{/each}}
],
}
{{/each}}
],
{{/if}}
},
{{#if formDetail.psDEFormDetails}}
{{>(lookup 'FORMDETAILSMODEL') items=formDetail.psDEFormDetails}}
......
{{#eq item.psLayoutPos 'FLEX'}}
<div style="flex-grow: {{#if item.psLayoutPos.grow}}{{item.psLayoutPos.grow}}{{else}}0{{/if}};">
<IbizFormGroup name="{{item.codeName}}" title="{{item.caption}}">
<IbizFormGroup v-show="state.detailsModel.{{item.codeName}}.visible" name="{{item.codeName}}" title="{{item.caption}}">
{{#eq item.psLayout.layout "FLEX"}}
<div class="app-form-layout-flex" style="{{#if item.psLayout.dir}}flex-direction: {{item.psLayout.dir}};{{/if}}{{#if item.psLayout.align}}justify-content: {{item.psLayout.align}};{{/if}}{{#if item.psLayout.vAlign}}align-items: {{item.psLayout.vAlign}};{{/if}}">
{{#each item.psDEFormDetails as | formDetail |}}
......@@ -19,7 +19,7 @@
{{else}}
<a-col
{{> @macro/front-end/ctrl/common/layoutPos.hbs item=item.psLayoutPos}} >
<IbizFormGroup name="{{item.codeName}}" title="{{item.caption}}">
<IbizFormGroup v-show="state.detailsModel.{{item.codeName}}.visible" name="{{item.codeName}}" title="{{item.caption}}">
{{#eq item.psLayout.layout "FLEX"}}
<div class="app-form-layout-flex" style="{{#if item.psLayout.dir}}flex-direction: {{item.psLayout.dir}};{{/if}}{{#if item.psLayout.align}}justify-content: {{item.psLayout.align}};{{/if}}{{#if item.psLayout.vAlign}}align-items: {{item.psLayout.vAlign}};{{/if}}">
{{#each item.psDEFormDetails as | formDetail |}}
......
{{#eq item.psLayoutPos 'FLEX'}}
<div style="flex-grow: {{#if item.psLayoutPos.grow}}{{item.psLayoutPos.grow}}{{else}}0{{/if}};">
<div class="ibiz-form-iframe" style="{{#if item.contentHeight}}height: {{item.contentHeight}}px;{{/if}}{{#if item.contentWidth}}width: {{item.contentWidth}}px{{/if}}">
<div v-show="state.detailsModel.{{item.codeName}}.visible" class="ibiz-form-iframe" style="{{#if item.contentHeight}}height: {{item.contentHeight}}px;{{/if}}{{#if item.contentWidth}}width: {{item.contentWidth}}px{{/if}}">
<iframe src="{{item.iFrameUrl}}" style="height: 100%;width: 100%;border: 0"></iframe>
</div>
</div>
{{else}}
<a-col
{{> @macro/front-end/ctrl/common/layoutPos.hbs item=item.psLayoutPos}} >
<div class="ibiz-form-iframe" style="{{#if item.contentHeight}}height: {{item.contentHeight}}px;{{/if}}{{#if item.contentWidth}}width: {{item.contentWidth}}px{{/if}}">
<div v-show="state.detailsModel.{{item.codeName}}.visible" class="ibiz-form-iframe" style="{{#if item.contentHeight}}height: {{item.contentHeight}}px;{{/if}}{{#if item.contentWidth}}width: {{item.contentWidth}}px{{/if}}">
<iframe src="{{item.iFrameUrl}}" style="height: 100%;width: 100%;border: 0"></iframe>
</div>
</a-col>
......
{{>@macro/editor/include-editor.hbs}}
{{#eq item.psLayoutPos 'FLEX'}}
<div style="flex-grow: {{#if item.psLayoutPos.grow}}{{item.psLayoutPos.grow}}{{else}}0{{/if}};">
<IbizFormItem name="{{item.codeName}}" label="{{item.caption}}">
<IbizFormItem v-show="state.detailsModel.{{item.codeName}}.visible" name="{{item.codeName}}" label="{{item.caption}}">
{{#if item.psEditor}}
{{>(lookup . 'item.psEditor.editorType') item=item ctrlType="form"}}
{{/if}}
......@@ -10,7 +10,7 @@
{{else}}
<a-col
{{> @macro/front-end/ctrl/common/layoutPos.hbs item=item.psLayoutPos}} >
<IbizFormItem name="{{item.codeName}}" label="{{item.caption}}">
<IbizFormItem v-show="state.detailsModel.{{item.codeName}}.visible" name="{{item.codeName}}" label="{{item.caption}}">
{{#if item.psEditor}}
{{>(lookup . 'item.psEditor.editorType') item=item ctrlType="form"}}
{{/if}}
......
<a-tab-pane key="{{item.codeName}}" tab="{{item.caption}}">
<a-tab-pane v-show="state.detailsModel.{{item.codeName}}.visible" key="{{item.codeName}}" tab="{{item.caption}}">
{{#eq item.psLayout.layout "FLEX"}}
<div class="app-form-layout-flex" style="{{#if item.psLayout.dir}}flex-direction: {{item.psLayout.dir}};{{/if}}{{#if item.psLayout.align}}justify-content: {{item.psLayout.align}};{{/if}}{{#if item.psLayout.vAlign}}align-items: {{item.psLayout.vAlign}};{{/if}}">
{{#each item.psDEFormDetails as | formDetail |}}
......
{{#eq item.psLayoutPos 'FLEX'}}
<div style="flex-grow: {{#if item.psLayoutPos.grow}}{{item.psLayoutPos.grow}}{{else}}0{{/if}};">
<IbizRaw
{{#if item.psSysCss}}class="{{item.psSysCss.cssName}}"{{/if}}
{{#if item.psSysImage}}{{#if item.psSysImage.cssClass}}iconClass="{{item.psSysImage.cssClass}}"{{/if}}{{#if item.psSysImage.imagePath}}imgPath="{{item.psSysImage.imagePath}}"{{/if}}{{/if}}
contentType="{{item.contentType}}"
style="{{#if item.rawItemHeight}}height: {{item.rawItemHeight}}px;{{/if}}{{#if item.rawItemWidth}}width: {{item.rawItemWidth}}px{{/if}}"
{{#if (eq item.contentType 'RAW')}}value="{{item.rawContent}}"{{else if (eq item.contentType 'HTML')}}:value="`{{item.htmlContent}}`"{{/if}}/>
<IbizRaw
v-show="state.detailsModel.{{item.codeName}}.visible"
{{#if item.psSysCss}}class="{{item.psSysCss.cssName}}"{{/if}}
{{#if item.psSysImage}}{{#if item.psSysImage.cssClass}}iconClass="{{item.psSysImage.cssClass}}"{{/if}}{{#if item.psSysImage.imagePath}}imgPath="{{item.psSysImage.imagePath}}"{{/if}}{{/if}}
contentType="{{item.contentType}}"
style="{{#if item.rawItemHeight}}height: {{item.rawItemHeight}}px;{{/if}}{{#if item.rawItemWidth}}width: {{item.rawItemWidth}}px{{/if}}"
{{#if (eq item.contentType 'RAW')}}value="{{item.rawContent}}"{{else if (eq item.contentType 'HTML')}}:value="`{{item.htmlContent}}`"{{/if}}/>
</div>
{{else}}
<a-col
{{> @macro/front-end/ctrl/common/layoutPos.hbs item=item.psLayoutPos}} >
<IbizRaw
{{#if item.psSysCss}}class="{{item.psSysCss.cssName}}"{{/if}}
{{#if item.psSysImage}}{{#if item.psSysImage.cssClass}}iconClass="{{item.psSysImage.cssClass}}"{{/if}}{{#if item.psSysImage.imagePath}}imgPath="{{item.psSysImage.imagePath}}"{{/if}}{{/if}}
contentType="{{item.contentType}}"
style="{{#if item.rawItemHeight}}height: {{item.rawItemHeight}}px;{{/if}}{{#if item.rawItemWidth}}width: {{item.rawItemWidth}}px{{/if}}"
{{#if (eq item.contentType 'RAW')}}value="{{item.rawContent}}"{{else if (eq item.contentType 'HTML')}}:value="`{{item.htmlContent}}`"{{/if}}/>
</a-col>
<IbizRaw
v-show="state.detailsModel.{{item.codeName}}.visible"
{{#if item.psSysCss}}class="{{item.psSysCss.cssName}}"{{/if}}
{{#if item.psSysImage}}{{#if item.psSysImage.cssClass}}iconClass="{{item.psSysImage.cssClass}}"{{/if}}{{#if item.psSysImage.imagePath}}imgPath="{{item.psSysImage.imagePath}}"{{/if}}{{/if}}
contentType="{{item.contentType}}"
style="{{#if item.rawItemHeight}}height: {{item.rawItemHeight}}px;{{/if}}{{#if item.rawItemWidth}}width: {{item.rawItemWidth}}px{{/if}}"
{{#if (eq item.contentType 'RAW')}}value="{{item.rawContent}}"{{else if (eq item.contentType 'HTML')}}:value="`{{item.htmlContent}}`"{{/if}}/>
</a-col>
{{/eq}}
<a-tab-pane key="{{item.codeName}}" tab="{{item.caption}}">
<a-tab-pane v-show="state.detailsModel.{{item.codeName}}.visible" key="{{item.codeName}}" tab="{{item.caption}}">
{{#eq item.psLayout.layout "FLEX"}}
<div class="app-form-layout-flex" style="{{#if item.psLayout.dir}}flex-direction: {{item.psLayout.dir}};{{/if}}{{#if item.psLayout.align}}justify-content: {{item.psLayout.align}};{{/if}}{{#if item.psLayout.vAlign}}align-items: {{item.psLayout.vAlign}};{{/if}}">
{{#each item.psDEFormDetails as | formDetail |}}
......
......@@ -8,4 +8,5 @@
{{#*inline "FORMPART"}}{{>@macro/form-detail/form-formpart.hbs}}{{/inline}}
{{#*inline "TABPAGE"}}{{>@macro/form-detail/form-tabpage.hbs}}{{/inline}}
{{#*inline "DRUIPART"}}{{>@macro/form-detail/form-druipart.hbs}}{{/inline}}
{{#*inline "FORMDETAILSMODEL"}}{{>@macro/form-detail/form-details-model.hbs}}{{/inline}}
\ No newline at end of file
{{#*inline "FORMDETAILSMODEL"}}{{>@macro/form-detail/form-details-model.hbs}}{{/inline}}
{{#*inline "FORMACTIONMODEL"}}{{>@macro/form-detail/form-action-model.hbs}}{{/inline}}
\ No newline at end of file
......@@ -5,7 +5,7 @@
{{else if (eq item.columnType 'UAGRIDCOLUMN')}}
{{#each item.psDEUIActionGroup.psUIActionGroupDetails as | action |}}
{{#action}}
{ name: "{{name}}", caption: "{{psUIAction.caption}}", showIcon: {{showIcon}}, showCaption: {{showCaption}}, separator: {{addSeparator}}, uIActionTag: "{{psUIAction.uIActionTag}}", noPrivDisplayMode: {{#if psUIAction.noPrivDisplayMode}}{{psUIAction.noPrivDisplayMode}}{{else}}6{{/if}}, disabled: false, visible: true,{{#if psUIAction.psSysImage}}{{#if psUIAction.psSysImage.imagePath}} imgPath: "{{psUIAction.psSysImage.imagePath}}",{{/if}}{{#if psUIAction.psSysImage.cssClass}} iconClass: "{{psUIAction.psSysImage.cssClass}}",{{/if}}{{/if}} },
{ name: "{{name}}", caption: "{{psUIAction.caption}}", showIcon: {{showIcon}}, showCaption: {{showCaption}}, separator: {{addSeparator}}, uIActionTag: "{{psUIAction.uIActionTag}}", noPrivDisplayMode: {{psUIAction.noPrivDisplayMode}}, dataAccessAction: '{{psUIAction.dataAccessAction}}', actionTarget: '{{psUIAction.actionTarget}}', disabled: false, visible: true,{{#if psUIAction.psSysImage}}{{#if psUIAction.psSysImage.imagePath}} imgPath: "{{psUIAction.psSysImage.imagePath}}",{{/if}}{{#if psUIAction.psSysImage.cssClass}} iconClass: "{{psUIAction.psSysImage.cssClass}}",{{/if}}{{/if}} },
{{/action}}
{{/each}}
{{/if}}
\ No newline at end of file
......@@ -19,7 +19,7 @@ const emit = defineEmits<FormGroupEmit>();
:title="title"
:bordered="false">
<template #extra>
<a href="#">行为</a>
<!-- <a href="#">行为</a> -->
</template>
<slot></slot>
</a-card>
......
import { deepCopy, FormControlProps, FormControlState, IActionParam, MainControl } from '@core';
import { deepCopy, FormControlProps, FormControlState, IActionParam, IParam, MainControl, UIUtil, verifyValue } from '@core';
/**
* @description 表单部件
......@@ -16,21 +16,49 @@ export class FormControl extends MainControl {
public declare controlState: FormControlState;
/**
* 在表单数据改变(单一属性变化)时被调用。会依次执行以下逻辑:
* @description 检验表单动态逻辑
* @param {IParam} data 表单数据
* @param {IParam} logic 动态逻辑
* @return {*}
* @memberof FormControl
*/
public verifyGroupLogic(data: IParam, logic: IParam) {
if (logic.logicType == 'GROUP' && logic.logics?.length > 0) {
let result: boolean = true;
if (logic.groupOP == 'AND') {
const falseItem = logic.logics.find((childLogic: IParam)=> {
return !this.verifyGroupLogic(data, childLogic);
})
result = falseItem ? false : true;
} else if (logic.groupOP == 'OR') {
const trueItem = logic.logics.find((childLogic: IParam)=> {
return this.verifyGroupLogic(data, childLogic);
})
result = trueItem ? true : false;
}
// 是否取反
return logic.notMode ? !result : result;
} else if (logic.logicType == 'SINGLE') {
return verifyValue(data[logic.name], logic.condOP, logic.value);
}
return false;
}
/**
* @description 在表单数据改变(单一属性变化)时被调用。会依次执行以下逻辑:
* 1. 重置项逻辑
* 2. 表单项更新
* 3. 动态控制逻辑
* 4. 自动保存逻辑
*
* @param {string} name 属性名称
* @param {*} value 属性值
* @param {string} name 表单项名称
* @param {*} value 表单项值
* @memberof FormControl
*/
public formDataChange(name: string, value: any) {
this.controlState.data[name] = value;
this.resetFormData(name);
// TODO 表单项更新
// TODO 动态控制逻辑
this.formDynamicLogic(name);
// TODO 自动保存(可以单独做一个逻辑块,监听data的变化)
}
......@@ -40,62 +68,149 @@ export class FormControl extends MainControl {
* @memberof FormControl
*/
public resetFormData(name: string) {
const formItems: any[] = this.controlState.formDetails;
if (formItems && formItems.length > 0) {
for (const item of formItems) {
if (item.resetItemName && item.resetItemName == name) {
this.formDataChange( item.name, null);
if (item.valueItemName) {
this.formDataChange(item.valueItemName, null);
}
const { detailsModel } = this.controlState;
Object.values(detailsModel).forEach((item: IParam) => {
if (item.resetItemName && Object.is(name, item.resetItemName)) {
this.formDataChange(item.name, null);
if (item.valueItemName) {
this.formDataChange(item.valueItemName, null);
}
}
})
}
/**
* @description 表单动态逻辑
* @param {string} name 表单项名称
* @memberof FormControl
*/
public formDynamicLogic(name: string) {
const { data } = this.controlState;
const { detailsModel } = toRefs(this.controlState);
Object.values(detailsModel.value).forEach((item: IParam) => {
if (item.groupLogics?.length > 0) {
item.groupLogics.forEach((logic: IParam) => {
let relatedNames = logic.relatedDetailNames || [];
if (Object.is(name, '') || relatedNames.indexOf(name) != -1) {
let ret = this.verifyGroupLogic(data, logic);
switch (logic.logicCat) {
// 动态空输入,不满足则必填
case 'ITEMBLANK':
item.required = !ret;
break;
// 动态启用,满足则启用
case 'ITEMENABLE':
item.disabled = !ret;
break;
// 动态显示,满足则显示
case 'PANELVISIBLE':
item.visible = ret;
break;
}
}
});
}
});
}
/**
* @description 表单执行某些整体数据发生变化行为之后,依次执行以下逻辑
* 1.根据行为类型将主键合并到context中
* 2.设置新建默认值和更新默认值
* 4.计算行为权限状态
* 5.设置表单项启用
* 6.表单动态逻辑
* @param {string} action
* @memberof FormControl
*/
public afterFormAction(action: string) {
const { appDeCodeName, data } = this.controlState;
const { context } = toRefs(this.controlState);
if (appDeCodeName) {
if (Object.is(action, 'save') || Object.is(action, 'autoSave') || Object.is(action, 'submit')) {
if (data[appDeCodeName]) {
Object.assign(context.value, { [appDeCodeName]: data[appDeCodeName] });
}
}
}
this.setDefaultValue(action);
this.calcActionAuthState();
this.setFormEnableCond();
this.formDynamicLogic('');
}
/**
* @description 动态显示逻辑
* @description 设置表单启用项
* @memberof FormControl
*/
public displayLogic(name: string) {
const formItems: any[] = this.controlState.formDetails;
// 表单动态逻辑
// allFormDetails?.forEach((detail: IPSDEFormDetail) => {
// detail.getPSDEFDGroupLogics()?.forEach((logic: IPSDEFDCatGroupLogic) => {
// // todo lxm 缺少getRelatedDetailNames
// let relatedNames = logic.getRelatedDetailNames() || [];
// if (Object.is(name, '') || relatedNames.indexOf(name) != -1) {
// let ret = this.verifyGroupLogic(this.data, logic);
// switch (logic.logicCat) {
// // 动态空输入,不满足则必填
// case 'ITEMBLANK':
// this.detailsModel[detail.name].required = !ret;
// break;
// // 动态启用,满足则启用
// case 'ITEMENABLE':
// this.detailsModel[detail.name].setDisabled(!ret);
// break;
// // 动态显示,满足则显示
// case 'PANELVISIBLE':
// this.detailsModel[detail.name].setVisible(ret);
// break;
// }
// }
// })
// })
public setFormEnableCond() {
const { data } = this.controlState;
const { detailsModel } = toRefs(this.controlState);
Object.values(detailsModel.value).forEach((item: IParam) => {
if (Object.is(item.detailType, 'FORMITEM')) {
switch (item.enableCond) {
case 0:
// 不启用
item.disabled = false;
break;
case 1:
// 新建
if (Object.is(data.srfuf, '0')) {
item.disabled = true;
} else {
item.disabled = false;
}
break;
case 2:
// 更新
if (Object.is(data.srfuf, '1')) {
item.disabled = true;
} else {
item.disabled = false;
}
break;
case 3:
// 启用
item.disabled = true;
break;
default:
break;
}
}
});
}
/**
* 在表单执行某些行为能力后,表单整体数据发生改变后被调用。会依次执行以下逻辑:
* 1.
*
* @param {string} action 调用的表单行为方法
* @description 计算行为权限状态
* @memberof FormControl
*/
public afterFormLoad(action: string) {
// 改变context当前实体主键,并抛出抽屉脏值的事件
// TODO 设置表单项启用(如果可以响应式变化则不用处理)
// 新建默认值和更新默认值
// TODO 动态控制逻辑
public calcActionAuthState() {
const { data, UIService, actionModel } = this.controlState;
const { detailsModel } = toRefs(this.controlState);
const tempModel = deepCopy(actionModel);
UIUtil.calcActionItemAuthState(data, tempModel, UIService);
Object.values(detailsModel.value).forEach((item: IParam) => {
if (Object.is(item.detailType, 'BUTTON') && item.uIActionTag) {
// 更新按钮的权限状态值
item.visible = tempModel[item.uIActionTag].visible;
item.disabled = tempModel[item.uIActionTag].disabled;
item.isPower = tempModel[item.uIActionTag].dataActionResult === 1 ? true : false;
} else if (Object.is(item.detailType, 'GROUPPANEL') && item.uIActionGroup?.details?.length > 0) {
// 更新分组面板界面行为组的权限状态值
item.uiActionGroup.details.forEach((actionDetail: any) => {
actionDetail.visible = tempModel[actionDetail.uIActionTag].visible;
actionDetail.disabled = tempModel[actionDetail.uIActionTag].disabled;
});
}
});
}
/**
* @description 设置默认值
* @param {string} action 表单行为
* @memberof FormControl
*/
public setDefaultValue(action: string) {
// TODO 新建默认值和更新默认值
}
/**
......@@ -115,15 +230,11 @@ export class FormControl extends MainControl {
*/
const load = async (opt: any = {}) => {
try {
// 获取需要的状态变量
const { controlService, context, viewParams, showBusyIndicator } = this.controlState;
// 判断实体行为
const loadAction = this.controlState.controlAction.loadAction;
if (!loadAction) {
const { controlService, context, viewParams, showBusyIndicator, controlAction } = this.controlState;
const { data } = toRefs(this.controlState);
if (!controlAction.loadAction) {
return;
}
// 处理请求参数
let _context = deepCopy(context);
let _viewParams = deepCopy(viewParams);
......@@ -132,17 +243,12 @@ export class FormControl extends MainControl {
const response = await controlService.get(
_context,
{ viewParams: _viewParams },
{
action: loadAction,
isLoading: showBusyIndicator,
},
{ action: controlAction.loadAction, isLoading: showBusyIndicator },
);
if (!response.status || response.status !== 200) {
return;
if (response.status && response.status == 200) {
data.value = response.data;
this.afterFormAction('load');
}
// 请求后处理
this.controlState.data = response.data;
} catch (error) {
// TODO 错误异常处理
console.log(error);
......
......@@ -35,4 +35,11 @@ export interface MainControlState extends ControlStateBase {
* @memberof MainControlState
*/
UIService: IParam;
/**
* @description 应用实体名称
* @type {string}
* @memberof MainControlState
*/
appDeCodeName: string;
}
\ No newline at end of file
......@@ -274,139 +274,4 @@ export class RouteUtil {
public static getIndexViewParam(): any {
return this.indexViewParam;
}
/**
* 计算界面行为项权限状态
*
* @static
* @param {*} [data] 传入数据
* @param {*} [ActionModel] 界面行为模型
* @param {*} [UIService] 界面行为服务
* @memberof RouteUtil
*/
public static calcActionItemAuthState(data: any, ActionModel: any, UIService: any) {
let result: any[] = [];
if (!UIService) return;
for (const key in ActionModel) {
if (!ActionModel.hasOwnProperty(key)) {
return result;
}
const _item = ActionModel[key];
let dataActionResult: any;
if (_item && _item['dataAccessAction']) {
if (Object.is(_item['actionTarget'], 'NONE') || Object.is(_item['actionTarget'], '')) {
dataActionResult = UIService.getAllOPPrivs(undefined, _item['dataAccessAction']);
} else {
if (data && Object.keys(data).length > 0) {
dataActionResult = UIService.getAllOPPrivs(data, _item['dataAccessAction']);
}
}
} else {
dataActionResult = 1;
}
// 无权限:0;有权限:1
if (dataActionResult === 0) {
// 禁用:1;隐藏:2;隐藏且默认隐藏:6
if (_item.getNoPrivDisplayMode === 1) {
_item.disabled = true;
}
if (_item.getNoPrivDisplayMode === 2 || _item.getNoPrivDisplayMode === 6) {
_item.visabled = false;
} else {
_item.visabled = true;
}
}
if (dataActionResult === 1) {
_item.visabled = true;
_item.disabled = false;
}
// 返回权限验证的结果
_item.dataActionResult = dataActionResult;
result.push(dataActionResult);
}
return result;
}
/**
* 计算界面行为项权限状态(树节点版本)
*
* @static
* @param {*} [data] 传入数据
* @param {*} [ActionModel] 界面行为模型
* @param {*} [UIService] 界面行为服务
* @memberof RouteUtil
*/
public static calcTreeActionItemAuthState(data: any, ActionModel: any, UIService: any) {
let result: any[] = [];
if (!UIService) return;
for (const key in ActionModel) {
if (!ActionModel.hasOwnProperty(key)) {
return result;
}
const _item = ActionModel[key];
let dataActionResult: any;
if (Object.is(_item['actiontarget'], 'NONE') || Object.is(_item['actiontarget'], '')) {
dataActionResult = UIService.getAllOPPrivs(undefined, _item['dataaccaction']);
} else {
if (_item && _item['dataaccaction'] && UIService.isEnableDEMainState) {
if (data && Object.keys(data).length > 0) {
dataActionResult = UIService.getAllOPPrivs(data, _item['dataaccaction']);
}
}
}
// 无权限:0;有权限:1
if (dataActionResult === 0) {
// 禁用:1;隐藏:2;隐藏且默认隐藏:6
if (_item.noprivdisplaymode === 1) {
_item.disabled = true;
}
if (_item.noprivdisplaymode === 2 || _item.noprivdisplaymode === 6) {
_item.visabled = false;
} else {
_item.visabled = true;
}
}
if (dataActionResult === 1) {
_item.visabled = true;
_item.disabled = false;
}
// 返回权限验证的结果
_item.dataActionResult = dataActionResult;
result.push(dataActionResult);
}
return result;
}
/**
* 计算重定向上下文
*
* @static
* @param {*} [tempContext] 上下文
* @param {*} [data] 传入数据
* @param {*} [redirectAppEntity] 应用实体对象
* @memberof RouteUtil
*/
public static async calcRedirectContext(tempContext: any, data: any, redirectAppEntity: any) {
if (
redirectAppEntity &&
redirectAppEntity.getMinorPSAppDERSs() &&
(redirectAppEntity.getMinorPSAppDERSs() as []).length > 0
) {
for (const item of redirectAppEntity.getMinorPSAppDERSs()) {
const parentPSAppDEFieldCodeName: string = item.M.getParentPSAppDEField?.codeName;
if (parentPSAppDEFieldCodeName) {
const curData: any = data;
if (curData && curData[parentPSAppDEFieldCodeName.toLowerCase()]) {
const majorAppEntity: any = item.getMajorPSAppDataEntity();
await majorAppEntity.fill();
if (!tempContext[majorAppEntity.codeName.toLowerCase()]) {
Object.assign(tempContext, {
[majorAppEntity.codeName.toLowerCase()]: curData[parentPSAppDEFieldCodeName.toLowerCase()],
});
}
}
}
}
}
}
}
......@@ -38,17 +38,17 @@ export class UIUtil {
// 无权限:0;有权限:1
if (dataActionResult === 0) {
// 禁用:1;隐藏:2;隐藏且默认隐藏:6
if (item.getNoPrivDisplayMode === 1) {
if (item.noPrivDisplayMode === 1) {
item.disabled = true;
}
if (item.getNoPrivDisplayMode === 2 || item.getNoPrivDisplayMode === 6) {
item.visabled = false;
if (item.noPrivDisplayMode === 2 || item.noPrivDisplayMode === 6) {
item.visible = false;
} else {
item.visabled = true;
item.visible = true;
}
}
if (dataActionResult === 1) {
item.visabled = true;
item.visible = true;
item.disabled = false;
}
// 返回权限验证的结果
......
......@@ -52,11 +52,16 @@ export const CtrlConfig = {
controlName: '{{ctrl.name}}',
controlService: new EditFormService<ControlVO>(ControlVO, new {{pascalCase ctrl.psAppDataEntity.codeName}}Service() ),
data: new ControlVO({}),
formDetails: {
detailsModel: {
{{#each ctrl.psDEFormPages as | FormPage | }}
{{>(lookup 'FORMDETAILSMODEL') items=FormPage.psDEFormDetails}}
{{/each}}
},
actionModel: {
{{#each ctrl.psDEFormPages as | FormPage | }}
{{>(lookup 'FORMACTIONMODEL') items=FormPage.psDEFormDetails}}
{{/each}}
},
rules: {
{{#each ctrl.psDEFormEditItemVRs as | ruleItem |}}
{{#neq ruleItem 2}}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册