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

Commit

Permalink
feat(insert image perfect): insert image perfect
Browse files Browse the repository at this point in the history
insert image perfect
wpxp123456 committed Sep 7, 2020

Verified

This commit was signed with the committer’s verified signature.
primeos Michael Weiss
1 parent 2be467d commit ad0a88a
Showing 3 changed files with 165 additions and 9 deletions.
12 changes: 12 additions & 0 deletions src/controllers/controlHistory.js
Original file line number Diff line number Diff line change
@@ -114,6 +114,12 @@ const controlHistory = {
server.saveParam("cg", ctr.sheetIndex, ctr.config["columnlen"], { "k": "columnlen" });
}

let images = $.extend(true, {}, ctr.images);
Store.luckysheetfile[getSheetIndex(ctr.sheetIndex)].images = images;
server.saveParam("all", ctr.sheetIndex, images, { "k": "images" });
imageCtrl.images = images;
imageCtrl.allImagesShow();

jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length);
}
else if (ctr.type == "cellRowChange") {
@@ -389,6 +395,12 @@ const controlHistory = {
server.saveParam("cg", ctr.sheetIndex, ctr.curconfig["columnlen"], { "k": "columnlen" });
}

let images = $.extend(true, {}, ctr.curImages);
Store.luckysheetfile[getSheetIndex(ctr.sheetIndex)].images = images;
server.saveParam("all", ctr.sheetIndex, images, { "k": "images" });
imageCtrl.images = images;
imageCtrl.allImagesShow();

jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length);
}
else if (ctr.type == "cellRowChange") {
24 changes: 22 additions & 2 deletions src/controllers/handler.js
Original file line number Diff line number Diff line change
@@ -2911,15 +2911,19 @@ export default function luckysheetHandler() {

cfg["rowlen"][Store.luckysheet_rows_change_size_start[1]] = Math.ceil(size/Store.zoomRatio);

let images = imageCtrl.moveChangeSize("row", Store.luckysheet_rows_change_size_start[1], size);

if (Store.clearjfundo) {
Store.jfundo = [];

Store.jfredo.push({
"type": "resize",
"ctrlType": "resizeR",
"sheetIndex": Store.currentSheetIndex,
"config": $.extend(true, {}, Store.config),
"curconfig": $.extend(true, {}, cfg),
"sheetIndex": Store.currentSheetIndex
"images": $.extend(true, {}, imageCtrl.images),
"curImages": $.extend(true, {}, images)
});
}

@@ -2929,6 +2933,12 @@ export default function luckysheetHandler() {

server.saveParam("cg", Store.currentSheetIndex, cfg["rowlen"], { "k": "rowlen" });

//images
Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)].images = images;
server.saveParam("all", Store.currentSheetIndex, images, { "k": "images" });
imageCtrl.images = images;
imageCtrl.allImagesShow();

jfrefreshgrid_rhcw(Store.flowdata.length, null);
}

@@ -2977,15 +2987,19 @@ export default function luckysheetHandler() {

cfg["columnlen"][Store.luckysheet_cols_change_size_start[1]] = Math.ceil(size/Store.zoomRatio);

let images = imageCtrl.moveChangeSize("column", Store.luckysheet_cols_change_size_start[1], size);

if (Store.clearjfundo) {
Store.jfundo = [];

Store.jfredo.push({
"type": "resize",
"ctrlType": "resizeC",
"sheetIndex": Store.currentSheetIndex,
"config": $.extend(true, {}, Store.config),
"curconfig": $.extend(true, {}, cfg),
"sheetIndex": Store.currentSheetIndex
"images": $.extend(true, {}, imageCtrl.images),
"curImages": $.extend(true, {}, images)
});
}

@@ -2995,6 +3009,12 @@ export default function luckysheetHandler() {

server.saveParam("cg", Store.currentSheetIndex, cfg["columnlen"], { "k": "columnlen" });

//images
Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)].images = images;
server.saveParam("all", Store.currentSheetIndex, images, { "k": "images" });
imageCtrl.images = images;
imageCtrl.allImagesShow();

jfrefreshgrid_rhcw(null, Store.flowdata[0].length);

setTimeout(function () {
138 changes: 131 additions & 7 deletions src/controllers/imageCtrl.js
Original file line number Diff line number Diff line change
@@ -461,12 +461,17 @@ const imageCtrl = {
e.stopPropagation();
})

//image restore
$("#luckysheet-image-showBoxs").off("mousedown.restore").on("mousedown.restore", ".luckysheet-modal-controll-restore", function(e) {
_this.restoreImgItem();
e.stopPropagation();
})

//image delete
$("#luckysheet-image-showBoxs").off("mousedown.delete").on("mousedown.delete", ".luckysheet-modal-controll-del", function(e) {
_this.removeImgItem();
e.stopPropagation();
})

},
configChange: function(type, value){
let _this = this;
@@ -777,6 +782,42 @@ const imageCtrl = {

_this.ref();
},
restoreImgItem: function() {
let _this = this;
let imgItem = _this.images[_this.currentImgId];

imgItem.default.width = imgItem.originWidth;
imgItem.default.height = imgItem.originHeight;

imgItem.crop.width = imgItem.originWidth;
imgItem.crop.height = imgItem.originHeight;
imgItem.crop.offsetLeft = 0;
imgItem.crop.offsetTop = 0;

let imgItemParam = _this.getImgItemParam(imgItem);

let width = imgItemParam.width;
let height = imgItemParam.height;
let left = imgItemParam.left;
let top = imgItemParam.top;
let position = imgItemParam.position;

$("#luckysheet-modal-dialog-activeImage").show().css({
"width": width,
"height": height,
"left": left,
"top": top,
"position": position
});

$("#luckysheet-modal-dialog-activeImage .luckysheet-modal-dialog-content").css({
"background-image": "url(" + imgItem.src + ")",
"background-size": imgItem.default.width + "px " + imgItem.default.height + "px",
"background-position": -imgItem.crop.offsetLeft + "px " + -imgItem.crop.offsetTop + "px"
})

_this.ref();
},
removeImgItem: function() {
let _this = this;

@@ -808,19 +849,71 @@ const imageCtrl = {
$("#luckysheet-image-showBoxs .img-list").append(modelHtml);
}
},
moveChangeSize: function(rc, index, changeSize) {
moveChangeSize: function(rc, index, size) {
let _this = this;
let images = $.extend(true, {}, _this.images);

if(rc == "row"){
let row = Store.visibledatarow[index],
row_pre = index - 1 == -1 ? 0 : Store.visibledatarow[index - 1];
let changeSize = size - (row - row_pre - 1);


for(let imgId in images){
let imgItem = images[imgId];
let imgItemParam = _this.getImgItemParam(imgItem);
let type = imgItem.type;

if(type == "1"){
if(imgItemParam.top >= row){
imgItem.default.top = imgItemParam.top + changeSize - imgItem.crop.offsetTop;
}
else{
if(imgItemParam.top + imgItemParam.height > row){
if(imgItemParam.top < row + changeSize){
let scaleY = (imgItemParam.height + changeSize) / imgItemParam.height;
imgItem.default.height = Math.round(imgItem.default.height * scaleY);
imgItem.crop.height = Math.round(imgItem.crop.height * scaleY);
imgItem.crop.offsetTop = Math.round(imgItem.crop.offsetTop * scaleY);
}
else{
let scaleY = (imgItemParam.top + imgItemParam.height - row) / imgItemParam.height;
imgItem.default.height = Math.round(imgItem.default.height * scaleY);
imgItem.crop.height = Math.round(imgItem.crop.height * scaleY);
imgItem.crop.offsetTop = Math.round(imgItem.crop.offsetTop * scaleY);
imgItem.default.top = row + changeSize - imgItem.crop.offsetTop;
}
}
else{
if(imgItemParam.top > row + changeSize){
let scaleY = 1 / imgItemParam.height;
imgItem.default.height = Math.round(imgItem.default.height * scaleY);
imgItem.crop.height = Math.round(imgItem.crop.height * scaleY);
imgItem.crop.offsetTop = Math.round(imgItem.crop.offsetTop * scaleY);
imgItem.default.top = row + changeSize - imgItem.crop.offsetTop;
}
else if(imgItemParam.top + imgItemParam.height > row + changeSize){
let scaleY = (row + changeSize - imgItemParam.top) / imgItemParam.height;
imgItem.default.height = Math.round(imgItem.default.height * scaleY);
imgItem.crop.height = Math.round(imgItem.crop.height * scaleY);
imgItem.crop.offsetTop = Math.round(imgItem.crop.offsetTop * scaleY);
}
}
}
}
else if(type == "2"){
if(imgItemParam.top >= row){
imgItem.default.top = imgItemParam.top + changeSize - imgItem.crop.offsetTop;
}
else if(imgItemParam.top > row + changeSize){
imgItem.default.top = row + changeSize - imgItem.crop.offsetTop;
}
}
}
}
else if(rc == "column"){
let col = Store.visibledatacolumn[index],
col_pre = index - 1 == -1 ? 0 : Store.visibledatacolumn[index - 1];
let changeSize = size - (col - col_pre - 1);

for(let imgId in images){
let imgItem = images[imgId];
@@ -829,22 +922,53 @@ const imageCtrl = {

if(type == "1"){
if(imgItemParam.left >= col){
imgItem.default.left = imgItemParam.left + changeSize - item.crop.offsetLeft;
imgItem.default.left = imgItemParam.left + changeSize - imgItem.crop.offsetLeft;
}
else{
if(imgItemParam.left + imgItemParam.width > col){
let scaleX = obj.clientWidth / item.crop.width;
if(imgItemParam.left < col + changeSize){
let scaleX = (imgItemParam.width + changeSize) / imgItemParam.width;
imgItem.default.width = Math.round(imgItem.default.width * scaleX);
imgItem.crop.width = Math.round(imgItem.crop.width * scaleX);
imgItem.crop.offsetLeft = Math.round(imgItem.crop.offsetLeft * scaleX);
}
else{
let scaleX = (imgItemParam.left + imgItemParam.width - col) / imgItemParam.width;
imgItem.default.width = Math.round(imgItem.default.width * scaleX);
imgItem.crop.width = Math.round(imgItem.crop.width * scaleX);
imgItem.crop.offsetLeft = Math.round(imgItem.crop.offsetLeft * scaleX);
imgItem.default.left = col + changeSize - imgItem.crop.offsetLeft;
}
}
else{

if(imgItemParam.left > col + changeSize){
let scaleX = 1 / imgItemParam.width;
imgItem.default.width = Math.round(imgItem.default.width * scaleX);
imgItem.crop.width = Math.round(imgItem.crop.width * scaleX);
imgItem.crop.offsetLeft = Math.round(imgItem.crop.offsetLeft * scaleX);
imgItem.default.left = col + changeSize - imgItem.crop.offsetLeft;
}
else if(imgItemParam.left + imgItemParam.width > col + changeSize){
let scaleX = (col + changeSize - imgItemParam.left) / imgItemParam.width;
imgItem.default.width = Math.round(imgItem.default.width * scaleX);
imgItem.crop.width = Math.round(imgItem.crop.width * scaleX);
imgItem.crop.offsetLeft = Math.round(imgItem.crop.offsetLeft * scaleX);
}
}
}
}
else if(type == "2"){

if(imgItemParam.left >= col){
imgItem.default.left = imgItemParam.left + changeSize - imgItem.crop.offsetLeft;
}
else if(imgItemParam.left > col + changeSize){
imgItem.default.left = col + changeSize - imgItem.crop.offsetLeft;
}
}
}
}

return images;
},
ref: function() {
let _this = this;

0 comments on commit ad0a88a

Please sign in to comment.