Browse Source

系统设置添加规则优化

wangwei 4 years ago
parent
commit
072a18ba10

+ 1 - 1
package.json

@@ -1,5 +1,5 @@
 {
-  "name": "jet-admin",
+  "name": "pyadmin",
   "version": "2.4.2",
   "author": {
     "name": "jet",

+ 3 - 2
src/components/Form/src/hooks/useFormEvents.ts

@@ -237,13 +237,14 @@ export function useFormEvents({
     const formEl = unref(formElRef);
     if (!formEl) return;
     try {
-      console.log('===========try=========');
       const values = await validate();
-      console.log(`values`, values);
       const res = handleFormValues(values);
       emit('submit', res);
     } catch (error) {
       console.log(`error`, error);
+      if (error.errorFields[0].errors[0]) {
+        error = error.errorFields[0].errors[0];
+      }
       throw new Error(error);
     }
   }

+ 15 - 8
src/views/conventional/system/components/ArrayCom.vue

@@ -60,23 +60,30 @@
             console.log(evt);
             console.log(`移动前的位置索引`, evt.oldIndex);
             console.log(`移动后的位置索引`, evt.newIndex);
-            const newIndex = evt.newIndex as number;
-            const oldIndex = evt.oldIndex as number;
-            const temp = state.list[oldIndex];
-            state.list[oldIndex] = state.list[newIndex];
-            state.list[newIndex] = temp;
-            console.log(`list`, state.list);
+            // // const newIndex = evt.newIndex as number;
+            // const oldIndex = evt.oldIndex as number;
+            // const newIndex = evt.newIndex as number;
+            // const current = state.list[oldIndex];
+            // const list: object[] = [];
+            // state.list.map((item, index) => {
+            //   if (index != oldIndex) {
+            //     list.push(item);
+            //   }
+            // });
+            // list.splice(newIndex, 0, current);
+            // console.log(`list`, list);
+            // state.list = list;
+            // console.log(`list`, state.list);
           },
         });
       }
       onMounted(() => {
         initSortable(); // 开启拖拽功能
-        // console.log(`fn`, fn)
       });
 
       function create() {
         console.log(`state.list`, state.list);
-        state.list.push({ name: '' });
+        state.list.push({ name: '', value: '' });
       }
       function remove(i) {
         console.log(`i`, i);

+ 47 - 3
src/views/conventional/system/data.ts

@@ -222,8 +222,7 @@ export const schemas: FormSchema[] = [
     colProps: {
       span: 20,
     },
-    required: true,
-    rules: [{ type: 'email', trigger: 'blur', message: 'dsfhhhh' }],
+    rules: [{ required: true, type: 'email', trigger: 'blur' }],
   },
   {
     field: 'value',
@@ -243,11 +242,56 @@ export const schemas: FormSchema[] = [
   },
   {
     field: 'rule',
-    component: 'SelectOptGroup',
+    component: 'Select',
     label: '校验规则',
     colProps: {
       span: 20,
     },
+    componentProps: {
+      mode: 'multiple',
+      options: [
+        {
+          label: '必选(required)',
+          value: 'required',
+          key: 'required',
+        },
+        {
+          label: '数字(digits)',
+          value: 'digits',
+          key: 'digits',
+        },
+        {
+          label: '字母(letters)',
+          value: 'letters',
+          key: 'letters',
+        },
+        {
+          label: '日期(time)',
+          value: 'time',
+          key: 'time',
+        },
+        {
+          label: '邮箱(email)',
+          value: 'email',
+          key: 'email',
+        },
+        {
+          label: '网址(url)',
+          value: 'url',
+          key: 'url',
+        },
+        {
+          label: 'QQ号(qq)',
+          value: 'qq',
+          key: 'qq',
+        },
+        {
+          label: '身份证(IDcard)',
+          value: 'IDcard',
+          key: 'IDcard',
+        },
+      ],
+    },
   },
   {
     field: 'extra',

+ 12 - 1
src/views/conventional/system/index.vue

@@ -18,7 +18,12 @@
     />
     <span v-if="tipShow" class="tip">点击添加新的配置</span>
     <BasicTable ref="tableRef" :canResize="true" v-if="tableShow" @register="registerTable" />
-    <BasicForm class="config-form" v-if="formShow" @register="registerForm" />
+    <BasicForm
+      class="config-form"
+      v-if="formShow"
+      @register="registerForm"
+      @submit="handleSubmit"
+    />
     <div v-if="tableShow" class="actions">
       <a-button class="mr-2" type="default" @click="onBasicConfig">
         {{ t('common.resetText') }}
@@ -219,6 +224,11 @@
           console.log('=======全部校验通过========');
         }
       }
+
+      function handleSubmit(e) {
+        console.log('=======values =======');
+        console.log(`e`, e);
+      }
       return {
         t,
         tableRef,
@@ -229,6 +239,7 @@
         onBasicConfig,
         addConfig,
         onSubmit,
+        handleSubmit,
         ...toRefs(state),
       };
     },