Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Commit

Permalink
feat(api and config): api exitEditMode() scroll() config defaultFontSize
Browse files Browse the repository at this point in the history
  • Loading branch information
wpxp123456 committed Oct 19, 2020
1 parent 63ef73c commit 5eedc48
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 12 deletions.
8 changes: 2 additions & 6 deletions docs/zh/guide/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ Luckysheet针对常用的数据操作需求,开放了主要功能的API,开
------------

### exitEditMode([,setting])


- **参数**

Expand Down Expand Up @@ -2036,14 +2035,11 @@ Luckysheet针对常用的数据操作需求,开放了主要功能的API,开

### scroll([setting])

[todo]


- **参数**

- {PlainObject} [setting]: 可选参数
+ {Number} [scrollWidth]:横向滚动值。默认为当前横向滚动位置。
+ {Number} [scrollHeight]:纵向滚动值。默认为当前纵向滚动位置。
+ {Number} [scrollLeft]:横向滚动值。默认为当前横向滚动位置。
+ {Number} [scrollTop]:纵向滚动值。默认为当前纵向滚动位置。
+ {Number} [targetRow]:纵向滚动到指定的行号。默认为当前纵向滚动位置。
+ {Number} [targetColumn]:横向滚动到指定的列号。默认为当前横向滚动位置。
+ {Function} [success]: 表格刷新成功后的回调函数
Expand Down
1 change: 1 addition & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ export default {
columeHeaderHeight: 20,
defaultColWidth:73,
defaultRowHeight:19,
defaultFontSize:10,
}
2 changes: 1 addition & 1 deletion src/controllers/constant.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/controllers/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,6 @@ export function keyboardInitial(){
$("#luckysheet-input-box").click(function () {
formula.rangeHightlightselected($("#luckysheet-rich-text-editor"));
}).add("#" + Store.container).on("keydown", function (event) {
if ($("#luckysheet-modal-dialog-mask").is(":visible") || $(event.target).hasClass("luckysheet-mousedown-cancel") || $(event.target).hasClass("formulaInputFocus")) {
return;
}

let ctrlKey = event.ctrlKey;
let altKey = event.altKey;
let shiftKey = event.shiftKey;
Expand Down Expand Up @@ -322,6 +318,10 @@ export function keyboardInitial(){

return;
}

if ($("#luckysheet-modal-dialog-mask").is(":visible") || $(event.target).hasClass("luckysheet-mousedown-cancel") || $(event.target).hasClass("formulaInputFocus")) {
return;
}

let $inputbox = $("#luckysheet-input-box");

Expand Down
3 changes: 3 additions & 0 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ luckysheet.create = function (setting) {
Store.lang = extendsetting.lang; //language
Store.allowEdit = extendsetting.allowEdit;
Store.fontList = extendsetting.fontList;
Store.defaultFontSize = extendsetting.defaultFontSize;
server.gridKey = extendsetting.gridKey;
server.loadUrl = extendsetting.loadUrl;
server.updateUrl = extendsetting.updateUrl;
Expand Down Expand Up @@ -104,7 +105,9 @@ luckysheet.create = function (setting) {
luckysheetConfigsetting.plugins = extendsetting.plugins;

luckysheetConfigsetting.rowHeaderWidth = extendsetting.rowHeaderWidth;
Store.rowHeaderWidth = extendsetting.rowHeaderWidth;
luckysheetConfigsetting.columeHeaderHeight = extendsetting.columeHeaderHeight;
Store.columeHeaderHeight = extendsetting.columeHeaderHeight;

luckysheetConfigsetting.defaultColWidth = extendsetting.defaultColWidth;
luckysheetConfigsetting.defaultRowHeight = extendsetting.defaultRowHeight;
Expand Down
152 changes: 152 additions & 0 deletions src/global/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,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页,只设置参数不渲染
Expand Down Expand Up @@ -4647,6 +4662,143 @@ export function setSheetMove(type, options = {}) {
}


/**
* 显示指定下标工作表的网格线,返回操作的工作表对象
* @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;
}


/**
* 滚动当前工作表位置
* @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画布
*
Expand Down
1 change: 1 addition & 0 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ const Store = {
inlineStringEditRange:null,

fontList:[],
defaultFontSize: 10,

currentSheetView:"viewNormal",

Expand Down
2 changes: 1 addition & 1 deletion src/utils/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ function luckysheetfontformat(format) {

//font-size/line-height
if (!format.fs) {
font += "10pt ";
font += Store.luckysheetfontformat + "pt ";
}
else {
font += Math.ceil(format.fs) + "pt ";
Expand Down

0 comments on commit 5eedc48

Please sign in to comment.