Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello_uni-id-pages
提交
6362c8b1
H
hello_uni-id-pages
项目概览
DCloud
/
hello_uni-id-pages
通知
1054
Star
31
Fork
43
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
2
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello_uni-id-pages
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
2
合并请求
2
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
6362c8b1
编写于
6月 19, 2023
作者:
雪洛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: uni-id-co validator mixin error
上级
62754ecd
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
56 addition
and
52 deletion
+56
-52
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/common/validator.js
...ges/uniCloud/cloudfunctions/uni-id-co/common/validator.js
+51
-47
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/index.obj.js
...i-id-pages/uniCloud/cloudfunctions/uni-id-co/index.obj.js
+5
-5
未找到文件。
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/common/validator.js
浏览文件 @
6362c8b1
...
...
@@ -198,52 +198,6 @@ function getRuleCategory(rule) {
}
}
function
isMatchUnionType
(
val
,
rule
)
{
if
(
!
rule
.
children
||
rule
.
children
.
length
===
0
)
{
return
true
}
const
children
=
rule
.
children
for
(
let
i
=
0
;
i
<
children
.
length
;
i
++
)
{
const
child
=
children
[
i
]
const
category
=
getRuleCategory
(
child
)
let
pass
=
false
switch
(
category
)
{
case
'
base
'
:
pass
=
isMatchBaseType
(
val
,
child
)
break
case
'
array
'
:
pass
=
isMatchArrayType
(
val
,
child
)
break
default
:
break
}
if
(
pass
)
{
return
true
}
}
return
false
}
function
isMatchBaseType
(
val
,
rule
)
{
if
(
typeof
baseValidator
[
rule
.
type
]
!==
'
function
'
)
{
throw
new
Error
(
`invalid schema type:
${
rule
.
type
}
`
)
}
const
validateRes
=
baseValidator
[
rule
.
type
](
val
)
if
(
validateRes
&&
validateRes
.
errCode
)
{
return
false
}
return
true
}
function
isMatchArrayType
(
arr
,
rule
)
{
if
(
getType
(
arr
)
!==
'
array
'
)
{
return
false
}
if
(
rule
.
children
&&
rule
.
children
.
length
&&
arr
.
some
(
item
=>
!
isMatchUnionType
(
item
,
rule
)))
{
return
false
}
return
true
}
// 特殊符号 https://www.ibm.com/support/pages/password-strength-rules ~!@#$%^&*_-+=`|\(){}[]:;"'<>,.?/
// const specialChar = '~!@#$%^&*_-+=`|\(){}[]:;"\'<>,.?/'
...
...
@@ -320,7 +274,57 @@ class Validator {
return
this
.
customValidator
[
type
]
||
this
.
baseValidator
[
type
]
}
_isMatchUnionType
(
val
,
rule
)
{
if
(
!
rule
.
children
||
rule
.
children
.
length
===
0
)
{
return
true
}
const
children
=
rule
.
children
for
(
let
i
=
0
;
i
<
children
.
length
;
i
++
)
{
const
child
=
children
[
i
]
const
category
=
getRuleCategory
(
child
)
let
pass
=
false
switch
(
category
)
{
case
'
base
'
:
pass
=
this
.
_isMatchBaseType
(
val
,
child
)
break
case
'
array
'
:
pass
=
this
.
_isMatchArrayType
(
val
,
child
)
break
default
:
break
}
if
(
pass
)
{
return
true
}
}
return
false
}
_isMatchBaseType
(
val
,
rule
)
{
const
method
=
this
.
getRealBaseValidator
(
rule
.
type
)
if
(
typeof
method
!==
'
function
'
)
{
throw
new
Error
(
`invalid schema type:
${
rule
.
type
}
`
)
}
const
validateRes
=
method
(
val
)
if
(
validateRes
&&
validateRes
.
errCode
)
{
return
false
}
return
true
}
_isMatchArrayType
(
arr
,
rule
)
{
if
(
getType
(
arr
)
!==
'
array
'
)
{
return
false
}
if
(
rule
.
children
&&
rule
.
children
.
length
&&
arr
.
some
(
item
=>
!
this
.
_isMatchUnionType
(
item
,
rule
)))
{
return
false
}
return
true
}
get
validator
()
{
const
_this
=
this
return
new
Proxy
({},
{
get
:
(
_
,
prop
)
=>
{
if
(
typeof
prop
!==
'
string
'
)
{
...
...
@@ -332,7 +336,7 @@ class Validator {
}
const
rule
=
parseValidatorName
(
prop
)
return
function
(
val
)
{
if
(
!
isMatchUnionType
(
val
,
rule
))
{
if
(
!
_this
.
_
isMatchUnionType
(
val
,
rule
))
{
return
{
errCode
:
ERROR
.
INVALID_PARAM
}
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/index.obj.js
浏览文件 @
6362c8b1
...
...
@@ -180,21 +180,21 @@ module.exports = {
// }
// })
// // 新增规则同样可以在数组验证规则中使用
// this.validator.valdate({
// this.validator.val
i
date({
// timestamp: 123456789
// }, {
// timestamp: 'timestamp'
// })
// this.validator.valdate({
// this.validator.val
i
date({
// timestampList: [123456789, 123123123123]
// }, {
// timestampList: 'array<timestamp>'
// })
// // 甚至更复杂的写法
// this.validator.valdate({
// timestamp: [123456789, 123123123123]
// this.validator.val
i
date({
// timestamp: [123456789
123123123
, 123123123123]
// }, {
// timestamp: 'timestamp|array<timestamp>'
// timestamp: 'timestamp|array<timestamp
|number
>'
// })
// 挂载uni-captcha到this上,方便后续调用
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录