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

Commit

Permalink
Merge pull request #305 from flowerField/master
Browse files Browse the repository at this point in the history
优化:限制sheet工作表的重命名不能为空
  • Loading branch information
mengshukeji authored Dec 7, 2020
2 parents a2cf969 + d355b48 commit 1d7ea8d
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 8 deletions.
15 changes: 15 additions & 0 deletions docs/guide/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,21 @@ Note that you also need to configure `loadUrl` and `loadSheetUrl` to take effect

------------

### limitSheetNameLength
- Type: Boolean
- Default: true
- Usage:Is the length of the sheet name limited in scenarios such as sheet renaming

------------

### defaultSheetNameMaxLength
- Type:Number
- Default:31
- Usage:Default maximum allowed sheet name length

------------


## Hook Function (TODO)

When the hook function is used in secondary development, hooks will be implanted in each common mouse or keyboard operation, and the function passed in by the developer will be called to expand the function of Luckysheet.
Expand Down
16 changes: 16 additions & 0 deletions docs/zh/guide/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ Luckysheet开放了更细致的自定义配置选项,分别有
- 列标题区域的高度 [columnHeaderHeight](#columnHeaderHeight)
- 是否显示公式栏 [sheetFormulaBar](#sheetFormulaBar)
- 初始化默认字体大小 [defaultFontSize](#defaultFontSize)
- 是否限制工作表名长度 [limitSheetNameLength](#limitSheetNameLength)
- 默认允许工作表名的最大长度 [defaultSheetNameMaxLength](#defaultSheetNameMaxLength)

### container
- 类型:String
Expand Down Expand Up @@ -599,6 +601,20 @@ Luckysheet开放了更细致的自定义配置选项,分别有

------------

### limitSheetNameLength
- 类型:Boolean
- 默认值:true
- 作用:工作表重命名等场景下是否限制工作表名称的长度

------------

### defaultSheetNameMaxLength
- 类型:Number
- 默认值:31
- 作用:默认允许的工作表名最大长度

------------

## 钩子函数

钩子函数应用于二次开发时,会在各个常用鼠标或者键盘操作时植入钩子,调用开发者传入的函数,起到扩展Luckysheet功能的作用。
Expand Down
1 change: 1 addition & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const uglifyOptions = {

// babel config
const babelConfig = {
compact:false,
babelHelpers: 'bundled',
exclude: 'node_modules/**', // Only compile our source code
plugins: [
Expand Down
3 changes: 2 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export default {
defaultColWidth:73,
defaultRowHeight:19,
defaultFontSize:10,

limitSheetNameLength:true, //是否限制工作表名的长度
defaultSheetNameMaxLength:31, //默认工作表名称的最大长度
sheetFormulaBar:true, //是否显示公式栏
showtoolbarConfig:{}, //自定义工具栏
showsheetbarConfig:{}, //自定义底部sheet页
Expand Down
8 changes: 4 additions & 4 deletions src/controllers/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ const server = {
//客户端接收服务端数据时触发
_this.websocket.onmessage = function(result){
Store.result = result
let data = eval('(' + result.data + ')');
let data = new Function("return " + result.data)();
console.info(data);
let type = data.type;
let {message,id} = data;
Expand Down Expand Up @@ -522,7 +522,7 @@ const server = {
let op = item.op, pos = item.pos;

if(getObjType(value) != "object"){
value = eval('('+ value +')');
value = new Function("return " + value)();
}

let r = value.r, c = value.c;
Expand Down Expand Up @@ -995,7 +995,7 @@ const server = {
// console.log("request");
if(_this.updateUrl != ""){
$.post(_this.updateUrl, { compress: iscommpress, gridKey: _this.gridKey, data: params }, function (data) {
let re = eval('('+ data +')')
let re = new Function("return " + data)();
if(re.status){
$("#luckysheet_info_detail_update").html("最近存档时间:"+ dayjs().format("M-D H:m:s"));
$("#luckysheet_info_detail_save").html("同步成功");
Expand Down Expand Up @@ -1055,7 +1055,7 @@ const server = {
if(_this.updateImageUrl != ""){
// $.post(_this.updateImageUrl, { compress: true, gridKey: _this.gridKey, data:data1 }, function (data) {
$.post(_this.updateImageUrl, { compress: false, gridKey: _this.gridKey, data:data1 }, function (data) {
let re = eval('('+ data +')')
let re = new Function("return " + data)();
if(re.status){
imageRequestLast = dayjs();
}
Expand Down
48 changes: 47 additions & 1 deletion src/controllers/sheetBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import luckysheetConfigsetting from './luckysheetConfigsetting';


//表格底部名称栏区域 相关事件(增、删、改、隐藏显示、颜色等等)
let isInitialSheetConfig = false, luckysheetcurrentSheetitem = null, jfdbclicklagTimeout = null;
let isInitialSheetConfig = false, luckysheetcurrentSheetitem = null, jfdbclicklagTimeout = null,oldSheetFileName = "";;
function showsheetconfigmenu() {
if (!isInitialSheetConfig) {
isInitialSheetConfig = true;
Expand Down Expand Up @@ -225,10 +225,55 @@ export function initialSheetBar(){
luckysheetsheetnameeditor($(this));
});

let compositionFlag = true;
$("#luckysheet-sheet-area").on("compositionstart", "span.luckysheet-sheets-item-name", ()=> compositionFlag = false);
$("#luckysheet-sheet-area").on("compositionend", "span.luckysheet-sheets-item-name", ()=> compositionFlag = true);
$("#luckysheet-sheet-area").on("input", "span.luckysheet-sheets-item-name", function () {
if(Store.allowEdit===false){
return;
}

if(Store.limitSheetNameLength === false){
return
}

let maxLength = Store.defaultSheetNameMaxLength;
if(maxLength === 0){
return
}

setTimeout( ()=> {
if (compositionFlag) {

if ($(this).text().length >= maxLength) { /* 检查:值是否越界 */
setTimeout(() => {
$(this).text($(this).text().substring(0, maxLength));

let range = window.getSelection();
range.selectAllChildren(this);
range.collapseToEnd();
}, 0);
}
}
}, 0);
});

$("#luckysheet-sheet-area").on("blur", "span.luckysheet-sheets-item-name", function (e) {
if(Store.allowEdit===false){
return;
}

if(0 === $(this).text().length){

alert(locale_sheetconfig.sheetNamecannotIsEmptyError);
setTimeout(()=>{
$(this).text(oldSheetFileName);
luckysheetsheetnameeditor($(this));
$(this).focus();
}, 1);
return;
}

let $t = $(this);
let txt = $t.text(), oldtxt = $t.data("oldtxt");
var reg1 = new RegExp("[\\[\\]:\\?*\/'\"]");
Expand Down Expand Up @@ -279,6 +324,7 @@ export function initialSheetBar(){
let $t = $(this);
if (kcode == keycode.ENTER) {
let index = getSheetIndex(Store.currentSheetIndex);
oldSheetFileName = Store.luckysheetfile[index].name || oldSheetFileName;
Store.luckysheetfile[index].name = $t.text();
$t.attr("contenteditable", "false");
}
Expand Down
2 changes: 2 additions & 0 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ luckysheet.create = function (setting) {
Store.fullscreenmode = extendsetting.fullscreenmode;
Store.lang = extendsetting.lang; //language
Store.allowEdit = extendsetting.allowEdit;
Store.limitSheetNameLength = extendsetting.limitSheetNameLength;
Store.defaultSheetNameMaxLength = extendsetting.defaultSheetNameMaxLength;
Store.fontList = extendsetting.fontList;
server.gridKey = extendsetting.gridKey;
server.loadUrl = extendsetting.loadUrl;
Expand Down
18 changes: 16 additions & 2 deletions src/css/luckysheet-core.css
Original file line number Diff line number Diff line change
Expand Up @@ -2329,8 +2329,14 @@ body:not(.ewa-ipad) .luckysheet-rows-h-cell-sel:hover {
padding-right: 10px;
padding-left: 12px;
}


#luckysheet-sheet-list .luckysheet-cols-menuitem .luckysheet-cols-menuitem-content {
padding-right: 0px;
max-width: 430px;
min-width: 100px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.luckysheet-filter-menu div.luckysheet-cols-menuitem {
padding-top: 0px;
padding-bottom: 0px;
Expand Down Expand Up @@ -2978,6 +2984,14 @@ fieldset[disabled] .btn-danger.focus {
#luckysheet-sheet-list .luckysheet-cols-menuitem .luckysheet-cols-menuitem-content {
padding-left: 5px;
}
/*
#luckysheet-sheet-list .luckysheet-cols-menuitem .luckysheet-cols-menuitem-content {
max-width: 420px;
min-width: 190px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
} */


#luckysheet-sheet-list .icon {
Expand Down
1 change: 1 addition & 0 deletions src/locale/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -9512,6 +9512,7 @@ export default {
noHide:"Can't hide, at least keep one sheet tag",
chartEditNoOpt:"This operation is not allowed in chart editing mode!",
sheetNameSpecCharError:"The name cannot contain:[ ] : \ ? * / ' \"",
sheetNamecannotIsEmptyError:"Sheet name cannot be empty"
},
conditionformat: {
conditionformat_greaterThan: 'Conditionformat-GreaterThan',
Expand Down
1 change: 1 addition & 0 deletions src/locale/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -9510,6 +9510,7 @@ export default {
noHide:"No se puede ocultar, al menos conserva una etiqueta de hoja",
chartEditNoOpt:"¡Esta operación no está permitida en el modo de edición de gráficos!",
sheetNameSpecCharError:"El nombre no puede contener:[ ] : \ ? * / ' \"",
sheetNamecannotIsEmptyError:"El nombre de la hoja no puede estar vacío"
},
conditionformat: {
conditionformat_greaterThan: 'Conditionformat-GreaterThan',
Expand Down
1 change: 1 addition & 0 deletions src/locale/zh.js
Original file line number Diff line number Diff line change
Expand Up @@ -9755,6 +9755,7 @@ export default {
noHide:"不能隐藏, 至少保留一个sheet标签",
chartEditNoOpt:"图表编辑模式下不允许该操作!",
sheetNameSpecCharError:"名称不能包含:[ ] : \ ? * / ' \"",
sheetNamecannotIsEmptyError:"名称不能为空"
},
conditionformat: {
conditionformat_greaterThan: '条件格式——大于',
Expand Down

0 comments on commit 1d7ea8d

Please sign in to comment.