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

update:更新表单

上级 78687765
......@@ -11,6 +11,33 @@
dataType: '{{formDetail.dataType}}',
required: {{#if formDetail.allowEmpty}}false{{else}}true{{/if}},
enableCond: {{formDetail.enableCond}},
{{#if formDetail.psDEFormItemUpdate}}
formItemUpdate: {
{{#if formDetail.psDEFormItemUpdate.customCode}}
customCode: {{formDetail.psDEFormItemUpdate.customCode}},
scriptCode: "{{formDetail.psDEFormItemUpdate.scriptCode}}",
{{else}}
showBusyIndicator: "{{formDetail.psDEFormItemUpdate.showBusyIndicator}}",
appDEMethod: "{{formDetail.psDEFormItemUpdate.psAppDEMethod}}",
updateDetails: [
{{#each formDetail.psDEFormItemUpdate.psDEFIUpdateDetails as | updateDetails | }}
"{{updateDetails.codeName}}",
{{/each}}
],
{{/if}}
},
{{/if}}
{{#if formDetail.createDVT}}
createDVT: "{{formDetail.createDVT}}",
createDV: "{{formDetail.createDV}}",
{{/if}}
{{#if formDetail.updateDVT}}
updateDVT: "{{formDetail.updateDVT}}",
updateDV: "{{formDetail.updateDV}}",
{{/if}}
{{#if formDetail.psAppDEField}}
valueFormat: '{{formDetail.psAppDEField.valueFormat}}',
{{/if}}
{{#if formDetail.resetItemName}}
resetItemName: '{{formDetail.resetItemName}}',
{{/if}}
......
......@@ -35,4 +35,11 @@ export interface FormControlState extends MainControlState {
* @memberof FormControlState
*/
rules: IParam;
/**
* @description 支持自动保存
* @type {boolean}
* @memberof FormControlState
*/
enableAutoSave: boolean;
}
import { deepCopy, FormControlProps, FormControlState, IActionParam, IParam, MainControl, UIUtil, verifyValue } from '@core';
import { DataTypes, dateFormat, deepCopy, FormControlProps, FormControlState, IActionParam, IParam, MainControl, UIUtil, verifyValue } from '@core';
/**
* @description 表单部件
......@@ -57,7 +57,7 @@ export class FormControl extends MainControl {
public formDataChange(name: string, value: any) {
this.controlState.data[name] = value;
this.resetFormData(name);
// TODO 表单项更新
this.formItemUpdate(name);
this.formDynamicLogic(name);
// TODO 自动保存(可以单独做一个逻辑块,监听data的变化)
}
......@@ -79,6 +79,40 @@ export class FormControl extends MainControl {
})
}
/**
* @description 表单项更新
* @param {string} name 表单项名称
* @memberof FormControl
*/
public async formItemUpdate(name: string) {
const { detailsModel, context, viewParams, controlService } = this.controlState;
const { data } = toRefs(this.controlState);
if (detailsModel[name] && detailsModel[name].formItemUpdate) {
const formItemUpdate = detailsModel[name].formItemUpdate;
if (formItemUpdate.customCode) {
if (formItemUpdate.scriptCode) {
eval(formItemUpdate.scriptCode);
}
} else {
const arg = Object.assign(deepCopy(viewParams), data.value);
const tempContext = deepCopy(context);
const response = await controlService.frontLogic(
tempContext,
{ viewParams: arg },
{ action: formItemUpdate.appDEMethod, isLoading: formItemUpdate.showBusyIndicator },
);
if (response.status && response.status == 200) {
formItemUpdate.updateDetails?.forEach((detailsName: string) => {
if (data.value.hasOwnProperty(detailsName)) {
data.value[detailsName] = response.data[detailsName];
}
})
this.afterFormAction('formItemUpdate');
}
}
}
}
/**
* @description 表单动态逻辑
* @param {string} name 表单项名称
......@@ -155,19 +189,11 @@ export class FormControl extends MainControl {
break;
case 1:
// 新建
if (Object.is(data.srfuf, '0')) {
item.disabled = true;
} else {
item.disabled = false;
}
item.disabled = data.srfuf != 0;
break;
case 2:
// 更新
if (Object.is(data.srfuf, '1')) {
item.disabled = true;
} else {
item.disabled = false;
}
item.disabled = data.srfuf != 1;
break;
case 3:
// 启用
......@@ -210,7 +236,160 @@ export class FormControl extends MainControl {
* @memberof FormControl
*/
public setDefaultValue(action: string) {
// TODO 新建默认值和更新默认值
switch (action) {
case 'loadDraft':
this.setCreateDefault();
break;
case 'load':
this.setUpdateDefault();
break;
}
}
/**
* @description 设置新建默认值
* @memberof FormControl
*/
public setCreateDefault() {
const { detailsModel, context, viewParams, controlService } = this.controlState;
const { data } = toRefs(this.controlState);
Object.values(detailsModel).forEach((detail: IParam) => {
if (Object.is(detail.detailType, 'FORMITEM')) {
if ((detail.createDV || detail.createDVT) && data.value.hasOwnProperty(detail.codeName)) {
switch (detail.createDVT) {
case 'CONTEXT':
data.value[detail.codeName] = viewParams[detail.createDV];
break;
case 'SESSION':
data.value[detail.codeName] = context[detail.createDV];
break;
case 'APPDATA':
data.value[detail.codeName] = context[detail.createDV];
break;
case 'OPERATORNAME':
data.value[detail.codeName] = context['srfusername'];
break;
case 'OPERATOR':
data.value[detail.codeName] = context['srfuserid'];
break;
case 'CURTIME':
data.value[detail.codeName] = dateFormat(new Date(), detail.valueFormat);
break;
case 'PARAM':
data.value[detail.codeName] = controlService.getRemoteCopyData()?.[detail.codeName] || null;
break;
default:
data.value[detail.codeName] = DataTypes.isNumber(detail.dataType) ? Number(detail?.createDV) : detail?.createDV;
break;
}
}
}
})
}
/**
* @description 设置更新默认值
* @memberof FormControl
*/
public setUpdateDefault() {
const { detailsModel, context, viewParams, controlService } = this.controlState;
const { data } = toRefs(this.controlState);
Object.values(detailsModel).forEach((detail: IParam) => {
if (Object.is(detail.detailType, 'FORMITEM')) {
if ((detail.updateDV || detail.updateDVT) && data.value.hasOwnProperty(detail.codeName)) {
switch (detail.updateDVT) {
case 'CONTEXT':
data.value[detail.codeName] = viewParams[detail.updateDV];
break;
case 'SESSION':
data.value[detail.codeName] = context[detail.updateDV];
break;
case 'APPDATA':
data.value[detail.codeName] = context[detail.updateDV];
break;
case 'OPERATORNAME':
data.value[detail.codeName] = context['srfusername'];
break;
case 'OPERATOR':
data.value[detail.codeName] = context['srfuserid'];
break;
case 'CURTIME':
data.value[detail.codeName] = dateFormat(new Date(), detail.valueFormat);
break;
case 'PARAM':
data.value[detail.codeName] = controlService.getRemoteCopyData()?.[detail.codeName] || null;
break;
default:
data.value[detail.codeName] = DataTypes.isNumber(detail.dataType) ? Number(detail.updateDV) : detail.updateDV;
break;
}
}
}
})
}
/**
* @description 使用加载草稿功能模块
* @param {FormControlProps} props 传入的props
* @return {*}
* @memberof FormControl
*/
public useLoadDraft(props: FormControlProps) {
const { viewSubject, controlName } = this.controlState;
/**
* 加载行为
*
* @param [opt={}]
* @return {*}
*/
const loadDraft = async (opt: any = {}) => {
try {
const { controlService, context, viewParams, showBusyIndicator, controlAction, appDeKeyFieldName } = this.controlState;
const { data } = toRefs(this.controlState);
if (!controlAction.loadDraftAction) {
return;
}
// 处理请求参数
let _context = deepCopy(context);
let _viewParams = deepCopy(viewParams);
// 发起请求处理与解析请求
const response = await controlService.loadDraft(
_context,
{ viewParams: _viewParams },
{ action: controlAction.loadDraftAction, isLoading: showBusyIndicator },
);
if (response.status && response.status == 200) {
if (appDeKeyFieldName && response.data[appDeKeyFieldName]) {
response.data[appDeKeyFieldName] = null;
}
data.value = response.data;
this.afterFormAction('loadDraft');
}
} catch (error) {
// TODO 错误异常处理
console.log(error);
}
};
// 订阅viewSubject,监听load行为
if (viewSubject) {
let subscription = viewSubject.subscribe(({ tag, action, data }: IActionParam) => {
if (Object.is(controlName, tag) && Object.is('loadDraft', action)) {
loadDraft(data);
}
});
// 部件卸载时退订viewSubject
onUnmounted(() => {
subscription.unsubscribe();
});
}
return {
load: loadDraft,
};
}
/**
......
......@@ -314,7 +314,6 @@ export class GridControl extends MainControl {
}
});
_columnsModel.forEach((column: IParam) => {
console.log(this.getAggValue(dataAgg, column));
aggData.push(this.getAggValue(dataAgg, column))
});
}
......
......@@ -42,4 +42,18 @@ export interface MainControlState extends ControlStateBase {
* @memberof MainControlState
*/
appDeCodeName: string;
/**
* @description 应用实体主键属性codeName
* @type {string}
* @memberof MainControlState
*/
appDeKeyFieldName: string;
/**
* @description 应用实体主信息属性codeName
* @type {string}
* @memberof MainControlState
*/
appDeMajorFieldName: string;
}
\ No newline at end of file
......@@ -96,4 +96,33 @@ export class EditFormService<T extends ControlVOBase> extends ControlServiceBase
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
}
}
/**
* @description 获取远端数据
* @return {*}
* @memberof EditFormService
*/
public getRemoteCopyData() {
// return this.remoteCopyData;
}
}
/**
* 数据类型
*
*/
export class DataTypes {
static readonly DataTypes: any = {
UNKNOWN : 0, //
BIGINT : 1,
BINARY : 2,
BIT : 3,
CHAR : 4,
DATETIME : 5,
DECIMAL : 6,
FLOAT : 7,
IMAGE : 8,
INT : 9,
MONEY : 10,
NCHAR : 11,
NTEXT : 12,
NVARCHAR : 13,
NUMERIC : 14,
REAL : 15,
SMALLDATETIME : 16,
SMALLINT : 17,
SMALLMONEY : 18,
SQL_VARIANT : 19,
SYSNAME : 20,
TEXT : 21,
TIMESTAMP : 22,
TINYINT : 23,
VARBINARY : 24,
VARCHAR : 25,
UNIQUEIDENTIFIER : 26,
DATE : 27, // 纯日期型
TIME : 28, // 纯时间
BIGDECIMAL : 29, // 大数值
}
/**
* @description 是否忽略大小写
* @protected
* @static
* @param {string} value
* @param {string} value2
* @return {*}
* @memberof DataTypes
*/
protected static equalsIgnoreCase(value:string, value2: string){
return value.toLocaleLowerCase() == value2.toLocaleLowerCase();
}
/**
* @description 字符串转数值
* @static
* @param {string} strValue
* @return {*} {number}
* @memberof DataTypes
*/
public static fromString(strValue: string): number {
let result = this.DataTypes[strValue.toUpperCase()];
return result || this.DataTypes.VARCHAR;
}
/**
* @description 是否为number类型
* @static
* @param {string} strValue
* @return {*} {boolean}
* @memberof DataTypes
*/
public static isNumber(strValue: string): boolean {
const numberTypes: any[] = ['BIGINT','BINARY','DECIMAL','FLOAT','INT','MONEY','NUMERIC','REAL','SMALLINT','SMALLMONEY','TINYINT','VARBINARY'];
if(numberTypes.indexOf(strValue) !== -1){
return true;
}else{
return false
}
}
/**
* @description 获取字符串名称
* @static
* @param {number} nDataType
* @return {*}
* @memberof DataTypes
*/
public static toString(nDataType: number) {
let result = 'VARCHAR';
for(let key in this.DataTypes){
if(nDataType == this.DataTypes[key]){
result = key;
break;
}
}
return result;
}
}
......@@ -2,4 +2,5 @@ export { RouteUtil } from './route-util';
export { UIUtil } from './ui-util';
export { UIActionUtil } from './uiaction-util';
export { ViewUtil } from './view-util';
export { AppUtil } from './app-util';
\ No newline at end of file
export { AppUtil } from './app-util';
export { DataTypes } from './data-types';
\ No newline at end of file
......@@ -10,6 +10,36 @@ export function deepCopy(data: Record<any, any>): Record<any, any>{
return clone(data)
}
/**
* @description 日期格式化
* @export
* @param {*} date 日期对象
* @param {string} [fmt='YYYY-MM-DD HH:mm:ss'] 格式化
* @return {*} {string}
*/
export function dateFormat(date: any, fmt: string = 'YYYY-MM-DD HH:mm:ss'): string {
let ret;
const opt: any = {
'Y+': date.getFullYear().toString(), // 年
'M+': (date.getMonth() + 1).toString(), // 月
'd+': date.getDate().toString(), // 日
'D+': date.getDate().toString(), // 日
'H+': date.getHours().toString(), // 时
'h+': date.getHours().toString(), // 时
'm+': date.getMinutes().toString(), // 分
's+': date.getSeconds().toString(), // 秒
'S+': date.getSeconds().toString()
// 有其他格式化字符需求可以继续添加,必须转化成字符串
};
for (let k in opt) {
ret = new RegExp('(' + k + ')').exec(fmt);
if (ret) {
fmt = fmt.replace(ret[1], ret[1].length == 1 ? opt[k] : opt[k].padStart(ret[1].length, '0'));
}
}
return fmt;
}
/**
* @description 除undefined,null,NaN以外都为true
* @export
......
......@@ -52,6 +52,7 @@ export const CtrlConfig = {
controlName: '{{ctrl.name}}',
controlService: new EditFormService<ControlVO>(ControlVO, new {{pascalCase ctrl.psAppDataEntity.codeName}}Service() ),
data: new ControlVO({}),
enableAutoSave: {{ctrl.enableAutoSave}},
detailsModel: {
{{#each ctrl.psDEFormPages as | FormPage | }}
{{>(lookup 'FORMDETAILSMODEL') items=FormPage.psDEFormDetails}}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册