mengshukeji 5 years ago
parent
commit
0282fa06ad
  1. 30
      docs/zh/guide/api.md
  2. 22
      src/controllers/cellFormat.js
  3. 64
      src/controllers/imageCtrl.js
  4. 50
      src/controllers/postil.js
  5. 4
      src/controllers/zoom.js
  6. 447
      src/global/api.js
  7. 8
      src/global/draw.js
  8. 4
      src/global/formula.js
  9. 6
      src/global/setdata.js

30
docs/zh/guide/api.md

@ -544,8 +544,6 @@ Luckysheet针对常用的数据操作需求,开放了主要功能的API,开
### setRowHeight(rowInfo [,setting])
(TODO)
- **参数**
- {Object} [rowInfo]: 行数和高度对应关系
@ -568,8 +566,6 @@ Luckysheet针对常用的数据操作需求,开放了主要功能的API,开
### setColumnWidth(columnInfo [,setting])
(TODO)
- **参数**
- {Number} [columnInfo]: 列数和宽度对应关系
@ -2104,14 +2100,12 @@ Luckysheet针对常用的数据操作需求,开放了主要功能的API,开
### setSheetZoom(zoom [,setting])
[todo]
- **参数**
- {Number} [zoom]: 工作表缩放比例
- {Number} [zoom]: 工作表缩放比例,值范围为0.1 ~ 4;
- {PlainObject} [setting]: 可选参数
+ {Number} [order]: 工作表下标;默认值为当前工作表下标
+ {Function} [success]: 操作结束的回调函数
- **说明**
@ -2395,15 +2389,21 @@ Luckysheet针对常用的数据操作需求,开放了主要功能的API,开
## 数据验证
### setDataVerification(option, [setting])
[todo]
### setDataVerification(optionItem, [setting])
- **参数**
- {Object} [option]: 数据验证的配置信息
- {Object} [optionItem]: 数据验证的配置信息
+ {String} [type]: 类型;值可为`"dropdown"`(下拉列表)、`"checkbox"`(复选框)、`"number"`(数字)、`"number_integer"`(数字-整数)、`"number_decimal"`(数字-小数)、`"text_content"`(文本-内容)、`"text_length"`(文本-长度)、`"date"`(日期)、`"validity"`(有效性);
+ {String | Null} [type2]: 条件类型;类型`type`值为`"dropdown"`、`"checkbox"`时,`type2`值可为`null`;类型`type`值为`"number"`、`"number_integer"`、`"number_decimal"`、`"text_length"`时,`type2`值可为`"bw"`(介于)、`"nb"`(不介于)、`"eq"`(等于)、`"ne"`(不等于)、`"gt"`(大于)、`"lt"`(小于)、`"gte"`(大于等于)、`"lte"`(小于等于);类型`type`值为`"text_content"`时,`type2`值可为`"include"`(包括)、`"exclude"`(不包括)、`"equal"`(等于);类型`type`值为`"date"`时,`type2`值可为`"bw"`(介于)、`"nb"`(不介于)、`"eq"`(等于)、`"ne"`(不等于)、`"bf"`(早于)、`"nbf"`(不早于)、`"af"`(晚于)、`"naf"`(不晚于);类型`type`值为`"validity"`时,`type2`值可为`"card"`(身份证号码)、`"phone"`(手机号);
+ {String | Number} [value1]: 条件值1;类型`type`值为`"dropdown"`时,`value1`值可为选区或以英文逗号隔开的字符串,如`"1,2,3"`或者`"A1:B2"`;类型`type`值为`"validity"`时,`value1`值可为空;其他类型时`value1`值为数值或字符串;
+ {String | Number} [value2]: 条件值2;类型`type`值为`"checkbox"`或者条件类型`type2`值为`"bw"`、`"nb"`时有`value2`值,条件值为数值或日期时,条件值2要大于等于条件值1;其它情况可为空;
+ {Boolean} [remote]: 自动远程获取选项;默认为`false`;
+ {Boolean} [prohibitInput]: 输入数据无效时禁止输入;默认为`false`;
+ {Boolean} [hintShow]: 选中单元格时显示提示语;默认为`false`;
+ {String} [hintText]: 提示语文本;`hintShow`为`true`时需配置;
- {PlainObject} [setting]: 可选参数
+ {Array | Object | String} [range]: 数据验证的选区范围,支持选区的格式为`"A1:B2"`、`"sheetName!A1:B2"`或者`{row:[0,1],column:[0,1]}`,只能为单个选区;默认为当前选区
+ {Object | String} [range]: 数据验证的选区范围,支持选区的格式为`"A1:B2"`、`"sheetName!A1:B2"`或者`{row:[0,1],column:[0,1]}`,只能为单个选区;默认为当前选区
+ {Number} [order]: 工作表下标;默认值为当前工作表下标
+ {Function} [success]: 操作结束的回调函数
@ -2415,12 +2415,10 @@ Luckysheet针对常用的数据操作需求,开放了主要功能的API,开
### deleteDataVerification([setting])
[todo,待确认是否合理]
- **参数**
- {PlainObject} [setting]: 可选参数
+ {Array | Object | String} [range]: 数据验证的选区范围,支持选区的格式为`"A1:B2"`、`"sheetName!A1:B2"`或者`{row:[0,1],column:[0,1]}`,只能为单个选区;默认为当前选区
+ {Object | String} [range]: 数据验证的选区范围,支持选区的格式为`"A1:B2"`、`"sheetName!A1:B2"`或者`{row:[0,1],column:[0,1]}`,只能为单个选区;默认为当前选区
+ {Number} [order]: 工作表下标;默认值为当前工作表下标
+ {Function} [success]: 操作结束的回调函数

22
src/controllers/cellFormat.js

@ -6,6 +6,7 @@ import menuButton from './menuButton';
import {checkProtectionNotEnable} from './protection';
import { jfrefreshgrid } from '../global/refresh';
import locale from '../locale/locale';
import { setcellvalue } from '../global/setdata';
let isInitialCellFormatModel = false;
@ -22,9 +23,17 @@ function initialCellFormatModelEvent(){
hidden = hidden==true?1:0;
let d = recycleSeletion(
function(cell){
cell.lo = locked;
cell.hi = hidden;
function(cell, r, c, data){
if(cell==null){
setcellvalue(r, c, data, {
lo:locked,
hi:hidden
});
}
else{
cell.lo = locked;
cell.hi = hidden;
}
},
function(){
alert(local_cellFormat.sheetDataIsNullAlert);
@ -79,7 +88,8 @@ function recycleSeletion(cycleFunction, dataIsNullFunction){
// }
// count++;
cycleFunction(cell);
cycleFunction(cell, r, c, data);
}
}
}
@ -152,12 +162,12 @@ export function openCellFormatModel(){
recycleSeletion(
function(cell){
// let cell = data[r][c];
if(cell.lo==null || cell.lo==1){
if(cell==null || cell.lo==null || cell.lo==1){
locked = true;
lockedCount++;
}
if(cell.hi==1){
if(cell!=null && cell.hi==1){
hidden = true;
hiddenCount++;
}

64
src/controllers/imageCtrl.js

@ -97,19 +97,19 @@ const imageCtrl = {
let src = imgItem.src;
let imgItemParam = _this.getImgItemParam(imgItem);
let width = imgItemParam.width*Store.zoomRatio;
let height = imgItemParam.height*Store.zoomRatio;
let left = imgItemParam.left*Store.zoomRatio;
let top = imgItemParam.top*Store.zoomRatio;
let width = imgItemParam.width * Store.zoomRatio;
let height = imgItemParam.height * Store.zoomRatio;
let left = imgItemParam.left * Store.zoomRatio;
let top = imgItemParam.top * Store.zoomRatio;
let position = imgItemParam.position;
let borderWidth = imgItem.border.width;
return `<div id="${id}" class="luckysheet-modal-dialog luckysheet-modal-dialog-image" style="width:${width}px;height:${height}px;padding:0;position:${position};left:${left}px;top:${top}px;z-index:200;">
<div class="luckysheet-modal-dialog-content" style="width:100%;height:100%;overflow:hidden;position:relative;">
<img src="${src}" style="position:absolute;width:${imgItem.default.width*Store.zoomRatio}px;height:${imgItem.default.height*Store.zoomRatio}px;left:${-imgItem.crop.offsetLeft*Store.zoomRatio}px;top:${-imgItem.crop.offsetTop*Store.zoomRatio}px;" />
<img src="${src}" style="position:absolute;width:${imgItem.default.width * Store.zoomRatio}px;height:${imgItem.default.height * Store.zoomRatio}px;left:${-imgItem.crop.offsetLeft * Store.zoomRatio}px;top:${-imgItem.crop.offsetTop * Store.zoomRatio}px;" />
</div>
<div class="luckysheet-modal-dialog-border" style="border:${borderWidth}px ${imgItem.border.style} ${imgItem.border.color};border-radius:${imgItem.border.radius*Store.zoomRatio}px;position:absolute;left:${-borderWidth}px;right:${-borderWidth}px;top:${-borderWidth}px;bottom:${-borderWidth}px;"></div>
<div class="luckysheet-modal-dialog-border" style="border:${borderWidth}px ${imgItem.border.style} ${imgItem.border.color};border-radius:${imgItem.border.radius * Store.zoomRatio}px;position:absolute;left:${-borderWidth}px;right:${-borderWidth}px;top:${-borderWidth}px;bottom:${-borderWidth}px;"></div>
</div>`;
},
getSliderHtml: function() {
@ -354,10 +354,10 @@ const imageCtrl = {
let item = _this.images[id];
let imgItemParam = _this.getImgItemParam(item);
let width = imgItemParam.width*Store.zoomRatio;
let height = imgItemParam.height*Store.zoomRatio;
let left = imgItemParam.left*Store.zoomRatio;
let top = imgItemParam.top*Store.zoomRatio;
let width = imgItemParam.width * Store.zoomRatio;
let height = imgItemParam.height * Store.zoomRatio;
let left = imgItemParam.left * Store.zoomRatio;
let top = imgItemParam.top * Store.zoomRatio;
let position = imgItemParam.position;
$("#luckysheet-modal-dialog-activeImage").show().css({
@ -370,19 +370,19 @@ const imageCtrl = {
$("#luckysheet-modal-dialog-activeImage .luckysheet-modal-dialog-content").css({
"background-image": "url(" + item.src + ")",
"background-size": item.default.width*Store.zoomRatio + "px " + item.default.height*Store.zoomRatio + "px",
"background-position": -item.crop.offsetLeft*Store.zoomRatio + "px " + -item.crop.offsetTop*Store.zoomRatio + "px"
"background-size": item.default.width * Store.zoomRatio + "px " + item.default.height * Store.zoomRatio + "px",
"background-position": -item.crop.offsetLeft * Store.zoomRatio + "px " + -item.crop.offsetTop * Store.zoomRatio + "px"
})
$("#luckysheet-modal-dialog-activeImage .luckysheet-modal-dialog-border").css({
"border-width": item.border.width*Store.zoomRatio,
"border-width": item.border.width * Store.zoomRatio,
"border-style": item.border.style,
"border-color": item.border.color,
"border-radius": item.border.radius*Store.zoomRatio,
"left": -item.border.width*Store.zoomRatio,
"right": -item.border.width*Store.zoomRatio,
"top": -item.border.width*Store.zoomRatio,
"bottom": -item.border.width*Store.zoomRatio,
"border-radius": item.border.radius * Store.zoomRatio,
"left": -item.border.width * Store.zoomRatio,
"right": -item.border.width * Store.zoomRatio,
"top": -item.border.width * Store.zoomRatio,
"bottom": -item.border.width * Store.zoomRatio,
})
_this.sliderHtmlShow();
@ -591,10 +591,10 @@ const imageCtrl = {
let imgItem = _this.images[_this.currentImgId];
let imgItemParam = _this.getImgItemParam(imgItem);
let width = imgItemParam.width*Store.zoomRatio;
let height = imgItemParam.height*Store.zoomRatio;
let left = imgItemParam.left*Store.zoomRatio;
let top = imgItemParam.top*Store.zoomRatio;
let width = imgItemParam.width * Store.zoomRatio;
let height = imgItemParam.height * Store.zoomRatio;
let left = imgItemParam.left * Store.zoomRatio;
let top = imgItemParam.top * Store.zoomRatio;
let position = imgItemParam.position;
$("#" + _this.currentImgId).show().css({
@ -605,20 +605,20 @@ const imageCtrl = {
"position": position
});
$("#" + _this.currentImgId + " img").css({
"width": imgItem.default.width*Store.zoomRatio,
"height": imgItem.default.height*Store.zoomRatio,
"left": -imgItem.crop.offsetLeft*Store.zoomRatio,
"top": -imgItem.crop.offsetTop*Store.zoomRatio
"width": imgItem.default.width * Store.zoomRatio,
"height": imgItem.default.height * Store.zoomRatio,
"left": -imgItem.crop.offsetLeft * Store.zoomRatio,
"top": -imgItem.crop.offsetTop * Store.zoomRatio
});
$("#" + _this.currentImgId + " .luckysheet-modal-dialog-border").css({
"border-width": imgItem.border.width*Store.zoomRatio,
"border-width": imgItem.border.width * Store.zoomRatio,
"border-style": imgItem.border.style,
"border-color": imgItem.border.color,
"border-radius": imgItem.border.radius*Store.zoomRatio,
"left": -imgItem.border.width*Store.zoomRatio,
"right": -imgItem.border.width*Store.zoomRatio,
"top": -imgItem.border.width*Store.zoomRatio,
"bottom": -imgItem.border.width*Store.zoomRatio,
"border-radius": imgItem.border.radius * Store.zoomRatio,
"left": -imgItem.border.width * Store.zoomRatio,
"right": -imgItem.border.width * Store.zoomRatio,
"top": -imgItem.border.width * Store.zoomRatio,
"bottom": -imgItem.border.width * Store.zoomRatio,
})
_this.currentImgId = null;

50
src/controllers/postil.js

@ -208,18 +208,21 @@ const luckysheetPostil = {
let toX = col;
let toY = row_pre;
let fromX = toX + 18;
let fromY = toY - 18;
let fromX = toX + 18 * Store.zoomRatio;
let fromY = toY - 18 * Store.zoomRatio;
if(fromY < 0){
fromY = 2;
}
let width = _this.defaultWidth * Store.zoomRatio
let height = _this.defaultHeight * Store.zoomRatio
let size = _this.getArrowCanvasSize(fromX, fromY, toX, toY);
let html = '<div id="luckysheet-postil-overshow">' +
'<canvas class="arrowCanvas" width="'+ size[2] +'" height="'+ size[3] +'" style="position:absolute;left:'+ size[0] +'px;top:'+ size[1] +'px;z-index:100;pointer-events:none;"></canvas>' +
'<div style="width:132px;min-height:72px;color:#000;padding:5px;border:1px solid #000;background-color:rgb(255,255,225);position:absolute;left:'+ fromX +'px;top:'+ fromY +'px;z-index:100;">'+ value +'</div>' +
'<div style="width:'+ (width - 12) +'px;min-height:'+ (height - 12) +'px;color:#000;padding:5px;border:1px solid #000;background-color:rgb(255,255,225);position:absolute;left:'+ fromX +'px;top:'+ fromY +'px;z-index:100;">'+ value +'</div>' +
'</div>';
$(html).appendTo($("#luckysheet-cell-main"));
@ -349,10 +352,10 @@ const luckysheetPostil = {
let toX = col;
let toY = row_pre;
let left = postil["left"] == null ? toX + 18 : postil["left"];
let top = postil["top"] == null ? toY - 18 : postil["top"];
let width = postil["width"] == null ? _this.defaultWidth : postil["width"];
let height = postil["height"] == null ? _this.defaultHeight : postil["height"];
let left = postil["left"] == null ? toX + 18 * Store.zoomRatio : postil["left"] * Store.zoomRatio;
let top = postil["top"] == null ? toY - 18 * Store.zoomRatio : postil["top"] * Store.zoomRatio;
let width = postil["width"] == null ? _this.defaultWidth * Store.zoomRatio : postil["width"] * Store.zoomRatio;
let height = postil["height"] == null ? _this.defaultHeight * Store.zoomRatio : postil["height"] * Store.zoomRatio;
let value = postil["value"] == null ? "" : postil["value"];
if(top < 0){
@ -418,18 +421,21 @@ const luckysheetPostil = {
let toX = col;
let toY = row_pre;
let fromX = toX + 18;
let fromY = toY - 18;
let fromX = toX + 18 * Store.zoomRatio;
let fromY = toY - 18 * Store.zoomRatio;
if(fromY < 0){
fromY = 2;
}
let width = _this.defaultWidth * Store.zoomRatio;
let height = _this.defaultHeight * Store.zoomRatio;
let size = _this.getArrowCanvasSize(fromX, fromY, toX, toY);
let html = '<div id="luckysheet-postil-show_'+ r +'_'+ c +'" class="luckysheet-postil-show luckysheet-postil-show-active">' +
'<canvas class="arrowCanvas" width="'+ size[2] +'" height="'+ size[3] +'" style="position:absolute;left:'+ size[0] +'px;top:'+ size[1] +'px;z-index:100;pointer-events:none;"></canvas>' +
'<div class="luckysheet-postil-show-main" style="width:144px;height:84px;color:#000;padding:5px;border:1px solid #000;background-color:rgb(255,255,225);position:absolute;left:'+ fromX +'px;top:'+ fromY +'px;box-sizing:border-box;z-index:100;">' +
'<div class="luckysheet-postil-show-main" style="width:'+ width +'px;height:'+ height +'px;color:#000;padding:5px;border:1px solid #000;background-color:rgb(255,255,225);position:absolute;left:'+ fromX +'px;top:'+ fromY +'px;box-sizing:border-box;z-index:100;">' +
'<div class="luckysheet-postil-dialog-move">' +
'<div class="luckysheet-postil-dialog-move-item luckysheet-postil-dialog-move-item-t" data-type="t"></div>' +
'<div class="luckysheet-postil-dialog-move-item luckysheet-postil-dialog-move-item-r" data-type="r"></div>' +
@ -507,10 +513,10 @@ const luckysheetPostil = {
let toX = col;
let toY = row_pre;
let left = postil["left"] == null ? toX + 18 : postil["left"];
let top = postil["top"] == null ? toY - 18 : postil["top"];
let width = postil["width"] == null ? _this.defaultWidth : postil["width"];
let height = postil["height"] == null ? _this.defaultHeight : postil["height"];
let left = postil["left"] == null ? toX + 18 * Store.zoomRatio : postil["left"] * Store.zoomRatio;
let top = postil["top"] == null ? toY - 18 * Store.zoomRatio : postil["top"] * Store.zoomRatio;
let width = postil["width"] == null ? _this.defaultWidth * Store.zoomRatio : postil["width"] * Store.zoomRatio;
let height = postil["height"] == null ? _this.defaultHeight * Store.zoomRatio : postil["height"] * Store.zoomRatio;
let value = postil["value"] == null ? "" : postil["value"];
if(top < 0){
@ -609,10 +615,10 @@ const luckysheetPostil = {
let toX = col;
let toY = row_pre;
let left = postil["left"] == null ? toX + 18 : postil["left"];
let top = postil["top"] == null ? toY - 18 : postil["top"];
let width = postil["width"] == null ? _this.defaultWidth : postil["width"];
let height = postil["height"] == null ? _this.defaultHeight : postil["height"];
let left = postil["left"] == null ? toX + 18 * Store.zoomRatio : postil["left"] * Store.zoomRatio;
let top = postil["top"] == null ? toY - 18 * Store.zoomRatio : postil["top"] * Store.zoomRatio;
let width = postil["width"] == null ? _this.defaultWidth * Store.zoomRatio : postil["width"] * Store.zoomRatio;
let height = postil["height"] == null ? _this.defaultHeight * Store.zoomRatio : postil["height"] * Store.zoomRatio;
let value = postil["value"] == null ? "" : postil["value"];
if(top < 0){
@ -723,10 +729,10 @@ const luckysheetPostil = {
let toX = col;
let toY = row_pre;
let left = postil["left"] == null ? toX + 18 : postil["left"];
let top = postil["top"] == null ? toY - 18 : postil["top"];
let width = postil["width"] == null ? _this.defaultWidth : postil["width"];
let height = postil["height"] == null ? _this.defaultHeight : postil["height"];
let left = postil["left"] == null ? toX + 18 * Store.zoomRatio : postil["left"] * Store.zoomRatio;
let top = postil["top"] == null ? toY - 18 * Store.zoomRatio : postil["top"] * Store.zoomRatio;
let width = postil["width"] == null ? _this.defaultWidth * Store.zoomRatio : postil["width"] * Store.zoomRatio;
let height = postil["height"] == null ? _this.defaultHeight * Store.zoomRatio : postil["height"] * Store.zoomRatio;
let value = postil["value"] == null ? "" : postil["value"];
if(top < 0){

4
src/controllers/zoom.js

@ -5,6 +5,7 @@ import sheetmanage from './sheetmanage';
import {changeSheetContainerSize} from './resize';
import { jfrefreshgrid_rhcw } from '../global/refresh';
import server from './server';
import luckysheetPostil from './postil';
import imageCtrl from './imageCtrl';
@ -31,6 +32,9 @@ export function zoomChange(ratio){
let currentSheet = sheetmanage.getSheetByIndex();
//批注
luckysheetPostil.buildAllPs(currentSheet.data);
//图片
imageCtrl.images = currentSheet.images;
imageCtrl.allImagesShow();

447
src/global/api.js

@ -35,6 +35,8 @@ import { selectHightlightShow, selectIsOverlap } from '../controllers/select';
import { sheetHTML, luckysheetdefaultstyle } from '../controllers/constant';
import { createFilterOptions } from '../controllers/filter';
import controlHistory from '../controllers/controlHistory';
import { zoomRefreshView, zoomNumberDomBind } from '../controllers/zoom';
import dataVerificationCtrl from "../controllers/dataVerificationCtrl";
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;
@ -1176,6 +1178,113 @@ export function showColumn(startIndex, endIndex, options = {}) {
showRowOrColumn('column', startIndex, endIndex, options);
}
/**
* 设置指定行的高度
* @param {Object} rowInfo 行数和高度对应关系
* @param {Object} options 可选参数
* @param {Number} options.order 工作表索引默认值为当前工作表索引
* @param {Function} options.success 操作结束的回调函数
*/
export function setRowHeight(rowInfo, options = {}) {
if(getObjType(rowInfo) != 'object'){
return tooltip.info("The rowInfo parameter is invalid.", "");
}
let {
order = getSheetIndex(Store.currentSheetIndex),
success
} = {...options}
let file = Store.luckysheetfile[order];
if(file == null){
return tooltip.info("The order parameter is invalid.", "");
}
let cfg = $.extend(true, {}, file.config);
if(cfg['rowlen'] == null){
cfg['rowlen'] = {};
}
for(let r in rowInfo){
if(parseInt(r) >= 0){
let len = rowInfo[r];
if(Number(len) >= 0){
cfg['rowlen'][parseInt(r)] = Number(len);
}
}
}
file.config = cfg;
server.saveParam("cg", file.index, cfg["rowlen"], { "k": "rowlen" });
if(file.index == Store.currentSheetIndex){
Store.config = cfg;
jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length);
}
if (success && typeof success === 'function') {
success()
}
}
/**
* 设置指定列的宽度
* @param {Object} columnInfo 行数和高度对应关系
* @param {Object} options 可选参数
* @param {Number} options.order 工作表索引默认值为当前工作表索引
* @param {Function} options.success 操作结束的回调函数
*/
export function setColumnWidth(columnInfo, options = {}) {
if(getObjType(columnInfo) != 'object'){
return tooltip.info("The columnInfo parameter is invalid.", "");
}
let {
order = getSheetIndex(Store.currentSheetIndex),
success
} = {...options}
let file = Store.luckysheetfile[order];
if(file == null){
return tooltip.info("The order parameter is invalid.", "");
}
let cfg = $.extend(true, {}, file.config);
if(cfg['columnlen'] == null){
cfg['columnlen'] = {};
}
for(let c in columnInfo){
if(parseInt(c) >= 0){
let len = columnInfo[c];
if(Number(len) >= 0){
cfg['columnlen'][parseInt(c)] = Number(len);
}
}
}
file.config = cfg;
server.saveParam("cg", file.index, cfg["columnlen"], { "k": "columnlen" });
if(file.index == Store.currentSheetIndex){
Store.config = cfg;
jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length);
}
if (success && typeof success === 'function') {
success()
}
}
/**
* 返回当前选区对象的数组可能存在多个选区
* 每个选区的格式为row/column信息组成的对象{row:[0,1],column:[0,1]}
@ -4722,6 +4831,46 @@ export function setSheetOrder(orderList, options = {}) {
}
/**
* 设置工作表缩放比例
* @param {Number} zoom 工作表缩放比例值范围为0.1 ~ 4
* @param {Object} options 可选参数
* @param {Number} options.order 工作表下标默认值为当前工作表下标
* @param {Function} options.success 操作结束的回调函数
*/
export function setSheetZoom(zoom, options = {}) {
if(getObjType(zoom) != 'number' && (zoom < 0.1 || zoom > 4)){
return tooltip.info("The zoom parameter is invalid.", "");
}
let {
order = getSheetIndex(Store.currentSheetIndex),
success
} = {...options}
let file = Store.luckysheetfile[order];
if(file == null){
return tooltip.info("The order parameter is invalid.", "");
}
file["zoomRatio"] = zoom;
server.saveParam("all", file.index, zoom, { "k": "zoomRatio" });
if(file.index == Store.currentSheetIndex){
Store.zoomRatio = zoom;
zoomNumberDomBind();
zoomRefreshView();
}
if (success && typeof success === 'function') {
success();
}
}
/**
* 显示指定下标工作表的网格线返回操作的工作表对象
* @param {Object} options 可选参数
@ -5211,6 +5360,304 @@ export function getLuckysheetfile(){
return getluckysheetfile();
}
/**
* 指定工作表范围设置数据验证功能并设置参数
* @param {Object} optionItem 数据验证的配置信息
* @param {String} optionItem.type 类型
* @param {String | Null} optionItem.type2 条件类型
* @param {String | Number} optionItem.value1 条件值1
* @param {String | Number} optionItem.value2 条件值2
* @param {Boolean} optionItem.checked 选中状态
* @param {Boolean} optionItem.remote 自动远程获取选项
* @param {Boolean} optionItem.prohibitInput 输入数据无效时禁止输入
* @param {Boolean} optionItem.hintShow 选中单元格时显示提示语
* @param {String} optionItem.hintText 提示语文本
* @param {Object} options 可选参数
* @param {Array | Object | String} options.range 选区范围默认为当前选区
* @param {Number} options.order 工作表下标默认值为当前工作表下标
* @param {Function} options.success 操作结束的回调函数
*/
export function setDataVerification(optionItem, options = {}) {
if(getObjType(optionItem) != 'object'){
return tooltip.info("The optionItem parameter is invalid.", "");
}
let {
type,
type2 = null,
value1 = '',
value2 = '',
remote = false,
prohibitInput = false,
hintShow = false,
hintText = ''
} = {...optionItem}
let typeValues = ["dropdown", "checkbox", "number", "number_integer", "number_decimal", "text_content", "text_length", "date", "validity"];
let type2Values_1 = ["bw", "nb", "eq", "ne", "gt", "lt", "gte", "lte"];
let type2Values_2 = ["include", "exclude", "equal"];
let type2Values_3 = ["bw", "nb", "eq", "ne", "bf", "nbf", "af", "naf"];
let type2Values_4 = ["card", "phone"];
if(!typeValues.includes(type)){
return tooltip.info("The optionItem.type parameter is invalid.", "");
}
let dvText = locale().dataVerification;
if(type == 'dropdown'){
if(value1.length == 0){
tooltip.info('<i class="fa fa-exclamation-triangle"></i>', dvText.tooltipInfo1);
return;
}
}
else if(type == 'checkbox'){
if(value1.length == 0 || value2.length == 0){
tooltip.info('<i class="fa fa-exclamation-triangle"></i>', dvText.tooltipInfo2);
return;
}
}
else if(type == 'number' || type == 'number_integer' || type == 'number_decimal'){
if(!type2Values_1.includes(type2)){
return tooltip.info("The optionItem.type2 parameter is invalid.", "");
}
if(!isRealNum(value1)){
tooltip.info('<i class="fa fa-exclamation-triangle"></i>', dvText.tooltipInfo3);
return;
}
if(type2 == 'bw' || type2 == 'nb'){
if(!isRealNum(value2)){
tooltip.info('<i class="fa fa-exclamation-triangle"></i>', dvText.tooltipInfo3);
return;
}
if(Number(value2) < Number(value1)){
tooltip.info('<i class="fa fa-exclamation-triangle"></i>', dvText.tooltipInfo4);
return;
}
}
}
else if(type == 'text_content'){
if(!type2Values_2.includes(type2)){
return tooltip.info("The optionItem.type2 parameter is invalid.", "");
}
if(value1.length == 0){
tooltip.info('<i class="fa fa-exclamation-triangle"></i>', dvText.tooltipInfo5);
return;
}
}
else if(type == 'text_length'){
if(!type2Values_1.includes(type2)){
return tooltip.info("The optionItem.type2 parameter is invalid.", "");
}
if(!isRealNum(value1)){
tooltip.info('<i class="fa fa-exclamation-triangle"></i>', dvText.tooltipInfo3);
return;
}
if(type2 == 'bw' || type2 == 'nb'){
if(!isRealNum(value2)){
tooltip.info('<i class="fa fa-exclamation-triangle"></i>', dvText.tooltipInfo3);
return;
}
if(Number(value2) < Number(value1)){
tooltip.info('<i class="fa fa-exclamation-triangle"></i>', dvText.tooltipInfo4);
return;
}
}
}
else if(type == 'date'){
if(!type2Values_3.includes(type2)){
return tooltip.info("The optionItem.type2 parameter is invalid.", "");
}
if(!isdatetime(value1)){
tooltip.info('<i class="fa fa-exclamation-triangle"></i>', dvText.tooltipInfo6);
return;
}
if(type2 == 'bw' || type2 == 'nb'){
if(!isdatetime(value2)){
tooltip.info('<i class="fa fa-exclamation-triangle"></i>', dvText.tooltipInfo6);
return;
}
if(diff(value1, value2) > 0){
tooltip.info('<i class="fa fa-exclamation-triangle"></i>', dvText.tooltipInfo7);
return;
}
}
}
else if(type == 'validity'){
if(!type2Values_4.includes(type2)){
return tooltip.info("The optionItem.type2 parameter is invalid.", "");
}
}
if(getObjType(remote) != 'boolean'){
return tooltip.info("The optionItem.remote parameter is invalid.", "");
}
if(getObjType(prohibitInput) != 'boolean'){
return tooltip.info("The optionItem.prohibitInput parameter is invalid.", "");
}
if(getObjType(hintShow) != 'boolean'){
return tooltip.info("The optionItem.hintShow parameter is invalid.", "");
}
let {
range = Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1],
order = getSheetIndex(Store.currentSheetIndex),
success
} = {...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 file = Store.luckysheetfile[order];
if(file == null){
return tooltip.info("The order parameter is invalid.", "");
}
let item = {
type: type,
type2: type2,
value1: value1,
value2: value2,
checked: false,
remote: remote,
prohibitInput: prohibitInput,
hintShow: hintShow,
hintText: hintText,
}
let currentDataVerification = $.extend(true, {}, file.dataVerification);
let data = $.extend(true, [], file.data);
if(data.length == 0){
data = sheetmanage.buildGridData(file);
}
let str = range.row[0],
edr = range.row[1],
stc = range.column[0],
edc = range.column[1];
for(let r = str; r <= edr; r++){
for(let c = stc; c <= edc; c++){
currentDataVerification[r + '_' + c] = item;
if(type == 'checkbox'){
setcellvalue(r, c, data, item.value2);
}
}
}
if(file.index == Store.currentSheetIndex){
let historyDataVerification = $.extend(true, {}, file.dataVerification);
if(type == 'checkbox'){
dataVerificationCtrl.refOfCheckbox(historyDataVerification, currentDataVerification, Store.currentSheetIndex, data, range);
}
else{
dataVerificationCtrl.ref(historyDataVerification, currentDataVerification, Store.currentSheetIndex);
}
}
else{
file.dataVerification = currentDataVerification;
file.data = data;
}
if (success && typeof success === 'function') {
success();
}
}
/**
* 指定工作表范围删除数据验证功能
* @param {Object} options 可选参数
* @param {Array | Object | String} options.range 选区范围默认为当前选区
* @param {Number} options.order 工作表下标默认值为当前工作表下标
* @param {Function} options.success 操作结束的回调函数
*/
export function deleteDataVerification(options = {}) {
let {
range = Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1],
order = getSheetIndex(Store.currentSheetIndex),
success
} = {...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 file = Store.luckysheetfile[order];
if(file == null){
return tooltip.info("The order parameter is invalid.", "");
}
let currentDataVerification = $.extend(true, {}, file.dataVerification);
let str = range.row[0],
edr = range.row[1],
stc = range.column[0],
edc = range.column[1];
for(let r = str; r <= edr; r++){
for(let c = stc; c <= edc; c++){
delete currentDataVerification[r + '_' + c];
}
}
if(file.index == Store.currentSheetIndex){
let historyDataVerification = $.extend(true, {}, file.dataVerification);
dataVerificationCtrl.ref(historyDataVerification, currentDataVerification, Store.currentSheetIndex);
}
else{
file.dataVerification = currentDataVerification;
}
if (success && typeof success === 'function') {
success();
}
}
/**
* data => celldata data二维数组数据转化成 {r, c, v}格式一维数组
*

8
src/global/draw.js

@ -1112,7 +1112,7 @@ let nullCellRender = function(r, c, start_r, start_c, end_r, end_c,luckysheetTab
//若单元格有批注
if(Store.flowdata[r][c] != null && Store.flowdata[r][c].ps != null){
let ps_w = 5*Store.zoomRatio, ps_h = 5*Store.zoomRatio;
let ps_w = 8*Store.zoomRatio, ps_h = 8*Store.zoomRatio;
luckysheetTableContent.beginPath();
luckysheetTableContent.moveTo( (end_c + offsetLeft - 1- ps_w), (start_r + offsetTop));
luckysheetTableContent.lineTo( (end_c + offsetLeft - 1), (start_r + offsetTop));
@ -1338,17 +1338,17 @@ let cellRender = function(r, c, start_r, start_c, end_r, end_c, value, luckyshee
let verticalAlignPos_text = (pos_y + verticalCellHeight - space_height) ; //文本垂直方向基准线
luckysheetTableContent.textBaseline = "bottom";
let verticalAlignPos_checkbox = verticalAlignPos_text - 13;
let verticalAlignPos_checkbox = verticalAlignPos_text - 13 * Store.zoomRatio;
if(verticalAlign == "0"){ //居中对齐
verticalAlignPos_text = (pos_y + verticalCellHeight / 2);
luckysheetTableContent.textBaseline = "middle";
verticalAlignPos_checkbox = verticalAlignPos_text - 6;
verticalAlignPos_checkbox = verticalAlignPos_text - 6 * Store.zoomRatio;
}
else if(verticalAlign == "1"){ //上对齐
verticalAlignPos_text = (pos_y + space_height);
luckysheetTableContent.textBaseline = "top";
verticalAlignPos_checkbox = verticalAlignPos_text + 1;
verticalAlignPos_checkbox = verticalAlignPos_text + 1 * Store.zoomRatio;
}
horizonAlignPos = horizonAlignPos / Store.zoomRatio;

4
src/global/formula.js

@ -1238,7 +1238,7 @@ const luckysheetformula = {
}
if(!checkProtectionLocked(r, c, Store.currentSheetIndex)){
return
return;
}
//数据验证 输入数据无效时禁止输入
@ -5188,6 +5188,7 @@ const luckysheetformula = {
"r": u.r,
"c": u.c,
"v": v[1],
"f": v[2],
"spe":v[3],
"index": u.index
});
@ -5226,6 +5227,7 @@ const luckysheetformula = {
}
}
updateValue.v = item.v;
updateValue.f = item.f;
setcellvalue(item.r, item.c, data, updateValue);
server.saveParam("v", item.index, item.v, {
"r": item.r,

6
src/global/setdata.js

@ -22,9 +22,9 @@ function setcellvalue(r, c, d, v) {
if(v.f != null){
cell.f = v.f;
}
else{
delete cell.f;
}
// else{
// delete cell.f;
// }
if(v.spl != null){
cell.spl = v.spl;

Loading…
Cancel
Save