Commit 3dcd2320 authored by 秦海涛's avatar 秦海涛

add: validate

parent 79ed990b
......@@ -4,7 +4,7 @@
"pages/cmp/index/index"
],
"window": {
"defaultTitle": "www"
"defaultTitle": "店铺漂流记商家管理后台"
},
"plugins": {
"myPlugin": {
......
......@@ -311,6 +311,7 @@ Component({
if(dialogType !== 'probablity') {
this.showItemTips("probablityTips", "success", "");
}
const {
LUKCY_POCKET_TYPE,
COUPON_TYPE,
......
......@@ -6,11 +6,11 @@ export default {
env: "test", // online 线上 test 测试
// 默认云函数名称
cloudFnName: 'backstage',
cloudFnName: 'duiba',
// 小程序appId
appId: "eee",
appId: "3000000002590532",
// 配置应用appID, 权益插件用
bizCode: "222",
bizCode: "3000000002693435",
};
......@@ -18,6 +18,11 @@
"resolved": "https://registry.npm.taobao.org/dayjs/download/dayjs-1.8.28.tgz",
"integrity": "sha1-N6piAd9IPQiWRctsj2zvbwxNvAc="
},
"lodash": {
"version": "4.17.19",
"resolved": "https://registry.npm.taobao.org/lodash/download/lodash-4.17.19.tgz?cache=0&sync_timestamp=1594226805918&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Flodash%2Fdownload%2Flodash-4.17.19.tgz",
"integrity": "sha1-5I3e2+MLMyF4PFtDAfvTU7weSks="
},
"miniapp-router": {
"version": "0.1.7",
"resolved": "https://registry.npm.taobao.org/miniapp-router/download/miniapp-router-0.1.7.tgz",
......
......@@ -7,6 +7,7 @@
"@tbmp/mp-cloud-sdk": "1.1.4",
"async-validator": "^3.3.0",
"dayjs": "^1.8.28",
"lodash": "^4.17.19",
"miniapp-router": "^0.1.6",
"moment": "^2.24.0"
}
......
......@@ -20,7 +20,6 @@
originalStartTime="{{originalStartTime}}"
onChange="onTimeChange"
disableStartTime="{{isStart}}"
tips="demo"
/>
</form-item>
......@@ -37,6 +36,7 @@
dataName="title"
hasLimitHint="{{true}}"
onChange="onChange"
tips="活动名称仅在配置后台展示,用于区分活动,不在C端展示"
/>
</form-item>
......@@ -53,6 +53,7 @@
dataName="subtitle"
hasLimitHint="{{true}}"
onChange="onChange"
tips="活动副标题用于C端游戏首页展示,需与活动奖品相关,用于吸引用户参与"
/>
</form-item>
......@@ -69,7 +70,7 @@
<tb-label title="任务配置"/>
<form-item
<!-- <form-item
class="edit-content-form-item"
label="关注店铺"
validateState="{{formState['taskMap.attentionStore'].status}}"
......@@ -84,7 +85,7 @@
onChange="onTaskInputChange",
placeholder="1-99"
/>
</form-item>
</form-item> -->
<form-item
class="edit-content-form-item"
......
......@@ -242,7 +242,8 @@ Component({
const _this = this;
return new Promise((resolve, reject) => {
validator.validate(data, (errors, fields) => {
console.log(errors, fields)
console.log('errors', errors);
console.log('fields', fields);
const { formState } = _this.data;
_this.setFormTips(formState, errors, target)
if(errors) {
......
import { TASK_RATE_TYPE } from '../const'
import flatten from 'lodash/flatten'
import { rankTableValidator } from "../../../utils/validate";
// 使用 async-validator 校验
// 文档地址: https://github.com/yiminghe/async-validator
export const descriptor = {
title: {
required: true,
......@@ -14,8 +17,7 @@ export const descriptor = {
},
prizeInfoList: {
required: true,
validator: (rule, value) => !!value.length,
message: "请至少添加一项奖品配置"
validator: rankTableValidator
},
timeRange: {
required: true
......
......@@ -39,3 +39,32 @@ export const validateRangeNumber = (number, [ min, max ] = [], fixed = 0) => {
return true;
}
// 配置验证
// 排名表格验证
export const rankTableValidator = (rule, value, callback, source, options) => {
if(!value.length) return new Error('请配置至少一项奖品配置');
// rank字段不存在或为0
if(value.some(v => !v.rank)) return new Error('名次配置错误, 请检查');
const rankArr = (value.map(v => v.rank.split('-')));
// 判断排名连续
let valid = true;
rankArr.forEach((rank, i) => {
if(i === 0) return;
let lastRank = rankArr[i-1][rankArr[i-1].length - 1];
let curRank = rank[0];
if(curRank - lastRank !== 1) {
valid = false;
}
})
if(!valid) return new Error('名次索引必须连续, 请检查');
return callback()
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment