重构校验
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
[](https://github.com/x-extends/vxe-table/pulls?q=is%3Apr+is%3Aclosed)
|
||||
[](LICENSE)
|
||||
|
||||
A [vue](https://www.npmjs.com/package/vue) based PC form component, support add, delete, change, virtual list, virtual tree, lazy load, shortcut menu, data validation, print export, form rendering, data paging, modal window, custom template, renderer, flexible configuration items, etc...
|
||||
A [vue](https://www.npmjs.com/package/vue) based PC form component, support add, delete, change, virtual list, virtual tree, lazy load, shortcut menu, data validation, print export, form rendering, data paging, modal window, custom template, renderer, JSON configuration designed for zero code...
|
||||
|
||||
* Design concept
|
||||
* Efficient and concise API design for modern browsers.
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
[](https://github.com/x-extends/vxe-table/pulls?q=is%3Apr+is%3Aclosed)
|
||||
[](LICENSE)
|
||||
|
||||
一个基于 [vue](https://www.npmjs.com/package/vue) 的 PC 端表格组件,支持增删改查、虚拟列表、虚拟树、懒加载、快捷菜单、数据校验、打印导出、表单渲染、数据分页、弹窗、自定义模板、渲染器、贼灵活的配置项等...
|
||||
一个基于 [vue](https://www.npmjs.com/package/vue) 的 PC 端表格组件,支持增删改查、虚拟列表、虚拟树、懒加载、快捷菜单、数据校验、打印导出、表单渲染、数据分页、弹窗、自定义模板、渲染器、JSON 配置式为零代码而设计...
|
||||
|
||||
* 设计理念
|
||||
* 面向现代浏览器,高效的简洁 API 设计
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
[](https://github.com/x-extends/vxe-table/pulls?q=is%3Apr+is%3Aclosed)
|
||||
[](LICENSE)
|
||||
|
||||
一個基於 [vue](https://www.npmjs.com/package/vue) 的PC端表格組件,支持增删改查、虛擬清單、虛擬樹、懶加載、快捷選單、數據校驗、列印匯出、表單渲染、數據分頁、彈窗、自定義範本、渲染器、賊靈活的配寘項等…
|
||||
一個基於 [vue](https://www.npmjs.com/package/vue) 的PC端表格組件,支持增删改查、虛擬清單、虛擬樹、懶加載、快捷選單、數據校驗、列印匯出、表單渲染、數據分頁、彈窗、自定義範本、渲染器、JSON 配置式爲零代碼而設計…
|
||||
|
||||
* 設計理念
|
||||
* 面向現代瀏覽器,高效的簡潔 API 設計
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import './setup'
|
||||
import './renderer'
|
||||
import './formats'
|
||||
import './menus'
|
||||
import './validators'
|
||||
|
||||
13
examples/plugins/table/menus.ts
Normal file
13
examples/plugins/table/menus.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { VXETable } from '../../../packages/all'
|
||||
|
||||
// 自定义全局的格式化处理函数
|
||||
VXETable.menus.mixin({
|
||||
alertMsg: {
|
||||
menuMethod () {
|
||||
alert('1')
|
||||
}
|
||||
},
|
||||
test1 () {
|
||||
alert('2')
|
||||
}
|
||||
})
|
||||
12
examples/plugins/table/validators.ts
Normal file
12
examples/plugins/table/validators.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { VXETable } from '../../../packages/all'
|
||||
|
||||
// 自定义全局的格式化处理函数
|
||||
VXETable.validators.mixin({
|
||||
mobile: {
|
||||
cellValidatorMethod ({ cellValue }) {
|
||||
if (!cellValue) {
|
||||
return new Error('手机号不正确')
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "vxe-table",
|
||||
"version": "4.5.0-beta.12",
|
||||
"description": "一个基于 vue 的 PC 端表格组件,支持增删改查、虚拟列表、虚拟树、懒加载、快捷菜单、数据校验、树形结构、打印导出、表单渲染、数据分页、弹窗、自定义模板、渲染器等...",
|
||||
"version": "4.5.0-beta.13",
|
||||
"description": "一个基于 vue 的 PC 端表格组件,支持增删改查、虚拟列表、虚拟树、懒加载、快捷菜单、数据校验、树形结构、打印导出、表单渲染、数据分页、弹窗、自定义模板、渲染器、JSON 配置式为零代码而设计...",
|
||||
"scripts": {
|
||||
"update": "npm install --legacy-peer-deps",
|
||||
"serve": "vue-cli-service serve",
|
||||
|
||||
@@ -3,7 +3,7 @@ import XEUtils from 'xe-utils'
|
||||
import GlobalConfig from '../../v-x-e-table/src/conf'
|
||||
import { VXETable } from '../../v-x-e-table'
|
||||
import { getFuncText, isEnableConf, eqEmptyValue } from '../../tools/utils'
|
||||
import { errLog } from '../../tools/log'
|
||||
import { errLog, warnLog } from '../../tools/log'
|
||||
import { scrollToView } from '../../tools/dom'
|
||||
import { createItem, handleFieldOrItem, isHiddenItem, isActivetem } from './util'
|
||||
import { useSize } from '../../hooks/size'
|
||||
@@ -327,10 +327,10 @@ export default defineComponent({
|
||||
if (rules) {
|
||||
const itemValue = XEUtils.isUndefined(val) ? XEUtils.get(data, property) : val
|
||||
rules.forEach((rule) => {
|
||||
const { type, trigger, required } = rule
|
||||
const { type, trigger, required, validator } = rule
|
||||
if (validType === 'all' || !trigger || validType === trigger) {
|
||||
if (XEUtils.isFunction(rule.validator)) {
|
||||
const customValid = rule.validator({
|
||||
if (validator) {
|
||||
const validParams = {
|
||||
itemValue,
|
||||
rule,
|
||||
rules,
|
||||
@@ -338,7 +338,26 @@ export default defineComponent({
|
||||
field: property,
|
||||
property,
|
||||
$form: $xeform
|
||||
})
|
||||
}
|
||||
let customValid: any
|
||||
if (XEUtils.isString(validator)) {
|
||||
const gvItem = VXETable.validators.get(validator)
|
||||
if (gvItem) {
|
||||
if (gvItem.itemValidatorMethod) {
|
||||
customValid = gvItem.itemValidatorMethod(validParams)
|
||||
} else {
|
||||
if (process.env.VUE_APP_VXE_TABLE_ENV === 'development') {
|
||||
warnLog('vxe.error.notValidators', [validator])
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (process.env.VUE_APP_VXE_TABLE_ENV === 'development') {
|
||||
errLog('vxe.error.notValidators', [validator])
|
||||
}
|
||||
}
|
||||
} else {
|
||||
customValid = validator(validParams)
|
||||
}
|
||||
if (customValid) {
|
||||
if (XEUtils.isError(customValid)) {
|
||||
errorRules.push(new Rule({ type: 'custom', trigger, content: customValid.message, rule: new Rule(rule) }))
|
||||
|
||||
@@ -66,7 +66,10 @@ export default defineComponent({
|
||||
clearable: { type: Boolean as PropType<VxeInputPropTypes.Clearable>, default: () => GlobalConfig.input.clearable },
|
||||
readonly: Boolean as PropType<VxeInputPropTypes.Readonly>,
|
||||
disabled: Boolean as PropType<VxeInputPropTypes.Disabled>,
|
||||
placeholder: String as PropType<VxeInputPropTypes.Placeholder>,
|
||||
placeholder: {
|
||||
type: String as PropType<VxeInputPropTypes.Placeholder>,
|
||||
default: () => XEUtils.eqNull(GlobalConfig.input.placeholder) ? GlobalConfig.i18n('vxe.base.pleaseInput') : GlobalConfig.input.placeholder
|
||||
},
|
||||
maxlength: [String, Number] as PropType<VxeInputPropTypes.Maxlength>,
|
||||
autocomplete: { type: String as PropType<VxeInputPropTypes.Autocomplete>, default: 'off' },
|
||||
align: String as PropType<VxeInputPropTypes.Align>,
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
export default {
|
||||
vxe: {
|
||||
base: {
|
||||
pleaseInput: 'Please input',
|
||||
pleaseSelect: 'Select'
|
||||
},
|
||||
loading: {
|
||||
text: 'Loading...'
|
||||
},
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
export default {
|
||||
vxe: {
|
||||
base: {
|
||||
pleaseInput: 'Please input',
|
||||
pleaseSelect: 'Select'
|
||||
},
|
||||
loading: {
|
||||
text: 'Cargando...'
|
||||
},
|
||||
@@ -19,6 +23,7 @@ export default {
|
||||
errProp: 'Parámetro no compatible "{0}", posiblemente "{1}".',
|
||||
colRepet: 'columna.{0}="{0}" está duplicado, lo que puede hacer que algunas funciones sean inutilizables',
|
||||
notFunc: 'El método "{0}" no existe.',
|
||||
notValidators: 'Global validators "{0}" no existe.',
|
||||
notSlot: 'La ranura "{0}" no existe.',
|
||||
noTree: 'La estructura de árbol no soporta "{0}".',
|
||||
notProp: 'Parámetros no compatibles "{0}"',
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
export default {
|
||||
vxe: {
|
||||
base: {
|
||||
pleaseInput: 'Please input',
|
||||
pleaseSelect: 'Select'
|
||||
},
|
||||
loading: {
|
||||
text: 'Loading...'
|
||||
},
|
||||
@@ -19,6 +23,7 @@ export default {
|
||||
errProp: 'サポートされていないパラメーター "{0}","{1}" の可能性があります',
|
||||
colRepet: 'column.{0}="{0}" が重複しているため、機能が使えなくなることがあります。',
|
||||
notFunc: 'method "{0}" はありません',
|
||||
notValidators: 'Global validators "{0}" no existe.',
|
||||
notSlot: 'slot "{0}" はありません',
|
||||
noTree: 'Tree structureは "{0}" をサポートしていません',
|
||||
notProp: 'サポートされていないパラメータ "{0}"',
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
export default {
|
||||
vxe: {
|
||||
base: {
|
||||
pleaseInput: '请输入',
|
||||
pleaseSelect: '请选择'
|
||||
},
|
||||
loading: {
|
||||
text: '加载中...'
|
||||
},
|
||||
@@ -19,6 +23,7 @@ export default {
|
||||
errProp: '不支持的参数 "{0}",可能为 "{1}"',
|
||||
colRepet: 'column.{0}="{1}" 重复了,这可能会导致某些功能无法使用',
|
||||
notFunc: '方法 "{0}" 不存在',
|
||||
notValidators: '全局校验 "{0}" 不存在',
|
||||
notSlot: '插槽 "{0}" 不存在',
|
||||
noTree: '树结构不支持 "{0}"',
|
||||
notProp: '不支持的参数 "{0}"',
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
export default {
|
||||
vxe: {
|
||||
base: {
|
||||
pleaseInput: '请输入',
|
||||
pleaseSelect: '请选择'
|
||||
},
|
||||
loading: {
|
||||
text: '加載中...'
|
||||
},
|
||||
@@ -19,6 +23,7 @@ export default {
|
||||
errProp: '不支持的參數 "{0}",可能為 "{1}"',
|
||||
colRepet: 'column.{0}="{1}" 重複了,這可能會導致某些功能無法使用',
|
||||
notFunc: '方法 "{0}" 不存在',
|
||||
notValidators: '全局校验 "{0}" 不存在',
|
||||
notSlot: '插槽 "{0}" 不存在',
|
||||
noTree: '樹狀結構不支援 {0}',
|
||||
notProp: '不支持的參數 "{0}"',
|
||||
|
||||
@@ -279,10 +279,10 @@ const tableMenuHook: VxeGlobalHooksHandles.HookOptions = {
|
||||
ctxMenuLinkEvent (evnt, menu) {
|
||||
// 如果一级菜单有配置 code 则允许点击,否则不能点击
|
||||
if (!menu.disabled && (menu.code || !menu.children || !menu.children.length)) {
|
||||
const ctxMenuMethod = VXETable.menus.get(menu.code)
|
||||
const gMenuOpts = VXETable.menus.get(menu.code)
|
||||
const params = Object.assign({}, internalData._currMenuParams, { menu, $table: $xetable, $grid: $xetable.xegrid, $event: evnt })
|
||||
if (ctxMenuMethod) {
|
||||
ctxMenuMethod(params, evnt)
|
||||
if (gMenuOpts && gMenuOpts.menuMethod) {
|
||||
gMenuOpts.menuMethod(params, evnt)
|
||||
}
|
||||
$xetable.dispatchEvent('menu-click', params, evnt)
|
||||
menuMethods.closeMenu()
|
||||
|
||||
@@ -23,7 +23,10 @@ export default defineComponent({
|
||||
props: {
|
||||
modelValue: null,
|
||||
clearable: Boolean as PropType<VxeSelectPropTypes.Clearable>,
|
||||
placeholder: String as PropType<VxeSelectPropTypes.Placeholder>,
|
||||
placeholder: {
|
||||
type: String as PropType<VxeSelectPropTypes.Placeholder>,
|
||||
default: () => XEUtils.eqNull(GlobalConfig.select.placeholder) ? GlobalConfig.i18n('vxe.base.pleaseSelect') : GlobalConfig.select.placeholder
|
||||
},
|
||||
loading: Boolean as PropType<VxeSelectPropTypes.Loading>,
|
||||
disabled: Boolean as PropType<VxeSelectPropTypes.Disabled>,
|
||||
multiple: Boolean as PropType<VxeSelectPropTypes.Multiple>,
|
||||
|
||||
@@ -4169,14 +4169,14 @@ export default defineComponent({
|
||||
* 如果组件值 v-model 发生 change 时,调用改函数用于更新某一列编辑状态
|
||||
* 如果单元格配置了校验规则,则会进行校验
|
||||
*/
|
||||
updateStatus (scope, cellValue) {
|
||||
updateStatus (slotParams, cellValue) {
|
||||
const customVal = !XEUtils.isUndefined(cellValue)
|
||||
return nextTick().then(() => {
|
||||
const { editRules } = props
|
||||
const { validStore } = reactData
|
||||
const tableBody = refTableBody.value
|
||||
if (!scope && tableBody && editRules) {
|
||||
const { row, column } = scope
|
||||
if (slotParams && tableBody && editRules) {
|
||||
const { row, column } = slotParams
|
||||
const type = 'change'
|
||||
if ($xetable.hasCellRules) {
|
||||
if ($xetable.hasCellRules(type, row, column)) {
|
||||
|
||||
@@ -17,7 +17,10 @@ export default defineComponent({
|
||||
name: String as PropType<VxeTextareaPropTypes.Name>,
|
||||
readonly: Boolean as PropType<VxeTextareaPropTypes.Readonly>,
|
||||
disabled: Boolean as PropType<VxeTextareaPropTypes.Disabled>,
|
||||
placeholder: String as PropType<VxeTextareaPropTypes.Placeholder>,
|
||||
placeholder: {
|
||||
type: String as PropType<VxeTextareaPropTypes.Placeholder>,
|
||||
default: () => XEUtils.eqNull(GlobalConfig.textarea.placeholder) ? GlobalConfig.i18n('vxe.base.pleaseInput') : GlobalConfig.textarea.placeholder
|
||||
},
|
||||
maxlength: [String, Number] as PropType<VxeTextareaPropTypes.Maxlength>,
|
||||
rows: { type: [String, Number] as PropType<VxeTextareaPropTypes.Rows>, default: 2 },
|
||||
cols: { type: [String, Number] as PropType<VxeTextareaPropTypes.Cols>, default: null },
|
||||
|
||||
@@ -5,6 +5,7 @@ import { renderer } from './src/renderer'
|
||||
import { commands } from './src/commands'
|
||||
import { menus } from './src/menus'
|
||||
import { formats } from './src/formats'
|
||||
import { validators } from './src/validators'
|
||||
import { hooks } from './src/hooks'
|
||||
import { setup } from './src/setup'
|
||||
import { getLastZIndex, nextZIndex } from '../tools/utils'
|
||||
@@ -83,6 +84,7 @@ export const VXETable = {
|
||||
renderer,
|
||||
commands,
|
||||
formats,
|
||||
validators,
|
||||
menus,
|
||||
hooks,
|
||||
config,
|
||||
@@ -96,6 +98,7 @@ export * from './src/renderer'
|
||||
export * from './src/commands'
|
||||
export * from './src/menus'
|
||||
export * from './src/formats'
|
||||
export * from './src/validators'
|
||||
export * from './src/hooks'
|
||||
export * from './src/setup'
|
||||
|
||||
|
||||
@@ -1,8 +1,58 @@
|
||||
import VXEStore from './store'
|
||||
import XEUtils from 'xe-utils'
|
||||
import { warnLog } from '../../tools/log'
|
||||
|
||||
import { VxeGlobalMenus } from '../../../types/v-x-e-table'
|
||||
|
||||
export const menus = new VXEStore() as VxeGlobalMenus
|
||||
class VXEMenusStore {
|
||||
private store: any = {}
|
||||
|
||||
mixin (options: any): VXEMenusStore {
|
||||
XEUtils.each(options, (item, key) => {
|
||||
this.add(key, item)
|
||||
})
|
||||
return this
|
||||
}
|
||||
|
||||
has (name: string): boolean {
|
||||
return !!this.get(name)
|
||||
}
|
||||
|
||||
get (name: string): any {
|
||||
return this.store[name]
|
||||
}
|
||||
|
||||
add (name: string, render: any): VXEMenusStore {
|
||||
const conf = this.store[name]
|
||||
// 兼容
|
||||
if (XEUtils.isFunction(render)) {
|
||||
render = {
|
||||
menuMethod: render
|
||||
}
|
||||
}
|
||||
|
||||
// 检测是否覆盖
|
||||
if (process.env.VUE_APP_VXE_TABLE_ENV === 'development') {
|
||||
const confKeys = XEUtils.keys(conf)
|
||||
XEUtils.each(render, (item, key) => {
|
||||
if (confKeys.includes(key)) {
|
||||
warnLog('vxe.error.coverProp', [name, key])
|
||||
}
|
||||
})
|
||||
}
|
||||
this.store[name] = conf ? XEUtils.merge(conf, render) : render
|
||||
return this
|
||||
}
|
||||
|
||||
delete (name: string): void {
|
||||
delete this.store[name]
|
||||
}
|
||||
|
||||
forEach (callback: any): void {
|
||||
XEUtils.objectEach(this.store, callback)
|
||||
}
|
||||
}
|
||||
|
||||
export const menus = new VXEMenusStore() as VxeGlobalMenus
|
||||
|
||||
if (process.env.VUE_APP_VXE_TABLE_ENV === 'development') {
|
||||
Object.assign(menus, { _name: 'Menus' })
|
||||
|
||||
@@ -8,7 +8,9 @@ export class Store {
|
||||
private store: any = {}
|
||||
|
||||
mixin (options: any): Store {
|
||||
Object.assign(this.store, options)
|
||||
XEUtils.each(options, (item, key) => {
|
||||
this.add(key, item)
|
||||
})
|
||||
return this
|
||||
}
|
||||
|
||||
|
||||
9
packages/v-x-e-table/src/validators.ts
Normal file
9
packages/v-x-e-table/src/validators.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import VXEStore from './store'
|
||||
|
||||
import { VxeGlobalValidators } from '../../../types/v-x-e-table'
|
||||
|
||||
export const validators = new VXEStore() as VxeGlobalValidators
|
||||
|
||||
if (process.env.VUE_APP_VXE_TABLE_ENV === 'development') {
|
||||
Object.assign(validators, { _name: 'Validators' })
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
import { nextTick } from 'vue'
|
||||
import GlobalConfig from '../../v-x-e-table/src/conf'
|
||||
import XEUtils from 'xe-utils'
|
||||
import { VXETable } from '../../v-x-e-table'
|
||||
import { getFuncText, eqEmptyValue } from '../../tools/utils'
|
||||
import { scrollToView } from '../../tools/dom'
|
||||
import { errLog, warnLog } from '../../tools/log'
|
||||
import { handleFieldOrColumn, getRowid } from '../../table/src/util'
|
||||
|
||||
import { VxeGlobalHooksHandles, TableValidatorMethods, TableValidatorPrivateMethods, VxeTableDefines } from '../../../types/all'
|
||||
@@ -355,10 +357,10 @@ const validatorHook: VxeGlobalHooksHandles.HookOptions = {
|
||||
if (rules) {
|
||||
const cellValue = XEUtils.isUndefined(val) ? XEUtils.get(row, field) : val
|
||||
rules.forEach((rule) => {
|
||||
const { type, trigger, required } = rule
|
||||
const { type, trigger, required, validator } = rule
|
||||
if (validType === 'all' || !trigger || validType === trigger) {
|
||||
if (XEUtils.isFunction(rule.validator)) {
|
||||
const customValid = rule.validator({
|
||||
if (validator) {
|
||||
const validParams = {
|
||||
cellValue,
|
||||
rule,
|
||||
rules,
|
||||
@@ -366,9 +368,29 @@ const validatorHook: VxeGlobalHooksHandles.HookOptions = {
|
||||
rowIndex: $xetable.getRowIndex(row),
|
||||
column,
|
||||
columnIndex: $xetable.getColumnIndex(column),
|
||||
field: column.property,
|
||||
$table: $xetable
|
||||
})
|
||||
field: column.field,
|
||||
$table: $xetable,
|
||||
$grid: $xetable.xegrid
|
||||
}
|
||||
let customValid: any
|
||||
if (XEUtils.isString(validator)) {
|
||||
const gvItem = VXETable.validators.get(validator)
|
||||
if (gvItem) {
|
||||
if (gvItem.cellValidatorMethod) {
|
||||
customValid = gvItem.cellValidatorMethod(validParams)
|
||||
} else {
|
||||
if (process.env.VUE_APP_VXE_TABLE_ENV === 'development') {
|
||||
warnLog('vxe.error.notValidators', [validator])
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (process.env.VUE_APP_VXE_TABLE_ENV === 'development') {
|
||||
errLog('vxe.error.notValidators', [validator])
|
||||
}
|
||||
}
|
||||
} else {
|
||||
customValid = validator(validParams)
|
||||
}
|
||||
if (customValid) {
|
||||
if (XEUtils.isError(customValid)) {
|
||||
validRuleErr = true
|
||||
|
||||
@@ -1233,8 +1233,8 @@
|
||||
position: relative;
|
||||
&:before {
|
||||
content: "";
|
||||
top: var(--vxe-table-cell-dirty-width);
|
||||
left: var(--vxe-table-cell-dirty-width);
|
||||
top: calc(var(--vxe-table-cell-dirty-width) * -1);
|
||||
left: calc(var(--vxe-table-cell-dirty-width) * -1);
|
||||
position: absolute;
|
||||
border-width: var(--vxe-table-cell-dirty-width);
|
||||
border-style: solid;
|
||||
|
||||
21
types/form.d.ts
vendored
21
types/form.d.ts
vendored
@@ -262,18 +262,7 @@ export namespace VxeFormDefines {
|
||||
* 使用自定义校验函数,接收一个 Promise
|
||||
* @param params 参数
|
||||
*/
|
||||
validator?(params: {
|
||||
$form: VxeFormConstructor,
|
||||
itemValue: any,
|
||||
rule: VxeFormDefines.FormRule
|
||||
rules: VxeFormDefines.FormRule[]
|
||||
data: any
|
||||
field: string,
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
property: string
|
||||
}): void | Error | Promise<any>
|
||||
validator?: string | ((params: RuleValidatorParams) => void | Error | Promise<any>)
|
||||
/**
|
||||
* 提示消息
|
||||
*/
|
||||
@@ -286,6 +275,14 @@ export namespace VxeFormDefines {
|
||||
message?: string
|
||||
}
|
||||
|
||||
export interface RuleValidatorParams {
|
||||
$form: VxeFormConstructor
|
||||
itemValue: any
|
||||
rule: VxeFormDefines.FormRule
|
||||
rules: VxeFormDefines.FormRule[]
|
||||
data: any
|
||||
field: string
|
||||
}
|
||||
export interface ValidateErrorParams {
|
||||
$form: VxeFormConstructor,
|
||||
rule: VxeFormDefines.FormRule
|
||||
|
||||
9
types/v-x-e-table/index.d.ts
vendored
9
types/v-x-e-table/index.d.ts
vendored
@@ -6,6 +6,7 @@ import { VxeGlobalInterceptor } from './interceptor'
|
||||
import { VxeGlobalCommands } from './commands'
|
||||
import { VxeGlobalFormats } from './formats'
|
||||
import { VxeGlobalMenus } from './menus'
|
||||
import { VxeGlobalValidators } from './validators'
|
||||
import { VxeGlobalHooks } from './hooks'
|
||||
import { VxeGlobalSetup } from './setup'
|
||||
|
||||
@@ -39,6 +40,7 @@ export const renderer: VxeGlobalRenderer
|
||||
export const commands: VxeGlobalCommands
|
||||
export const formats: VxeGlobalFormats
|
||||
export const menus: VxeGlobalMenus
|
||||
export const validators: VxeGlobalValidators
|
||||
export const hooks: VxeGlobalHooks
|
||||
export const modal: ModalController
|
||||
export const saveFile: SaveFileFunction
|
||||
@@ -93,6 +95,10 @@ export interface VXETableCore {
|
||||
* Table context menu
|
||||
*/
|
||||
menus: VxeGlobalMenus
|
||||
/**
|
||||
* Validators table/form
|
||||
*/
|
||||
validators: VxeGlobalValidators
|
||||
/**
|
||||
* Table VxeGlobalHooks API
|
||||
*/
|
||||
@@ -131,7 +137,7 @@ export interface VXETableCore {
|
||||
}
|
||||
|
||||
/**
|
||||
* 一个基于 vue 的 PC 端表格组件,支持增删改查、虚拟滚动、懒加载、快捷菜单、数据校验、树形结构、打印导出、表单渲染、数据分页、虚拟列表、弹窗、自定义模板、渲染器、贼灵活的配置项等...
|
||||
* 一个基于 vue 的 PC 端表格组件,支持增删改查、虚拟列表、虚拟树、懒加载、快捷菜单、数据校验、树形结构、打印导出、表单渲染、数据分页、弹窗、自定义模板、渲染器、JSON 配置式为零代码而设计...
|
||||
*/
|
||||
export const VXETable: VXETableCore
|
||||
|
||||
@@ -140,6 +146,7 @@ export * from './interceptor'
|
||||
export * from './commands'
|
||||
export * from './formats'
|
||||
export * from './menus'
|
||||
export * from './validators'
|
||||
export * from './hooks'
|
||||
export * from './setup'
|
||||
|
||||
|
||||
26
types/v-x-e-table/menus.d.ts
vendored
26
types/v-x-e-table/menus.d.ts
vendored
@@ -5,18 +5,30 @@ import { VxeGlobalRendererHandles } from './renderer'
|
||||
/* eslint-disable no-use-before-define */
|
||||
|
||||
export namespace VxeGlobalMenusHandles {
|
||||
export type MenusCallback<D = VxeTableDataRow> = (params: MenusCallbackParams<D>, event: Event) => any
|
||||
|
||||
export type MenusOption<D = VxeTableDataRow> = {
|
||||
menuMethod?: (params: MenuMethodParams<D>, event: Event) => any
|
||||
}
|
||||
interface MenusParams<D = VxeTableDataRow> {
|
||||
$grid: VxeGridConstructor<D> | null
|
||||
$table: VxeTableConstructor<D> & VxeTablePrivateMethods<D>
|
||||
}
|
||||
export interface MenusCallbackParams<D = VxeTableDataRow> extends MenusParams<D>, VxeGlobalRendererHandles.RenderCellParams<D> {
|
||||
export interface MenuMethodParams<D = VxeTableDataRow> extends MenusParams<D>, VxeGlobalRendererHandles.RenderCellParams<D> {
|
||||
$grid: VxeGridConstructor<D> | null
|
||||
$table: VxeTableConstructor<D> & VxeTablePrivateMethods<D>
|
||||
$event: MouseEvent
|
||||
menu: VxeTableDefines.MenuFirstOption | VxeTableDefines.MenuChildOption
|
||||
}
|
||||
|
||||
/**
|
||||
* 请使用 MenusOption
|
||||
* @deprecated
|
||||
*/
|
||||
export type MenusCallback = MenusOption
|
||||
/**
|
||||
* 请使用 MenuMethodParams
|
||||
* @deprecated
|
||||
*/
|
||||
export interface MenusCallbackParams<D = VxeTableDataRow> extends MenuMethodParams<D> {}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -24,11 +36,11 @@ export namespace VxeGlobalMenusHandles {
|
||||
*/
|
||||
export interface VxeGlobalMenus {
|
||||
mixin(options: {
|
||||
[code: string]: VxeGlobalMenusHandles.MenusCallback<any>
|
||||
[code: string]: VxeGlobalMenusHandles.MenusOption<any> | ((params: VxeGlobalMenusHandles.MenuMethodParams<any>, event: Event) => any)
|
||||
}): VxeGlobalMenus
|
||||
has(code: string): boolean
|
||||
get(code: string): VxeGlobalMenusHandles.MenusCallback<any>
|
||||
add(code: string, callback: VxeGlobalMenusHandles.MenusCallback<any>): VxeGlobalMenus
|
||||
get(code: string): VxeGlobalMenusHandles.MenusOption<any>
|
||||
add(code: string, options: VxeGlobalMenusHandles.MenusOption<any> | ((params: VxeGlobalMenusHandles.MenuMethodParams<any>, event: Event) => any)): VxeGlobalMenus
|
||||
delete(code: string): void
|
||||
forEach(callback: (options: VxeGlobalMenusHandles.MenusCallback<any>, code: string) => void): void
|
||||
forEach(callback: (options: VxeGlobalMenusHandles.MenusOption<any>, code: string) => void): void
|
||||
}
|
||||
|
||||
30
types/v-x-e-table/validators.d.ts
vendored
Normal file
30
types/v-x-e-table/validators.d.ts
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import { VxeTableDefines, VxeTableDataRow } from '../table'
|
||||
import { VxeFormDefines } from '../form'
|
||||
|
||||
/* eslint-disable no-use-before-define */
|
||||
|
||||
export namespace VxeGlobalValidatorsHandles {
|
||||
export interface ValidatorsOptions<D = VxeTableDataRow> {
|
||||
itemValidatorMethod?: ItemValidatorMethod
|
||||
cellValidatorMethod?: CellValidatorMethod<D>
|
||||
}
|
||||
|
||||
export type ItemValidatorMethod = (params: ItemValidatorParams, ...args: any[]) => void | Error | Promise<any>
|
||||
export type CellValidatorMethod<D = VxeTableDataRow> = (params: CellValidatorParams<D>, ...args: any[]) => void | Error | Promise<any>
|
||||
export interface ItemValidatorParams extends VxeFormDefines.RuleValidatorParams {}
|
||||
export interface CellValidatorParams<D = VxeTableDataRow> extends VxeTableDefines.RuleValidatorParams<D> {}
|
||||
}
|
||||
|
||||
/**
|
||||
* 全局快捷菜单
|
||||
*/
|
||||
export interface VxeGlobalValidators {
|
||||
mixin(options: {
|
||||
[code: string]: VxeGlobalValidatorsHandles.ValidatorsOptions<any>
|
||||
}): VxeGlobalValidators
|
||||
has(code: string): boolean
|
||||
get(code: string): VxeGlobalValidatorsHandles.ValidatorsOptions<any>
|
||||
add(code: string, callback: VxeGlobalValidatorsHandles.ValidatorsOptions<any>): VxeGlobalValidators
|
||||
delete(code: string): void
|
||||
forEach(callback: (options: VxeGlobalValidatorsHandles.ValidatorsOptions<any>, code: string) => void): void
|
||||
}
|
||||
15
types/validator.d.ts
vendored
15
types/validator.d.ts
vendored
@@ -1,5 +1,6 @@
|
||||
import { VXEComponent } from './component'
|
||||
import { VxeTableDefines, VxeTableDataRow, VxeTableConstructor } from './table'
|
||||
import { VxeGridConstructor } from './grid'
|
||||
import { VxeColumnPropTypes } from './column'
|
||||
|
||||
/* eslint-disable no-use-before-define */
|
||||
@@ -71,7 +72,7 @@ declare module './table' {
|
||||
* 使用自定义校验函数,接收一个 Promise
|
||||
* @param params 参数
|
||||
*/
|
||||
validator?(params: VxeTableDefines.ValidatorErrorParams<D>): void | Error | Promise<void>
|
||||
validator?: string | ((params: RuleValidatorParams<D>) => void | Error | Promise<void>)
|
||||
/**
|
||||
* 提示消息
|
||||
*/
|
||||
@@ -83,6 +84,18 @@ declare module './table' {
|
||||
*/
|
||||
message?: string
|
||||
}
|
||||
export interface RuleValidatorParams<D = VxeTableDataRow> {
|
||||
$table: VxeTableConstructor<D>
|
||||
$grid: VxeGridConstructor<D> | null
|
||||
cellValue: any
|
||||
rule: ValidatorRule<D>
|
||||
rules: ValidatorRule<D>[]
|
||||
column: VxeTableDefines.ColumnInfo<D>
|
||||
columnIndex: number
|
||||
row: D
|
||||
rowIndex: number
|
||||
field: string
|
||||
}
|
||||
export interface ValidatorErrorParams<D = VxeTableDataRow> {
|
||||
$table: VxeTableConstructor<D>
|
||||
cellValue: any
|
||||
|
||||
Reference in New Issue
Block a user