vxe-grid table 修改表格数据校验的主题样式
在使用 vxe-table 可编辑表格时,数据校验可以支持2种主题样式
普通样式
通过设置 valid-config.theme=‘normal’ 设置为普通样式
高亮样式
通过设置 valid-config.theme=‘beautify’ 设置为高亮样式
<template>
<div>
<div>
<vxe-radio-group v-model="gridOptions.validConfig.theme">
<vxe-radio-button label="normal" content="简化"></vxe-radio-button>
<vxe-radio-button label="beautify" content="高亮"></vxe-radio-button>
</vxe-radio-group>
<vxe-button @click="validEvent">校验变动数据</vxe-button>
<vxe-button @click="fullValidEvent">校验全量数据</vxe-button>
</div>
<vxe-grid ref="gridRef" v-bind="gridOptions"></vxe-grid>
</div>
</template>
<script>
import { VxeUI } from 'vxe-table'
export default {
data () {
const gridOptions = {
border: true,
showOverflow: true,
keepSource: true,
height: 300,
editConfig: {
trigger: 'click',
mode: 'row',
showStatus: true
},
validConfig: {
msgMode: 'full',
theme: 'beautify'
},
editRules: {
name: [
{ required: true, message: '必须填写' }
],
role: [
{ required: true, message: '必须填写' }
]
},
columns: [
{ type: 'checkbox', width: 60 },
{ type: 'seq', width: 70 },
{ field: 'name', title: 'Name', editRender: { name: 'VxeInput' } },
{ field: 'role', title: 'Role', editRender: { name: 'VxeInput' } },
{ field: 'sex', title: 'Sex', editRender: { name: 'VxeInput' } },
{ field: 'age', title: 'Age', editRender: { name: 'VxeInput' } },
{ field: 'date', title: 'Date', editRender: { name: 'VxeInput' } }
],
data: [
{ id: 10001, name: 'Test1', role: 'Develop', sex: '0', age: 28, address: 'test abc' },
{ id: 10002, name: '', role: 'Test', sex: '1', age: 22, address: 'Guangzhou' },
{ id: 10003, name: 'Test3', role: 'PM', sex: '', age: 32, address: 'Shanghai' },
{ id: 10004, name: 'Test4', role: 'Designer', sex: '', age: 23, address: 'test abc' },
{ id: 10005, name: '', role: '', sex: '1', age: 30, address: 'Shanghai' },
{ id: 10006, name: 'Test6', role: 'Designer', sex: '1', age: 21, address: 'test abc' }
]
}
return {
gridOptions
}
},
methods: {
async validEvent () {
const $grid = this.$refs.gridRef
if ($grid) {
const errMap = await $grid.fullValidate()
if (errMap) {
VxeUI.modal.message({ status: 'error', content: '校验不通过!' })
} else {
VxeUI.modal.message({ status: 'success', content: '校验成功!' })
}
}
},
async fullValidEvent () {
const $grid = this.$refs.gridRef
if ($grid) {
const errMap = await $grid.fullValidate(true)
if (errMap) {
VxeUI.modal.message({ status: 'error', content: '校验不通过!' })
} else {
VxeUI.modal.message({ status: 'success', content: '校验成功!' })
}
}
}
}
}
</script>