onlineShareExcel.html 32 KB

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