Skip to content

t-form-modal

FormModal 表单弹窗

组件介绍

动态表单模态框组件,通过JSON配置弹出编辑框,支持多种表单组件类型,attrs可绑定事件和ref,实现表单各组件的关联控制。

平台兼容

HarmonyH5AndroidiOS小程序UTS

基础用法

vue
<template>
  <t-form-modal ref="formModalRef" @confirm="handleConfirm" @cancel="handleCancel"></t-form-modal>
  <t-button type="primary" @click="openInput">打开输入框</t-button>
  <t-button type="primary" @click="openSelect">打开选择器</t-button>
  <t-button type="primary" @click="openRadio">打开单选框</t-button>
</template>

<script setup>
const formModalRef = ref(null);

function openInput() {
  formModalRef.value.show({
    name: 'username',
    type: 'input',
    title: '请输入用户名',
    describe: '用户名长度为2-20个字符',
    value: '',
    attrs: {
      placeholder: '请输入用户名',
      maxlength: 20
    }
  });
}

function openSelect() {
  formModalRef.value.show({
    name: 'city',
    type: 'select',
    title: '请选择城市',
    describe: '请选择您所在的城市',
    value: '',
    list: [
      { label: '北京', value: 'beijing' },
      { label: '上海', value: 'shanghai' },
      { label: '广州', value: 'guangzhou' },
      { label: '深圳', value: 'shenzhen' }
    ],
    attrs: {
      placeholder: '请选择城市'
    }
  });
}

function openRadio() {
  formModalRef.value.show({
    name: 'gender',
    type: 'radio',
    title: '请选择性别',
    describe: '请选择您的性别',
    value: '',
    list: [
      { label: '男', value: 'male' },
      { label: '女', value: 'female' }
    ],
    attrs: {
      mode: 'button'
    }
  });
}

function handleConfirm(data) {
  console.log('确认提交:', data);
  // 处理提交的数据
}

function handleCancel() {
  console.log('取消操作');
}
</script>

Props

属性名类型默认值说明可选值
sizeString""组件尺寸large, medium, small, mini
typeString""组件类型info, primary, error, warning, success
disabledBooleanfalse组件是否禁用true, false
hoverBooleanfalse是否有点击效果true, false
pathString""点击组件后跳转的页面路径-
effectString""组件显示主题normal, dark, light, plain
confirmTextString"确认"提示框确认按钮的文本-

Events

事件名说明回调参数
confirm点击确认按钮时触发
cancel取消填写-
transitionend动画结束时触发boolean

Methods

方法名说明参数返回值
show显示模态框option: UTSJSONObject

支持的表单类型

类型说明对应组件
input文本输入框t-input
select下拉选择器t-select
pickerSelect选择器t-picker-select
radio单选框组t-radio-group
checkbox复选框组t-checkbox-group
stepper步进器t-stepper
slider滑块组件t-slider
rate评分组件t-rate
code验证码输入框t-code-input
switch开关组件t-switch
upload文件上传t-upload
textarea文本域t-textarea
color颜色选择器t-color
calendar日历组件t-calendar
cascader级联选择器t-cascader
fileManager文件管理器t-file-manager
date日期选择器t-select-date
city城市选择器t-picker-city