new doceditor(el, optionsopt, serviceopt)
- source:
- ,
examples
//通过script标签引用
//将build后的dist目录部署到服务器web目录,dist可更改名称,然后通过script标签引入
doceditor
//使用 es module 模块引用
//1、将源码包放到项目目录中。
//2、使用 npm install 进行安装
//3、打包配置,需要将doceditor下的public目录部署到输出目录,如果您使用webpack,在config中使用copyplugin插件:
plugins: [
new copyplugin({
patterns: [
{ from: "doceditor/public", to: "doceditor/public" }
],
})
]
//4、在代码中使用。
import doceditor from '@o2oa/doceditor'
var div = document.createelement("div");
document.body.appendchild(div)
const editor = doceditor.createeditor(div, {
'base': './doceditor/' //我们在打包配置中将public目录输出到了 doceditor/public,所以此处需要配置为'./doceditor/' 或 'doceditor/'
//此处配置其他所需要的参数
});
editor.load().then(()=>{
//编辑器加载完成
}));
//使用 commandjs 模块引用
//与 es module 模块基本相同,只是通过require函数引入doceditor
const doceditor = require('@o2oa/doceditor');
//后面与 es module 模块相同
parameters:
name | type | attributes | description |
---|---|---|---|
el |
element | 要装载编辑器的element对象 | |
options |
|
公文编辑配置数据数据 | |
service |
|
公文编辑请求对象,需要调用者实现。 |
methods
autozoom(temporary)
根据屏幕自动缩放正文大小
- source:
- ,
example
editor.autozoom();
parameters:
name | type | description |
---|---|---|
temporary |
boolean | 可选 是否是临时缩放(默认false) |
editfiletext()
进入编辑状态,正文可编辑
- source:
- ,
example
editor.editfiletext();
exithistorydoc()
退出痕迹查看状态
- source:
- ,
example
editor.exithistorydoc();
fullscreen()
全屏显示
- source:
- ,
example
editor.fullscreen();
getdata() → {object}
获取公文编辑器数据
- source:
- ,
example
const data = editor.getdata();
returns:
- type
- object
getdocumenthtml() → {string}
- source:
- ,
example
var html = editor.getdocumenthtml();
returns:
- type
- string
historydoc()
进入痕迹查看状态
- source:
- ,
example
editor.historydoc();
(async) load(data)
载入公文编辑器
- source:
- ,
example
const editor = doceditor.createeditor(node);
editor.load().then(()=>{
//...
});
parameters:
name | type | description |
---|---|---|
data |
object | 公文编辑数据 |
off(type, listener)
删除编辑器事件监听
- source:
- ,
example
const listener = (e)=>{
//e.editor 编辑器对象
}
editor.on('loadpage', listener); //监听编辑器事件
editor.off('loadpage', listener); //删除编辑器事件监听
parameters:
name | type | description |
---|---|---|
type |
string | 编辑器事件名称 |
listener |
functioin | 需要从目标事件移除的 listener 函数。 |
on(type, listener)
监听编辑器事件,
- source:
- ,
example
editor.on('loadpage', (e)=>{
//e.editor 编辑器对象
});
parameters:
name | type | description |
---|---|---|
type |
string | 编辑器事件名称,可以是dom原生事件,这会将事件绑定到editornode上 |
listener |
functioin | 事件出发时执行函数 |
(async) printdoc()
将公文编辑转换为word文件,并下载
- source:
- ,
example
editor.printdoc();
provide(obj)
为编辑器注入service对象,用于请求编辑器数据和保存数据等服务,
- source:
- ,
example
import doceditor from '@o2oa/doceditor';
const node = document.queryselector('div');
const editor = doceditor.createeditor(node);
class myservice extends doceditor.service{
async listhistory() {
//获取正文痕迹列表
}
async gethistory(id){
//获取指定的正文痕迹比较数据
}
async savehistory(data){
//保存正文痕迹比较数据
}
async getdata(){
//获取编辑器数据
}
async savedata(data){
//保存编辑器数据
}
}
const service = new myservice();
editor.provide({service});
editor.load().then(()=>{
//...
});
parameters:
name | type | description |
---|---|---|
obj |
object | 要注入到编辑器的对象 |
readfiletext()
进入阅读状态,正文不能编辑
- source:
- ,
example
editor.readfiletext();
redisplay()
重新计算公文要素显示
- source:
- ,
example
editor.redisplay();
(async) reload(options, data)
重新载入公文编辑器
- source:
- ,
example
const editor = doceditor.createeditor(node);
editor.reload().then(()=>{
//...
});
parameters:
name | type | description |
---|---|---|
options |
object | 公文编辑配置数据数据 |
data |
object | 公文编辑数据 |
resetdata()
重新设置公文编辑器数据和展现
- source:
- ,
example
const data = editor.resetdata();
save()
保存正文数据 (需要实现service.savedata方法来完成与服务器的交互)
- source:
- ,
example
editor.save();
savehistory()
保存修订痕迹数据。会计算正文内容与上一次保存或第一次打开时的差异,生成修订痕迹,并请求保存。(需要实现service.savehistory方法来完成与服务器的交互)
- source:
- ,
example
editor.savehistory();
seal(src, position)
对正文进行模拟盖章,此方法只是进行模拟盖章,通过图片显示,并非专业盖章,不具备法律效应。
- source:
- ,
example
editor.seal("../custom/img/seal.png", 0); //在第一个盖章位置进行模拟盖章
parameters:
name | type | description |
---|---|---|
src |
string | 盖章图片的url. |
position |
integer | 要盖章的位置, 默认为0. |
setdata(data)
设置公文编辑器数据
- source:
- ,
example
const data = editor.getdata();
data.filetext = "测试内容";
editor.setdata(data);
parameters:
name | type | description |
---|---|---|
data |
object | 公文编辑数据 |
toword() → {promise}
将公文转换为word
- source:
- ,
example
editor.toword();
returns:
- type
- promise
zoom(scale, temporary)
- source:
- ,
example
editor.zoom(1.3);
parameters:
name | type | description |
---|---|---|
scale |
number | 缩放比例(0.5 - 2) |
temporary |
boolean | 可选 是否是临时缩放(默认false) |
zoomin()
公文编辑器放大显示 5%(0.05)
- source:
- ,
example
editor.zoomin();
zoomout()
公文编辑器缩小显示 5%(0.05)
- source:
- ,
example
editor.zoomout();
events
afterpaste
- source:
- ,
aftersave
- source:
- ,
aftersavehistory
- source:
- ,
beforeload
- source:
- ,
beforesave
- source:
- ,
beforesavehistory
- source:
- ,
blur
- source:
- ,
change
- source:
- ,
focus
- source:
- ,
fullscreen
- source:
- ,
load
- source:
- ,
loaded
- source:
- ,
loadpage
- source:
- ,
paste
- source:
- ,
postload
- source:
- ,
queryload
- source:
- ,
showhistory
- source:
- ,