1
0
mirror of https://gitee.com/bookshelfplus/bookshelfplus synced 2025-09-22 01:30:40 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

管理员后台 添加书籍功能完成

This commit is contained in:
2022-04-06 16:42:54 +08:00
parent 15beb083c0
commit 468e6421d9
7 changed files with 195 additions and 139 deletions

View File

@@ -32,7 +32,7 @@ function getValidateUtils() {
},
// 验证是否为空 或者为空字符串 或者 trim() 为空字符串
notEmpty: function (notValidMsg) {
notEmptyAfterTrim: function (notValidMsg) {
let value = this.validateValue;
if (value === null || value === undefined || value === "" || value.trim() === "") {
this.result = false;
@@ -41,6 +41,27 @@ function getValidateUtils() {
return this;
},
// 验证字符串长度
length: function (min, max, notValidMsg) {
let value = this.validateValue;
if (value.length < min || value.length > max) {
this.result = false;
this.msg.push(notValidMsg);
}
return this;
},
// 验证是否包含特殊字符
specialChar: function (notValidMsg) {
let value = this.validateValue;
let reg = /[`~!@#$%^&*()_+<>?:"{},.\/;'[\]]/im;
if (reg.test(value)) {
this.result = false;
this.msg.push(notValidMsg);
}
return this;
},
// 不是字符串
notString: function (notValidMsg) {
let value = this.validateValue;
@@ -61,6 +82,16 @@ function getValidateUtils() {
return this;
},
// 不是字符串类型的数字
notStringNumber: function (notValidMsg) {
let value = this.validateValue;
if ((typeof value !== "string" && typeof value !== "number") || isNaN(value)) {
this.result = false;
this.msg.push(notValidMsg);
}
return this;
},
// 验证是否为整数
notInteger: function (notValidMsg) {
let value = this.validateValue;
@@ -72,10 +103,20 @@ function getValidateUtils() {
return this;
},
// 验证是否为字符串类型的整数
notStringInteger: function (notValidMsg) {
let value = this.validateValue;
if (typeof value !== "string" || isNaN(value) || value % 1 !== 0) {
this.result = false;
this.msg.push(notValidMsg);
}
return this;
},
// 验证是否为正整数
notPositiveInteger: function (notValidMsg) {
let value = this.validateValue;
if (typeof value !== "number" || isNaN(value) || value % 1 !== 0 || value <= 0) {
if ((typeof value !== "string" && typeof value !== "number") || isNaN(value) || value % 1 !== 0 || value <= 0) {
this.result = false;
this.msg.push(notValidMsg);
}
@@ -144,11 +185,13 @@ function getValidateUtils() {
},
// 返回结果
result: function () {
isValid: function () {
console.log("验证内容", this.validateValue, "验证结果", this.result, "错误信息", this.msg);
return {
result: this.result,
msg: this.msg
msg: this.msg.join("")
}
},
};
return validateUtils;
}

View File

@@ -1,6 +1,3 @@
// 需要先引入 ./utils/getValidateUtils.js
var validateUtils = getValidateUtils();
// #######################################################
// 渲染元素
// #######################################################
@@ -71,23 +68,4 @@ function renderFormControls({ Controls = [] }) {
});
// console.log(controlList);
return controlList;
}
// #######################################################
// 提交表单
// #######################################################
function formSubmit({
type = 'POST',
url = '',
data = {},
success = (response) => { console.log(response) },
error = (error) => { console.log(error) }
}) {
$.ajax({
type: type,
url: url,
data: data,
success: success,
error: error
});
}