当前位置: 首页 > article >正文

vue自定义表单布局

当项目无法满足实际业务需求时可以使用antd vue 原生布局具体用法参考Grid栅格用法

1.表单布局,一行两列

<template>
    <BasicModal v-bind="$attrs" @register="registerModal" :title="getTitle" :width="1000" @ok="handleSubmit">
        <a-form ref="formEl" :model="planModel" :label-col="{xs: {span: 24}, sm: {span: 6}}" :wrapper-col="{xs: {span: 24}, sm: {span: 18}}" :rules="validatorRules">
            <a-row>
                <a-col :span="12">
                    <a-form-item label="日程标题" name="title">
                        <a-input placeholder="请输入标题" v-model:value="planModel.title"/>
                    </a-form-item>
                </a-col>
                <a-col :span="12">
                    <a-form-item label="日程类型">
                        <JDictSelectTag placeholder="请选择类型" type="select" v-model:value="planModel.type" dictCode="eoa_plan_type"/>
                    </a-form-item>
                </a-col>
                <a-col :span="12">
                    <a-form-item label="提醒类型" name="remindType">
                        <a-select placeholder="请选择提醒类型" mode="multiple"  v-model:value="planModel.remindType">
                            <a-select-option value="1">邮件</a-select-option>
                            <a-select-option value="2">短信</a-select-option>
                            <a-select-option value="4">系统消息</a-select-option>
                        </a-select>
                    </a-form-item>
                </a-col>
                <a-col :span="12">
                    <a-form-item label="紧急程度" name="urgentLevel">
                        <JDictSelectTag placeholder="请选择紧急程度" type="select" v-model:value="planModel.urgentLevel" dictCode="urgent_level"/>
                    </a-form-item>
                </a-col>
                <a-col :span="12">
                    <a-form-item label="提醒时间" name="remind">
                        <JDictSelectTag placeholder="请选择提醒时间" type="select" v-model:value="planModel.remind" dictCode="remindTime"/>
                    </a-form-item>
                </a-col>
                <a-col :span="12">
                    <a-form-item label="重复提醒" name="reminders">
                        <JDictSelectTag placeholder="请选择重复提醒" type="select" v-model:value="planModel.reminders" dictCode="reminders"/>
                    </a-form-item>
                </a-col>
                <a-col :span="12">
                    <a-form-item label="日程时间" name="rangeTime">
                        <a-range-picker v-bind="dateRangePickerProps" v-model:value="planModel.rangeTime" />
                    </a-form-item>
                </a-col>
            </a-row>
        </a-form>
    </BasicModal>
</template>
<script lang="ts" setup>
     省略....
    const formEl = ref();
    const isUpdate = ref(true);
    //表单modal
    const planModel = reactive({ });
    //表单赋值
    const [registerModal, {setModalProps, closeModal}] = useModalInner(async (data) => {
        setModalProps({confirmLoading: false});
        isUpdate.value = !!data?.isUpdate;
        if (unref(isUpdate)) {
            const record = await queryById({id:data?.record?.id});
            Object.assign(planModel, record);
        }
    });
    //标题
    const getTitle = computed(() => (!unref(isUpdate) ? '新增' : '编辑'));

    /**
     * 表单提交事件
     * */
    async function handleSubmit() {
        formEl.value.validate().then(async() => {
            try {
                setModalProps({confirmLoading: true});
                let formData = Object.assign({}, planModel)
                await saveOrUpdate(formData,unref(isUpdate));
               closeModal();
               emit('success'); 
            } finally {
                setModalProps({confirmLoading: false});
            }
        }).catch((error: ValidateErrorEntity<any>) => {
            console.log('error', error);
        })
    }
</script>

<style lang="less" scoped>
  

http://www.kler.cn/a/298196.html

相关文章:

  • 【专业解析】电脑文件夹打不开的深层原因与高效数据恢复策略
  • 项目运行插件-日志管理
  • 海报制作软件有哪些?免费海报制作试试这些
  • 并发编程 - NSOperationNSOperationQueue(多线程)
  • Java语言程序设计基础篇_编程练习题*18.14 (求字符串中大写字母的个数)
  • Day20_0.1基础学习MATLAB学习小技巧总结(20)——MATLAB绘图篇(3)
  • Unity3D 小案例 像素贪吃蛇 01 蛇的移动
  • vben-admin:调用vben的对话框,并向对话框传递数据(vue3setup语法)
  • 【专题】2024年8月医药行业报告合集汇总PDF分享(附原数据表)
  • 前k个高频元素
  • 数据库,数据仓库,数据湖,湖仓一体到底是什么区别
  • 可以从以下几个方面判断一个 SQL 查询是否需要优化:
  • 大屏地图区域显示、复选框多选打点,自定义窗体信息(vue3+TS)
  • Web安全与网络安全:SQL漏洞注入
  • 再见Java 8,请掌握最新LTS
  • 微擎框架
  • 【爱加密_云平台-注册/登录安全分析报告】
  • 图像处理基础篇-镜像仿射透视
  • Leetcode面试经典150题-55.跳跃游戏
  • MongoDB基本语法