官网文档:https://vxetable.cn
vxe-table grid 表格数据校验错误提示框的主题样式,修改校验提示消息的样式非常简单,内置例子样式,普通样式和高亮样式,可以通过全局或局部方式进行设置。

默认的校验提示样式

{8FE2C831-79F9-42D6-9E21-784BF8BF9396}.png

美化校验提示样式

默认的错误提示样式不好看,设置为美化主题样式,通过参数 validConfig.theme = 'beautify' 就可以了,也可以全局设置

import { VxeUI } from 'vxe-table'

VxeUI.setConfig({
  table: {
    validConfig: {
       theme: 'beautify'
    }
  }
})

{528DF0C4-4FDE-4206-BB51-ACEA948BA257}.png

{5A7E6893-A1F9-4A71-83AE-8A03D03DC4FB}.png

<template>
  <div>
    <div>
      <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 setup>
import { ref, reactive } from 'vue'
import { VxeUI } from 'vxe-table'

const gridRef = ref()

const gridOptions = reactive({
  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' }
  ]
})

const validEvent = async () => {
  const $grid = gridRef.value
  if ($grid) {
    const errMap = await $grid.fullValidate()
    if (errMap) {
      VxeUI.modal.message({ status: 'error', content: '校验不通过!' })
    } else {
      VxeUI.modal.message({ status: 'success', content: '校验成功!' })
    }
  }
}

const fullValidEvent = async () => {
  const $grid = gridRef.value
  if ($grid) {
    const errMap = await $grid.fullValidate(true)
    if (errMap) {
      VxeUI.modal.message({ status: 'error', content: '校验不通过!' })
    } else {
      VxeUI.modal.message({ status: 'success', content: '校验成功!' })
    }
  }
}
</script>

github
gitee


abc26296
172 声望24 粉丝