Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
saas_plus
/
business-assistant
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 8275aa4b
authored
Mar 20, 2023
by
chenwq
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
表单校验
1 parent
4185d2a1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
117 additions
and
22 deletions
packageMine/pages/serviceManage/editService/constant/data.js
packageMine/pages/serviceManage/editService/editService.js
packageMine/pages/serviceManage/editService/editService.wxml
utils/util.js
packageMine/pages/serviceManage/editService/constant/data.js
0 → 100644
View file @
8275aa4
const
phoneRex
=
/^
[
1
]([
3-9
])[
0-9
]{9}
$/
const
formRule
=
{
merchantName
:
[{
required
:
true
,
message
:
'服务中心名称不能为空'
}],
contactName
:
[{
required
:
true
,
message
:
'联系人不能为空'
}],
phone
:
[
{
required
:
true
,
message
:
'联系电话不能为空'
},
{
validator
:
(
rule
,
value
)
=>
{
return
!
phoneRex
.
test
(
value
)
?
{
message
:
'请输入正确的手机号'
}
:
null
}
}
],
password
:
[
{
required
:
true
,
message
:
'登录密码不能为空'
},
{
validator
:
(
rule
,
value
)
=>
{
return
/^
[
a-zA-Z0-9
]{6,20}
$/
.
test
(
value
)
?
null
:
{
message
:
'登陆密码请输入6-20位数字和字母组合'
}
}
}
],
}
const
formItems
=
[{
label
:
'服务中心名称'
,
props
:
'merchantName'
,
type
:
'input'
,
maxlength
:
50
},
{
label
:
'联系人'
,
props
:
'contactName'
,
type
:
'input'
,
placeholder
:
'请输入联系人姓名'
,
maxlength
:
10
},
{
label
:
'联系电话'
,
tips
:
'(登录凭证)'
,
props
:
'phone'
,
type
:
'input'
,
placeholder
:
'请输入手机号码'
,
maxlength
:
11
},
{
label
:
'登录密码'
,
tips
:
'(可用于PC端登录)'
,
props
:
'password'
,
type
:
'input'
,
placeholder
:
'请输入登录密码(6-20位字母+数字)'
,
maxlength
:
20
}]
export
default
{
formRule
,
formItems
}
\ No newline at end of file
\ No newline at end of file
packageMine/pages/serviceManage/editService/editService.js
View file @
8275aa4
// packageMine/pages/serviceManage/editService/editService.js
// packageMine/pages/serviceManage/editService/editService.js
import
constantData
from
'./constant/data'
Page
({
Page
({
/**
/**
...
@@ -7,25 +8,24 @@ Page({
...
@@ -7,25 +8,24 @@ Page({
data
:
{
data
:
{
addOrEdit
:
''
,
addOrEdit
:
''
,
formData
:
{},
formData
:
{},
formItems
:
[{
formItems
:
constantData
.
formItems
,
label
:
'服务中心名称'
,
},
props
:
'merchantName'
,
type
:
'input'
handleInput
(
e
)
{
},
{
let
{
attr
}
=
e
.
currentTarget
.
dataset
label
:
'联系人'
,
let
{
value
}
=
e
.
detail
props
:
'contactName'
,
this
.
setData
({
type
:
'input'
[
'formData.'
+
attr
]:
value
},
{
})
label
:
'联系电话'
,
},
tips
:
'(登录凭证)'
,
props
:
'phone'
,
handleConfirm
()
{
type
:
'input'
let
{
addOrEdit
,
formData
}
=
this
.
data
},
{
let
validObj
=
wx
.
$util
.
checkRule
(
formData
,
constantData
.
formRule
)
label
:
'登录密码'
,
if
(
validObj
)
{
tips
:
'(可用于PC端登录)'
,
wx
.
$api
.
showToast
(
validObj
.
message
)
props
:
'password'
,
return
type
:
'input'
}
}],
},
},
/**
/**
...
...
packageMine/pages/serviceManage/editService/editService.wxml
View file @
8275aa4
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
<block wx:for="{{formItems}}" wx:key="index">
<block wx:for="{{formItems}}" wx:key="index">
<view class="label">{{item.label}}<text class="tips">{{item.tips}}</text></view>
<view class="label">{{item.label}}<text class="tips">{{item.tips}}</text></view>
<view class="input-box" wx:if="{{item.type == 'input'}}">
<view class="input-box" wx:if="{{item.type == 'input'}}">
<input type="text" placeholder="{{item.placeholder || '请输入' + item.label}}"
class="input" value="{{formData[item.props]}}" placeholder-class="input-placeholder
" />
<input type="text" placeholder="{{item.placeholder || '请输入' + item.label}}"
maxlength="{{item.maxlength}}" class="input" value="{{formData[item.props]}}" placeholder-class="input-placeholder" data-attr="{{item.props}}" bindinput="handleInput
" />
</view>
</view>
<view class="select-box" wx:if="{{item.type == 'select'}}" bindtap="jump" data-type="{{item.pageType}}">
<view class="select-box" wx:if="{{item.type == 'select'}}" bindtap="jump" data-type="{{item.pageType}}">
<view class="name" wx:if="{{formData[item.valueFn]}}">{{formData[item.valueFn]}}</view>
<view class="name" wx:if="{{formData[item.valueFn]}}">{{formData[item.valueFn]}}</view>
...
@@ -21,4 +21,3 @@
...
@@ -21,4 +21,3 @@
<view class="btn-blue" bindtap="handleConfirm">{{addOrEdit == 'add' ? '提交' : '保存'}}</view>
<view class="btn-blue" bindtap="handleConfirm">{{addOrEdit == 'add' ? '提交' : '保存'}}</view>
</view>
</view>
</view>
</view>
\ No newline at end of file
\ No newline at end of file
<select-service-confirm show="{{showServiceConfirm}}" tabBarStyle="{{tabBarStyle}}" serviceList="{{serviceList}}" bind:hiddenSelectConfirm="hiddenSelectConfirm"></select-service-confirm>
\ No newline at end of file
\ No newline at end of file
utils/util.js
View file @
8275aa4
...
@@ -288,6 +288,48 @@ const moneyThreeForTwoThousands = num => {
...
@@ -288,6 +288,48 @@ const moneyThreeForTwoThousands = num => {
return
d
+
(
result
+
num2
)
return
d
+
(
result
+
num2
)
}
}
/**
* 动态校验字段
* @param {*} obj 需校验的对象
* @param {*} formRule 校验规则
* formRule = {
* id: [
* { required: true, message: 'xx不能为空' },
* {
* validator: (rule, value) => {
* return value != 'cwq' ? { message: '错误信息' } : null
* }
* }
* ],
* }
*/
const
checkRule
=
function
(
obj
,
formRule
)
{
let
target
=
Object
.
keys
(
formRule
)
for
(
let
i
=
0
;
i
<
target
.
length
;
i
++
)
{
let
attr
=
target
[
i
]
let
item
=
formRule
[
attr
]
let
requirObj
=
item
.
find
(
k
=>
k
.
required
==
true
)
let
validFn
=
item
.
find
(
k
=>
k
.
validator
)
if
(
requirObj
&&
!
obj
[
attr
])
{
return
{
...
requirObj
,
attr
}
}
if
(
validFn
)
{
let
validObj
=
validFn
.
validator
({},
obj
[
attr
],
obj
)
if
(
validObj
)
{
return
{
...
validObj
,
attr
}
}
}
}
return
false
}
const
Util
=
{
const
Util
=
{
getImgVersion
,
getImgVersion
,
...
@@ -300,6 +342,7 @@ const Util = {
...
@@ -300,6 +342,7 @@ const Util = {
getCurrentPageUrl
,
getCurrentPageUrl
,
deepClone
,
deepClone
,
setNavigationBarTitle
,
setNavigationBarTitle
,
moneyThreeForTwoThousands
moneyThreeForTwoThousands
,
checkRule
};
};
export
default
Util
;
export
default
Util
;
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment