info
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
// 表单校验规则由 schema2code 生成,不建议直接修改校验规则,而建议通过 schema2code 生成, 详情: https://uniapp.dcloud.net.cn/uniCloud/schema
|
||||
|
||||
|
||||
const validator = {
|
||||
"bannerfile": {
|
||||
"rules": [
|
||||
{
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"format": "file"
|
||||
}
|
||||
],
|
||||
"title": "图片文件",
|
||||
"label": "图片文件"
|
||||
},
|
||||
"open_url": {
|
||||
"rules": [
|
||||
{
|
||||
"format": "string"
|
||||
},
|
||||
{
|
||||
"format": "url"
|
||||
},
|
||||
{
|
||||
"pattern": "^(http://|https://|/|./|@/)\\S"
|
||||
}
|
||||
],
|
||||
"title": "点击目标地址",
|
||||
"label": "点击目标地址"
|
||||
},
|
||||
"title": {
|
||||
"rules": [
|
||||
{
|
||||
"format": "string"
|
||||
},
|
||||
{
|
||||
"maxLength": 20
|
||||
}
|
||||
],
|
||||
"title": "标题",
|
||||
"label": "标题"
|
||||
},
|
||||
"sort": {
|
||||
"rules": [
|
||||
{
|
||||
"format": "int"
|
||||
}
|
||||
],
|
||||
"title": "排序",
|
||||
"label": "排序"
|
||||
},
|
||||
"category_id": {
|
||||
"rules": [
|
||||
{
|
||||
"format": "string"
|
||||
}
|
||||
],
|
||||
"title": "分类id",
|
||||
"label": "分类id"
|
||||
},
|
||||
"status": {
|
||||
"rules": [
|
||||
{
|
||||
"format": "bool"
|
||||
}
|
||||
],
|
||||
"title": "生效状态",
|
||||
"defaultValue": true,
|
||||
"label": "生效状态"
|
||||
},
|
||||
"description": {
|
||||
"rules": [
|
||||
{
|
||||
"format": "string"
|
||||
}
|
||||
],
|
||||
"title": "备注",
|
||||
"label": "备注"
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
export { validator, enumConverter, filterToWhere }
|
||||
@@ -0,0 +1,233 @@
|
||||
// 表单校验规则由 schema2code 生成,不建议直接修改校验规则,而建议通过 schema2code 生成, 详情: https://uniapp.dcloud.net.cn/uniCloud/schema
|
||||
|
||||
|
||||
const validator = {
|
||||
"user_id": {
|
||||
"rules": [
|
||||
{
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"format": "string"
|
||||
}
|
||||
],
|
||||
"defaultValue": {
|
||||
"$env": "uid"
|
||||
}
|
||||
},
|
||||
"category_id": {
|
||||
"rules": [
|
||||
{
|
||||
"format": "string"
|
||||
}
|
||||
],
|
||||
"title": "分类",
|
||||
"label": "分类"
|
||||
},
|
||||
"title": {
|
||||
"rules": [
|
||||
{
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"format": "string"
|
||||
}
|
||||
],
|
||||
"label": "标题",
|
||||
"title": "标题"
|
||||
},
|
||||
"excerpt": {
|
||||
"rules": [
|
||||
{
|
||||
"format": "string"
|
||||
}
|
||||
],
|
||||
"label": "摘要",
|
||||
"title": "文章摘录"
|
||||
},
|
||||
"article_status": {
|
||||
"rules": [
|
||||
{
|
||||
"format": "int"
|
||||
},
|
||||
{
|
||||
"range": [
|
||||
{
|
||||
"value": 0,
|
||||
"text": "草稿箱"
|
||||
},
|
||||
{
|
||||
"value": 1,
|
||||
"text": "已发布"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"title": "文章状态",
|
||||
"defaultValue": 0,
|
||||
"label": "文章状态"
|
||||
},
|
||||
"comment_status": {
|
||||
"rules": [
|
||||
{
|
||||
"format": "int"
|
||||
},
|
||||
{
|
||||
"range": [
|
||||
{
|
||||
"value": 0,
|
||||
"text": "关闭"
|
||||
},
|
||||
{
|
||||
"value": 1,
|
||||
"text": "开放"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"title": "开放评论",
|
||||
"label": "开放评论"
|
||||
},
|
||||
"last_comment_user_id": {
|
||||
"rules": [
|
||||
{
|
||||
"format": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"thumbnail": {
|
||||
"rules": [
|
||||
{
|
||||
"format": "array"
|
||||
}
|
||||
],
|
||||
"label": "封面大图",
|
||||
"title": "封面大图",
|
||||
"defaultValue": []
|
||||
},
|
||||
"publish_date": {
|
||||
"rules": [
|
||||
{
|
||||
"format": "timestamp"
|
||||
}
|
||||
],
|
||||
"title": "发表时间",
|
||||
"defaultValue": {
|
||||
"$env": "now"
|
||||
},
|
||||
"label": "发表时间"
|
||||
},
|
||||
"last_modify_date": {
|
||||
"rules": [
|
||||
{
|
||||
"format": "timestamp"
|
||||
}
|
||||
],
|
||||
"title": "最后修改时间",
|
||||
"defaultValue": {
|
||||
"$env": "now"
|
||||
},
|
||||
"label": "最后修改时间"
|
||||
},
|
||||
"preview_secret": {
|
||||
"rules": [
|
||||
{
|
||||
"format": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"preview_expired": {
|
||||
"rules": [
|
||||
{
|
||||
"format": "timestamp"
|
||||
}
|
||||
]
|
||||
},
|
||||
"view_count": {
|
||||
"rules": [
|
||||
{
|
||||
"format": "int"
|
||||
}
|
||||
],
|
||||
"title": "阅读数量",
|
||||
"defaultValue": 0,
|
||||
"label": "阅读数量"
|
||||
},
|
||||
"like_count": {
|
||||
"rules": [
|
||||
{
|
||||
"format": "int"
|
||||
}
|
||||
]
|
||||
},
|
||||
"content": {
|
||||
"rules": [
|
||||
{
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"format": "object"
|
||||
}
|
||||
],
|
||||
"label": "文章内容",
|
||||
"title": "文章内容"
|
||||
}
|
||||
}
|
||||
|
||||
const enumConverter = {
|
||||
"article_status_valuetotext": {
|
||||
"0": "草稿箱",
|
||||
"1": "已发布"
|
||||
},
|
||||
"comment_status_valuetotext": {
|
||||
"0": "关闭",
|
||||
"1": "开放"
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
export { validator, enumConverter, filterToWhere }
|
||||
Reference in New Issue
Block a user