فهرست منبع

chore: demo of customizing form layout using tailwind (#4549)

LinaBell 6 ماه پیش
والد
کامیت
b2c117f544
1فایلهای تغییر یافته به همراه100 افزوده شده و 0 حذف شده
  1. 100 0
      playground/src/views/examples/form/basic.vue

+ 100 - 0
playground/src/views/examples/form/basic.vue

@@ -223,6 +223,102 @@ const [BaseForm, baseFormApi] = useVbenForm({
   wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3',
 });
 
+const [CustomLayoutForm] = useVbenForm({
+  // 所有表单项共用,可单独在表单内覆盖
+  commonConfig: {
+    // 所有表单项
+    componentProps: {
+      class: 'w-full',
+    },
+  },
+  layout: 'horizontal',
+  schema: [
+    {
+      component: 'Input',
+      componentProps: {
+        placeholder: '请输入',
+      },
+      fieldName: 'field1',
+      label: '字符串',
+    },
+    {
+      component: 'Input',
+      componentProps: {
+        placeholder: '请输入',
+      },
+      fieldName: 'field2',
+      label: '字符串',
+    },
+    {
+      component: 'Input',
+      componentProps: {
+        placeholder: '请输入',
+      },
+      fieldName: 'field3',
+      label: '字符串',
+    },
+    {
+      component: 'Input',
+      componentProps: {
+        placeholder: '请输入',
+      },
+      fieldName: 'field4',
+      label: '字符串',
+    },
+    {
+      component: 'Input',
+      componentProps: {
+        placeholder: '请输入',
+      },
+      fieldName: 'field5',
+      // 从第三列开始 相当于中间空了一列
+      formItemClass: 'col-start-3',
+      label: '前面空了一列',
+    },
+    {
+      component: 'Input',
+      componentProps: {
+        placeholder: '请输入',
+      },
+      fieldName: 'field6',
+      // 占满三列空间
+      formItemClass: 'col-span-3',
+      label: '占满三列',
+    },
+    {
+      component: 'Input',
+      componentProps: {
+        placeholder: '请输入',
+      },
+      fieldName: 'field7',
+      // 占满2列空间 从第二列开始 相当于前面空了一列
+      formItemClass: 'col-span-2 col-start-2',
+      label: '占满2列',
+    },
+    {
+      component: 'Input',
+      componentProps: {
+        placeholder: '请输入',
+      },
+      fieldName: 'field8',
+      // 左右留空
+      formItemClass: 'col-start-2',
+      label: '左右留空',
+    },
+    {
+      component: 'Input',
+      componentProps: {
+        placeholder: '请输入',
+      },
+      fieldName: 'field9',
+      formItemClass: 'col-start-1',
+      label: '占满2列',
+    },
+  ],
+  // 一共三列
+  wrapperClass: 'lg:grid-cols-3',
+});
+
 function onSubmit(values: Record<string, any>) {
   message.success({
     content: `form values: ${JSON.stringify(values)}`,
@@ -256,6 +352,7 @@ function handleSetFormValue() {
 
 <template>
   <Page
+    content-class="flex flex-col gap-4"
     description="表单组件基础示例,请注意,该页面用到的参数代码会添加一些简单注释,方便理解,请仔细查看。"
     title="表单组件"
   >
@@ -265,5 +362,8 @@ function handleSetFormValue() {
       </template>
       <BaseForm />
     </Card>
+    <Card title="使用tailwind自定义布局">
+      <CustomLayoutForm />
+    </Card>
   </Page>
 </template>