DocApe.js
35.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
//*
// 文档模块
// */
import Loger from "../Loger";
import Ape from "./Ape";
import xdysdk from "libs/xdysdk";
import $ from "jquery";
import ClassDataProxy from "proxy/ClassDataProxy";
import DynamicPPT from './DynamicPPT';
import UIControlApe from './UIControlApe';
import ErrorApe from './ErrorApe';
let loger = Loger.getLoger('PC-DocApe');
const DOC_SHOW_FULL = 0;//完整显示
const DOC_SHOW_WIDTH = 1;//按宽度显示
const DOC_SHOW_HEIGHT = 2;//按高度显示
const PPT_WIDTH = 720;//动态ppt标准宽度
const PPT_HEIGHT = 540;//动态ppt标准高度
class DocApe extends Ape {
constructor() {
super();
this.showDocDefaultDelay = 0;
this._docShowType = DOC_SHOW_FULL;//文档显示模式
this.lastV=0;
this.lastH=0;
this.curV=0;
this.curH=0;
this._docList = {};//文档数据
this._currentDocId = 0;//当前显示文档id,0就是没有文档,只显示白板
this._currentPageNum = 1;//,默认页数是1
this._pageNum = 1;//,默认总页数是1
this.currentImagePath = "";//当前显示的图片地址
this.resizeDelay;//窗口大小变化延迟处理
this.dynamicPPT;
this.addEvent();
this.init();
}
init() {
//布局
this.dynamicPPT = new DynamicPPT();
$(window).on('resize', this.onWindowResize.bind(this));
$('.docBox').on('scroll', this._changeDocScroll.bind(this));//监听文档滚动
$(".docView").hide();
$(".docView").on('load', this._onLoadImage.bind(this));
$(".docView").on('error', this._onLoadImageError.bind(this));
//UI按钮点击事件
//$("#file").on("change", this._uploadFile.bind(this));//左侧栏的上传文档
$("#docFileBtn").on("change", this._uploadFile.bind(this));//文件列表中的上传文档
$("#docListOut").on("click", this._openDocListHandler.bind(this));//打开列表
//$(".docHeadline .iconfont").on("click", this._closeDocListHandler.bind(this));
$("#closeDocList").on("click", this._closeDocListHandler.bind(this));
//botTurn
$(".nextPage").on("click", this._nextHandler.bind(this));
$(".prevPage").on("click", this._prevHandler.bind(this));
$("#totalPageNum").text(this._pageNum);
$("#currentPageNum").text(this._currentPageNum);
//显示模式
$(".fitHeight").on("click", this._fitInHandler.bind(this));
$(".fitWidth").on("click", this._fitInHandler.bind(this));
$(".fitNormal").on("click", this._fitInHandler.bind(this));
//默认文档全部显示
$('.fitNormal').css("color", "#3498db");
//显示底部控制栏的按钮,默认都隐藏
$(".nextPage").hide();
$(".prevPage").hide();
this.hideFitGroup();
;
//默认隐藏页码显示
this._hidePageInfo();
this.onWindowResize();
UIControlApe.showBottomDocControlBar();
//特定页码
$('.turn').on('click', this._particularPage.bind(this));
let that = this;
$("#pageNo").on("keydown", function (e) {
let curKey = e.which;
if (curKey == 13) that._particularPage();
});
if (ClassDataProxy.userRole == ClassDataProxy.USER_HOST) {
$(document).keydown(function (e) {
if (e.keyCode == 37) {
that._prevHandler();
}
});
$(document).keydown(function (e) {
if (e.keyCode == 39) {
that._nextHandler();
}
});
}
$('.docBox')[0].ondragstart = function(){
return false;
}
}
addEvent() {
xdysdk.on("class_join_success", this._classJoinSuccessHandler.bind(this));
xdysdk.on("document_update", this._docUpdateHanlder.bind(this));//文档更新
xdysdk.on("document_delete", this._docDeleteHanlder.bind(this));//文档删除
}
_classJoinSuccessHandler(_data) {
if (_data.userRole == ClassDataProxy.USER_NOTMAL || ClassDataProxy.isRecordPlayBack) {
$("#docUploadOut").hide();
$("#file").hide();
$("#docListOut").hide();
$(".nextPage").hide();
$(".prevPage").hide();
this.hideFitGroup();
}
this.onWindowResize();
}
clear() {
loger.log("clear");
this._docList = {};//文档数据
this._currentDocId = 0;
this._currentPageNum = 1;
this._pageNum = 1;
this.currentImagePath = "";//清空记录的图片地址
ClassDataProxy.currentPageNum = this._currentPageNum;
ClassDataProxy.currentDocId = this._currentDocId;
this._hideDocView();
this.dynamicPPT.updataPPT(null);
}
stop() {
loger.log("stop");
this._docList = {};//文档数据
this._currentDocId = 0;
this._currentPageNum = 1;
this._pageNum = 1;
this.currentImagePath = "";//清空记录的图片地址
ClassDataProxy.currentPageNum = this._currentPageNum;
ClassDataProxy.currentDocId = this._currentDocId;
this._hideDocView();
this.dynamicPPT.updataPPT(null);
}
//舞台大小发生改变
onWindowResize() {
//loger.log("舞台大小发生改变");
clearTimeout(this.resizeDelay);
let _this = this;
this.resizeDelay = setTimeout(function () {
//loger.log("舞台大小发生改变->刷新文档显示");
clearTimeout(_this.resizeDelay);
_this._fitInDocView(_this._docShowType);
}, 400);
}
//文档区域的滚动条发生改变
_changeDocScroll(evt) {
clearTimeout(this.scrollCompleteTimer);
//如果自己是老师,需要同步自己的滚动条位置给其他人,否则不做处理
if (ClassDataProxy.userRole != ClassDataProxy.USER_HOST) {
return;
}
this.scrollCompleteTimer = setTimeout(() => {
this._updateCurrentDocScroll();
}, 400);
}
//更新当前文档的滚动条位置-老师控制-发送
_updateCurrentDocScroll() {
if (ClassDataProxy.userRole != ClassDataProxy.USER_HOST) {
return;
}
let maxScrollH = $(".docBox").prop("scrollWidth") - $(".docBox").width();
let maxScrollV = $(".docBox").prop("scrollHeight") - $(".docBox").height();
let _curV =parseInt( $(".docBox").scrollTop());
let _curH = parseInt($(".docBox").scrollLeft());
this.curV = parseInt(_curV / maxScrollV * 1000)||0;
this.curH = parseInt(_curH / maxScrollH * 1000)||0;
//loger.warn("lastV:"+this.lastV+" curV:"+this.curV+" lastH:"+this.lastH+" curH:"+this.curH);
if(Math.abs(this.curH-this.lastH)<20&&Math.abs(this.curV-this.lastV)<20){
//loger.warn("不需要同步滚动条位置");
this.lastV=this.curV;
this.lastH=this.curH;
return;
}
this.lastV=this.curV;
this.lastH=this.curH;
if (this._currentDocId > 0) {
this._sendDocumentCommand2sdk();
}
}
//更新当前文档的滚动条位置-收取
_setCurrentDocScroll(_data) {
if (ClassDataProxy.userRole == ClassDataProxy.USER_HOST) {
return;
}
this.curV = parseInt(_data.curV);
this.curH = parseInt(_data.curH);
let maxScrollH = $(".docBox").prop("scrollWidth") - $(".docBox").width();
let maxScrollV = $(".docBox").prop("scrollHeight") - $(".docBox").height();
let leftS = parseInt(this.curV * maxScrollV * 0.001);
let topS = parseInt(this.curH * maxScrollH * 0.001);
$(".docBox").scrollTop(leftS);
$(".docBox").scrollLeft(topS);
// loger.log("更新当前文档的滚动条位置",maxScrollH,maxScrollV,leftS,topS,_data);
}
//监听文档更新消息
_docUpdateHanlder(_data) {
//loger.log("文档模块收到SDK数据");
if (_data == null) {
return;
}
this._setCurrentDocScroll(_data);
//更新文档视图区域
if (_data.visible == true) {
clearTimeout(this.showDocDefaultDelay);
this._currentDocId = _data.itemIdx;
this._currentPageNum = _data.curPageNo;
this._pageNum = _data.pageNum;
//记录文档的显示模式
//如果是录制回放模式,固定使用全部显示的模式
if (ClassDataProxy.isRecordPlayBack) {
this._docShowType = DOC_SHOW_FULL;
} else {
this._docShowType = _data.showType || DOC_SHOW_FULL;
}
this._changeDocShowBtns(this._docShowType);
ClassDataProxy.currentPageNum = this._currentPageNum;
ClassDataProxy.currentDocId = this._currentDocId;
if (this._pageNum <= 1) {
this._hidePageInfo();
} else {
this._showPageInfo();
}
this._showDocView(_data);
}
//操作数据
this._updateDocListData(_data, "add");
}
//监听文档删除消息
_docDeleteHanlder(_data) {
loger.log("_docDeleteHanlder", _data);
this._updateDocListData(_data, "delete");
}
//更新文档数据(包括更新和删除)
_updateDocListData(_data, _type) {
if (_type == "add" && _data) {
//loger.log("添加文件数据", _data);
this._docList[_data.itemIdx] = _data;
} else {
loger.log("删除文档数据", _data.itemIdx);
delete this._docList[_data.itemIdx];
if (this._currentDocId == _data.itemIdx) {
this._currentDocId = 0;
this._currentPageNum = 1;
this._pageNum = 1;
ClassDataProxy.currentPageNum = this._currentPageNum;
ClassDataProxy.currentDocId = this._currentDocId;
//当前显示的文档数据被清除,文档图片也要删除
this._hideDocView();
//如果是动态ppt,也需要删除
if (this.dynamicPPT.pptData && this.dynamicPPT.pptData.itemIdx == _data.itemIdx) {
this.dynamicPPT.updataPPT(null);
}
this._docShowType = DOC_SHOW_FULL;//文档显示模式
//标注的区域也需要设置
$(".docView").width("0");
$(".docView").height("0");
let docBoxWidh = $(".docBox")[0].clientWidth;
let docBoxHeight = $(".docBox")[0].clientHeight;
$(".docGroup").width(docBoxWidh);
$(".docGroup").height(docBoxHeight);
$(".docGroup").css("left", "0px");
$(".docGroup").css("top", "0px");
this._hidePageInfo();
this.hideFitGroup();
this._hideOverflow();
this._emit(DocApe.DOC_IMAGE_LOAD, {"width": docBoxWidh, "height": docBoxHeight});
this.onWindowResize();
}
}
//更新文件列表(列表数据更新的时候需要刷新)
this._updateDocListView();
//根据总页数显示翻页按钮
if (this._currentDocId > 0 && this._pageNum > 1 && ClassDataProxy.userRole == ClassDataProxy.USER_HOST) {
$(".nextPage").show();
$(".prevPage").show();
} else {
$(".nextPage").hide();
$(".prevPage").hide();
}
//显示当前页和总页数
$("#totalPageNum").text(this._pageNum);
$("#currentPageNum").text(this._currentPageNum);
}
//更新底部控制栏
_updateFitGroup() {
if (this._currentDocId == 0 || this._pageNum < 1 || ClassDataProxy.userRole == ClassDataProxy.USER_NOTMAL || ClassDataProxy.userRole == ClassDataProxy.USER_INVISIBLE) {
this.hideFitGroup();
} else if (this._currentDocId > 0 && ClassDataProxy.userRole == ClassDataProxy.USER_HOST) {
this.showFitGroup();
}
}
hideFitGroup() {
$(".fitHeight").hide();
$(".fitWidth").hide();
$(".fitNormal").hide();
$(".turn").hide();
$(".pageNo").hide();
}
showFitGroup() {
$(".fitHeight").show();
$(".fitWidth").show();
$(".fitNormal").show();
}
//更新文件列表显示
_updateDocListView() {
$("#docFileContent").empty();
console.log("this._docList", this._docList);
for (let i in this._docList) {
if (this._docList[i].docId) {
let listItem = this._creatListItemDiv(i, this._docList[i].fileName, this._docList[i].itemIdx);
$("#docFileContent").append(listItem);
}
}
}
//隐藏滚动条
_hideOverflow() {
$(".docBox")[0].style.overflow = "";
}
//显示滚动条 _type(显示的滚动条方向)
_showOverflow(_type) {
this._hideOverflow();
if (_type && _type == "y") {
$(".docBox")[0].style.overflowY = "scroll";
$(".docBox")[0].style.overflowX = "hidden";
} else {
$(".docBox")[0].style.overflowX = "scroll";
$(".docBox")[0].style.overflowY = "hidden";
}
}
//隐藏页码信息
_hidePageInfo() {
$(".total-page").hide();
$(".cur-page").hide();
$(".bias").hide();
$(".pageNo").hide();
$(".turn").hide();
}
//显示页码信息
_showPageInfo() {
$(".total-page").show();
$(".cur-page").show();
$(".bias").show();
$(".pageNo").show();
$(".turn").show();
}
//显示文档
_showDocView(_data) {
if (_data.fileType == "zip") {
this.dynamicPPT.updataPPT(_data);
this._hideDocView();
this.onWindowResize();
this.hideFitGroup();
//老师的需要显示翻页
if (ClassDataProxy.userRole == ClassDataProxy.USER_HOST) {
$(".turn").show();
$(".pageNo").show();
}
} else {
this.dynamicPPT.updataPPT(null);
this.currentImagePath = "";//清空记录的图片地址
this._hideDocView();
this._updateFitGroup();
let imgArr = _data.images || [];
if (imgArr && imgArr.length > 0) {
let img = imgArr[this._currentPageNum - 1];
if (img) {
//console.warn("currentImagePath:"+this.currentImagePath,"newImg:"+img);
this.currentImagePath = img;
$(".docView").attr('src', img);
if (_data.curPageNo > 0 && _data.curPageNo < _data.pageNum - 1) {
if (_data.curPageNo >= 3) {
let _arr = [_data.images[_data.curPageNo - 3], _data.images[_data.curPageNo - 2], _data.images[_data.curPageNo], _data.images[_data.curPageNo + 1]];
this._preloadimages(_arr);
} else if (_data.curPageNo < 3&&_data.curPageNo>=1) {
let _arr = [_data.images[_data.curPageNo-1],_data.images[_data.curPageNo]];
this._preloadimages(_arr);
}
}
else if(_data.curPageNo > 0 &&_data.pageNum<=3){
let _arr = _data.images;
this._preloadimages(_arr);
}
$(".docView").attr('alt', _data.fileName || "");
$(".docView").show();
}
}
}
}
_preloadimages(arr) {
var newimages = [];
var arr = (typeof arr != "object") ? [arr] : arr //确保参数总是数组
for (var i = 0; i < arr.length; i++) {
newimages[i] = new Image();
newimages[i].src = arr[i];
if (newimages[i].complete || newimages[i].width) {
loger.log('该图片已经存在于缓存之中,不会再去重新下载');
}
else {
loger.log('图片不存在缓存之中');
newimages[i].onload = function () {
loger.log('图片下载成功!');
}
}
}
}
//隐藏文档
_hideDocView(_data) {
//清除原来的设置,先获取实际大小
$(".docView").removeAttr("width");
$(".docView").removeAttr("height");
$(".docView").attr('src', "");
$(".docView").width("0");
$(".docView").height("0");
$(".docView").hide();
this.currentImagePath="";
this._hideOverflow();
if (this._pageNum <= 1) {
this._hidePageInfo();
} else {
this._showPageInfo();
}
}
//显示文档列表
_openDocListHandler() {
this._emit(DocApe.SCENE_DOC_CHANGE, ClassDataProxy.SCENE_DOC);
UIControlApe.enabledBottomBar();
UIControlApe.enabledLeftBar();
UIControlApe.showBottomDocControlBar();
$("#docModalList").show();
$(".masker").show();
}
//关闭文档列表
_closeDocListHandler() {
$("#docModalList").hide();
$(".masker").hide();
}
//下一页
_nextHandler() {
loger.log('下一页', this.dynamicPPT.isNextAnimationComplete());
if (this.dynamicPPT && !this.dynamicPPT.isNextAnimationComplete()) {
//如果动态ppt的动画没有播放完成,需要切换动画
this.dynamicPPT.pptNextAnimationHandler();
} else {
//切换页面
if (this._currentDocId > 0 && this._currentPageNum < this._pageNum) {
let paramInfo = {
"itemIdx": this._currentDocId,
"curPageNo": this._currentPageNum + 1
};
xdysdk.api("sendDocumentSwitchPage", paramInfo);
}
}
}
//上一页
_prevHandler() {
loger.log('上一页', this.dynamicPPT.isPrevAnimationComplete());
if (this.dynamicPPT && !this.dynamicPPT.isPrevAnimationComplete()) {
//如果动态ppt的动画没有播放完成,需要切换动画
this.dynamicPPT.pptPrevAnimationHandler();
} else {
//切换页面
if (this._currentDocId > 0 && this._currentPageNum > 1) {
let paramInfo = {
"itemIdx": this._currentDocId,
"curPageNo": this._currentPageNum - 1
};
xdysdk.api("sendDocumentSwitchPage", paramInfo);
}
}
}
//显示默认模式
stopAndHide() {
this._closeDocListHandler();
if (this._docShowType == DOC_SHOW_FULL) {
return;
}
this._docShowType = DOC_SHOW_FULL;
this._changeDocShowBtns(this._docShowType);
this._fitInDocView(this._docShowType);
if (this._currentDocId > 0) {
this._sendDocumentCommand2sdk();
}
}
//切换文档显示模式
_fitInHandler(evt) {
//loger.log("切换文档显示模式", evt.target.className);
switch (evt.target.id) {
case "fitWidth":
if (this._docShowType == DOC_SHOW_WIDTH) {
return;
}
this._docShowType = DOC_SHOW_WIDTH;
this._changeDocShowBtns(this._docShowType);
break;
case "fitHeight":
if (this._docShowType == DOC_SHOW_HEIGHT) {
return;
}
this._docShowType = DOC_SHOW_HEIGHT;
this._changeDocShowBtns(this._docShowType);
break;
case "fitNormal":
if (this._docShowType == DOC_SHOW_FULL) {
return;
}
this._docShowType = DOC_SHOW_FULL;
this._changeDocShowBtns(this._docShowType);
break;
default:
break;
}
this._fitInDocView(this._docShowType);
if (this._currentDocId > 0) {
this._sendDocumentCommand2sdk();
}
}
//发送文档控制消息
_sendDocumentCommand2sdk() {
xdysdk.api("sendDocumentCommand", {
"itemIdx": this._currentDocId,
"showType": this._docShowType,
"curV": this.curV,//垂直方向的滚动条进度百分比 0-100
"curH": this.curH,//水平方向的滚动条进度百分比 0-100
"scale": 100//文档缩放百分比 0-100
});
}
_changeDocShowBtns(_showType) {
switch (_showType) {
case DOC_SHOW_WIDTH:
$('.fitWidth').css("color", "#3498db");
$('.fitHeight').css("color", "#ccc");
$('.fitNormal').css("color", "#ccc");
break;
case DOC_SHOW_HEIGHT:
$('.fitHeight').css("color", "#3498db");
$('.fitWidth').css("color", "#ccc");
$('.fitNormal').css("color", "#ccc");
break;
default :
$('.fitNormal').css("color", "#3498db");
$('.fitHeight').css("color", "#ccc");
$('.fitWidth').css("color", "#ccc");
break;
}
}
//适配文档显示,type是显示的类型(width-按宽度显示;height-按高度显示;full-完整显示)
_fitInDocView(_type) {
let docView = $(".docView")[0];
//let imgUrl=docView.src;
//let imgUrl="";
//loger.log("切换文档显示模式->", _type, this.currentImagePath);
if (docView && this.currentImagePath) {
$(".docView").attr('src', this.currentImagePath);
$(".docView").show();
} else {
let docBoxWidh = $(".docBox")[0].clientWidth;
let docBoxHeight = $(".docBox")[0].clientHeight;
//没有文档的时候,就按动态ppt的标注尺寸为准
let viewW = PPT_WIDTH;
let viewH = PPT_HEIGHT;
//loger.log("舞台尺寸->", docBoxWidh, docBoxHeight);
//设置适合的尺寸模型显示
let sizeObj;
if (this._docShowType == DOC_SHOW_WIDTH) {
sizeObj = ClassDataProxy.getFitInWidth(docBoxWidh, docBoxHeight, viewW, viewH);
this._showOverflow("y");
} else if (this._docShowType == DOC_SHOW_HEIGHT) {
sizeObj = ClassDataProxy.getFitInHeight(docBoxWidh, docBoxHeight, viewW, viewH);
this._showOverflow("x");
} else {
sizeObj = ClassDataProxy.getFitInFull(docBoxWidh, docBoxHeight, viewW, viewH);
this._hideOverflow();
}
if (sizeObj) {
//loger.log("设置图片显示", sizeObj);
let docView = $(".docView");
docView.width(sizeObj.w);
docView.height(sizeObj.h);
$(".docGroup").width(sizeObj.w);
$(".docGroup").height(sizeObj.h);
$(".docGroup").css("left", "0");
$(".docGroup").css("top", "0");
//水平居中显示
if (sizeObj.w < docBoxWidh) {
let leftMargin = (docBoxWidh - sizeObj.w) * 0.5;
$(".docGroup").css("left", "" + leftMargin + "px");
}
//垂直居中
if (sizeObj.h < docBoxHeight) {
let topMargin = (docBoxHeight - sizeObj.h) * 0.5;
$(".docGroup").css("top", "" + topMargin + "px");
}
this._emit(DocApe.DOC_IMAGE_LOAD, {"width": sizeObj.w, "height": sizeObj.h});
this.dynamicPPT.setPPTSize({"width": sizeObj.w, "height": sizeObj.h});
} else {
loger.warn("文档适配失败");
}
}
}
//文档图片加载完成
_onLoadImage(evt) {
let imagW = evt.currentTarget.naturalWidth;
let imagH = evt.currentTarget.naturalHeight;
let docBoxWidh = $(".docBox")[0].clientWidth;
let docBoxHeight = $(".docBox")[0].clientHeight;
//loger.log("加载图片完成->实际尺寸->", imagW, imagH);
//loger.log("舞台尺寸->", docBoxWidh, docBoxHeight);
//设置适合的尺寸模型显示
let sizeObj;
if (this._docShowType == DOC_SHOW_WIDTH) {
sizeObj = ClassDataProxy.getFitInWidth(docBoxWidh, docBoxHeight, imagW, imagH);
this._showOverflow("y");
} else if (this._docShowType == DOC_SHOW_HEIGHT) {
sizeObj = ClassDataProxy.getFitInHeight(docBoxWidh, docBoxHeight, imagW, imagH);
this._showOverflow("x");
} else {
sizeObj = ClassDataProxy.getFitInFull(docBoxWidh, docBoxHeight, imagW, imagH);
this._hideOverflow();
}
if (sizeObj) {
// loger.log("设置图片显示", sizeObj);
let docView = $(".docView");
docView.width(sizeObj.w);
docView.height(sizeObj.h);
$(".docGroup").width(sizeObj.w);
$(".docGroup").height(sizeObj.h);
$(".docGroup").css("left", "0");
$(".docGroup").css("top", "0");
//水平居中显示
if (sizeObj.w < docBoxWidh) {
let leftMargin = (docBoxWidh - sizeObj.w) * 0.5;
//loger.warn("left-----------------",leftMargin);
$(".docGroup").css("left", "" + leftMargin + "px");
}
//垂直居中
if (sizeObj.h < docBoxHeight) {
let topMargin = (docBoxHeight - sizeObj.h) * 0.5;
$(".docGroup").css("top", "" + topMargin + "px");
}
this._emit(DocApe.DOC_IMAGE_LOAD, {"width": sizeObj.w, "height": sizeObj.h});
this.dynamicPPT.setPPTSize({"width": sizeObj.w, "height": sizeObj.h});
} else {
loger.warn("文档适配失败");
}
}
//文档图片加载失败
_onLoadImageError(evt) {
if (!ClassDataProxy.isRecordPlayBack && this.currentImagePath) {
loger.warn("文档加载失败->", evt.currentTarget.alt, this.currentImagePath);
//ErrorApe.showError(ErrorApe.TYPE_3, ClassDataProxy.localConfig.fileLoadingErr + "->" + evt.currentTarget.alt);
}
}
//上传文件
_uploadFile(evt) {
let fileItem = document.getElementById('docFileBtn').files[0];
if (!fileItem) {
loger.log("没有选择文件");
return;
}
this._closeDocListHandler();
let fileStr = fileItem.name;
if(fileStr){
fileStr=fileStr.toLowerCase();
}
//let fileValue = fileStr.split('.')[1];
if (fileStr.lastIndexOf(".zip")>=0) {
this._uploadPPT(fileItem, evt);
}
else {
loger.log("文件名:" + fileItem.name + "->文件类型:" + fileItem.type);
//目前最大支持50M 格式为jpg png pdf docx pptx xlsx
//判断文件的大小
if (fileItem.size > 52428800) {
ErrorApe.showError(ErrorApe.TYPE_3, ClassDataProxy.localConfig.fileError);
return;
}
let fileName = fileItem.name;
if(fileName){
fileName = fileName.toLowerCase();
}
//判断选择的文件类型
if (fileName.lastIndexOf('.jpg') < 0 &&
fileName.lastIndexOf('.png') < 0 &&
fileName.lastIndexOf('.pdf') < 0 &&
fileName.lastIndexOf('.doc') < 0 &&
fileName.lastIndexOf('.ppt') < 0 &&
fileName.lastIndexOf('.xls') < 0) {
ErrorApe.showError(ErrorApe.TYPE_3, ClassDataProxy.localConfig.layoutCont);
return;
}
if (!ClassDataProxy.DOCServerIP) {
loger.warn("文档服务器地址无效,无法上传文件!");
ErrorApe.showError(ErrorApe.TYPE_3, ClassDataProxy.localConfig.serverError);
return
}
//上传时动画效果
UIControlApe.showLoadingMask();
//上传过程中 上传按钮不可点击
//$('.docUploadForbid').show();
UIControlApe.disEnabledDocBar();
UIControlApe.disEnabledMediaBar();
let fd = new FormData();
fd.append("fileToUpload", fileItem);
fd.append("siteID", ClassDataProxy.siteId); //站点
fd.append("convertTools", "msoffice"); //pptflash 仅限动态转ppt msoffice 其它类型
fd.append("meetingid", String(ClassDataProxy.classId)); //课堂号
fd.append("timestamp", String(ClassDataProxy.creatTimestamp())); //时间戳
fd.append("createUserName", String(ClassDataProxy.userName)); //上传人姓名
fd.append("createUserID", String(ClassDataProxy.nodeId)); //上传人ID
fd.append("modifyDate", ClassDataProxy.creatTimestampStr()); //上传时间
/*let ipport = ClassDataProxy.DOCServerIP;
if (ClassDataProxy.DOCServerPort) {
ipport = ipport + ":" + ClassDataProxy.DOCServerPort;
}
let docUrl = `http://${ipport}/DocSharing/fileUploadJson`;*/
let ipport=ClassDataProxy.DOCServerIP;
if( ClassDataProxy.DOCServerPort){
ipport=ipport+":"+ClassDataProxy.DOCServerPort;
}
let docUrl= `${ClassDataProxy.locationProtocol+ipport}/DocSharing/fileUploadJson`;
$.ajax({
type: "POST",
url: docUrl,
processData: false,
contentType: false,
data: fd,
xhr: function () {
let xhr = $.ajaxSettings.xhr();
if (xhr.upload) {
xhr.upload.addEventListener("progress", function (evt) {
let loaded = evt.loaded; //已经上传大小情况
let tot = evt.total; //附件总大小
let per = Math.floor(100 * loaded / tot); //已经上传的百分比
UIControlApe.updataLoadingMaskProgress(per);
}, false);
return xhr;
}
},
success: function (data) {
//loger.log("文档服务器返回的文档数据-.", data);
UIControlApe.hideLoadingMask();
UIControlApe.enabledDocBar();
UIControlApe.enabledMediaBar();
this._uploadFileSuccess(data);
$("#docFileBtn").val('')
}.bind(this),
error: function (data) {
UIControlApe.hideLoadingMask();
UIControlApe.enabledDocBar();
UIControlApe.enabledMediaBar();
loger.warn(name + "->上传文件失败", data);
ErrorApe.showError(ErrorApe.TYPE_3, name + "->" + ClassDataProxy.localConfig.uploaDocumentErr);
$("#docFileBtn").val('')
}
});
}
}
//上传ppt的zip
_uploadPPT(fileItem, evt) {
loger.log("文件名:" + fileItem.name + "->文件类型:" + fileItem.type);
//目前最大支持50M 格式为jpg png pdf docx pptx xlsx
//判断文件的大小
if (fileItem.size > 52428800) {
ErrorApe.showError(ErrorApe.TYPE_3, ClassDataProxy.localConfig.fileError);
return;
}
let fileName = fileItem.name.toLowerCase();
//判断选择的文件类型
if (fileName.lastIndexOf('.zip') < 0) {
ErrorApe.showError(ErrorApe.TYPE_3, ClassDataProxy.localConfig.fileFormatError);
return;
}
if (!ClassDataProxy.DOCServerIP) {
loger.warn("文档服务器地址无效,无法上传文件!");
ErrorApe.showError(ErrorApe.TYPE_3, ClassDataProxy.localConfig.serverError);
return
}
//上传时动画效果
UIControlApe.showLoadingMask();
UIControlApe.disEnabledDocBar();
UIControlApe.disEnabledMediaBar();
//上传过程中 上传按钮不可点击
//$('.docUploadForbid').show();
let fd = new FormData();
fd.append("fileToUpload", fileItem);
fd.append("classId", String(ClassDataProxy.classId)); //课堂号
fd.append("siteID", ClassDataProxy.siteId); //站点
fd.append("createUserID", String(ClassDataProxy.nodeId)); //上传人ID
fd.append("createUserName", String(ClassDataProxy.userName)); //上传人姓名
/* let ipport = ClassDataProxy.DOCServerIP;
if (ClassDataProxy.DOCServerPort) {
ipport = ipport + ":" + ClassDataProxy.DOCServerPort;
}
let pptUrl = `http://${ipport}/DocSharing/zipUpload`;*/
let ipport=ClassDataProxy.DOCServerIP;
if( ClassDataProxy.DOCServerPort){
ipport=ipport+":"+ClassDataProxy.DOCServerPort;
}
let pptUrl= `${ClassDataProxy.locationProtocol+ipport}/DocSharing/zipUpload`;
$.ajax({
type: "POST",
url: pptUrl,
processData: false,
contentType: false,
data: fd,
xhr: function () {
let xhr = $.ajaxSettings.xhr();
if (xhr.upload) {
xhr.upload.addEventListener("progress", function (evt) {
let loaded = evt.loaded; //已经上传大小情况
let tot = evt.total; //附件总大小
let per = Math.floor(100 * loaded / tot); //已经上传的百分比
UIControlApe.updataLoadingMaskProgress(per);
}, false);
return xhr;
}
},
success: function (data) {
//loger.log("文档服务器返回的文档数据-.", data);
UIControlApe.hideLoadingMask();
UIControlApe.enabledDocBar();
UIControlApe.enabledMediaBar();
this._uploadpptSuccess(data);
$("#docFileBtn").val('')
}.bind(this),
error: function (data) {
UIControlApe.hideLoadingMask();
UIControlApe.enabledDocBar();
UIControlApe.enabledMediaBar();
loger.warn(name + "->上传文件失败", data);
ErrorApe.showError(ErrorApe.TYPE_3, name + "" + ClassDataProxy.localConfig.uploaDocumentErr);
$("#docFileBtn").val('')
}
});
}
//上传的ppt的zip成功
_uploadpptSuccess(msg) {
loger.log("服务器返回的zip信息->", msg);
if (msg.docId) {
console.log("msg", msg);
$("#frame").attr("src", msg.filePath);
let fileInfo = {};
fileInfo.pageNum = msg.imgSize;// 文档的总页数
fileInfo.fileName = msg.fileName;//文档名字
fileInfo.fileType = msg.fileType; // 文档的原始类型(上传时的类型)
fileInfo.relativeUrl = msg.relativeLocation; //文档相对地址
let urlPath = msg.filePath + 'l';
urlPath = urlPath.replace('.htmll', '.html');
fileInfo.url = urlPath; //文档绝对地址 默认值: null
fileInfo.docId = msg.docId; //文档在数据库中的唯一id标识 默认值: null
fileInfo.visible = false; // 是否显示 默认值: false
loger.log("同步上传的文档消息给sdk", fileInfo);
xdysdk.api("sendDocumentUpload", fileInfo);
} else {
loger.warn("服务器返回的zip文件信息->不能同步-->docId无效", msg.docId);
ErrorApe.showError(ErrorApe.TYPE_3, name + "" + ClassDataProxy.localConfig.uploaDocumentErr);
}
}
//将上传文件的信息,传递给底层
_uploadFileSuccess(msg) {
loger.log("服务器返回的文档信息->", msg);
if (msg.docId && msg.flag == 0) {
let fileInfo = {};
fileInfo.pageNum = msg.imgSize;// 文档的总页数
fileInfo.fileName = msg.fileName;//文档名字
fileInfo.fileType = msg.fileType; // 文档的原始类型(上传时的类型)
fileInfo.relativeUrl = msg.relativeLocation; //文档相对地址
fileInfo.url = msg.filePath; //文档绝对地址 默认值: null
fileInfo.docId = msg.docId; //文档在数据库中的唯一id标识 默认值: null
fileInfo.visible = false; // 是否显示 默认值: false
fileInfo.dynamicTS = msg.dynamicTransferStatic; //是否动态转换 //文档上传后返回值中的字段dynamicTransferStatic 默认值: 0
//loger.log("同步上传的文档消息给sdk", fileInfo);
xdysdk.api("sendDocumentUpload", fileInfo);
} else {
loger.warn("服务器返回的文件信息->不能同步-->docId无效", msg.docId);
ErrorApe.showError(ErrorApe.TYPE_3, ClassDataProxy.localConfig.uploaDocumentErr);
}
}
//点击列表中切换文档
_switchDcoBtnHandler(evt) {
loger.log("_switchDcoBtnHandler---->", evt.target.id);
this._switchDcoHandler(evt.target.id)
}
//切换文档,把要显示的文档数据发送给SDK
_switchDcoHandler(_itemIdx) {
loger.log("_switchDcoHandler---->", _itemIdx);
let docItem = this._docList[_itemIdx];
if (docItem) {
let paramInfo = {
"itemIdx": parseInt(_itemIdx),
"visible": true
};
xdysdk.api("sendDocumentSwitchDoc", paramInfo);
this._closeDocListHandler();
} else {
loger.log("_switchDcoHandler---->文档不存在");
}
}
//删除文档鼠标事件
_deleteDcoHandler(evt) {
loger.log("_deleteDcoHandler---->", evt.target.id);
let docItem = this._docList[parseInt(evt.target.id)];
if (docItem) {
let paramInfo = {
"itemIdx": docItem.itemIdx,
"docId": docItem.docId,
"classId": ClassDataProxy.classId //课堂号
};
xdysdk.api("sendDocumentDelete", paramInfo);
} else {
loger.log("_deleteDcoHandler---->文档不存在");
}
}
//获取文档图片序列
_getDocFullAddress(_data) {
loger.log("获取文档显示地址---->", _data);
let paramInfo = {
"itemIdx": _data.itemIdx,
"url": _data.url
};
let result = xdysdk.api("getDocFullAddress", paramInfo);
loger.log("获取文档显示地址-->返回->", result);
if (result.code == 0) {
return result.docFullAddress.images;
}
return [];
}
_particularPage() {
let pageNo = $('#pageNo');
if (!pageNo || !pageNo.val()) {
return;
}
let page = parseInt(pageNo.val());
if (page) {
if (page > this._pageNum) {
page = this._pageNum;
}
if (page <= 0) {
page = 1;
}
pageNo.val(page);
let paramInfo = {
"itemIdx": this._currentDocId,
"curPageNo": page
};
xdysdk.api("sendDocumentSwitchPage", paramInfo);
$("#pageNo")[0].value = "";
$("#pageNo").blur();
}
}
//创建列表元素
_creatListItemDiv(_id, _fileName, _owner) {
let div = document.createElement("div");
div.id = "doc_" + _id;
//文件id
let ico = document.createElement("label");
ico.innerHTML = "";
ico.className = "iconfont";
div.appendChild(ico);
//文件名称
let nameDiv = document.createElement("label");
nameDiv.innerText = "" + _fileName;
nameDiv.title = "" + _fileName;
nameDiv.onclick = this._switchDcoBtnHandler.bind(this);
nameDiv.id = _id;
div.appendChild(nameDiv);
//删除按钮
let deleteBtn = document.createElement("label");
deleteBtn.type = "button";
// deleteBtn.value = "删除";
deleteBtn.id = _id;
deleteBtn.innerHTML = "";
deleteBtn.className = "iconfont";
deleteBtn.onclick = this._deleteDcoHandler.bind(this);
div.appendChild(deleteBtn);
return div;
}
}
DocApe.prototype.DOC_IMAGE_LOAD = DocApe.DOC_IMAGE_LOAD = "doc_image_load";
DocApe.prototype.SCENE_DOC_CHANGE = DocApe.SCENE_DOC_CHANGE = "scene_doc_change";
export default DocApe;