1.0.251 • Published 2 years ago

@zjyuanfei/zjsmartform v1.0.251

Weekly downloads
130
License
ISC
Repository
-
Last release
2 years ago

药研云-智能表单

Introduction

智能表单可以灵活配置和扩展,帮助开发人员快速构建高度定制的表单生成器。

Install

智能表单提供了一些基础控件,基于 Vue 和 element@2.13.1,所以请先安装它们。

npm i -S element @zjyuanfei/zjsmartform

Setup

import ElementUI from 'element-ui'
import smartForm from "@zjyuanfei/zjsmartform";
import 'element-ui/lib/theme-chalk/index.css';

Vue.use(ElementUI);
Vue.use(smartForm);

Basic usage

<template>
    <smart-form
      :panelList="panelList"
      @save="getData"
    />
</template>
<script>
  data(){
    return {
      panelList: []
    }
  },
  methods:{
    getData(){}
  }
</script>

Example

<template>
  <div>
    <!-- 配置模式 -->
    <smart-form
      v-if="!isEdit"
      ref="sf"
      :diyComponent="diyComponent"
      :diyConfig="diyConfig"
      :panelList="panelList"
      :templateList="templateList"
      @save="getData"
      :input-search="inputSearch"
    />
    <!-- 编辑模式 -->
    <smart-form
      v-else
      :disabled="false"
      :isEdit="isEdit"
      :diyComponent="diyComponent"
      :userLayout="userLayout"
      :input-search="inputSearch"
      @action-btn="handler"
    />
  </div>
</template>

<script>
import HelloWorld from "../components/HelloWorld";
import HelloWorld2 from "../components/HelloWorld2";
import ConfigInput from "../components/ConfigInput";
import ConfigInput2 from "../components/ConfigInput2";
export default {
  name: "Home",
  data() {
    return {
      isEdit: false,
      userLayout: [
        {
          x: 0,
          y: 0,
          w: 4,
          h: 2,
          i: 5,
          id: "ZDzxLpLVAJ",
          currentCompontent: "sfInput",
          btnArr: ["question", "checked", "edit", "freeze"],
          config: {
            area_id: "",
            area_title: "",
            ctrl_name: "",
            type: "text",
            title: "标题",
            domain_name: "",
            id: "",
            rank: "left",
            required: 0,
            width: 200,
            height: 40,
            align: "start",
            input_type: "0",
            meddra_ver: "0",
            unitValue: "",
            unitOptions: []
          }
        }
      ],
      diyComponent: [],
      diyConfig: [],
      templateListData: [
        {
          name: "第一个模板",
          data: [
            {
              x: 0,
              y: 0,
              w: 12,
              h: 2,
              i: 5,
              id: "BPVqKW8dzy",
              currentCompontent: "sfRegion",
              config: { area_title: "域" },
              moved: false
            },
            {
              x: 0,
              y: 2,
              w: 12,
              h: 2,
              i: 6,
              id: "Zrga8VAY15",
              currentCompontent: "sfText",
              config: {
                area_id: "",
                area_title: "",
                ctrl_name: "",
                type: "static_label",
                id: "",
                title: "静态文本",
                align: "start",
                fontsize: "16",
                bold: false
              },
              moved: false
            },
            {
              x: 0,
              y: 4,
              w: 12,
              h: 2,
              i: 7,
              id: "ky8WrNymvv",
              currentCompontent: "sfRegion",
              config: { area_title: "域" },
              moved: false
            },
            {
              x: 0,
              y: 6,
              w: 12,
              h: 2,
              i: 8,
              id: "Z6nm1eYlyQ",
              currentCompontent: "sfText",
              config: {
                area_id: "",
                area_title: "",
                ctrl_name: "",
                type: "static_label",
                id: "",
                title: "静态文本",
                align: "start",
                fontsize: "16",
                bold: false
              },
              moved: false
            }
          ]
        },
        {
          name: "第二个模板",
          data: [
            {
              x: 0,
              y: 0,
              w: 12,
              h: 2,
              i: 5,
              id: "ky8WrNARol",
              currentCompontent: "sfRegion",
              config: { area_title: "域" },
              moved: false
            },
            {
              x: 0,
              y: 2,
              w: 12,
              h: 2,
              i: 6,
              id: "kKyLwmlaRR",
              currentCompontent: "sfText",
              config: {
                area_id: "",
                area_title: "",
                ctrl_name: "",
                type: "static_label",
                id: "",
                title: "静态文本",
                align: "start",
                fontsize: "16",
                bold: false
              },
              moved: false
            },
            {
              x: 0,
              y: 4,
              w: 12,
              h: 2,
              i: 7,
              id: "BJEDMLJn4r",
              currentCompontent: "sfRegion",
              config: { area_title: "域" },
              moved: false
            },
            {
              x: 0,
              y: 6,
              w: 12,
              h: 8,
              i: 8,
              id: "2QzgYbVO5a",
              currentCompontent: "sfTable",
              config: {
                area_id: "",
                area_title: "",
                type: "dynamic_table",
                row: 1,
                col: 2,
                columnConfig: [
                  { label: "第1列", component: "el-input" },
                  { label: "第2列", component: "el-select" }
                ]
              },
              moved: false
            }
          ]
        }
      ],
      panelList: [
        {
          title: "web表单",
          list: [
            {
              name: "域",
              componentName: "sfRegion",
              componentConfig: "sfRegionConfig"
            },
            {
              name: "静态文本",
              componentName: "sfText",
              componentConfig: "sfTextConfig"
            },
            {
              name: "单行输入框",
              componentName: "sfInput",
              componentConfig: "sfInputConfig"
            },
            {
              name: "多行输入框",
              componentName: "sfTextarea",
              componentConfig: "sfTextareaConfig"
            },
            {
              name: "单选框",
              componentName: "sfRadio",
              componentConfig: "sfRadioConfig"
            },
            {
              name: "复选框",
              componentName: "sfCheckbox",
              componentConfig: "sfCheckboxConfig"
            },
            {
              name: "下拉框",
              componentName: "sfSelect",
              componentConfig: "sfSelectConfig"
            },
            {
              name: "日期控件",
              componentName: "sfDatepicker",
              componentConfig: "sfDatepickerConfig"
            },
            {
              name: "动态表格",
              componentName: "sfTable",
              componentConfig: "sfTableConfig"
            },
            {
              name: "静态表格",
              componentName: "sfStaticTable",
              componentConfig: "sfStaticTableConfig"
            }
          ]
        },
        {
          isExtend: true,
          title: "扩展控件",
          list: [
            {
              name: "helloWorld",
              componentName: "HelloWorld",
              componentConfig: "ConfigInput"
            }
          ]
        },
        {
          isExtend: true,
          title: "通用控件",
          list: [
            {
              name: "helloWorld2",
              componentName: "HelloWorld2",
              componentConfig: "ConfigInput2"
            }
          ]
        }
      ]
    };
  },
  created() {
    this.diyComponent = [HelloWorld, HelloWorld2];
    this.diyConfig = [ConfigInput, ConfigInput2];
  },
  methods: {
    templateList(obj, cb){
            if(obj){
                cb(this.templateListData)
            }
        },
    getData(layouts) {
      console.log(layouts, "lll");
    },
    inputSearch(queryString, cb) {
      let restaurants = [
        {
          value: "456三全鲜食(北新泾店)",
          address: "长宁区新渔路144号"
        },
        {
          value: "Hot honey 首尔炸鸡(仙霞路)",
          address: "上海市长宁区淞虹路661号"
        }
      ];
      if (queryString === "456") {
        restaurants = [{ value: "测试", address: "长宁区新渔路144号" }];
      }
      cb(restaurants);
    },
    handler(config) {
      console.log("核查逻辑:", config);
    }
  },
  computed: {}
};
</script>

Properties

  • panelList
    • type: Array
    • required: 1
    • default: []

控件选择面板,提供基于一组基础配置,数据结构下文中给出示例。

  • userLayout
    • type: Array
    • required: 0
    • default: []

传入的 layout

  • templateList: Function

模板列表,数据结构下文中给出示例。

  • isEdit
    • type: Boolean
    • required: 0
    • default: false

使用编辑模式

  • diyComponent
    • type: Array
    • required: 0
    • default: []

自定义组件

  • diyConfig
    • type: Array
    • required: 0
    • default: []

自定义组件的配置项,需要跟 diyComponent 中的自定义组件对应起来

  • input-search
    • type: Function
    • required: 0
    • params:
      • { String } queryString
      • { Function } callBack

输入框联想输入,queryString 是输入框的值,callBack 则用于接收搜索到的数据,参数是必须是数组类型。(Tips:函数触发已经做了防抖处理。)

Event

action-btn

核查逻辑点击事件

// template
<smart-form
  @action-btn="handler"
/>
// methods
handler: function(type){
  // Type 是按钮的类型 question,question-new,checked,freeze,edit
}

save

保存按钮,点击事件,返回当前配置的数组

// template
<smart-form
  @save="handler"
/>
// methods
handler: function(layouts){
  // layouts 是整个表单的配置数据
}

Methods

save

调用智能表单的保存方法

<template>
    <smart-form ref="sf" />
</template>

<script>
    methods:{
        handler(){
            this.$refs.sf.save()
        }
    }
</script>

highlightWidget

  • type: Function
  • required: 0
  • params:
    • { String } id 控件 id

表单模式下高亮控件,传入控件的 Id

<template>
    <smart-form ref="sf" />
</template>

<script>
    methods:{
        handler(){
            this.$refs.sf.highlightWidget(id)
        }
    }
</script>
1.0.206

2 years ago

1.0.205

2 years ago

1.0.208

2 years ago

1.0.207

2 years ago

1.0.204

2 years ago

1.0.203

2 years ago

1.0.251

2 years ago

1.0.250

2 years ago

1.0.220

2 years ago

1.0.222

2 years ago

1.0.221

2 years ago

1.0.228

2 years ago

1.0.227

2 years ago

1.0.229

2 years ago

1.0.224

2 years ago

1.0.223

2 years ago

1.0.226

2 years ago

1.0.225

2 years ago

1.0.211

2 years ago

1.0.210

2 years ago

1.0.217

2 years ago

1.0.216

2 years ago

1.0.219

2 years ago

1.0.218

2 years ago

1.0.213

2 years ago

1.0.212

2 years ago

1.0.215

2 years ago

1.0.214

2 years ago

1.0.209

2 years ago

1.0.242

2 years ago

1.0.241

2 years ago

1.0.244

2 years ago

1.0.243

2 years ago

1.0.240

2 years ago

1.0.249

2 years ago

1.0.246

2 years ago

1.0.245

2 years ago

1.0.248

2 years ago

1.0.247

2 years ago

1.0.231

2 years ago

1.0.230

2 years ago

1.0.233

2 years ago

1.0.232

2 years ago

1.0.239

2 years ago

1.0.238

2 years ago

1.0.235

2 years ago

1.0.234

2 years ago

1.0.237

2 years ago

1.0.236

2 years ago

1.0.200

2 years ago

1.0.202

2 years ago

1.0.201

2 years ago

1.0.187

2 years ago

1.0.186

2 years ago

1.0.189

2 years ago

1.0.188

2 years ago

1.0.183

2 years ago

1.0.182

2 years ago

1.0.185

2 years ago

1.0.184

2 years ago

1.0.181

2 years ago

1.0.180

2 years ago

1.0.176

2 years ago

1.0.175

2 years ago

1.0.178

2 years ago

1.0.177

2 years ago

1.0.172

2 years ago

1.0.171

2 years ago

1.0.174

2 years ago

1.0.173

2 years ago

1.0.179

2 years ago

1.0.170

2 years ago

1.0.198

2 years ago

1.0.197

2 years ago

1.0.199

2 years ago

1.0.194

2 years ago

1.0.193

2 years ago

1.0.196

2 years ago

1.0.195

2 years ago

1.0.190

2 years ago

1.0.192

2 years ago

1.0.191

2 years ago

1.0.165

2 years ago

1.0.164

2 years ago

1.0.167

2 years ago

1.0.166

2 years ago

1.0.161

2 years ago

1.0.160

2 years ago

1.0.163

2 years ago

1.0.162

2 years ago

1.0.169

2 years ago

1.0.168

2 years ago

1.0.156

3 years ago

1.0.158

3 years ago

1.0.157

3 years ago

1.0.159

2 years ago

1.0.154

3 years ago

1.0.155

3 years ago

1.0.153

3 years ago

1.0.152

3 years ago

1.0.150

3 years ago

1.0.151

3 years ago

1.0.149

3 years ago

1.0.147

3 years ago

1.0.146

3 years ago

1.0.148

3 years ago

1.0.143

3 years ago

1.0.142

3 years ago

1.0.145

3 years ago

1.0.144

3 years ago

1.0.141

3 years ago

1.0.140

3 years ago

1.0.139

3 years ago

1.0.136

3 years ago

1.0.138

3 years ago

1.0.137

3 years ago

1.0.132

3 years ago

1.0.134

3 years ago

1.0.133

3 years ago

1.0.135

3 years ago

1.0.131

3 years ago

1.0.130

3 years ago

1.0.129

3 years ago

1.0.128

3 years ago

1.0.127

3 years ago

1.0.126

3 years ago

1.0.121

3 years ago

1.0.120

3 years ago

1.0.123

3 years ago

1.0.122

3 years ago

1.0.125

3 years ago

1.0.124

3 years ago

1.0.118

3 years ago

1.0.119

3 years ago

1.0.117

3 years ago

1.0.116

3 years ago

1.0.115

3 years ago

1.0.109

3 years ago

1.0.110

3 years ago

1.0.112

3 years ago

1.0.111

3 years ago

1.0.114

3 years ago

1.0.113

3 years ago

1.0.107

3 years ago

1.0.108

3 years ago

1.0.106

3 years ago

1.0.105

3 years ago

1.0.104

3 years ago

1.0.103

3 years ago

1.0.101

3 years ago

1.0.102

3 years ago

1.0.77

3 years ago

1.0.76

3 years ago

1.0.75

3 years ago

1.0.79

3 years ago

1.0.78

3 years ago

1.0.100

3 years ago

1.0.80

3 years ago

1.0.84

3 years ago

1.0.83

3 years ago

1.0.82

3 years ago

1.0.81

3 years ago

1.0.88

3 years ago

1.0.87

3 years ago

1.0.86

3 years ago

1.0.85

3 years ago

1.0.89

3 years ago

1.0.91

3 years ago

1.0.90

3 years ago

1.0.95

3 years ago

1.0.94

3 years ago

1.0.93

3 years ago

1.0.92

3 years ago

1.0.99

3 years ago

1.0.98

3 years ago

1.0.97

3 years ago

1.0.96

3 years ago

1.0.62

3 years ago

1.0.61

3 years ago

1.0.60

3 years ago

1.0.66

3 years ago

1.0.65

3 years ago

1.0.64

3 years ago

1.0.63

3 years ago

1.0.69

3 years ago

1.0.68

3 years ago

1.0.67

3 years ago

1.0.73

3 years ago

1.0.72

3 years ago

1.0.71

3 years ago

1.0.70

3 years ago

1.0.74

3 years ago

1.0.48

3 years ago

1.0.49

3 years ago

1.0.51

3 years ago

1.0.50

3 years ago

1.0.55

3 years ago

1.0.54

3 years ago

1.0.53

3 years ago

1.0.52

3 years ago

1.0.59

3 years ago

1.0.58

3 years ago

1.0.57

3 years ago

1.0.56

3 years ago

1.0.47

3 years ago

1.0.46

3 years ago

1.0.44

3 years ago

1.0.43

3 years ago

1.0.45

3 years ago

1.0.42

3 years ago

1.0.41

3 years ago

1.0.39

3 years ago

1.0.40

3 years ago

1.0.38

3 years ago

1.0.37

3 years ago

1.0.36

3 years ago

1.0.35

3 years ago

1.0.34

3 years ago

1.0.33

3 years ago

1.0.32

3 years ago

1.0.22

3 years ago

1.0.26

3 years ago

1.0.25

3 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.29

3 years ago

1.0.28

3 years ago

1.0.27

3 years ago

1.0.31

3 years ago

1.0.30

3 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.21

3 years ago

1.0.20

3 years ago

1.0.15

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

0.2.98

3 years ago