incomeTemplateExcel.html 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  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_old/plugins/js/plugin.js?v=1.0.0"></script>
  34. <script src="/static/js/luckysheet_old/luckysheet.umd.js?v=1.0.0"></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. </form>
  59. </div>
  60. <div style="float: right;padding-right: 10px" id="shareBtn">
  61. <button id="share" class="btn btn-primary" style="padding:3px 6px;font-size: 18px;margin-right: 10px;width: 100px">分享</button>
  62. </div>
  63. </div>
  64. <div style="height:90%;width: 100%;">
  65. <div id="luckysheet" style="width:100%;height:100%">
  66. </div>
  67. </div>
  68. <script>
  69. //监听window是否全屏,并进行相应的操作,支持esc键退出
  70. window.onresize = function () {
  71. var isFull = !!(document.webkitIsFullScreen || document.mozFullScreen ||
  72. document.msFullscreenElement || document.fullscreenElement
  73. );//!document.webkitIsFullScreen都为true。因此用!!
  74. if (isFull == false) {
  75. $("#exitFullScreen").css("display", "none");
  76. $("#fullScreen").css("display", "");
  77. } else {
  78. $("#exitFullScreen").css("display", "");
  79. $("#fullScreen").css("display", "none");
  80. }
  81. }
  82. </script>
  83. <script>
  84. var id = '' // 模板id 查看/修改load时候用
  85. var powerFlag = '0'; // 权限控制 0 开启 1关闭
  86. var excelId = '';
  87. var flag = false; // 控制excel是否可以编辑
  88. var adminFlag = false;
  89. var userId; // 用户ID
  90. var excelInfo = {};
  91. var isAdmin = '';
  92. var excelLevel = '';
  93. var toolBar = '';
  94. var type = '';
  95. var emptyExcel = false;
  96. $(function () {
  97. userId = JSON.parse(window.top.sessionStorage.userInfo).loginNo
  98. })
  99. layui.use(['laydate', 'form'], function () {
  100. var laydate = layui.laydate;
  101. var form = layui.form;
  102. form.on('select(powerFlag)', function (data) {
  103. powerFlag = data.value
  104. })
  105. // 获取数据
  106. function getData() {
  107. // 先销毁excel重新加载
  108. if (window.luckysheet) {
  109. window.luckysheet.destroy();
  110. }
  111. //拿参数的
  112. var r = window.top.location.href.split('?')[1];
  113. var excelId = r.split('&')[1].split('=')[1];
  114. type = r.split('&')[0].split('=')[1];
  115. console.log("id:" + excelId);
  116. console.log("type:" + type);
  117. toolBar = '';
  118. var url = '/market/cIncomeExcelTemplate/getExcelInfo';
  119. util.ajaxJson("数据加载中", ctx + url,
  120. {
  121. "id": excelId ? excelId : '', "type": type
  122. }, function (res) {
  123. if (res.result == 0) {
  124. // 查看和修改时 下拉框赋值
  125. excelInfo = res.body.excelInfo;
  126. excelLevel = res.body.excelLevel;
  127. isAdmin = res.body.isExcelAdmin;
  128. emptyExcel = res.body.emptyExcel;
  129. console.log(type);
  130. if (type == '2') {
  131. if (isAdmin) {
  132. toolBar += '<input id="imports" type="file" class="btn btn-primary" style="padding:3px 6px;font-size: 12px;margin-right: 10px;"></input>';
  133. }
  134. }
  135. if (isAdmin) {
  136. toolBar += '<button id="exports" class="btn btn-primary btn-danger" style="padding:3px 6px;font-size: 12px;margin-right: 10px;">导出</button>';
  137. }
  138. toolBar += '<button id="saves" class="btn btn-primary btn-danger" style=" padding:3px 6px; font-size: 12px; margin-right: 10px;">保存</button>';
  139. toolBar += '<button id="closeExcel" class="btn btn-primary" style="padding:3px 6px;font-size: 12px;margin-right: 10px;">返回</button>' +
  140. '<button id="fullScreen" class="btn btn-primary" style="padding:3px 6px;font-size: 12px;margin-right: 10px;">全屏显示</button>' +
  141. '<button id="exitFullScreen" class="btn btn-primary" style="padding:3px 6px;font-size: 12px;margin-right: 10px;display:none">退出全屏</button>';
  142. var eJson = res.body.excelJson;
  143. var cellData = luckysheet.transToCellData(eJson[0].data);
  144. eJson[0].celldata = cellData;
  145. initExcel(res.body.excelJson);
  146. }
  147. });
  148. initExcel()
  149. }
  150. // 表格初始化
  151. function initExcel(data,name) {
  152. if (type == '1') {
  153. flag = true
  154. } else {
  155. flag = true
  156. }
  157. if (isAdmin) {
  158. adminFlag = true;
  159. }
  160. var fileName = excelInfo.name;
  161. if ($.trim(name)!=''){
  162. fileName = name;
  163. }
  164. try {
  165. luckysheet.create({
  166. container: 'luckysheet',
  167. data: data,
  168. showsheetbar: false, // 底部sheet显示/隐藏
  169. showsheetbarConfig: {
  170. add: false, //新增sheet
  171. menu: false, //sheet管理菜单
  172. sheet: false //sheet页显示
  173. },
  174. showstatisticBar: false, // 底部计数
  175. showtoolbar: true,
  176. myFolderUrl: '',
  177. showtoolbarConfig: {
  178. undoRedo: true, //撤销重做,注意撤消重做是两个按钮,由这一个配置决定显示还是隐藏
  179. paintFormat: true, //格式刷
  180. currencyFormat: true, //货币格式
  181. percentageFormat: true, //百分比格式
  182. numberDecrease: true, // '减少小数位数'
  183. numberIncrease: true, // '增加小数位数
  184. moreFormats: true, // '更多格式'
  185. font: true, // '字体'
  186. fontSize: true, // '字号大小'
  187. bold: true, // '粗体 (Ctrl+B)'
  188. italic: true, // '斜体 (Ctrl+I)'
  189. strikethrough: true, // '删除线 (Alt+Shift+5)'
  190. underline: true, // '下划线 (Alt+Shift+6)'
  191. textColor: true, // '文本颜色'
  192. fillColor: true, // '单元格颜色'
  193. border: true, // '边框'
  194. mergeCell: true, // '合并单元格'
  195. horizontalAlignMode: true, // '水平对齐方式'
  196. verticalAlignMode: true, // '垂直对齐方式'
  197. textWrapMode: true, // '换行方式'
  198. textRotateMode: false, // '文本旋转方式'
  199. image: false, // '插入图片'
  200. link: false, // '插入链接'
  201. chart: false, // '图表'(图标隐藏,但是如果配置了chart插件,右击仍然可以新建图表)
  202. postil: false, //'批注'
  203. pivotTable: false, //'数据透视表'
  204. function: true, // '公式'
  205. frozenMode: false, // '冻结方式'
  206. sortAndFilter: true, // '排序和筛选'
  207. conditionalFormat: false, // '条件格式'
  208. dataVerification: false, // '数据验证'
  209. splitColumn: true, // '分列'
  210. screenshot: false, // '截图'
  211. findAndReplace: true, // '查找替换'
  212. protection: false, // '工作表保护'
  213. print: false, // '打印'
  214. },
  215. showinfobar: true, // 顶部信息 文件名称 按钮
  216. allowUpdate: false, // 是否允许操作表格后的后台更新 在线文档websocket时为true
  217. allowEdit: flag, // 是否允许前台编辑
  218. title: fileName, // 文件名称
  219. lang: 'zh',
  220. enableAddRow: adminFlag,
  221. showstatisticBar: false, // 底部计数
  222. showstatisticBarConfig: {
  223. count: false, // 计数栏
  224. view: false, // 打印视图
  225. zoom: false, // 缩放
  226. },
  227. functionButton: toolBar,
  228. cellRightClickConfig: {
  229. copy: false, // 复制
  230. copyAs: false, // 复制为
  231. paste: false, // 粘贴
  232. insertRow: adminFlag, // 插入行
  233. insertColumn: adminFlag, // 插入列
  234. deleteRow: adminFlag, // 删除选中行
  235. deleteColumn: adminFlag, // 删除选中列
  236. deleteCell: false, // 删除单元格
  237. hideRow: false, // 隐藏选中行和显示选中行
  238. hideColumn: false, // 隐藏选中列和显示选中列
  239. rowHeight: true, // 行高
  240. columnWidth: true, // 列宽
  241. clear: false, // 清除内容
  242. matrix: false, // 矩阵操作选区
  243. sort: false, // 排序选区
  244. filter: false, // 筛选选区
  245. chart: false, // 图表生成
  246. image: false, // 插入图片
  247. link: false, // 插入链接
  248. data: false, // 数据验证
  249. cellFormat: false, // 设置单元格格式
  250. mComplete: false,
  251. mCetup: false,
  252. mRevoke: false
  253. },
  254. hook: {
  255. cellMousedown: function (a, b, c) {
  256. },
  257. cellUpdateBefore: function (r, c) {
  258. },
  259. cellMousedownBefore: function (a, p, s) {
  260. },
  261. rangePasteBefore: function (range, data) {
  262. //禁止选区粘贴
  263. return false;
  264. },
  265. },
  266. })
  267. } catch (err) {
  268. console.log(err)
  269. }
  270. if (isAdmin == false) {
  271. } else {
  272. }
  273. if (emptyExcel == true) {
  274. } else {
  275. }
  276. if (excelInfo.shareStatus == '1') {
  277. } else {
  278. }
  279. initHandel();
  280. }
  281. // 绑定按钮事件
  282. function initHandel() {
  283. $("#closeExcel").on("click", function () {
  284. window.parent['backToExcelList']('true');
  285. })
  286. $("#fullScreen").on("click", function () {
  287. fullScreen();
  288. })
  289. //退出全屏
  290. $("#exitFullScreen").on("click", function () {
  291. exitFullscreen();
  292. })
  293. //分享
  294. $('#share').off("click").click(function () {
  295. // 当前工作表名
  296. var excelId = $(window.parent.document).find("#excelId").attr("value");
  297. var sheetName = luckysheet.getSheet().name;
  298. var excelData = luckysheet.getSheet(sheetName);
  299. var urlsave = '/market/cOnlineExcel/saveExcel';
  300. var editFrom = $("#editFrom").val();
  301. var editTo = $("#editTo").val();
  302. var editStatus = $("#editStatus").val();
  303. var excelName = luckysheet.toJson().title;
  304. //校验可编辑列
  305. if ($.trim(editFrom) == '' && $.trim(editTo) == '') {
  306. } else if (/^\d*$/.test(editFrom) && /^\d*$/.test(editTo)) {
  307. if (editFrom == 0) {
  308. window.top.$vm.$message({
  309. message: '可编辑列开始不能为0',
  310. type: 'info'
  311. })
  312. return;
  313. }
  314. if (editFrom > editTo) {
  315. window.top.$vm.$message({
  316. message: '可编辑列的起始列不能大于结束列',
  317. type: 'info'
  318. })
  319. return;
  320. }
  321. } else if (/^[a-zA-Z]+$/.test(editFrom) && /^[a-zA-Z]+$/.test(editTo)) {
  322. } else {
  323. window.top.$vm.$message({
  324. message: '可编辑列必须全部为字母或数字',
  325. type: 'info'
  326. })
  327. return;
  328. }
  329. util.ajaxJson("正在加载中", ctx + '/market/cOnlineExcel/checkExcelEmpty', {
  330. data: excelData,
  331. }, function (data) {
  332. if (data.result == 1) {
  333. window.top.$vm.$message({
  334. message: data.desc,
  335. type: 'error'
  336. });
  337. } else {
  338. window.parent['shareExcel'](excelData, editFrom, editTo, editStatus, excelName,excelId);
  339. }
  340. });
  341. });
  342. // 保存
  343. $('#saves').off("click").click(function () {
  344. // 当前工作表名
  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. } else if (/^\d*$/.test(editFrom) && /^\d*$/.test(editTo)) {
  355. if (editFrom == 0) {
  356. window.top.$vm.$message({
  357. message: '可编辑列开始不能为0',
  358. type: 'info'
  359. })
  360. return;
  361. }
  362. if (editFrom > editTo) {
  363. window.top.$vm.$message({
  364. message: '可编辑列的起始列不能大于结束列',
  365. type: 'info'
  366. })
  367. return;
  368. }
  369. } else if (/^[a-zA-Z]+$/.test(editFrom) && /^[a-zA-Z]+$/.test(editTo)) {
  370. } else {
  371. window.top.$vm.$message({
  372. message: '可编辑列必须全部为字母或数字',
  373. type: 'info'
  374. });
  375. return;
  376. }
  377. util.ajaxJson("正在加载中", ctx + '/market/cOnlineExcel/checkExcelEmpty', {
  378. data: excelData,
  379. }, function (data) {
  380. if (data.result == 1) {
  381. window.top.$vm.$message({
  382. message: data.desc,
  383. type: 'error'
  384. });
  385. } else {
  386. util.ajaxJson("正在加载中", ctx + urlsave, {
  387. data: excelData,
  388. id: excelId,
  389. editConStart: editFrom,
  390. editConEnd: editTo,
  391. excelName: excelName,
  392. editStatus: editStatus
  393. }, function (data) {
  394. if (data.result == 1) {
  395. window.top.$vm.$message({
  396. message: data.desc,
  397. type: 'error'
  398. })
  399. } else {
  400. window.top.$vm.$message({
  401. message: '保存成功',
  402. type: 'info'
  403. });
  404. console.log(data);
  405. getData()
  406. }
  407. });
  408. }
  409. });
  410. })
  411. // 导出
  412. $('#exports').click(function () {
  413. var excelName = luckysheet.toJson().title;
  414. exportExcel(luckysheet.getluckysheetfile(), excelName)
  415. })
  416. // 导入
  417. $("#imports").change(function (evt) {
  418. var files = evt.target.files;
  419. if (files == null || files.length == 0) {
  420. window.top.$vm.$message({
  421. message: '没有文件导入',
  422. type: 'info'
  423. })
  424. return;
  425. }
  426. var name = files[0].name;
  427. var suffixArr = name.split("."),
  428. suffix = suffixArr[suffixArr.length - 1];
  429. if (suffix != "xlsx") {
  430. window.top.$vm.$message({
  431. message: '目前只支持xlsx文件的导入',
  432. type: 'info'
  433. })
  434. return;
  435. }
  436. // 解析文件
  437. LuckyExcel.transformExcelToLucky(
  438. files[0],
  439. function (exportJson, luckysheetfile) {
  440. console.log(exportJson);
  441. if (exportJson.sheets == null || exportJson.sheets.length == 0) {
  442. window.top.$vm.$message({
  443. message: '无法读取excel文件的内容,当前不支持xls文件',
  444. type: 'info'
  445. })
  446. return;
  447. }
  448. // 销毁原来的excel
  449. window.luckysheet.destroy();
  450. // 重新加载
  451. var a = exportJson.sheets[0];
  452. a.name = '';
  453. initExcel([a], name.replace('.xlsx', ''));
  454. // 绑定按钮事件
  455. initHandel()
  456. }
  457. );
  458. });
  459. }
  460. getData()
  461. })
  462. </script>
  463. </body>
  464. </html>