Browse Source

fix(network): #3752 协议ID校验

Lind 3 years ago
parent
commit
3b4f14e8f7
1 changed files with 20 additions and 0 deletions
  1. 20 0
      src/pages/link/Protocol/index.tsx

+ 20 - 0
src/pages/link/Protocol/index.tsx

@@ -14,6 +14,7 @@ import { useIntl } from '@@/plugin-locale/localeExports';
 import type { ISchema } from '@formily/json-schema';
 import type { ISchema } from '@formily/json-schema';
 import { CurdModel } from '@/components/BaseCrud/model';
 import { CurdModel } from '@/components/BaseCrud/model';
 import Service from '@/pages/link/Protocol/service';
 import Service from '@/pages/link/Protocol/service';
+import { onFormMount, registerValidateRules } from '@formily/core';
 
 
 export const service = new Service('protocol');
 export const service = new Service('protocol');
 const Protocol = () => {
 const Protocol = () => {
@@ -139,6 +140,14 @@ const Protocol = () => {
     },
     },
   ];
   ];
 
 
+  registerValidateRules({
+    validateId(value) {
+      if (!value) return '';
+      const reg = new RegExp('^\\w{3,20}$');
+      return reg.exec(value) ? '' : 'ID只能由数字、26个英文字母或者下划线组成';
+    },
+  });
+
   const schema: ISchema = {
   const schema: ISchema = {
     type: 'object',
     type: 'object',
     properties: {
     properties: {
@@ -166,6 +175,10 @@ const Protocol = () => {
                 max: 64,
                 max: 64,
                 message: '最多可输入64个字符',
                 message: '最多可输入64个字符',
               },
               },
+              {
+                validateId: true,
+                message: 'ID只能由数字、26个英文字母或者下划线组成',
+              },
             ],
             ],
           },
           },
           name: {
           name: {
@@ -283,6 +296,13 @@ const Protocol = () => {
         modelConfig={{ width: '550px' }}
         modelConfig={{ width: '550px' }}
         schema={schema}
         schema={schema}
         actionRef={actionRef}
         actionRef={actionRef}
+        formEffect={() => {
+          onFormMount((form) => {
+            form.setFieldState('id', (state) => {
+              state.disabled = CurdModel.model === 'edit';
+            });
+          });
+        }}
       />
       />
       {/* {visible && <Debug data={current} close={() => setVisible(!visible)} />} */}
       {/* {visible && <Debug data={current} close={() => setVisible(!visible)} />} */}
     </PageContainer>
     </PageContainer>