onlineShareExcel.html 35 KB

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