Mr_HJ / form-generator项目学习-增加自定义的超融组件(二)

更多ruoyi-nbcio功能请看演示系统

gitee源代码地址

前后端代码: https://gitee.com/nbacheng/ruoyi-nbcio

演示地址:RuoYi-Nbcio后台管理系统

更多nbcio-boot功能请看演示系统

gitee源代码地址

后端代码: https://gitee.com/nbacheng/nbcio-boot

前端代码:https://gitee.com/nbacheng/nbcio-vue.git

在线演示(包括H5) : http://122.227.135.243:9888
 

这部分主要介绍,改造原有的form-generator模拟显示方式

1、因为原先用iframe的方式,用固定的html文件模板方式处理,这样很不灵活,特别是对自己自定义的组件来说。

    所以改专用的preview.vue来处理,如下:

<template>
  <el-dialog v-bind="$attrs" :close-on-click-modal="false" :modal-append-to-body="false"
    append-to-body v-on="$listeners" @open="Open" @close="close"
    title="预览" :width="formConf.generalWidth">
    <parser :form-conf="formConf" @submit="submitForm" :key="key" ref="previewForm" />
    <div slot="footer">
      <el-button @click="close">{
  {'取 消'}}</el-button>
      <el-button type="primary" @click="handelConfirm">{
  {'确 定'}}
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
import Parser from '@/utils/generator/parser'
export default {
  components: { Parser },
  props: ['formData'],
  data() {
    return {
      key: +new Date(),
      formConf: {}
    }
  },
  created() { },
  methods: {
    Open() {
      this.key = +new Date()
      this.formConf = this.formData
    },
    onClose() {
    },
    close(e) {
      this.$emit('update:visible', false)
    },
    handelConfirm() {
      this.$refs.previewForm && this.$refs.previewForm.submitForm()
    },
    submitForm(data, callback) {
      console.log('submitForm提交数据:', data)
      if (callback && typeof callback === "function") {
        callback()
      }
    }
  }
}
</script>

2、代码显示里面也进行单独处理,同时修改setEditorValue,保证每次打开都能显示代码(原先有时候可以有时候不显示)

setEditorValue(id, type, codeStr) {
     // if (editorObj[type]) {
     //   editorObj[type].setValue(codeStr)
     // } else {
        editorObj[type] = monaco.editor.create(document.getElementById(id), {
          value: codeStr,
          theme: 'vs-dark',
          language: mode[type],
          automaticLayout: true
        })
      //}
      // ctrl + s 刷新
      editorObj[type].onKeyDown(e => {
        if (e.keyCode === 49 && (e.metaKey || e.ctrlKey)) {
          this.runCode()
        }
      })
    },

同时界面用下面方式处理

<div class="view-border">
              <parser v-show="isParser" :form-conf="formData" @submit="submitForm" :key="key" ref="previewForm" />
            </div>


.view-border {
  margin-top: 10px;
  border-top: 5px dashed blue;
  border-right: 5px dashed blue;
  border-bottom: 5px dashed blue;
  border-left: 5px dashed blue;
}

3、效果图

最近更新

  1. Spring AOP 基础知识

    2024-01-13 09:16:01       1 阅读
  2. PHP MySQL 简介

    2024-01-13 09:16:01       1 阅读
  3. linux 文件末尾追加内容

    2024-01-13 09:16:01       1 阅读
  4. 从IE到Edge:微软浏览器的演变与未来展望

    2024-01-13 09:16:01       1 阅读
  5. 浅谈ES6

    2024-01-13 09:16:01       1 阅读
  6. 风景园林工程设计乙级资质业绩要求案例分析

    2024-01-13 09:16:01       1 阅读

热门阅读

  1. response.cookies详解

    2024-01-13 09:16:01       37 阅读
  2. MySQL数据库基础

    2024-01-13 09:16:01       35 阅读
  3. 【linux】 shell 之 字符串 -z, -n 判断

    2024-01-13 09:16:01       35 阅读
  4. windows系统Mysql备份脚本

    2024-01-13 09:16:01       43 阅读
  5. c++简单做一个文件变长储存(自己封装字符串类)

    2024-01-13 09:16:01       33 阅读
  6. TCP/IP Illustrated Episode 23

    2024-01-13 09:16:01       31 阅读