欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Vue elementUI 自定義表單模板組件功能實現(xiàn)

 更新時間:2022年12月24日 10:47:10   作者:周圍都是小趴菜  
在項目開發(fā)中,我們會遇到這種需求,在管理后臺添加自定義表單,在指定的頁面使用定義好的表單,這篇文章主要介紹了Vue elementUI 自定義表單模板組件,需要的朋友可以參考下

elementUI 實現(xiàn)一個自定義的表單模板組件
注:該功能基于elementUI
背景:在項目開發(fā)中,我們會遇到這種需求,在管理后臺添加自定義表單,在指定的頁面使用定義好的表單

直接上代碼:

<template>
  <div>
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <div class="addBox">
        <el-form :model="form" label-width="90px" ref="form" :rules="rules">
          <el-form-item label="選項名稱" lebel-width="80" prop="label">
            <el-input placeholder="請輸入自定義選項名稱" maxlength="20" clearable v-model="form.label" @input="change($event)">
            </el-input>
          </el-form-item>
          <el-form-item label="選項提示" lebel-width="80" prop="tips">
            <el-input @input="change($event)" placeholder="請輸入提示內容" maxlength="20" clearable v-model="form.tips">
            </el-input>
          </el-form-item>
          <el-form-item label="選項類型" prop="value">
            <el-cascader clearable ref="cascader" v-model="value" :options="options" @change="handleChange">
            </el-cascader>
          </el-form-item>
          <el-form-item v-if="radioCount" label="最多選幾項">
            <el-input-number v-model="form.radioCount" controls-position="right" :min="1"></el-input-number>
            <!-- <el-input type="number" v-model="form.radioCount"></el-input> -->
          </el-form-item>
          <el-form-item v-if="isRadio" v-for="(domain, index) in radioOptions" :key="domain.id"
            :label="'添加選項' + (index + 1)" prop="name">
            <el-row>
              <el-col :span="18">
                <el-input placeholder="請輸入選擇框選項" v-model="domain.name"></el-input>
              </el-col>
              <el-col :span="6">
                <el-button @click="addType" v-if="index == 0">新增</el-button>
              </el-col>
              <el-col :span="6">
                <el-button @click.prevent="removeType(domain)" v-if="index > 0">刪除</el-button>
              </el-col>
            </el-row>
          </el-form-item>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">確 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  export default {
    name: 'WorkspaceJsonProjectCopy',

    data() {
      return {
        title: '新增選項',
        isRadio: false,
        value: [],
        rules: {},
        open: true,
        radioCount: false,
        form: {
          radioOptions: [{}],
          label: ''
        },
        radioOptions: [{}],
        options: [{
            value: "input",
            label: "輸入框",
            children: [{
                value: "phone",
                label: "手機號",
                children: [{
                    value: "0",
                    label: "非必填"
                  },
                  {
                    value: "1",
                    label: "必填"
                  }
                ]
              },
              {
                value: "idcard",
                label: "身份證號",
                children: [{
                    value: "0",
                    label: "非必填"
                  },
                  {
                    value: "1",
                    label: "必填"
                  }
                ]
              },
              {
                value: "link",
                label: "鏈接",
                children: [{
                    value: "0",
                    label: "非必填"
                  },
                  {
                    value: "1",
                    label: "必填"
                  }
                ]
              },
              {
                value: "email",
                label: "郵箱",
                children: [{
                    value: "0",
                    label: "非必填"
                  },
                  {
                    value: "1",
                    label: "必填"
                  }
                ]
              },
              {
                value: "other",
                label: "其他",
                children: [{
                    value: "0",
                    label: "非必填"
                  },
                  {
                    value: "1",
                    label: "必填"
                  }
                ]
              }
            ]
          },
          {
            value: "radio",
            label: "選擇框",
            children: [{
                value: "danxuan",
                label: "單選",
                children: [{
                    value: "0",
                    label: "非必填"
                  },
                  {
                    value: "1",
                    label: "必填"
                  }
                ]
              },
              {
                value: "duoxuan",
                label: "多選",
                children: [{
                    value: "0",
                    label: "非必填"
                  },
                  {
                    value: "1",
                    label: "必填"
                  }
                ]
              }
            ]
          },
          {
            value: "image",
            label: "圖片",
            children: [{
                value: "0",
                label: "非必填"
              },
              {
                value: "1",
                label: "必填"
              }
            ]
          },
          {
            value: "date",
            label: "日期—年月日",
            children: [{
                value: "0",
                label: "非必填"
              },
              {
                value: "1",
                label: "必填"
              }
            ]
          },
          {
            value: "datetime",
            label: "時間—時分秒",
            children: [{
                value: "0",
                label: "非必填"
              },
              {
                value: "1",
                label: "必填"
              }
            ]
          },
        ],
      };
    },

    mounted() {

    },

    methods: {
      change() {
        this.$forceUpdate();
      },
      // 彈窗選擇選項類型
      handleChange(value) {
        this.value = value
        if (value[0] && value[0] == 'radio' && value[1] == 'danxuan') {
          this.radioOptions = [{}]
          this.isRadio = true
          this.radioCount = false
        }
        if (value[0] && value[0] == 'radio' && value[1] == 'duoxuan') {
          this.radioOptions = [{}]
          this.isRadio = true
          this.radioCount = true
        }
        if (value[0] && value[0] != 'radio') {

          this.radioOptions = [{}]
          this.isRadio = false
          this.radioCount = false
        }
      },
      // 重置彈窗
      reset() {
        this.form = {}
        this.value = []
        this.radioOptions = [{}]
        this.isRadio = false
        this.radioCount = false,
          this.isEdit = false
        const _cascader = this.$refs.cascader
        if (_cascader) {
          _cascader.$refs.panel.checkedValue = [];
          _cascader.$refs.panel.activePath = [];
          _cascader.$refs.panel.syncActivePath()
        }
        this.resetForm("form");
      },
      // 取消彈窗
      cancel() {
        this.open = false;
        this.form = {}
        this.reset()
      },
      // 新增添加選擇框選項
      addType() {
        this.radioOptions.push({})
      },
      // 刪除新增的選擇框選項
      removeType(item) {
        var index = this.radioOptions.indexOf(item);
        if (index !== -1) {
          this.radioOptions.splice(index, 1);
        }
      },
      // 獲取創(chuàng)建時間
      getDate() {
        var date = new Date()
        var Y = date.getFullYear() + '-'
        var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
        var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' '
        var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':'
        var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':'
        var s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds())
        return Y + M + D + h + m + s
      },
      submitForm: function () {
        var value = this.value
        this.$refs["form"].validate((valid) => {
          if (valid) {
            if (value[0] == 'input') {
              var submitData = JSON.stringify({
                createTime: this.getDate(),
                label: this.form.label,
                type: 'input',
                inputType: value[1],
                mustFill: value[2],
                tips: this.form.tips,
                radioCount: null,
                radioOption: null
              })

            } else if (value[0] == 'radio' && value[1] == 'danxuan') {
              var options = []
              this.form.radioOptions = this.radioOptions
              for (var item of this.form.radioOptions) {
                options.push(item.name)
              }
              var subOption = options.join(';')
              console.log(options.join(';'))
              var submitData = JSON.stringify({
                createTime: this.getDate(),
                label: this.form.label,
                type: 'radio',
                radioCount: 1,
                mustFill: value[2],
                radioOption: subOption,
                tips: this.form.tips,
                inputType: null
              })
              console.log(this.form.radioOptions)
            } else if (value[0] == 'radio' && value[1] == 'duoxuan') {
              var options = []
              this.form.radioOptions = this.radioOptions
              for (var item of this.form.radioOptions) {
                options.push(item.name)
              }
              var subOption = options.join(';')

              console.log(options.join(';'))
              var submitData = JSON.stringify({
                createTime: this.getDate(),
                label: this.form.label,
                type: 'radio',
                mustFill: value[2],
                radioOption: subOption,
                tips: this.form.tips,
                radioCount: this.form.radioCount,
                inputType: null
              })
            } else if (value[0] == 'image') {
              var submitData = JSON.stringify({
                createTime: this.getDate(),
                label: this.form.label,
                type: 'image',
                mustFill: value[1],
                id: this.id,
                tips: this.form.tips,
                inputType: null,
                radioCount: null,
                radioOption: null
              })
            } else if (value[0] == 'date') {
              var submitData = JSON.stringify({
                createTime: this.getDate(),
                label: this.form.label,
                type: 'date',
                mustFill: value[1],
                id: this.id,
                tips: this.form.tips,
                inputType: null,
                radioCount: null,
                radioOption: null
              })
            } else if (value[0] == 'datetime') {
              var submitData = JSON.stringify({
                createTime: this.getDate(),
                label: this.form.label,
                type: 'datetime',
                mustFill: value[1],
                id: this.id,
                tips: this.form.tips,
                inputType: null,
                radioCount: null,
                radioOption: null
              })
            }
            console.log(submitData)
          }
        })
      },
    },

  };
</script>

在這里插入圖片描述

在這里插入圖片描述

到此這篇關于Vue elementUI 自定義表單模板組件的文章就介紹到這了,更多相關Vue elementUI 自定義表單模板組件內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • 詳解如何在vue項目中使用layui框架及采坑

    詳解如何在vue項目中使用layui框架及采坑

    這篇文章主要介紹了vue使用layui框架,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-05-05
  • 前端框架Vue.js構建大型應用淺析

    前端框架Vue.js構建大型應用淺析

    這篇文章主要為大家詳細介紹了前端框架Vue.js構建大型應用的相關資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • VUEJS 2.0 子組件訪問/調用父組件的實例

    VUEJS 2.0 子組件訪問/調用父組件的實例

    下面小編就為大家分享一篇VUEJS 2.0 子組件訪問/調用父組件的實例。具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-02-02
  • vue?導入js中的兩種方法(示例詳解)

    vue?導入js中的兩種方法(示例詳解)

    這篇文章主要介紹了vue?導入js中的方法,本文通過兩種方法結合示例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-07-07
  • 使用 webpack 插件自動生成 vue 路由文件的方法

    使用 webpack 插件自動生成 vue 路由文件的方法

    這篇文章主要介紹了使用 webpack 插件自動生成 vue 路由文件的方法,本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-08-08
  • 詳解如何在vue中使用sass

    詳解如何在vue中使用sass

    本篇文章主要介紹了詳解如何在vue中使用sass,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-06-06
  • vue 條件渲染v-if和v-show

    vue 條件渲染v-if和v-show

    這篇文章主要介紹了vue 條件渲染v-if和v-show,在模板中,可以根據(jù)條件進行渲染。條件用到的是v-if、v-else-if以及v-else來組合實現(xiàn)的,有時候我們想要在一個條件中加載多個html元素,那么我們可以通過template元素上實現(xiàn),下面就來看看具體實現(xiàn)吧
    2021-10-10
  • vue loadmore 組件滑動加載更多源碼解析

    vue loadmore 組件滑動加載更多源碼解析

    這篇文章主要介紹了vue loadmore 組件滑動加載更多源碼解析,需要的朋友可以參考下
    2017-07-07
  • vue項目適配大屏端的方法示例

    vue項目適配大屏端的方法示例

    眾所周知在vue移動端h5頁面當中,適配是經(jīng)常會遇到的問題,這篇文章主要給大家介紹了關于vue項目適配大屏端的相關資料,需要的朋友可以參考下
    2021-08-08
  • Vue實現(xiàn)監(jiān)聽某個元素滾動,親測有效

    Vue實現(xiàn)監(jiān)聽某個元素滾動,親測有效

    這篇文章主要介紹了Vue實現(xiàn)監(jiān)聽某個元素滾動,親測有效!具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-07-07

最新評論