Skip to content

Frame 框架

frame 框架打开的子页面要关闭时,需要通过调用父级页面的fApi.closeModel方法关闭

在线预览

规则

基础示例

js
const rule = {
    type:"frame",
    title:"素材",
    field:"fodder",
    value:["/uploads/20131030/30-075657_191.jpg?2"],
    props:{
        type:"image",
        src:"iframe.html",
        maxLength:2,


},
    validate:[
        {required:true, type: 'array', min: 2, message: '请选择2张图片', trigger: 'change'}
    ],
}

Props 配置示例

图片选择(image)

js
const rule = {
    type:"frame",
    title:"商品图片",
    field:"images",
    value:[],
    props:{
        type:"image",
        src:"/image-picker.html",
        maxLength: 5,
        width: "800px",
        height: "600px",
    },
    validate:[
        {required:true, type: 'array', min: 1, message: '请至少选择1张图片', trigger: 'change'}
    ],
}

文件选择(file)

js
const rule = {
    type:"frame",
    title:"附件",
    field:"files",
    value:[],
    props:{
        type:"file",
        src:"/file-picker.html",
        maxLength: 3,
    },
}

输入框(input)

js
const rule = {
    type:"frame",
    title:"自定义内容",
    field:"content",
    value:"",
    props:{
        type:"input",
        src:"/content-editor.html",
        width: "900px",
        height: "700px",
    },
}

开启助手方法

js
const rule = {
    type:"frame",
    title:"素材选择",
    field:"material",
    value:[],
    props:{
        type:"image",
        src:"/material-picker.html",
        helper: true,
        maxLength: 5,
    },
}

Events 事件示例

监听打开和关闭

js
const rule = {
    type:"frame",
    title:"素材选择",
    field:"material",
    value:[],
    props:{
        type:"image",
        src:"/material-picker.html",
        maxLength: 5,
    },
    on: {
        open: () => {
            console.log('打开弹出框');
        },
        close: () => {
            console.log('关闭弹出框');
        },
        change: (value) => {
            console.log('值改变:', value);
        },
    },
}

选择后验证

js
const rule = {
    type:"frame",
    title:"商品图片",
    field:"images",
    value:[],
    props:{
        type:"image",
        src:"/image-picker.html",
        maxLength: 5,
    },
    inject: true,
    on: {
        change: ($inject, value) => {
            // 验证图片数量
            if (value.length < 2) {
                $inject.api.setMessage('images', '请至少选择2张图片');
            } else {
                $inject.api.clearMessage('images');
            }
        },
    },
    validate:[
        {required:true, type: 'array', min: 2, message: '请至少选择2张图片', trigger: 'change'}
    ],
}

value: String | Number | Array

props

属性说明类型默认值
typeframe显示类型,有input(字符串),file(文件),image(图片)Stringinput
src框架页面的地址String-
helper开启框架页面内助手方法Booleanfalse
disabled禁用组件Booleanfalse
icon打开弹出框的按钮图标String-
srcKeyvalueObject[]时需要定义 srcKeyString-
width弹出框宽度String-
height弹出框高度String-
okBtnText弹出框确定按钮文字String'确定'
closeBtnText弹出框关闭按钮文字String'关闭'
modalTitle图片预览弹出框标题文字String'预览'
handleIcon操作按钮的图标 ,设置为false将不显示,设置为true为默认的预览图标,类型为file时默认为false,image类型默认为trueString | Boolean-
title弹出框标题String-
modal配置弹出框 propsObject-
allowRemove是否可删除,设置为false是不显示删除按钮,type等于 image 或者 file 时有效Booleantrue
onChangevalue改变时触发Function-
onOpen打开弹出层回调Function-
onOk点击确定时的回调,返回false将不关闭弹窗Function-
onHandle点击操作按钮事件,默认为图片预览Function-
onBeforeRemove点击删除按钮删除前事件,返回false将不删除Function-
onRemove点击删除按钮事件Function-
onCancel弹出框关闭时触发,返回false将不关闭弹窗Function-

helper

开启助手方法后框架页面会增加全局变量form_create_helper,用于快速操作组件

  • close

  • 参数: - field 组件的 field

  • 说明: 关闭当前frame组件的弹出框

  • 示例:

    js
    form_create_helper.close(field)
  • set

  • 参数: - field 组件的 field - value 组件的值

  • 说明: 修改当前frame组件的值

  • 示例:

    js
    form_create_helper.set(field,[1,2,3])
  • get

  • 参数: - field 组件的 field

  • 说明: 获取当前frame组件的值

  • 示例:

    js
    const value = form_create_helper.get(field)

FormCreate 是一个开源项目,基于 MIT 许可证发布,欢迎个人和企业用户免费使用