|
@@ -0,0 +1,154 @@
|
|
|
+
|
|
|
+/* 初始化
|
|
|
+ options 其他配置 包括初始化数据 data:[{ celldata:[] }]
|
|
|
+ sheetInfo 表格id相关信息 用来内容hooks变化时保存草稿
|
|
|
+ limit 限制性数据
|
|
|
+ callbackItems 回调函数组成的对象
|
|
|
+*/
|
|
|
+import { showToast } from "vant";
|
|
|
+export function initSheet(container,options={},sheetInfo={},limit,callbackItems) {
|
|
|
+ console.log(limit);
|
|
|
+ const configOpt = {
|
|
|
+ container,
|
|
|
+ lang: localStorage.getItem('i18n') == 'en' ? 'en' : 'zh', // 设定表格语言
|
|
|
+ showinfobar: false,//顶部info
|
|
|
+ showsheetbar:false,//底部sheet页 暂禁止添加多个表格
|
|
|
+ showtoolbarConfig:{
|
|
|
+ image: false,//图片
|
|
|
+ print: false,//打印
|
|
|
+ chart: false, // '图表'
|
|
|
+ postil: false, //'批注'
|
|
|
+ },
|
|
|
+ cellRightClickConfig: {
|
|
|
+ chart: false, // 图表生成
|
|
|
+ image: false, // 插入图片
|
|
|
+ link: false, // 插入链接
|
|
|
+ },
|
|
|
+ ...options,
|
|
|
+ // allowCopy:false,//没效果
|
|
|
+ hook: {
|
|
|
+ cellEditBefore:(range)=>{
|
|
|
+ if(limit.disabled){
|
|
|
+ showToast({message: '当前不可编辑',type:'warning'})
|
|
|
+ setTimeout(()=>{
|
|
|
+ luckysheet.exitEditMode();
|
|
|
+ },0)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ cellUpdateBefore:()=>{
|
|
|
+ if(limit.disabled){
|
|
|
+ // 不可编辑
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // rangeCopyBefore:(range,data)=>{
|
|
|
+ // // 不触发
|
|
|
+ // console.log(range,data,'range,data','rangeCopyBefore');
|
|
|
+ // },
|
|
|
+ // rangeCopyAfter:(range,data)=>{
|
|
|
+ // // 不触发
|
|
|
+ // console.log(range,data,'range,data','rangeCopyAfter');
|
|
|
+ // },
|
|
|
+ updated: (a,b,c,d,e)=> {
|
|
|
+ /**
|
|
|
+ * lucksheet 本身没有完美的禁止用户编辑的功能,只能自己控制了,用户操作后撤销,用户撤销后重做
|
|
|
+ * stopUndo -- 阻止撤销 由于撤销会触发updated,又再进行撤销,直接撤销到最初状态了,我们只需要撤销一次
|
|
|
+ * withdrawUndo -- 撤销用户撤销的操作 即重做
|
|
|
+ */
|
|
|
+ if(limit.disabled){
|
|
|
+ if((!luckysheet.stopUndo)){
|
|
|
+ setTimeout(()=>{
|
|
|
+ showToast({message: '当前不可编辑',type:'warning'})
|
|
|
+ if(luckysheet.withdrawUndo) {
|
|
|
+ // 重做用户撤销的操作,我们自己的重做操作,不能再撤销
|
|
|
+ luckysheet.stopUndo=false
|
|
|
+ luckysheet.withdrawUndo=false
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let result=luckysheet.undo()
|
|
|
+ luckysheet.stopUndo=false
|
|
|
+ if(Object.keys(result).length==0){
|
|
|
+ requestAnimationFrame(()=>{
|
|
|
+ luckysheet.redo()
|
|
|
+ luckysheet.withdrawUndo=true
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },0)
|
|
|
+ luckysheet.stopUndo=true
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // console.log(callbackItems);
|
|
|
+ callbackItems.updated()
|
|
|
+ //草稿
|
|
|
+ // if(sheetInfo.Source&&sheetInfo.Source===1) {
|
|
|
+ // let data = luckysheet.getAllSheets()[0];
|
|
|
+ // data.luckysheet_select_save = [];
|
|
|
+ // const { ExcelInfoId,ExcelName,ExcelClassifyId } = sheetInfo;
|
|
|
+ // ExcelInfoId && sheetInterface.sheetDrafSave({
|
|
|
+ // ExcelInfoId,
|
|
|
+ // ExcelName,
|
|
|
+ // ExcelClassifyId,
|
|
|
+ // Content: JSON.stringify(data)
|
|
|
+ // })
|
|
|
+ // }
|
|
|
+ },
|
|
|
+ ...options.hook,
|
|
|
+ },
|
|
|
+
|
|
|
+ showtoolbar: false, // 是否显示工具栏
|
|
|
+ showstatisticBar: false, // 是否显示底部计数栏
|
|
|
+ sheetBottomConfig: false, // sheet页下方的添加行按钮和回到顶部按钮配置
|
|
|
+ allowEdit: false, // 是否允许前台编辑
|
|
|
+ enableAddRow: false, // 允许增加行
|
|
|
+ enableAddCol: false, // 允许增加列
|
|
|
+ userInfo: false, // 右上角的用户信息展示样式
|
|
|
+ showRowBar: false, // 是否显示行号区域
|
|
|
+ showColumnBar: false, // 是否显示列号区域
|
|
|
+ sheetFormulaBar: false, // 是否显示公式栏
|
|
|
+ enableAddBackTop: false,//返回头部按钮
|
|
|
+ rowHeaderWidth: 0,//纵坐标
|
|
|
+ columnHeaderHeight: 0,//横坐标
|
|
|
+ showstatisticBarConfig: {
|
|
|
+ count:false,
|
|
|
+ view:false,
|
|
|
+ zoom:false,
|
|
|
+ },
|
|
|
+ showsheetbarConfig: {
|
|
|
+ add: false, //新增sheet
|
|
|
+ menu: false, //sheet管理菜单
|
|
|
+ sheet: false, //sheet页显示
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+ luckysheet.create(configOpt)
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+/* 保存表格关联截图 手动选区截图再清空选区 */
|
|
|
+export const getSheetImage = (data) => {
|
|
|
+ const { celldata } = data;
|
|
|
+
|
|
|
+ //超过1000个就不遍历了
|
|
|
+ let r_start,r_end,c_start,c_end;
|
|
|
+ if(celldata.length > 1000) {
|
|
|
+ const splitData = celldata.slice(0,1000);
|
|
|
+ const r_arr = splitData.map(_ => _.c);
|
|
|
+ r_start = splitData[0].r;
|
|
|
+ r_end = splitData[splitData.length-1].r;
|
|
|
+ c_start = Math.min(...r_arr);
|
|
|
+ c_end = Math.max(...r_arr);
|
|
|
+
|
|
|
+ }else {
|
|
|
+ const r_arr = celldata.map(_ => _.c);
|
|
|
+ r_start = celldata[0].r;
|
|
|
+ r_end = celldata[celldata.length-1].r;
|
|
|
+ c_start = Math.min(...r_arr);
|
|
|
+ c_end = Math.max(...r_arr);
|
|
|
+ }
|
|
|
+
|
|
|
+ luckysheet.setRangeShow({row:[r_start,r_end],column:[c_start,c_end]},{show: false})
|
|
|
+ let img = luckysheet.getScreenshot()
|
|
|
+ return img;
|
|
|
+
|
|
|
+}
|