123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711 |
- <!DOCTYPE html>
- <html>
- <head lang='zh'>
- <meta charset='utf-8'>
- <meta http-equiv="X-UA-Compatible" content="IE=edge" />
- <meta name="renderer" content="webkit" />
- <meta name="viewport" content="width=device-width, initial-scale=1,user-scalable=0" />
- <title>Luckysheet</title>
- <link rel='stylesheet' href='/static/js/luckysheet/plugins/css/pluginsCss.css' />
- <link rel='stylesheet' href='/static/js/luckysheet/plugins/plugins.css' />
- <link rel='stylesheet' href='/static/js/luckysheet/css/luckysheet.css' />
- <link rel='stylesheet' href='/static/js/luckysheet/assets/iconfont/iconfont.css' />
- <link charset="utf-8" rel="stylesheet" href="/static/css/layui.css">
- <script>
- var _PageHeight = document.documentElement.clientHeight,
- _PageWidth = document.documentElement.clientWidth;
- var _LoadingTop = _PageHeight > 61 ? (_PageHeight - 61) / 2 : 0,
- _LoadingLeft = _PageWidth > 215 ? (_PageWidth - 215) / 2 : 0;
- 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>';
- document.write(_LoadingHtml);
- document.onreadystatechange = completeLoading;
- function completeLoading() {
- if (document.readyState == "complete") {
- var loadingMask = document.getElementById('loadingDiv');
- loadingMask.parentNode.removeChild(loadingMask);
- }
- }
- </script>
- <script src="/static/js/layui.js"></script>
- <script src="/static/js/exceljs.js"></script>
- <script src="/static/js/fileSave.js"></script>
- <script src="/static/js/luckysheet/luckSheetExcel.js"></script>
- <script src="/static/js/luckysheet/plugins/js/plugin.js"></script>
- <script src="/static/js/luckysheet/luckysheet.umd.js"></script>
- <script src="/static/js/api.config.js"></script>
- <script src="/static/js/util.js"></script>
- <script src="/static/js/url.js"></script>
- <script src="/static/js/exportExcel.js"></script>
- <script src="/static/js/fullScreen.js"></script>
- </head>
- <style>
- * {
- padding: 0;
- margin: 0;
- }
- html,
- body {
- height: 100%;
- }
- #monthSelect {
- padding: 10px 0px;
- }
- </style>
- <body style="background: #fff;">
- <div class="layui-inline" id="monthSelect" style="width: 100%">
- <div class="layui-input-inline">
- <form>
- <label>控制权限</label>
- <select name="city" id="editStatus" style="width: 70px">
- <option value="0">开启</option>
- <option value="1">关闭</option>
- </select>
- <label> 可编辑列:从 </label><input type="text" id="editFrom" style="width: 50px"
- onkeyup="this.value=this.value.replace('-','')"></input> 到 <input type="text" id="editTo"
- style="width: 50px" onkeyup="this.value=this.value.replace('-','')"></input>
- </form>
- </div>
- <div style="float: right;padding-right: 10px" id="shareBtn">
- <button id="share" class="btn btn-primary"
- style="padding:3px 6px;font-size: 12px;margin-right: 10px;width: 70px">分享
- </button>
- <!-- <button id="saves" lass="btn btn-primary"
- style=" padding:3px 6px; font-size: 12px; margin-right: 10px;">保存</button> -->
- </div>
- <div style="float: right;padding-right: 10px" id="newShareBtn">
- <button id="newShare" class="btn btn-primary"
- style="padding:3px 6px;font-size: 12px;margin-right: 10px;width: 70px">分享
- </button>
- </div>
- <div style="float: right;padding-right: 10px">
- <!-- <input id="importspro" type="file" class="btn btn-primary"
- style="padding:3px 6px;font-size: 12px;margin-right: 10px;"></input> -->
- <button id="savesid" class="btn btn-primary"
- style="padding:3px 6px;font-size: 12px;margin-right: 10px;width: 70px">保存</button>
- <button id="closeExcel" class="btn btn-primary"
- style="padding:3px 6px;font-size: 12px;margin-right: 10px;width: 70px">返回</button><button
- id="fullScreen" class="btn btn-primary"
- style="padding:3px 6px;font-size: 12px;margin-right: 10px;width: 70px">全屏显示</button><button
- id="exitFullScreen" class="btn btn-primary"
- style="padding:3px 6px;font-size: 12px;margin-right: 10px;width: 70px;display:none">退出全屏</button>
- <button id="exports" class="btn btn-primary"
- style="padding:3px 6px;font-size: 12px;margin-right: 10px;width: 70px">导出</button>
- </div>
- </div>
- <div style="height:90%;width: 100%;">
- <div id="luckysheet" style="width:100%;height:100%">
- </div>
- </div>
- <script>
- //监听window是否全屏,并进行相应的操作,支持esc键退出
- window.onresize = function () {
- var isFull = !!(document.webkitIsFullScreen || document.mozFullScreen ||
- document.msFullscreenElement || document.fullscreenElement
- );//!document.webkitIsFullScreen都为true。因此用!!
- if (isFull == false) {
- $("#exitFullScreen").css("display", "none");
- $("#fullScreen").css("display", "");
- } else {
- $("#exitFullScreen").css("display", "");
- $("#fullScreen").css("display", "none");
- }
- }
- </script>
- <script>
- var lockFlag = 'see';
- util.ajaxJson("", ctx + "/market/cadvLedger/getRoleByCode", {}, function (res) {
- console.log("html" + res.result);
- if (res.result == 1) {
- lockFlag = 'add';//省级
- } else {
- lockFlag = 'updata';//管理员
- }
- });
- var id = '' // 模板id 查看/修改load时候用
- var powerFlag = '0'; // 权限控制 0 开启 1关闭
- var excelId = '';
- var flag = false; // 控制excel是否可以编辑
- var adminFlag = false;
- var userId; // 用户ID
- var excelInfo = {};
- var isAdmin = '';
- var excelLevel = '';
- var toolBar = '';
- var type = '';
- var emptyExcel = false;
- var fullScreenState = false;
- $(function () {
- userId = JSON.parse(window.top.sessionStorage.userInfo).loginNo
- })
- layui.use(['laydate', 'form'], function () {
- var laydate = layui.laydate;
- var form = layui.form;
- form.on('select(powerFlag)', function (data) {
- powerFlag = data.value
- })
- // 获取数据
- function getData() {
- // 先销毁excel重新加载
- if (window.luckysheet) {
- window.luckysheet.destroy();
- }
- //拿参数的
- var excelId = $(window.parent.document).find("#excelId").attr("value");
- console.log(excelId);
- type = '2';
- toolBar = '';
- var url = '/market/cOnlineExcel/getExcelInfo';
- util.ajaxJson("数据加载中", ctx + url, {
- "id": excelId ? excelId : '',
- }, function (res) {
- if (res.result == 0) {
- // 查看和修改时 下拉框赋值
- excelInfo = res.body.excelInfo;
- excelLevel = res.body.excelLevel;
- isAdmin = res.body.isExcelAdmin;
- emptyExcel = res.body.emptyExcel;
- $("#editFrom").val(excelInfo.editConStart);
- $("#editTo").val(excelInfo.editConEnd);
- $("#editStatus").val(excelInfo.editStatus);
- console.log(type);
- if (type == '2') {
- if (!isAdmin) {
- $("#importspro").css("display", "none");
- // toolBar += '<input id="importspro" type="file" class="btn btn-primary" style="padding:3px 6px;font-size: 12px;margin-right: 10px;"></input>';
- }
- }
- if (!isAdmin) {
- $("#exports").css("display", "none");
- // toolBar += '<button id="exports" class="btn btn-primary btn-danger" style="padding:3px 6px;font-size: 12px;margin-right: 10px;">导出</button>';
- }
- // toolBar += '<button id="savesid" class="btn btn-primary btn-danger" style=" padding:3px 6px; font-size: 12px; margin-right: 10px;">保存</button>';
- // 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>';
- var eJson = res.body.excelJson;
- // var cellData = luckysheet.transToCellData(eJson[0].data);
- // eJson[0].celldata = cellData;
- initExcel(res.body.excelJson, '', excelId);
- }
- });
- //initExcel()
- }
- // 表格初始化
- function initExcel(data, name, ids) {
- if (type == '1') {
- flag = false
- } else {
- flag = true
- }
- if (isAdmin) {
- adminFlag = true;
- }
- var fileName = excelInfo.fileName;
- if ($.trim(name) != '') {
- fileName = name;
- }
- try {
- luckysheet.create({
- container: 'luckysheet',
- data: data,
- showsheetbar: false, // 底部sheet显示/隐藏
- loadUrl:
- window.location.protocol +
- "//10.149.85.91:7777" +
- "/sheet/worksheet/" +
- ids + '/' + JSON.parse(window.sessionStorage.userInfo).loginNo,
- loadSheetUrl:
- window.location.protocol +
- "//10.149.85.91:7777" +
- "/sheet/loadsheet/" +
- ids,
- updateUrl:
- "ws://" +
- "//10.149.85.91:7777" +
- "/ws/" +
- JSON.parse(window.sessionStorage.userInfo).loginName +
- "/" +
- ids,
- showsheetbarConfig: {
- add: false, //新增sheet
- menu: false, //sheet管理菜单
- sheet: false //sheet页显示
- },
- showstatisticBar: false, // 底部计数
- showtoolbar: true,
- myFolderUrl: '',
- showtoolbarConfig: {
- undoRedo: true, //撤销重做,注意撤消重做是两个按钮,由这一个配置决定显示还是隐藏
- paintFormat: true, //格式刷
- currencyFormat: true, //货币格式
- percentageFormat: true, //百分比格式
- numberDecrease: true, // '减少小数位数'
- numberIncrease: true, // '增加小数位数
- moreFormats: true, // '更多格式'
- font: true, // '字体'
- fontSize: true, // '字号大小'
- bold: true, // '粗体 (Ctrl+B)'
- italic: true, // '斜体 (Ctrl+I)'
- strikethrough: true, // '删除线 (Alt+Shift+5)'
- underline: true, // '下划线 (Alt+Shift+6)'
- textColor: true, // '文本颜色'
- fillColor: true, // '单元格颜色'
- border: true, // '边框'
- mergeCell: true, // '合并单元格'
- horizontalAlignMode: true, // '水平对齐方式'
- verticalAlignMode: true, // '垂直对齐方式'
- textWrapMode: true, // '换行方式'
- textRotateMode: false, // '文本旋转方式'
- image: false, // '插入图片'
- link: false, // '插入链接'
- chart: false, // '图表'(图标隐藏,但是如果配置了chart插件,右击仍然可以新建图表)
- postil: false, //'批注'
- pivotTable: false, //'数据透视表'
- function: true, // '公式'
- frozenMode: true, // '冻结方式'
- sortAndFilter: true, // '排序和筛选'
- conditionalFormat: false, // '条件格式'
- dataVerification: false, // '数据验证'
- splitColumn: true, // '分列'
- screenshot: false, // '截图'
- findAndReplace: true, // '查找替换'
- protection: false, // '工作表保护'
- print: false, // '打印'
- },
- showinfobar: true, // 顶部信息 文件名称 按钮
- allowUpdate: true, // 是否允许操作表格后的后台更新 在线文档websocket时为true
- allowEdit: flag, // 是否允许前台编辑
- title: fileName, // 文件名称
- lang: 'zh',
- enableAddRow: true,
- showstatisticBar: false, // 底部计数
- showstatisticBarConfig: {
- count: false, // 计数栏
- view: false, // 打印视图
- zoom: false, // 缩放
- },
- functionButton: toolBar,
- cellRightClickConfig: {
- copy: false, // 复制
- copyAs: false, // 复制为
- paste: false, // 粘贴
- insertRow: true, // 插入行
- insertColumn: true, // 插入列
- deleteRow: true, // 删除选中行
- deleteColumn: true, // 删除选中列
- deleteCell: false, // 删除单元格
- hideRow: false, // 隐藏选中行和显示选中行
- hideColumn: false, // 隐藏选中列和显示选中列
- rowHeight: true, // 行高
- columnWidth: true, // 列宽
- clear: false, // 清除内容
- matrix: false, // 矩阵操作选区
- sort: false, // 排序选区
- filter: false, // 筛选选区
- chart: false, // 图表生成
- image: false, // 插入图片
- link: false, // 插入链接
- data: false, // 数据验证
- cellFormat: false, // 设置单元格格式
- mComplete: false,
- mCetup: false,
- mRevoke: false
- },
- hook: {
- cellMousedown: function (a, b, c) {
- },
- cellUpdateBefore: function (r, c, value, isRefresh) {
- // 当用户修改单元格里的值,去掉单引号时
- // eslint-disable-next-line no-undef
- const data = luckysheet.toJson().data[0].data
- if (data[r][c] && data[r][c].qp && data[r][c].qp == 1 && value.indexOf("'") < 0) {
- // eslint-disable-next-line no-undef
- luckysheet.setCellFormat(r, c, 'qp', 0)
- }
- },
- updated: function (operate) {
- // 当用户清空单元格里的数据时
- if (operate.type === 'datachange') {
- const row1 = operate.range[0].row[0]
- const row2 = operate.range[0].row[1]
- const col1 = operate.range[0].column[0]
- const col2 = operate.range[0].column[1]
- for (let r = row1; r <= row2; r++) {
- for (let c = col1; c <= col2; c++) {
- const newValue = operate.curdata[r][c]
- if (newValue && !newValue.v && !newValue.m && newValue.qp && newValue.qp == 1) {
- // eslint-disable-next-line no-undef
- luckysheet.setCellFormat(r, c, 'qp', 0)
- }
- }
- }
- }
- },
- cellMousedownBefore: function (a, p, s) {
- },
- rangePasteBefore: function (range, data) {
- },
- },
- })
- } catch (err) {
- console.log(err)
- }
- if (isAdmin == false) {
- $("#editStatus").attr('disabled', true);
- $("#editFrom").attr('disabled', true);
- $("#editTo").attr('disabled', true);
- $("#shareBtn").hide();
- $("#newShareBtn").hide();
- } else {
- $("#editStatus").attr('disabled', false);
- $("#editFrom").attr('disabled', false);
- $("#editTo").attr('disabled', false);
- $("#shareBtn").show();
- $("#newShareBtn").show();
- }
- if (emptyExcel == true) {
- $("#shareBtn").show();
- $("#savesid").hide();
- $("#newShareBtn").hide();
- } else {
- $("#shareBtn").hide();
- $("#savesid").show();
- if (isAdmin) {
- $("#newShareBtn").show();
- }
- //console.log("执行自动保存定时器")
- // var t1 = window.setInterval(function autoSave() {
- // console.log("执行自动保存")
- // var excelId = $(window.parent.document).find("#excelId").attr("value");
- // var sheetName = luckysheet.getSheet().name;
- // var excelData = luckysheet.getSheet(sheetName);
- // var urlsave = '/market/cOnlineExcel/saveExcel';
- // var editFrom = $("#editFrom").val();
- // var editTo = $("#editTo").val();
- // var editStatus = $("#editStatus").val();
- // var excelName = luckysheet.toJson().title;
- // if ($.trim(editFrom) == '' && $.trim(editTo) == '') {
- //
- // } else if (/^\d*$/.test(editFrom) && /^\d*$/.test(editTo)) {
- // if (editFrom == 0) {
- // window.top.$vm.$message({
- // message: '自动保存出错:可编辑列开始不能为0',
- // type: 'info'
- // })
- // return;
- // }
- // if (editFrom > editTo) {
- // window.top.$vm.$message({
- // message: '自动保存出错:可编辑列的起始列不能大于结束列',
- // type: 'info'
- // })
- // return;
- // }
- // } else if (/^[a-zA-Z]+$/.test(editFrom) && /^[a-zA-Z]+$/.test(editTo)) {
- //
- // } else {
- // window.top.$vm.$message({
- // message: '自动保存出错:可编辑列必须全部为字母或数字',
- // type: 'info'
- // });
- // return;
- // }
- // util.ajaxJson(null, ctx + '/market/cOnlineExcel/checkExcelEmpty', {
- // data: excelData,
- // }, function (data) {
- // if (data.result == 1) {
- // window.top.$vm.$message({
- // message: data.desc,
- // type: 'error'
- // });
- // } else {
- // util.ajaxJson(null, ctx + urlsave, {
- // data: excelData,
- // id: excelId,
- // editConStart: editFrom,
- // editConEnd: editTo,
- // excelName: excelName,
- // editStatus: editStatus
- // }, function (data) {
- // if (data.result == 1) {
- // window.top.$vm.$message({
- // message: data.desc,
- // type: 'error'
- // })
- // } else {
- // // window.top.$vm.$message({
- // // message: '自动保存成功',
- // // type: 'info'
- // // });
- // //console.log(data);
- // //getData()
- // }
- // });
- // }
- // });
- // }, 15000)
- }
- if (excelInfo.shareStatus == '1') {
- $("#editTo").attr('disabled', true);
- $("#editFrom").attr('disabled', true);
- } else {
- $("#editTo").attr('disabled', false);
- $("#editFrom").attr('disabled', false);
- }
- initHandel();
- }
- function isNumber(val) {
- var regPos = /^\d+(\.\d+)?$/; //非负浮点数
- var regNeg = /^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$/;
- //负浮点数
- if (regPos.test(val) && regNeg.test(val)) {
- return true;
- } else {
- return false;
- }
- }
- function processShare(type) {
- // 当前工作表名
- var excelId = $(window.parent.document).find("#excelId").attr("value");
- var sheetName = luckysheet.getSheet().name;
- var excelData = luckysheet.getSheet(sheetName);
- var urlsave = '/market/cOnlineExcel/saveExcel';
- var editFrom = $("#editFrom").val();
- var editTo = $("#editTo").val();
- var editStatus = $("#editStatus").val();
- var excelName = luckysheet.toJson().title;
- //校验可编辑列
- if ($.trim(editFrom) == '' && $.trim(editTo) == '') {
- } else if (/^\d*$/.test(editFrom) && /^\d*$/.test(editTo)) {
- if (editFrom == 0) {
- window.top.$vm.$message({
- message: '可编辑列开始不能为0',
- type: 'info'
- })
- return;
- }
- if (editFrom > editTo) {
- window.top.$vm.$message({
- message: '可编辑列的起始列不能大于结束列',
- type: 'info'
- })
- return;
- }
- } else if (/^[a-zA-Z]+$/.test(editFrom) && /^[a-zA-Z]+$/.test(editTo)) {
- } else {
- window.top.$vm.$message({
- message: '可编辑列必须全部为字母或数字',
- type: 'info'
- })
- return;
- }
- util.ajaxJson("正在加载中", ctx + '/market/cOnlineExcel/checkExcelEmpty', {
- data: excelData,
- }, function (data) {
- if (data.result == 1) {
- window.top.$vm.$message({
- message: data.desc,
- type: 'error'
- });
- } else {
- //excelJson, editFrom, editTo, editStatus, excelName, excelId, type
- window.parent['shareExcel'](excelData, editFrom, editTo, editStatus, excelName, excelId, type);
- }
- });
- }
- // 绑定按钮事件
- function initHandel() {
- $("#closeExcel").on("click", function () {
- window.parent['backToExcelList']('true');
- })
- $("#fullScreen").on("click", function () {
- if (fullScreenState) {
- fullScreenState = false;
- $("#fullScreen").html('全屏显示');
- } else {
- fullScreenState = true;
- $("#fullScreen").html('退出全屏');
- }
- window.parent['fullScreen']('true');
- //fullScreen();
- })
- //退出全屏
- $("#exitFullScreen").on("click", function () {
- exitFullscreen();
- })
- //分享
- $('#share').off("click").click(function () {
- console.log(123);
- if (fullScreenState) {
- fullScreenState = false;
- $("#fullScreen").html('全屏显示');
- window.parent['fullScreen']('true');
- }
- processShare(1);
- });
- //新增分享
- $('#newShare').off("click").click(function () {
- console.log(123);
- if (fullScreenState) {
- fullScreenState = false;
- $("#fullScreen").html('全屏显示');
- window.parent['fullScreen']('true');
- }
- processShare(2);
- });
- // 保存
- $('#savesid').off("click").click(function () {
- console.log(123);
- // 当前工作表名
- var excelId = $(window.parent.document).find("#excelId").attr("value");
- var sheetName = luckysheet.getSheet().name;
- var excelData = luckysheet.getSheet(sheetName);
- var urlsave = '/market/cOnlineExcel/saveExcel';
- var editFrom = $("#editFrom").val();
- var editTo = $("#editTo").val();
- var editStatus = $("#editStatus").val();
- var excelName = luckysheet.toJson().title;
- if ($.trim(editFrom) == '' && $.trim(editTo) == '') {
- } else if (/^\d*$/.test(editFrom) && /^\d*$/.test(editTo)) {
- if (editFrom == 0) {
- window.top.$vm.$message({
- message: '可编辑列开始不能为0',
- type: 'info'
- })
- return;
- }
- if (editFrom > editTo) {
- window.top.$vm.$message({
- message: '可编辑列的起始列不能大于结束列',
- type: 'info'
- })
- return;
- }
- } else if (/^[a-zA-Z]+$/.test(editFrom) && /^[a-zA-Z]+$/.test(editTo)) {
- } else {
- window.top.$vm.$message({
- message: '可编辑列必须全部为字母或数字',
- type: 'info'
- });
- return;
- }
- util.ajaxJson("正在加载中", ctx + '/market/cOnlineExcel/checkExcelEmpty', { data: excelData, }, function (data) {
- if (data.result == 1) {
- window.top.$vm.$message({
- message: data.desc,
- type: 'error'
- });
- } else {
- util.ajaxJson("正在加载中", ctx + urlsave, {
- data: excelData,
- id: excelId,
- editConStart: editFrom,
- editConEnd: editTo,
- excelName: excelName,
- editStatus: editStatus
- }, function (data) {
- if (data.result == 1) {
- window.top.$vm.$message({
- message: data.desc,
- type: 'error'
- })
- } else {
- window.top.$vm.$message({
- message: '保存成功',
- type: 'info'
- });
- console.log(data);
- getData()
- }
- });
- }
- });
- })
- // 导出
- $('#exports').click(function () {
- var excelName = luckysheet.toJson().title;
- exportExcel(luckysheet.getluckysheetfile(), excelName)
- })
- // 导入
- $("#importspro").change(function (evt) {
- var excelId = $(window.parent.document).find("#excelId").attr("value");
- console.log(evt);
- var files = evt.target.files;
- console.log(files);
- if (files == null || files.length == 0) {
- window.top.$vm.$message({
- message: '没有文件导入',
- type: 'info'
- })
- return;
- }
- var name = files[0].name;
- var suffixArr = name.split("."),
- suffix = suffixArr[suffixArr.length - 1];
- if (suffix != "xlsx") {
- window.top.$vm.$message({
- message: '目前只支持xlsx文件的导入',
- type: 'info'
- })
- return;
- }
- // 解析文件
- LuckyExcel.transformExcelToLucky(files[0], function (exportJson, luckysheetfile) {
- console.log(exportJson);
- if (exportJson.sheets == null || exportJson.sheets.length == 0) {
- window.top.$vm.$message({
- message: '无法读取excel文件的内容,当前不支持xls文件',
- type: 'info'
- })
- return;
- }
- let res = JSON.stringify(exportJson)
- console.log(res);
- util.ajaxJson("正在导入中", "http://10.149.85.91:7777/sheet/excel/importFile", { exceldata: res, id: excelId }, function (res) {
- console.log(res);
- if (res.code === '1') {
- // 销毁原来的excel
- window.luckysheet.destroy();
- // // 重新加载
- var a = exportJson.sheets[0];
- a.name = '';
- if (res.code === '1') {
- }
- initExcel([a], name.replace('.xlsx', ''), excelId);
- // // 绑定按钮事件
- initHandel()
- }
- });
- }
- );
- });
- }
- getData()
- })
- </script>
- </body>
- </html>
|