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

新增特性,修复bug #1384

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/controllers/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -5516,10 +5516,10 @@ export default function luckysheetHandler() {
// *如果禁止前台编辑,则中止下一步操作
if (!checkIsAllowEdit()) {
tooltip.info("", locale().pivotTable.errorNotAllowEdit);
return;
}
if (!checkProtectionNotEnable(Store.currentSheetIndex)) {
return;
return;
}

hyperlinkCtrl.createDialog();
Expand Down
26 changes: 25 additions & 1 deletion src/controllers/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getSheetIndex, getRangetxt } from '../methods/get';
import Store from '../store';
import method from '../global/method';
import locale from '../locale/locale';
import { refreshMenuButtonFocus } from "../global/api";
import { refreshMenuButtonFocus, getRangesByTxt, checkRangeWithinSpecifiedRange } from "../global/api";

//公式函数 选区实体框
function seletedHighlistByindex(id, r1, r2, c1, c2) {
Expand Down Expand Up @@ -184,6 +184,9 @@ function selectHightlightShow(isRestore = false) {

/* 刷新当前状态栏 */
refreshMenuButtonFocus();

// 刷新上方工具栏状态(不在允许输入范围内,工具栏不可用)
refreshToolbar()
}

Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)].luckysheet_select_save = Store.luckysheet_select_save;
Expand All @@ -197,6 +200,27 @@ function selectHightlightShow(isRestore = false) {
Store.luckysheet_select_save_previous = luckysheet_select_save_previous;
}

// 刷新工具栏
function refreshToolbar() {
if (!Store.config?.authority?.allowRangeList || Store.config?.authority?.allowRangeList?.length === 0) {
return
}
const currentAllowedRange = []
Store.config?.authority?.allowRangeList?.forEach((range) => {
const allowRange = getRangesByTxt(range.sqref);
currentAllowedRange.push(...(allowRange || []))
})
// 检查修改区域是否是保护区域内 如果是不能修改
const hasDisabled = $('#luckysheet-wa-editor').hasClass('disabled')
const within = checkRangeWithinSpecifiedRange(Store.luckysheet_select_save, currentAllowedRange);
if (!within) {
!hasDisabled && $('#luckysheet-wa-editor').addClass('disabled')
} else {
hasDisabled && $('#luckysheet-wa-editor').removeClass('disabled')
}

}

//选区标题栏
function selectTitlesShow(rangeArr, isRestore = false) {
let s = $.extend(true, [], rangeArr);
Expand Down
9 changes: 9 additions & 0 deletions src/css/luckysheet-core.css
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,15 @@
transition: all 0.2s;
}

.luckysheet-wa-editor.disabled>:not(#luckysheet-icon-undo):not(#luckysheet-icon-redo) {
cursor: not-allowed;
pointer-events: none;
opacity: 0.6;
filter: alpha(opacity=60);
-webkit-box-shadow: none;
box-shadow: none;
}

/*
.luckysheet-wa-editor>div.luckysheetfulltoolbar {
display: inline-block;
Expand Down
98 changes: 89 additions & 9 deletions src/global/api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Store from "../store";
import { replaceHtml, getObjType, chatatABC, luckysheetactiveCell } from "../utils/util";
import { replaceHtml, getObjType, chatatABC, luckysheetactiveCell, getRangeDetailInfoArr, getRangeDetailInfo } from "../utils/util";
import { getSheetIndex, getluckysheet_select_save, getluckysheetfile } from "../methods/get";
import locale from "../locale/locale";
import method from './method';
Expand Down Expand Up @@ -31,8 +31,8 @@ import luckysheetsizeauto from '../controllers/resize';
import sheetmanage from '../controllers/sheetmanage';
import conditionformat from '../controllers/conditionformat';
import { luckysheet_searcharray } from "../controllers/sheetSearch";
import { selectHightlightShow, selectIsOverlap } from '../controllers/select';
import { sheetHTML, luckysheetdefaultstyle } from '../controllers/constant';
import { selectHightlightShow, selectIsOverlap, selectionCopyShow } from '../controllers/select';
import { sheetHTML, luckysheetdefaultstyle, modelHTML } from '../controllers/constant';
import { createFilterOptions } from '../controllers/filter';
import controlHistory from '../controllers/controlHistory';
import { zoomRefreshView, zoomNumberDomBind } from '../controllers/zoom';
Expand Down Expand Up @@ -5929,13 +5929,14 @@ export function getAllChartsBase64(cb) {
chartMap[item.index] = {}
item.chart.forEach((chartInfo) => {
const chartDom = document.querySelector(`#${chartInfo.chart_id}`);
const chartInstance = echarts.getInstanceByDom(chartDom);
chartInstance.resize({width:chartInfo.width,height: chartInfo.height,animation: {
duration: 0
}})
if (chartDom) {
const chartInstance = echarts.getInstanceByDom(chartDom);
chartInstance.resize({width:chartInfo.width,height: chartInfo.height,animation: {
duration: 0
}})

chartMap[item.index][chartInfo.chart_id] = chartInstance

chartMap[item.index][chartInfo.chart_id] = chartInstance
}
});

}
Expand Down Expand Up @@ -6788,6 +6789,15 @@ export function getRangeByTxt(txt){
};
}

/**
* 根据范围字符串转换为range数组
* @param {String} txt 范围字符串
*/
export function getRangesByTxt(txt){
const range = conditionformat.getRangeByTxt(txt);
return range;
}


/**
* 根据范围数组转换为范围字符串
Expand Down Expand Up @@ -6949,3 +6959,73 @@ export function openSearchDialog(source = 1){
luckysheetSearchReplace.init();
$("#luckysheet-search-replace #searchInput input").focus();
}

export function getCurrentSheetIndex(){
return Store.currentSheetIndex
}

/**
* 展示选区
* @param {Array | Object | String} range 选区范围
*/
export function showSelectionCopy (range) {
selectionCopyShow(range)
}

/**
* 检查某一单元格是否在指定区域内
* @param {Number} r 单元格所在行
* @param {Number} c 单元格所在列
* @param {Array} specifiedRange 指定区域
*/
export function checkCellWithinSpecifiedRange(r, c, specifiedRange) {
let within = false
if (!specifiedRange || specifiedRange.length === 0) {
return false
}
for(let item of specifiedRange){
let r1 = item.row[0], r2 = item.row[1];
let c1 = item.column[0], c2 = item.column[1];

if(r>=r1 && r<=r2 && c>=c1 && c<=c2){
within = true;
break;
}
}
return within
}

/**
* 检查range是否在指定区域内
* @param {Array} range 需要检查的区域
* @param {Array} specifiedRange 指定区域
*/
export function checkRangeWithinSpecifiedRange(range = [], specifiedRange = []) {
if (!specifiedRange || specifiedRange.length === 0) {
return false
}
if (!range || range.length === 0) {
return false
}

for(let item of range){
let r1 = item.row[0], r2 = item.row[1];
let c1 = item.column[0], c2 = item.column[1];

for(let r=r1;r<=r2;r++){
for(let c=c1;c<=c2;c++){
const within = checkCellWithinSpecifiedRange(r, c , specifiedRange);
if(!within){
return false;
}
}
}
}
return true

}

export {
getRangeDetailInfoArr,
getRangeDetailInfo
}
3 changes: 2 additions & 1 deletion src/global/formula.js
Original file line number Diff line number Diff line change
Expand Up @@ -5980,7 +5980,8 @@ const luckysheetformula = {
}

if (!_this.testFunction(txt, fp) || fp == "") {
tooltip.info("", locale_formulaMore.execfunctionError);
const file = Store.luckysheetfile[getSheetIndex(index)];
tooltip.info("", `${locale_formulaMore.execfunctionError}: ${file.name}>${chatatABC(c)}${r + 1}>${txt}`);
return [false, _this.error.n, txt];
}

Expand Down
45 changes: 45 additions & 0 deletions src/utils/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,49 @@ function camel2split(camel) {
});
}

/**
* 根据range(只包含row column坐标) 转换为range的详细内容(除坐标 还有宽高 偏移量等)
* @param {Object} range 由getRangeByTxt方法返回{column, row}
*/
function getRangeDetailInfo(range) {
let r1 = range.row[0], r2 = range.row[1];
let c1 = range.column[0], c2 = range.column[1];
let row = Store.visibledatarow[r2],
row_pre = r1 - 1 == -1 ? 0 : Store.visibledatarow[r1 - 1];
let col = Store.visibledatacolumn[c2],
col_pre = c1 - 1 == -1 ? 0 : Store.visibledatacolumn[c1 - 1];

return {
"left": col_pre,
"width": col - col_pre - 1,
"top": row_pre,
"height": row - row_pre - 1,
"left_move": col_pre,
"width_move": col - col_pre - 1,
"top_move": row_pre,
"height_move": row - row_pre - 1,
"row": [r1, r2],
"column": [c1, c2],
"row_focus": r1,
"column_focus": c1
}
}

/**
* 根据range数组,转换为range的详细内容数组
* @param {Array} rangeArr 由getRangesByTxt方法返回[{column, row}]
*/
function getRangeDetailInfoArr(rangeArr) {
const result = []
if(rangeArr.length > 0){
for(let s = 0; s < rangeArr.length; s++){
const detail = getRangeDetailInfo(rangeArr[s])
result.push(detail)
}
}
return result
}

export {
isJsonString,
common_extend,
Expand Down Expand Up @@ -917,4 +960,6 @@ export {
createProxy,
arrayRemoveItem,
camel2split,
getRangeDetailInfo,
getRangeDetailInfoArr,
};