onlineShareExcel.html 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. <!DOCTYPE html>
  2. <html>
  3. <head lang='zh'>
  4. <meta charset='utf-8'>
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="renderer" content="webkit" />
  7. <meta name="viewport" content="width=device-width, initial-scale=1,user-scalable=0" />
  8. <title>Luckysheet</title>
  9. <link rel='stylesheet' href='/static/js/luckysheet/plugins/css/pluginsCss.css' />
  10. <link rel='stylesheet' href='/static/js/luckysheet/plugins/plugins.css' />
  11. <link rel='stylesheet' href='/static/js/luckysheet/css/luckysheet.css' />
  12. <link rel='stylesheet' href='/static/js/luckysheet/assets/iconfont/iconfont.css' />
  13. <link charset="utf-8" rel="stylesheet" href="/static/css/layui.css?v=1.0.0">
  14. <script>
  15. var _PageHeight = document.documentElement.clientHeight,
  16. _PageWidth = document.documentElement.clientWidth;
  17. var _LoadingTop = _PageHeight > 61 ? (_PageHeight - 61) / 2 : 0,
  18. _LoadingLeft = _PageWidth > 215 ? (_PageWidth - 215) / 2 : 0;
  19. var _LoadingHtml = '<div id="loadingDiv" style="position:absolute;left:0;width:100%;height:' + _PageHeight + 'px;top:0;background:#f3f8ff;opacity:1;filter:alpha(opacity=80);z-index:10000;"><div style="position: absolute; cursor1: wait; left: ' + _LoadingLeft + 'px; top:' + _LoadingTop + 'px; width: auto; height: 57px; line-height: 57px; padding-left: 50px; padding-right: 5px; color: #696969; font-family:\'Microsoft YaHei\';"><img style="width:200px;height:200px" src="../images/loading.gif"></div></div>';
  20. document.write(_LoadingHtml);
  21. document.onreadystatechange = completeLoading;
  22. function completeLoading() {
  23. if (document.readyState == "complete") {
  24. var loadingMask = document.getElementById('loadingDiv');
  25. loadingMask.parentNode.removeChild(loadingMask);
  26. }
  27. }
  28. </script>
  29. <script src="/static/js/layui.js?v=1.0.0"></script>
  30. <script src="/static/js/exceljs.js"></script>
  31. <script src="/static/js/fileSave.js"></script>
  32. <script src="/static/js/luckysheet/luckSheetExcel.js"></script>
  33. <script src="/static/js/luckysheet/plugins/js/plugin.js"></script>
  34. <script src="/static/js/luckysheet/luckysheet.umd.js"></script>
  35. <script src="/static/js/api.config.js"></script>
  36. <script src="/static/js/util.js?v=1.0.0"></script>
  37. <script src="/static/js/url.js?v=1.0.0"></script>
  38. <script src="/static/js/exportExcel.js"></script>
  39. <script src="/static/js/fullScreen.js"></script>
  40. </head>
  41. <style>
  42. * {
  43. padding: 0;
  44. margin: 0;
  45. }
  46. html,
  47. body {
  48. height: 100%;
  49. }
  50. #monthSelect {
  51. padding: 10px 0px;
  52. }
  53. </style>
  54. <body style="background: #fff;">
  55. <div class="layui-inline" id="monthSelect" style="width: 100%">
  56. <div class="layui-input-inline">
  57. <form>
  58. <label>控制权限</label>
  59. <select name="city" id="editStatus" style="width: 70px">
  60. <option value="0">开启</option>
  61. <option value="1">关闭</option>
  62. </select>
  63. <label> 可编辑列:从 </label><input type="text" id="editFrom" style="width: 50px"
  64. onkeyup="this.value=this.value.replace('-','')"></input> 到 <input type="text" id="editTo"
  65. style="width: 50px" onkeyup="this.value=this.value.replace('-','')"></input>
  66. </form>
  67. </div>
  68. <div style="float: right;padding-right: 10px" id="shareBtn">
  69. <button id="share" class="btn btn-primary"
  70. style="padding:3px 6px;font-size: 18px;margin-right: 10px;width: 100px">分享
  71. </button>
  72. </div>
  73. <div style="float: right;padding-right: 10px" id="newShareBtn">
  74. <button id="newShare" class="btn btn-primary"
  75. style="padding:3px 6px;font-size: 18px;margin-right: 10px;width: 100px">分享
  76. </button>
  77. </div>
  78. </div>
  79. <div style="height:90%;width: 100%;">
  80. <div id="luckysheet" style="width:100%;height:100%">
  81. </div>
  82. </div>
  83. <script>
  84. //监听window是否全屏,并进行相应的操作,支持esc键退出
  85. window.onresize = function () {
  86. var isFull = !!(document.webkitIsFullScreen || document.mozFullScreen ||
  87. document.msFullscreenElement || document.fullscreenElement
  88. );//!document.webkitIsFullScreen都为true。因此用!!
  89. if (isFull == false) {
  90. $("#exitFullScreen").css("display", "none");
  91. $("#fullScreen").css("display", "");
  92. } else {
  93. $("#exitFullScreen").css("display", "");
  94. $("#fullScreen").css("display", "none");
  95. }
  96. }
  97. </script>
  98. <script>
  99. var lockFlag = 'see';
  100. util.ajaxJson("", ctx + "/market/cadvLedger/getRoleByCode", {}, function (res) {
  101. console.log("html" + res.result);
  102. if (res.result == 1) {
  103. lockFlag = 'add';//省级
  104. } else {
  105. lockFlag = 'updata';//管理员
  106. }
  107. });
  108. var id = '' // 模板id 查看/修改load时候用
  109. var powerFlag = '0'; // 权限控制 0 开启 1关闭
  110. var excelId = '';
  111. var flag = false; // 控制excel是否可以编辑
  112. var adminFlag = false;
  113. var userId; // 用户ID
  114. var excelInfo = {};
  115. var isAdmin = '';
  116. var excelLevel = '';
  117. var toolBar = '';
  118. var type = '';
  119. var emptyExcel = false;
  120. var fullScreenState = false;
  121. $(function () {
  122. userId = JSON.parse(window.top.sessionStorage.userInfo).loginNo
  123. })
  124. layui.use(['laydate', 'form'], function () {
  125. var laydate = layui.laydate;
  126. var form = layui.form;
  127. form.on('select(powerFlag)', function (data) {
  128. powerFlag = data.value
  129. })
  130. // 获取数据
  131. function getData() {
  132. // 先销毁excel重新加载
  133. if (window.luckysheet) {
  134. window.luckysheet.destroy();
  135. }
  136. //拿参数的
  137. var excelId = $(window.parent.document).find("#excelId").attr("value");
  138. console.log(excelId);
  139. type = '2';
  140. toolBar = '';
  141. var url = '/market/cOnlineExcel/getExcelInfo';
  142. util.ajaxJson("数据加载中", ctx + url, {
  143. "id": excelId ? excelId : '',
  144. }, function (res) {
  145. if (res.result == 0) {
  146. // 查看和修改时 下拉框赋值
  147. excelInfo = res.body.excelInfo;
  148. excelLevel = res.body.excelLevel;
  149. isAdmin = res.body.isExcelAdmin;
  150. emptyExcel = res.body.emptyExcel;
  151. $("#editFrom").val(excelInfo.editConStart);
  152. $("#editTo").val(excelInfo.editConEnd);
  153. $("#editStatus").val(excelInfo.editStatus);
  154. console.log(type);
  155. if (type == '2') {
  156. if (isAdmin) {
  157. toolBar += '<input id="imports" type="file" class="btn btn-primary" style="padding:3px 6px;font-size: 12px;margin-right: 10px;"></input>';
  158. }
  159. }
  160. console.log(5);
  161. if (isAdmin) {
  162. toolBar += '<button id="exports" class="btn btn-primary btn-danger" style="padding:3px 6px;font-size: 12px;margin-right: 10px;">导出</button>';
  163. }
  164. console.log(6);
  165. toolBar += '<button id="saves" class="btn btn-primary btn-danger" style=" padding:3px 6px; font-size: 12px; margin-right: 10px;">保存</button>';
  166. toolBar += '<button id="closeExcel" class="btn btn-primary" style="padding:3px 6px;font-size: 12px;margin-right: 10px;">返回</button><button id="fullScreen" class="btn btn-primary" style="padding:3px 6px;font-size: 12px;margin-right: 10px;">全屏显示</button><button id="exitFullScreen" class="btn btn-primary" style="padding:3px 6px;font-size: 12px;margin-right: 10px;display:none">退出全屏</button>';
  167. var eJson = res.body.excelJson;
  168. console.log(7);
  169. // var cellData = luckysheet.transToCellData(eJson[0].data);
  170. console.log(8);
  171. // eJson[0].celldata = cellData;
  172. console.log(res.body.excelJson);
  173. initExcel(res.body.excelJson, '', excelId);
  174. }
  175. });
  176. //initExcel()
  177. }
  178. // 表格初始化
  179. function initExcel(data, name, ids) {
  180. if (type == '1') {
  181. flag = false
  182. } else {
  183. flag = true
  184. }
  185. if (isAdmin) {
  186. adminFlag = true;
  187. }
  188. var fileName = excelInfo.fileName;
  189. if ($.trim(name) != '') {
  190. fileName = name;
  191. }
  192. try {
  193. console.log(123);
  194. luckysheet.create({
  195. container: 'luckysheet',
  196. data: data,
  197. showsheetbar: false, // 底部sheet显示/隐藏
  198. loadUrl:
  199. window.location.protocol +
  200. "//43.138.50.94:7777" +
  201. "/sheet/worksheet/" +
  202. ids + '/' +JSON.parse(window.sessionStorage.userInfo).loginNo,
  203. loadSheetUrl:
  204. window.location.protocol +
  205. "//43.138.50.94:7777" +
  206. "/sheet/loadsheet/" +
  207. ids,
  208. updateUrl:
  209. "ws://" +
  210. "//43.138.50.94:7777" +
  211. "/ws/" +
  212. JSON.parse(window.sessionStorage.userInfo).loginName +
  213. "/" +
  214. ids,
  215. showsheetbarConfig: {
  216. add: false, //新增sheet
  217. menu: false, //sheet管理菜单
  218. sheet: false //sheet页显示
  219. },
  220. showstatisticBar: false, // 底部计数
  221. showtoolbar: true,
  222. myFolderUrl: '',
  223. showtoolbarConfig: {
  224. undoRedo: true, //撤销重做,注意撤消重做是两个按钮,由这一个配置决定显示还是隐藏
  225. paintFormat: true, //格式刷
  226. currencyFormat: true, //货币格式
  227. percentageFormat: true, //百分比格式
  228. numberDecrease: true, // '减少小数位数'
  229. numberIncrease: true, // '增加小数位数
  230. moreFormats: true, // '更多格式'
  231. font: true, // '字体'
  232. fontSize: true, // '字号大小'
  233. bold: true, // '粗体 (Ctrl+B)'
  234. italic: true, // '斜体 (Ctrl+I)'
  235. strikethrough: true, // '删除线 (Alt+Shift+5)'
  236. underline: true, // '下划线 (Alt+Shift+6)'
  237. textColor: true, // '文本颜色'
  238. fillColor: true, // '单元格颜色'
  239. border: true, // '边框'
  240. mergeCell: true, // '合并单元格'
  241. horizontalAlignMode: true, // '水平对齐方式'
  242. verticalAlignMode: true, // '垂直对齐方式'
  243. textWrapMode: true, // '换行方式'
  244. textRotateMode: false, // '文本旋转方式'
  245. image: false, // '插入图片'
  246. link: false, // '插入链接'
  247. chart: false, // '图表'(图标隐藏,但是如果配置了chart插件,右击仍然可以新建图表)
  248. postil: false, //'批注'
  249. pivotTable: false, //'数据透视表'
  250. function: true, // '公式'
  251. frozenMode: true, // '冻结方式'
  252. sortAndFilter: true, // '排序和筛选'
  253. conditionalFormat: false, // '条件格式'
  254. dataVerification: false, // '数据验证'
  255. splitColumn: true, // '分列'
  256. screenshot: false, // '截图'
  257. findAndReplace: true, // '查找替换'
  258. protection: false, // '工作表保护'
  259. print: false, // '打印'
  260. },
  261. showinfobar: true, // 顶部信息 文件名称 按钮
  262. allowUpdate: true, // 是否允许操作表格后的后台更新 在线文档websocket时为true
  263. allowEdit: flag, // 是否允许前台编辑
  264. title: fileName, // 文件名称
  265. lang: 'zh',
  266. enableAddRow: true,
  267. showstatisticBar: false, // 底部计数
  268. showstatisticBarConfig: {
  269. count: false, // 计数栏
  270. view: false, // 打印视图
  271. zoom: false, // 缩放
  272. },
  273. functionButton: toolBar,
  274. cellRightClickConfig: {
  275. copy: false, // 复制
  276. copyAs: false, // 复制为
  277. paste: false, // 粘贴
  278. insertRow: true, // 插入行
  279. insertColumn: true, // 插入列
  280. deleteRow: true, // 删除选中行
  281. deleteColumn: true, // 删除选中列
  282. deleteCell: false, // 删除单元格
  283. hideRow: false, // 隐藏选中行和显示选中行
  284. hideColumn: false, // 隐藏选中列和显示选中列
  285. rowHeight: true, // 行高
  286. columnWidth: true, // 列宽
  287. clear: false, // 清除内容
  288. matrix: false, // 矩阵操作选区
  289. sort: false, // 排序选区
  290. filter: false, // 筛选选区
  291. chart: false, // 图表生成
  292. image: false, // 插入图片
  293. link: false, // 插入链接
  294. data: false, // 数据验证
  295. cellFormat: false, // 设置单元格格式
  296. mComplete: false,
  297. mCetup: false,
  298. mRevoke: false,
  299. },
  300. hook: {
  301. cellMousedown: function (a, b, c) {
  302. },
  303. cellUpdateBefore: function (r, c) {
  304. },
  305. cellMousedownBefore: function (a, p, s) {
  306. },
  307. rangePasteBefore: function (range, data) {
  308. },
  309. },
  310. })
  311. } catch (err) {
  312. console.log(err)
  313. }
  314. if (isAdmin == false) {
  315. $("#editStatus").attr('disabled', true);
  316. $("#editFrom").attr('disabled', true);
  317. $("#editTo").attr('disabled', true);
  318. $("#shareBtn").hide();
  319. $("#newShareBtn").hide();
  320. } else {
  321. $("#editStatus").attr('disabled', false);
  322. $("#editFrom").attr('disabled', false);
  323. $("#editTo").attr('disabled', false);
  324. $("#shareBtn").show();
  325. $("#newShareBtn").show();
  326. }
  327. if (emptyExcel == true) {
  328. $("#shareBtn").show();
  329. $("#saves").hide();
  330. $("#newShareBtn").hide();
  331. } else {
  332. $("#shareBtn").hide();
  333. $("#saves").show();
  334. if (isAdmin) {
  335. $("#newShareBtn").show();
  336. }
  337. //console.log("执行自动保存定时器")
  338. // var t1 = window.setInterval(function autoSave() {
  339. // console.log("执行自动保存")
  340. // var excelId = $(window.parent.document).find("#excelId").attr("value");
  341. // var sheetName = luckysheet.getSheet().name;
  342. // var excelData = luckysheet.getSheet(sheetName);
  343. // var urlsave = '/market/cOnlineExcel/saveExcel';
  344. // var editFrom = $("#editFrom").val();
  345. // var editTo = $("#editTo").val();
  346. // var editStatus = $("#editStatus").val();
  347. // var excelName = luckysheet.toJson().title;
  348. // if ($.trim(editFrom) == '' && $.trim(editTo) == '') {
  349. //
  350. // } else if (/^\d*$/.test(editFrom) && /^\d*$/.test(editTo)) {
  351. // if (editFrom == 0) {
  352. // window.top.$vm.$message({
  353. // message: '自动保存出错:可编辑列开始不能为0',
  354. // type: 'info'
  355. // })
  356. // return;
  357. // }
  358. // if (editFrom > editTo) {
  359. // window.top.$vm.$message({
  360. // message: '自动保存出错:可编辑列的起始列不能大于结束列',
  361. // type: 'info'
  362. // })
  363. // return;
  364. // }
  365. // } else if (/^[a-zA-Z]+$/.test(editFrom) && /^[a-zA-Z]+$/.test(editTo)) {
  366. //
  367. // } else {
  368. // window.top.$vm.$message({
  369. // message: '自动保存出错:可编辑列必须全部为字母或数字',
  370. // type: 'info'
  371. // });
  372. // return;
  373. // }
  374. // util.ajaxJson(null, ctx + '/market/cOnlineExcel/checkExcelEmpty', {
  375. // data: excelData,
  376. // }, function (data) {
  377. // if (data.result == 1) {
  378. // window.top.$vm.$message({
  379. // message: data.desc,
  380. // type: 'error'
  381. // });
  382. // } else {
  383. // util.ajaxJson(null, ctx + urlsave, {
  384. // data: excelData,
  385. // id: excelId,
  386. // editConStart: editFrom,
  387. // editConEnd: editTo,
  388. // excelName: excelName,
  389. // editStatus: editStatus
  390. // }, function (data) {
  391. // if (data.result == 1) {
  392. // window.top.$vm.$message({
  393. // message: data.desc,
  394. // type: 'error'
  395. // })
  396. // } else {
  397. // // window.top.$vm.$message({
  398. // // message: '自动保存成功',
  399. // // type: 'info'
  400. // // });
  401. // //console.log(data);
  402. // //getData()
  403. // }
  404. // });
  405. // }
  406. // });
  407. // }, 15000)
  408. }
  409. if (excelInfo.shareStatus == '1') {
  410. $("#editTo").attr('disabled', true);
  411. $("#editFrom").attr('disabled', true);
  412. } else {
  413. $("#editTo").attr('disabled', false);
  414. $("#editFrom").attr('disabled', false);
  415. }
  416. initHandel();
  417. }
  418. function isNumber(val) {
  419. var regPos = /^\d+(\.\d+)?$/; //非负浮点数
  420. var regNeg = /^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$/;
  421. //负浮点数
  422. if (regPos.test(val) && regNeg.test(val)) {
  423. return true;
  424. } else {
  425. return false;
  426. }
  427. }
  428. function processShare(type) {
  429. // 当前工作表名
  430. var excelId = $(window.parent.document).find("#excelId").attr("value");
  431. var sheetName = luckysheet.getSheet().name;
  432. var excelData = luckysheet.getSheet(sheetName);
  433. var urlsave = '/market/cOnlineExcel/saveExcel';
  434. var editFrom = $("#editFrom").val();
  435. var editTo = $("#editTo").val();
  436. var editStatus = $("#editStatus").val();
  437. var excelName = luckysheet.toJson().title;
  438. //校验可编辑列
  439. if ($.trim(editFrom) == '' && $.trim(editTo) == '') {
  440. } else if (/^\d*$/.test(editFrom) && /^\d*$/.test(editTo)) {
  441. if (editFrom == 0) {
  442. window.top.$vm.$message({
  443. message: '可编辑列开始不能为0',
  444. type: 'info'
  445. })
  446. return;
  447. }
  448. if (editFrom > editTo) {
  449. window.top.$vm.$message({
  450. message: '可编辑列的起始列不能大于结束列',
  451. type: 'info'
  452. })
  453. return;
  454. }
  455. } else if (/^[a-zA-Z]+$/.test(editFrom) && /^[a-zA-Z]+$/.test(editTo)) {
  456. } else {
  457. window.top.$vm.$message({
  458. message: '可编辑列必须全部为字母或数字',
  459. type: 'info'
  460. })
  461. return;
  462. }
  463. util.ajaxJson("正在加载中", ctx + '/market/cOnlineExcel/checkExcelEmpty', {
  464. data: excelData,
  465. }, function (data) {
  466. if (data.result == 1) {
  467. window.top.$vm.$message({
  468. message: data.desc,
  469. type: 'error'
  470. });
  471. } else {
  472. //excelJson, editFrom, editTo, editStatus, excelName, excelId, type
  473. window.parent['shareExcel'](excelData, editFrom, editTo, editStatus, excelName, excelId, type);
  474. }
  475. });
  476. }
  477. // 绑定按钮事件
  478. function initHandel() {
  479. $("#closeExcel").on("click", function () {
  480. window.parent['backToExcelList']('true');
  481. })
  482. $("#fullScreen").on("click", function () {
  483. if (fullScreenState) {
  484. fullScreenState = false;
  485. $("#fullScreen").html('全屏显示');
  486. } else {
  487. fullScreenState = true;
  488. $("#fullScreen").html('退出全屏');
  489. }
  490. window.parent['fullScreen']('true');
  491. //fullScreen();
  492. })
  493. //退出全屏
  494. $("#exitFullScreen").on("click", function () {
  495. exitFullscreen();
  496. })
  497. //分享
  498. $('#share').off("click").click(function () {
  499. if (fullScreenState) {
  500. fullScreenState = false;
  501. $("#fullScreen").html('全屏显示');
  502. window.parent['fullScreen']('true');
  503. }
  504. processShare(1);
  505. });
  506. //新增分享
  507. $('#newShare').off("click").click(function () {
  508. if (fullScreenState) {
  509. fullScreenState = false;
  510. $("#fullScreen").html('全屏显示');
  511. window.parent['fullScreen']('true');
  512. }
  513. processShare(2);
  514. });
  515. // 保存
  516. $('#saves').off("click").click(function () {
  517. console.log(123);
  518. // 当前工作表名
  519. var excelId = $(window.parent.document).find("#excelId").attr("value");
  520. var sheetName = luckysheet.getSheet().name;
  521. var excelData = luckysheet.getSheet(sheetName);
  522. var urlsave = '/market/cOnlineExcel/saveExcel';
  523. var editFrom = $("#editFrom").val();
  524. var editTo = $("#editTo").val();
  525. var editStatus = $("#editStatus").val();
  526. var excelName = luckysheet.toJson().title;
  527. if ($.trim(editFrom) == '' && $.trim(editTo) == '') {
  528. } else if (/^\d*$/.test(editFrom) && /^\d*$/.test(editTo)) {
  529. if (editFrom == 0) {
  530. window.top.$vm.$message({
  531. message: '可编辑列开始不能为0',
  532. type: 'info'
  533. })
  534. return;
  535. }
  536. if (editFrom > editTo) {
  537. window.top.$vm.$message({
  538. message: '可编辑列的起始列不能大于结束列',
  539. type: 'info'
  540. })
  541. return;
  542. }
  543. } else if (/^[a-zA-Z]+$/.test(editFrom) && /^[a-zA-Z]+$/.test(editTo)) {
  544. } else {
  545. window.top.$vm.$message({
  546. message: '可编辑列必须全部为字母或数字',
  547. type: 'info'
  548. });
  549. return;
  550. }
  551. util.ajaxJson("正在加载中", ctx + '/market/cOnlineExcel/checkExcelEmpty', {
  552. data: excelData,
  553. }, function (data) {
  554. if (data.result == 1) {
  555. window.top.$vm.$message({
  556. message: data.desc,
  557. type: 'error'
  558. });
  559. } else {
  560. util.ajaxJson("正在加载中", ctx + urlsave, {
  561. data: excelData,
  562. id: excelId,
  563. editConStart: editFrom,
  564. editConEnd: editTo,
  565. excelName: excelName,
  566. editStatus: editStatus
  567. }, function (data) {
  568. if (data.result == 1) {
  569. window.top.$vm.$message({
  570. message: data.desc,
  571. type: 'error'
  572. })
  573. } else {
  574. window.top.$vm.$message({
  575. message: '保存成功',
  576. type: 'info'
  577. });
  578. console.log(data);
  579. getData()
  580. }
  581. });
  582. }
  583. });
  584. })
  585. // 导出
  586. $('#exports').click(function () {
  587. var excelName = luckysheet.toJson().title;
  588. exportExcel(luckysheet.getluckysheetfile(), excelName)
  589. })
  590. // 导入
  591. $("#imports").change(function (evt) {
  592. var files = evt.target.files;
  593. if (files == null || files.length == 0) {
  594. window.top.$vm.$message({
  595. message: '没有文件导入',
  596. type: 'info'
  597. })
  598. return;
  599. }
  600. var name = files[0].name;
  601. var suffixArr = name.split("."),
  602. suffix = suffixArr[suffixArr.length - 1];
  603. if (suffix != "xlsx") {
  604. window.top.$vm.$message({
  605. message: '目前只支持xlsx文件的导入',
  606. type: 'info'
  607. })
  608. return;
  609. }
  610. // 解析文件
  611. LuckyExcel.transformExcelToLucky(
  612. files[0],
  613. function (exportJson, luckysheetfile) {
  614. console.log(exportJson);
  615. if (exportJson.sheets == null || exportJson.sheets.length == 0) {
  616. window.top.$vm.$message({
  617. message: '无法读取excel文件的内容,当前不支持xls文件',
  618. type: 'info'
  619. })
  620. return;
  621. }
  622. // 销毁原来的excel
  623. window.luckysheet.destroy();
  624. // 重新加载
  625. var a = exportJson.sheets[0];
  626. a.name = '';
  627. initExcel([a], name.replace('.xlsx', ''));
  628. // 绑定按钮事件
  629. initHandel()
  630. }
  631. );
  632. });
  633. }
  634. getData()
  635. })
  636. </script>
  637. </body>
  638. </html>