11<template >
22 <div >
3- <vxe-grid v-bind =" gridOptions" ></vxe-grid >
3+ <div >
4+ <vxe-radio-group v-model =" gridOptions.validConfig.theme" >
5+ <vxe-radio-button checked-value =" normal" content =" 简化" ></vxe-radio-button >
6+ <vxe-radio-button checked-value =" beautify" content =" 高亮" ></vxe-radio-button >
7+ </vxe-radio-group >
8+
9+ <vxe-button @click =" validEvent" >校验变动数据</vxe-button >
10+ <vxe-button @click =" fullValidEvent" >校验全量数据</vxe-button >
11+ </div >
12+ <vxe-grid ref =" gridRef" v-bind =" gridOptions" ></vxe-grid >
413 </div >
514</template >
615
716<script lang="ts" setup>
8- import { reactive } from ' vue'
9- import type { VxeGridProps } from ' ../../../types'
17+ import { ref , reactive } from ' vue'
18+ import { VxeUI } from ' ../../../packages'
19+ import { VxeGridProps , VxeTablePropTypes , VxeGridInstance } from ' ../../../types'
1020
1121interface RowVO {
1222 id: number
@@ -17,27 +27,71 @@ interface RowVO {
1727 address: string
1828}
1929
20- const gridOptions = reactive <VxeGridProps <RowVO >>({
21- customConfig: {
22- mode: ' modal' ,
23- checkMethod ({ column }) {
24- return ! [' seq' , ' name' ].includes (column .field )
25- }
30+ const gridRef = ref <VxeGridInstance <RowVO >>()
31+
32+ const gridOptions = reactive <VxeGridProps <RowVO > & { validConfig: VxeTablePropTypes .ValidConfig }>({
33+ border: true ,
34+ showOverflow: true ,
35+ keepSource: true ,
36+ height: 300 ,
37+ editConfig: {
38+ trigger: ' click' ,
39+ mode: ' row' ,
40+ showStatus: true
2641 },
27- toolbarConfig: {
28- custom: true
42+ validConfig: {
43+ msgMode: ' full' ,
44+ theme: ' beautify' ,
45+ showErrorBackground: true
46+ },
47+ editRules: {
48+ name: [
49+ { required: true , message: ' 必须填写' }
50+ ],
51+ role: [
52+ { required: true , message: ' 必须填写' }
53+ ]
2954 },
3055 columns: [
31- { field: ' seq' , type: ' seq' , width: 70 },
32- { field: ' name' , title: ' Name' },
33- { field: ' sex' , title: ' Sex' },
34- { field: ' age' , title: ' Age' }
56+ { type: ' checkbox' , width: 60 },
57+ { type: ' seq' , width: 70 },
58+ { field: ' name' , title: ' Name' , editRender: { name: ' VxeInput' } },
59+ { field: ' role' , title: ' Role' , editRender: { name: ' VxeInput' } },
60+ { field: ' sex' , title: ' Sex' , editRender: { name: ' VxeInput' } },
61+ { field: ' age' , title: ' Age' , editRender: { name: ' VxeInput' } },
62+ { field: ' date' , title: ' Date' , editRender: { name: ' VxeInput' } }
3563 ],
3664 data: [
37- { id: 10001 , name: ' Test1' , role: ' Develop' , sex: ' Man' , age: 28 , address: ' test abc' },
38- { id: 10002 , name: ' Test2' , role: ' Test' , sex: ' Women' , age: 22 , address: ' Guangzhou' },
39- { id: 10003 , name: ' Test3' , role: ' PM' , sex: ' Man' , age: 32 , address: ' Shanghai' },
40- { id: 10004 , name: ' Test4' , role: ' Designer' , sex: ' Women' , age: 24 , address: ' Shanghai' }
65+ { id: 10001 , name: ' Test1' , role: ' Develop' , sex: ' 0' , age: 28 , address: ' test abc' },
66+ { id: 10002 , name: ' ' , role: ' Test' , sex: ' 1' , age: 22 , address: ' Guangzhou' },
67+ { id: 10003 , name: ' Test3' , role: ' PM' , sex: ' ' , age: 32 , address: ' Shanghai' },
68+ { id: 10004 , name: ' Test4' , role: ' Designer' , sex: ' ' , age: 23 , address: ' test abc' },
69+ { id: 10005 , name: ' ' , role: ' ' , sex: ' 1' , age: 30 , address: ' Shanghai' },
70+ { id: 10006 , name: ' Test6' , role: ' Designer' , sex: ' 1' , age: 21 , address: ' test abc' }
4171 ]
4272})
73+
74+ const validEvent = async () => {
75+ const $grid = gridRef .value
76+ if ($grid ) {
77+ const errMap = await $grid .fullValidate ()
78+ if (errMap ) {
79+ VxeUI .modal .message ({ status: ' error' , content: ' 校验不通过!' })
80+ } else {
81+ VxeUI .modal .message ({ status: ' success' , content: ' 校验成功!' })
82+ }
83+ }
84+ }
85+
86+ const fullValidEvent = async () => {
87+ const $grid = gridRef .value
88+ if ($grid ) {
89+ const errMap = await $grid .fullValidate (true )
90+ if (errMap ) {
91+ VxeUI .modal .message ({ status: ' error' , content: ' 校验不通过!' })
92+ } else {
93+ VxeUI .modal .message ({ status: ' success' , content: ' 校验成功!' })
94+ }
95+ }
96+ }
4397 </script >
0 commit comments