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

Commit

Permalink
fix(image): resize and change row or column size
Browse files Browse the repository at this point in the history
  • Loading branch information
wpxp123456 committed Oct 10, 2020
1 parent e0e7f94 commit 05c49a2
Show file tree
Hide file tree
Showing 3 changed files with 252 additions and 30 deletions.
160 changes: 143 additions & 17 deletions src/controllers/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2356,17 +2356,24 @@ export default function luckysheetHandler() {

width = resizeXY[4] - resizeXY[6] + resizeXY[2] - left;

top = resizeXY[5] - resizeXY[7] + topchange;
height = Math.round(width * (resizeXY[3] / resizeXY[2]));
top = resizeXY[5] - resizeXY[7] + resizeXY[3] - height;

if(top < minTop){
top = minTop;
height = resizeXY[5] - resizeXY[7] + resizeXY[3] - top;

width = Math.round(height * (resizeXY[2] / resizeXY[3]));
left = resizeXY[4] - resizeXY[6] + resizeXY[2] - width;
}

if(top > resizeXY[5] - resizeXY[7] + resizeXY[3] - 1){
top = resizeXY[5] - resizeXY[7] + resizeXY[3] - 1;
}
height = resizeXY[5] - resizeXY[7] + resizeXY[3] - top;

height = resizeXY[5] - resizeXY[7] + resizeXY[3] - top;
width = Math.round(height * (resizeXY[2] / resizeXY[3]));
left = resizeXY[4] - resizeXY[6] + resizeXY[2] - width;
}
}
else if(resize == 'lm'){//左中
left = resizeXY[4] - resizeXY[6] + leftchange;
Expand Down Expand Up @@ -2397,16 +2404,22 @@ export default function luckysheetHandler() {

width = resizeXY[4] - resizeXY[6] + resizeXY[2] - left;

top = resizeXY[5] - resizeXY[7];
height = Math.round(width * (resizeXY[3] / resizeXY[2]));

height = resizeXY[3] + topchange;
top = resizeXY[5] - resizeXY[7];

if(height < 1){
height = 1;

width = Math.round(height * (resizeXY[2] / resizeXY[3]));
left = resizeXY[4] - resizeXY[6] + resizeXY[2] - width;
}

if(height > minTop + Store.cellmainHeight - Store.cellMainSrollBarSize - top){
height = minTop + Store.cellmainHeight - Store.cellMainSrollBarSize - top;

width = Math.round(height * (resizeXY[2] / resizeXY[3]));
left = resizeXY[4] - resizeXY[6] + resizeXY[2] - width;
}
}
else if(resize == 'rt'){//右上
Expand All @@ -2422,17 +2435,22 @@ export default function luckysheetHandler() {
width = minLeft + Store.cellmainWidth - Store.cellMainSrollBarSize - left;
}

top = resizeXY[5] - resizeXY[7] + topchange;
height = Math.round(width * (resizeXY[3] / resizeXY[2]));
top = resizeXY[5] - resizeXY[7] + resizeXY[3] - height;

if(top < minTop){
top = minTop;
height = resizeXY[5] - resizeXY[7] + resizeXY[3] - top;

width = Math.round(height * (resizeXY[2] / resizeXY[3]));
}

if(top > resizeXY[5] - resizeXY[7] + resizeXY[3] - 1){
top = resizeXY[5] - resizeXY[7] + resizeXY[3] - 1;
}
height = resizeXY[5] - resizeXY[7] + resizeXY[3] - top;

height = resizeXY[5] - resizeXY[7] + resizeXY[3] - top;
width = Math.round(height * (resizeXY[2] / resizeXY[3]));
}
}
else if(resize == 'rm'){//右中
left = resizeXY[4] - resizeXY[6];
Expand Down Expand Up @@ -2463,16 +2481,19 @@ export default function luckysheetHandler() {
width = minLeft + Store.cellmainWidth - Store.cellMainSrollBarSize - left;
}

height = Math.round(width * (resizeXY[3] / resizeXY[2]));
top = resizeXY[5] - resizeXY[7];

height = resizeXY[3] + topchange;

if(height < 1){
height = 1;

width = Math.round(height * (resizeXY[2] / resizeXY[3]));
}

if(height > minTop + Store.cellmainHeight - Store.cellMainSrollBarSize - top){
height = minTop + Store.cellmainHeight - Store.cellMainSrollBarSize - top;

width = Math.round(height * (resizeXY[2] / resizeXY[3]));
}
}
else if(resize == 'mt'){//中上
Expand Down Expand Up @@ -2509,21 +2530,105 @@ export default function luckysheetHandler() {
}
}
else{
if (resize == "lm" || resize == "lt" || resize == "lb") {
if(resize == 'lt'){//左上
left = x;
width = resizeXY[2] - leftchange;

if (left > resizeXY[2] + resizeXY[4] - 1) {
left = resizeXY[2] + resizeXY[4] - 1;
width = resizeXY[2] + resizeXY[0] - (resizeXY[2] + resizeXY[4] - 1);
}
else if (left <= 0) {
left = 0;
width = resizeXY[2] + resizeXY[0];
}

height = Math.round(width * (resizeXY[3] / resizeXY[2]));
top = resizeXY[3] + resizeXY[1] - height;

if (top > resizeXY[3] + resizeXY[5] - 1) {
top = resizeXY[3] + resizeXY[5] - 1;
height = resizeXY[3] + resizeXY[1] - (resizeXY[3] + resizeXY[5] - 1);

width = Math.round(height * (resizeXY[2] / resizeXY[3]));
left = resizeXY[2] + resizeXY[0] - width;
}
else if (top <= 0) {
top = 0;
height = resizeXY[3] + resizeXY[1];

width = Math.round(height * (resizeXY[2] / resizeXY[3]));
left = resizeXY[2] + resizeXY[0] - width;
}
}
else if(resize == 'lm'){//左中
left = x;
width = resizeXY[2] - leftchange;

if (left > resizeXY[2] + resizeXY[4] - 1) {
left = resizeXY[2] + resizeXY[4] - 1;
width = resizeXY[2] + resizeXY[0] - (resizeXY[2] + resizeXY[4] - 1);
}
else if (left <= 0) {
left = 0;
width = resizeXY[2] + resizeXY[0];
}
}
else if(resize == 'lb'){//左下
left = x;
width = resizeXY[2] - leftchange;

if (left > resizeXY[2] + resizeXY[4] - 1) {
left = resizeXY[2] + resizeXY[4] - 1;
width = resizeXY[2] - (resizeXY[2] + resizeXY[4] - 1 - resizeXY[0]);
width = resizeXY[2] + resizeXY[0] - (resizeXY[2] + resizeXY[4] - 1);
}
else if (left <= 0) {
left = 0;
width = resizeXY[2] + resizeXY[0];
}

height = Math.round(width * (resizeXY[3] / resizeXY[2]));

if (height < 1) {
height = 1;

width = Math.round(height * (resizeXY[2] / resizeXY[3]));
left = resizeXY[2] + resizeXY[0] - width;
}
else if (height >= imageCtrl.currentWinH - resizeXY[5] - 42 - 6) {
height = imageCtrl.currentWinH - resizeXY[5] - 42 - 6;

width = Math.round(height * (resizeXY[2] / resizeXY[3]));
left = resizeXY[2] + resizeXY[0] - width;
}
}
else if(resize == 'rt'){//右上
width = resizeXY[2] + leftchange;

if (resize == "rm" || resize == "rt" || resize == "rb") {
if (width < 1) {
width = 1;
}
else if (width >= imageCtrl.currentWinW - resizeXY[4] - 22 - 36) {
width = imageCtrl.currentWinW - resizeXY[4] - 22 - 36;
}

height = Math.round(width * (resizeXY[3] / resizeXY[2]));
top = resizeXY[3] + resizeXY[1] - height;

if (top > resizeXY[3] + resizeXY[5] - 1) {
top = resizeXY[3] + resizeXY[5] - 1;
height = resizeXY[3] + resizeXY[1] - (resizeXY[3] + resizeXY[5] - 1);

width = Math.round(height * (resizeXY[2] / resizeXY[3]));
}
else if (top <= 0) {
top = 0;
height = resizeXY[3] + resizeXY[1];

width = Math.round(height * (resizeXY[2] / resizeXY[3]));
}
}
else if(resize == 'rm'){//右中
width = resizeXY[2] + leftchange;

if (width < 1) {
Expand All @@ -2533,22 +2638,43 @@ export default function luckysheetHandler() {
width = imageCtrl.currentWinW - resizeXY[4] - 22 - 36;
}
}
else if(resize == 'rb'){//右下
width = resizeXY[2] + leftchange;

if (width < 1) {
width = 1;
}
else if (width >= imageCtrl.currentWinW - resizeXY[4] - 22 - 36) {
width = imageCtrl.currentWinW - resizeXY[4] - 22 - 36;
}

height = Math.round(width * (resizeXY[3] / resizeXY[2]));

if (resize == "mt" || resize == "lt" || resize == "rt") {
if (height < 1) {
height = 1;

width = Math.round(height * (resizeXY[2] / resizeXY[3]));
}
else if (height >= imageCtrl.currentWinH - resizeXY[5] - 42 - 6) {
height = imageCtrl.currentWinH - resizeXY[5] - 42 - 6;

width = Math.round(height * (resizeXY[2] / resizeXY[3]));
}
}
else if(resize == 'mt'){//中上
top = y;
height = resizeXY[3] - topchange;

if (top > resizeXY[3] + resizeXY[5] - 1) {
top = resizeXY[3] + resizeXY[5] - 1;
height = resizeXY[3] - (resizeXY[3] + resizeXY[5] - 1 - resizeXY[1]);
height = resizeXY[3] + resizeXY[1] - (resizeXY[3] + resizeXY[5] - 1);
}
else if (top <= 0) {
top = 0;
height = resizeXY[3] + resizeXY[1];
}
}

if (resize == "mb" || resize == "lb" || resize == "rb") {
else if(resize == 'mb'){//中下
height = resizeXY[3] + topchange;

if (height < 1) {
Expand Down
15 changes: 14 additions & 1 deletion src/controllers/rowColumnOperation.js
Original file line number Diff line number Diff line change
Expand Up @@ -1696,6 +1696,7 @@ export function rowColumnOperationInitial(){

let cfg = $.extend(true, {}, Store.config);
let type;
let images = null;

if(Store.luckysheetRightHeadClickIs == "row"){
if(!checkProtectionAuthorityNormal(Store.currentSheetIndex, "formatRows")){
Expand Down Expand Up @@ -1724,6 +1725,8 @@ export function rowColumnOperationInitial(){

for(let r = r1; r <= r2; r++){
cfg["rowlen"][r] = size;

images = imageCtrl.moveChangeSize("row", r, size);
}
}
}
Expand Down Expand Up @@ -1754,6 +1757,8 @@ export function rowColumnOperationInitial(){

for(let c = c1; c <= c2; c++){
cfg["columnlen"][c] = size;

images = imageCtrl.moveChangeSize("column", c, size);
}
}
}
Expand All @@ -1763,16 +1768,24 @@ export function rowColumnOperationInitial(){
Store.jfredo.push({
"type": "resize",
"ctrlType": type,
"sheetIndex": Store.currentSheetIndex,
"config": $.extend(true, {}, Store.config),
"curconfig": $.extend(true, {}, cfg),
"sheetIndex": Store.currentSheetIndex
"images": $.extend(true, {}, imageCtrl.images),
"curImages": $.extend(true, {}, images)
});
}

//config
Store.config = cfg;
Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)].config = Store.config;

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

if(Store.luckysheetRightHeadClickIs == "row"){
server.saveParam("cg", Store.currentSheetIndex, cfg["rowlen"], { "k": "rowlen" });
jfrefreshgrid_rhcw(Store.flowdata.length, null);
Expand Down
Loading

0 comments on commit 05c49a2

Please sign in to comment.