DrawTool.js
9.4 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
//*
// 白板标注工具栏
// */
import Emiter from "Emiter";
import Loger from "Loger";
import $ from "jquery";
import xdysdk from "libs/xdysdk";
import ClassDataProxy from "proxy/ClassDataProxy";
let loger = Loger.getLoger('PC-DrawTool');
class DrawTool extends Emiter {
constructor() {
super();
this.isShow = false;
ClassDataProxy.isDraw = false;
this.addEvent();
this.init();
}
init() {
//布局
$(".foldDrawTool").on("click", this._controlDrawToolVisible.bind(this));
//UI按钮点击事件
$(".toolColor").on("mouseleave", this._showColorNone.bind(this));
// $(".showColor").on("mouseleave", this._showColorNone.bind(this));
$(".showColor").on("mouseenter", this._showColorBlock.bind(this));
//形状列表显示
$(".toolForm").on("mouseleave", this._showFormNone.bind(this));
$("#showForm").on("mouseenter", this._showFormBlock.bind(this));
//点击形状按钮
$('#showForm').on('click',this._showFormBlock.bind(this));
$('#curveBrush').on('click',this._formHandler.bind(this));
$('#straightBrush').on('click',this._formHandler.bind(this));
$('#squareBrush').on('click',this._formHandler.bind(this));
$('#circleBrush').on('click',this._formHandler.bind(this));
$('#customBrush').on('click',this._formHandler.bind(this));
$(".showColor").on("click", this._showColorBlock.bind(this));
$(".redColor").on("click", this._colorHandler.bind(this));
$(".blueColor").on("click", this._colorHandler.bind(this));
$(".purpleColor").on("click", this._colorHandler.bind(this));
$(".yellowColor").on("click", this._colorHandler.bind(this));
$(".pencil").on("click", this._pencilHandler.bind(this));
$(".rescind").on("click", this._rescindHandler.bind(this));//撤销
$(".clearContent").on("click", this._clearHandler.bind(this));//删除
//点击其他区域后颜色板隐藏
// $(".middle").on("click",this._hideColorTool.bind(this));
$(".left").on("click",this._hideColorTool.bind(this));
$(".header").on("click",this._hideColorTool.bind(this));
$(".right").on("click",this._hideColorTool.bind(this));
$(".docBox").on("click",this._hideColorTool.bind(this));
//老是断控制学生端画笔
$('#controlBrush').on('click',this._controlBrushHandler.bind(this));
}
addEvent() {
xdysdk.on("class_join_success", this._classJoinSuccessHandler.bind(this));
xdysdk.on("class_insert_roster", this._insertRosterHandler.bind(this)); //人员进入
xdysdk.on("class_update_status", this._classUpdateHandler.bind(this));//会议状态更新
}
_classJoinSuccessHandler(_data) {
if (_data.userRole == ClassDataProxy.USER_NOTMAL) {
// $(".foldDrawTool").hide();
// $(".drawTool").hide();
this.isShow = true;
} else {
$(".foldDrawTool").show();
$(".drawTool").show();
this.isShow = true;
}
}
_insertRosterHandler(_data){
if(_data){
if(ClassDataProxy.userRole == ClassDataProxy.USER_NOTMAL){
if(!ClassDataProxy.isEnableDraw){
//隐藏学生端画笔
this._hideBrushSwitch();
}
}
}
}
_classUpdateHandler(_data){
if(_data){
//控制学生端画笔是否可以绘画
ClassDataProxy.isEnableDraw = _data.isEnableDraw || false;
this._checkBrushSwitch();
}
}
_checkBrushSwitch(){
this._brushSwitchHandler();
}
//老是断控制学生端画笔
_controlBrushHandler(evt){
if(ClassDataProxy.isEnableDraw == true){
ClassDataProxy.isEnableDraw = false;
xdysdk.api("changeDrawStatus",{"isEnableDraw":false});
}else{
ClassDataProxy.isEnableDraw = true;
xdysdk.api("changeDrawStatus",{"isEnableDraw":true})
}
}
//学生端画笔开关
_brushSwitchHandler(){
if(ClassDataProxy.isEnableDraw == true){
if(ClassDataProxy.userRole == ClassDataProxy.USER_NOTMAL){
//显示学生端画笔
this._showBrushSwitch();
}
//更改老师端状态
if(ClassDataProxy.userRole == ClassDataProxy.USER_HOST){
$('.controlBrush').addClass('controlBrushClick');
}
}else{
//隐藏学生端画笔
if(ClassDataProxy.userRole == ClassDataProxy.USER_NOTMAL){
this._hideBrushSwitch();
//学生端是否可以画图
ClassDataProxy.isDraw = false;
}
//更改老师端状态
if(ClassDataProxy.userRole == ClassDataProxy.USER_HOST){
$('.controlBrush').removeClass('controlBrushClick');
}
}
}
//显示学生端画笔
_showBrushSwitch(){
$('.foldDrawToolOut').show();
$('.foldDrawTool').show();
$(".drawTool").show();
$(".drawTool").css("height", "160px");
}
//隐藏学生端画笔
_hideBrushSwitch(){
$('.foldDrawToolOut').hide();
$('.foldDrawTool').hide();
$(".drawTool").hide();
}
_pencilHandler() {
if(ClassDataProxy.isLaser==true){
ClassDataProxy.isLaser=false;
let paramInfo = {
"pointGroup": [],//有多个坐标点组成
"duration":0 //多长时间发一次数据
};
xdysdk.api("sendInsertCursor", paramInfo);
$(".canvasContent").css("cursor", "default");
}
$(".laserBoard").css("z-index","-1");
$(".toolColor").css("display", "none");
ClassDataProxy.isDraw = !ClassDataProxy.isDraw;
this._emit(DrawTool.DRAW_TOOL_CHANGE, {"action": "pencil", "isDraw": ClassDataProxy.isDraw});
if (ClassDataProxy.isDraw) {
$(".canvasContent").css({"cursor":"url(images/tool/penciling.png),crosshair"});
} else {
$(".canvasContent").css("cursor", "default");
}
}
_rescindHandler() {
$(".toolColor").css("display", "none");
this._emit(DrawTool.DRAW_TOOL_CHANGE, {"action": "rescind"});
}
_clearHandler() {
$(".toolColor").css("display", "none");
this._emit(DrawTool.DRAW_TOOL_CHANGE, {"action": "clear"});
}
_colorHandler(evt) {
$(".toolColor").css("display","none");
loger.log(evt.target.id, evt.target.title);
let color = evt.target.title;
this._emit(DrawTool.DRAW_TOOL_CHANGE, {"action": "changeColor", "color": color});
let showColor = document.getElementById('showColor');
switch (evt.target.id) {
case "redColor":
showColor.style.background = 'url("images/colorRed.png") no-repeat';
$(".showColor").unbind("click");
this._showColorNone();
this._showFormNone();
break;
case "blueColor":
showColor.style.background = 'url("images/colorBlue.png") no-repeat';
$(".showColor").unbind("click");
this._showColorNone();
this._showFormNone();
break;
case "purpleColor":
showColor.style.background = 'url("images/colorPurple.png") no-repeat';
$(".showColor").unbind("click");
this._showColorNone();
this._showFormNone();
break;
case "yellowColor":
showColor.style.background = 'url("images/colorYellow.png") no-repeat';
$(".showColor").unbind("click");
this._showColorNone();
this._showFormNone();
break;
default:
break
}
}
_formHandler(){
$(".toolForm").css("display","none");
$("#showForm").unbind("click");
loger.log('点击隐藏形状工具列表');
}
_showColorBlock() {
$(".toolColor").css("display", "block");
$(".toolColor").css("z-index", 0);
$(".toolForm").css("display", "none");
$(".toolForm").css("z-index", 0);
}
_showColorNone() {
$(".toolColor").css("display", "none");
$(".toolColor").css("z-index", 0);
}
_showFormBlock(){
$(".toolForm").css("display", "block");
$(".toolForm").css("z-index", 2);
$(".toolColor").css("display", "none");
$(".toolColor").css("z-index", 0);
}
_showFormNone(){
$(".toolForm").css("display", "none");
$(".toolForm").css("z-index", 0);
}
_controlDrawToolVisible() {
// if(ClassDataProxy.isEnableDraw == true){
if (this.isShow) {
$(".drawTool").hide();
$(".arrowTop").hide();
$(".arrowBottom").show();
} else {
$(".drawTool").show();
$(".arrowTop").show();
$(".arrowBottom").hide();
}
this.isShow = !this.isShow;
// }
}
_hideColorTool(){
$(".toolColor").css("display", "none");
$(".toolForm").css("display", "none");
}
}
DrawTool.prototype.DRAW_TOOL_CHANGE = DrawTool.DRAW_TOOL_CHANGE = "draw_tool_change";
export default DrawTool;