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

add: validate

parent 79ed990b
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"pages/cmp/index/index" "pages/cmp/index/index"
], ],
"window": { "window": {
"defaultTitle": "www" "defaultTitle": "店铺漂流记商家管理后台"
}, },
"plugins": { "plugins": {
"myPlugin": { "myPlugin": {
......
...@@ -311,6 +311,7 @@ Component({ ...@@ -311,6 +311,7 @@ Component({
if(dialogType !== 'probablity') { if(dialogType !== 'probablity') {
this.showItemTips("probablityTips", "success", ""); this.showItemTips("probablityTips", "success", "");
} }
const { const {
LUKCY_POCKET_TYPE, LUKCY_POCKET_TYPE,
COUPON_TYPE, COUPON_TYPE,
......
...@@ -6,11 +6,11 @@ export default { ...@@ -6,11 +6,11 @@ export default {
env: "test", // online 线上 test 测试 env: "test", // online 线上 test 测试
// 默认云函数名称 // 默认云函数名称
cloudFnName: 'backstage', cloudFnName: 'duiba',
// 小程序appId // 小程序appId
appId: "eee", appId: "3000000002590532",
// 配置应用appID, 权益插件用 // 配置应用appID, 权益插件用
bizCode: "222", bizCode: "3000000002693435",
}; };
...@@ -18,6 +18,11 @@ ...@@ -18,6 +18,11 @@
"resolved": "https://registry.npm.taobao.org/dayjs/download/dayjs-1.8.28.tgz", "resolved": "https://registry.npm.taobao.org/dayjs/download/dayjs-1.8.28.tgz",
"integrity": "sha1-N6piAd9IPQiWRctsj2zvbwxNvAc=" "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": { "miniapp-router": {
"version": "0.1.7", "version": "0.1.7",
"resolved": "https://registry.npm.taobao.org/miniapp-router/download/miniapp-router-0.1.7.tgz", "resolved": "https://registry.npm.taobao.org/miniapp-router/download/miniapp-router-0.1.7.tgz",
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
"@tbmp/mp-cloud-sdk": "1.1.4", "@tbmp/mp-cloud-sdk": "1.1.4",
"async-validator": "^3.3.0", "async-validator": "^3.3.0",
"dayjs": "^1.8.28", "dayjs": "^1.8.28",
"lodash": "^4.17.19",
"miniapp-router": "^0.1.6", "miniapp-router": "^0.1.6",
"moment": "^2.24.0" "moment": "^2.24.0"
} }
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
originalStartTime="{{originalStartTime}}" originalStartTime="{{originalStartTime}}"
onChange="onTimeChange" onChange="onTimeChange"
disableStartTime="{{isStart}}" disableStartTime="{{isStart}}"
tips="demo"
/> />
</form-item> </form-item>
...@@ -37,6 +36,7 @@ ...@@ -37,6 +36,7 @@
dataName="title" dataName="title"
hasLimitHint="{{true}}" hasLimitHint="{{true}}"
onChange="onChange" onChange="onChange"
tips="活动名称仅在配置后台展示,用于区分活动,不在C端展示"
/> />
</form-item> </form-item>
...@@ -53,6 +53,7 @@ ...@@ -53,6 +53,7 @@
dataName="subtitle" dataName="subtitle"
hasLimitHint="{{true}}" hasLimitHint="{{true}}"
onChange="onChange" onChange="onChange"
tips="活动副标题用于C端游戏首页展示,需与活动奖品相关,用于吸引用户参与"
/> />
</form-item> </form-item>
...@@ -69,7 +70,7 @@ ...@@ -69,7 +70,7 @@
<tb-label title="任务配置"/> <tb-label title="任务配置"/>
<form-item <!-- <form-item
class="edit-content-form-item" class="edit-content-form-item"
label="关注店铺" label="关注店铺"
validateState="{{formState['taskMap.attentionStore'].status}}" validateState="{{formState['taskMap.attentionStore'].status}}"
...@@ -84,7 +85,7 @@ ...@@ -84,7 +85,7 @@
onChange="onTaskInputChange", onChange="onTaskInputChange",
placeholder="1-99" placeholder="1-99"
/> />
</form-item> </form-item> -->
<form-item <form-item
class="edit-content-form-item" class="edit-content-form-item"
......
...@@ -242,7 +242,8 @@ Component({ ...@@ -242,7 +242,8 @@ Component({
const _this = this; const _this = this;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
validator.validate(data, (errors, fields) => { validator.validate(data, (errors, fields) => {
console.log(errors, fields) console.log('errors', errors);
console.log('fields', fields);
const { formState } = _this.data; const { formState } = _this.data;
_this.setFormTips(formState, errors, target) _this.setFormTips(formState, errors, target)
if(errors) { if(errors) {
......
import { TASK_RATE_TYPE } from '../const' 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 = { export const descriptor = {
title: { title: {
required: true, required: true,
...@@ -14,8 +17,7 @@ export const descriptor = { ...@@ -14,8 +17,7 @@ export const descriptor = {
}, },
prizeInfoList: { prizeInfoList: {
required: true, required: true,
validator: (rule, value) => !!value.length, validator: rankTableValidator
message: "请至少添加一项奖品配置"
}, },
timeRange: { timeRange: {
required: true required: true
......
...@@ -39,3 +39,32 @@ export const validateRangeNumber = (number, [ min, max ] = [], fixed = 0) => { ...@@ -39,3 +39,32 @@ export const validateRangeNumber = (number, [ min, max ] = [], fixed = 0) => {
return true; 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