@ -1,5 +1,5 @@
import Store from "../store" ;
import { replaceHtml , getObjType , chatatABC } from "../utils/util" ;
import { replaceHtml , getObjType , chatatABC , luckysheetactiveCell } from "../utils/util" ;
import { getSheetIndex , getluckysheet_select_save , getluckysheetfile } from "../methods/get" ;
import locale from "../locale/locale" ;
@ -20,6 +20,7 @@ import { luckysheetDeleteCell, luckysheetextendtable, luckysheetdeletetable } fr
import { isRealNull , valueIsError , isRealNum , isEditMode , hasPartMC } from "./validate" ;
import { isdatetime , diff } from "./datecontroll" ;
import { getBorderInfoCompute } from './border' ;
import { luckysheetDrawMain } from './draw' ;
import server from "../controllers/server" ;
import menuButton from '../controllers/menuButton' ;
@ -31,8 +32,9 @@ import sheetmanage from '../controllers/sheetmanage';
import conditionformat from '../controllers/conditionformat' ;
import { luckysheet_searcharray } from "../controllers/sheetSearch" ;
import { selectHightlightShow , selectIsOverlap } from '../controllers/select' ;
import { sheetHTML } from '../controllers/constant' ;
import { sheetHTML , luckysheetdefaultstyle } from '../controllers/constant' ;
import { createFilterOptions } from '../controllers/filter' ;
import controlHistory from '../controllers/controlHistory' ;
const IDCardReg = /^\d{6}(18|19|20)?\d{2}(0[1-9]|1[12])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i ;
@ -433,6 +435,21 @@ export function replace(content, replaceContent, options = {}) {
return matchCells ;
}
/ * *
* 手动触发退出编辑模式
* @ param { Object } options 可选参数
* @ param { Function } options . success 操作结束的回调函数
* /
export function exitEditMode ( options = { } ) {
formula . updatecell ( Store . luckysheetCellUpdate [ 0 ] , Store . luckysheetCellUpdate [ 1 ] ) ;
if ( options . success && typeof options . success === 'function' ) {
options . success ( ) ;
}
}
/ * *
* 冻结首行
* 若设置冻结的sheet不是当前sheet页 , 只设置参数不渲染
@ -4647,9 +4664,221 @@ export function setSheetMove(type, options = {}) {
}
/ * *
* 重新排序所有工作表的位置 , 指定工作表顺序的数组 。
* @ param { Array } orderList 工作表顺序 , 设置工作表的index和order来指定位置
* @ param { Object } options 可选参数
* @ param { Function } options . success 操作结束的回调函数
* /
export function setSheetOrder ( orderList , options = { } ) {
if ( orderList == null || orderList . length == 0 ) {
return tooltip . info ( "Type orderList not available" , "" ) ;
}
let orderListMap = { } ;
orderList . forEach ( ( item ) => {
orderListMap [ item . index . toString ( ) ] = item . order ;
} )
Store . luckysheetfile . sort ( ( x , y ) => {
let order_x = orderListMap [ x . index . toString ( ) ] ;
let order_y = orderListMap [ y . index . toString ( ) ] ;
if ( order_x != null && order_y != null ) {
return order_x - order_y ;
}
else if ( order_x != null ) {
return - 1 ;
}
else if ( order_y != null ) {
return 1 ;
}
else {
return 1 ;
}
} )
let orders = { } ;
Store . luckysheetfile . forEach ( ( item , i , arr ) => {
arr [ i ] . order = i ;
orders [ item . index . toString ( ) ] = i ;
if ( i > 0 ) {
let preIndex = arr [ i - 1 ] . index ;
$ ( "#luckysheet-sheets-item" + item . index ) . insertAfter ( $ ( "#luckysheet-sheets-item" + preIndex ) ) ;
}
} )
server . saveParam ( "shr" , null , orders ) ;
let {
success
} = { ... options }
if ( success && typeof success === 'function' ) {
success ( ) ;
}
}
/ * *
* 显示指定下标工作表的网格线 , 返回操作的工作表对象
* @ param { Object } options 可选参数
* @ param { Number } options . order 需要显示网格线的工作表下标 ; 默认值为当前工作表下标
* @ param { Function } options . success 操作结束的回调函数
* /
export function showGridLines ( options = { } ) {
let {
order = getSheetIndex ( Store . currentSheetIndex ) ,
success
} = { ... options }
let file = Store . luckysheetfile [ order ] ;
if ( file == null ) {
return tooltip . info ( "The order parameter is invalid." , "" ) ;
}
file . showGridLines = true ;
if ( file . index == Store . currentSheetIndex ) {
Store . showGridLines = true ;
setTimeout ( function ( ) {
luckysheetrefreshgrid ( ) ;
} , 1 ) ;
}
setTimeout ( ( ) => {
if ( success && typeof success === 'function' ) {
success ( ) ;
}
} , 1 ) ;
return file ;
}
/ * *
* 隐藏指定下标工作表的网格线 , 返回操作的工作表对象
* @ param { Object } options 可选参数
* @ param { Number } options . order 需要显示网格线的工作表下标 ; 默认值为当前工作表下标
* @ param { Function } options . success 操作结束的回调函数
* /
export function hideGridLines ( options = { } ) {
let {
order = getSheetIndex ( Store . currentSheetIndex ) ,
success
} = { ... options }
let file = Store . luckysheetfile [ order ] ;
if ( file == null ) {
return tooltip . info ( "The order parameter is invalid." , "" ) ;
}
file . showGridLines = false ;
if ( file . index == Store . currentSheetIndex ) {
Store . showGridLines = false ;
setTimeout ( function ( ) {
luckysheetrefreshgrid ( ) ;
} , 1 ) ;
}
setTimeout ( ( ) => {
if ( success && typeof success === 'function' ) {
success ( ) ;
}
} , 1 ) ;
return file ;
}
/ * *
* 刷新canvas
* @ param { Object } options 可选参数
* @ param { Function } options . success 操作结束的回调函数
* /
export function refresh ( options = { } ) {
luckysheetrefreshgrid ( ) ;
let {
success
} = { ... options }
if ( success && typeof success === 'function' ) {
success ( ) ;
}
}
/ * *
* 滚动当前工作表位置
* @ param { Object } options 可选参数
* @ param { Number } options . scrollLeft 横向滚动值
* @ param { Number } options . scrollTop 纵向滚动值
* @ param { Number } options . targetRow 纵向滚动到指定的行号
* @ param { Number } options . targetColumn 横向滚动到指定的列号
* @ param { Function } options . success 操作结束的回调函数
* /
export function scroll ( options = { } ) {
let {
scrollLeft ,
scrollTop ,
targetRow ,
targetColumn ,
success
} = { ... options }
if ( scrollLeft != null ) {
if ( getObjType ( scrollLeft ) != 'number' ) {
return tooltip . info ( "The scrollLeft parameter is invalid." , "" ) ;
}
$ ( "#luckysheet-scrollbar-x" ) . scrollLeft ( scrollLeft ) ;
}
else if ( targetColumn != null ) {
if ( getObjType ( targetColumn ) != 'number' ) {
return tooltip . info ( "The targetColumn parameter is invalid." , "" ) ;
}
let col = Store . visibledatacolumn [ targetColumn ] ,
col_pre = targetColumn <= 0 ? 0 : Store . visibledatacolumn [ targetColumn - 1 ] ;
$ ( "#luckysheet-scrollbar-x" ) . scrollLeft ( col_pre ) ;
}
if ( scrollTop != null ) {
if ( getObjType ( scrollTop ) != 'number' ) {
return tooltip . info ( "The scrollTop parameter is invalid." , "" ) ;
}
$ ( "#luckysheet-scrollbar-y" ) . scrollTop ( scrollTop ) ;
}
else if ( targetRow != null ) {
if ( getObjType ( targetRow ) != 'number' ) {
return tooltip . info ( "The targetRow parameter is invalid." , "" ) ;
}
let row = Store . visibledatarow [ targetRow ] ,
row_pre = targetRow <= 0 ? 0 : Store . visibledatarow [ targetRow - 1 ] ;
$ ( "#luckysheet-scrollbar-y" ) . scrollTop ( row_pre ) ;
}
if ( success && typeof success === 'function' ) {
success ( ) ;
}
}
/ * *
* 根据窗口大小自动resize画布
*
* @ param { Object } options 可选参数
* @ param { Function } options . success 操作结束的回调函数
* /
@ -4666,6 +4895,200 @@ export function resize(options = {}){
}
/ * *
* 返回指定选区截图后生成的base64格式的图片
* @ param { Object } options 可选参数
* @ param { Object | String } options . range 选区范围 , 只能为单个选区 ; 默认为当前选区
* /
export function getScreenshot ( options = { } ) {
let {
range = Store . luckysheet_select_save [ Store . luckysheet_select_save . length - 1 ] ,
} = { ... options }
if ( getObjType ( range ) == 'string' ) {
if ( ! formula . iscelldata ( range ) ) {
return tooltip . info ( "The range parameter is invalid." , "" ) ;
}
let cellrange = formula . getcellrange ( range ) ;
range = {
"row" : cellrange . row ,
"column" : cellrange . column
} ;
}
if ( getObjType ( range ) != 'object' || range . row == null || range . column == null ) {
return tooltip . info ( "The range parameter is invalid." , "" ) ;
}
let str = range . row [ 0 ] ,
edr = range . row [ 1 ] ,
stc = range . column [ 0 ] ,
edc = range . column [ 1 ] ;
let has_PartMC = hasPartMC ( Store . config , str , edr , stc , edc ) ;
if ( has_PartMC ) {
return tooltip . info ( 'Cannot perform this operation on partially merged cells' , '' ) ;
}
let visibledatarow = Store . visibledatarow ;
let visibledatacolumn = Store . visibledatacolumn ;
let scrollHeight , rh_height ;
if ( str - 1 < 0 ) {
scrollHeight = 0 ;
rh_height = visibledatarow [ edr ] ;
}
else {
scrollHeight = visibledatarow [ str - 1 ] ;
rh_height = visibledatarow [ edr ] - visibledatarow [ str - 1 ] ;
}
let scrollWidth , ch_width ;
if ( stc - 1 < 0 ) {
scrollWidth = 0 ;
ch_width = visibledatacolumn [ edc ] ;
}
else {
scrollWidth = visibledatacolumn [ stc - 1 ] ;
ch_width = visibledatacolumn [ edc ] - visibledatacolumn [ stc - 1 ] ;
}
let newCanvas = $ ( "<canvas>" ) . attr ( {
width : Math . ceil ( ch_width * Store . devicePixelRatio ) ,
height : Math . ceil ( rh_height * Store . devicePixelRatio )
} ) . css ( { width : ch_width , height : rh_height } ) ;
luckysheetDrawMain ( scrollWidth , scrollHeight , ch_width , rh_height , 1 , 1 , null , null , newCanvas ) ;
let ctx_newCanvas = newCanvas . get ( 0 ) . getContext ( "2d" ) ;
//补上 左边框和上边框
ctx_newCanvas . beginPath ( ) ;
ctx_newCanvas . moveTo (
0 ,
0
) ;
ctx_newCanvas . lineTo (
0 ,
Store . devicePixelRatio * rh_height
) ;
ctx_newCanvas . lineWidth = Store . devicePixelRatio * 2 ;
ctx_newCanvas . strokeStyle = luckysheetdefaultstyle . strokeStyle ;
ctx_newCanvas . stroke ( ) ;
ctx_newCanvas . closePath ( ) ;
ctx_newCanvas . beginPath ( ) ;
ctx_newCanvas . moveTo (
0 ,
0
) ;
ctx_newCanvas . lineTo (
Store . devicePixelRatio * ch_width ,
0
) ;
ctx_newCanvas . lineWidth = Store . devicePixelRatio * 2 ;
ctx_newCanvas . strokeStyle = luckysheetdefaultstyle . strokeStyle ;
ctx_newCanvas . stroke ( ) ;
ctx_newCanvas . closePath ( ) ;
let url = newCanvas . get ( 0 ) . toDataURL ( "image/png" ) ;
return url ;
}
/ * *
* 设置工作簿名称
* @ param { String } name 工作簿名称
* @ param { Object } options 可选参数
* @ param { Function } options . success 操作结束的回调函数
* /
export function setWorkbookName ( name , options = { } ) {
if ( name == null || name . toString ( ) . length == 0 ) {
return tooltip . info ( "The name parameter is invalid." , "" ) ;
}
$ ( "#luckysheet_info_detail_input" ) . val ( name ) ;
let {
success
} = { ... options }
if ( success && typeof success === 'function' ) {
success ( ) ;
}
}
/ * *
* 撤销当前操作 , 返回刚刚撤销的操作对象
* @ param { Object } options 可选参数
* @ param { Function } options . success 操作结束的回调函数
* /
export function undo ( options = { } ) {
let ctr = $ . extend ( true , { } , Store . jfredo [ Store . jfredo . length - 1 ] ) ;
controlHistory . redo ( new Event ( 'custom' ) ) ;
luckysheetactiveCell ( ) ;
let {
success
} = { ... options }
setTimeout ( ( ) => {
if ( success && typeof success === 'function' ) {
success ( ) ;
}
} , 1 ) ;
return ctr ;
}
/ * *
* 重做当前操作 , 返回刚刚重做的操作对象
* @ param { Object } options 可选参数
* @ param { Function } options . success 操作结束的回调函数
* /
export function redo ( options = { } ) {
let ctr = $ . extend ( true , { } , Store . jfundo [ Store . jfundo . length - 1 ] ) ;
controlHistory . undo ( new Event ( 'custom' ) ) ;
luckysheetactiveCell ( ) ;
let {
success
} = { ... options }
setTimeout ( ( ) => {
if ( success && typeof success === 'function' ) {
success ( ) ;
}
} , 1 ) ;
return ctr ;
}
/ * *
* 返回所有工作表配置
* /
export function getAllSheets ( ) {
let data = $ . extend ( true , [ ] , Store . luckysheetfile ) ;
data . forEach ( ( item , index , arr ) => {
if ( item . data != null && item . data . length > 0 ) {
item . celldata = sheetmanage . getGridData ( item . data ) ;
}
delete item . load ;
} )
return data ;
}
/ * *
* 根据index获取sheet页配置
*
@ -4796,18 +5219,39 @@ export function getLuckysheetfile(){
* @ param { Function } options . success 操作结束的回调函数
* /
export function transToCellData ( data , options = { } ) {
let {
success
} = { ... options }
setTimeout ( ( ) => {
if ( success && typeof success === 'function' ) {
success ( ) ;
}
} , 0 )
return sheetmanage . getGridData ( data )
}
/ * *
* celldata => data , celldata一维数组数据转化成表格所需二维数组
*
* @ param { Array } celldata 二维数组数据
* @ param { Object } options 可选参数
* @ param { Function } options . success 操作结束的回调函数
* /
export function transToData ( celldata , options = { } ) {
let {
success
} = { ... options }
setTimeout ( ( ) => {
if ( success && typeof success === 'function' ) {
success ( ) ;
}
} , 0 )
return sheetmanage . buildGridData ( {
celldata : celldata
} )
}