Mr_HJ / form-generator项目文档学习与记录(续2)

更多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

上面代码按钮显示相应的代码与界面

javascript 复制代码
<el-button icon="el-icon-view" type="text" @click="Code">
          代码
        </el-button>
javascript 复制代码
Code() {
      this.operationType = 'Code'
      let data = {
        fileName: undefined,
          type: 'file'
      }
      this.generate(data);
    },
javascript 复制代码
generate(data) {
      const func = this[`exec${titleCase(this.operationType)}`]
      this.generateConf = data
      func && func(data)
    },

上面实现是调用了下面的方法,就是execCode方法

ƒ execCode(data) {

this.AssembleFormData();

this.drawerVisible = true;

}

其中AssembleFormData就把配置信息与要显示的字段放进去

javascript 复制代码
AssembleFormData() {
      this.formData = {
        ...this.formConf,
        fields: deepClone(this.drawingList)
      }
    },

通过开关显示这个下面的组件

javascript 复制代码
<form-drawer
      :visible.sync="drawerVisible"
      :form-data="formData"
      size="100%"
      :generate-conf="generateConf"
    />

这个页面主要用到了两个组件,样式优化组件beautifier和显示组件monaco-editor,在打开el-drawer的时候就进行初始化了

javascript 复制代码
onOpen() {
      const { type } = this.generateConf
      this.htmlCode = makeUpHtml(this.formData, type)
      this.jsCode = makeUpJs(this.formData, type)
      this.cssCode = makeUpCss(this.formData)
      this.key = +new Date()
      loadBeautifier(btf => {
        beautifier = btf
        this.htmlCode = beautifier.html(this.htmlCode, beautifierConf.html)
        this.jsCode = beautifier.js(this.jsCode, beautifierConf.js)
        this.cssCode = beautifier.css(this.cssCode, beautifierConf.html)

        loadMonaco(val => {
          monaco = val
          this.setEditorValue('editorHtml', 'html', this.htmlCode)
          this.setEditorValue('editorJs', 'js', this.jsCode)
          this.setEditorValue('editorCss', 'css', this.cssCode)
          if (!this.isInitcode) {
            this.isParser = true
            this.isParser && (this.isInitcode = true) && this.runCode()
          }
        })
      })
    },

对于左边代码显示部分,主要是下面部分处理,为了避免一些问题,下面注释了一些没用的信息

javascript 复制代码
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()
        }
      })
    },

之前说过,原来模拟显示采用iframe 加载的是提前写好的 html,但这种方式对于新加的组件就不怎么友好了,所以修改成如下方式了

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

效果图如下:

相关推荐
一水鉴天8 分钟前
整体设计 之28 整体设计 架构表表述总表的 完整程序(之27 的Q268 )(codebuddy)
java·前端·javascript
DsirNg14 分钟前
使用 SSE 单向推送实现 系统通知功能
前端·javascript
星光一影23 分钟前
美容/心理咨询/问诊/法律咨询/牙医预约/线上线下预约/牙医行业通用医疗预约咨询小程序
mysql·小程序·vue·php·uniapp
IT_陈寒23 分钟前
SpringBoot 3.2 实战:用这5个新特性让你的API性能提升40%
前端·人工智能·后端
霍理迪35 分钟前
HTML初相识
前端·html
yuyu_030436 分钟前
SOHE智能厨余垃圾处理系统
java·vue
恋猫de小郭1 小时前
Android 宣布 Runtime 编译速度史诗级提升:在编译时间上优化了 18%
android·前端·flutter
莓莓儿~1 小时前
Next.js 14 App Router数据获取开发手册
开发语言·前端·javascript
文心快码BaiduComate1 小时前
AI Coding老跑偏?用Comate Rules功能,少走十年弯路!
前端·架构·前端框架
PineappleCoder1 小时前
WebP/AVIF 有多香?比 JPEG 小 30%,<picture>标签完美解决兼容性
前端·面试·性能优化