sheetmanage.js 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029
  1. import { isEditMode } from '../global/validate';
  2. import cleargridelement from '../global/cleargridelement';
  3. import { getcellvalue, datagridgrowth,getcellFormula } from '../global/getdata';
  4. import { setcellvalue } from '../global/setdata';
  5. import luckysheetcreatedom from '../global/createdom';
  6. import tooltip from '../global/tooltip';
  7. import formula from '../global/formula';
  8. import { luckysheetrefreshgrid, jfrefreshgrid_rhcw } from '../global/refresh';
  9. import rhchInit from '../global/rhchInit';
  10. import editor from '../global/editor';
  11. import { luckysheetextendtable, luckysheetdeletetable } from '../global/extend';
  12. import { isRealNum } from '../global/validate';
  13. import { replaceHtml, getObjType, chatatABC, arrayRemoveItem } from '../utils/util';
  14. import { sheetHTML,luckysheetlodingHTML } from './constant';
  15. import server from './server';
  16. import luckysheetConfigsetting from './luckysheetConfigsetting';
  17. import pivotTable from './pivotTable';
  18. import luckysheetsizeauto from './resize';
  19. import luckysheetPostil from './postil';
  20. import imageCtrl from './imageCtrl';
  21. import dataVerificationCtrl from './dataVerificationCtrl';
  22. import hyperlinkCtrl from './hyperlinkCtrl';
  23. import luckysheetFreezen from './freezen';
  24. import { createFilterOptions, labelFilterOptionState } from './filter';
  25. import { selectHightlightShow, selectionCopyShow } from './select';
  26. import Store from '../store';
  27. import locale from '../locale/locale';
  28. import { renderChartShow } from '../expendPlugins/chart/plugin';
  29. import {changeSheetContainerSize, menuToolBarWidth} from './resize';
  30. import {zoomNumberDomBind} from './zoom';
  31. import menuButton from './menuButton';
  32. import method from '../global/method';
  33. const sheetmanage = {
  34. generateRandomSheetIndex: function(prefix) {
  35. if(prefix == null){
  36. prefix = "Sheet";
  37. }
  38. let userAgent = window.navigator.userAgent.replace(/[^a-zA-Z0-9]/g, "").split("");
  39. let mid = "";
  40. for(let i = 0; i < 12; i++){
  41. mid += userAgent[Math.round(Math.random() * (userAgent.length - 1))];
  42. }
  43. let time = new Date().getTime();
  44. return prefix + "_" + mid + "_" + time;
  45. },
  46. generateRandomSheetName: function(file, isPivotTable) {
  47. let index = file.length;
  48. const locale_pivotTable = locale().pivotTable;
  49. const title = locale_pivotTable.title;
  50. for(let i = 0; i < file.length; i++){
  51. if(file[i].name.indexOf("Sheet") > -1 || file[i].name.indexOf(title) > -1){
  52. let suffix = parseFloat(file[i].name.replace("Sheet", "").replace(title, ""));
  53. if(suffix != "NaN" && Math.ceil(suffix) > index){
  54. index = Math.ceil(suffix);
  55. }
  56. }
  57. }
  58. if(isPivotTable){
  59. return title + (index + 1);
  60. }
  61. else{
  62. return "Sheet" + (index + 1);
  63. }
  64. },
  65. generateCopySheetName: function(file, name) {
  66. let _locale = locale();
  67. let locale_info = _locale.info;
  68. let copyWord = "(" + locale_info.copy;
  69. const copy_i = name.toString().indexOf(copyWord);
  70. if (~copy_i) {
  71. name = name.toString().substring(0, copy_i);
  72. }
  73. let index = "";
  74. let nameCopy = name + copyWord;
  75. const sheetNames = [];
  76. for (let i = 0; i < file.length; i++) {
  77. let fileName = file[i].name.toString();
  78. sheetNames.push(fileName);
  79. let st_i = fileName.indexOf(nameCopy);
  80. if(st_i === 0) {
  81. index = index || 2;
  82. let ed_i = fileName.indexOf(")", st_i + nameCopy.length);
  83. let num = fileName.substring(st_i + nameCopy.length, ed_i);
  84. if (isRealNum(num)) {
  85. if(parseInt(num) >= index){
  86. index = parseInt(num) + 1;
  87. }
  88. }
  89. }
  90. }
  91. let sheetCopyName;
  92. do {
  93. let postfix = copyWord + index + ")";
  94. const lengthLimit = 31 - postfix.length;
  95. sheetCopyName = name;
  96. if (sheetCopyName.length > lengthLimit) {
  97. sheetCopyName = sheetCopyName.slice(0, lengthLimit - 1) + "…";
  98. }
  99. sheetCopyName = sheetCopyName + postfix;
  100. } while (~sheetNames.indexOf(sheetCopyName) && (index = (index || 1) + 1))
  101. return sheetCopyName;
  102. },
  103. getSheetByIndex: function(index) {
  104. let _this = this;
  105. if(index == null){
  106. index = Store.currentSheetIndex;
  107. }
  108. let i = _this.getSheetIndex(index);
  109. return Store.luckysheetfile[i];
  110. },
  111. getSheetByName: function(name) {
  112. let _this = this;
  113. if(name == null){
  114. return null;
  115. }
  116. for(let i=0;i<Store.luckysheetfile.length;i++){
  117. let file = Store.luckysheetfile[i];
  118. if(file.name==name){
  119. return file;
  120. }
  121. }
  122. return null;
  123. },
  124. getCurSheetnoset: function() {
  125. let curindex = 0;
  126. for (let i = 0; i < Store.luckysheetfile.length; i++) {
  127. if (Store.luckysheetfile[i].status == 1) {
  128. curindex = Store.luckysheetfile[i].index;
  129. break;
  130. }
  131. }
  132. return curindex;
  133. },
  134. getCurSheet: function() {
  135. if (Store.luckysheetfile.length) {
  136. let hasActive = false, indexs = []
  137. Store.luckysheetfile.forEach(item => {
  138. if ('undefined' === typeof item.index) {
  139. item.index = this.generateRandomSheetIndex()
  140. }
  141. if (indexs.includes(item.index)) {
  142. item.index = this.generateRandomSheetIndex()
  143. }else {
  144. indexs.push(item.index)
  145. }
  146. if ('undefined' === typeof item.status) {
  147. item.status = 0
  148. }
  149. if (item.status == 1) {
  150. if (hasActive) {
  151. item.status = 0
  152. }else {
  153. hasActive = true
  154. }
  155. }
  156. })
  157. if (!hasActive) {
  158. Store.luckysheetfile[0].status = 1
  159. }
  160. }
  161. Store.currentSheetIndex = Store.luckysheetfile[0].index;
  162. for (let i = 0; i < Store.luckysheetfile.length; i++) {
  163. if (Store.luckysheetfile[i].status == 1) {
  164. Store.currentSheetIndex = Store.luckysheetfile[i].index;
  165. break;
  166. }
  167. }
  168. return Store.currentSheetIndex;
  169. },
  170. addNewSheet: function(e, isPivotTable) {
  171. if(isEditMode() || Store.allowEdit===false){
  172. // alert("非编辑模式下不允许该操作!");
  173. return;
  174. }
  175. // 钩子 sheetCreateBefore
  176. if(!method.createHookFunction('sheetCreateBefore')){
  177. return;
  178. }
  179. let _this = this;
  180. let order = Store.luckysheetfile.length;
  181. let index = _this.generateRandomSheetIndex();
  182. let sheetname = _this.generateRandomSheetName(Store.luckysheetfile, isPivotTable);
  183. $("#luckysheet-sheet-container-c").append(replaceHtml(sheetHTML, { "index": index, "active": "", "name": sheetname, "style": "","colorset":"" }));
  184. let sheetconfig = {
  185. "name": sheetname,
  186. "color": "",
  187. "status": "0",
  188. "order": order,
  189. "index": index,
  190. "celldata": [],
  191. "row": Store.defaultrowNum,
  192. "column": Store.defaultcolumnNum,
  193. "config": {},
  194. "pivotTable": null,
  195. "isPivotTable": !!isPivotTable
  196. };
  197. Store.luckysheetfile.push(sheetconfig);
  198. $("#luckysheet-sheet-area div.luckysheet-sheets-item").removeClass("luckysheet-sheets-item-active");
  199. $("#luckysheet-sheets-item" + index).addClass("luckysheet-sheets-item-active");
  200. $("#luckysheet-cell-main").append('<div id="luckysheet-datavisual-selection-set-' + index + '" class="luckysheet-datavisual-selection-set"></div>');
  201. cleargridelement(e);
  202. server.saveParam("sha", null, $.extend(true, {}, sheetconfig));
  203. if (Store.clearjfundo) {
  204. Store.jfundo.length = 0;
  205. let redo = {};
  206. redo["type"] = "addSheet";
  207. redo["sheetconfig"] = $.extend(true, {}, sheetconfig);
  208. redo["index"] = index;
  209. redo["currentSheetIndex"] = Store.currentSheetIndex;
  210. Store.jfredo.push(redo);
  211. }
  212. _this.changeSheetExec(index, isPivotTable, true);
  213. // 钩子 sheetCreateAfter 不应该在这里 应在绘制完成后 因此在 changeSheet 实现
  214. },
  215. setSheetHide: function(index, isDelete) {
  216. let _this = this;
  217. let currentIdx = _this.getSheetIndex(index);
  218. // 钩子 sheetHideBefore
  219. if(!isDelete && !method.createHookFunction('sheetHideBefore', {sheet: Store.luckysheetfile[currentIdx]})){
  220. return;
  221. }
  222. Store.luckysheetfile[currentIdx].hide = 1;
  223. let luckysheetcurrentSheetitem = $("#luckysheet-sheets-item" + index);
  224. luckysheetcurrentSheetitem.hide();
  225. $("#luckysheet-sheet-area div.luckysheet-sheets-item").removeClass("luckysheet-sheets-item-active");
  226. let indicator;
  227. if(luckysheetConfigsetting.showsheetbarConfig.sheet){
  228. indicator = luckysheetcurrentSheetitem.nextAll(":visible");
  229. if (luckysheetcurrentSheetitem.nextAll(":visible").length > 0) {
  230. indicator = indicator.eq(0).data("index");
  231. }
  232. else {
  233. indicator = luckysheetcurrentSheetitem.prevAll(":visible").eq(0).data("index");
  234. }
  235. }else{
  236. let nextActiveIdx , showSheetIdxs = [];
  237. Store.luckysheetfile.forEach((ele,index)=>{
  238. if(1 !== ele.hide) showSheetIdxs.push(index);
  239. });
  240. let len = showSheetIdxs.length;
  241. if(1 === len){
  242. nextActiveIdx = showSheetIdxs[0];
  243. }else{
  244. nextActiveIdx = showSheetIdxs[len-1] > currentIdx ? showSheetIdxs.find(e => e>currentIdx ) : showSheetIdxs[len-1];
  245. }
  246. indicator = Store.luckysheetfile[nextActiveIdx].index;
  247. }
  248. $("#luckysheet-sheets-item" + indicator).addClass("luckysheet-sheets-item-active");
  249. _this.changeSheetExec(indicator);
  250. _this.locationSheet();
  251. server.saveParam("sh", luckysheetcurrentSheetitem.data("index"), 1, { "op": "hide", "cur": indicator });
  252. // 钩子 sheetHideAfter
  253. if (!isDelete) {
  254. method.createHookFunction('sheetHideAfter', {sheet: Store.luckysheetfile[currentIdx]});
  255. }
  256. },
  257. setSheetShow: function(index) {
  258. let _this = this;
  259. const file = Store.luckysheetfile[_this.getSheetIndex(index)]
  260. // 钩子 sheetShowBefore
  261. if(!method.createHookFunction('sheetShowBefore', {sheet: file})){
  262. return;
  263. }
  264. file.hide = 0;
  265. _this.changeSheetExec(index);
  266. server.saveParam("sh", index, 0, {"op": "show", "cur": null});
  267. // 钩子 sheetShowAfter
  268. method.createHookFunction('sheetShowAfter', {sheet: file});
  269. },
  270. sheetMaxIndex: 0,
  271. ordersheet: function(property) {
  272. return function (a, b) {
  273. let value1 = a[property];
  274. let value2 = b[property];
  275. return value1 - value2;
  276. }
  277. },
  278. getCurrentOrder: function() {
  279. let orders = {};
  280. $("#luckysheet-sheet-area div.luckysheet-sheets-item").each(function (a) {
  281. let index = $(this).data("index");
  282. for (let i = 0; i < Store.luckysheetfile.length; i++) {
  283. if (Store.luckysheetfile[i].index == index) {
  284. orders[index.toString()] = a;
  285. break;
  286. }
  287. }
  288. });
  289. return orders;
  290. },
  291. reOrderAllSheet: function() {
  292. let orders = {};
  293. $("#luckysheet-sheet-area div.luckysheet-sheets-item").each(function (a) {
  294. let index = $(this).data("index");
  295. for (let i = 0; i < Store.luckysheetfile.length; i++) {
  296. if (Store.luckysheetfile[i].index == index) {
  297. Store.luckysheetfile[i].order = a;
  298. orders[index.toString()] = a;
  299. break;
  300. }
  301. }
  302. });
  303. server.saveParam("shr", null, orders);
  304. Store.luckysheetfile.sort((x, y) => {
  305. let order_x = x.order;
  306. let order_y = y.order;
  307. if(order_x != null && order_y != null){
  308. return order_x - order_y;
  309. }
  310. else if(order_x != null){
  311. return -1;
  312. }
  313. else if(order_y != null){
  314. return 1;
  315. }
  316. else{
  317. return 1;
  318. }
  319. })
  320. },
  321. createSheet: function() { //修复拖动sheet更新后台后,重新打开显示错误
  322. let _this = this;
  323. let btn = [];
  324. Store.luckysheetfile.sort(_this.ordersheet('order'));
  325. for (let i = 0; i < Store.luckysheetfile.length; i++) {
  326. let display = "";
  327. let sheetIndex = Store.luckysheetfile[i].index;
  328. let colorset = '';
  329. if(Store.luckysheetfile[i].color != null){
  330. colorset = '<div class="luckysheet-sheets-item-color" style=" position: absolute; width: 100%; height: 3px; bottom: 0px; left: 0px; background-color: ' + Store.luckysheetfile[i].color + ';"></div>';
  331. }
  332. if (Store.currentSheetIndex == sheetIndex) { //使用Store.luckysheetfile中的index比较,而不是order
  333. btn.push(replaceHtml(sheetHTML, { "index": sheetIndex, "active": "luckysheet-sheets-item-active", "name": Store.luckysheetfile[i].name, "style": "","colorset":colorset }));
  334. }
  335. else {
  336. if (Store.luckysheetfile[i].hide == 1) {
  337. btn.push(replaceHtml(sheetHTML, { "index": sheetIndex, "active": "", "name": Store.luckysheetfile[i].name, "style": "display:none;","colorset":colorset }));
  338. }
  339. else {
  340. btn.push(replaceHtml(sheetHTML, { "index": sheetIndex, "active": "", "name": Store.luckysheetfile[i].name, "style": "","colorset":colorset }));
  341. }
  342. display = "style='display:none;'";
  343. }
  344. //Store.luckysheetfile[i].index = i; //index即为默认
  345. // if(sheetIndex > this.sheetMaxIndex){
  346. // this.sheetMaxIndex = sheetIndex;
  347. // }
  348. $("#luckysheet-cell-main").append('<div ' + display + ' id="luckysheet-datavisual-selection-set-' + sheetIndex + '" class="luckysheet-datavisual-selection-set"></div>');
  349. }
  350. $("#luckysheet-sheet-container-c").append(btn.join(""));
  351. _this.locationSheet();
  352. },
  353. // *控制sheet栏的左右滚动按钮是否显示
  354. locationSheet: function() {
  355. let $c = $("#luckysheet-sheet-container-c"), winW = $("#"+Store.container).width();
  356. let $cursheet = $("#luckysheet-sheet-container-c > div.luckysheet-sheets-item-active").eq(0);
  357. let scrollLeftpx = 0;
  358. let c_width = 0;
  359. $("#luckysheet-sheet-container-c > div.luckysheet-sheets-item:visible").each(function(){
  360. if($(this).hasClass("luckysheet-sheets-item-active")){
  361. scrollLeftpx = c_width;
  362. }
  363. c_width += $(this).outerWidth();
  364. });
  365. setTimeout(function(){
  366. $c.scrollLeft(scrollLeftpx - 10);
  367. if (luckysheetConfigsetting.showsheetbarConfig.sheet){
  368. if (c_width >= winW * 0.7) {
  369. $("#luckysheet-sheet-area .luckysheet-sheets-scroll").css("display", "inline-block");
  370. $("#luckysheet-sheet-container .docs-sheet-fade-left").show();
  371. } else {
  372. $("#luckysheet-sheet-area .luckysheet-sheets-scroll").css("display", "none");
  373. $("#luckysheet-sheet-container .docs-sheet-fade-left").hide();
  374. }
  375. }
  376. }, 1)
  377. },
  378. copySheet: function(copyindex, e) {
  379. if(isEditMode() || Store.allowEdit===false){
  380. // alert("非编辑模式下不允许该操作!");
  381. return;
  382. }
  383. let _this = this;
  384. let order = Store.luckysheetfile.length;
  385. let index = _this.generateRandomSheetIndex();
  386. let copyarrindex = _this.getSheetIndex(copyindex);
  387. let copyjson = $.extend(true, {}, Store.luckysheetfile[copyarrindex]);
  388. copyjson.order = order;
  389. copyjson.index = index;
  390. copyjson.name = _this.generateCopySheetName(Store.luckysheetfile, copyjson.name);
  391. // 钩子 sheetCreateBefore
  392. if(!method.createHookFunction('sheetCopyBefore', {
  393. targetSheet: Store.luckysheetfile[copyarrindex],
  394. copySheet: copyjson
  395. })){
  396. return;
  397. }
  398. let colorset = '';
  399. if(copyjson.color != null){
  400. colorset = '<div class="luckysheet-sheets-item-color" style=" position: absolute; width: 100%; height: 3px; bottom: 0px; left: 0px; background-color: ' + copyjson.color + ';"></div>';
  401. }
  402. let copyobject = $("#luckysheet-sheets-item" + copyindex);
  403. $("#luckysheet-sheet-container-c").append(replaceHtml(sheetHTML, { "index": copyjson.index, "active": "", "name": copyjson.name, "order": copyjson.order, "style": "", "colorset": colorset }));
  404. $("#luckysheet-sheets-item" + copyjson.index).insertAfter(copyobject);
  405. Store.luckysheetfile.splice(copyarrindex + 1, 0, copyjson);
  406. $("#luckysheet-sheet-area div.luckysheet-sheets-item").removeClass("luckysheet-sheets-item-active");
  407. $("#luckysheet-sheets-item" + index).addClass("luckysheet-sheets-item-active");
  408. $("#luckysheet-cell-main").append('<div id="luckysheet-datavisual-selection-set-' + index + '" class="luckysheet-datavisual-selection-set"></div>');
  409. cleargridelement(e);
  410. server.saveParam("shc", index, { "copyindex": copyindex, "name": copyjson.name });
  411. _this.changeSheetExec(index, undefined, undefined, true);
  412. _this.reOrderAllSheet();
  413. if (Store.clearjfundo) {
  414. Store.jfredo.push({
  415. "type": "copySheet",
  416. "copyindex": copyindex,
  417. "index": copyjson.index,
  418. "sheetIndex": copyjson.index
  419. });
  420. }
  421. else if (Store.jfredo.length > 0) {
  422. let jfredostr = Store.jfredo[Store.jfredo.length - 1];
  423. if (jfredostr.type == "copySheet") {
  424. jfredostr.index = copyjson.index;
  425. jfredostr.sheetIndex = copyjson.index;
  426. }
  427. }
  428. },
  429. hasSheet: function(index) {
  430. if (index == null) {
  431. return false;
  432. }
  433. index = this.getSheetIndex(index);
  434. if (index == null) {
  435. return false;
  436. }
  437. else {
  438. return true;
  439. }
  440. },
  441. createSheetbydata: function(data, isrenew, isBefore=true) {
  442. let _this = this;
  443. let colorset = '';
  444. if(data.color != null){
  445. colorset = '<div class="luckysheet-sheets-item-color" style=" position: absolute; width: 100%; height: 3px; bottom: 0px; left: 0px; background-color: ' + data.color + ';"></div>';
  446. }
  447. $("#luckysheet-sheet-container-c").append(replaceHtml(sheetHTML, { "index": data.index, "active": "", "name": data.name, "order": data.order, "style": "", "colorset": colorset }));
  448. if(isBefore){
  449. let previndex = data.order;
  450. if(previndex >= Store.luckysheetfile.length){
  451. previndex = Store.luckysheetfile.length - 1;
  452. $("#luckysheet-sheets-item" + data.index).insertAfter($("#luckysheet-sheets-item" + Store.luckysheetfile[previndex].index));
  453. }
  454. else{
  455. $("#luckysheet-sheets-item" + data.index).insertBefore($("#luckysheet-sheets-item" + Store.luckysheetfile[previndex].index));
  456. }
  457. }
  458. Store.luckysheetfile.push(data);
  459. $("#luckysheet-sheet-area div.luckysheet-sheets-item").removeClass("luckysheet-sheets-item-active");
  460. $("#luckysheet-sheets-item" + data.index).addClass("luckysheet-sheets-item-active");
  461. $("#luckysheet-cell-main").append('<div id="luckysheet-datavisual-selection-set-' + data.index + '" class="luckysheet-datavisual-selection-set"></div>');
  462. cleargridelement();
  463. if(isrenew != null){
  464. server.saveParam("shre", null, { "reIndex": data.index });
  465. data.hide = 0;
  466. server.saveParam("sh", data.index, 0, {"op": "show", "cur": null});
  467. }
  468. else{
  469. server.saveParam("sha", null, data);
  470. }
  471. _this.changeSheetExec(data.index, data.isPivotTable, true);
  472. _this.reOrderAllSheet();
  473. },
  474. deleteSheet: function(index) {
  475. let _this = this;
  476. if(Store.allowEdit===false){
  477. return;
  478. }
  479. let arrIndex = _this.getSheetIndex(index);
  480. const file = Store.luckysheetfile[arrIndex];
  481. // 钩子 sheetDeleteBefore
  482. if(!method.createHookFunction('sheetDeleteBefore', { sheet: file })){
  483. return;
  484. }
  485. _this.setSheetHide(index, true);
  486. $("#luckysheet-sheets-item" + index).remove();
  487. $("#luckysheet-datavisual-selection-set-" + index).remove();
  488. let removedsheet = Store.luckysheetfile.splice(arrIndex, 1);
  489. _this.reOrderAllSheet();
  490. server.saveParam("shd", null, {"deleIndex": index });
  491. if (Store.clearjfundo) {
  492. removedsheet[0].type = "deleteSheet";
  493. Store.jfredo.push(removedsheet[0]);
  494. }
  495. // 钩子 sheetDeleteAfter
  496. method.createHookFunction('sheetDeleteAfter', { sheet: file });
  497. },
  498. nulldata: null,
  499. getGridData: function(d) {
  500. let ret = [];
  501. for(let r = 0; r < d.length; r++){
  502. for(let c = 0; c < d[0].length; c++){
  503. if(d[r][c] == null){
  504. continue;
  505. }
  506. ret.push({r:r, c:c, v:d[r][c]});
  507. }
  508. }
  509. return ret;
  510. },
  511. buildGridData: function(file) {
  512. // 如果已经存在二维数据data,那么直接返回data;如果只有celldata,那么就转化成二维数组data,再返回
  513. let row = file.row == null ? Store.defaultrowNum : file.row,
  514. column = file.column == null ? Store.defaultcolumnNum : file.column,
  515. data = file.data && file.data.length > 0 ? file.data : datagridgrowth([], row, column),
  516. celldata = file.celldata;
  517. if (file.data && file.data.length > 0) {
  518. for (let i = 0; i < data.length; i++) {
  519. for (let j = 0; j < data[0].length; j++) {
  520. setcellvalue(i, j, data, data[i][j]);
  521. }
  522. }
  523. } else {
  524. if(celldata && celldata.length > 0){
  525. for(let i = 0; i < celldata.length; i++){
  526. let item = celldata[i];
  527. let r = item.r;
  528. let c = item.c;
  529. let v = item.v;
  530. if(r == null && c == null) {
  531. continue;
  532. }
  533. if(r >= data.length){
  534. data = datagridgrowth(data, r - data.length + 1, 0);
  535. }
  536. if(c >= data[0].length){
  537. data = datagridgrowth(data, 0, c - data[0].length + 1);
  538. }
  539. setcellvalue(r, c, data, v);
  540. }
  541. }
  542. }
  543. //亿万格式+精确度 恢复全局初始化
  544. luckysheetConfigsetting.autoFormatw = false;
  545. luckysheetConfigsetting.accuracy = undefined;
  546. return data;
  547. },
  548. cutGridData: function(d) {
  549. let rowindex = 0;
  550. for(let r = d.length - 1; r >= 0; r--){
  551. let isnull = true;
  552. for(let c = 0; c < d[0].length; c++){
  553. let value = getcellvalue(r, c);
  554. if(value != null && $.trim(value).length > 0){
  555. isnull = false;
  556. break;
  557. }
  558. }
  559. if(!isnull){
  560. break;
  561. }
  562. else{
  563. rowindex = r;
  564. }
  565. }
  566. return d.slice(0, rowindex);
  567. },
  568. addGridData: function(celldata, row, column) {
  569. let data = datagridgrowth([], row, column);
  570. if(celldata != null){
  571. for(let i = 0; i < celldata.length; i++){
  572. let item = celldata[i];
  573. let r = item.r;
  574. let c = item.c;
  575. let v = item.v;
  576. if(r >= data.length){
  577. data = datagridgrowth(data, r - data.length + 1, 0);
  578. }
  579. if(c >= data[0].length){
  580. data = datagridgrowth(data, 0, c - data[0].length + 1);
  581. }
  582. setcellvalue(r, c, data, v)
  583. }
  584. }
  585. return data;
  586. },
  587. sheetParamRestore: function(file, data) {
  588. Store.luckysheet_select_save = file["luckysheet_select_save"];
  589. if(Store.luckysheet_select_save == null || Store.luckysheet_select_save.length == 0){
  590. if(data[0] != null && data[0][0] != null && data[0][0].mc != null){
  591. Store.luckysheet_select_save = [{
  592. "row": [0, data[0][0].mc.rs - 1],
  593. "column": [0, data[0][0].mc.cs - 1]
  594. }];
  595. }
  596. else{
  597. Store.luckysheet_select_save = [{
  598. "row": [0, 0],
  599. "column": [0, 0]
  600. }];
  601. }
  602. }
  603. Store.luckysheet_selection_range = file["luckysheet_selection_range"] == null ? [] : file["luckysheet_selection_range"];
  604. Store.config = file["config"] == null ? {} : file["config"];
  605. Store.zoomRatio = file["zoomRatio"] == null ? 1 : file["zoomRatio"];
  606. if(file["defaultRowHeight"]!=null){
  607. Store.defaultrowlen = parseFloat(file["defaultRowHeight"]);
  608. }
  609. else{
  610. Store.defaultrowlen = luckysheetConfigsetting["defaultRowHeight"];
  611. }
  612. if(file["defaultColWidth"]!=null){
  613. Store.defaultcollen = parseFloat(file["defaultColWidth"]);
  614. }
  615. else{
  616. Store.defaultcollen = luckysheetConfigsetting["defaultColWidth"];
  617. }
  618. if(file["showGridLines"]!=null){
  619. let showGridLines = file["showGridLines"];
  620. if(showGridLines==0 || showGridLines==false){
  621. Store.showGridLines = false;
  622. }
  623. else{
  624. Store.showGridLines = true;
  625. }
  626. }
  627. else{
  628. Store.showGridLines = true;
  629. }
  630. },
  631. initialjfFile: function(menu, title) {
  632. let _this = this;
  633. _this.getCurSheet();
  634. let file = Store.luckysheetfile[_this.getSheetIndex(Store.currentSheetIndex)];
  635. _this.nulldata = datagridgrowth([], Store.defaultrowNum, Store.defaultcolumnNum);
  636. let data = _this.buildGridData(file);
  637. //初始化的时候 记录选区
  638. let select_save = [];
  639. file.jfgird_select_save = file.jfgird_select_save || [];
  640. if(file.jfgird_select_save.op) {
  641. file.jfgird_select_save = []
  642. }
  643. file.jfgird_select_save.forEach(item=>select_save.push({"row":item.row,"column":item.column}));
  644. file.luckysheet_select_save = select_save;
  645. this.sheetParamRestore(file, data);
  646. let r2 = Store.luckysheet_select_save[0].row[1],
  647. c2 = Store.luckysheet_select_save[0].column[1];
  648. if(Store.luckysheet_select_save.length > 1){
  649. for(let i = 0; i < Store.luckysheet_select_save.length; i++){
  650. if(Store.luckysheet_select_save[i].row[1] > r2){
  651. r2 = Store.luckysheet_select_save[i].row[1];
  652. }
  653. if(Store.luckysheet_select_save[i].column[1] > c2){
  654. c2 = Store.luckysheet_select_save[i].column[1];
  655. }
  656. }
  657. }
  658. menuButton.fontInitial(Store.fontList);//initial font
  659. file.data = data;
  660. let rowheight = data.length;
  661. if(r2 > rowheight - 1){
  662. rowheight = r2 + 1;
  663. }
  664. let colwidth = data[0].length;
  665. if(c2 > colwidth - 1){
  666. colwidth = c2 + 1;
  667. }
  668. //钩子函数 表格创建之前触发
  669. if(typeof luckysheetConfigsetting.beforeCreateDom == "function" ){
  670. luckysheetConfigsetting.beforeCreateDom(luckysheet);
  671. }
  672. if(typeof luckysheetConfigsetting.workbookCreateBefore == "function"){
  673. luckysheetConfigsetting.workbookCreateBefore(luckysheet);
  674. }
  675. // Store.flowdata = data;
  676. luckysheetcreatedom(colwidth, rowheight, data, menu, title);
  677. setTimeout(function () {
  678. tooltip.createHoverTip("#luckysheet_info_detail" ,".luckysheet_info_detail_back, .luckysheet_info_detail_input, .luckysheet_info_detail_update");
  679. tooltip.createHoverTip("#luckysheet-wa-editor" ,".luckysheet-toolbar-menu-button, .luckysheet-toolbar-button, .luckysheet-toolbar-combo-button");
  680. Store.luckysheetTableContentHW = [
  681. $("#luckysheet-cell-main").width() + Store.rowHeaderWidth - Store.cellMainSrollBarSize,
  682. $("#luckysheet-cell-main").height() + Store.columnHeaderHeight - Store.cellMainSrollBarSize
  683. ];
  684. $("#luckysheetTableContent, #luckysheetTableContentF").attr({
  685. width: Math.ceil(Store.luckysheetTableContentHW[0] * Store.devicePixelRatio),
  686. height: Math.ceil(Store.luckysheetTableContentHW[1] * Store.devicePixelRatio)
  687. }).css({
  688. width: Store.luckysheetTableContentHW[0],
  689. height: Store.luckysheetTableContentHW[1]
  690. }).get(0).getContext("2d");
  691. let locale_info = locale().info;
  692. let key = server.gridKey;
  693. let cahce_key = key + "__qkcache";
  694. let ini = function(){
  695. file["load"] = "1";
  696. _this.createSheet();
  697. let execF = function(){
  698. _this.mergeCalculation(file["index"]);
  699. _this.setSheetParam(false);
  700. // editor.webWorkerFlowDataCache(Store.flowdata);//worker存数据
  701. _this.storeSheetParam();
  702. _this.restoreselect();
  703. _this.CacheNotLoadControll = [];
  704. _this.restoreCache();
  705. formula.execFunctionGroupForce(luckysheetConfigsetting.forceCalculation);
  706. _this.restoreSheetAll(Store.currentSheetIndex);
  707. // luckysheetrefreshgrid(0, 0);
  708. $("#luckysheet_info_detail_save").html(locale_info.detailSave);
  709. if (!!file.isPivotTable) {
  710. Store.luckysheetcurrentisPivotTable = true;
  711. // pivotTable.changePivotTable(Store.currentSheetIndex); //此方法需要注释掉,在restoreSheetAll中已经执行了刷新了数据透视表,这里就不需要了
  712. }
  713. else {
  714. Store.luckysheetcurrentisPivotTable = false;
  715. $("#luckysheet-modal-dialog-slider-pivot").hide();
  716. }
  717. // Store toolbar button width value
  718. menuToolBarWidth();
  719. luckysheetsizeauto();
  720. //等待滚动条dom宽高加载完成后 初始化滚动位置
  721. if(file["scrollLeft"] != null && file["scrollLeft"] > 0){
  722. $("#luckysheet-scrollbar-x").scrollLeft(file["scrollLeft"]);
  723. }
  724. else{
  725. $("#luckysheet-scrollbar-x").scrollLeft(0);
  726. }
  727. if(file["scrollTop"] != null && file["scrollTop"] > 0){
  728. $("#luckysheet-scrollbar-y").scrollTop(file["scrollTop"]);
  729. }
  730. else{
  731. $("#luckysheet-scrollbar-y").scrollTop(0);
  732. }
  733. // 此处已经渲染完成表格,应该挪到前面
  734. // //钩子函数 表格创建之前触发
  735. // if(typeof luckysheetConfigsetting.beforeCreateDom == "function" ){
  736. // luckysheetConfigsetting.beforeCreateDom(luckysheet);
  737. // }
  738. // if(typeof luckysheetConfigsetting.workbookCreateBefore == "function"){
  739. // luckysheetConfigsetting.workbookCreateBefore(luckysheet);
  740. // }
  741. arrayRemoveItem(Store.asyncLoad,'core');
  742. if(luckysheetConfigsetting.pointEdit){
  743. setTimeout(function(){
  744. Store.loadingObj.close()
  745. }, 0);
  746. }
  747. else{
  748. setTimeout(function(){
  749. Store.loadingObj.close()
  750. }, 500);
  751. }
  752. }
  753. let loadSheetUrl = server.loadSheetUrl;
  754. if(loadSheetUrl == ""){
  755. // execF();
  756. // }
  757. // else if(sheetindex.length>0 && loadSheetUrl == ""){
  758. // for(let i = 0;i<Store.luckysheetfile.length;i++){
  759. // let otherfile = Store.luckysheetfile[i];
  760. // if(otherfile.index == file.index){
  761. // continue;
  762. // }
  763. // // let otherfile = Store.luckysheetfile[_this.getSheetIndex(item)];
  764. // if(otherfile["load"] == null || otherfile["load"] == "0"){
  765. // otherfile["data"] = _this.buildGridData(otherfile);
  766. // otherfile["load"] = "1";
  767. // }
  768. // }
  769. _this.loadOtherFile(file);
  770. execF();
  771. }
  772. else{
  773. let sheetindexset = _this.checkLoadSheetIndex(file);
  774. let sheetindex = [];
  775. for(let i = 0; i < sheetindexset.length; i++){
  776. let item = sheetindexset[i];
  777. if(item == file["index"]){
  778. continue;
  779. }
  780. sheetindex.push(item);
  781. }
  782. // No request is sent if it is not linked to other worksheets
  783. if(sheetindex.length === 0){
  784. execF();
  785. return;
  786. }
  787. $.post(loadSheetUrl, {"gridKey" : server.gridKey, "index": sheetindex.join(",")}, function (d) {
  788. let dataset = new Function("return " + d)();
  789. for(let item in dataset){
  790. if(item == file["index"]){
  791. continue;
  792. }
  793. let otherfile = Store.luckysheetfile[_this.getSheetIndex(item)];
  794. if(otherfile["load"] == null || otherfile["load"] == "0"){
  795. otherfile.celldata = dataset[item.toString()];
  796. otherfile["data"] = _this.buildGridData(otherfile);
  797. otherfile["load"] = "1";
  798. }
  799. }
  800. execF();
  801. });
  802. }
  803. }
  804. try {
  805. localforage.getItem(cahce_key).then(function(readValue) {
  806. if(readValue != null){
  807. _this.CacheNotLoadControll = readValue;
  808. }
  809. server.clearcachelocaldata(function(){
  810. ini();
  811. });
  812. });
  813. } catch(e) {
  814. ini();
  815. console.log("缓存操作失败");
  816. }
  817. }, 1);
  818. },
  819. storeSheetParam: function() {
  820. let index = this.getSheetIndex(Store.currentSheetIndex);
  821. let file = Store.luckysheetfile[index];
  822. file["config"] = Store.config;
  823. file["visibledatarow"] = Store.visibledatarow;
  824. file["visibledatacolumn"] = Store.visibledatacolumn;
  825. file["ch_width"] = Store.ch_width;
  826. file["rh_height"] = Store.rh_height;
  827. file["luckysheet_select_save"] = $.extend(true, [], Store.luckysheet_select_save);
  828. file["luckysheet_selection_range"] = $.extend(true, [], Store.luckysheet_selection_range);
  829. if($("#luckysheet-scrollbar-x")[0].scrollWidth > $("#luckysheet-scrollbar-x")[0].offsetWidth){
  830. file["scrollLeft"] = $("#luckysheet-scrollbar-x").scrollLeft(); //横向滚动条
  831. }
  832. if($("#luckysheet-scrollbar-y")[0].scrollHeight > $("#luckysheet-scrollbar-y")[0].offsetHeight){
  833. file["scrollTop"] = $("#luckysheet-scrollbar-y").scrollTop(); //纵向滚动条
  834. }
  835. file["zoomRatio"] = Store.zoomRatio;
  836. },
  837. setSheetParam: function(isload=true) {
  838. let index = this.getSheetIndex(Store.currentSheetIndex);
  839. let file = Store.luckysheetfile[index];
  840. Store.flowdata = file["data"];
  841. editor.webWorkerFlowDataCache(Store.flowdata);//worker存数据
  842. // formula.execFunctionGroupData = null;
  843. formula.execFunctionGlobalData = null;
  844. window.luckysheet_getcelldata_cache = null;
  845. this.sheetParamRestore(file, Store.flowdata);
  846. if(file["freezen"] == null){
  847. luckysheetFreezen.freezenhorizontaldata = null;
  848. luckysheetFreezen.freezenverticaldata = null;
  849. }
  850. else{
  851. luckysheetFreezen.freezenhorizontaldata = file["freezen"].horizontal == null ? null : file["freezen"].horizontal.freezenhorizontaldata;
  852. luckysheetFreezen.freezenverticaldata = file["freezen"].vertical == null ? null : file["freezen"].vertical.freezenverticaldata;
  853. }
  854. if(isload){
  855. rhchInit(Store.flowdata.length, Store.flowdata[0].length);
  856. }
  857. //批注
  858. luckysheetPostil.buildAllPs(Store.flowdata);
  859. //图片
  860. imageCtrl.currentImgId = null;
  861. imageCtrl.images = file.images;
  862. imageCtrl.allImagesShow();
  863. imageCtrl.init();
  864. //数据验证
  865. dataVerificationCtrl.dataVerification = file.dataVerification;
  866. dataVerificationCtrl.init();
  867. //链接
  868. hyperlinkCtrl.hyperlink = file.hyperlink;
  869. hyperlinkCtrl.init();
  870. createFilterOptions(file["filter_select"], file["filter"]);
  871. },
  872. restoreselect: function() {
  873. let index = this.getSheetIndex(Store.currentSheetIndex);
  874. let file = Store.luckysheetfile[index];
  875. //选区
  876. selectHightlightShow(true);
  877. //复制选区虚线框
  878. selectionCopyShow();
  879. if (file["scrollLeft"] != null && file["scrollLeft"] > 0) {
  880. $("#luckysheet-scrollbar-x").scrollLeft(file["scrollLeft"]); //列标题
  881. }
  882. else {
  883. $("#luckysheet-scrollbar-x").scrollLeft(0);
  884. }
  885. if (file["scrollTop"] != null && file["scrollTop"] > 0) {
  886. $("#luckysheet-scrollbar-y").scrollTop(file["scrollTop"]); //列标题
  887. }
  888. else {
  889. $("#luckysheet-scrollbar-y").scrollTop(0);
  890. }
  891. },
  892. storeSheetParamALL: function() {
  893. let _this = this;
  894. _this.storeSheetParam();
  895. let index = _this.getSheetIndex(Store.currentSheetIndex);
  896. Store.luckysheetfile[index]["data"] = Store.flowdata;
  897. Store.luckysheetfile[index]["config"] = $.extend(true, {}, Store.config);
  898. },
  899. mergeCalculationSheet:{},
  900. mergeCalculation:function(index){
  901. let file = Store.luckysheetfile[this.getSheetIndex(index)];
  902. let config = file.config, data = file.data;
  903. if(config==null){
  904. return;
  905. }
  906. let mergeConfig = config.merge;
  907. if(mergeConfig==null || index in this.mergeCalculationSheet || file["autoCalculationMerge"]===false){
  908. return;
  909. }
  910. this.mergeCalculationSheet[index] = 1;
  911. for(let x in mergeConfig){
  912. let r = parseInt(x.substr(0, x.indexOf('_')));
  913. let c = parseInt(x.substr(x.indexOf('_') + 1));
  914. let mcInfo = mergeConfig[x];
  915. if(data[r][c]==null){
  916. data[r][c] = {};
  917. }
  918. data[r][c]["mc"] = {
  919. r:r,
  920. c:c,
  921. rs:mcInfo.rs,
  922. cs:mcInfo.cs,
  923. }
  924. for(let ir=r;ir<r+mcInfo.rs;ir++){
  925. for(let ic=c;ic<c+mcInfo.cs;ic++){
  926. if(ir==r && ic==c){
  927. continue;
  928. }
  929. if(data[ir][ic]==null){
  930. data[ir][ic] = {};
  931. }
  932. data[ir][ic]["mc"] = {
  933. r:r,
  934. c:c,
  935. }
  936. }
  937. }
  938. }
  939. },
  940. loadOtherFile:function(file){
  941. let _this = this;
  942. // let sheetindexset = _this.checkLoadSheetIndex(file);
  943. // let sheetindex = [];
  944. // for(let i = 0; i < sheetindexset.length; i++){
  945. // let item = sheetindexset[i];
  946. // if(item == file["index"]){
  947. // continue;
  948. // }
  949. // sheetindex.push(item);
  950. // }
  951. // for(let i = 0;i<sheetindex.length;i++){
  952. // let item = sheetindex[i];
  953. // let otherfile = Store.luckysheetfile[_this.getSheetIndex(item)];
  954. // if(otherfile["load"] == null || otherfile["load"] == "0"){
  955. // otherfile["data"] = _this.buildGridData(otherfile);
  956. // otherfile["load"] = "1";
  957. // }
  958. // }
  959. for(let i = 0;i<Store.luckysheetfile.length;i++){
  960. let otherfile = Store.luckysheetfile[i];
  961. if(otherfile.index == file.index){
  962. continue;
  963. }
  964. // let otherfile = Store.luckysheetfile[_this.getSheetIndex(item)];
  965. if(otherfile["load"] == null || otherfile["load"] == "0"){
  966. otherfile["data"] = _this.buildGridData(otherfile);
  967. otherfile["load"] = "1";
  968. }
  969. }
  970. },
  971. changeSheet: function(index, isPivotInitial, isNewSheet, isCopySheet) {
  972. if(isEditMode()){
  973. // alert("非编辑模式下不允许该操作!");
  974. return;
  975. }
  976. let _this = this;
  977. if(index==Store.currentSheetIndex){
  978. return;
  979. }
  980. if(server.allowUpdate){
  981. $("#luckysheet-cell-main #luckysheet-multipleRange-show").empty();
  982. server.multipleIndex = 0;
  983. }
  984. let file = Store.luckysheetfile[_this.getSheetIndex(index)]
  985. // 钩子 sheetCreateAfter
  986. if (isNewSheet) {
  987. method.createHookFunction('sheetCreateAfter', { sheet: file });
  988. }
  989. // 钩子 sheetCopyAfter
  990. if (isCopySheet) {
  991. method.createHookFunction('sheetCopyAfter', { sheet: file });
  992. }
  993. // 钩子函数
  994. method.createHookFunction('sheetActivate', index, isPivotInitial, isNewSheet);
  995. $('#luckysheet-filter-selected-sheet' + Store.currentSheetIndex + ', #luckysheet-filter-options-sheet' + Store.currentSheetIndex).hide();
  996. $('#luckysheet-filter-selected-sheet' + index + ', #luckysheet-filter-options-sheet' + index).show();
  997. _this.storeSheetParamALL();
  998. _this.setCurSheet(index);
  999. if (!!file.isPivotTable) {
  1000. Store.luckysheetcurrentisPivotTable = true;
  1001. if (!isPivotInitial) {
  1002. pivotTable.changePivotTable(index);
  1003. }
  1004. }
  1005. else{
  1006. Store.luckysheetcurrentisPivotTable = false;
  1007. $("#luckysheet-modal-dialog-slider-pivot").hide();
  1008. luckysheetsizeauto(false);
  1009. }
  1010. let load = file["load"];
  1011. if (load != null) {
  1012. let data = _this.buildGridData(file);
  1013. file.data = data;
  1014. // _this.loadOtherFile(file);
  1015. _this.mergeCalculation(index);
  1016. _this.setSheetParam(true);
  1017. _this.showSheet();
  1018. setTimeout(function () {
  1019. formula.execFunctionGroup();
  1020. luckysheetrefreshgrid();
  1021. server.saveParam("shs", null, Store.currentSheetIndex);
  1022. }, 1);
  1023. }
  1024. else {
  1025. let loadSheetUrl = server.loadSheetUrl;
  1026. if(loadSheetUrl == "" || Store.luckysheetcurrentisPivotTable || !!isNewSheet){
  1027. let data = _this.buildGridData(file);
  1028. file["data"] = data;
  1029. file["load"] = "1";
  1030. // *这里不应该调用loadOtherFile去加载其余页面的数据,
  1031. // *因为loadOtherFile里判断后会调用buildGridData把其余的sheet的数据设置为空的二维数组,即使那个sheet在服务端存在数据.
  1032. // *这就导致一个数据丢失问题.
  1033. // _this.loadOtherFile(file);
  1034. // let sheetindexset = _this.checkLoadSheetIndex(file);
  1035. // let sheetindex = [];
  1036. // for(let i = 0; i < sheetindexset.length; i++){
  1037. // let item = sheetindexset[i];
  1038. // if(item == file["index"]){
  1039. // continue;
  1040. // }
  1041. // sheetindex.push(item);
  1042. // }
  1043. // for(let i = 0;i<sheetindex.length;i++){
  1044. // let item = sheetindex[i];
  1045. // let otherfile = Store.luckysheetfile[_this.getSheetIndex(item)];
  1046. // if(otherfile["load"] == null || otherfile["load"] == "0"){
  1047. // otherfile["data"] = _this.buildGridData(otherfile);
  1048. // otherfile["load"] = "1";
  1049. // }
  1050. // }
  1051. _this.mergeCalculation(index);
  1052. _this.setSheetParam();
  1053. _this.showSheet();
  1054. setTimeout(function () {
  1055. _this.restoreCache();
  1056. formula.execFunctionGroupForce(luckysheetConfigsetting.forceCalculation);
  1057. _this.restoreSheetAll(Store.currentSheetIndex);
  1058. luckysheetrefreshgrid();
  1059. }, 1);
  1060. server.saveParam("shs", null, Store.currentSheetIndex);
  1061. }
  1062. else{
  1063. $("#luckysheet-grid-window-1").append(luckysheetlodingHTML());
  1064. let sheetindex = _this.checkLoadSheetIndex(file);
  1065. $.post(loadSheetUrl, {"gridKey" : server.gridKey, "index": sheetindex.join(",")}, function (d) {
  1066. let dataset = new Function("return " + d)();
  1067. file.celldata = dataset[index.toString()];
  1068. let data = _this.buildGridData(file);
  1069. setTimeout(function(){
  1070. Store.loadingObj.close()
  1071. }, 500);
  1072. for(let item in dataset){
  1073. if(item == index){
  1074. continue;
  1075. }
  1076. let otherfile = Store.luckysheetfile[_this.getSheetIndex(item)];
  1077. if(otherfile["load"] == null || otherfile["load"] == "0"){
  1078. otherfile.celldata = dataset[item.toString()];
  1079. otherfile["data"] = _this.buildGridData(otherfile);
  1080. otherfile["load"] = "1";
  1081. }
  1082. }
  1083. file["data"] = data;
  1084. file["load"] = "1";
  1085. _this.mergeCalculation(index);
  1086. _this.setSheetParam();
  1087. _this.showSheet();
  1088. setTimeout(function () {
  1089. _this.restoreCache();
  1090. formula.execFunctionGroupForce(luckysheetConfigsetting.forceCalculation);
  1091. _this.restoreSheetAll(Store.currentSheetIndex);
  1092. luckysheetrefreshgrid();
  1093. }, 1);
  1094. server.saveParam("shs", null, Store.currentSheetIndex);
  1095. });
  1096. }
  1097. }
  1098. $("#luckysheet-cell-main .luckysheet-datavisual-selection-set").hide();
  1099. $("#luckysheet-datavisual-selection-set-" + index).show();
  1100. //隐藏其他sheet的图表,显示当前sheet的图表 chartMix
  1101. renderChartShow(index);
  1102. luckysheetFreezen.initialFreezen(index);
  1103. _this.restoreselect();
  1104. },
  1105. checkLoadSheetIndexToDataIndex:{},
  1106. checkLoadSheetIndex: function(file) {
  1107. let calchain = formula.getAllFunctionGroup();//file.calcChain; //index
  1108. let chart = file.chart; //dataSheetIndex
  1109. let pivotTable = file.pivotTable; //pivotDataSheetIndex
  1110. let ret= [], cache = {};
  1111. if(file.index in this.checkLoadSheetIndexToDataIndex){
  1112. return [];
  1113. }
  1114. ret.push(file.index);
  1115. cache[file.index.toString()] = 1;
  1116. this.checkLoadSheetIndexToDataIndex[file.index] = 1;
  1117. if(calchain != null){
  1118. let dataIndexList = {};
  1119. for(let i = 0; i < calchain.length; i++){
  1120. let f = calchain[i];
  1121. let dataindex = f.index;
  1122. let formulaTxt = getcellFormula(f.r, f.c, dataindex);
  1123. if(formulaTxt==null){
  1124. let file = Store.luckysheetfile[this.getSheetIndex(dataindex)];
  1125. file.data = this.buildGridData(file);
  1126. formulaTxt = getcellFormula(f.r, f.c, dataindex);
  1127. if(formulaTxt==null){
  1128. continue;
  1129. }
  1130. }
  1131. if(formulaTxt.indexOf("!")==-1){
  1132. // dataIndexList[dataindex] = 1;
  1133. formula.addToSheetIndexList(formulaTxt, dataindex);
  1134. }
  1135. else if(formula.formulaContainSheetList!=null && formula.formulaContainSheetList[formulaTxt]!=null){
  1136. for(let dataSheetIndex in formula.formulaContainSheetList[formulaTxt]){
  1137. dataIndexList[dataSheetIndex] = 1;
  1138. }
  1139. }
  1140. else{
  1141. formula.functionParser(formulaTxt, (str)=>{
  1142. formula.addToCellList(formulaTxt, str);
  1143. if(str.indexOf("!")>-1){
  1144. let name = str.substr(0, str.indexOf('!'));
  1145. // dataNameList[name] = true;
  1146. let sheet = this.getSheetByName(name);
  1147. if(sheet!=null){
  1148. let dataSheetIndex = sheet.index;
  1149. dataIndexList[dataSheetIndex] = 1;
  1150. formula.addToSheetIndexList(formulaTxt, dataSheetIndex);
  1151. }
  1152. }
  1153. });
  1154. if(formula.formulaContainSheetList[formulaTxt]==null){
  1155. // dataIndexList[dataindex] = 1;
  1156. formula.addToSheetIndexList(formulaTxt, dataindex);
  1157. }
  1158. }
  1159. if(dataindex == null){
  1160. continue;
  1161. }
  1162. // if(cache[dataindex.toString()] == null){
  1163. // // ret.push(dataindex);
  1164. // cache[dataindex.toString()] = 1;
  1165. // this.checkLoadSheetIndexToDataIndex[dataindex] = 1;
  1166. // }
  1167. }
  1168. for(let index in dataIndexList){
  1169. // let sheet = this.getSheetByName(n);
  1170. // if(sheet==null){
  1171. // continue;
  1172. // }
  1173. // if(index == Store.currentSheetIndex){
  1174. // continue;
  1175. // }
  1176. let dataindex = index;
  1177. if(cache[dataindex.toString()] == null){
  1178. ret.push(dataindex);
  1179. cache[dataindex.toString()] = 1;
  1180. this.checkLoadSheetIndexToDataIndex[dataindex] = 1;
  1181. }
  1182. }
  1183. }
  1184. if(chart != null){
  1185. for(let i = 0; i < chart.length; i++){
  1186. let cc = chart[i];
  1187. let dataindex = cc.dataSheetIndex;
  1188. if(dataindex == null){
  1189. continue;
  1190. }
  1191. if(cache[dataindex.toString()] == null){
  1192. ret.push(dataindex);
  1193. cache[dataindex.toString()] = 1;
  1194. }
  1195. }
  1196. }
  1197. if(pivotTable != null){
  1198. let dataindex = pivotTable.pivotDataSheetIndex;
  1199. if(dataindex != null && cache[dataindex.toString()] == null){
  1200. ret.push(dataindex);
  1201. cache[dataindex.toString()] = 1;
  1202. }
  1203. }
  1204. return ret;
  1205. },
  1206. showSheet: function() {
  1207. // changeSheetContainerSize();
  1208. $("#luckysheet-cell-flow_0").css({ "width": Store.ch_width, "top": "-1px" }); //width更新
  1209. $("#luckysheet-sheettable_0").css({ "width": Store.ch_width - 1, "height": Store.rh_height });
  1210. $("#luckysheetrowHeader_0").css("height", Store.rh_height);
  1211. $("#luckysheet-cols-h-cells_0").css("width", Store.ch_width); //width更新
  1212. $("#luckysheet-scrollbar-x div").width(Store.ch_width);
  1213. $("#luckysheet-scrollbar-y div").height(Store.rh_height + Store.columnHeaderHeight - Store.cellMainSrollBarSize - 3);
  1214. //等待滚动条dom宽高计算完成后 初始化该表格滚动位置
  1215. let index = this.getSheetIndex(Store.currentSheetIndex);
  1216. let file = Store.luckysheetfile[index];
  1217. Store.scrollRefreshSwitch = false;
  1218. if(file["scrollLeft"] != null && file["scrollLeft"] > 0){
  1219. $("#luckysheet-scrollbar-x").scrollLeft(file["scrollLeft"] * Store.zoomRatio);
  1220. }
  1221. else{
  1222. $("#luckysheet-scrollbar-x").scrollLeft(0);
  1223. }
  1224. if(file["scrollTop"] != null && file["scrollTop"] > 0){
  1225. $("#luckysheet-scrollbar-y").scrollTop(file["scrollTop"] * Store.zoomRatio);
  1226. }
  1227. else{
  1228. $("#luckysheet-scrollbar-y").scrollTop(0);
  1229. }
  1230. setTimeout(() => {
  1231. Store.scrollRefreshSwitch = true;
  1232. }, 0);
  1233. zoomNumberDomBind(Store.zoomRatio);
  1234. },
  1235. setCurSheet: function(index) {
  1236. for (let i = 0; i < Store.luckysheetfile.length; i++) {
  1237. if (Store.luckysheetfile[i]["index"] == index) {
  1238. Store.luckysheetfile[i].status = 1;
  1239. }
  1240. else {
  1241. Store.luckysheetfile[i].status = 0;
  1242. }
  1243. }
  1244. Store.currentSheetIndex = index;
  1245. },
  1246. getSheetIndex: function(index) {
  1247. for (let i = 0; i < Store.luckysheetfile.length; i++) {
  1248. if (Store.luckysheetfile[i]["index"] == index) {
  1249. return i;
  1250. }
  1251. }
  1252. return null;
  1253. },
  1254. changeSheetExec: function(index, isPivotInitial, isNewSheet, isCopySheet) {
  1255. let $sheet = $("#luckysheet-sheets-item" + index);
  1256. window.luckysheet_getcelldata_cache = null;
  1257. $("#luckysheet-sheet-area div.luckysheet-sheets-item").removeClass("luckysheet-sheets-item-active");
  1258. $sheet.addClass("luckysheet-sheets-item-active").show();
  1259. cleargridelement();
  1260. this.changeSheet(index, isPivotInitial, isNewSheet, isCopySheet);
  1261. $("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu").hide();
  1262. if (formula.rangestart) {
  1263. formula.createRangeHightlight();
  1264. }
  1265. this.sheetBarShowAndHide(index);
  1266. },
  1267. sheetArrowShowAndHide(){
  1268. const $wrap = $('#luckysheet-sheet-container-c');
  1269. if (!$wrap.length) return;
  1270. var sw = $wrap[0].scrollWidth;
  1271. var w = Math.ceil($wrap.width());
  1272. if (sw > w) {
  1273. if(luckysheetConfigsetting.showsheetbarConfig.sheet){
  1274. $("#luckysheet-sheet-area .luckysheet-sheets-scroll").css("display", "inline-block");
  1275. $("#luckysheet-sheet-container .docs-sheet-fade-left").show();
  1276. }
  1277. }
  1278. else{
  1279. $("#luckysheet-sheet-area .luckysheet-sheets-scroll").css("display", "none");
  1280. $("#luckysheet-sheet-container .docs-sheet-fade-left").hide();
  1281. }
  1282. },
  1283. // *显示sheet栏左右的灰色
  1284. sheetBarShowAndHide(index){
  1285. let $c = $("#luckysheet-sheet-container-c");
  1286. if(index!=null){
  1287. let $sheet = $("#luckysheet-sheets-item" + index);
  1288. $c.scrollLeft($sheet.offset().left);
  1289. }
  1290. let c_width = $c.width(), c_srollwidth = $c[0].scrollWidth, scrollLeft = $c.scrollLeft();
  1291. if (scrollLeft <= 0) {
  1292. $("#luckysheet-sheet-container .docs-sheet-fade-left").hide();
  1293. }
  1294. else {
  1295. $("#luckysheet-sheet-container .docs-sheet-fade-left").show();
  1296. }
  1297. if (c_width + scrollLeft >= c_srollwidth) {
  1298. $("#luckysheet-sheet-container .docs-sheet-fade-right").hide();
  1299. }
  1300. else {
  1301. $("#luckysheet-sheet-container .docs-sheet-fade-right").show();
  1302. }
  1303. },
  1304. delChart: function(chart_id, sheetIndex) {
  1305. let index = this.getSheetIndex(sheetIndex);
  1306. let file = Store.luckysheetfile[index];
  1307. if (file.chart == null) {
  1308. file.chart = [];
  1309. }
  1310. else {
  1311. for (let i = 0; i < file.chart.length; i++) {
  1312. if (file.chart[i].chart_id == chart_id) {
  1313. Store.luckysheetfile[index].chart.splice(i, 1);
  1314. break;
  1315. }
  1316. }
  1317. }
  1318. },
  1319. saveChart: function(json) {//采用chartMix store存储,弃用Store.luckysheetfile存储,防止重复存储
  1320. let index = this.getSheetIndex(json.sheetIndex);
  1321. let file = Store.luckysheetfile[index];
  1322. if (file.chart == null) {
  1323. file.chart = [];
  1324. file.chart.push(json);
  1325. }
  1326. else {
  1327. for (let i = 0; i < file.chart.length; i++) {
  1328. if (file.chart[i].chart_id == json.chart_id) {
  1329. let old = $.extend(true, {}, file.chart[i]);
  1330. file.chart[i] = $.extend(true, {}, old, json);
  1331. return;
  1332. }
  1333. }
  1334. file.chart.push(json);
  1335. }
  1336. },
  1337. getChart: function(sheetIndex, chart_id) {
  1338. let index = this.getSheetIndex(sheetIndex);
  1339. let file = Store.luckysheetfile[index];
  1340. if (file.chart == null) {
  1341. return null;
  1342. }
  1343. else {
  1344. for (let i = 0; i < file.chart.length; i++) {
  1345. if (file.chart[i].chart_id == chart_id) {
  1346. return file.chart[i];
  1347. }
  1348. }
  1349. return null;
  1350. }
  1351. },
  1352. getRangetxt: function(sheetIndex, range, currentIndex) {
  1353. let sheettxt = "";
  1354. if (currentIndex == null) {
  1355. currentIndex = Store.currentSheetIndex;
  1356. }
  1357. if (sheetIndex != currentIndex) {
  1358. sheettxt = Store.luckysheetfile[this.getSheetIndex(sheetIndex)].name + "!";
  1359. }
  1360. let row0 = range["row"][0], row1 = range["row"][1];
  1361. let column0 = range["column"][0], column1 = range["column"][1];
  1362. if (row0 == null && row1 == null) {
  1363. return sheettxt + chatatABC(column0) + ":" + chatatABC(column1);
  1364. }
  1365. else if (column0 == null && column1 == null) {
  1366. return sheettxt + (row0 + 1) + ":" + (row1 + 1);
  1367. }
  1368. else {
  1369. if (column0 == column1 && row0 == row1) {
  1370. return sheettxt + chatatABC(column0) + (row0 + 1);
  1371. }
  1372. else {
  1373. return sheettxt + chatatABC(column0) + (row0 + 1) + ":" + chatatABC(column1) + (row1 + 1);
  1374. }
  1375. }
  1376. },
  1377. getSheetName: function(sheetIndex) {
  1378. if (sheetIndex == null) {
  1379. sheetIndex = Store.currentSheetIndex;
  1380. }
  1381. return Store.luckysheetfile[this.getSheetIndex(sheetIndex)].name;
  1382. },
  1383. getSheetMerge: function() {
  1384. if(Store.config.merge == null){
  1385. return null;
  1386. }
  1387. return Store.config.merge;
  1388. },
  1389. getSheetData: function(sheetIndex) {
  1390. if (sheetIndex == null) {
  1391. sheetIndex = Store.currentSheetIndex;
  1392. }
  1393. return Store.luckysheetfile[this.getSheetIndex(sheetIndex)].data;
  1394. },
  1395. getSheetConfig: function(sheetIndex) {
  1396. let _this = this;
  1397. if (sheetIndex == null) {
  1398. sheetIndex = Store.currentSheetIndex;
  1399. }
  1400. let config = Store.luckysheetfile[_this.getSheetIndex(sheetIndex)].config;
  1401. if(config == null){
  1402. Store.luckysheetfile[_this.getSheetIndex(sheetIndex)].config = {};
  1403. }
  1404. return Store.luckysheetfile[_this.getSheetIndex(sheetIndex)].config;
  1405. },
  1406. restoreFilter: function(sheetIndex) {
  1407. let index = this.getSheetIndex(sheetIndex);
  1408. let file = Store.luckysheetfile[index];
  1409. // if($('#luckysheet-filter-selected-sheet' + sheetIndex).length > 0 || file.filter_select == null || JSON.stringify(file.filter_select) == "{}"){
  1410. // if(file.config != null && file.config.rowhidden != null){
  1411. // file.config.rowhidden = {};
  1412. // Store.config = file.config;
  1413. // jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length,false);
  1414. // }
  1415. // return;
  1416. // }
  1417. if(getObjType(file.filter_select) == "string"){
  1418. file.filter_select = JSON.parse(file.filter_select);
  1419. }
  1420. if(file.filter_select == null || file.filter_select.row == null || file.filter_select.column == null){
  1421. return;
  1422. }
  1423. createFilterOptions(file.filter_select);
  1424. if(getObjType(file.filter) != "object"){
  1425. if(file.filter != null && getObjType(file.filter) == "string"){
  1426. file.filter = JSON.parse(file.filter);
  1427. }
  1428. }
  1429. let rowhidden = {};
  1430. if(file.config != null && file.config.rowhidden != null){
  1431. rowhidden = file.config.rowhidden;
  1432. }
  1433. $("#luckysheet-filter-options-sheet" + sheetIndex + " .luckysheet-filter-options").each(function(i){
  1434. if(file.filter == null){
  1435. return false;
  1436. }
  1437. let $top = $(this);
  1438. let item = file.filter[i];
  1439. if(item == null){
  1440. return true;
  1441. }
  1442. if(getObjType(item) != "object"){
  1443. item = JSON.parse(item);
  1444. }
  1445. labelFilterOptionState($top, item.optionstate, item.rowhidden, item.caljs, false, item.st_r, item.ed_r, item.cindex, item.st_c, item.ed_c);
  1446. rowhidden = $.extend(true, rowhidden, item.rowhidden);
  1447. });
  1448. if(file.config == null){
  1449. file.config = {};
  1450. }
  1451. file.config["rowhidden"] = rowhidden;
  1452. Store.config = file.config;
  1453. jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length,false);
  1454. },
  1455. restorePivot: function(sheetIndex) {
  1456. let index = this.getSheetIndex(sheetIndex);
  1457. let file = Store.luckysheetfile[index];
  1458. if (!file.isPivotTable) {
  1459. return;
  1460. }
  1461. pivotTable.getCellData(sheetIndex);
  1462. pivotTable.initialPivotManage(true);
  1463. pivotTable.refreshPivotTable(false);
  1464. },
  1465. restoreSheetAll: function(sheetIndex) {
  1466. let _this= this;
  1467. _this.restorePivot(sheetIndex);
  1468. _this.restoreFilter(sheetIndex);
  1469. _this.restoreFreezen(sheetIndex);
  1470. },
  1471. restoreFreezen: function(sheetIndex) {
  1472. luckysheetFreezen.initialFreezen(sheetIndex);
  1473. },
  1474. restoreCache: function() {
  1475. let _this = this;
  1476. let data = _this.CacheNotLoadControll;
  1477. _this.CacheNotLoadControll = [];
  1478. if(data.length == 0){
  1479. return;
  1480. }
  1481. for(let i = 0; i < data.length; i++){
  1482. let item = data[i];
  1483. _this.execCache(item);
  1484. }
  1485. },
  1486. CacheNotLoadControll:[],
  1487. execCache: function(item) {
  1488. let _this = this;
  1489. let type = item.t;
  1490. let index = item.i;
  1491. let value = item.v;
  1492. let file = Store.luckysheetfile[_this.getSheetIndex(index)];
  1493. if(type == "sha"){
  1494. Store.luckysheetfile.push(value);
  1495. }
  1496. else if(type == "shc"){
  1497. let copyjson = $.extend(true, {}, Store.luckysheetfile[_this.getSheetIndex(value.copyindex)]);
  1498. copyjson.index = index;
  1499. Store.luckysheetfile.push(copyjson);
  1500. }
  1501. else if(type == "shd"){
  1502. Store.luckysheetfile.splice(value.deleIndex, 1);
  1503. }
  1504. else if(type == "shr"){
  1505. for(let pos in value){
  1506. Store.luckysheetfile[_this.getSheetIndex(pos)].order = value[pos];
  1507. }
  1508. }
  1509. if((file == null || file.load != "1") && !(type in {"sha":0, "shc":0, "shd":0, "shr":0}) ){
  1510. _this.CacheNotLoadControll.push(item);
  1511. return;
  1512. }
  1513. if(type == "v"){
  1514. let r = item.r, c = item.c, v = item.v;
  1515. let data = _this.getSheetData(index);
  1516. file.data[r][c] = v;
  1517. }
  1518. else if(type == "fc"){
  1519. let op = item.op, pos = item.pos;
  1520. if(getObjType(value) != "object"){
  1521. value = new Function("return " + value)();
  1522. }
  1523. let r = value.r, c = value.c;
  1524. if(op == "del" ){
  1525. formula.delFunctionGroup(r, c, index);
  1526. }
  1527. else {
  1528. formula.insertUpdateFunctionGroup(r, c, index);
  1529. }
  1530. }
  1531. else if(type == "cg"){
  1532. let v = value, k = item.k;
  1533. let config1 = _this.getSheetConfig(index);
  1534. if(!(k in config1)){
  1535. config1[k] = {};
  1536. }
  1537. for(let key in v){
  1538. config1[k][key] = v[key];
  1539. }
  1540. Store.config = config1;
  1541. }
  1542. else if(type == "f"){
  1543. let v = value, op = item.op, pos = item.pos;
  1544. let filter = file.filter;
  1545. if(filter == null){
  1546. filter = {};
  1547. }
  1548. if(op == "upOrAdd"){
  1549. filter[pos] = v;
  1550. }
  1551. else if(op == "del"){
  1552. delete filter[pos];
  1553. }
  1554. }
  1555. else if(type == "fsc"){
  1556. file.filter = null;
  1557. file.filter_select = null;
  1558. }
  1559. else if(type == "fsr"){
  1560. let v = value;
  1561. file.filter = v.filter;
  1562. file.filter_select = v.filter_select;
  1563. }
  1564. else if(type == "sh"){
  1565. let op = item.op, cur = item.cur, v = value;
  1566. if(op == "hide"){
  1567. file.status = 0;
  1568. Store.luckysheetfile[_this.getSheetIndex(cur)].status = 1;
  1569. }
  1570. else if(op == "show"){
  1571. for(let i = 0; i < Store.luckysheetfile.length; i++){
  1572. Store.luckysheetfile[i].status = 0;
  1573. }
  1574. file.status = 1;
  1575. }
  1576. }
  1577. else if(type == "all"){
  1578. let k = item.k, s = item.s;
  1579. if(s && getObjType(value) != "object"){
  1580. file[k] = JSON.stringify(value);
  1581. }
  1582. else{
  1583. file[k] = value;
  1584. }
  1585. }
  1586. else if(type == "c"){
  1587. let op = item.op, cid = item.cid;
  1588. if(op == "add"){
  1589. file.chart.push(value);
  1590. }
  1591. else if(op == "xy" || op == "wh" || op == "update"){
  1592. for(let i = 0; i < file.chart.length; i++){
  1593. if(file.chart[i].chart_id == cid){
  1594. for(let item in file.chart[i]){
  1595. for(let vitem in value){
  1596. if(item == vitem){
  1597. file.chart[i][item] = value[vitem];
  1598. }
  1599. }
  1600. }
  1601. return;
  1602. }
  1603. }
  1604. }
  1605. else if(op == "del"){
  1606. for(let i = 0; i < file.chart.length; i++){
  1607. if(file.chart[i].chart_id == cid){
  1608. file.chart.splice(i, 1);
  1609. return;
  1610. }
  1611. }
  1612. }
  1613. }
  1614. else if(type == "drc"){
  1615. let rc = item.rc, index = value.index, len = value.len;
  1616. let celldata = file.celldata;
  1617. if(rc == "r"){
  1618. for(let i = 0; celldata.length == 0; i++){
  1619. let cell = celldata[i];
  1620. if(cell.r >= index && cell.r < index + len){
  1621. delete celldata[i];
  1622. }
  1623. else if(cell.r >= index + len){
  1624. cell.r -= len;
  1625. }
  1626. }
  1627. file.row -= len;
  1628. }
  1629. else{
  1630. for(let i = 0; celldata.length == 0; i++){
  1631. let cell = celldata[i];
  1632. if(cell.c >= index && cell.c < index + len){
  1633. delete celldata[i];
  1634. }
  1635. else if(cell.c >= index + len){
  1636. cell.c -= len;
  1637. }
  1638. }
  1639. file.column -= len;
  1640. }
  1641. let ret = [];
  1642. for(let i = 0; i < celldata.length; i++){
  1643. if(celldata[i] != null){
  1644. ret.push(celldata[i]);
  1645. }
  1646. }
  1647. file.celldata = ret;
  1648. let mtype, mst, med;
  1649. if(rc == "r"){
  1650. mtype = "row";
  1651. }
  1652. else{
  1653. mtype = "column";
  1654. }
  1655. mst = index;
  1656. med = index + len - 1;
  1657. luckysheetdeletetable(mtype, mst, med, true);
  1658. }
  1659. else if(type=="arc"){
  1660. let rc = item.rc, index = value.index, len = value.len;
  1661. let celldata = file.celldata;
  1662. if(rc == "r"){
  1663. for(let i = 0; i < celldata.length; i++){
  1664. let cell = celldata[i];
  1665. if(cell.r > index){
  1666. cell.r += len;
  1667. }
  1668. }
  1669. file.row += len;
  1670. }
  1671. else{
  1672. for(let i = 0; i < celldata.length; i++){
  1673. let cell = celldata[i];
  1674. if(cell.c > index){
  1675. cell.c += len;
  1676. }
  1677. }
  1678. file.column += len;
  1679. }
  1680. let mtype;
  1681. if(rc == "r"){
  1682. mtype = "row";
  1683. }
  1684. else{
  1685. mtype = "column";
  1686. }
  1687. luckysheetextendtable(mtype, index, len, true);
  1688. }
  1689. else if(type == "na"){
  1690. server.saveParam("na", null, value);
  1691. }
  1692. else if(type == "thumb"){
  1693. setTimeout(function(){
  1694. _this.imageRequest();
  1695. }, 2000);
  1696. }
  1697. }
  1698. }
  1699. export default sheetmanage;