Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
xf360 committed Dec 8, 2023
1 parent d49a7a3 commit 3454761
Show file tree
Hide file tree
Showing 11 changed files with 236 additions and 91 deletions.
26 changes: 26 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@

基于 onlyoffice7.6

js入口:apps/api/documents/api.js
编辑器入口:apps/[documenteditor]/main/index.html

加载步骤:
1.引用apps/api/documents/api.js
2.上一步的js会根据配置构造对应编辑器页面的url地址apps/[documenteditor]/main/index.html,并拼接为iframe标签。
3.iframe加载编辑器页面加载完成后发送postmessage消息到方法_onMessage中,

编辑器加载过程:
1.从url中获取配置参数,确认浏览器版本、语言、logo、域、主题
2.从/sdkjs/develop/sdkjs/[word]/scripts.js中获取要引用的js文件列表
3.将上一步的js列表插入到index.html文件中,并加载
4.使用requiredjs script data-main的方式加载界面(backone应用)apps\[documenteditor]\main\app[_dev].js
5.app[_dev].js会加载各种依赖及启动backone应用
6.启动后执行apps\common\main\lib\core\application.js的start方法
7.首页controller为apps\documenteditor\main\app\controller\Viewport.js 对应的view为apps\documenteditor\main\app\view\Viewport.js template为apps\documenteditor\main\app\template\Viewport.template
8.首页加载完成后调用new Asc.asc_docs_api初始化编辑器,Asc.asc_docs_api方法为/sdkjs/[word]/api.js脚本加载。
9.apps\common\main\lib\component为ui组件库(checkbox,button等)
10.apps\documenteditor\main\app\controller\Toolbar.js为编辑器工具条(主页,插入,视图等)
11.sdk\word\Editor\Run.js 为文档run内容解析文件,其中content为段落内容,value属性为字符的unicode编码。
12.callback url http://localhost/example/track?filename=new.docx&useraddress=172.17.0.1

13.使用window.io或 socketio 和后端建立连接链接地址:/7.5.1-23/web-apps/apps/documenteditor/main/../../../../doc/172.17.0.1new.docx121701950543362/c(ws://localhost/7.5.1-23/doc/172.17.0.1new.docx121701950543362/c/)
14.ws 服务会将文档docx转为bin文件,然后把下载路径返回给前端,前端在下载该bin文档打开。
24 changes: 16 additions & 8 deletions apps/api/documents/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

;(function(DocsAPI, window, document, undefined) {

// debugger;//1
console.log('---1.api初始化:')
/*
# Full #
Expand Down Expand Up @@ -318,12 +320,15 @@
*/

// TODO: allow several instances on one page simultaneously

//编辑器初始化
DocsAPI.DocEditor = function(placeholderId, config) {
// debugger;//2.
console.log('---2.构建编辑器iframe:')
var _self = this,
_config = config || {};

//生成配置
extend(_config, DocsAPI.DocEditor.defaultConfig);
//
_config.editorConfig.canUseHistory = _config.events && !!_config.events.onRequestHistory;
_config.editorConfig.canHistoryClose = _config.events && !!_config.events.onRequestHistoryClose;
_config.editorConfig.canHistoryRestore = _config.events && !!_config.events.onRequestRestore;
Expand Down Expand Up @@ -395,6 +400,7 @@
};

var _onMessage = function(msg) {
console.log('收到消息',msg);//编辑器发过来的消息
if ( msg ) {
if ( msg.type === "onExternalPluginMessage" ) {
_sendCommand(msg);
Expand Down Expand Up @@ -509,15 +515,16 @@
iframe;

if (target && _checkConfigParams()) {
iframe = createIframe(_config);
iframe = createIframe(_config);//创建编辑器iframe
if (_config.editorConfig.customization && _config.editorConfig.customization.integrationMode==='embed')
window.AscEmbed && window.AscEmbed.initWorker(iframe);

if (iframe.src) {
var pathArray = iframe.src.split('/');
this.frameOrigin = pathArray[0] + '//' + pathArray[2];
}
target.parentNode && target.parentNode.replaceChild(iframe, target);
target.parentNode && target.parentNode.replaceChild(iframe, target);//将iframe编辑器插入当前文档
//绑定事件3.
var _msgDispatcher = new MessageDispatcher(_onMessage, this);
}

Expand Down Expand Up @@ -792,7 +799,6 @@
}
});
};

return {
showMessage : _showMessage,
processSaveResult : _processSaveResult,
Expand Down Expand Up @@ -843,11 +849,12 @@
DocsAPI.DocEditor.version = function() {
return '{{PRODUCT_VERSION}}';
};

//绑定事件
MessageDispatcher = function(fn, scope) {
var _fn = fn,
_scope = scope || window,
eventFn = function(msg) {
// debugger;//iframe编辑器加载完成 1-1
_onMessage(msg);
};

Expand Down Expand Up @@ -923,7 +930,7 @@

return "";
}

//获取对应编辑器路径
function getAppPath(config) {
var extensionPath = getExtensionPath(),
path = extensionPath ? extensionPath : (config.type=="test" ? getTestPath() : getBasePath()),
Expand Down Expand Up @@ -1036,7 +1043,7 @@

return params;
}

//创建编辑器iframe
function createIframe(config) {
var iframe = document.createElement("iframe");

Expand All @@ -1061,6 +1068,7 @@
return iframe;
}

//向子窗体(编辑器)发送消息
function postMessage(wnd, msg) {
if (wnd && wnd.postMessage && window.JSON) {
// TODO: specify explicit origin
Expand Down
3 changes: 3 additions & 0 deletions apps/common/Gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ if (window.Common === undefined) {
};

var _postMessage = function(msg) {
debugger;//发送消息到调用方
// TODO: specify explicit origin
if (window.parent && window.JSON) {
msg.frameEditorId = window.frameEditorId;
Expand All @@ -165,6 +166,8 @@ if (window.Common === undefined) {
};

var _onMessage = function(msg) {
debugger;
console.log("gateway.js 收到消息")
// TODO: check message origin
if (msg.origin !== window.parentOrigin && msg.origin !== window.location.origin && !(msg.origin==="null" && (window.parentOrigin==="file://" || window.location.origin==="file://"))) return;

Expand Down
2 changes: 2 additions & 0 deletions apps/common/main/lib/core/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@
},

start: function() {
debugger;
console.log('---5.1 backone应用启动:')
// initialize controllers
this.initializeControllers(this.controllers || {});
// call to controller.onLaunch callback
Expand Down
7 changes: 7 additions & 0 deletions apps/documenteditor/main/app/controller/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ define([
},

onLaunch: function() {
console.log('controllers/main加载')
var me = this;

this.stackLongActions = new Common.IrregularStack({
Expand Down Expand Up @@ -247,6 +248,8 @@ define([
Common.Gateway.on('showmessage', _.bind(this.onExternalMessage, this));
Common.Gateway.on('opendocument', _.bind(this.loadDocument, this));
Common.Gateway.on('grabfocus', _.bind(this.onGrabFocus, this));
//触发appready事件
console.log('触发appready事件')
Common.Gateway.appReady();

// $(window.top).resize(_.bind(this.onDocumentResize, this));
Expand Down Expand Up @@ -491,6 +494,8 @@ define([
},

loadDocument: function(data) {
console.log('loadDocument加载文档')
debugger;
this.permissions = {};
this.document = data.doc;

Expand Down Expand Up @@ -1189,6 +1194,8 @@ define([
},

onDocumentContentReady: function() {
debugger;
console.log('onDocumentContentReady')
if (this._isDocReady)
return;

Expand Down
2 changes: 2 additions & 0 deletions apps/documenteditor/main/app/controller/ViewTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ define([
},

onChangeRulers: function (btn, checked) {
console.log('切换是否显示标尺');
debugger;
Common.localStorage.setBool('de-hidden-rulers', !checked);
Common.Utils.InternalSettings.set("de-hidden-rulers", !checked);
this.api.asc_SetViewRulers(checked);
Expand Down
8 changes: 5 additions & 3 deletions apps/documenteditor/main/app/controller/Viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ define([
'documenteditor/main/app/view/LeftMenu'
], function (Viewport) {
'use strict';

// debugger;
console.log('---加载控制器controllers/Viewport.js')
DE.Controllers.Viewport = Backbone.Controller.extend(_.assign({
// Specifying a Viewport model
models: [],
Expand All @@ -65,7 +66,7 @@ define([
// When controller is created let's setup view event listeners
initialize: function() {
// This most important part when we will tell our controller what events should be handled

debugger;
var me = this;
this.addListeners({
'FileMenu': {
Expand Down Expand Up @@ -128,9 +129,10 @@ define([

// When our application is ready, lets get started
onLaunch: function() {
debugger;
// Create and render main view
this.viewport = this.createView('Viewport').render();

debugger;
this.api = new Asc.asc_docs_api({
'id-view' : 'editor_sdk',
'translate': this.getApplication().getController('Main').translationTable
Expand Down
7 changes: 5 additions & 2 deletions apps/documenteditor/main/app/view/Viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ define([
'common/main/lib/component/Layout'
], function (viewportTemplate, $, _, Backbone) {
'use strict';

// debugger;
console.log('---加载控制器view/Viewport.js')
DE.Views.Viewport = Backbone.View.extend({
el: '#viewport',

Expand All @@ -65,6 +66,7 @@ define([

// Render layout
render: function() {
debugger;
this.$el.html(this.template({}));

// Workaround Safari's scrolling problem
Expand All @@ -79,6 +81,7 @@ define([
}

var $container = $('#viewport-vbox-layout', this.$el);
//页面主体框架
this.vlayout = new Common.UI.VBoxLayout({
box: $container,
items: [{
Expand All @@ -100,7 +103,7 @@ define([
}
]
});

//编辑器主体框架
$container = $('#viewport-hbox-layout', this.$el);
var items = $container.find(' > .layout-item');
let iarray = [{ // left menu chat & comment
Expand Down
1 change: 1 addition & 0 deletions apps/documenteditor/main/app_dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ require([
,'common/main/lib/controller/Draw'
], function() {
window.compareVersions = true;
console.log('---5.应用启动:')
app.start();
});
}
Expand Down
Loading

0 comments on commit 3454761

Please sign in to comment.