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

Commit

Permalink
feat(protection feature): protection feature similar to Excel
Browse files Browse the repository at this point in the history
fix some bug
  • Loading branch information
DR-Univer committed Oct 8, 2020
1 parent ade56d5 commit a71c92a
Show file tree
Hide file tree
Showing 33 changed files with 2,731 additions and 114 deletions.
3 changes: 2 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ const paths = {
'src/plugins/js/localforage.min.js',
'src/plugins/js/lodash.min.js',
'src/plugins/js/daterangepicker.js',
'src/plugins/js/jstat.min.js'
'src/plugins/js/jstat.min.js',
'src/plugins/js/crypto-api.min.js'
],

//plugins concat
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
"standard-version": "^8.0.2",
"vuepress": "^1.5.0"
},
"dependencies": {},
"dependencies": {
"jspdf": "^2.1.1"
},
"scripts": {
"build": "cross-env NODE_ENV=production gulp build",
"dev": "cross-env NODE_ENV=development gulp dev",
Expand Down
191 changes: 191 additions & 0 deletions src/controllers/cellFormat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
import Store from '../store';
import { replaceHtml,transformRangeToAbsolute,openSelfModel } from '../utils/util';
import { modelHTML } from './constant';
import sheetmanage from './sheetmanage';
import menuButton from './menuButton';
import {checkProtectionNotEnable} from './protection';
import { jfrefreshgrid } from '../global/refresh';
import locale from '../locale/locale';


let isInitialCellFormatModel = false;

function initialCellFormatModelEvent(){
const _locale = locale();
const local_cellFormat = _locale.cellFormat;

$("#luckysheet-cellFormat-confirm").click(function(){
let locked = $("#luckysheet-protection-check-locked").is(':checked');
let hidden = $("#luckysheet-protection-check-hidden").is(':checked');

locked = locked==true?1:0;
hidden = hidden==true?1:0;

let d = recycleSeletion(
function(cell){
cell.lo = locked;
cell.hi = hidden;
},
function(){
alert(local_cellFormat.sheetDataIsNullAlert);
}
);

jfrefreshgrid(d, undefined, undefined, false);

$("#luckysheet-cellFormat-config").hide();
$("#luckysheet-modal-dialog-mask").hide();
});
}

function recycleSeletion(cycleFunction, dataIsNullFunction){
if(Store.luckysheet_select_save != null && Store.luckysheet_select_save.length > 0){
let sheetFile = sheetmanage.getSheetByIndex(), data=sheetFile.data;
if(data!=null){

for(let i=0;i<Store.luckysheet_select_save.length;i++){
let selection = Store.luckysheet_select_save[i];
let row = selection.row, column = selection.column;
for(let r=row[0];r<=row[1];r++){
for(let c=column[0];c<=column[1];c++){
let cell;

let margeset = menuButton.mergeborer(data, r, c);
if (!!margeset) {
// row = margeset.row[1];
// row_pre = margeset.row[0];
let row_index = margeset.row[2];
// row_index_ed = margeset.row[3];

// col = margeset.column[1];
// col_pre = margeset.column[0];
let col_index = margeset.column[2];
// col_index_ed = margeset.column[3];

cell = data[row_index][col_index];
}
else{
cell = data[r][c];
}

// if(cell.lo==null || cell.lo==1){
// locked = true;
// lockedCount++;
// }

// if(cell.hi==1){
// hidden = true;
// hiddenCount++;
// }

// count++;
cycleFunction(cell);
}
}
}
}
else{
// locked = true;
dataIsNullFunction();
}

return data;
}
}

function initialCellFormatModel(){
if(isInitialCellFormatModel){
return;
}

isInitialCellFormatModel = true;
const _locale = locale();
const local_cellFormat = _locale.cellFormat;
const locale_button = _locale.button;

//Password input initial
$("body").append(replaceHtml(modelHTML, {
"id": "luckysheet-cellFormat-config",
"addclass": "luckysheet-cellFormat-config",
"title": local_cellFormat.cellFormatTitle,
"content": `
<div class="luckysheet-cellFormat-menu-c">
<div class="luckysheet-cellFormat-menu luckysheet-cellFormat-menu-active" id="luckysheet-cellFormat-protection">
${local_cellFormat.protection}
</div>
</div>
<div id="luckysheet-cellFormat-protection-content" class="luckysheet-cellFormat-content">
<div class="luckysheet-cellFormat-protection">
<p>
${local_cellFormat.protectionTips}
</p>
<label for="luckysheet-protection-check-locked"><input id="luckysheet-protection-check-locked" name="luckysheet-protection-check-locked" type="checkbox">${local_cellFormat.locked}</label><span>部分选中</span>
<br/>
<label for="luckysheet-protection-check-hidden"><input id="luckysheet-protection-check-hidden" name="luckysheet-protection-check-hidden" type="checkbox">${local_cellFormat.hidden}</label><span>全部选中</span>
</div>
</div>
`,
"botton": `<button id="luckysheet-cellFormat-confirm" class="btn btn-primary">${locale_button.confirm}</button>
<button class="btn btn-default luckysheet-model-close-btn">${locale_button.cancel}</button>`,
"style": "z-index:100003"
}));

initialCellFormatModelEvent();
}

export function openCellFormatModel(){
initialCellFormatModel();

const _locale = locale();
const local_cellFormat = _locale.cellFormat;
const locale_button = _locale.button;

$("#luckysheet-rightclick-menu").hide();

if(!checkProtectionNotEnable(Store.currentSheetIndex)){
return;
}

let locked =false, hidden=false;
let lockedCount=0, hiddenCount=0, count=0;
if(Store.luckysheet_select_save != null && Store.luckysheet_select_save.length > 0){
recycleSeletion(
function(cell){
// let cell = data[r][c];
if(cell.lo==null || cell.lo==1){
locked = true;
lockedCount++;
}

if(cell.hi==1){
hidden = true;
hiddenCount++;
}

count++;
},
function(){
locked = true;
}
);
}
else{
alert(local_cellFormat.selectionIsNullAlert);
return;
}

let tipsLock="", tipshidden="";
if(locked){
tipsLock = lockedCount==count?local_cellFormat.tipsAll:local_cellFormat.tipsPart;
}

if(hidden){
tipshidden = hiddenCount==count?local_cellFormat.tipsAll:local_cellFormat.tipsPart;
}

$("#luckysheet-protection-check-locked").prop('checked',locked).parent().next().html(tipsLock);
$("#luckysheet-protection-check-hidden").prop('checked',hidden).parent().next().html(tipshidden);


openSelfModel("luckysheet-cellFormat-config");
}
37 changes: 37 additions & 0 deletions src/controllers/conditionformat.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import server from './server';
import { selectionCopyShow } from './select';
import sheetmanage from './sheetmanage';
import locale from '../locale/locale';
import {checkProtectionFormatCells} from './protection';
import Store from '../store';

//条件格式
Expand Down Expand Up @@ -110,6 +111,10 @@ const conditionformat = {
});

$(document).off("click.CFadministerRuleConfirm").on("click.CFadministerRuleConfirm", "#luckysheet-administerRule-dialog-confirm", function(){
if(!checkProtectionFormatCells(Store.currentSheetIndex)){
return;
}

//保存之前的规则
let fileH = $.extend(true, [], Store.luckysheetfile);
let historyRules = _this.getHistoryRules(fileH);
Expand Down Expand Up @@ -221,6 +226,11 @@ const conditionformat = {

// 新建规则
$(document).off("click.CFnewConditionRule").on("click.CFnewConditionRule", "#newConditionRule", function(){
let sheetIndex = $("#luckysheet-administerRule-dialog .chooseSheet option:selected").val();
if(!checkProtectionFormatCells(sheetIndex)){
return;
}

if(Store.luckysheet_select_save.length == 0){
if(isEditMode()){
alert(conditionformat_Text.pleaseSelectRange);
Expand All @@ -234,6 +244,11 @@ const conditionformat = {
_this.newConditionRuleDialog(1);
});
$(document).off("click.CFnewConditionRuleConfirm").on("click.CFnewConditionRuleConfirm", "#luckysheet-newConditionRule-dialog-confirm", function(){

if(!checkProtectionFormatCells(Store.currentSheetIndex)){
return;
}

let index = $("#luckysheet-newConditionRule-dialog .ruleTypeItem.on").index();
let type1 = $("#luckysheet-newConditionRule-dialog #type1 option:selected").val();
let type2 = $("#luckysheet-newConditionRule-dialog ." + type1 + "Box #type2 option:selected").val();
Expand Down Expand Up @@ -586,7 +601,14 @@ const conditionformat = {

// 编辑规则
$(document).off("click.CFeditorConditionRule").on("click.CFeditorConditionRule", "#editorConditionRule", function(){

let sheetIndex = $("#luckysheet-administerRule-dialog .chooseSheet option:selected").val();

if(!checkProtectionFormatCells(sheetIndex)){
return;
}


let itemIndex = $("#luckysheet-administerRule-dialog .ruleList .listBox .item.on").attr("data-item");
let rule = {
"sheetIndex": sheetIndex,
Expand Down Expand Up @@ -979,13 +1001,23 @@ const conditionformat = {
// 删除规则
$(document).off("click.CFdeleteConditionRule").on("click.CFdeleteConditionRule", "#deleteConditionRule", function(){
let sheetIndex = $("#luckysheet-administerRule-dialog .chooseSheet option:selected").val();

if(!checkProtectionFormatCells(sheetIndex)){
return;
}

let itemIndex = $("#luckysheet-administerRule-dialog .ruleList .listBox .item.on").attr("data-item");
_this.fileClone[getSheetIndex(sheetIndex)]["luckysheet_conditionformat_save"].splice(itemIndex, 1);
_this.administerRuleDialog();
});

// 规则子菜单弹出层 点击确定修改样式
$(document).off("click.CFdefault").on("click.CFdefault", "#luckysheet-conditionformat-dialog-confirm", function(){

if(!checkProtectionFormatCells(Store.currentSheetIndex)){
return;
}

//条件名称
let conditionName = $("#luckysheet-conditionformat-dialog .box").attr("data-itemvalue");

Expand Down Expand Up @@ -1668,6 +1700,7 @@ const conditionformat = {
this.getConditionRuleList(index);
},
getConditionRuleList: function(index){

let _this = this;

$("#luckysheet-administerRule-dialog .ruleList .listBox").empty();
Expand Down Expand Up @@ -3636,6 +3669,10 @@ const conditionformat = {
return computeMap;
},
updateItem: function(type, cellrange, format){
if(!checkProtectionFormatCells(Store.currentSheetIndex)){
return;
}

let _this = this;
let index = getSheetIndex(Store.currentSheetIndex);

Expand Down
23 changes: 20 additions & 3 deletions src/controllers/constant.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/controllers/dropCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { jfrefreshgrid } from '../global/refresh';
import editor from '../global/editor';
import formula from '../global/formula';
import conditionformat from './conditionformat';
import {checkProtectionLockedRangeList} from './protection';
import { selectHightlightShow } from './select';
import { getSheetIndex } from '../methods/get';
import { getObjType, replaceHtml } from '../utils/util';
Expand Down Expand Up @@ -441,6 +442,10 @@ const luckysheetDropCell = {
update: function(){
let _this = this;

if(!checkProtectionLockedRangeList([_this.applyRange], Store.currentSheetIndex)){
return;
}

if(Store.allowEdit===false){
return;
}
Expand Down
Loading

0 comments on commit a71c92a

Please sign in to comment.