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

Commit

Permalink
fix(fix allowedit): fix allowEdit attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
tubiaoge committed Jul 30, 2020
1 parent 69aee1a commit 35820b3
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/controllers/dropCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,10 @@ const luckysheetDropCell = {
update: function(){
let _this = this;

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

let d = editor.deepCopyFlowData(Store.flowdata);
let file = Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)];

Expand Down
4 changes: 2 additions & 2 deletions src/controllers/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2667,7 +2667,7 @@ export default function luckysheetHandler() {

//选区拖动替换
$("#luckysheet-cell-main div.luckysheet-cs-draghandle").mousedown(function (event) {
if(isEditMode()){//此模式下禁用选区拖动
if(isEditMode() || Store.allowEdit===false){//此模式下禁用选区拖动
return;
}

Expand Down Expand Up @@ -2709,7 +2709,7 @@ export default function luckysheetHandler() {

//选区下拉
$("#luckysheet-cell-main div.luckysheet-cs-fillhandle").mousedown(function (event) {
if(isEditMode()){//此模式下禁用选区下拉
if(isEditMode() || Store.allowEdit===false){//此模式下禁用选区下拉
return;
}

Expand Down
4 changes: 4 additions & 0 deletions src/controllers/menuButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -2781,6 +2781,10 @@ const menuButton = {
updateFormat: function(d, attr, foucsStatus){
let _this = this;

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

let canvasElement = document.createElement('canvas');
let canvas = canvasElement.getContext("2d");

Expand Down
3 changes: 3 additions & 0 deletions src/controllers/pivotTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,9 @@ const pivotTable = {
}
},
createPivotTable: function (e) {
if(isEditMode() || Store.allowEdit===false){
return;
}
let _this = this;

let datasheetindex = Store.currentSheetIndex;
Expand Down
12 changes: 12 additions & 0 deletions src/controllers/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ const selection = {
clipboardData = e.originalEvent.clipboardData;
}



Store.luckysheet_selection_range = [];
//copy范围
let minR = Store.luckysheet_select_save[0].row[0],
Expand Down Expand Up @@ -549,6 +551,10 @@ const selection = {
paste: function (e, triggerType) {//paste事件
let _this = this;

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

let textarea = $("#luckysheet-copy-content");
textarea.focus();
textarea.select();
Expand Down Expand Up @@ -581,6 +587,9 @@ const selection = {
}, 10);
},
pasteHandler: function (data, borderInfo) {
if(Store.allowEdit===false){
return;
}
if(Store.luckysheet_select_save.length > 1){
if(isEditMode()){
alert("不能对多重选择区域执行此操作,请选择单个区域,然后再试");
Expand Down Expand Up @@ -791,6 +800,9 @@ const selection = {
}
},
pasteHandlerOfCutPaste: function(copyRange){
if(Store.allowEdit===false){
return;
}
let cfg = $.extend(true, {}, Store.config);
if(cfg["merge"] == null){
cfg["merge"] = {};
Expand Down
9 changes: 9 additions & 0 deletions src/controllers/sheetBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ export function initialSheetBar(){
});

let luckysheetsheetnameeditor = function ($t) {
if(Store.allowEdit===false){
return;
}
$t.attr("contenteditable", "true").addClass("luckysheet-mousedown-cancel").data("oldtxt", $t.text());

setTimeout(function () {
Expand All @@ -221,6 +224,9 @@ export function initialSheetBar(){
});

$("#luckysheet-sheet-area").on("blur", "span.luckysheet-sheets-item-name", function (e) {
if(Store.allowEdit===false){
return;
}
let $t = $(this);
let txt = $t.text(), oldtxt = $t.data("oldtxt");

Expand Down Expand Up @@ -269,6 +275,9 @@ export function initialSheetBar(){
});

$("#luckysheet-sheet-area").on("keydown", "span.luckysheet-sheets-item-name", function (e) {
if(Store.allowEdit===false){
return;
}
let kcode = e.keyCode;
let $t = $(this);
if (kcode == keycode.ENTER) {
Expand Down
8 changes: 6 additions & 2 deletions src/controllers/sheetmanage.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ const sheetmanage = {
return Store.currentSheetIndex;
},
addNewSheet: function(e, isPivotTable) {
if(isEditMode()){
if(isEditMode() || Store.allowEdit===false){
// alert("非编辑模式下不允许该操作!");
return;
}
Expand Down Expand Up @@ -352,7 +352,7 @@ const sheetmanage = {
}, 1)
},
copySheet: function(copyindex, e) {
if(isEditMode()){
if(isEditMode() || Store.allowEdit===false){
// alert("非编辑模式下不允许该操作!");
return;
}
Expand Down Expand Up @@ -460,6 +460,10 @@ const sheetmanage = {
deleteSheet: function(index) {
let _this = this;

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

let arrIndex = _this.getSheetIndex(index);
_this.setSheetHide(index);

Expand Down
2 changes: 1 addition & 1 deletion src/controllers/updateCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import cleargridelement from '../global/cleargridelement';
import Store from '../store';

export default function luckysheetupdateCell(row, row_pre, row_index, col, col_pre, col_index, d, cover, isnotfocus) {
if(isEditMode()){//此模式下禁用单元格编辑
if(isEditMode() || Store.allowEdit===false){//此模式下禁用单元格编辑
return;
}

Expand Down
5 changes: 3 additions & 2 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ luckysheet.create = function (setting) {
Store.fullscreenmode = extendsetting.fullscreenmode;
Store.lang = extendsetting.lang; //language
Store.allowEdit = extendsetting.allowEdit;

Store.editMode = extendsetting.editMode;

server.gridKey = extendsetting.gridKey;
server.loadUrl = extendsetting.loadUrl;
server.updateUrl = extendsetting.updateUrl;
Expand Down Expand Up @@ -82,7 +83,7 @@ luckysheet.create = function (setting) {
luckysheetConfigsetting.enablePage = extendsetting.enablePage;
luckysheetConfigsetting.pageInfo = extendsetting.pageInfo;

luckysheetConfigsetting.editMode = extendsetting.editMode;

luckysheetConfigsetting.chartConfigChange = extendsetting.chartConfigChange;
luckysheetConfigsetting.beforeCreateDom = extendsetting.beforeCreateDom;

Expand Down
2 changes: 1 addition & 1 deletion src/global/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function hasChinaword(s) {

//是否为非编辑模式
function isEditMode() {
if(luckysheetConfigsetting.editMode){
if(Store.editMode){
return true;
}
else{
Expand Down
1 change: 1 addition & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
luckysheet.create({
container: 'luckysheet',
lang: 'en',
allowEdit:true,
plugins: ['chart'],
data: [sheetCell,sheetFormula,sheetConditionFormat,sheetTable,sheetSparkline,sheetComment,sheetPivotTableData,sheetPivotTable]
})
Expand Down

0 comments on commit 35820b3

Please sign in to comment.