vue3 vben table form 使用

搜索:

const typeOps = [
  {
    label: 'a',
    value: '1',
  },
  {
    label: 'b',
    value: '2',
  },
];

{
    field: 'displaySystem',
    label: '系统',
    component: 'Select',
    componentProps: {
      options: typeOps ,
      showSearch: true,
      optionFilterProp: 'label',
    },
    colProps: {
      span: 5,
    },
},
{
    field: 'deptId',
    label: '部门',
    component: 'ApiSelect',
    componentProps: ({ formModel, formActionType }) => {
      return {
        api: getSelectDept,
        labelField: 'deptName',
        valueField: 'deptId',
        onChange: (e, v) => {
          const { updateSchema } = formActionType;
          formModel.city = undefined;
          updateSchema({
            field: 'systemUsersId',
            componentProps: {
              options: [],
            },
          });
          console.log('ApiSelect====>:', e, v);
        },
      };
    },
    colProps: {
      span: 12,
    },
    required: true,
    dynamicDisabled: ({ values }) => {
      return !!values.id;
    },
},
{
    field: 'time',
    label: '时间',
    component: 'RangePicker',
    componentProps: {
      // format: 'YYYY-MM-DD HH:mm:ss',
      placeholder: ['开始时间', '结束时间'],
      showTime: { format: 'YYYY-MM-DD HH:mm:ss' },
    },
},

//便捷按钮
import dayjs, { Dayjs } from 'dayjs'
type RangeValue = [Dayjs, Dayjs]
{
    field: 'payTimeBetween',
    component: 'RangePicker',
    label: '时间',
    componentProps: {
      // format: 'YYYY-MM-DD HH:mm:ss',
      placeholder: ['开始日期', '结束日期'],
      showTime: { format: 'YYYY-MM-DD HH:mm:ss' },
      ranges: {
        昨天: [
          dayjs(dayjs(new Date().getTime() - 3600 * 1000 * 24).format('YYYY-MM-DD') + ' 00:00:00'),
          dayjs(dayjs(new Date().getTime() - 3600 * 1000 * 24).format('YYYY-MM-DD') + ' 23:59:59')
        ] as RangeValue
      }
    }
}

表格:

import { Image} from 'ant-design-vue';
 {
    title: '图片',
    dataIndex: 'photoUrl',
    align: 'center',
    customRender: ({ record }) => {
      if (!record.photoUrl) return;
      return h(Image, { src: record.photoUrl, width: '50px' });
    },
},

import { h } from 'vue';
import { Image, Switch } from 'ant-design-vue';
import { useMessage } from '/@/hooks/web/useMessage';
import { updateAdvertisement } from '../../../../api/adNews/advertisement';
{
    title: '状态',
    dataIndex: 'upFlag',
    align: 'center',
    customRender: ({ record }) => {
      console.log(record.upFlag);
      return h(Switch, {
        checked: record.upFlag == '1',
        checkedChildren: '上架',
        unCheckedChildren: '下架',
        onChange(checked: boolean) {
          const newStatus = checked ? '1' : '0';
          const { createMessage } = useMessage();
          updateAdvertisement({ ...record, upFlag: newStatus })
            .then(() => {
              record.upFlag = newStatus;
              createMessage.success(`状态修改成功`);
            })
            .catch(() => {})
            .finally(() => {});
        },
      });
    },
},

const statusOps = [
  {
    label: 'a',
    value: '0',
  },
  {
    label: 'b',
    value: '1',
  },
  {
    label: 'c',
    value: '2',
  },
];
const statusColorOps = { 1: 'red', 2: 'green', 0: '#f50' };
{
    title: '状态',
    dataIndex: 'status',
    align: 'center',
    customRender: ({ record }) => {
      const obj = statusOps.find((item) => item.value == record.status);
      return h(Tag, { color: statusColorOps[record.status] }, () => obj?.label);
    },
},

import dayjs, { Dayjs } from 'dayjs'
{
    title: '时间',
    dataIndex: 'payTime',
    align: 'center',
    customRender: ({ record }) => {
      return h('div', {}, record.payTime ? dayjs(new Date(record.payTime)).format('YYYY-MM-DD HH:mm:ss') : '')
    }
  },

表单:

 {
    field: 'id',
    label: '主键',
    component: 'Input',
    required: false,
    show: false,
  },
{
    field: 'sortNo',
    label: '排序',
    component: 'InputNumber',
    required: true,
  },

//
const typeOps = [
  {
    label: 'a',
    value: '1',
  },
  {
    label: 'b',
    value: '2',
  },
];
 {
    field: 'type',
    label: '类型',
    component: 'Select',
    componentProps: {
      options: typeOps,
    },
    // required: true,
    rules: [{ required: true, message: '请' }],
    ifShow: ({ values }) => {
      return !!values.type;
    },
  },
//多选下拉框
  {
    field: 'displaySystem',
    label: '系统',
    component: 'Select',
    componentProps: {
      options: displaySystemOps,
      mode: 'multiple',
      showArrow: true,
      showSearch: true,
      optionFilterProp: 'label',
    },
    required: true,
    dynamicDisabled: ({ values }) => {
      return !!values.id;
    },
  },
//
import { Switch } from 'ant-design-vue';
{
    field: 'upFlag',
    label: '状态',
    component: 'Switch',
    defaultValue: '0',
    componentProps: {
      unCheckedValue: '0',
      checkedValue: '1',
      checkedChildren: '上架',
      unCheckedChildren: '下架',
    },
    // required: true,
  },

//年月日时间点
{
    field: 'enableTime',
    label: '活动开始时间',
    component: 'DatePicker',
    componentProps: {
      showTime: { format: 'YYYY-MM-DD HH:mm:ss' },
    },
    required: true,
  },

{
    field: 'pass',
    label: '结果',
    component: 'RadioGroup',
    required: true,
    colProps: {
      span: 8,
    },
    componentProps: {
      options: [
        {
          label: '通过',
          value: true,
        },
        {
          label: '不通过',
          value: false,
        },
      ],
    },
    defaultValue: true,
    ifShow: ({ values }) => {
      return values.applyStatus == 6;
    },
  },
{
    field: 'auditRemark',
    label: '不通过理由',
    component: 'InputTextArea',
    required: true,
    ifShow: ({ values }) => {
      return !values.pass && values.applyStatus == 6;
    },
    componentProps: {
      placeholder: '请输入不通过理由',
      // rows: 5,
      autosize: { minRows: 5 },
      showCount: true,
      maxlength: 500,
    },
    colProps: {
      span: 24,
    },
  },
{
    field: 'fileList',
    label: '图片',
    component: 'Input',
    slot: 'fileListSlot',
    rules: [
      {
        required: true,
        validator: async (rule, value) => {
          console.log(value);
          if (!(value && value[0])) {
            return Promise.reject('请上传图片');
          }
          return Promise.resolve();
        },
        trigger: 'change',
      },
    ],
  },

描述:

const statusOps = {
  '0': '下线',
  '1': '上线',
};
const statusColorOps = { '0': 'red', '1': 'green' };
{
    field: 'status',
    label: '活动状态',
    span: 1,
    render: (curVal) => {
      return h(Tag, { color: statusColorOps[curVal] }, () => statusOps[curVal]);
    },
  },

import { h } from 'vue';
  {
    field: 'color',
    label: '颜色',
    span: 1,
    render: (curVal) => {
      return h('div', {
        style: { background: curVal, width: '20px', height: '20px' },
      });
    },
    show: ({ proposalFormDetailsList }) => {
      if (proposalFormDetailsList == undefined) return false;
      if (!proposalFormDetailsList && !proposalFormDetailsList.length) return false;
      for (const item of proposalFormDetailsList) {
        if (item.insuranceName == '公众') {
          return true;
        }
      }
      return false;
    },
    span: 3,
  },

 {
    field: 'useRule',
    label: '规则',
    span: 3,
    render: (curVal) => {
      return h('div', {
        innerHTML: curVal, // 这里是要渲染的数据
      });
    },
  },

{
    field: 'url',
    label: '照片',
    render: (curVal) => {
      if (!curVal) return;
      const imageList = [] as any;
      curVal.forEach((item) => {
        imageList.push(h(Image, { src: item, style: { margin: '10px 20px', width: '50px' } }));
      });
      return h('div', {}, imageList);
    },
    span: 3,
  },

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Vue3 dynamic-form是一个基于Vue3的动态表单组件,用于快速生成表单页面。它允许开发者根据后端接口返回的数据动态生成表单项,包括输入框、下拉框、单选框、复选框等常见的表单控件。 使用Vue3 dynamic-form,开发者只需要提供一个配置文件,配置文件中包含了表单的字段、类型、校验规则等信息。组件会根据这些配置自动生成表单,并实现表单数据的校验和提交功能。 Vue3 dynamic-form具有以下特点: 1. 灵活性:由于使用配置文件来生成表单,开发者可以灵活地控制表单的展示逻辑、校验规则等。可以通过简单的配置文件,快速生成复杂的表单页面。 2. 高性能:Vue3 dynamic-form基于Vue3,充分利用了Vue3的优化特性,例如静态提升、编译时优化等,使得组件的渲染和更新更加高效。 3. 组件化:Vue3 dynamic-form是一个独立的组件,可以在各种Vue3项目中独立使用。可以通过传入不同的配置文件,生成不同的表单页面,实现代码的复用和拓展性。 4. 扩展性:Vue3 dynamic-form提供了丰富的插件和扩展机制,开发者可以根据自己的需求自定义表单控件、校验规则等。 总而言之,Vue3 dynamic-form是一个功能强大、灵活性高、性能优越的动态表单组件,为开发者提供了便捷的表单生成和校验功能,大大节省了开发时间和精力。无论是简单的表单页面还是复杂的表单需求,都可以通过Vue3 dynamic-form轻松实现。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值