项目地址:https://gitee.com/zhao-xuhang/tinymce

1.前期准备

这是个vue2项目所以要使用vue-cli (虽然开发tinymce插件和这个没关系)

1. 使用npm安装下面的依赖

1  "@packy-tang/vue-tinymce": "^1.1.2",
2 "@tinymce/tinymce-vue": "^3.2.8",
3 "tinymce": "^6.0.1",
2.打开node_modules 把 tinymce放到public (因为没有获取tinymceAPI密钥)
3.在index.html放入 <script src="./tinymce/tinymce.min.js"></script> 
4. 在main.js中引入
1 Vue.prototype.$tinymce = tinymce // 将全局tinymce对象指向给Vue作用域下
2 Vue.use(VueTinymce) // 安装vue的tinymce组件

5.在组件中引入tinymce

<vue-tinymce id="myTinymce" v-model="content" :setting="setting" :setup="setup" />  

setting配置

 1 setting: {
2 menubar: 'file edit view insert format tools table tc help',
3 toolbar:
4 "template preview | undo redo | fullscreen | formatselect alignleft aligncenter alignright alignjustify | link unlink | numlist bullist | image media table | fontselect fontsizeselect forecolor backcolor | bold italic underline strikethrough | indent outdent | superscript subscript | removeformat | help | print | control",
5 // toolbar_drawer: "sliding",
6 quickbars_selection_toolbar:
7 "removeformat | bold italic underline strikethrough | fontsizeselect forecolor backcolor",
8 plugins: "template preview link image media table lists fullscreen quickbars help control",
9 language: "zh_CN", //本地化设置
10 height: 500,
11 templates: [
12 {
13 title: "Some title 1",
14 description: "Some desc 1",
15 content: '<input type="text" />',
16 },
17 {
18 title: "Some title 2",
19 description: "Some desc 2",
20 content: '15111',
21 },
22 ],
23 }

2.开发插件

tinymce文档:https://www.tiny.cloud/docs/api/tinymce/root_tinymce/

1.打开目录public\tinymce\plugins 在里面找一个文件复制一份

2.文件夹改个名字control(这个名字最好是要引入的插件名),把plugin.js中的代码复制到plugin.min.js中   把control添加到toolbar和plugins

3.添加按钮 绑定方法 dialogOpener

1 // 添加插件的 button 和 菜单栏
2 const register = (editor, dialogOpener) => {
3 editor.ui.registry.addButton('control', {
4 icon: 'non-breaking', //图标
5 tooltip: '插入控件', //提示
6 onAction: dialogOpener //执行的方法
7 });
8 };

点击时会打开弹框 关于弹框的配置:https://www.tiny.cloud/docs/ui-components/dialog/

点击确定会执行弹框中的 onSubmit向内容中添加对应控件

4.添加上下文菜单 对控件执行编辑,删除操作   关于添加上下文菜单:https://www.tiny.cloud/docs/ui-components/contexttoolbar/

  1.注册上下文菜单的按钮    

编辑按钮 editor.ui.registry.addButton('changecontrol', {}) //获取到对应的控件数据,执行打开弹框进行编辑控件数据  
删除按钮 editor.ui.registry.addButton('removecontrol', {})
  2.添加上下文菜单到页面上  editor.ui.registry.addContextToolbar('editcontrol', {}) 
  3.为控件+号添加事件激活上下文菜单  

  
1 dom.bind(dom.select('.c-menu'), 'click', (e)=>{
2    // 显示指定的上下文菜单
3    editor.dispatch('contexttoolbar-show', { toolbarKey: 'editcontrol' });
4    // 隐藏指定的上下文菜单
5    // editor.dispatch('contexttoolbar-hide', { toolbarKey: 'editcontrol' });
6    console.log(e)
7    e.stopPropagation()
8 });

5.获取控件数据  将 editor.getControlValue = getControlValue 绑定到editor上

 1 // 获取控件数据值
2 let getControlValue = (editor)=>{
3 let dom = tinymce.activeEditor.dom
4 let controls = dom.select('.control')
5 let data = controls.map(item=>{
6 let dataControl = JSON.parse(item.getAttribute('data-control'))
7 let controlValue = item.getAttribute('data-value')
8 //文本框 没有data-value
9 if(!controlValue){
10 controlValue = item.firstElementChild.innerHTML
11 }
12 return {
13 controlType:dataControl.initialData.select,
14 fieldName:dataControl.initialData.name,
15 controlValue,
16 }
17 })
18 console.log(data)
19 return data
20 }
在页面上添加按钮绑定获取数据的方法 this.$tinymce.activeEditor.getControlValue() 

3.总结

复制新建插件文件->将插件添加到tinymce->编辑插件文件(1.注册添加控件插件按钮,2.绑定插件按钮的方法,3.添加编辑删除控件的上下文菜单按钮,4.获取控件数据)

预留问题:

  1.插件按钮应该做成下拉选择控件类型而不是弹框后再选择控件类型

  2.只能获取一次控件值,执行获取控件值  this.$tinymce.activeEditor.getControlValue() 后,再次修改控件值没有改变控件数据

关于我开发tinymce的自由表单、病历插件这件事的更多相关文章

  1. 表单元素(控件)不可见,你用visibility还是display?(转)

    属性大比拼:visibility和display的介绍 今天在做一个表单时涉及到这方面,当选中相应的选项后设置相应的几个元素(控件可见或不可见),后来还是用了visibility来实现.我们先来看下v ...

  2. 微信小程序——仿jqueryValidate表单验证插件WxValidate的二次封装(一)

    在做web开发时,表单验证插件我们前端用的是jqueryValidate,由于个人主要精力是在后台JAVA开发上,为了让插件与后台更好的结合和使用,通过JAVA的自定义组件将表单全部重新写了一边,同时 ...

  3. 如何使用.NET开发全版本支持的Outlook插件产品(二)——完善插件

    插件项目所有代码都已经上传至 https://github.com/VanPan/TestOutlookAdding 勿在浮砂筑高台--定位错误 在介绍后面的插件开发技术之前,让我们先来看看已经达到的 ...

  4. SNF开发平台WinForm之三-开发-单表选择控件创建-SNF快速开发平台3.3-Spring.Net.Framework

    3.1运行效果: 3.2开发实现: 3.2.1 这个开发与第一个开发操作步骤是一致的,不同之处就是在生成完代码之后,留下如下圈红程序,其它删除. 第一个开发地址:开发-单表表格编辑管理页面 http: ...

  5. SNF快速开发平台MVC-各种级联绑定方式,演示样例程序(包含表单和表格控件)

    做了这么多项目,经常会使用到级联.联动的情况. 如:省.市.县.区.一级分类.二级分类.三级分类.仓库.货位. 方式:有表单需要做级联的,还是表格行上需要做级联操作的. 实现:实现方法也有很多种方式. ...

  6. 数据库开发-Django ORM的单表查询

    数据库开发-Django ORM的单表查询 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.查询集 1>.查询集相关概述 查询会返回结果的集,它是django.db.mod ...

  7. jQuery学习之:Validation表单验证插件

    http://polaris.blog.51cto.com/1146394/258781/ 最近由于公司决定使用AJAX + Struts2来重构项目,让我仔细研究一下这两个,然后集中给同事讲讲,让每 ...

  8. Atitit.hybrid混合型应用 浏览器插件,控件的实现方式 浏览器运行本地程序的解决方案大的总结---提升用户体验and开发效率..

    Atitit.hybrid混合型应用 浏览器插件,控件的实现方式 浏览器运行本地程序的解决方案大的总结---提升用户体验and开发效率.. 1. hybrid App 1 1.1. Hybrid Ap ...

  9. 【jquery】Validform,一款不错的 jquery 表单验证插件

    关于 Validform 这是一款很不错的 jquery 表单验证插件,它几乎能够满足任何验证需求,仅仅一行代码就能搞定整站的表单验证. $('form').Validform(); 为什么能如此方便 ...

随机推荐

  1. vue2.0开发聊天程序(八) 初步完成

    项目地址 服务器源码地址:https://github.com/ermu592275254/chat-socket 网页源码地址:https://github.com/ermu592275254/ch ...

  2. WPF控件大全(表格)-学习总结

    Label标签 label控件:一般用户描述性文字显示. 在Label控件使用时,一般给予用户提示.用法上没有什么很特殊的,label控件的值记住:不是Text 而是 Content属性. TextB ...

  3. C#ASP.NET网站开发步骤

    1. 创建项目ASP.NET Web 应用程序. 2. 选择"Web 窗体"模板,然后单击 "确定" 按钮创建项目. 3. 在解决方案资源管理器中,右键添加we ...

  4. 【weex开发】环境配置流程

    1,安装node.js node官网下载,然后安装即可. 安装完成以后可以查看node和npm版本 $ node -v v6.11.3 $ npm -v 3.10.10 2,安装weex-toolki ...

  5. 将word文件转为excel文件

    有些word文件里的数据是有顺序或者规律,想转成表格的形式,下面就以我要转的word为例. 我的word文件是这样的 1.word转txt(文本文件) 文件--->另存为--->路径--- ...

  6. c++对c的拓展_函数的引用

    注意:1.引用可作为形参较指针更为直观 2可作为返回值 (判断标准:空间是否释放) #include <iostream> #include <stdlib.h> using ...

  7. python版本共存与语法的注释

    python的多种版本共存 首先还是先下载python解释器除最高版本的另外两个版本 个人推荐的是 3.6.8和2.7.14 首先我电脑是win7系统 在计算机属性右键点开高级设置点击环境变量 将下载 ...

  8. 搭建MySQL集群-注意版本

    系统环境采样(来自其他机器,直接copy过来的,在安装的机器上,按照步骤查看即可,当然这些还不够实际,后续补充) 检查系统内是否有其他mysql rpm -qa | grep mysql 是否存在my ...

  9. mybatis plus @TableId注解 type属性的含义

    首先该注解用在主键id上,它的type属性有8种类型 AUTO(0),NONE(1),INPUT(2),ASSIGN_ID(3),ASSIGN_UUID(4),ID_WORKER(3),ID_WORK ...

  10. 4.Docker容器学习之Dockerfile入门到放弃

    原文地址: 点击直达 0x01 Dockerfile 编写 描述:Dockerfile是一个文本格式的配置文件,其内包含了一条条的指令(Instruction),每一条指令构建一层,因此每一条指令的内 ...