Browse Source

Merge pull request #305 from flowerField/master

优化:限制sheet工作表的重命名不能为空
master
mengshukeji 5 years ago
committed by GitHub
parent
commit
1d7ea8d2a0
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      docs/guide/config.md
  2. 16
      docs/zh/guide/config.md
  3. 1
      gulpfile.js
  4. 3
      src/config.js
  5. 8
      src/controllers/server.js
  6. 48
      src/controllers/sheetBar.js
  7. 2
      src/core.js
  8. 18
      src/css/luckysheet-core.css
  9. 1
      src/locale/en.js
  10. 1
      src/locale/es.js
  11. 1
      src/locale/zh.js

15
docs/guide/config.md

@ -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.

16
docs/zh/guide/config.md

@ -74,6 +74,8 @@ Luckysheet开放了更细致的自定义配置选项,分别有
- 列标题区域的高度 [columnHeaderHeight](#columnHeaderHeight)
- 是否显示公式栏 [sheetFormulaBar](#sheetFormulaBar)
- 初始化默认字体大小 [defaultFontSize](#defaultFontSize)
- 是否限制工作表名长度 [limitSheetNameLength](#limitSheetNameLength)
- 默认允许工作表名的最大长度 [defaultSheetNameMaxLength](#defaultSheetNameMaxLength)
### container
- 类型:String
@ -599,6 +601,20 @@ Luckysheet开放了更细致的自定义配置选项,分别有
------------
### limitSheetNameLength
- 类型:Boolean
- 默认值:true
- 作用:工作表重命名等场景下是否限制工作表名称的长度
------------
### defaultSheetNameMaxLength
- 类型:Number
- 默认值:31
- 作用:默认允许的工作表名最大长度
------------
## 钩子函数
钩子函数应用于二次开发时,会在各个常用鼠标或者键盘操作时植入钩子,调用开发者传入的函数,起到扩展Luckysheet功能的作用。

1
gulpfile.js

@ -41,6 +41,7 @@ const uglifyOptions = {
// babel config
const babelConfig = {
compact:false,
babelHelpers: 'bundled',
exclude: 'node_modules/**', // Only compile our source code
plugins: [

3
src/config.js

@ -57,7 +57,8 @@ export default {
defaultColWidth:73,
defaultRowHeight:19,
defaultFontSize:10,
limitSheetNameLength:true, //是否限制工作表名的长度
defaultSheetNameMaxLength:31, //默认工作表名称的最大长度
sheetFormulaBar:true, //是否显示公式栏
showtoolbarConfig:{}, //自定义工具栏
showsheetbarConfig:{}, //自定义底部sheet页

8
src/controllers/server.js

@ -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;
@ -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;
@ -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("同步成功");
@ -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();
}

48
src/controllers/sheetBar.js

@ -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;
@ -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("[\\[\\]:\\?*\/'\"]");
@ -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");
}

2
src/core.js

@ -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;

18
src/css/luckysheet-core.css

@ -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;
@ -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 {

1
src/locale/en.js

@ -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',

1
src/locale/es.js

@ -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',

1
src/locale/zh.js

@ -9755,6 +9755,7 @@ export default {
noHide:"不能隐藏, 至少保留一个sheet标签",
chartEditNoOpt:"图表编辑模式下不允许该操作!",
sheetNameSpecCharError:"名称不能包含:[ ] : \ ? * / ' \"",
sheetNamecannotIsEmptyError:"名称不能为空"
},
conditionformat: {
conditionformat_greaterThan: '条件格式——大于',

Loading…
Cancel
Save