onlineShareExcels.html 35 KB

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