kccExcel.html 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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="/marketfront/static/js/luckysheet_old/plugins/js/plugin.js?v=1.0.0"></script>-->
  34. <!-- <script src="/marketfront/static/js/luckysheet_old/luckysheet.umd.js?v=1.0.0"></script>-->
  35. <script src="../js/luckysheet_old/plugins/js/plugin.js?v=1.0.0"></script>
  36. <script src="../js/luckysheet_old/luckysheet.umd.js?v=1.0.0"></script>
  37. <script src="/static/js/api.config.js"></script>
  38. <script src="/static/js/util.js?v=1.0.0"></script>
  39. <script src="/static/js/url.js?v=1.0.0"></script>
  40. <script src="/static/js/exportExcel.js"></script>
  41. <script src="/static/js/fullScreen.js"></script>
  42. </head>
  43. <style>
  44. * {
  45. padding: 0;
  46. margin: 0;
  47. }
  48. html,
  49. body {
  50. height: 100%;
  51. }
  52. #monthSelect {
  53. padding: 10px 0px;
  54. }
  55. </style>
  56. <body style="background: #fff;">
  57. <div class="layui-inline" id="monthSelect" style="width: 100%">
  58. <div class="layui-input-inline">
  59. <form class="layui-form mc-work-form">
  60. <label> 地市可编辑列:从 </label><input type="text" id="editFrom" style="width: 100px"
  61. onkeyup="this.value=this.value.replace(/[^a-zA-Z]/g,'')"></input> 到 <input
  62. type="text" id="editTo" style="width: 100px"
  63. onkeyup="this.value=this.value.replace(/[^a-zA-Z]/g,'')"></input>
  64. </form>
  65. </div>
  66. <label style="color: red;float: right;padding-right: 10px">提示:请在第三列填写地市</label>
  67. </div>
  68. <div style="height:90%;width: 100%;">
  69. <div id="luckysheet" style="width:100%;height:100%">
  70. </div>
  71. </div>
  72. <script>
  73. //监听window是否全屏,并进行相应的操作,支持esc键退出
  74. window.onresize = function () {
  75. var isFull = !!(document.webkitIsFullScreen || document.mozFullScreen ||
  76. document.msFullscreenElement || document.fullscreenElement
  77. );//!document.webkitIsFullScreen都为true。因此用!!
  78. if (isFull == false) {
  79. $("#exitFullScreen").css("display", "none");
  80. $("#fullScreen").css("display", "");
  81. } else {
  82. $("#exitFullScreen").css("display", "");
  83. $("#fullScreen").css("display", "none");
  84. }
  85. }
  86. </script>
  87. <script>
  88. var lockFlag = 'see';
  89. util.ajaxJson("", ctx + "/market/cadvLedger/getRoleByCode", {}, function (res) {
  90. console.log("html" + res.result);
  91. if (res.result == 1) {
  92. lockFlag = 'add';//省级
  93. } else {
  94. lockFlag = 'updata';//管理员
  95. }
  96. });
  97. var id = '' // 模板id 查看/修改load时候用
  98. var powerFlag = '0'; // 权限控制 0 开启 1关闭
  99. var excelId = '';
  100. var flag = false; // 控制excel是否可以编辑
  101. var adminFlag = false;
  102. var userId; // 用户ID
  103. var excelInfo = {};
  104. var isAdmin = '';
  105. var excelLevel = '';
  106. var toolBar = '';
  107. var type = '';
  108. $(function () {
  109. userId = JSON.parse(window.top.sessionStorage.userInfo).loginNo
  110. })
  111. layui.use(['laydate', 'form'], function () {
  112. var laydate = layui.laydate;
  113. var form = layui.form;
  114. form.on('select(powerFlag)', function (data) {
  115. powerFlag = data.value
  116. })
  117. // 获取数据
  118. function getData() {
  119. // 先销毁excel重新加载
  120. if (window.luckysheet) {
  121. window.luckysheet.destroy();
  122. }
  123. //拿参数的
  124. var r = window.top.location.href.split('?')[1];
  125. var excelId = r.split('&')[1].split('=')[1];
  126. type = r.split('&')[0].split('=')[1];
  127. toolBar = '';
  128. var url = '/market/cKeyChannelCoopExcel/getExcelInfo';
  129. util.ajaxJson("数据加载中", ctx + url, {
  130. "id": excelId ? excelId : '',
  131. }, function (res) {
  132. if (res.result == 0) {
  133. // 查看和修改时 下拉框赋值
  134. excelInfo = res.body.excelInfo;
  135. excelLevel = res.body.excelLevel;
  136. isAdmin = res.body.isExcelAdmin;
  137. $("#editFrom").val(excelInfo.editConStart);
  138. $("#editTo").val(excelInfo.editConEnd);
  139. console.log(type);
  140. if (type == '2') {
  141. if (isAdmin) {
  142. toolBar += '<input id="imports" type="file" class="btn btn-primary" style="padding:3px 6px;font-size: 12px;margin-right: 10px;"></input>';
  143. }
  144. toolBar += '<button id="saves" class="btn btn-primary btn-danger" style=" padding:3px 6px; font-size: 12px; margin-right: 10px;">保存</button>';
  145. }
  146. if (isAdmin) {
  147. toolBar += '<button id="exports" class="btn btn-primary" style="padding:3px 6px;font-size: 12px;margin-right: 10px;">导出</button>';
  148. }
  149. toolBar += '<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>';
  150. var eJson = res.body.excelJson;
  151. var cellData = luckysheet.transToCellData(eJson[0].data);
  152. eJson[0].celldata = cellData;
  153. initExcel(res.body.excelJson);
  154. }
  155. });
  156. initExcel()
  157. }
  158. // 表格初始化
  159. function initExcel(data) {
  160. if (type == '1') {
  161. flag = false
  162. } else {
  163. flag = true
  164. }
  165. if (isAdmin) {
  166. adminFlag = true;
  167. }
  168. try {
  169. luckysheet.create({
  170. container: 'luckysheet',
  171. data: data,
  172. showsheetbar: false, // 底部sheet显示/隐藏
  173. showsheetbarConfig: {
  174. add: false, //新增sheet
  175. menu: false, //sheet管理菜单
  176. sheet: false //sheet页显示
  177. },
  178. showstatisticBar: false, // 底部计数
  179. showtoolbar: false,
  180. showinfobar: true, // 顶部信息 文件名称 按钮
  181. allowUpdate: false, // 是否允许操作表格后的后台更新 在线文档websocket时为true
  182. allowEdit: flag, // 是否允许前台编辑
  183. title: excelInfo.name, // 文件名称
  184. lang: 'zh',
  185. enableAddRow: adminFlag,
  186. showstatisticBar: false, // 底部计数
  187. showstatisticBarConfig: {
  188. count: false, // 计数栏
  189. view: false, // 打印视图
  190. zoom: false, // 缩放
  191. },
  192. functionButton: toolBar,
  193. cellRightClickConfig: {
  194. copy: false, // 复制
  195. copyAs: false, // 复制为
  196. paste: false, // 粘贴
  197. insertRow: adminFlag, // 插入行
  198. insertColumn: adminFlag, // 插入列
  199. deleteRow: adminFlag, // 删除选中行
  200. deleteColumn: adminFlag, // 删除选中列
  201. deleteCell: false, // 删除单元格
  202. hideRow: false, // 隐藏选中行和显示选中行
  203. hideColumn: false, // 隐藏选中列和显示选中列
  204. rowHeight: true, // 行高
  205. columnWidth: true, // 列宽
  206. clear: false, // 清除内容
  207. matrix: false, // 矩阵操作选区
  208. sort: false, // 排序选区
  209. filter: false, // 筛选选区
  210. chart: false, // 图表生成
  211. image: false, // 插入图片
  212. link: false, // 插入链接
  213. data: false, // 数据验证
  214. cellFormat: false, // 设置单元格格式
  215. mComplete: false,
  216. mCetup: false,
  217. mRevoke: false
  218. },
  219. hook: {
  220. cellMousedown: function (a, b, c) {
  221. // if (b.c == luckysheet.getSheet().data[b.r].length - 1) {
  222. // return false
  223. // }
  224. },//绑定鼠标事件
  225. cellUpdateBefore: function (r, c) {
  226. console.log('执行事件');
  227. // c坐标 r行坐标
  228. // if(lockFlag == 'updata'){
  229. // return true
  230. // }
  231. // if (c == luckysheet.getSheet().data[r].length - 1) {
  232. // if(luckysheet.getSheet().data[r][c] != null ){
  233. // return false
  234. // }
  235. // }
  236. // var editConStart = excelInfo.editConStart;
  237. // var editConEnd = excelInfo.editConEnd;
  238. // //console.log(r + '---' + c)
  239. // if ($.trim(editConStart) != '' && $.trim(editConEnd) != '' && isAdmin == false) {
  240. // editConStart = editConStart - 1;
  241. // editConEnd = editConEnd - 1;
  242. // // console.log(editConStart + '---' + editConEnd);
  243. // // console.log(c < editConStart);
  244. // // console.log(c > editConEnd);
  245. // // console.log(c == 3);
  246. // if (c < editConStart || c > editConEnd || c == 2) {
  247. // window.top.$vm.$message({
  248. // message: '您无权修改当前列',
  249. // type: 'info'
  250. // });
  251. // return false;
  252. // }
  253. // }
  254. if (r == 0 && isAdmin == false) {
  255. window.top.$vm.$message({
  256. message: '您无权修改当前行',
  257. type: 'info'
  258. });
  259. return false;
  260. }
  261. },
  262. cellMousedownBefore: function (a, p, s) {
  263. if (flag == false) {
  264. window.top.$vm.$message({
  265. message: '查看模式无法编辑',
  266. type: 'info'
  267. });
  268. return false;
  269. } else {
  270. //r行,c列
  271. var r = p.r;
  272. var c = p.c;
  273. // var editConStart = excelInfo.editConStart;
  274. // var editConEnd = excelInfo.editConEnd;
  275. // //console.log(r + '---' + c)
  276. // if ($.trim(editConStart) != '' && $.trim(editConEnd) != '' && isAdmin == false) {
  277. // editConStart = editConStart - 1;
  278. // editConEnd = editConEnd - 1;
  279. // // console.log(editConStart + '---' + editConEnd);
  280. // // console.log(c < editConStart);
  281. // // console.log(c > editConEnd);
  282. // // console.log(c == 3);
  283. // if (c < editConStart || c > editConEnd || c == 2) {
  284. // window.top.$vm.$message({
  285. // message: '您无权修改当前列',
  286. // type: 'info'
  287. // });
  288. // return false;
  289. // }
  290. // }
  291. if (r == 0 && isAdmin == false) {
  292. window.top.$vm.$message({
  293. message: '您无权修改当前行',
  294. type: 'info'
  295. });
  296. return false;
  297. }
  298. }
  299. },
  300. rangePasteBefore: function (range, data) {
  301. //禁止选区粘贴
  302. return false;
  303. },
  304. },
  305. })
  306. } catch (err) {
  307. console.log(err)
  308. }
  309. if (isAdmin == false) {
  310. $('#monthSelect').hide()
  311. } else {
  312. $('#monthSelect').show()
  313. }
  314. initHandel()
  315. }
  316. // 绑定按钮事件
  317. function initHandel() {
  318. $("#fullScreen").on("click", function () {
  319. fullScreen();
  320. })
  321. //退出全屏
  322. $("#exitFullScreen").on("click", function () {
  323. exitFullscreen();
  324. })
  325. // 保存
  326. $('#saves').off("click").click(function () {
  327. // 当前工作表名
  328. var r = window.top.location.href.split('?')[1];
  329. var excelId = r.split('&')[1].split('=')[1];
  330. var sheetName = luckysheet.getSheet().name;
  331. var data = luckysheet.getSheet(sheetName);
  332. var urlsave = '/market/cKeyChannelCoopExcel/saveExcel';
  333. var editFrom = $("#editFrom").val();
  334. var editTo = $("#editTo").val();
  335. // if (editTo < editFrom) {
  336. // window.top.$vm.$message({
  337. // message: '可编辑列的起始列不能大于结束列',
  338. // type: 'error'
  339. // });
  340. // return;
  341. // }
  342. if (isAdmin && ($.trim(editFrom) == '' || $.trim(editTo) == '')) {
  343. window.top.$vm.$message({
  344. message: '可编辑列不可为空',
  345. type: 'error'
  346. });
  347. return;
  348. }
  349. util.ajaxJson("正在加载中", ctx + urlsave, {
  350. data: data,
  351. id: excelId,
  352. editConStart: editFrom,
  353. editConEnd: editTo
  354. }, function (data) {
  355. if (data.result == 1) {
  356. window.top.$vm.$message({
  357. message: data.desc,
  358. type: 'error'
  359. })
  360. } else {
  361. console.log(data);
  362. getData()
  363. }
  364. });
  365. })
  366. // 导出
  367. $('#exports').click(function () {
  368. exportExcel(luckysheet.getluckysheetfile(), excelInfo.name)
  369. })
  370. // 导入
  371. $("#imports").change(function (evt) {
  372. var files = evt.target.files;
  373. if (files == null || files.length == 0) {
  374. window.top.$vm.$message({
  375. message: '没有文件导入',
  376. type: 'info'
  377. })
  378. return;
  379. }
  380. var name = files[0].name;
  381. var suffixArr = name.split("."),
  382. suffix = suffixArr[suffixArr.length - 1];
  383. if (suffix != "xlsx") {
  384. window.top.$vm.$message({
  385. message: '目前只支持xlsx文件的导入',
  386. type: 'info'
  387. })
  388. return;
  389. }
  390. // 解析文件
  391. LuckyExcel.transformExcelToLucky(
  392. files[0],
  393. function (exportJson, luckysheetfile) {
  394. console.log(exportJson);
  395. if (exportJson.sheets == null || exportJson.sheets.length == 0) {
  396. window.top.$vm.$message({
  397. message: '无法读取excel文件的内容,当前不支持xls文件',
  398. type: 'info'
  399. })
  400. return;
  401. }
  402. // 销毁原来的excel
  403. window.luckysheet.destroy();
  404. // 重新加载
  405. var a = exportJson.sheets[0];
  406. a.name = '';
  407. initExcel([a])
  408. // 绑定按钮事件
  409. initHandel()
  410. }
  411. );
  412. });
  413. }
  414. getData()
  415. })
  416. </script>
  417. </body>
  418. </html>