sheetBar.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863
  1. import sheetmanage from './sheetmanage';
  2. import server from './server';
  3. import {
  4. sheetselectlistitemHTML,
  5. sheetselectlistHTML,
  6. keycode,
  7. } from './constant';
  8. import { replaceHtml, mouseclickposition } from '../utils/util';
  9. import { getSheetIndex } from '../methods/get';
  10. import { isEditMode } from '../global/validate';
  11. import formula from '../global/formula';
  12. import cleargridelement from '../global/cleargridelement';
  13. import tooltip from '../global/tooltip';
  14. selectTextDom;
  15. import { selectTextDom } from '../global/cursorPos';
  16. import locale from '../locale/locale';
  17. import Store from '../store';
  18. import luckysheetConfigsetting from './luckysheetConfigsetting';
  19. import { pagerInit } from '../global/api';
  20. import method from '../global/method';
  21. //表格底部名称栏区域 相关事件(增、删、改、隐藏显示、颜色等等)
  22. let isInitialSheetConfig = false,
  23. luckysheetcurrentSheetitem = null,
  24. jfdbclicklagTimeout = null,
  25. oldSheetFileName = '';
  26. function showsheetconfigmenu() {
  27. if (!isInitialSheetConfig) {
  28. isInitialSheetConfig = true;
  29. const _locale = locale();
  30. let locale_toolbar = _locale.toolbar;
  31. $('#luckysheetsheetconfigcolorur').spectrum({
  32. showPalette: true,
  33. preferredFormat: 'hex',
  34. clickoutFiresChange: false,
  35. showInitial: true,
  36. showInput: true,
  37. flat: true,
  38. hideAfterPaletteSelect: false,
  39. showSelectionPalette: true,
  40. maxPaletteSize: 10,
  41. cancelText: _locale.sheetconfig.cancelText,
  42. chooseText: _locale.sheetconfig.chooseText,
  43. togglePaletteMoreText: locale_toolbar.toolMore,
  44. togglePaletteLessText: locale_toolbar.toolLess,
  45. clearText: locale_toolbar.clearText,
  46. noColorSelectedText: locale_toolbar.noColorSelectedText,
  47. palette: [
  48. [
  49. 'rgb(0, 0, 0)',
  50. 'rgb(67, 67, 67)',
  51. 'rgb(102, 102, 102)',
  52. 'rgb(204, 204, 204)',
  53. 'rgb(217, 217, 217)',
  54. 'rgb(255, 255, 255)',
  55. ],
  56. [
  57. 'rgb(152, 0, 0)',
  58. 'rgb(255, 0, 0)',
  59. 'rgb(255, 153, 0)',
  60. 'rgb(255, 255, 0)',
  61. 'rgb(0, 255, 0)',
  62. 'rgb(0, 255, 255)',
  63. 'rgb(74, 134, 232)',
  64. 'rgb(0, 0, 255)',
  65. 'rgb(153, 0, 255)',
  66. 'rgb(255, 0, 255)',
  67. ],
  68. [
  69. 'rgb(230, 184, 175)',
  70. 'rgb(244, 204, 204)',
  71. 'rgb(252, 229, 205)',
  72. 'rgb(255, 242, 204)',
  73. 'rgb(217, 234, 211)',
  74. 'rgb(208, 224, 227)',
  75. 'rgb(201, 218, 248)',
  76. 'rgb(207, 226, 243)',
  77. 'rgb(217, 210, 233)',
  78. 'rgb(234, 209, 220)',
  79. ],
  80. [
  81. 'rgb(221, 126, 107)',
  82. 'rgb(234, 153, 153)',
  83. 'rgb(249, 203, 156)',
  84. 'rgb(255, 229, 153)',
  85. 'rgb(182, 215, 168)',
  86. 'rgb(162, 196, 201)',
  87. 'rgb(164, 194, 244)',
  88. 'rgb(159, 197, 232)',
  89. 'rgb(180, 167, 214)',
  90. 'rgb(213, 166, 189)',
  91. ],
  92. [
  93. 'rgb(204, 65, 37)',
  94. 'rgb(224, 102, 102)',
  95. 'rgb(246, 178, 107)',
  96. 'rgb(255, 217, 102)',
  97. 'rgb(147, 196, 125)',
  98. 'rgb(118, 165, 175)',
  99. 'rgb(109, 158, 235)',
  100. 'rgb(111, 168, 220)',
  101. 'rgb(142, 124, 195)',
  102. 'rgb(194, 123, 160)',
  103. ],
  104. [
  105. 'rgb(166, 28, 0)',
  106. 'rgb(204, 0, 0)',
  107. 'rgb(230, 145, 56)',
  108. 'rgb(241, 194, 50)',
  109. 'rgb(106, 168, 79)',
  110. 'rgb(69, 129, 142)',
  111. 'rgb(60, 120, 216)',
  112. 'rgb(61, 133, 198)',
  113. 'rgb(103, 78, 167)',
  114. 'rgb(166, 77, 121)',
  115. ],
  116. [
  117. 'rgb(91, 15, 0)',
  118. 'rgb(102, 0, 0)',
  119. 'rgb(120, 63, 4)',
  120. 'rgb(127, 96, 0)',
  121. 'rgb(39, 78, 19)',
  122. 'rgb(12, 52, 61)',
  123. 'rgb(28, 69, 135)',
  124. 'rgb(7, 55, 99)',
  125. 'rgb(32, 18, 77)',
  126. 'rgb(76, 17, 48)',
  127. ],
  128. [
  129. '#c1232b',
  130. '#27727b',
  131. '#fcce10',
  132. '#e87c25',
  133. '#b5c334',
  134. '#fe8463',
  135. '#9bca63',
  136. '#fad860',
  137. '#f3a43b',
  138. '#60c0dd',
  139. '#d7504b',
  140. '#c6e579',
  141. '#f4e001',
  142. '#f0805a',
  143. '#26c0c0',
  144. '#c12e34',
  145. '#e6b600',
  146. '#0098d9',
  147. '#2b821d',
  148. '#005eaa',
  149. '#339ca8',
  150. '#cda819',
  151. '#32a487',
  152. '#3fb1e3',
  153. '#6be6c1',
  154. '#626c91',
  155. '#a0a7e6',
  156. '#c4ebad',
  157. '#96dee8',
  158. ],
  159. ],
  160. change: function(color) {
  161. let $input = $(this);
  162. if (color != null) {
  163. color = color.toHexString();
  164. } else {
  165. color = 'rgb(0, 0, 0)';
  166. }
  167. let oldcolor = null;
  168. if (
  169. luckysheetcurrentSheetitem.find('.luckysheet-sheets-item-color')
  170. .length > 0
  171. ) {
  172. oldcolor = luckysheetcurrentSheetitem
  173. .find('.luckysheet-sheets-item-color')
  174. .css('background-color');
  175. }
  176. luckysheetcurrentSheetitem
  177. .find('.luckysheet-sheets-item-color')
  178. .remove();
  179. luckysheetcurrentSheetitem.append(
  180. '<div class="luckysheet-sheets-item-color" style=" position: absolute; width: 100%; height: 3px; bottom: 0px; left: 0px; background-color: ' +
  181. color +
  182. ';"></div>'
  183. );
  184. let index = getSheetIndex(Store.currentSheetIndex);
  185. Store.luckysheetfile[index].color = color;
  186. server.saveParam('all', Store.currentSheetIndex, color, { k: 'color' });
  187. if (Store.clearjfundo) {
  188. let redo = {};
  189. redo['type'] = 'sheetColor';
  190. redo['sheetIndex'] = Store.currentSheetIndex;
  191. redo['oldcolor'] = oldcolor;
  192. redo['color'] = color;
  193. Store.jfundo.length = 0;
  194. Store.jfredo.push(redo);
  195. }
  196. },
  197. });
  198. $('#luckysheetsheetconfigcolorreset').click(function() {
  199. let oldcolor = null;
  200. if (
  201. luckysheetcurrentSheetitem.find('.luckysheet-sheets-item-color')
  202. .length > 0
  203. ) {
  204. oldcolor = luckysheetcurrentSheetitem
  205. .find('.luckysheet-sheets-item-color')
  206. .css('background-color');
  207. }
  208. luckysheetcurrentSheetitem.find('.luckysheet-sheets-item-color').remove();
  209. let index = getSheetIndex(Store.currentSheetIndex);
  210. Store.luckysheetfile[index].color = null;
  211. server.saveParam('all', Store.currentSheetIndex, null, { k: 'color' });
  212. if (Store.clearjfundo) {
  213. let redo = {};
  214. redo['type'] = 'sheetColor';
  215. redo['sheetIndex'] = Store.currentSheetIndex;
  216. redo['oldcolor'] = oldcolor;
  217. redo['color'] = null;
  218. Store.jfundo.length = 0;
  219. Store.jfredo.push(redo);
  220. }
  221. });
  222. }
  223. let index = getSheetIndex(Store.currentSheetIndex);
  224. if (
  225. Store.luckysheetfile[index].color != null &&
  226. Store.luckysheetfile[index].color.length > 0
  227. ) {
  228. $('#luckysheetsheetconfigcolorur').spectrum(
  229. 'set',
  230. Store.luckysheetfile[index].color
  231. );
  232. }
  233. $('#luckysheetsheetconfigcolorur')
  234. .parent()
  235. .find('span, div, button, input, a')
  236. .addClass('luckysheet-mousedown-cancel');
  237. // 如果全部按钮设置了隐藏,则不显示
  238. const config = luckysheetConfigsetting.sheetRightClickConfig;
  239. // if(!config.delete && !config.copy && !config.rename && !config.color && !config.hide && !config.move){
  240. if (Object.values(config).every((ele) => !ele)) {
  241. return;
  242. }
  243. setTimeout(function() {
  244. mouseclickposition(
  245. $('#luckysheet-rightclick-sheet-menu'),
  246. luckysheetcurrentSheetitem.offset().left +
  247. luckysheetcurrentSheetitem.width(),
  248. luckysheetcurrentSheetitem.offset().top - 18,
  249. 'leftbottom'
  250. );
  251. }, 1);
  252. }
  253. let luckysheetsheetrightclick = function($t, $cur, e) {
  254. clearTimeout(jfdbclicklagTimeout);
  255. if (
  256. $cur.hasClass('luckysheet-sheets-item-name') &&
  257. $cur.attr('contenteditable') == 'true'
  258. ) {
  259. return;
  260. }
  261. if (
  262. formula.rangestart ||
  263. formula.rangedrag_column_start ||
  264. formula.rangedrag_row_start ||
  265. formula.israngeseleciton()
  266. ) {
  267. setTimeout(function() {
  268. formula.setCaretPosition(
  269. formula.rangeSetValueTo.get(0),
  270. 0,
  271. formula.rangeSetValueTo.text().length
  272. );
  273. formula.createRangeHightlight();
  274. $('#luckysheet-input-box-index')
  275. .find('.luckysheet-input-box-index-sheettxt')
  276. .remove()
  277. .end()
  278. .prepend(
  279. "<span class='luckysheet-input-box-index-sheettxt'>" +
  280. sheetmanage.getSheetName(formula.rangetosheet) +
  281. '!</span>'
  282. )
  283. .show();
  284. $('#luckysheet-input-box-index').css({
  285. left: $('#luckysheet-input-box').css('left'),
  286. top: parseInt($('#luckysheet-input-box').css('top')) - 20 + 'px',
  287. 'z-index': $('#luckysheet-input-box').css('z-index'),
  288. });
  289. }, 1);
  290. } else {
  291. //保存正在编辑的单元格内容
  292. if (parseInt($('#luckysheet-input-box').css('top')) > 0) {
  293. formula.updatecell(
  294. Store.luckysheetCellUpdate[0],
  295. Store.luckysheetCellUpdate[1]
  296. );
  297. }
  298. $('#luckysheet-input-box').removeAttr('style');
  299. $(
  300. '#luckysheet-formula-functionrange .luckysheet-formula-functionrange-highlight'
  301. ).remove();
  302. }
  303. $('#luckysheet-sheet-area div.luckysheet-sheets-item').removeClass(
  304. 'luckysheet-sheets-item-active'
  305. );
  306. $t.addClass('luckysheet-sheets-item-active');
  307. cleargridelement(e);
  308. sheetmanage.changeSheet($t.data('index'));
  309. $('#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu').hide();
  310. if (
  311. $cur.hasClass('luckysheet-sheets-item-menu') ||
  312. $cur.hasClass('fa-sort-desc') ||
  313. e.which == '3'
  314. ) {
  315. luckysheetcurrentSheetitem = $cur.closest('.luckysheet-sheets-item');
  316. showsheetconfigmenu();
  317. }
  318. };
  319. export function initialSheetBar() {
  320. const _locale = locale();
  321. const locale_sheetconfig = _locale.sheetconfig;
  322. isInitialSheetConfig = false;
  323. $('#luckysheet-sheet-area')
  324. .on('mousedown', 'div.luckysheet-sheets-item', function(e) {
  325. if (isEditMode()) {
  326. // alert("非编辑模式下不允许该操作!");
  327. return;
  328. }
  329. let $t = $(this),
  330. $cur = $(e.target),
  331. $item = $cur.closest('.luckysheet-sheets-item');
  332. if (e.which == '3') {
  333. setTimeout(() => {
  334. luckysheetsheetrightclick($t, $cur, e);
  335. luckysheetcurrentSheetitem = $item;
  336. showsheetconfigmenu();
  337. return;
  338. }, 0);
  339. }
  340. if (
  341. $item.hasClass('luckysheet-sheets-item-active') &&
  342. $item.find('.luckysheet-sheets-item-name').attr('contenteditable') ==
  343. 'false'
  344. ) {
  345. jfdbclicklagTimeout = setTimeout(function() {
  346. Store.luckysheet_sheet_move_status = true;
  347. Store.luckysheet_sheet_move_data = {};
  348. Store.luckysheet_sheet_move_data.widthlist = [];
  349. $('#luckysheet-sheet-area div.luckysheet-sheets-item:visible').each(
  350. function(i) {
  351. if (i == 0) {
  352. Store.luckysheet_sheet_move_data.widthlist.push(
  353. parseInt($(this).outerWidth())
  354. );
  355. } else {
  356. Store.luckysheet_sheet_move_data.widthlist.push(
  357. parseInt($(this).outerWidth()) +
  358. Store.luckysheet_sheet_move_data.widthlist[i - 1]
  359. );
  360. }
  361. }
  362. );
  363. Store.luckysheet_sheet_move_data.curindex = $(
  364. '#luckysheet-sheet-area div.luckysheet-sheets-item'
  365. ).index($item);
  366. let x = e.pageX;
  367. Store.luckysheet_sheet_move_data.curleft = x - $item.offset().left;
  368. Store.luckysheet_sheet_move_data.pageX = x;
  369. Store.luckysheet_sheet_move_data.activeobject = $item;
  370. Store.luckysheet_sheet_move_data.cursorobject = $cur;
  371. let $itemclone = $item
  372. .clone()
  373. .css('visibility', 'hidden')
  374. .attr('id', 'luckysheet-sheets-item-clone');
  375. $item.after($itemclone);
  376. $item.css({
  377. position: 'absolute',
  378. opacity: 0.8,
  379. cursor: 'move',
  380. transition: 'initial',
  381. 'z-index': 10,
  382. });
  383. }, 200);
  384. }
  385. })
  386. .on('click', 'div.luckysheet-sheets-item', function(e) {
  387. if (isEditMode()) {
  388. // alert("非编辑模式下不允许该操作!");
  389. return;
  390. }
  391. let $t = $(this),
  392. $cur = $(e.target);
  393. luckysheetsheetrightclick($t, $cur, e);
  394. server.keepHighLightBox();
  395. });
  396. let luckysheetsheetnameeditor = function($t) {
  397. if (Store.allowEdit === false) {
  398. return;
  399. }
  400. $t.attr('contenteditable', 'true')
  401. .addClass('luckysheet-mousedown-cancel')
  402. .data('oldtxt', $t.text());
  403. setTimeout(function() {
  404. selectTextDom($t.get(0));
  405. }, 1);
  406. };
  407. $('#luckysheet-sheet-area').on(
  408. 'dblclick',
  409. 'span.luckysheet-sheets-item-name',
  410. function(e) {
  411. luckysheetsheetnameeditor($(this));
  412. }
  413. );
  414. let compositionFlag = true;
  415. $('#luckysheet-sheet-area').on(
  416. 'compositionstart',
  417. 'span.luckysheet-sheets-item-name',
  418. () => (compositionFlag = false)
  419. );
  420. $('#luckysheet-sheet-area').on(
  421. 'compositionend',
  422. 'span.luckysheet-sheets-item-name',
  423. () => (compositionFlag = true)
  424. );
  425. $('#luckysheet-sheet-area').on(
  426. 'input',
  427. 'span.luckysheet-sheets-item-name',
  428. function() {
  429. if (Store.allowEdit === false) {
  430. return;
  431. }
  432. if (Store.limitSheetNameLength === false) {
  433. return;
  434. }
  435. let maxLength = Store.defaultSheetNameMaxLength;
  436. if (maxLength === 0) {
  437. return;
  438. }
  439. setTimeout(() => {
  440. if (compositionFlag) {
  441. if ($(this).text().length >= maxLength) {
  442. /* 检查:值是否越界 */
  443. setTimeout(() => {
  444. $(this).text(
  445. $(this)
  446. .text()
  447. .substring(0, maxLength)
  448. );
  449. let range = window.getSelection();
  450. range.selectAllChildren(this);
  451. range.collapseToEnd();
  452. }, 0);
  453. }
  454. }
  455. }, 0);
  456. }
  457. );
  458. $('#luckysheet-sheet-area').on(
  459. 'blur',
  460. 'span.luckysheet-sheets-item-name',
  461. function(e) {
  462. if (Store.allowEdit === false) {
  463. return;
  464. }
  465. let $t = $(this);
  466. let txt = $t.text(),
  467. oldtxt = $t.data('oldtxt');
  468. if (0 === $(this).text().length) {
  469. tooltip.info('', locale_sheetconfig.sheetNamecannotIsEmptyError);
  470. $t.text(oldtxt).attr('contenteditable', 'false');
  471. return;
  472. }
  473. if (
  474. txt.length > 31 ||
  475. txt.charAt(0) == "'" ||
  476. txt.charAt(txt.length - 1) == "'" ||
  477. /[:\:\\\/?\?\*\[\]]+/.test(txt)
  478. ) {
  479. tooltip.info('', locale_sheetconfig.sheetNameSpecCharError);
  480. $t.text(oldtxt).attr('contenteditable', 'false');
  481. return;
  482. }
  483. let index = getSheetIndex(Store.currentSheetIndex);
  484. for (let i = 0; i < Store.luckysheetfile.length; i++) {
  485. if (index != i && Store.luckysheetfile[i].name == txt) {
  486. if (isEditMode()) {
  487. alert(locale_sheetconfig.tipNameRepeat);
  488. } else {
  489. tooltip.info('', locale_sheetconfig.tipNameRepeat);
  490. }
  491. $t.text(oldtxt).attr('contenteditable', 'false');
  492. return;
  493. }
  494. }
  495. sheetmanage.sheetArrowShowAndHide();
  496. Store.luckysheetfile[index].name = txt;
  497. server.saveParam('all', Store.currentSheetIndex, txt, { k: 'name' });
  498. $t.attr('contenteditable', 'false').removeClass(
  499. 'luckysheet-mousedown-cancel'
  500. );
  501. if (Store.clearjfundo) {
  502. let redo = {};
  503. redo['type'] = 'sheetName';
  504. redo['sheetIndex'] = Store.currentSheetIndex;
  505. redo['oldtxt'] = oldtxt;
  506. redo['txt'] = txt;
  507. Store.jfundo.length = 0;
  508. Store.jfredo.push(redo);
  509. }
  510. // 钩子: sheetEditNameAfter
  511. method.createHookFunction('sheetEditNameAfter', {
  512. i: Store.luckysheetfile[index].index,
  513. oldName: oldtxt,
  514. newName: txt,
  515. });
  516. }
  517. );
  518. $('#luckysheet-sheet-area').on(
  519. 'keydown',
  520. 'span.luckysheet-sheets-item-name',
  521. function(e) {
  522. if (Store.allowEdit === false) {
  523. return;
  524. }
  525. let kcode = e.keyCode;
  526. let $t = $(this);
  527. if (kcode == keycode.ENTER) {
  528. let index = getSheetIndex(Store.currentSheetIndex);
  529. oldSheetFileName = Store.luckysheetfile[index].name || oldSheetFileName;
  530. Store.luckysheetfile[index].name = $t.text();
  531. $t.attr('contenteditable', 'false');
  532. }
  533. }
  534. );
  535. $('#luckysheetsheetconfigrename').click(function() {
  536. var $name = luckysheetcurrentSheetitem.find(
  537. 'span.luckysheet-sheets-item-name'
  538. );
  539. // 钩子 sheetEditNameBefore
  540. if (
  541. !method.createHookFunction('sheetEditNameBefore', {
  542. i: luckysheetcurrentSheetitem.data('index'),
  543. name: $name.text(),
  544. })
  545. ) {
  546. return;
  547. }
  548. luckysheetsheetnameeditor(
  549. luckysheetcurrentSheetitem.find('span.luckysheet-sheets-item-name')
  550. );
  551. $('#luckysheet-input-box').removeAttr('style');
  552. $('#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu').hide();
  553. });
  554. $('#luckysheetsheetconfigshow').click(function() {
  555. $('#luckysheet-sheets-m').click();
  556. $('#luckysheet-input-box').removeAttr('style');
  557. $('#luckysheet-rightclick-sheet-menu').hide();
  558. });
  559. $('#luckysheetsheetconfigmoveleft').click(function() {
  560. if (luckysheetcurrentSheetitem.prevAll(':visible').length > 0) {
  561. luckysheetcurrentSheetitem.insertBefore(
  562. luckysheetcurrentSheetitem.prevAll(':visible').eq(0)
  563. );
  564. sheetmanage.reOrderAllSheet();
  565. }
  566. $('#luckysheet-input-box').removeAttr('style');
  567. $('#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu').hide();
  568. });
  569. $('#luckysheetsheetconfigmoveright').click(function() {
  570. if (luckysheetcurrentSheetitem.nextAll(':visible').length > 0) {
  571. luckysheetcurrentSheetitem.insertAfter(
  572. luckysheetcurrentSheetitem.nextAll(':visible').eq(0)
  573. );
  574. sheetmanage.reOrderAllSheet();
  575. }
  576. $('#luckysheet-input-box').removeAttr('style');
  577. $('#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu').hide();
  578. });
  579. $('#luckysheetsheetconfigdelete').click(function(e) {
  580. $('#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu').hide();
  581. if (
  582. $('#luckysheet-sheet-container-c .luckysheet-sheets-item:visible')
  583. .length <= 1
  584. ) {
  585. if (isEditMode()) {
  586. alert(locale_sheetconfig.noMoreSheet);
  587. } else {
  588. tooltip.info(locale_sheetconfig.noMoreSheet, '');
  589. }
  590. return;
  591. }
  592. let index = getSheetIndex(Store.currentSheetIndex);
  593. tooltip.confirm(
  594. locale_sheetconfig.confirmDelete +
  595. '【' +
  596. Store.luckysheetfile[index].name +
  597. '】?',
  598. "<span style='color:#9e9e9e;font-size:12px;'>" +
  599. locale_sheetconfig.redoDelete +
  600. '</span>',
  601. function() {
  602. sheetmanage.deleteSheet(luckysheetcurrentSheetitem.data('index'));
  603. },
  604. null
  605. );
  606. $('#luckysheet-input-box').removeAttr('style');
  607. });
  608. $('#luckysheetsheetconfigdeleteother').click(function(e) {
  609. $('#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu').hide();
  610. if (
  611. $('#luckysheet-sheet-container-c .luckysheet-sheets-item:visible')
  612. .length <= 1
  613. ) {
  614. if (isEditMode()) {
  615. alert(locale_sheetconfig.noMoreSheet);
  616. } else {
  617. tooltip.info(locale_sheetconfig.noMoreSheet, '');
  618. }
  619. return;
  620. }
  621. let index = getSheetIndex(Store.currentSheetIndex);
  622. tooltip.confirm(
  623. locale_sheetconfig.confirmDeleteOther +
  624. '【' +
  625. Store.luckysheetfile[index].name +
  626. '】?',
  627. "<span style='color:#9e9e9e;font-size:12px;'>" +
  628. locale_sheetconfig.redoDelete +
  629. '</span>',
  630. function() {
  631. sheetmanage.deleteOtherSheet(luckysheetcurrentSheetitem.data('index'));
  632. },
  633. null
  634. );
  635. $('#luckysheet-input-box').removeAttr('style');
  636. });
  637. $('#luckysheetsheetconfigcopy').click(function(e) {
  638. sheetmanage.copySheet(luckysheetcurrentSheetitem.data('index'), e);
  639. $('#luckysheet-input-box').removeAttr('style');
  640. $('#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu').hide();
  641. });
  642. $('#luckysheetsheetconfighide').click(function() {
  643. if (
  644. $('#luckysheet-sheet-area div.luckysheet-sheets-item:visible').length == 1
  645. ) {
  646. if (isEditMode()) {
  647. alert(locale_sheetconfig.noHide);
  648. } else {
  649. tooltip.info('', locale_sheetconfig.noHide);
  650. }
  651. return;
  652. }
  653. sheetmanage.setSheetHide(luckysheetcurrentSheetitem.data('index'));
  654. $('#luckysheet-input-box').removeAttr('style');
  655. $('#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu').hide();
  656. });
  657. $('#luckysheet-sheets-add').click(function(e) {
  658. //保存正在编辑的单元格内容
  659. if (parseInt($('#luckysheet-input-box').css('top')) > 0) {
  660. formula.updatecell(
  661. Store.luckysheetCellUpdate[0],
  662. Store.luckysheetCellUpdate[1]
  663. );
  664. }
  665. sheetmanage.addNewSheet(e);
  666. sheetmanage.locationSheet();
  667. $('#luckysheet-input-box').removeAttr('style');
  668. });
  669. let sheetscrollani = null,
  670. sheetscrollstart = 0,
  671. sheetscrollend = 0,
  672. sheetscrollstep = 150;
  673. $('#luckysheet-sheets-leftscroll').click(function() {
  674. let $c = $('#luckysheet-sheet-container-c');
  675. sheetscrollstart = $c.scrollLeft();
  676. sheetscrollend = $c.scrollLeft() - sheetscrollstep;
  677. if (sheetscrollend <= 0) {
  678. $('#luckysheet-sheet-container .docs-sheet-fade-left').hide();
  679. }
  680. $('#luckysheet-sheet-container .docs-sheet-fade-right').show();
  681. clearInterval(sheetscrollani);
  682. sheetscrollani = setInterval(function() {
  683. sheetscrollstart -= 4;
  684. $c.scrollLeft(sheetscrollstart);
  685. if (sheetscrollstart <= sheetscrollend) {
  686. clearInterval(sheetscrollani);
  687. }
  688. }, 1);
  689. });
  690. $('#luckysheet-sheets-rightscroll').click(function() {
  691. let $c = $('#luckysheet-sheet-container-c');
  692. sheetscrollstart = $c.scrollLeft();
  693. sheetscrollend = $c.scrollLeft() + sheetscrollstep;
  694. if (sheetscrollstart > 0) {
  695. $('#luckysheet-sheet-container .docs-sheet-fade-right').hide();
  696. }
  697. $('#luckysheet-sheet-container .docs-sheet-fade-left').show();
  698. clearInterval(sheetscrollani);
  699. sheetscrollani = setInterval(function() {
  700. sheetscrollstart += 4;
  701. $c.scrollLeft(sheetscrollstart);
  702. if (sheetscrollstart >= sheetscrollend) {
  703. clearInterval(sheetscrollani);
  704. }
  705. }, 1);
  706. });
  707. let initialOpenSheet = true;
  708. $('#luckysheet-sheets-m').click(function(e) {
  709. //保存正在编辑的单元格内容
  710. if (parseInt($('#luckysheet-input-box').css('top')) > 0) {
  711. formula.updatecell(
  712. Store.luckysheetCellUpdate[0],
  713. Store.luckysheetCellUpdate[1]
  714. );
  715. }
  716. $('#luckysheet-sheet-list').html('');
  717. let item = '';
  718. for (let i = 0; i < Store.luckysheetfile.length; i++) {
  719. let f = Store.luckysheetfile[i],
  720. icon = '',
  721. style = '';
  722. if (f['status'] == 1) {
  723. icon = '<i class="fa fa-check" aria-hidden="true"></i>';
  724. }
  725. if (f['hide'] == 1) {
  726. continue;
  727. icon = '<i class="fa fa-low-vision" aria-hidden="true"></i>';
  728. style += 'color:#BBBBBB;';
  729. }
  730. if (f['color'] != null && f['color'].length > 0) {
  731. style += 'border-right:4px solid ' + f['color'] + ';';
  732. }
  733. item += replaceHtml(sheetselectlistitemHTML, {
  734. index: f['index'],
  735. name: f['name'],
  736. icon: icon,
  737. style: style,
  738. });
  739. }
  740. if (initialOpenSheet) {
  741. $('#' + Store.container).append(
  742. replaceHtml(sheetselectlistHTML, { item: item })
  743. );
  744. $('#luckysheet-sheet-list').on(
  745. 'click',
  746. '.luckysheet-cols-menuitem',
  747. function(e) {
  748. if (isEditMode()) {
  749. // tooltip.info("提示", "图表编辑模式下不允许该操作!");
  750. alert(locale_sheetconfig.chartEditNoOpt);
  751. return;
  752. }
  753. let $item = $(this),
  754. index = $item.data('index');
  755. if ($item.data('index') != Store.currentSheetIndex) {
  756. sheetmanage.setSheetShow(index);
  757. sheetmanage.locationSheet();
  758. }
  759. server.keepHighLightBox();
  760. }
  761. );
  762. initialOpenSheet = false;
  763. } else {
  764. $('#luckysheet-sheet-list').html(item);
  765. }
  766. let $t = $('#luckysheet-sheet-list');
  767. let left = $(this).offset().left - $('#' + Store.container).offset().left;
  768. let bottom = $(this).height() + $('#luckysheet-sta-content').height() + 12;
  769. $t.css({ left: left + 'px', bottom: bottom + 'px' }).show();
  770. $('#luckysheet-input-box').removeAttr('style');
  771. });
  772. // 初始化分页器
  773. if (luckysheetConfigsetting.pager) {
  774. pagerInit(luckysheetConfigsetting.pager);
  775. }
  776. }