mirror of
https://gitee.com/xuliangzhan_admin/vxe-table.git
synced 2026-01-21 05:27:57 +08:00
修复非空校验错误问题
This commit is contained in:
@@ -2302,7 +2302,7 @@ export default {
|
||||
setTimeout(() => this.defaultExpand(), 1500)
|
||||
},
|
||||
loadSponsors () {
|
||||
XEAjax.get('https://api.xuliangzhan.com:10443/api/pub/sponsors').then(data => {
|
||||
XEAjax.get('https://api.xuliangzhan.com:10443/demo/api/pub/sponsors').then(data => {
|
||||
this.sponsorList = data
|
||||
})
|
||||
},
|
||||
@@ -2320,7 +2320,7 @@ export default {
|
||||
}
|
||||
},
|
||||
getVersion () {
|
||||
XEAjax.get('https://api.xuliangzhan.com:10443/api/npm/versions/vxe-table').then(({ time, tags, versions }) => {
|
||||
XEAjax.get('https://api.xuliangzhan.com:10443/demo/api/npm/versions/vxe-table').then(({ time, tags, versions }) => {
|
||||
this.showPlugin = true
|
||||
const stableVersionList = []
|
||||
const betaVersionList = []
|
||||
|
||||
@@ -111,10 +111,10 @@ export default {
|
||||
filters.forEach(({ property, values }) => {
|
||||
queryParams[property] = values.join(',')
|
||||
})
|
||||
return XEAjax.get(`https://api.xuliangzhan.com:10443/api/pub/page/list/${page.pageSize}/${page.currentPage}`, queryParams)
|
||||
return XEAjax.get(`https://api.xuliangzhan.com:10443/demo/api/pub/page/list/${page.pageSize}/${page.currentPage}`, queryParams)
|
||||
},
|
||||
delete: ({ body }) => XEAjax.post('https://api.xuliangzhan.com:10443/api/pub/save', body),
|
||||
save: ({ body }) => XEAjax.post('https://api.xuliangzhan.com:10443/api/pub/save', body)
|
||||
delete: ({ body }) => XEAjax.post('https://api.xuliangzhan.com:10443/demo/api/pub/save', body),
|
||||
save: ({ body }) => XEAjax.post('https://api.xuliangzhan.com:10443/demo/api/pub/save', body)
|
||||
}
|
||||
},
|
||||
columns: [
|
||||
@@ -280,10 +280,10 @@ export default {
|
||||
filters.forEach(({ property, values }) => {
|
||||
queryParams[property] = values.join(',')
|
||||
})
|
||||
return XEAjax.get(\`https://api.xuliangzhan.com:10443/api/pub/page/list/\${page.pageSize}/\${page.currentPage}\`, queryParams)
|
||||
return XEAjax.get(\`https://api.xuliangzhan.com:10443/demo/api/pub/page/list/\${page.pageSize}/\${page.currentPage}\`, queryParams)
|
||||
},
|
||||
delete: ({ body }) => XEAjax.post('https://api.xuliangzhan.com:10443/api/pub/save', body),
|
||||
save: ({ body }) => XEAjax.post('https://api.xuliangzhan.com:10443/api/pub/save', body)
|
||||
delete: ({ body }) => XEAjax.post('https://api.xuliangzhan.com:10443/demo/api/pub/save', body),
|
||||
save: ({ body }) => XEAjax.post('https://api.xuliangzhan.com:10443/demo/api/pub/save', body)
|
||||
}
|
||||
},
|
||||
columns: [
|
||||
@@ -396,7 +396,7 @@ export default {
|
||||
const formBody = new FormData()
|
||||
formBody.append('file', file)
|
||||
// 上传文件
|
||||
return XEAjax.post('https://api.xuliangzhan.com:10443/api/pub/import', formBody).then(data => {
|
||||
return XEAjax.post('https://api.xuliangzhan.com:10443/demo/api/pub/import', formBody).then(data => {
|
||||
const $grid = this.$refs.xGrid
|
||||
this.$XModal.message({ content: \`成功导入 \${data.result.insertRows} 条记录!\`, status: 'success' })
|
||||
// 导入完成,刷新表格
|
||||
@@ -426,11 +426,11 @@ export default {
|
||||
})
|
||||
}
|
||||
// 开始服务端导出
|
||||
return XEAjax.post('https://api.xuliangzhan.com:10443/api/pub/export', body).then(data => {
|
||||
return XEAjax.post('https://api.xuliangzhan.com:10443/demo/api/pub/export', body).then(data => {
|
||||
if (data.id) {
|
||||
this.$XModal.message({ content: '导出成功,开始下载', status: 'success' })
|
||||
// 读取路径,请求文件
|
||||
XEAjax.fetch(\`https://api.xuliangzhan.com:10443/api/pub/export/download/\${data.id}\`).then(response => {
|
||||
XEAjax.fetch(\`https://api.xuliangzhan.com:10443/demo/api/pub/export/download/\${data.id}\`).then(response => {
|
||||
response.blob().then(blob => {
|
||||
// 开始下载
|
||||
this.$XSaveFile({ filename: '导出数据', type: 'xlsx', content: blob })
|
||||
@@ -487,7 +487,7 @@ export default {
|
||||
const formBody = new FormData()
|
||||
formBody.append('file', file)
|
||||
// 上传文件
|
||||
return XEAjax.post('https://api.xuliangzhan.com:10443/api/pub/import', formBody).then(data => {
|
||||
return XEAjax.post('https://api.xuliangzhan.com:10443/demo/api/pub/import', formBody).then(data => {
|
||||
const $grid = this.$refs.xGrid
|
||||
this.$XModal.message({ content: `成功导入 ${data.result.insertRows} 条记录!`, status: 'success' })
|
||||
// 导入完成,刷新表格
|
||||
@@ -517,11 +517,11 @@ export default {
|
||||
})
|
||||
}
|
||||
// 开始服务端导出
|
||||
return XEAjax.post('https://api.xuliangzhan.com:10443/api/pub/export', body).then(data => {
|
||||
return XEAjax.post('https://api.xuliangzhan.com:10443/demo/api/pub/export', body).then(data => {
|
||||
if (data.id) {
|
||||
this.$XModal.message({ content: '导出成功,开始下载', status: 'success' })
|
||||
// 读取路径,请求文件
|
||||
XEAjax.fetch(`https://api.xuliangzhan.com:10443/api/pub/export/download/${data.id}`).then(response => {
|
||||
XEAjax.fetch(`https://api.xuliangzhan.com:10443/demo/api/pub/export/download/${data.id}`).then(response => {
|
||||
response.blob().then(blob => {
|
||||
// 开始下载
|
||||
this.$XSaveFile({ filename: '导出数据', type: 'xlsx', content: blob })
|
||||
|
||||
@@ -105,10 +105,10 @@ export default {
|
||||
filters.forEach(({ property, values }) => {
|
||||
queryParams[property] = values.join(',')
|
||||
})
|
||||
return XEAjax.get(`https://api.xuliangzhan.com:10443/api/pub/page/list/${page.pageSize}/${page.currentPage}`, queryParams)
|
||||
return XEAjax.get(`https://api.xuliangzhan.com:10443/demo/api/pub/page/list/${page.pageSize}/${page.currentPage}`, queryParams)
|
||||
},
|
||||
// 被某些特殊功能所触发,例如:导出数据 mode=all 时,会触发该方法并对返回的数据进行导出
|
||||
queryAll: () => XEAjax.get('https://api.xuliangzhan.com:10443/api/pub/all')
|
||||
queryAll: () => XEAjax.get('https://api.xuliangzhan.com:10443/demo/api/pub/all')
|
||||
}
|
||||
},
|
||||
toolbarConfig: {
|
||||
@@ -239,10 +239,10 @@ export default {
|
||||
filters.forEach(({ property, values }) => {
|
||||
queryParams[property] = values.join(',')
|
||||
})
|
||||
return XEAjax.get(\`https://api.xuliangzhan.com:10443/api/pub/page/list/\${page.pageSize}/\${page.currentPage}\`, queryParams)
|
||||
return XEAjax.get(\`https://api.xuliangzhan.com:10443/demo/api/pub/page/list/\${page.pageSize}/\${page.currentPage}\`, queryParams)
|
||||
},
|
||||
// 被某些特殊功能所触发,例如:导出数据 mode=all 时,会触发该方法并对返回的数据进行导出
|
||||
queryAll: () => XEAjax.get('https://api.xuliangzhan.com:10443/api/pub/all')
|
||||
queryAll: () => XEAjax.get('https://api.xuliangzhan.com:10443/demo/api/pub/all')
|
||||
}
|
||||
},
|
||||
toolbarConfig: {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "vxe-table",
|
||||
"version": "3.2.18",
|
||||
"version": "3.2.19",
|
||||
"description": "一个基于 vue 的 PC 端表格组件,支持增删改查、虚拟滚动、懒加载、快捷菜单、数据校验、树形结构、打印导出、表单渲染、数据分页、虚拟列表、模态窗口、自定义模板、渲染器、贼灵活的配置项、扩展接口等...",
|
||||
"scripts": {
|
||||
"serve": "vue-cli-service serve",
|
||||
|
||||
@@ -3,6 +3,7 @@ import VxeTableColgroup from '../table/src/group'
|
||||
export const Colgroup = Object.assign(VxeTableColgroup, {
|
||||
install (Vue) {
|
||||
Vue.component(VxeTableColgroup.name, VxeTableColgroup)
|
||||
// 兼容旧用法
|
||||
Vue.component('VxeTableColgroup', VxeTableColgroup)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -3,6 +3,7 @@ import VxeTableColumn from '../table/src/column'
|
||||
export const Column = Object.assign(VxeTableColumn, {
|
||||
install (Vue) {
|
||||
Vue.component(VxeTableColumn.name, VxeTableColumn)
|
||||
// 兼容旧用法
|
||||
Vue.component('VxeTableColumn', VxeTableColumn)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -4,6 +4,7 @@ import vSize from '../../mixins/size'
|
||||
import VXETable from '../../v-x-e-table'
|
||||
import { UtilTools, isEnableConf } from '../../tools'
|
||||
import { createItem } from './util'
|
||||
import { eqEmptyValue } from '../../tools/src/utils'
|
||||
import { browse } from '../../tools/src/dom'
|
||||
|
||||
class Rule {
|
||||
@@ -26,6 +27,29 @@ class Rule {
|
||||
}
|
||||
}
|
||||
|
||||
function validErrorRuleValue (rule, val) {
|
||||
const { type, min, max, pattern } = rule
|
||||
const isNumType = type === 'number'
|
||||
const numVal = isNumType ? XEUtils.toNumber(val) : XEUtils.getSize(val)
|
||||
// 判断数值
|
||||
if (isNumType) {
|
||||
return isNaN(val)
|
||||
}
|
||||
// 如果存在 min,判断最小值
|
||||
if (!XEUtils.eqNull(min)) {
|
||||
return numVal < XEUtils.toNumber(min)
|
||||
}
|
||||
// 如果存在 max,判断最大值
|
||||
if (!XEUtils.eqNull(max)) {
|
||||
return numVal > XEUtils.toNumber(max)
|
||||
}
|
||||
// 如果存在 pattern,正则校验
|
||||
if (pattern) {
|
||||
return (XEUtils.isRegExp(pattern) ? pattern : new RegExp(pattern)).test(val)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
function getResetValue (value, resetValue) {
|
||||
if (XEUtils.isArray(value)) {
|
||||
resetValue = []
|
||||
@@ -499,22 +523,26 @@ export default {
|
||||
callback()
|
||||
}
|
||||
}).catch(() => {
|
||||
this.showErrTime = setTimeout(() => {
|
||||
itemList.forEach(item => {
|
||||
if (item.errRule) {
|
||||
item.showError = true
|
||||
}
|
||||
})
|
||||
}, 20)
|
||||
if (callback) {
|
||||
callback(validRest)
|
||||
}
|
||||
if (validOpts.autoPos) {
|
||||
this.$nextTick(() => {
|
||||
this.handleFocus(validFields)
|
||||
})
|
||||
}
|
||||
return Promise.reject(validRest)
|
||||
return new Promise((resolve, reject) => {
|
||||
this.showErrTime = setTimeout(() => {
|
||||
itemList.forEach(item => {
|
||||
if (item.errRule) {
|
||||
item.showError = true
|
||||
}
|
||||
})
|
||||
}, 20)
|
||||
if (validOpts.autoPos) {
|
||||
this.$nextTick(() => {
|
||||
this.handleFocus(validFields)
|
||||
})
|
||||
}
|
||||
if (callback) {
|
||||
callback(validRest)
|
||||
resolve()
|
||||
} else {
|
||||
reject(validRest)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
if (callback) {
|
||||
@@ -536,7 +564,7 @@ export default {
|
||||
* validator=Function({ itemValue, rule, rules, data, property }) 自定义校验,接收一个 Promise
|
||||
* trigger=change 触发方式
|
||||
*/
|
||||
validItemRules (type, property, val) {
|
||||
validItemRules (validType, property, val) {
|
||||
const { data, rules: formRules } = this
|
||||
const errorRules = []
|
||||
const syncVailds = []
|
||||
@@ -545,7 +573,8 @@ export default {
|
||||
if (rules) {
|
||||
const itemValue = XEUtils.isUndefined(val) ? XEUtils.get(data, property) : val
|
||||
rules.forEach(rule => {
|
||||
if (type === 'all' || !rule.trigger || type === rule.trigger) {
|
||||
const { type, trigger, required } = rule
|
||||
if (validType === 'all' || !trigger || validType === rule.trigger) {
|
||||
if (XEUtils.isFunction(rule.validator)) {
|
||||
const customValid = rule.validator({
|
||||
itemValue,
|
||||
@@ -557,29 +586,20 @@ export default {
|
||||
})
|
||||
if (customValid) {
|
||||
if (XEUtils.isError(customValid)) {
|
||||
errorRules.push(new Rule({ type: 'custom', trigger: rule.trigger, message: customValid.message, rule: new Rule(rule) }))
|
||||
errorRules.push(new Rule({ type: 'custom', trigger, message: customValid.message, rule: new Rule(rule) }))
|
||||
} else if (customValid.catch) {
|
||||
// 如果为异步校验(注:异步校验是并发无序的)
|
||||
syncVailds.push(
|
||||
customValid.catch(e => {
|
||||
errorRules.push(new Rule({ type: 'custom', trigger: rule.trigger, message: e ? e.message : rule.message, rule: new Rule(rule) }))
|
||||
errorRules.push(new Rule({ type: 'custom', trigger, message: e ? e.message : rule.message, rule: new Rule(rule) }))
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const isNumber = rule.type === 'number'
|
||||
const numVal = isNumber ? XEUtils.toNumber(itemValue) : XEUtils.getSize(itemValue)
|
||||
if (itemValue === null || itemValue === undefined || itemValue === '') {
|
||||
if (rule.required) {
|
||||
errorRules.push(new Rule(rule))
|
||||
}
|
||||
} else if (
|
||||
(isNumber && isNaN(itemValue)) ||
|
||||
(!isNaN(rule.min) && numVal < parseFloat(rule.min)) ||
|
||||
(!isNaN(rule.max) && numVal > parseFloat(rule.max)) ||
|
||||
(rule.pattern && !(rule.pattern.test ? rule.pattern : new RegExp(rule.pattern)).test(itemValue))
|
||||
) {
|
||||
const isArrType = type === 'array'
|
||||
const hasEmpty = isArrType ? (!XEUtils.isArray(itemValue) || !itemValue.length) : eqEmptyValue(itemValue)
|
||||
if (required ? (hasEmpty || validErrorRuleValue(rule, itemValue)) : (!hasEmpty && validErrorRuleValue(rule, itemValue))) {
|
||||
errorRules.push(new Rule(rule))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import XEUtils from 'xe-utils'
|
||||
import GlobalConfig from '../../v-x-e-table/src/conf'
|
||||
import VXETable from '../../v-x-e-table'
|
||||
import { UtilTools, DomTools, isEnableConf } from '../../tools'
|
||||
import { eqCellNull } from './util'
|
||||
import { UtilTools, DomTools } from '../../tools'
|
||||
import { eqEmptyValue, isEnableConf } from '../../tools/src/utils'
|
||||
|
||||
function renderHelpIcon (h, params) {
|
||||
const { $table, column } = params
|
||||
@@ -178,7 +178,7 @@ export const Cell = {
|
||||
return [
|
||||
h('span', {
|
||||
class: 'vxe-cell--label'
|
||||
}, editRender && eqCellNull(cellValue) ? [
|
||||
}, editRender && eqEmptyValue(cellValue) ? [
|
||||
// 如果设置占位符
|
||||
h('span', {
|
||||
class: 'vxe-cell--placeholder'
|
||||
|
||||
@@ -2,8 +2,9 @@ import XEUtils from 'xe-utils'
|
||||
import GlobalConfig from '../../v-x-e-table/src/conf'
|
||||
import Cell from './cell'
|
||||
import VXETable from '../../v-x-e-table'
|
||||
import { UtilTools, DomTools, isEnableConf } from '../../tools'
|
||||
import { clearTableAllStatus, handleFieldOrColumn, eqCellNull } from './util'
|
||||
import { UtilTools, DomTools } from '../../tools'
|
||||
import { clearTableAllStatus, handleFieldOrColumn } from './util'
|
||||
import { eqEmptyValue, isEnableConf } from '../../tools/src/utils'
|
||||
import { browse, getPaddingTopBottomSize, setScrollTop, setScrollLeft } from '../../tools/src/dom'
|
||||
import { formats } from '../../v-x-e-table/src/formats'
|
||||
|
||||
@@ -26,7 +27,7 @@ function getRowUniqueId () {
|
||||
function eqCellValue (row1, row2, field) {
|
||||
const val1 = XEUtils.get(row1, field)
|
||||
const val2 = XEUtils.get(row2, field)
|
||||
if (eqCellNull(val1) && eqCellNull(val2)) {
|
||||
if (eqEmptyValue(val1) && eqEmptyValue(val2)) {
|
||||
return true
|
||||
}
|
||||
if (XEUtils.isString(val1) || XEUtils.isNumber(val1)) {
|
||||
|
||||
@@ -1,13 +1,6 @@
|
||||
import VXETable from '../../v-x-e-table'
|
||||
import XEUtils from 'xe-utils'
|
||||
|
||||
/**
|
||||
* 单元格的值为:'' | null | undefined 时都属于空值
|
||||
*/
|
||||
export function eqCellNull (cellValue) {
|
||||
return cellValue === '' || XEUtils.eqNull(cellValue)
|
||||
}
|
||||
|
||||
const lineOffsetSizes = {
|
||||
mini: 3,
|
||||
small: 2,
|
||||
|
||||
@@ -157,6 +157,13 @@ function outLog (type) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断值为:'' | null | undefined 时都属于空值
|
||||
*/
|
||||
export function eqEmptyValue (cellValue) {
|
||||
return cellValue === '' || XEUtils.eqNull(cellValue)
|
||||
}
|
||||
|
||||
export const UtilTools = {
|
||||
warn: outLog('warn'),
|
||||
error: outLog('error'),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import XEUtils from 'xe-utils'
|
||||
import { eqCellNull } from '../../table/src/util'
|
||||
import { UtilTools, DomTools } from '../../tools'
|
||||
import { eqEmptyValue } from '../../tools/src/utils'
|
||||
|
||||
/**
|
||||
* 校验规则
|
||||
@@ -29,13 +29,13 @@ class Rule {
|
||||
}
|
||||
}
|
||||
|
||||
function validErrorCellValue (rule, cellValue) {
|
||||
function validErrorRuleValue (rule, val) {
|
||||
const { type, min, max, pattern } = rule
|
||||
const isNumType = type === 'number'
|
||||
const numVal = isNumType ? XEUtils.toNumber(cellValue) : XEUtils.getSize(cellValue)
|
||||
const numVal = isNumType ? XEUtils.toNumber(val) : XEUtils.getSize(val)
|
||||
// 判断数值
|
||||
if (isNumType) {
|
||||
return isNaN(cellValue)
|
||||
return isNaN(val)
|
||||
}
|
||||
// 如果存在 min,判断最小值
|
||||
if (!XEUtils.eqNull(min)) {
|
||||
@@ -47,7 +47,7 @@ function validErrorCellValue (rule, cellValue) {
|
||||
}
|
||||
// 如果存在 pattern,正则校验
|
||||
if (pattern) {
|
||||
return (XEUtils.isRegExp(pattern) ? pattern : new RegExp(pattern)).test(cellValue)
|
||||
return (XEUtils.isRegExp(pattern) ? pattern : new RegExp(pattern)).test(val)
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -258,8 +258,8 @@ export default {
|
||||
}
|
||||
} else {
|
||||
const isArrType = type === 'array'
|
||||
const hasEmpty = isArrType ? (!XEUtils.isArray(cellValue) || !cellValue.length) : eqCellNull(cellValue)
|
||||
if (required ? (hasEmpty || validErrorCellValue(rule, cellValue)) : (!hasEmpty && validErrorCellValue(rule, cellValue))) {
|
||||
const hasEmpty = isArrType ? (!XEUtils.isArray(cellValue) || !cellValue.length) : eqEmptyValue(cellValue)
|
||||
if (required ? (hasEmpty || validErrorRuleValue(rule, cellValue)) : (!hasEmpty && validErrorRuleValue(rule, cellValue))) {
|
||||
this.validRuleErr = true
|
||||
errorRules.push(new Rule(rule))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user