提交 03de3d9e 编写于 作者: zhangkang's avatar zhangkang

update:表格值规则

上级 64779705
......@@ -9,11 +9,17 @@
{{#if (eq item.columnType 'DEFGRIDCOLUMN')}}
{{#if item.enableRowEdit}}
<div v-if="state.rowEditState" class="editor-cell">
<AppFormItem
name="state"
:error="state.gridEditState.state?.[index]?.message"
:rules="state.rules.state"
>
{{#each ctrl.psDEGridEditItems as | editColumn | }}
{{#if (eq editColumn.codeName item.codeName)}}
{{>(lookup . 'editColumn.psEditor.editorType') item=editColumn ctrlType="grid"}}
{{/if}}
{{/each}}
</AppFormItem>
</div>
<div v-else class="text-cell">
<span class="text">\{{text}}</span>
......
......@@ -25,6 +25,7 @@
"vue": "^3.2.23",
"vue-global-api": "^0.4.1",
"vue-router": "^4.0.12",
"async-validator":"^3.3.0",
"moment": "2.24.0"
},
"devDependencies": {
......
......@@ -29,6 +29,14 @@ export interface GridControlState extends MDControlState {
*/
rules: IParam;
/**
* 表格编辑状态
*
* @type {IParam[]}
* @memberof GridControlState
*/
gridEditState: any;
/**
* @description 表格聚合
* @type {IParam}
......
import { deepCopy, GridControlState, IActionParam, IParam, MDControl } from "@core";
import { createUUID } from "qx-util";
import schema, { ErrorList, FieldErrorList } from 'async-validator';
/**
* @description 表格部件
* @export
......@@ -73,7 +73,7 @@ export class GridControl extends MDControl {
return false;
}
return {
type:isSingleSelect ? 'radio' : 'checkbox',
type: isSingleSelect ? 'radio' : 'checkbox',
columnWidth: 90,
selectedRowKeys: selectedRowKeys.value,
checkStrictly: this.props.multiple ? false : true,
......@@ -125,6 +125,7 @@ export class GridControl extends MDControl {
if (items.value[rowIndex][tag] !== data) {
items.value[rowIndex][tag] = data;
items.value[rowIndex]["rowDataState"] = "update";
this.validateField(tag, data, rowIndex);
}
break;
default:
......@@ -132,6 +133,32 @@ export class GridControl extends MDControl {
}
}
/**
*
*
* @param {string} name
* @param {*} value
* @memberof GridControl
*/
public validateField(name: string, value: any, rowIndex: number): Promise<boolean> {
return new Promise((resolve: any, reject: any) => {
const { rules, gridEditState } = toRefs(this.state);
const fileRule = rules.value[name];
if (!fileRule) {
resolve(true);
return;
}
const validator = new schema({ [name]: fileRule });
validator.validate({ [name]: value }, undefined, (errors: ErrorList, fields: FieldErrorList) => {
const error =errors?.find((item:any)=>{
return item.field === name;
})
gridEditState.value[name][rowIndex] = error;
})
})
}
/**
* @description 操作列事件触发
* @param {IActionParam} action
......@@ -139,7 +166,7 @@ export class GridControl extends MDControl {
* @memberof GridControl
*/
public onToolbarEvent(action: IActionParam, record: IParam) {
//todo 界面行为
//todo 界面行为
}
/**
......@@ -201,7 +228,7 @@ export class GridControl extends MDControl {
/**
* @description 处理数据聚合
*
*
* @memberof GridControl
*/
public async handleDataAgg() {
......@@ -246,7 +273,7 @@ export class GridControl extends MDControl {
/**
* @description 远程聚合
*
*
* @memberof GridControl
*/
public async remoteAgg(): Promise<IParam[]> {
......@@ -258,7 +285,7 @@ export class GridControl extends MDControl {
/**
* @description 获取聚合值
*
*
* @param {IParam[]} aggData 聚合数据
* @param {string} column 列模型
* @memberof GridControl
......@@ -440,6 +467,8 @@ export class GridControl extends MDControl {
*/
public moduleInstall() {
const superParams = super.moduleInstall();
console.log(this.state);
return {
...superParams,
useCustom: this.useCustom(),
......
......@@ -70,6 +70,13 @@ export const ctrlState = {
{{>(lookup 'UACOLUMNMODEL') item=column}}
{{/each}}
],
gridEditState:{
{{#each ctrl.psDEGridEditItems as | column |}}
{{#if column.codeName }}
{{column.codeName}}:{},
{{/if}}
{{/each}}
},
columnsModel: [
{{#if ctrl.enableGroup}}
{{#if ctrl.groupPSAppDEField}}
......@@ -90,4 +97,18 @@ export const ctrlState = {
],
// 是否单选
isSingleSelect:{{#if ctrl.singleSelect}}{{ctrl.singleSelect}}{{else}}false{{/if}},
rules:{
{{#each ctrl.psDEGridEditItemVRs as | ruleItem |}}
{{#if ruleItem.valueRuleType 'SYSVALUERULE'}}
{{ruleItem.psDEGridEditItemName}}: [
{
trigger: ['change', 'blur'],
{{#eq ruleItem.psSysValueRule.ruleType 'REG'}}
pattern: /{{ruleItem.psSysValueRule.regExCode}}/,
{{/eq}}
message:'{{ruleItem.psSysValueRule.ruleInfo}}'
}],
{{/if}}
{{/each}}
}
};
\ No newline at end of file
......@@ -43,58 +43,60 @@ const { useScrollOption, useRowKey, useRowClassName, useCustomRow, useRowSelecti
defineExpose({ state, name: '{{ctrl.name}}', newRow, remove, save, load, refresh, getData });
</script>
<template>
<a-table
bordered
sticky
class="app-grid{{#if ctrl.psSysCss}} {{ctrl.psSysCss.cssName}}{{/if}}"
:rowKey="useRowKey"
:showHeader="true"
:scroll="useScrollOption"
:sortDirections="['ascend', 'descend']"
:data-source="state.items"
:row-selection="useRowSelectionOption"
:columns="state.columnsModel"
:pagination="state.mdCtrlPaging.pagination"
:customRow="useCustomRow"
:rowClassName="useRowClassName"
@change="onGridChange"
@resizeColumn="onResizeColumn"
>
<template #emptyText>
<div class="not-data">
<span class="empty-text">
{{#if ctrl.emptyText}}
{{ctrl.emptyText}}
{{else}}
无数据
{{/if}}
</span>
{{!-- 快速工具栏 --}}
</div>
</template>
<template #headerCell="{title, column}">
{{#each ctrl.psDEGridColumns as | column |}}
{{>(lookup 'COLUMNHEADER') item=column ctrl=ctrl}}
{{/each}}
</template>
<template #bodyCell="{ column, text, record, index }">
{{#each ctrl.psDEGridColumns as | column |}}
{{>(lookup 'COLUMN') item=column ctrl=ctrl}}
{{/each}}
</template>
{{#neq ctrl.aggMode 'NONE'}}
<template #summary>
<a-table-summary>
<a-table-summary-row>
<a-table-summary-cell align="center">数据聚合</a-table-summary-cell>
<a-table-summary-cell v-for="(item, index) in state.gridAgg.aggData" :key="index">
<span>\{{item}}</span>
</a-table-summary-cell>
</a-table-summary-row>
</a-table-summary>
</template>
{{/neq}}
</a-table>
<a-form name="{{ctrl.name}}" class="app-grid-form" >
<a-table
bordered
sticky
class="app-grid{{#if ctrl.psSysCss}} {{ctrl.psSysCss.cssName}}{{/if}}"
:rowKey="useRowKey"
:showHeader="true"
:scroll="useScrollOption"
:sortDirections="['ascend', 'descend']"
:data-source="state.items"
:row-selection="useRowSelectionOption"
:columns="state.columnsModel"
:pagination="state.mdCtrlPaging.pagination"
:customRow="useCustomRow"
:rowClassName="useRowClassName"
@change="onGridChange"
@resizeColumn="onResizeColumn"
>
<template #emptyText>
<div class="not-data">
<span class="empty-text">
{{#if ctrl.emptyText}}
{{ctrl.emptyText}}
{{else}}
无数据
{{/if}}
</span>
{{!-- 快速工具栏 --}}
</div>
</template>
<template #headerCell="{title, column}">
{{#each ctrl.psDEGridColumns as | column |}}
{{>(lookup 'COLUMNHEADER') item=column ctrl=ctrl}}
{{/each}}
</template>
<template #bodyCell="{ column, text, record, index }">
{{#each ctrl.psDEGridColumns as | column |}}
{{>(lookup 'COLUMN') item=column ctrl=ctrl}}
{{/each}}
</template>
{{#neq ctrl.aggMode 'NONE'}}
<template #summary>
<a-table-summary>
<a-table-summary-row>
<a-table-summary-cell align="center">数据聚合</a-table-summary-cell>
<a-table-summary-cell v-for="(item, index) in state.gridAgg.aggData" :key="index">
<span>\{{item}}</span>
</a-table-summary-cell>
</a-table-summary-row>
</a-table-summary>
</template>
{{/neq}}
</a-table>
</a-form>
</template>
<style lang="scss">
.app-grid {
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册