Browse Source

Merge branch 'master' of https://github.com/mengshukeji/Luckysheet into master

master
wbfsa 5 years ago
parent
commit
29f2593167
  1. 15
      docs/guide/config.md
  2. 16
      docs/zh/guide/config.md
  3. 1
      gulpfile.js
  4. 3
      src/config.js
  5. 2
      src/controllers/select.js
  6. 31
      src/controllers/server.js
  7. 48
      src/controllers/sheetBar.js
  8. 2
      src/core.js
  9. 18
      src/css/luckysheet-core.css
  10. 22
      src/global/api.js
  11. 61
      src/global/getRowlen.js
  12. 1
      src/locale/en.js
  13. 1
      src/locale/es.js
  14. 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页

2
src/controllers/select.js

@ -458,7 +458,7 @@ function selectionCopyShow(range) {
let copyDomHtml = '<div class="luckysheet-selection-copy" style="display: block; left: ' + col_pre + 'px; width: ' + (col - col_pre - 1) + 'px; top: ' + row_pre + 'px; height: ' + (row - row_pre - 1) + 'px;">' +
'<div class="luckysheet-selection-copy-top luckysheet-copy"></div>' +
'<div class="luckysheet-selection-copy-right luckysheet-copy"d></iv>' +
'<div class="luckysheet-selection-copy-right luckysheet-copy"></div>' +
'<div class="luckysheet-selection-copy-bottom luckysheet-copy"></div>' +
'<div class="luckysheet-selection-copy-left luckysheet-copy"></div>' +
'<div class="luckysheet-selection-copy-hc"></div>' +

31
src/controllers/server.js

@ -8,13 +8,15 @@ import menuButton from './menuButton';
import { createFilterOptions } from './filter';
import luckysheetFreezen from './freezen';
import luckysheetPostil from './postil';
import imageCtrl from './imageCtrl';
import dataVerificationCtrl from './dataVerificationCtrl';
import hyperlinkCtrl from './hyperlinkCtrl';
import { getObjType, replaceHtml, getByteLen } from '../utils/util';
import { getSheetIndex } from '../methods/get';
import Store from '../store';
import { collaborativeEditBox } from './select'
import locale from '../locale/locale';
import dayjs from "dayjs";
import imageCtrl from './imageCtrl';
import json from '../global/json';
const server = {
@ -169,7 +171,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;
@ -517,12 +519,31 @@ const server = {
}, 1);
}
}
else if(k == "images"){ //图片
if(index == Store.currentSheetIndex){
imageCtrl.images = value;
imageCtrl.allImagesShow();
imageCtrl.init();
}
}
else if(k == "dataVerification"){ //数据验证
if(index == Store.currentSheetIndex){
dataVerificationCtrl.dataVerification = value;
dataVerificationCtrl.init();
}
}
else if(k == "hyperlink"){ //链接
if(index == Store.currentSheetIndex){
hyperlinkCtrl.hyperlink = value;
hyperlinkCtrl.init();
}
}
}
else if(type == "fc"){ //函数链calc
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 +1016,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 +1076,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 {

22
src/global/api.js

@ -113,7 +113,10 @@ export function setCellValue(row, column, value, options = {}) {
return tooltip.info("The order parameter is invalid.", "");
}
let data = $.extend(true, [], file.data);
let data = file.data;
if(isRefresh) {
data = $.extend(true, [], file.data);
}
if(data.length == 0){
data = sheetmanage.buildGridData(file);
}
@ -147,6 +150,10 @@ export function setCellValue(row, column, value, options = {}) {
}
else if(value instanceof Object){
let curv = {};
let cell = data[row][column];
if(isRealNull(cell)){
cell = {};
}
if(value.f!=null && value.v==null){
curv.f = value.f;
if(value.ct!=null){
@ -164,6 +171,9 @@ export function setCellValue(row, column, value, options = {}) {
if(value.v!=null){
curv.v = value.v;
}
else {
curv.v = cell.v;
}
if(value.m!=null){
curv.m = value.m;
}
@ -175,7 +185,11 @@ export function setCellValue(row, column, value, options = {}) {
if(attr in formatList){
menuButton.updateFormatCell(data, attr, v, row, row, column, column);//change range format
}
else {
cell[attr] = v;
}
}
data[row][column] = cell;
}
else{
if(value.toString().substr(0,1)=="=" || value.toString().substr(0,5)=="<span"){
@ -318,7 +332,7 @@ export function setCellFormat(row, column, attr, value, options = {}) {
success
} = { ...options };
let targetSheetData = $.extend(true, [], Store.luckysheetfile[order].data);
let cellData = targetSheetData[row][column];
let cellData = targetSheetData[row][column] || {};
// 特殊格式
if (attr == 'ct' && (!value || !value.hasOwnProperty('fa') || !value.hasOwnProperty('t'))) {
@ -349,8 +363,10 @@ export function setCellFormat(row, column, attr, value, options = {}) {
cellData[attr] = value;
}
targetSheetData[row][column] = cellData;
// refresh
jfrefreshgrid(data, [{ "row": [row, row], "column": [column, column] }]);
jfrefreshgrid(targetSheetData, [{ "row": [row, row], "column": [column, column] }]);
if (success && typeof success === 'function') {
success(cellData);

61
src/global/getRowlen.js

@ -26,9 +26,6 @@ function rowlenByRange(d, r1, r2, cfg) {
}
let currentRowLen = Store.defaultrowlen;
// if(cfg_clone["rowlen"][r] != null){
// currentRowLen = cfg_clone["rowlen"][r];
// }
if(cfg_clone["customHeight"][r]==1){
continue;
@ -39,7 +36,7 @@ function rowlenByRange(d, r1, r2, cfg) {
for(let c = 0; c < d[r].length; c++){
let cell = d[r][c];
if(cell == null){
if(cell == null || cell.mc != null){
continue;
}
@ -53,63 +50,11 @@ function rowlenByRange(d, r1, r2, cfg) {
});
let computeRowlen = 0;
// console.log("rowlen", textInfo);
if(textInfo!=null){
computeRowlen = textInfo.textHeightAll+2;
}
// let fontset = luckysheetfontformat(cell);
// canvas.font = fontset;
// let value = getcellvalue(r, c, d).toString(); //单元格文本
// let measureText = getMeasureText(value, canvas);
// let textMetrics = measureText.width; //文本宽度
// let oneLineTextHeight = measureText.actualBoundingBoxDescent + measureText.actualBoundingBoxAscent;
// let spaceHeight = Math.ceil(oneLineTextHeight/3);
// let computeRowlen; //计算行高
// let word_space_height = oneLineTextHeight/3;
// if(cell.tb == "2"){
// //自动换行
// let cellWidth = colLocationByIndex(c)[1] - colLocationByIndex(c)[0] - 4; //单元格宽度
// if(textMetrics > cellWidth){
// let strArr = []; //文本截断数组
// strArr = getCellTextSplitArr(value, strArr, cellWidth, canvas);
// computeRowlen = (oneLineTextHeight+word_space_height) * strArr.length + spaceHeight;
// }
// else{
// computeRowlen = oneLineTextHeight + spaceHeight;
// }
// }
// else if(cell.tr != null){
// //单元格有旋转标示
// let tr = cell.tr;
// if(tr == "0"){
// //无旋转
// computeRowlen = oneLineTextHeight + spaceHeight;
// }
// else if(tr == "1" || tr == "2"){
// //向下倾斜(45 旋转)----向上倾斜(-45 旋转)
// computeRowlen = 0.707 * (textMetrics + oneLineTextHeight) + spaceHeight;
// }
// else if(tr == "3"){
// //竖排文字
// computeRowlen = value.length * oneLineTextHeight + spaceHeight;
// }
// else if(tr == "4" || tr == "5"){
// //向下90(90 旋转)----向上90(-90 旋转)
// computeRowlen = textMetrics + spaceHeight;
// }
// computeRowlen = Math.round(computeRowlen);
// }
// else{
// computeRowlen = oneLineTextHeight + spaceHeight;
// }
//比较计算高度和当前高度取最大高度
if(computeRowlen > currentRowLen){
currentRowLen = computeRowlen;
@ -118,7 +63,7 @@ function rowlenByRange(d, r1, r2, cfg) {
}
currentRowLen = currentRowLen/Store.zoomRatio;
console.log(currentRowLen);
if(currentRowLen != Store.defaultrowlen){
cfg_clone["rowlen"][r] = currentRowLen;
}

1
src/locale/en.js

@ -9528,6 +9528,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

@ -9526,6 +9526,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

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

Loading…
Cancel
Save