Commit 780725b3 authored by Bill's avatar Bill

完善校验

parent 9828d35c
......@@ -11,10 +11,12 @@ import { Input, Select } from 'antd';
import { PublicApi } from '@/services/api';
import { useInitialValues } from '../hooks/useInitialValues';
import CustomUpload from '../components/WrapCustomUpload';
import useCustomValidator from '../hooks/useValidator'
const actions = createFormActions();
const AdvertisementInfo = () => {
useCustomValidator()
const { id, preview } = usePageStatus();
const initialValues = useInitialValues({id:id}, PublicApi.getManageContentAdvertGet);
const [submitLoading, setSubmitLoading ] = useState(false);
......
......@@ -34,7 +34,7 @@ const schema = {
"x-rules": [
{
"required": true,
"message": "最长20个字符,10个汉字"
"message": "最长60个字符,30个汉字"
},
{
limitByte: true, // 自定义校验规则
......@@ -70,6 +70,12 @@ const schema = {
title: '跳转链接',
type: 'string',
'x-component': 'Input',
"x-rules": [
{
limitByte: true, // 自定义校验规则
maxByte: 100,
}
]
},
imageUrl: {
type: "object",
......
......@@ -14,10 +14,12 @@ import { useInitialValues } from '../hooks/useInitialValues';
import CustomCheckbox from '../components/CustomCheckbox';
import BraftEditor from 'braft-editor';
import { setFormStatus } from '../utils/utils';
import useCustomValidator from '../hooks/useValidator'
const actions = createFormActions();
const AdvertisementInfo = () => {
useCustomValidator();
const { id, preview } = usePageStatus();
const initialValues: any = useInitialValues({id:id}, PublicApi.getManageContentNoticeGet);
const [submitLoading, setSubmitLoading ] = useState(false);
......
......@@ -23,7 +23,7 @@ const schema = {
"x-rules": [
{
"required": true,
"message": "最长20个字符,10个汉字"
"message": "最长60个字符,30个汉字"
},
{
limitByte: true, // 自定义校验规则
......
......@@ -6,6 +6,7 @@ import ReutrnEle from '@/components/ReturnEle';
import { usePageStatus } from '@/hooks/usePageStatus';
import { history, Prompt } from 'umi';
import { PublicApi } from '@/services/api';
import useCustomValidator from '../hooks/useValidator'
interface IOption {
value: number|string,
......@@ -41,9 +42,6 @@ const schema = {
name: 'name',
title: '栏目名称',
'x-component': 'Input',
'x-component-props': {
maxLength: 20
},
"required": true,
"x-rules": [
{
......@@ -89,6 +87,7 @@ const useInitialValues = (id) => {
}
const ColumnInfo = () => {
useCustomValidator();
const { id, preview } = usePageStatus();
const [ submitLoading, setSubmitLoading ] = useState(false);
const initialValues = useInitialValues(id);
......
import React from 'react';
import { Table } from 'antd';
const CustomTable = (props) => {
const { column, dataSource, ...rest } = props;
return (
<div>
<Table
column={column}
dataSource={dataSource}
{...rest}
></Table>
</div>
)
}
export default CustomTable;
\ No newline at end of file
import React from 'react';
import React, { useEffect } from 'react';
import {
SchemaForm,
registerVirtualBox
registerVirtualBox,
SchemaField,
registerValidationRules
} from '@formily/antd';
import { Row, Col } from 'antd';
// import { FormMegaLayout, Input } from '@formily/antd-components';
import { SchemaField } from "@formily/antd";
const renderCol = (schema) => {
const { flexcol = {}, } = schema && schema['x-component-props'] || {};
......@@ -17,7 +18,6 @@ const renderCol = (schema) => {
registerVirtualBox('CustomFlexRowLayout', (props) => {
const schemaProps = props;
console.log("CustomFlexRowLayout", schemaProps);
const childProperties = schemaProps.schema && schemaProps.schema.getOrderProperties() || [];
const { justify = "start", align = "top" } = schemaProps && schemaProps.props && schemaProps.props['x-component-props'] || {}
return (
......@@ -35,9 +35,7 @@ const FlexColumnLayoutStyle = {
}
registerVirtualBox('CustomFlexColumnLayout', (props) => {
const schemaProps = props;
console.log("CustomFlexColumnLayout", schemaProps);
const childProperties = schemaProps.schema && schemaProps.schema.getOrderProperties() || [];
console.log("childProperties", childProperties)
const { style } = schemaProps && schemaProps.props && schemaProps.props['x-component-props'] || {};
return (
......@@ -58,6 +56,7 @@ registerVirtualBox('CustomFlexColumnLayout', (props) => {
const FilterTable = (props) => {
const { actions, schema, components, ...rest } = props;
return (
<div>
<SchemaForm
......
import FilterTable from './FilterTable';
import CustomTable from './CustomTable';
import { SchemaFlexRowLayout, SchemaFlexColumnLayout } from './FlexLayout';
export {
FilterTable,
CustomTable,
SchemaFlexRowLayout,
SchemaFlexColumnLayout
}
\ No newline at end of file
import React, { useEffect, useState } from 'react';
import {
registerValidationRules
} from '@formily/antd';
const useCustomValidator = () => {
useEffect(() => {
//自定义校验规则
registerValidationRules({
limitByte: (value, desc, rules) => {
const { allowChineseTransform = true, maxByte } = desc;
let str = value;
let message = `不能超过${maxByte}个字符`
if (allowChineseTransform) {
str = str.replace(/[\u4E00-\u9FA5]/g, "AA");
message += `,或者${maxByte / 2}个汉字`
}
return str.length > maxByte ? message : "";
}
});
}, [])
}
export default useCustomValidator
......@@ -10,10 +10,12 @@ import { Input, Select } from 'antd';
import CustomUpload from '../components/WrapCustomUpload';
import { PublicApi } from '@/services/api';
import { useInitialValues } from '../hooks/useInitialValues';
import useCustomValidator from '../hooks/useValidator'
const actions = createFormActions();
const ImageInfo = () => {
useCustomValidator();
const { id, preview } = usePageStatus();
const initialValues: any = useInitialValues({id:id}, PublicApi.getManageContentImageGet);
const [submitLoading, setSubmitLoading ] = useState(false);
......
import React, { useEffect, useState } from 'react';
import { SchemaForm,Submit, FormButtonGroup, Reset, createVirtualBox, createFormActions } from '@formily/antd';
import { Card, Select, Input, Checkbox, Grid, Button } from 'antd';
import { SchemaForm,Submit, FormButtonGroup, Reset, createFormActions, registerValidationRules } from '@formily/antd';
import { Card, Select, Input, Checkbox} from 'antd';
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import ReutrnEle from '@/components/ReturnEle';
import { usePageStatus } from '@/hooks/usePageStatus';
......@@ -13,12 +13,14 @@ import { useInitialValues } from '../hooks/useInitialValues';
import { PublicApi } from '@/services/api';
import infomationInfoSchema from './schema/infomationInfoSchema';
import CustomUpload from '../components/WrapCustomUpload';
import useCustomValidator from '../hooks/useValidator'
const actions = createFormActions();
const { TextArea } = Input;
const InfomationInfo = () => {
useCustomValidator();
const { id, preview } = usePageStatus();
const [isTop, setIsTop] = useState(1);
const [labelIds, setLabelIds] = useState<number[]>([]);
......
......@@ -33,12 +33,14 @@ const schema = {
title: '标题',
'x-component': 'Input',
'x-component-props': {
placeholder: '30个字符,15个汉字'
},
"x-rules": {
"required": true,
"message": "最长30个字符,15个汉字"
placeholder: '最长30个汉字,60个字符',
},
"x-rules": [
{
limitByte: true,
maxByte: 60
}
]
},
columnId: {
name: 'columnId',
......@@ -131,11 +133,18 @@ const schema = {
"x-component": 'TextArea',
"x-component-props": {
placeholder: "最长300个字符,150个汉字",
rows: 5,
},
"x-rules": {
"required": true,
"message": "最长300个字符,150个汉字"
},
"x-rules": [
{
"required": true,
"message": "最长300个字符,150个汉字"
},
{
limitByte: true,
maxByte: 300
}
],
},
contentLayout: {
'x-component': 'mega-layout',
......
......@@ -7,6 +7,7 @@ import { usePageStatus } from '@/hooks/usePageStatus';
import { history, Prompt } from 'umi';
import { useInitialValues } from '../hooks/useInitialValues';
import { PublicApi } from '@/services/api';
import useCustomValidator from '../hooks/useValidator'
const { TextArea } = Input;
const schema = {
......@@ -27,20 +28,32 @@ const schema = {
title: '标签名称',
'x-component': 'Input',
"required": true,
"x-rules": {
"required": true,
"message": "请填写标签名称"
},
"x-rules": [
{
"required": true,
"message": "请填写标签名称"
},
{
limitByte: true, // 自定义校验规则
maxByte: 20,
}
],
},
explain: {
name: 'explain',
title: '标签说明',
'x-component': 'TextArea',
"required": true,
"x-rules": {
"required": true,
"message": "请选择标签说明"
},
"x-rules": [
{
"required": true,
"message": "请选择标签说明"
},
{
limitByte: true, // 自定义校验规则
maxByte: 80,
}
],
},
}
}
......@@ -50,6 +63,7 @@ const schema = {
const TagInfo = () => {
useCustomValidator();
const { id, preview } = usePageStatus();
const [ submitLoading, setSubmitLoading ] = useState(false);
const initialValues = useInitialValues({id:id}, PublicApi.getManageContentLabelGet);
......
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