From 063b983daaf51a7f1e8677bde1e9c0e618866c91 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 21 二月 2020 10:30:19 +0800 Subject: [PATCH] 2020-02-21 --- src/utils/utils.js | 67 +++++++++++++++++++-------------- 1 files changed, 38 insertions(+), 29 deletions(-) diff --git a/src/utils/utils.js b/src/utils/utils.js index ea12648..6de456a 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -464,12 +464,10 @@ val = val.replace(/(^\s*$)|\t*|\v*/ig, '') - let limitlen = col.type.match(/\d+/)[0] - if (!val && col.required === 'true') { // 蹇呭~鏍¢獙 let _error = _position + dict['main.excel.content.emptyerror'] errors.push(_error) - } else if (val.length > limitlen) { // 闀垮害鏍¢獙 + } else if (val.length > col.limit) { // 闀垮害鏍¢獙 let _error = _position + dict['main.excel.content.maxlimit'] errors.push(_error) } else { // 鍏抽敭瀛楁牎楠� @@ -482,36 +480,47 @@ }) } } else if (/^int/ig.test(col.type)) { - if (typeof(val) !== 'number' || parseInt(val) < parseFloat(val)) { // 妫�楠屾槸鍚︿负鏁存暟 - let _error = _position + dict['main.excel.content.interror'] + if (!val) { + let _error = _position + dict['main.excel.content.emptyerror'] errors.push(_error) - } else if ((col.min || col.min === 0) && val < col.min) { // 鏈�灏忓�兼楠� - let _error = _position + dict['main.excel.content.limitmin'] - errors.push(_error) - } else if ((col.max || col.max === 0) && val > col.max) { // 鏈�澶у�兼楠� - let _error = _position + dict['main.excel.content.limitmax'] - errors.push(_error) + } else { + let _val = val + '' + + if (!/^(([^0][0-9]+|0)$)|^(([1-9]+)$)/.test(_val)) { // 妫�楠屾槸鍚︿负鏁存暟 + let _error = _position + dict['main.excel.content.interror'] + errors.push(_error) + } else if ((col.min || col.min === 0) && val < col.min) { // 鏈�灏忓�兼楠� + let _error = _position + dict['main.excel.content.limitmin'] + errors.push(_error) + } else if ((col.max || col.max === 0) && val > col.max) { // 鏈�澶у�兼楠� + let _error = _position + dict['main.excel.content.limitmax'] + errors.push(_error) + } } } else if (/^Decimal/ig.test(col.type)) { - let _val = val + '' - _val = _val.split('.') - let limitlen = col.type.match(/\d+/ig)[1] + if (!val) { + let _error = _position + dict['main.excel.content.emptyerror'] + errors.push(_error) + } else { + let _val = val + '' + let _vals = _val.split('.') - if (typeof(val) !== 'number') { // 妫�楠屾槸鍚︿负娴偣鏁� - let _error = _position + dict['main.excel.content.floaterror'] - errors.push(_error) - } else if (_val[0].length > 18) { // 妫�楠屾暣鏁颁綅 - let _error = _position + dict['main.excel.content.floatIntover'] - errors.push(_error) - } else if (_val[1] && _val[1].length > limitlen) { // 鏈�灏忓�兼楠� - let _error = _position + dict['main.excel.content.floatPointover'] - errors.push(_error) - } else if ((col.min || col.min === 0) && val < col.min) { // 鏈�灏忓�兼楠� - let _error = _position + dict['main.excel.content.limitmin'] - errors.push(_error) - } else if ((col.max || col.max === 0) && val > col.max) { // 鏈�澶у�兼楠� - let _error = _position + dict['main.excel.content.limitmax'] - errors.push(_error) + if (!/^(([^0][0-9]+|0)\.([0-9]+)$)|^(([^0][0-9]+|0)$)|^(([1-9]+)\.([0-9]+)$)|^(([1-9]+)$)/.test(_val)) { // 妫�楠屾槸鍚︿负娴偣鏁� + let _error = _position + dict['main.excel.content.floaterror'] + errors.push(_error) + } else if (_vals[0].length > 18) { // 妫�楠屾暣鏁颁綅 + let _error = _position + dict['main.excel.content.floatIntover'] + errors.push(_error) + } else if (_vals[1] && _vals[1].length > col.limit) { // 鏈�灏忓�兼楠� + let _error = _position + dict['main.excel.content.floatPointover'] + errors.push(_error) + } else if ((col.min || col.min === 0) && val < col.min) { // 鏈�灏忓�兼楠� + let _error = _position + dict['main.excel.content.limitmin'] + errors.push(_error) + } else if ((col.max || col.max === 0) && val > col.max) { // 鏈�澶у�兼楠� + let _error = _position + dict['main.excel.content.limitmax'] + errors.push(_error) + } } } -- Gitblit v1.8.0