165 lines
3.0 KiB
JavaScript
165 lines
3.0 KiB
JavaScript
"use strict";
|
|
const validator = {
|
|
"font_color": {
|
|
"rules": [
|
|
{
|
|
"required": true
|
|
},
|
|
{
|
|
"format": "string"
|
|
},
|
|
{
|
|
"pattern": "^#[0-9a-fA-F]{3,6}$"
|
|
}
|
|
]
|
|
},
|
|
"backgrond_color": {
|
|
"rules": [
|
|
{
|
|
"required": true
|
|
},
|
|
{
|
|
"format": "string"
|
|
},
|
|
{
|
|
"pattern": "^#[0-9a-fA-F]{3,6}$"
|
|
}
|
|
]
|
|
},
|
|
"select_src": {
|
|
"rules": [
|
|
{
|
|
"required": true
|
|
},
|
|
{
|
|
"format": "string"
|
|
}
|
|
]
|
|
},
|
|
"temptele_src": {
|
|
"rules": [
|
|
{
|
|
"required": true
|
|
},
|
|
{
|
|
"format": "string"
|
|
}
|
|
]
|
|
},
|
|
"temptele_name": {
|
|
"rules": [
|
|
{
|
|
"required": true
|
|
},
|
|
{
|
|
"format": "string"
|
|
},
|
|
{
|
|
"minLength": 2,
|
|
"maxLength": 50
|
|
}
|
|
]
|
|
},
|
|
"select_icon_color": {
|
|
"rules": [
|
|
{
|
|
"required": true
|
|
},
|
|
{
|
|
"format": "string"
|
|
},
|
|
{
|
|
"pattern": "^#[0-9a-fA-F]{3,6}$"
|
|
}
|
|
]
|
|
},
|
|
"icon_color": {
|
|
"rules": [
|
|
{
|
|
"required": true
|
|
},
|
|
{
|
|
"format": "string"
|
|
},
|
|
{
|
|
"pattern": "^#[0-9a-fA-F]{3,6}$"
|
|
}
|
|
]
|
|
},
|
|
"user_name_color": {
|
|
"rules": [
|
|
{
|
|
"required": true
|
|
},
|
|
{
|
|
"format": "string"
|
|
},
|
|
{
|
|
"pattern": "^#[0-9a-fA-F]{3,6}$"
|
|
}
|
|
]
|
|
},
|
|
"btn_color": {
|
|
"rules": [
|
|
{
|
|
"required": true
|
|
},
|
|
{
|
|
"format": "string"
|
|
},
|
|
{
|
|
"pattern": "^#[0-9a-fA-F]{3,6}$"
|
|
}
|
|
]
|
|
}
|
|
};
|
|
const enumConverter = {};
|
|
function filterToWhere(filter, command) {
|
|
let where = {};
|
|
for (let field in filter) {
|
|
let { type, value } = filter[field];
|
|
switch (type) {
|
|
case "search":
|
|
if (typeof value === "string" && value.length) {
|
|
where[field] = new RegExp(value);
|
|
}
|
|
break;
|
|
case "select":
|
|
if (value.length) {
|
|
let selectValue = [];
|
|
for (let s of value) {
|
|
selectValue.push(command.eq(s));
|
|
}
|
|
where[field] = command.or(selectValue);
|
|
}
|
|
break;
|
|
case "range":
|
|
if (value.length) {
|
|
let gt = value[0];
|
|
let lt = value[1];
|
|
where[field] = command.and([command.gte(gt), command.lte(lt)]);
|
|
}
|
|
break;
|
|
case "date":
|
|
if (value.length) {
|
|
let [s, e] = value;
|
|
let startDate = new Date(s);
|
|
let endDate = new Date(e);
|
|
where[field] = command.and([command.gte(startDate), command.lte(endDate)]);
|
|
}
|
|
break;
|
|
case "timestamp":
|
|
if (value.length) {
|
|
let [startDate, endDate] = value;
|
|
where[field] = command.and([command.gte(startDate), command.lte(endDate)]);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
return where;
|
|
}
|
|
exports.enumConverter = enumConverter;
|
|
exports.filterToWhere = filterToWhere;
|
|
exports.validator = validator;
|
|
//# sourceMappingURL=../../../.sourcemap/mp-weixin/js_sdk/validator/cms-temp.js.map
|