ExcelBasic.js 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550
  1. Namespace.register("U.MD.O.E.BC");
  2. /*excel 的 基础功能*/
  3. U.MD.O.E.BC.scroll = {};
  4. U.MD.O.E.BC.scroll.isScroll = false; //鼠标在不可以滚动的范围
  5. /*
  6. *判断是否可以滚动
  7. */
  8. U.MD.O.E.BC.scroll.canScroll = function () {
  9. var _rowBoard = $(".U_MD_O_E_rowBoard")[0], //左边div
  10. _cellBox = $(".U_MD_O_E_cellBox")[0]; //div区域
  11. var _mouseenter = function () {
  12. U.MD.O.E.BC.scroll.isScroll = true; //鼠标进入可以滚动的范围
  13. }
  14. var _mouseleave = function () {
  15. U.MD.O.E.BC.scroll.isScroll = false; //鼠标离开可以滚动的范围
  16. }
  17. $(_rowBoard).bind({//绑定鼠标移动事件
  18. mouseenter: _mouseenter,
  19. mouseleave: _mouseleave
  20. })
  21. $(_cellBox).bind({//绑定鼠标移动事件
  22. mouseenter: _mouseenter,
  23. mouseleave: _mouseleave
  24. })
  25. }
  26. U.MD.O.E.BC.headInputFocus = true; //文本框正在是否聚焦 (默认聚焦)
  27. U.MD.O.E.BC.editorFocus = false; //单元格编辑框是否聚焦
  28. /*
  29. * 上下滚轮总事件
  30. */
  31. U.MD.O.E.BC.scrollY = function () {
  32. U.MD.O.E.BC.scroll.canScroll(); //判断是否可以滚动
  33. U.MD.O.E.BC.scrollY.mousewheel(); //鼠标绑定滚动事件
  34. U.MD.O.E.BC.scrollY.tbDragChecked(); //滚轮选中上下拖拽事件
  35. U.MD.O.E.BC.scrollY.rlDragChecked(); //滚轮选中左右拖拽事件
  36. }
  37. /*
  38. * 滚轮选中左右拖拽事件
  39. */
  40. U.MD.O.E.BC.scrollY.rlDragChecked = function () {
  41. var _xBar = $(".U_MD_O_E_Xbar")[0], //滚动条
  42. _xBarRoll = $(".U_MD_O_E_XbarRoll")[0], //滚动条里面的滚动按钮
  43. _headInput = $(".U_MD_O_E_headInput")[0], //c6区域
  44. _colBoardBox = $(".U_MD_O_E_colBoardBox")[0], //顶部div
  45. _cellBox = $(".U_MD_O_E_cellBox")[0]; //div区域
  46. $(_xBarRoll).bind("mousedown", function (e) {
  47. U.UF.EV.stopBubble(e); //阻止冒泡
  48. console.log(_xBarRoll.offsetLeft);
  49. var _barRollX = _xBarRoll.offsetLeft,
  50. _oX = e.pageX, //选中时的X
  51. _newX;
  52. console.log(_oX);
  53. var _drapMove = function (e) {//拖拽时移动用的函数
  54. U.UF.EV.stopBubble(e); //阻止冒泡
  55. U.UF.EV.stopDefault(e); //取消默认拖拽
  56. _newX = e.pageX;
  57. var _left = Math.max(0, _newX - _oX + _barRollX); //滚动按钮的left值不能小于0
  58. _left = Math.min(_xBar.offsetWidth + 1, _left); //滚动按钮的left值不能大于滚动条的宽
  59. _xBarRoll.style.left = _left + "px";
  60. _NewRollleft = parseFloat(_xBarRoll.style.left); //拉拽后的left
  61. _xBar.style.width = _headInput.offsetWidth - 65 + "px"; //滚动条的长度随着页面百分比的变化而变化
  62. _double = ($(".U_MD_O_E_colBoardBox")[0].offsetWidth + 60 - document.body.clientWidth) / parseFloat(_xBar.style.width); //滚动占滚动条的百分比
  63. $(".U_MD_O_E_colBoardBox")[0].style.left = -_NewRollleft * _double + "px"; //顶部div的left值
  64. _cellBox.style.left = -_NewRollleft * _double + "px"; //div区域left值
  65. _Newleft = parseInt($(".U_MD_O_E_colBoardBox")[0].style.left);
  66. };
  67. var _dragUp = function () { //拖拽时松开用的函数
  68. $(document).unbind('mousemove', _drapMove);
  69. $(document).unbind('mouseup', _dragUp);
  70. };
  71. $(document).bind('mousemove', _drapMove);
  72. $(document).bind('mouseup', _dragUp);
  73. })
  74. }
  75. /*
  76. * 滚轮选中上下拖拽事件
  77. */
  78. U.MD.O.E.BC.scrollY.tbDragChecked = function () {
  79. var _Ybar = $(".U_MD_O_E_Ybar")[0], //滚动条
  80. _yBarRoll = $(".U_MD_O_E_YbarRoll")[0], //滚动条里面的滚动按钮
  81. _taskBar = $(".U_MD_O_E_taskBar")[0].offsetHeight, //互联办公模块
  82. _rowBoard = $(".U_MD_O_E_rowBoard")[0], //左边div
  83. _cellBox = $(".U_MD_O_E_cellBox")[0], //div区域
  84. _head_features = $(".U_MD_O_E_Editor_head_features")[0].offsetHeight;
  85. _NewRolltop = 0;
  86. $(_yBarRoll).bind("mousedown", function (e) {
  87. U.UF.EV.stopBubble(e); //阻止冒泡
  88. var _barRollY = _yBarRoll.offsetTop,
  89. _oY = e.pageY, //选中时的y
  90. _newY;
  91. var _drapMove = function (e) {//拖拽时移动用的函数
  92. U.UF.EV.stopBubble(e); //阻止冒泡wx`
  93. U.UF.EV.stopDefault(e); //取消默认拖拽
  94. _newY = e.pageY;
  95. var _top = Math.max(0, _newY - _oY + _barRollY), //滚动按钮的top值不能小于0
  96. _top = Math.min(_Ybar.offsetHeight + 1, _top); //滚动按钮的top值不能大于滚动条的高
  97. _yBarRoll.style.top = _top + "px";
  98. _NewRolltop = parseFloat(_yBarRoll.style.top); //拉拽后的top
  99. _visual = document.body.clientHeight - 36 - _head_features - _taskBar; //可视页面高度
  100. _Ybar.style.height = _visual - 40 + "px"; //滚动条的长度随着页面百分比的变化而变化
  101. _double = (_rowBoard.offsetHeight + 25 - _visual) / parseFloat(_Ybar.style.height); //页面滚动和滚动条滚动的百分比
  102. _rowBoard.style.top = -_NewRolltop * _double + "px"; //最终左边div的高
  103. _cellBox.style.top = -_NewRolltop * _double + "px"; //最终div的高
  104. _Newtop = parseInt(_rowBoard.style.top);
  105. };
  106. var _dragUp = function () { //拖拽时松开用的函数
  107. $(document).unbind('mousemove', _drapMove);
  108. $(document).unbind('mouseup', _dragUp);
  109. };
  110. $(document).bind('mousemove', _drapMove);
  111. $(document).bind('mouseup', _dragUp);
  112. })
  113. }
  114. /*
  115. * 绑定鼠标滚轮事件
  116. */
  117. U.MD.O.E.BC.scrollY.mousewheel = function () {
  118. var _Ybar = $(".U_MD_O_E_Ybar")[0], //滚动条
  119. _yBarRoll = $(".U_MD_O_E_YbarRoll")[0], //滚动条里面的滚动按钮
  120. _taskBar = $(".U_MD_O_E_taskBar")[0].offsetHeight, //互联办公模块
  121. _rowBoard = $(".U_MD_O_E_rowBoard")[0], //左边div
  122. _cellBox = $(".U_MD_O_E_cellBox")[0], //div区域
  123. _head_features = $(".U_MD_O_E_Editor_head_features")[0].offsetHeight;
  124. $(document).bind('mousewheel', function (e) {
  125. if (!U.MD.O.E.BC.scroll.isScroll) return;
  126. if (e.deltaY > 0) { //向下滚动
  127. _visual = document.body.clientHeight - 36 - _head_features - _taskBar; //可视页面高度
  128. _Ybar.style.height = _visual - 40 + "px"; //滚动条的长度随着页面百分比的变化而变化
  129. _double = (_rowBoard.offsetHeight + 25 - _visual) / parseFloat(_Ybar.style.height); //页面滚动和滚动条滚动的百分比
  130. if (_NewRolltop - 1 > _Ybar.offsetHeight) return;
  131. _yBarRoll.style.top = (_NewRolltop + 2) + "px";
  132. _NewRolltop = parseFloat(_yBarRoll.style.top); //删除尾部的px
  133. _rowBoard.style.top = -_NewRolltop * _double + "px"; //最终左边div的高
  134. _cellBox.style.top = -_NewRolltop * _double + "px"; //最终div的高
  135. _Newtop = parseInt(_rowBoard.style.top);
  136. } else {//向上滚动
  137. if (_Newtop == 0) return;
  138. _visual = document.body.clientHeight - 36 - _head_features - _taskBar; //可视页面高度
  139. _Ybar.style.height = _visual - 40 + "px"; //滚动条的长度随着页面百分比的变化而变化
  140. _double = (_rowBoard.offsetHeight + 25 - _visual) / parseFloat(_Ybar.style.height); //页面滚动和滚动条滚动的百分比
  141. _yBarRoll.style.top = Math.max((_NewRolltop - 2), 0) + "px"; //取最大值
  142. _NewRolltop = parseFloat(_yBarRoll.style.top); //删除尾部的px
  143. _rowBoard.style.top = -Math.max(_NewRolltop * _double, 0) + "px"; //最终左边div的高
  144. _cellBox.style.top = -Math.max(_NewRolltop * _double, 0) + "px"; //最终div的高
  145. _Newtop = Math.min(parseInt(_rowBoard.style.top), 0);
  146. }
  147. });
  148. }
  149. /**
  150. *
  151. * 给cell添加鼠标拖拽的选中效果
  152. * @param {object} cell 添加鼠标拖拽效果的
  153. */
  154. U.MD.O.E.BC.dragCheckd = function (cell) {
  155. var _cellEl = cell;
  156. var _Ybar = $(".U_MD_O_E_Ybar")[0], //滚动条
  157. _yBarRoll = $(".U_MD_O_E_YbarRoll")[0], //滚动条里面的滚动按钮
  158. _taskBar = $(".U_MD_O_E_taskBar")[0].offsetHeight, //互联办公模块
  159. _rowBoard = $(".U_MD_O_E_rowBoard")[0], //左边div
  160. _cellBox = $(".U_MD_O_E_cellBox")[0], //div区域
  161. _head_features = $(".U_MD_O_E_Editor_head_features")[0].offsetHeight;
  162. var _xBar = $(".U_MD_O_E_Xbar")[0], //滚动条
  163. _xBarRoll = $(".U_MD_O_E_XbarRoll")[0], //滚动条里面的滚动按钮
  164. _headInput = $(".U_MD_O_E_headInput")[0], //c6区域
  165. _colBoardBox = $(".U_MD_O_E_colBoardBox")[0]; //顶部div
  166. $(_cellEl).bind('mousedown', function (e) {
  167. var _Excel = top.$("#UD_Excel" + U.MD.O.E.fileinfo.UserDirectoryID)[0];
  168. U.UF.EV.stopBubble(e); //阻止冒泡
  169. //if (e.button === 2) return; //不准右键拖拽
  170. var _excel = U.MD.O.E,
  171. _focusBox = $("#U_MD_O_E_focusBox")[0],
  172. _editorBox = $("#U_MD_O_E_editorBox")[0],
  173. _startEl = this, //获取点击元素
  174. _startX = _startEl.col, //记录x坐标轴 A-Z
  175. _startY = _startEl.row, //获取y坐标轴 1-200的数字\
  176. _endX = _startX, //结束点x
  177. _endY = _startY, //结束点y
  178. _endPreX = _startX,
  179. _endPreY = _startY,
  180. _parent = this.parentNode,
  181. _elList,
  182. _drag = false,
  183. i,
  184. j,
  185. minX = Math.min(_startX, _endX),
  186. maxX = Math.max(_startX, _endX),
  187. minY = Math.min(_startY, _endY),
  188. maxY = Math.max(_startY, _endY),
  189. _endEl;
  190. if (e.button === 2 && (_focusBox.style.background)) return;
  191. $("#U_UF_EL_rightmenu")[0] && $("#U_UF_EL_rightmenu")[0].remove(); //删除右键元素
  192. $(".U_MD_O_E_cellCheckd").removeClass("U_MD_O_E_cellCheckd"); //删除所有被选中状态的单元格
  193. if (this.s_merge) { //如果点击的是合并单元格元素
  194. maxX = this.e_mergecol;
  195. maxY = this.e_mergerow;
  196. _excel.BC.modifyFocusSize(minX, minY, maxX, maxY);
  197. } else {
  198. _excel.BC.modifyFocusSize(minX, minY, maxX, maxY);
  199. //$(this).addClass('U_MD_O_E_cellCheckd');
  200. }
  201. var _drapMove = function (e) {//拖拽时移动用的函数
  202. var _moveY = e.pageY + _Excel.getElementsByClassName("U_MD_O_E_S")[0].parentNode.clientHeight,
  203. _moveX = e.pageX;
  204. if (_moveX < 0) {//超出区域-左
  205. clearInterval(_PageMove);
  206. _PageMove = setInterval(function () {
  207. if (_Newleft == 0) return; //到A列的时候不再执行
  208. _visual = document.body.clientWidth; //可视页面宽度
  209. _xBar.style.width = _visual - 100 + "px"; //滚动条的长度随着页面百分比的变化而变化
  210. _double = (_colBoardBox.offsetWidth - _visual) / parseFloat(_xBar.style.width); //滚动条的长度和页面总宽度的比例
  211. _xBarRoll.style.left = Math.max((_NewRollleft - (107 / _double)), 0) + "px"; //滚动条里面的滚动按钮的左边距
  212. _NewRollleft = parseFloat(_xBarRoll.style.left); //当前滚动按钮的左边距
  213. _colBoardBox.style.left = -Math.max((_NewRollleft * _double), 0) + "px"; //取最大值
  214. _cellBox.style.left = -Math.max((_NewRollleft * _double), 0) + "px";
  215. _Newleft = Math.min(parseInt(_colBoardBox.style.left), 0); //取最小值
  216. U.MD.O.E.BC.cellCheckd(param, "left", e);
  217. }, 100)
  218. } else if (_moveX > _Excel.clientWidth) {//超出区域-右
  219. clearInterval(_PageMove);
  220. _PageMove = setInterval(function () {
  221. _visual = document.body.clientWidth; //可视页面宽度
  222. _xBar.style.width = _visual - 100 + "px"; //滚动条的长度随着页面百分比的变化而变化
  223. _double = (_colBoardBox.offsetWidth - _visual) / parseFloat(_xBar.style.width); //滚动条的长度和页面总宽度的比例
  224. if (_NewRollleft + 1 > _xBar.offsetWidth) return; //到最后一列的时候不再执行
  225. _xBarRoll.style.left = (_NewRollleft + (107 / _double)) + "px"; //滚动条里面的滚动按钮的左边距
  226. _NewRollleft = parseFloat(_xBarRoll.style.left); //当前滚动按钮的左边距
  227. _colBoardBox.style.left = -_NewRollleft * _double + "px";
  228. _cellBox.style.left = -_NewRollleft * _double + "px";
  229. _Newleft = parseInt(_colBoardBox.style.left);
  230. U.MD.O.E.BC.cellCheckd(param, "right", e);
  231. }, 100)
  232. } else if (_moveY < 0) {//超出区域-上
  233. clearInterval(_PageMove);
  234. _PageMove = setInterval(function () {
  235. if (_Newtop == 0) return; //到达最上面一行return
  236. _visual = document.body.clientHeight - 36 - _head_features - _taskBar; //可视页面高度
  237. _Ybar.style.height = _visual - 40 + "px"; //滚动条的长度随着页面百分比的变化而变化
  238. _double = (_rowBoard.offsetHeight + 25 - _visual) / parseFloat(_Ybar.style.height); //页面滚动和滚动条滚动的百分比
  239. _yBarRoll.style.top = Math.max((_NewRolltop - 2), 0) + "px"; //滚动按钮的的高取最大值
  240. _NewRolltop = parseFloat(_yBarRoll.style.top); //当前滚动按钮的上边距
  241. _rowBoard.style.top = -Math.max(_NewRolltop * _double, 0) + "px";
  242. _cellBox.style.top = -Math.max(_NewRolltop * _double, 0) + "px";
  243. _Newtop = Math.min(parseInt(_rowBoard.style.top), 0);
  244. U.MD.O.E.BC.cellCheckd(param, "up", e);
  245. }, 100)
  246. } else if (_moveY > _Excel.clientHeight) {//超出区域-下
  247. clearInterval(_PageMove);
  248. _PageMove = setInterval(function () {
  249. _visual = document.body.clientHeight - 36 - _head_features - _taskBar; //可视页面高度
  250. _Ybar.style.height = _visual - 40 + "px"; //滚动条的长度随着页面百分比的变化而变化
  251. _double = (_rowBoard.offsetHeight + 25 - _visual) / parseFloat(_Ybar.style.height); //页面滚动和滚动条滚动的百分比
  252. if (_NewRolltop - 1 > _Ybar.offsetHeight) return; //到达最后一行则return
  253. _yBarRoll.style.top = (_NewRolltop + 2) + "px";
  254. _NewRolltop = parseFloat(_yBarRoll.style.top); //当前滚动按钮的上边距
  255. _rowBoard.style.top = -_NewRolltop * _double + "px";
  256. _cellBox.style.top = -_NewRolltop * _double + "px";
  257. _Newtop = parseInt(_rowBoard.style.top);
  258. U.MD.O.E.BC.cellCheckd(param, "down", e);
  259. }, 100);
  260. } else {
  261. clearInterval(_PageMove);
  262. }
  263. U.MD.O.E.BC.cellCheckd(param, "", e);
  264. };
  265. var _dragUp = function () { //拖拽时松开用的函数
  266. _startEl.style.zIndex = "0";
  267. _excel.BC.cellAddClass(minX, parseInt(minY), maxX, parseInt(maxY));
  268. clearInterval(_PageMove);
  269. $(document).unbind('mousemove', _drapMove);
  270. $(document).unbind('mouseup', _dragUp);
  271. $(document).unbind('mousewheel', _scrollMove);
  272. };
  273. var _scrollMove = function (e) {
  274. var _elNum = 0,
  275. _elList = e.path,
  276. _endEl = _elList.filter(_filter)[0];
  277. U.UF.EV.stopBubble(e); //阻止冒泡
  278. U.UF.EV.stopDefault(e); //取消默认拖拽
  279. if (!_endEl || !(_endEl.row) || !(_endEl.col)) return; //如果没有自定义属性(其他非单元格元素) 则不判断
  280. _endX = _endEl.col; //结束点的x坐标
  281. _endY = _endEl.row; //结束点的y坐标
  282. if (_endX !== _endPreX || _endY !== _endPreY) { //意思是当鼠标mousemove指向的元素不同时
  283. _focusBox.style.zIndex = "";
  284. minX = Math.min(_startX, _endX);
  285. maxX = Math.max(_startX, _endX);
  286. minY = Math.min(_startY, _endY);
  287. maxY = Math.max(_startY, _endY);
  288. var _cellEl,
  289. s_mergeCell, //合并单元格元素
  290. _cellArr = [];
  291. for (i = minX; i <= maxX; i++) {
  292. for (j = minY; j <= maxY; j++) {
  293. _cellEl = $(_parent).find("#POS_" + i + "_" + j)[0];
  294. _cellEl.s_merge ? s_mergeCell = $(_parent).find("#" + _cellEl.s_merge)[0] : "";
  295. if (s_mergeCell && _cellArr.indexOf(s_mergeCell) === -1) { //如果选中的是合并单元格的元素
  296. _endCell = $(_parent).find("#" + _cellEl.e_merge)[0];
  297. _cellArr.push(s_mergeCell);
  298. minX = Math.min(minX, s_mergeCell.col, _endCell.col);
  299. maxX = Math.max(maxX, s_mergeCell.col, _endCell.col);
  300. minY = Math.min(minY, s_mergeCell.row, _endCell.row);
  301. maxY = Math.max(maxY, s_mergeCell.row, _endCell.row);
  302. i = minX;
  303. j = minY;
  304. }
  305. }
  306. }
  307. _excel.BC.modifyFocusSize(minX, parseInt(minY), maxX, parseInt(maxY));
  308. _endPreX = _endX;
  309. _endPreY = _endY;
  310. }
  311. };
  312. var param = {
  313. startEl: _startEl,
  314. startX: _startX,
  315. startY: _startY,
  316. filter: _filter,
  317. parent: _parent,
  318. endX: _endX,
  319. endY: _endY,
  320. endPreX: _endPreX,
  321. endPreY: _endPreY,
  322. minX: minX,
  323. maxX: maxX,
  324. minY: minY,
  325. maxY: maxY,
  326. i: i,
  327. j: j
  328. }
  329. $(document).bind('mousemove', _drapMove); //执行mousemove事件
  330. $(document).bind('mouseup', _dragUp); //执行mouseup事件
  331. $(document).bind('mousewheel', _scrollMove); //执行mousewheel事件
  332. });
  333. var _filter = function (d) {
  334. return d.nodeName === "DIV" && d.col;
  335. };
  336. };
  337. /*
  338. *单元格选中超出单元格选区外的操作
  339. *@param {object} obj 操作对象
  340. *@param {number} direction 超出单元格选区的方向
  341. */
  342. U.MD.O.E.BC.cellCheckd = function (obj, direction, e) {
  343. var _excel = U.MD.O.E,
  344. _focusBox = $("#U_MD_O_E_focusBox")[0],
  345. _editorBox = $("#U_MD_O_E_editorBox")[0];
  346. var _elNum = 0,
  347. _elList = e.path,
  348. _endEl = _elList.filter(obj.filter)[0],
  349. _direction = direction || "";
  350. U.UF.EV.stopBubble(e); //阻止冒泡
  351. U.UF.EV.stopDefault(e); //取消默认拖拽
  352. if (_direction == "left") {
  353. obj.endX -= 1; //结束点的x坐标
  354. } else if (_direction == "right") {
  355. obj.endX = Math.min(obj.endX + 1, 26); //结束点的x坐标
  356. } else if (_direction == "up") {
  357. obj.endY -= 1; //结束点的y坐标
  358. } else if (_direction == "down") {
  359. obj.endY = Math.min(obj.endY + 1, 200); //结束点的y坐标
  360. } else {
  361. if (!_endEl || !(_endEl.row) || !(_endEl.col)) return; //如果没有自定义属性(其他非单元格元素) 则不判断
  362. obj.endX = _endEl.col; //结束点的x坐标
  363. obj.endY = _endEl.row; //结束点的y坐标
  364. }
  365. //console.log(_endY);
  366. if (obj.endX !== obj.endPreX || obj.endY !== obj.endPreY) { //意思是当鼠标mousemove指向的元素不同时
  367. _focusBox.style.zIndex = "";
  368. obj.minX = Math.min(obj.startX, obj.endX);
  369. obj.maxX = Math.max(obj.startX, obj.endX);
  370. obj.minY = Math.min(obj.startY, obj.endY);
  371. obj.maxY = Math.max(obj.startY, obj.endY);
  372. var _cellEl,
  373. s_mergeCell, //合并单元格元素
  374. _cellArr = [];
  375. for (var i = obj.minX; i <= obj.maxX; i++) {
  376. for (var j = obj.minY; j <= obj.maxY; j++) {
  377. _cellEl = $(obj.parent).find("#POS_" + i + "_" + j)[0];
  378. _cellEl.s_merge ? s_mergeCell = $(obj.parent).find("#" + _cellEl.s_merge)[0] : "";
  379. if (s_mergeCell && _cellArr.indexOf(s_mergeCell) === -1) { //如果选中的是合并单元格的元素
  380. _endCell = $(obj.parent).find("#" + _cellEl.e_merge)[0];
  381. _cellArr.push(s_mergeCell);
  382. obj.minX = Math.min(obj.minX, s_mergeCell.col, _endCell.col);
  383. obj.maxX = Math.max(obj.maxX, s_mergeCell.col, _endCell.col);
  384. obj.minY = Math.min(obj.minY, s_mergeCell.row, _endCell.row);
  385. obj.maxY = Math.max(obj.maxY, s_mergeCell.row, _endCell.row);
  386. i = obj.minX;
  387. j = obj.minY;
  388. }
  389. }
  390. }
  391. _excel.BC.modifyFocusSize(obj.minX, parseInt(obj.minY), obj.maxX, parseInt(obj.maxY)); //改变聚焦区域大小
  392. _excel.BC.cellAddClass(obj.minX, parseInt(obj.minY), obj.maxX, parseInt(obj.maxY)); //给聚焦区内的单元格添加样式
  393. obj.endPreX = obj.endX;
  394. obj.endPreY = obj.endY;
  395. }
  396. }
  397. /**
  398. *上下拉伸事件
  399. * @param {number} rowrule 行尺
  400. */
  401. U.MD.O.E.BC.rowExpanding = function (rowrule) { //高度扩张
  402. var _div = rowrule;
  403. $(_div).bind({
  404. 'mousedown': function (e) {
  405. //$("#U_UF_EL_rightmenu")[0] && $("#U_UF_EL_rightmenu")[0].remove(); //删除右键元素
  406. this.style.backgroundColor = "";
  407. this.style.width = document.body.clientWidth + "px"; //将行尺宽度暂满全屏
  408. U.UF.EV.stopBubble(e); //阻止冒泡
  409. var _oMouseY = e.pageY, //获取鼠标按下时的Y坐标
  410. _rowrule = this,
  411. _oY = parseInt(this.style.top), //获取当前Top坐标
  412. _rowDiv = this.parentNode, //获取行尺对应的div元素
  413. _initHeight = _rowDiv.offsetHeight, //行被拉伸前的初始高度
  414. _mouseY, //鼠标移动时的Y坐标
  415. _dis, //移动后的高度
  416. _oHeight = _rowDiv.offsetHeight, //_rowDiv的高度 会根据内容有个最小值 因此 这个_rowDiv最后的高度 才是最终值
  417. _rowName = +(this.parentNode.rowname),
  418. _moveDis; //移动的距离
  419. var expandingMove = function (e) { //拖拽时移动用的函数
  420. U.UF.EV.stopDefault(e); //取消默认拖拽
  421. _mouseY = e.pageY; //鼠标移动时的Y坐标
  422. _dis = _mouseY - _oMouseY + _oY; //
  423. _dis = Math.max(20, _dis); //拉伸后的高度不能小于20px
  424. _moveDis = _dis - _oHeight; //移动的距离
  425. _rowDiv.style.height = _dis + "px";
  426. _rowrule.style.top = _dis + "px";
  427. };
  428. var expandingUp = function () { //拖拽时松开用的函数
  429. $(document).unbind('mousemove', expandingMove);
  430. $(document).unbind('mouseup', expandingUp);
  431. _rowrule.style.backgroundColor = "";
  432. _rowrule.style.width = "100%";
  433. var info = {
  434. initHeight: _initHeight,
  435. rowName: _rowName,
  436. moveDis: _moveDis
  437. }
  438. U.MD.O.E.BC.rowExpandingEnd([info]);
  439. U.MD.O.E.BC.reSelectCell();
  440. };
  441. $(document).bind('mousemove', expandingMove);
  442. $(document).bind('mouseup', expandingUp)
  443. },
  444. 'mousemove': function (e) {
  445. U.UF.EV.stopBubble(e); //阻止冒泡
  446. U.UF.EV.stopDefault(e); //取消默认拖拽
  447. }
  448. });
  449. };
  450. /*
  451. * 行的拉伸
  452. * param infoArr 为数组json 格式[{info},{info},{info}]
  453. info 内容:
  454. {
  455. initHeight 行被拉伸前的高度
  456. rowName 拉伸行的 位置
  457. moveDis 拉伸行的 距离
  458. }
  459. * req 为true时 表示 不发送send请求
  460. */
  461. U.MD.O.E.BC.rowExpandingEnd = function (infoArr, req) {
  462. var _cellList = U.UF.C.toArray($(".U_MD_O_E_cell")), //所有的单元格
  463. _cellParent = $(".U_MD_O_E_cellBox")[0], //单元格的父元素
  464. _rowBoardList = $(".U_MD_O_E_row"),
  465. _data = [],
  466. len = _rowBoardList.length;
  467. infoArr.forEach(function (info) {
  468. var _rowName = info.rowName,
  469. _moveDis = info.moveDis,
  470. i,
  471. _rowCellList = _cellList.filter(function (el) { //第 rowName 列 的 所有单元格
  472. return +(el.row) === _rowName;
  473. }),
  474. _oHeight = info.initHeight, //行被拉伸前的高度
  475. _top,
  476. _mergeId,
  477. _elMergeId,
  478. _mergeCell,
  479. _iRowCell, //第i行的所有单元格
  480. _elId,
  481. _frag = $$("frag");
  482. _rowCellList.forEach(function (el) {
  483. _elMergeId = el.s_merge; //被合并单元格(最大)的位置
  484. if (_elMergeId && (_mergeId !== _elMergeId)) { //合并单元格的 拉伸判断
  485. _mergeId = _elMergeId; //被合并单元格的位置 记录 防止重复给被合并的单元格拉伸
  486. _elId = el.id;
  487. _mergeCell = $("#" + _mergeId)[0];
  488. _mergeCell.style.height = _mergeCell.offsetHeight + _moveDis + "px";
  489. if (_elId === _mergeId) return; //如果被合并单元格的位置和单元格的位置相等 则返回 不需要再添加一次宽
  490. }
  491. _frag.appendChild(el);
  492. el.style.height = _oHeight + _moveDis + "px";
  493. });
  494. for (i = _rowName + 1; i <= len; i++) {
  495. _iRowCell = _cellList.filter(function (el) { //第 i 行 的 所有单元格
  496. return +(el.row) === i;
  497. });
  498. _top = _rowBoardList[i - 1].offsetTop
  499. _iRowCell.forEach(function (el) {
  500. _frag.appendChild(el);
  501. el.style.top = _top + "px";
  502. });
  503. }
  504. _cellParent.appendChild(_frag);
  505. _data.push({
  506. rowName: _rowName, //拉伸行的位置
  507. height: _oHeight + _moveDis, //被拉伸后的高度
  508. moveDis: _moveDis //被拉伸的 距离
  509. });
  510. });
  511. U.MD.O.E.dataChange(U.MD.O.E.excelInfo("rowExpanding", _data), req);
  512. };
  513. /**
  514. *左右拉伸事件
  515. *@param {number} colrule 列尺
  516. */
  517. U.MD.O.E.BC.colExpanding = function (colrule) { //宽度扩张
  518. var _div = colrule;
  519. $(_div).bind({
  520. 'mousedown': function (e) {
  521. this.style.backgroundColor = "#8cb3e0";
  522. this.style.height = document.body.clientHeight + "px";
  523. U.UF.EV.stopBubble(e); //阻止冒泡
  524. var _oMouseX = e.pageX, //获取鼠标按下时的X坐标
  525. _colrule = this,
  526. _oX = parseInt(this.style.left), //获取当前left坐标
  527. _colDiv = this.parentNode, //获取列尺对应的div元素
  528. _initWidth = _colDiv.offsetWidth, //列的初始宽度
  529. _colBoard = $(".U_MD_O_E_colBoard")[0], //列板 A-Z 的父元素
  530. _colBoardWidth = _colBoard.offsetWidth, //为添加总宽用
  531. _mouseX, //鼠标移动时的X坐标
  532. //_colName = +($(this.parentNode).attr("colname")), //鼠标移动时的X坐标
  533. _colName = +(this.parentNode.colname),
  534. _dis, //移动的距离
  535. _oWidth = _colDiv.offsetWidth, //_colDiv的宽度最小值 mousemove时 要拿来做比较
  536. _moveDis;
  537. var expandingMove = function (e) { //拖拽时移动用的函数
  538. U.UF.EV.stopDefault(e); //取消默认拖拽
  539. _mouseX = e.pageX; //鼠标移动时的Y坐标
  540. _dis = _mouseX - _oMouseX + _oX; //
  541. _dis = Math.max(50, _dis); //拉伸后的高度不能小于20px
  542. _moveDis = _dis - _oWidth; //移动的距离
  543. _colBoard.style.width = _colBoardWidth + _moveDis + "px";
  544. _colDiv.style.width = _dis + "px";
  545. _colrule.style.left = _dis + "px";
  546. };
  547. var expandingUp = function () { //拖拽时松开用的函数
  548. $(document).unbind('mousemove', expandingMove);
  549. $(document).unbind('mouseup', expandingUp);
  550. _colrule.style.backgroundColor = "";
  551. _colrule.style.height = "100%";
  552. var info = {
  553. initWidth: _initWidth,
  554. colName: _colName,
  555. moveDis: _moveDis
  556. }
  557. U.MD.O.E.BC.colExpandingEnd([info]);
  558. U.MD.O.E.BC.reSelectCell();
  559. };
  560. $(document).bind('mousemove', expandingMove);
  561. $(document).bind('mouseup', expandingUp)
  562. },
  563. 'mousemove': function (e) {
  564. U.UF.EV.stopBubble(e); //阻止冒泡
  565. U.UF.EV.stopDefault(e); //取消默认拖拽
  566. }
  567. });
  568. };
  569. /**
  570. * @param i nfoArr 为数组json 格式[{info},{info},{info}]
  571. info 内容:
  572. { initWidth 列拉伸前的宽度
  573. colName 拉伸列的 位置
  574. moveDis 拉伸列的 距离
  575. }
  576. * req 为true时 表示 不发送send请求
  577. */
  578. U.MD.O.E.BC.colExpandingEnd = function (infoArr, req) {
  579. var _cellList = U.UF.C.toArray($(".U_MD_O_E_cell")), //所有的单元格
  580. _cellParent = $(".U_MD_O_E_cellBox")[0], //单元格的父元素
  581. _colBoardList = $(".U_MD_O_E_column"),
  582. _data = [],
  583. len = _colBoardList.length;
  584. infoArr.forEach(function (info) {
  585. var _colName = info.colName,
  586. _moveDis = info.moveDis,
  587. i,
  588. _colCellList = _cellList.filter(function (el) { //第 colName 列 的 所有单元格
  589. return +(el.col) === _colName;
  590. }),
  591. _oWidth = info.initWidth,
  592. _left,
  593. _mergeId,
  594. _elMergeId,
  595. _elId,
  596. _mergeCell,
  597. _iColCell, //第 i 列的 所有单元格
  598. _frag = $$("frag");
  599. _colCellList.forEach(function (el) {
  600. _elMergeId = el.s_merge; //被合并单元格(最大)的位置
  601. if (_elMergeId && (_mergeId !== _elMergeId)) { //合并单元格的 拉伸判断
  602. _mergeId = _elMergeId; //被合并单元格的位置 记录 防止重复给被合并的单元格拉伸
  603. _elId = el.id;
  604. _mergeCell = $("#" + _mergeId)[0];
  605. _mergeCell.style.width = _mergeCell.offsetWidth + _moveDis + "px";
  606. if (_elId === _mergeId) return; //如果被合并单元格的位置和单元格的位置相等 则返回 不需要再添加一次宽
  607. }
  608. _frag.appendChild(el);
  609. el.style.width = _oWidth + _moveDis + "px";
  610. });
  611. for (i = _colName + 1; i <= len; i++) {
  612. _iColCell = _cellList.filter(function (el) { //第 colName 列 的 所有单元格
  613. return +(el.col) === i;
  614. });
  615. _left = _colBoardList[i - 1].offsetLeft;
  616. _iColCell.forEach(function (el) {
  617. _frag.appendChild(el);
  618. el.style.left = _left + "px";
  619. })
  620. }
  621. _cellParent.appendChild(_frag);
  622. _data.push({
  623. colName: _colName, //拉伸列的位置
  624. width: _oWidth + _moveDis, //被拉伸后的宽度
  625. moveDis: _moveDis //被拉伸的 距离
  626. });
  627. });
  628. console.log(_data);
  629. U.MD.O.E.dataChange(U.MD.O.E.excelInfo("colExpanding", _data), req);
  630. }
  631. /*
  632. * 单元格添加样式
  633. *@param {number} minX 最小X值
  634. *@param {number} minY 最小Y值
  635. *@param {number} maxX 最大X值
  636. *@param {number} maxY 最大Y值
  637. */
  638. U.MD.O.E.BC.cellAddClass = function (minX, minY, maxX, maxY) {
  639. var _focusBox = $("#U_MD_O_E_focusBox")[0],
  640. _id,
  641. _cell,
  642. i,
  643. j;
  644. for (i = minX; i <= maxX; i++) {
  645. for (j = minY; j <= maxY; j++) {
  646. _id = "POS_" + i + "_" + j
  647. _cell = $("#" + _id)[0];
  648. $(_cell).addClass("U_MD_O_E_cellCheckd");
  649. }
  650. }
  651. }
  652. /**
  653. *
  654. * @param tr 获取所有tr用的(遍历所有tr)
  655. * @param {number} x1 开始点x坐标
  656. * @param {number} y1 开始点y坐标
  657. * @param {number} x2 结束点x坐标
  658. * @param {number} y2 结束点y坐标
  659. */
  660. U.MD.O.E.BC.modifyFocusSize = function (x1, y1, x2, y2) { //获取首尾坐标轴 修改聚焦元素大小
  661. var _x1 = Math.min(x1, x2), //A-Z 65-91
  662. _x2 = Math.max(x1, x2), //A-Z 65-91
  663. _y1 = Math.min(y1, y2), //1-200
  664. _y2 = Math.max(y1, y2),
  665. allWidth = 0,
  666. allHeight = 0,
  667. i,
  668. j,
  669. _colNum = _x1,
  670. _colEl = $(".U_MD_O_E_column")[_colNum - 1],
  671. _rowNum = _y1,
  672. _rowEl = $(".U_MD_O_E_row")[_rowNum - 1],
  673. _lFCornerEl = $("#POS_" + _x1 + "_" + _y1)[0],
  674. _focusBox = $("#U_MD_O_E_focusBox")[0], //单元格里的选中元素
  675. _colCheckdEl = $(".U_MD_O_E_colCheckdEl")[0], //列板里的选中元素
  676. _rowCheckdEl = $(".U_MD_O_E_rowCheckdEl")[0]; //行板里的选中元素
  677. _focusBox.style.display = "block";
  678. _focusBox.style.zIndex = "";
  679. while (_colNum !== _x2 + 1) { //获取选中元素的 宽 = 聚焦div的宽
  680. allWidth += _colEl.offsetWidth; //每一列的宽度之和
  681. _colEl = _colEl.nextElementSibling;
  682. _colNum++;
  683. }
  684. while (_rowNum !== _y2 + 1) {
  685. allHeight += _rowEl.offsetHeight; //每一行的高度之和
  686. _rowEl = _rowEl.nextElementSibling;
  687. _rowNum++;
  688. }
  689. _colCheckdEl.style.width = allWidth + "px";
  690. _colCheckdEl.style.left = _lFCornerEl.style.left;
  691. _colCheckdEl.style.background = "#e1e2e6";
  692. _rowCheckdEl.style.height = allHeight + "px";
  693. _rowCheckdEl.style.top = _lFCornerEl.style.top;
  694. _rowCheckdEl.style.background = "#e1e2e6";
  695. _focusBox.style.width = allWidth + "px";
  696. _focusBox.style.height = allHeight + "px";
  697. _focusBox.style.left = _lFCornerEl.style.left;
  698. _focusBox.style.top = _lFCornerEl.style.top;
  699. _focusBox.style.background = "#c1e3ff";
  700. }
  701. /*
  702. *列的选中与拖拽
  703. *@param {number}colBoard 选中的列头
  704. */
  705. U.MD.O.E.BC.cBoardChecked = function (colBoard) {
  706. $(colBoard).bind('mousedown', function (e) {
  707. U.UF.EV.stopBubble(e); //阻止冒泡
  708. $("#U_UF_EL_rightmenu")[0] && $("#U_UF_EL_rightmenu")[0].remove(); //删除右键元素
  709. var _excel = U.MD.O.E,
  710. _x1 = this.colname,
  711. _x2 = this.colname,
  712. _y1 = 1,
  713. _y2 = $(".U_MD_O_E_row").length,
  714. _focusBox = $("#U_MD_O_E_focusBox")[0], //获取聚焦元素
  715. _editorBox = $("#U_MD_O_E_editorBox")[0], //获取编辑元素
  716. _startEl = this, //获取点击元素
  717. _startX = _startEl.colname, //记录x坐标轴 A-Z
  718. _startY = 1,
  719. _endX = _startX,
  720. _endY = $(".U_MD_O_E_row").length,
  721. _endPreX = _startX, //记录上一个的位置
  722. _parent = $(".U_MD_O_E_cellBox"),
  723. i,
  724. j,
  725. minX = Math.min(_startX, _endX),
  726. maxX = Math.max(_startX, _endX),
  727. minY = Math.min(_startY, _endY),
  728. maxY = Math.max(_startY, _endY),
  729. _endEl;
  730. if (e.button === 2 && (_focusBox.style.background)) return; //无视
  731. $(".U_MD_O_E_cellCheckd").removeClass("U_MD_O_E_cellCheckd"); //删除所有被选中状态的单元格
  732. var _firstCell = $("#POS_" + _x1 + "_1")[0];
  733. U.MD.O.E.BC.focusSwitch(_firstCell);
  734. U.MD.O.E.BC.modifyFocusSize(_x1, _y1, _x2, _y2);
  735. var move = function (e) {
  736. U.MD.O.E.BC.cellAddClass();
  737. _endEl = e.path.filter(_filter)[0];
  738. U.UF.EV.stopBubble(e); //阻止冒泡
  739. U.UF.EV.stopDefault(e); //取消默认拖拽
  740. if (!_endEl) return;
  741. if (_endEl.row) { //单元格
  742. _endX = _endEl.col; //结束点的x坐标
  743. }
  744. if (_endEl.colname) { //列板元素
  745. _endX = _endEl.colname; //结束点的x坐标
  746. }
  747. if (_endX !== _endPreX) { //意思是当鼠标mousemove指向的元素不同时
  748. minX = Math.min(_startX, _endX);
  749. maxX = Math.max(_startX, _endX);
  750. minY = Math.min(_startY, _endY);
  751. maxY = Math.max(_startY, _endY);
  752. _excel.BC.modifyFocusSize(minX, parseInt(minY), maxX, parseInt(maxY));
  753. _endPreX = _endX;
  754. }
  755. };
  756. var stop = function (e) {
  757. _excel.BC.cellAddClass(minX, parseInt(minY), maxX, parseInt(maxY)); //
  758. $(document).unbind({
  759. 'mousemove': move,
  760. 'mouseup': stop
  761. });
  762. }
  763. $(document).bind({
  764. 'mousemove': move,
  765. 'mouseup': stop
  766. });
  767. var _filter = function (d) {
  768. return d.nodeName === "DIV" && (d.col || d.colname);
  769. };
  770. })
  771. }
  772. /*
  773. *行的选中与拖拽
  774. *@param {number} rowBoard 选中的行头
  775. */
  776. U.MD.O.E.BC.rBoardChecked = function (rowBoard) {
  777. $(rowBoard).bind('mousedown', function (e) {
  778. U.UF.EV.stopBubble(e); //阻止冒泡
  779. $("#U_UF_EL_rightmenu")[0] && $("#U_UF_EL_rightmenu")[0].remove(); //删除右键元素
  780. var _excel = U.MD.O.E,
  781. _x1 = 1,
  782. _x2 = $(".U_MD_O_E_column").length,
  783. _y1 = this.rowname,
  784. _y2 = this.rowname,
  785. _focusBox = $("#U_MD_O_E_focusBox")[0], //获取聚焦元素
  786. _editorBox = $("#U_MD_O_E_editorBox")[0], //获取编辑元素
  787. _startEl = this, //获取点击元素
  788. _startX = 1, //记录x坐标轴 A-Z
  789. _endX = $(".U_MD_O_E_column").length,
  790. _startY = _startEl.rowname,
  791. _endY = _startY,
  792. _endPreY = _startY, //记录上一个的位置
  793. _parent = $(".U_MD_O_E_cellBox"),
  794. i,
  795. j,
  796. minX = Math.min(_startX, _endX),
  797. maxX = Math.max(_startX, _endX),
  798. minY = Math.min(_startY, _endY),
  799. maxY = Math.max(_startY, _endY),
  800. _endEl;
  801. if (e.button === 2 && (_focusBox.style.background)) return; //无视
  802. $(".U_MD_O_E_cellCheckd").removeClass("U_MD_O_E_cellCheckd"); //删除所有被选中状态的单元格
  803. var _firstCell = $("#POS_" + "1_" + _y1)[0];
  804. U.MD.O.E.BC.focusSwitch(_firstCell);
  805. _excel.BC.modifyFocusSize(minX, parseInt(minY), maxX, parseInt(maxY));
  806. var move = function (e) {
  807. console.log("_startY:" + _startY + "_endPreY:" + _endPreY);
  808. U.MD.O.E.BC.cellAddClass();
  809. _endEl = e.path.filter(_filter)[0];
  810. U.UF.EV.stopBubble(e); //阻止冒泡
  811. U.UF.EV.stopDefault(e); //取消默认拖拽
  812. if (!_endEl) return;
  813. if (_endEl.row) { //单元格
  814. _endY = _endEl.row; //结束点的x坐标
  815. }
  816. if (_endEl.rowname) { //列板元素
  817. _endY = _endEl.rowname; //结束点的x坐标
  818. }
  819. if (_endY !== _endPreY) { //意思是当鼠标mousemove指向的元素不同时
  820. minX = Math.min(_startX, _endX);
  821. maxX = Math.max(_startX, _endX);
  822. minY = Math.min(_startY, _endY);
  823. maxY = Math.max(_startY, _endY);
  824. _excel.BC.modifyFocusSize(minX, parseInt(minY), maxX, parseInt(maxY));
  825. _endPreY = _endY;
  826. }
  827. }
  828. var stop = function (e) {
  829. _excel.BC.cellAddClass(minX, parseInt(minY), maxX, parseInt(maxY));
  830. $(document).unbind({
  831. 'mousemove': move,
  832. 'mouseup': stop
  833. });
  834. }
  835. $(document).bind({
  836. 'mousemove': move,
  837. 'mouseup': stop
  838. });
  839. var _filter = function (d) {
  840. return d.nodeName === "DIV" && (d.row || d.rowname);
  841. };
  842. });
  843. }
  844. /**
  845. * 单元格聚焦
  846. *@param {number} el = 传进来的单元格元素
  847. */
  848. U.MD.O.E.BC.Focus = function (el) {
  849. $(el).bind('mousedown', function (e) {
  850. var _focusBox = $("#U_MD_O_E_focusBox")[0], //聚焦元素
  851. _editorBox = $("#U_MD_O_E_editorBox")[0], //编辑元素
  852. _headInput = $(".U_MD_O_E_headInput")[0]; //文本框元素
  853. U.MD.O.E.BC.focusSwitch(this); //文本框内容同步
  854. if (el.getAttribute("name") == "seted") {
  855. var _style = el.getAttribute("style");
  856. _editorBox.setAttribute("style", _style);
  857. _editorBox.style.zIndex = "";
  858. } else {
  859. $('#U_MD_O_E_editorBox')[0].removeAttribute("style");
  860. }
  861. })
  862. }
  863. /*
  864. * 编辑器失去焦点函数
  865. */
  866. U.MD.O.E.BC.blur = function () {
  867. var _editorBox = $("#U_MD_O_E_editorBox")[0], //聚焦元素里的编辑器
  868. _focusBox = $("#U_MD_O_E_focusBox")[0],
  869. _headInput = $(".U_MD_O_E_headInput")[0]; //c6文本框元素
  870. $(_editorBox).bind('blur', function (e) {
  871. U.MD.O.E.BC.editorBlur(e);
  872. });
  873. $(_editorBox).bind('mousedown', function (e) {
  874. if ($(this).attr("contenteditable")) {
  875. U.MD.O.E.BC.editorFocus = true;
  876. }
  877. })
  878. $(_headInput).bind('blur', function () {
  879. U.MD.O.E.BC.headInputBlur();
  880. })
  881. }
  882. /*
  883. * 编辑器失焦
  884. */
  885. U.MD.O.E.BC.editorBlur = function (e) {
  886. var _editorBox = $("#U_MD_O_E_editorBox")[0]; //聚焦元素里的编辑器
  887. U.MD.O.E.BC.editorFocus = false; //文本框已失焦
  888. if (U.MD.O.E.setStyle) {
  889. U.MD.O.E.placeCaretAtEnd(_editorBox.lastElementChild);
  890. U.MD.O.E.setStyle = false;
  891. return;
  892. }
  893. if (!U.MD.O.E.BC.editorFocus && !U.MD.O.E.BC.headInputFocus) {
  894. var _cell = _editorBox.editorCell; //获取最底层的div
  895. _cell.innerHTML = _editorBox.innerHTML; //将聚焦元素的内容赋值给最底层
  896. $(_editorBox).attr("contenteditable", false);
  897. var _allButton = $(".U_MD_O_E_Editor_head_features_ul_d");
  898. for (var i = 0; i < _allButton.length; i++) {
  899. _allButton[i].removeAttribute("disabled");
  900. }
  901. _editorBox.innerHTML = ""; //聚焦元素的内容清空
  902. var _data = {
  903. row: _cell.row,
  904. col: _cell.col,
  905. content: _cell.innerHTML,
  906. innerText: _cell.innerText //之所以要发innerText 是因为要用来判断data数据里单元格的内容如果被改为空 则删除掉该单元格的数据
  907. }; //讲内容打包给后台
  908. U.MD.O.E.dataChange(U.MD.O.E.excelInfo("blur", [_data])); //聚焦时 保存数据
  909. console.log(_cell.id + ":" + "成功!");
  910. }
  911. }
  912. /*
  913. * 文本框失焦事件
  914. */
  915. U.MD.O.E.BC.headInputBlur = function () {
  916. var _editorBox = $("#U_MD_O_E_editorBox")[0]; //聚焦元素里的
  917. U.MD.O.E.BC.headInputFocus = false;
  918. if (!U.MD.O.E.BC.editorFocus && !U.MD.O.E.BC.headInputFocus) {
  919. var _cell = _editorBox.editorCell;
  920. if (!_cell) return;
  921. _cell.innerHTML = _editorBox.innerHTML; //将值赋值给最下层div
  922. _editorBox.innerHTML = ""; //将聚焦层的值清空
  923. $(_editorBox).attr("contenteditable", false);
  924. var _allButton = $(".U_MD_O_E_Editor_head_features_ul_d");
  925. for (var i = 0; i < _allButton.length; i++) {
  926. _allButton[i].removeAttribute("disabled");
  927. }
  928. //协同操作
  929. var _data = {
  930. row: _cell.row,
  931. col: _cell.col,
  932. content: _cell.innerHTML,
  933. innerText: _cell.innerText //之所以要发innerText 是因为要用来判断data数据里单元格的内容如果被改为空 则删除掉该单元格的数据
  934. }; //讲内容打包给后台
  935. U.MD.O.E.dataChange(U.MD.O.E.excelInfo("blur", [_data])); //聚焦时 保存数据
  936. }
  937. }
  938. /*
  939. * 单元格聚焦后的双击绑定
  940. */
  941. U.MD.O.E.BC.focusDbClick = function () {
  942. $("#U_MD_O_E_editorBox").bind('dblclick', function (e) {
  943. var _cell = this.focusEl;
  944. this.innerHTML = _cell.innerHTML;
  945. _cell.innerHTML = "";
  946. $(this).attr("contenteditable", true);
  947. if (!this.innerHTML) {
  948. var _div = $$("div", { innerHTML: "\u200D" }, this)
  949. _div.focus();
  950. this.focus();
  951. }
  952. U.MD.O.E.placeCaretAtEnd(this.lastElementChild);
  953. U.MD.O.E.BC.editorFocus = true; //编辑器正在聚焦
  954. this.editorCell = _cell;
  955. var _borderDivList = $(".U_MD_O_E_borderDefalut");
  956. _borderDivList.removeClass("U_MD_O_E_borderDefalut");
  957. _borderDivList.addClass("U_MD_O_E_borderEditable");
  958. });
  959. }
  960. /*
  961. *双击编辑时的初始化
  962. */
  963. U.MD.O.E.BC.editorKeyEvent = function () {
  964. U.MD.O.E.BC.editorKeyUp(); //keyup事件
  965. U.MD.O.E.BC.editorKeyDown(); //keydown事件
  966. // var _keydown = function (e) {
  967. // var _code = e.keyCode;
  968. // if (_code === 13) {
  969. // // return false;
  970. // //console.log(112)
  971. // }
  972. // }
  973. // var _delinput = function () { //此处为第一行不能删除
  974. // var _range = U.UF.E.getRangeAt(),
  975. // _firstDiv = U.UF.E.getLineElement(_range.startContainer),
  976. // _div;
  977. // if (_firstDiv.id === "U_MD_O_E_editorBox") {
  978. // this.querySelectorAll("br").forEach(function (br) {
  979. // br.remove();
  980. // })
  981. // _div = $$("div", { innerHTML: "\u200D" }, this);
  982. // U.MD.O.E.placeCaretAtEnd(_div);
  983. // }
  984. // };
  985. // var _editorBox = $("#U_MD_O_E_editorBox")[0]; //聚焦元素里的 可编辑div
  986. // var _json = {};
  987. // $(_editorBox).bind('input', _delinput);
  988. };
  989. /*
  990. * 编辑器keyup事件编写
  991. */
  992. U.MD.O.E.BC.editorKeyUp = function () {
  993. var _cellBox = $(".U_MD_O_E_cellBox")[0], //所有单元格的父节点
  994. _focusBox = $("#U_MD_O_E_focusBox")[0], //聚焦元素
  995. _editorBox = $("#U_MD_O_E_editorBox")[0], //聚焦元素里的 可编辑div
  996. _headInput = $(".U_MD_O_E_headInput")[0]; //c6文本框元素
  997. $(document).bind("keypress", function (e) { //执行函数
  998. if (e.charCode === 13) return; //如果是enter键 则直接return
  999. if ($(_editorBox).attr("contenteditable") === "true") return; //如果编辑器是编辑状态的话 则直接return
  1000. $(_editorBox).attr("contenteditable", true);
  1001. var _div = $$("div", { innerHTML: "\u200D" }, _editorBox)
  1002. U.MD.O.E.placeCaretAtEnd(_div); //产生光标
  1003. U.MD.O.E.BC.editorFocus = true; //编辑器正在聚焦
  1004. _editorBox.focusEl.innerHTML = ""; //单元格内容清空
  1005. _headInput.innerHTML = _editorBox.innerText; //将聚焦元素的 innerHTML 传给文本框
  1006. _editorBox.editorCell = _editorBox.focusEl;
  1007. var _allButton = $(".U_MD_O_E_Editor_head_features_ul_d");
  1008. for (var i = 0; i < _allButton.length; i++) {
  1009. _allButton[i].setAttribute("disabled", true);
  1010. }
  1011. if (_focusBox.style.background) {
  1012. var _cell = _editorBox.editorCell;
  1013. $(".U_MD_O_E_cellCheckd").removeClass("U_MD_O_E_cellCheckd"); //删除所有被选中状态的单元格
  1014. U.MD.O.E.BC.modifyFocusSize(_cell.col, _cell.row, _cell.col, _cell.row);
  1015. $(_cell).addClass("U_MD_O_E_cellCheckd");
  1016. $(_cell).removeClass("U_MD_O_E_focus");
  1017. _focusBox.style.background = "";
  1018. }
  1019. })
  1020. $(_editorBox).bind("input", function (e) { //执行函数
  1021. _headInput.innerHTML = _editorBox.innerText; //将聚焦元素的 innerHTML 传给文本框
  1022. })
  1023. $(_headInput).bind("input", function (e) { //执行函数
  1024. U.UF.EV.stopBubble(e); //阻止冒泡
  1025. $(_editorBox).attr("contenteditable", true);
  1026. _editorBox.innerHTML = this.innerHTML; //将聚焦元素的 innerHTML 传给文本框
  1027. _editorBox.focusEl.innerHTML = ""; //单元格内容清空
  1028. _editorBox.editorCell = _editorBox.focusEl;
  1029. })
  1030. $(_headInput).bind("mousedown", function (e) { //执行函数
  1031. U.MD.O.E.BC.headInputFocus = true;
  1032. })
  1033. $(_headInput).bind("keypress", function (e) { //执行函数
  1034. U.UF.EV.stopBubble(e); //阻止冒泡
  1035. })
  1036. }
  1037. /*
  1038. * 编辑器keyDown事件编写
  1039. */
  1040. U.MD.O.E.BC.editorKeyDown = function (e) {
  1041. U.UF.EV.addElementEvent("keydown", document, function (e) { //执行函数
  1042. var _keyCode = e.keyCode,
  1043. _excel = U.MD.O.E.BC;
  1044. if (_keyCode === 40 || _keyCode === 13) {
  1045. }
  1046. if (_keyCode == 8 || _keyCode == 46 || _keyCode == 110) {
  1047. if ($('.U_MD_O_E_excelBox')[0].imgStretch.stretch.style.display == "block") {//判断是否为图片删除
  1048. var imgObj = $('.U_MD_O_E_excelBox')[0].imgStretch.stretch.upimg.path[0];
  1049. imgObj.parentNode.removeChild(imgObj); //删除图片
  1050. $('.U_MD_O_E_excelBox')[0].imgStretch.stretch.style.display = "none"; //影藏拉伸框
  1051. }
  1052. }
  1053. switch (_keyCode) {
  1054. case 40:
  1055. case 13:
  1056. _excel.down();
  1057. break;
  1058. case 37:
  1059. _excel.left();
  1060. break;
  1061. case 38:
  1062. _excel.up();
  1063. break;
  1064. case 39:
  1065. _excel.right();
  1066. break;
  1067. }
  1068. }); //禁止浏览器回退
  1069. // $(document).bind("keydown", )
  1070. };
  1071. /*
  1072. * 键盘事件向下事件
  1073. */
  1074. U.MD.O.E.BC.down = function () {
  1075. var _excel = U.MD.O.E.BC,
  1076. _editorBox = $("#U_MD_O_E_editorBox")[0], //编辑元素
  1077. _headInput = $(".U_MD_O_E_headInput")[0], //文本框元素
  1078. cell = _editorBox.focusEl,
  1079. minX = cell.col,
  1080. maxX = cell.col,
  1081. minY = cell.row + 1,
  1082. maxY = cell.row + 1; //编辑元素
  1083. if (cell.e_merge) { //如果当前是合并单元格元素
  1084. minY = cell.e_mergerow + 1;
  1085. maxY = cell.e_mergerow + 1;
  1086. }
  1087. $(cell).attr("contenteditable", false);
  1088. cell = $("#POS_" + minX + "_" + minY)[0];
  1089. if (!cell) return;
  1090. if (cell.e_merge) { //如果下一行的元素是合并单元格元素
  1091. minX = cell.s_mergecol;
  1092. maxX = cell.e_mergecol;
  1093. minY = cell.s_mergerow;
  1094. maxY = cell.e_mergerow;
  1095. }
  1096. _excel.modifyFocusSize(minX, minY, maxX, maxY);
  1097. _excel.cellAddClass(minX, minY, maxX, maxY);
  1098. if (cell.e_merge) {
  1099. _excel.focusSwitch($("#" + cell.s_merge)[0])
  1100. } else {
  1101. _excel.focusSwitch(cell);
  1102. }
  1103. _editorBox.blur();
  1104. _headInput.blur();
  1105. }
  1106. /*
  1107. * 键盘事件向上事件
  1108. */
  1109. U.MD.O.E.BC.up = function () {
  1110. var _excel = U.MD.O.E.BC,
  1111. _editorBox = $("#U_MD_O_E_editorBox")[0], //编辑元素
  1112. _headInput = $(".U_MD_O_E_headInput")[0], //文本框元素
  1113. cell = _editorBox.focusEl,
  1114. minX = cell.col,
  1115. maxX = cell.col,
  1116. minY = cell.row - 1,
  1117. maxY = cell.row - 1; //编辑元素
  1118. if (cell.e_merge) { //如果当前是合并单元格元素
  1119. minY = cell.s_mergerow - 1;
  1120. maxY = cell.s_mergerow - 1;
  1121. }
  1122. $(cell).attr("contenteditable", false);
  1123. cell = $("#POS_" + minX + "_" + minY)[0];
  1124. if (!cell) return;
  1125. if (cell.e_merge) { //如果下一行的元素是合并单元格元素
  1126. minX = cell.s_mergecol;
  1127. maxX = cell.e_mergecol;
  1128. minY = cell.s_mergerow;
  1129. maxY = cell.e_mergerow;
  1130. }
  1131. _excel.modifyFocusSize(minX, minY, maxX, maxY);
  1132. _excel.cellAddClass(minX, minY, maxX, maxY);
  1133. if (cell.e_merge) {
  1134. _excel.focusSwitch($("#" + cell.s_merge)[0])
  1135. } else {
  1136. _excel.focusSwitch(cell);
  1137. }
  1138. _editorBox.blur();
  1139. _headInput.blur();
  1140. }
  1141. /*
  1142. * 键盘事件向左事件
  1143. */
  1144. U.MD.O.E.BC.left = function () {
  1145. var _excel = U.MD.O.E.BC,
  1146. _editorBox = $("#U_MD_O_E_editorBox")[0], //编辑元素
  1147. _headInput = $(".U_MD_O_E_headInput")[0], //文本框元素
  1148. cell = _editorBox.focusEl,
  1149. minX = cell.col - 1,
  1150. maxX = cell.col - 1,
  1151. minY = cell.row,
  1152. maxY = cell.row; //编辑元素
  1153. if (cell.e_merge) { //如果当前是合并单元格元素
  1154. minX = cell.s_mergecol - 1;
  1155. maxX = cell.s_mergecol - 1;
  1156. }
  1157. $(cell).attr("contenteditable", false);
  1158. cell = $("#POS_" + minX + "_" + minY)[0];
  1159. if (!cell) return;
  1160. if (cell.e_merge) { //如果下一行的元素是合并单元格元素
  1161. minX = cell.s_mergecol;
  1162. maxX = cell.e_mergecol;
  1163. minY = cell.s_mergerow;
  1164. maxY = cell.e_mergerow;
  1165. }
  1166. _excel.modifyFocusSize(minX, minY, maxX, maxY);
  1167. _excel.cellAddClass(minX, minY, maxX, maxY);
  1168. if (cell.e_merge) {
  1169. _excel.focusSwitch($("#" + cell.s_merge)[0])
  1170. } else {
  1171. _excel.focusSwitch(cell);
  1172. }
  1173. _editorBox.blur();
  1174. _headInput.blur();
  1175. }
  1176. /*
  1177. * 键盘事件向右事件
  1178. */
  1179. U.MD.O.E.BC.right = function () {
  1180. var _excel = U.MD.O.E.BC,
  1181. _editorBox = $("#U_MD_O_E_editorBox")[0], //编辑元素
  1182. _headInput = $(".U_MD_O_E_headInput")[0], //文本框元素
  1183. cell = _editorBox.focusEl,
  1184. minX = cell.col + 1,
  1185. maxX = cell.col + 1,
  1186. minY = cell.row,
  1187. maxY = cell.row; //编辑元素
  1188. if (cell.e_merge) { //如果当前是合并单元格元素
  1189. minX = cell.e_mergecol + 1;
  1190. maxX = cell.e_mergecol + 1;
  1191. }
  1192. $(cell).attr("contenteditable", false);
  1193. cell = $("#POS_" + minX + "_" + minY)[0];
  1194. console.log($("#" + cell.s_merge)[0]);
  1195. if (!cell) return;
  1196. if (cell.e_merge) { //如果下一行的元素是合并单元格元素
  1197. minX = cell.s_mergecol;
  1198. maxX = cell.e_mergecol;
  1199. minY = cell.s_mergerow;
  1200. maxY = cell.e_mergerow;
  1201. }
  1202. _excel.modifyFocusSize(minX, minY, maxX, maxY);
  1203. _excel.cellAddClass(minX, minY, maxX, maxY);
  1204. if (cell.e_merge) {
  1205. _excel.focusSwitch($("#" + cell.s_merge)[0])
  1206. } else {
  1207. _excel.focusSwitch(cell);
  1208. }
  1209. _editorBox.blur();
  1210. _headInput.blur();
  1211. }
  1212. /* 聚焦元素切换时 文本框内容同步
  1213. * @param {number} cell 单元格元素
  1214. */
  1215. U.MD.O.E.BC.focusSwitch = function (cell) {
  1216. var _editorBox = $("#U_MD_O_E_editorBox")[0], //编辑元素
  1217. _focusBox = $("#U_MD_O_E_focusBox")[0], //聚焦元素
  1218. _headInput = $(".U_MD_O_E_headInput")[0]; //文本框元素
  1219. _editorBox.focusEl = cell;
  1220. _headInput.innerHTML = cell.innerHTML; //将聚焦元素的 innerHTML 传给文本框
  1221. $(".U_MD_O_E_focus").removeClass("U_MD_O_E_focus");
  1222. $(cell).addClass('U_MD_O_E_focus'); //第一个聚焦的颜色一定是白色
  1223. _focusBox.style.zIndex = "1";
  1224. _focusBox.style.background = "";
  1225. $(cell).attr("contenteditable", true);
  1226. }
  1227. /*
  1228. * 重新选择单元格
  1229. * @param {element} data 如果data不存在 则重新调整聚焦元素的大小
  1230. */
  1231. U.MD.O.E.BC.reSelectCell = function (data) {
  1232. var _excel = U.MD.O.E;
  1233. if (!data) { //如果data不存在 则重新调整聚焦元素的大小
  1234. var _startcell = _excel.cellCheckd()[0], //获取首个选中元素
  1235. _endcell = _excel.cellCheckd()[1], //获取最后一个选中的元素
  1236. _minx = _startcell.col,
  1237. _miny = _startcell.row,
  1238. _maxx = _endcell.col,
  1239. _maxy = _endcell.row;
  1240. _excel.BC.modifyFocusSize(_minx, _miny, _maxx, _maxy); //重新调整聚焦元素的大小
  1241. return;
  1242. } else {
  1243. var _data = data,
  1244. _checkeddata = _data.checkeddata, //右键前的两单元格的坐标数据
  1245. _type = data.type;
  1246. if (_data.type === "removeLine") {
  1247. var _linenum = $(".U_MD_O_E_row").length, //总行数
  1248. _rmlineNum = _data.rmlinenum; //删除行的数量
  1249. if (_checkeddata.maxy > _linenum) { //如果删除前单元格的行 大于 删后的总数量的话:
  1250. _checkeddata.miny = _checkeddata.miny - _rmlineNum;
  1251. _checkeddata.maxy = _checkeddata.maxy - _rmlineNum;
  1252. }
  1253. } else if (_data.type === "removeCol") {
  1254. var _colnum = $(".U_MD_O_E_column").length, //总列数
  1255. _rmcolnum = _data.rmcolnum; //删除列的数量
  1256. if (_checkeddata.maxx > _colnum) { //如果删除前单元格的列 大于 删后的总数量的话:
  1257. _checkeddata.minx = _checkeddata.minx - _rmcolnum;
  1258. _checkeddata.maxx = _checkeddata.maxx - _rmcolnum;
  1259. }
  1260. }
  1261. }
  1262. var _minx = _checkeddata.minx,
  1263. _miny = _checkeddata.miny,
  1264. _maxx = _checkeddata.maxx,
  1265. _maxy = _checkeddata.maxy;
  1266. _excel.BC.modifyFocusSize(_minx, _miny, _maxx, _maxy);
  1267. _excel.BC.cellAddClass(_minx, _miny, _maxx, _maxy);
  1268. }
  1269. /*
  1270. * return object
  1271. * @param {element} startcell 左上角的单元格
  1272. * @param {element} endcell 右下角的单元格
  1273. */
  1274. U.MD.O.E.BC.selectCellData = function (startcell, endcell) {
  1275. var minx = startcell.col,
  1276. miny = startcell.row,
  1277. maxx = endcell.col,
  1278. maxy = endcell.row;
  1279. return {
  1280. minx: minx,
  1281. miny: miny,
  1282. maxx: maxx,
  1283. maxy: maxy
  1284. }
  1285. }
  1286. /*
  1287. * 添加自定义attr属性的同时 且添加了原型链下的属性
  1288. * @param {element} value 属性
  1289. */
  1290. U.select.prototype.eAttr = function (value, item) {
  1291. $(this).attr(value, item);
  1292. var _value = value.toLowerCase();
  1293. this[0][_value] = item;
  1294. }
  1295. /*
  1296. * 删除attr属性时 原型链下的属性也跟着删掉
  1297. * @param {element} value 属性
  1298. */
  1299. U.select.prototype.eRmAttr = function (value) {
  1300. $(this).rmAttr(value);
  1301. delete (this[0][value]);
  1302. }
  1303. /*
  1304. * 图片总控制
  1305. * @param {element} img 图片元素
  1306. */
  1307. U.MD.O.E.BC.pictureControl = function (img) {
  1308. U.MD.O.E.BC.pictureControl.imgDrag(img); //图片拖拽
  1309. }
  1310. /*
  1311. * 图片拖拽
  1312. * @param {element} img 图片元素
  1313. */
  1314. U.MD.O.E.BC.pictureControl.imgDrag = function (img) {
  1315. $(img).bind("mousedown", function (e) {
  1316. U.UF.EV.stopBubble(e); //阻止冒泡
  1317. U.UF.EV.stopDefault(e); //取消默认拖拽
  1318. var _oY = e.pageY, //选中时的y
  1319. _oX = e.pageX, //选中时的x
  1320. _marginLeft = img.offsetLeft, //图片的左边距
  1321. _marginTop = img.offsetTop, //图片的上边距
  1322. _newY,
  1323. _newX,
  1324. _copydata = {};
  1325. var _drapMove = function (e) {//拖拽时移动用的函数
  1326. U.UF.EV.stopBubble(e); //阻止冒泡wx`
  1327. _newY = e.pageY; //位移后的Y
  1328. _newX = e.pageX; //位移后的X
  1329. _differenceY = _newY - _oY; //位移后的值和选中的值得差值
  1330. _differenceX = _newX - _oX;
  1331. img.style.left = _marginLeft + _differenceX + "px";
  1332. img.style.top = _marginTop + _differenceY + "px";
  1333. };
  1334. var _dragUp = function () { //拖拽时松开用的函数
  1335. $(document).unbind('mousemove', _drapMove);
  1336. $(document).unbind('mouseup', _dragUp);
  1337. var _data = {
  1338. src: img.src,
  1339. left: parseFloat(img.style.left),
  1340. top: parseFloat(img.style.top),
  1341. width: img.offsetWidth,
  1342. height: img.offsetHeight,
  1343. type: "img"
  1344. };
  1345. U.MD.O.E.dataChange(U.MD.O.E.excelInfo("imgChange", _data));
  1346. };
  1347. $(document).bind('mousemove', _drapMove);
  1348. $(document).bind('mouseup', _dragUp);
  1349. })
  1350. }
  1351. /**
  1352. * 添加超链接
  1353. * @param {element} _cellList为选中的单元集合
  1354. * @param {element} req 判断是否发送数据给后台
  1355. * */
  1356. U.UF.E.excelAddHref = function (_cellList, req) {
  1357. var _editorBox = $("#U_MD_O_E_editorBox")[0],
  1358. _cellList = U.UF.C.toArray($(".U_MD_O_E_cellCheckd"));
  1359. //判断是否多个单元格选择
  1360. if (req !== true) {
  1361. if (_cellList.length > 1) {
  1362. //如果是则提示无法添加A标签
  1363. U.UF.UI.alertClick('选择范围过多,因此无法编辑');
  1364. } else {
  1365. //否则执行添加A标签操作
  1366. _a = $('a', _cellList[0])[0]; //获取选区中的第一个a标签
  1367. if (_a) {//如果有a标签则执行弹出删除链接的提示框
  1368. _href = _a ? _a.href : '', //如果存在则已第一个a标签做为href
  1369. _text = _editorBox.focusEl.innerText; //获取选区的文字
  1370. _trimtext = _text.trim(); //删除空格字符
  1371. var _box = $$('div'); //创建Confirm最大层div
  1372. var _hrefinput = $$('div', { innerHTML: '<span>链接</span><input style="height:25px;margin-top:5px;width:200px" class="confirm_input" placeholder="网页链接地址" value="' + _href + '" />', style: { 'margin-top': '15px'} }, _box); //创建链接区域
  1373. U.UF.UI.canconfirm(_box, U.UF.C.closure(U.UF.E.addHref.excelConfirm, [_cellList, _hrefinput, _textinput, _trimtext])); //创建Confirm
  1374. } else {
  1375. _href = _a ? _a.href : '', //如果存在则已第一个a标签做为href
  1376. _text = _editorBox.focusEl.innerText; //获取选区的文字
  1377. _trimtext = _text.trim(); //删除空格字符
  1378. var _box = $$('div', { "style": { 'display': 'flex', 'flex-direction': 'column', 'margin-left': '41px'} }); //创建Confirm最大层div
  1379. var _textinput = $$('div', { innerHTML: '<span style="display:block">文本</span><input style="height:25px;margin-top:5px;width:222px" class="confirm_input" value="' + _trimtext + '" />', style: { 'margin-top': '25px'} }, _box); //创建文本区域
  1380. var _hrefinput = $$('div', { innerHTML: '<span style="display:block">链接</span><input style="height:25px;margin-top:5px;width:222px" class="confirm_input" value="http://"' + _href + '" />', style: { 'margin-top': '20px'} }, _box); //创建链接区域
  1381. U.UF.UI.confirm(_box, U.UF.C.closure(U.UF.E.addHref.excelConfirm, [_cellList, _hrefinput, _textinput, _trimtext])); //创建Confirm
  1382. }
  1383. $(".confirm_input").bind('keyup', function (e) {
  1384. U.UF.EV.stopBubble(e); //阻止冒泡
  1385. })
  1386. $(".confirm_input").bind('keydown', function (e) {
  1387. U.UF.EV.stopBubble(e); //阻止冒泡
  1388. })
  1389. $(".confirm_input").bind('keypress', function (e) {
  1390. U.UF.EV.stopBubble(e); //阻止冒泡
  1391. })
  1392. }
  1393. }
  1394. //判断是否发送给后台
  1395. if (req == true) {
  1396. var _data = {
  1397. row: _cellList[0].row,
  1398. col: _cellList[0].col,
  1399. content: _cellList[0].innerHTML
  1400. }
  1401. U.MD.O.E.dataChange(U.MD.O.E.excelInfo("clearAContent", _data));
  1402. }
  1403. };
  1404. /*
  1405. *单元格文字复制
  1406. */
  1407. U.MD.O.E.BC.cloneCell = function () {
  1408. var _clonecorner = $(".U_MD_O_E_borderCorner")[0]; //获取选中的单元格
  1409. $(_clonecorner).bind('mousedown', function (e) {
  1410. var _excel = U.MD.O.E,
  1411. _focusBox = $("#U_MD_O_E_focusBox")[0], //获取选中单元格的最上层
  1412. _editorBox = $("#U_MD_O_E_editorBox")[0], //获取选中单元格的内容层
  1413. _startEl = $(".U_MD_O_E_focus")[0], //获取点击元素
  1414. _startElHtml = _startEl.innerHTML,
  1415. _startX = _startEl.col, //记录x坐标轴 A-Z
  1416. _startY = _startEl.row, //获取y坐标轴 1-200的数字\
  1417. _endX = _startX, //结束点x
  1418. _endY = _startY, //结束点y
  1419. _endPreX = _startX,
  1420. _endPreY = _startY,
  1421. _parent = $(".U_MD_O_E_focus")[0].parentNode,
  1422. _elList,
  1423. _drag = false,
  1424. i,
  1425. j,
  1426. minX = Math.min(_startX, _endX),
  1427. maxX = Math.max(_startX, _endX),
  1428. minY = Math.min(_startY, _endY),
  1429. maxY = Math.max(_startY, _endY),
  1430. _endEl;
  1431. var _drapMove = function (e) {
  1432. //单元格选中
  1433. var _elNum = 0,
  1434. _elList = e.path,
  1435. _endEl = _elList.filter(_filter)[0];
  1436. U.UF.EV.stopBubble(e); //阻止冒泡
  1437. U.UF.EV.stopDefault(e); //取消默认拖拽
  1438. if (!_endEl || !(_endEl.row) || !(_endEl.col)) return; //如果没有自定义属性(其他非单元格元素) 则不判断
  1439. _endX = _endEl.col; //结束点的x坐标
  1440. _endY = _endEl.row; //结束点的y坐标
  1441. if (_endX !== _endPreX || _endY !== _endPreY) { //意思是当鼠标mousemove指向的元素不同时
  1442. _focusBox.style.zIndex = "";
  1443. minX = Math.min(_startX, _endX);
  1444. maxX = Math.max(_startX, _endX);
  1445. minY = Math.min(_startY, _endY);
  1446. maxY = Math.max(_startY, _endY);
  1447. var _cellEl,
  1448. s_mergeCell, //合并单元格元素
  1449. _cellArr = [];
  1450. for (i = minX; i <= maxX; i++) {
  1451. for (j = minY; j <= maxY; j++) {
  1452. _cellEl = $(_parent).find("#POS_" + i + "_" + j)[0];
  1453. _cellEl.s_merge ? s_mergeCell = $(_parent).find("#" + _cellEl.s_merge)[0] : "";
  1454. if (s_mergeCell && _cellArr.indexOf(s_mergeCell) === -1) { //如果选中的是合并单元格的元素
  1455. _endCell = $(_parent).find("#" + _cellEl.e_merge)[0];
  1456. _cellArr.push(s_mergeCell);
  1457. minX = Math.min(minX, s_mergeCell.col, _endCell.col);
  1458. maxX = Math.max(maxX, s_mergeCell.col, _endCell.col);
  1459. minY = Math.min(minY, s_mergeCell.row, _endCell.row);
  1460. maxY = Math.max(maxY, s_mergeCell.row, _endCell.row);
  1461. i = minX;
  1462. j = minY;
  1463. }
  1464. }
  1465. }
  1466. _excel.BC.modifyFocusSize(minX, parseInt(minY), maxX, parseInt(maxY));
  1467. _endPreX = _endX;
  1468. _endPreY = _endY;
  1469. }
  1470. }
  1471. var _drapUp = function (e) {
  1472. //结束事件
  1473. _startEl.style.zIndex = "0";
  1474. _excel.BC.cellAddClass(minX, parseInt(minY), maxX, parseInt(maxY));
  1475. var _allcheckdcell = $(".U_MD_O_E_cellCheckd"),
  1476. _copydata = [];
  1477. for (var k = 0; k < _allcheckdcell.length; k++) {
  1478. _allcheckdcell[k].innerHTML = _startElHtml;
  1479. var _data = {
  1480. row: _allcheckdcell[k].row,
  1481. col: _allcheckdcell[k].col,
  1482. content: _allcheckdcell[k].innerHTML,
  1483. innerText: _allcheckdcell[k].innerText //之所以要发innerText 是因为要用来判断data数据里单元格的内容如果被改为空 则删除掉该单元格的数据
  1484. }; //讲内容打包给后台
  1485. _copydata.push(_data);
  1486. }
  1487. U.MD.O.E.dataChange(U.MD.O.E.excelInfo("blur", _copydata));
  1488. $(document).unbind('mousemove', _drapMove); //结束mousemove事件
  1489. $(document).unbind('mouseup', _drapUp); //结束mouseup事件
  1490. }
  1491. $(document).bind('mousemove', _drapMove);
  1492. $(document).bind('mouseup', _drapUp);
  1493. });
  1494. var _filter = function (d) {
  1495. return d.nodeName === "DIV" && d.col;
  1496. };
  1497. }