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

Commit

Permalink
feat(image insert): image insert
Browse files Browse the repository at this point in the history
image insert
  • Loading branch information
wpxp123456 committed Aug 28, 2020
1 parent 758d789 commit 4232dfc
Show file tree
Hide file tree
Showing 5 changed files with 728 additions and 5 deletions.
55 changes: 55 additions & 0 deletions src/controllers/constant.js

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

169 changes: 168 additions & 1 deletion src/controllers/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import luckysheetFreezen from './freezen';
import pivotTable from './pivotTable';
import luckysheetDropCell from './dropCell';
import luckysheetPostil from './postil';
import imageCtrl from './imageCtrl';
import menuButton from './menuButton';
import conditionformat from './conditionformat';
import alternateformat from './alternateformat';
Expand Down Expand Up @@ -1922,6 +1923,119 @@ export default function luckysheetHandler() {
// resize chart
Store.resizeChart(Store.chartparam.luckysheetCurrentChart)
}
//image move
else if (imageCtrl.move) {
let mouse = mouseposition(event.pageX, event.pageY);
let x = mouse[0] + $("#luckysheet-cell-main").scrollLeft();
let y = mouse[1] + $("#luckysheet-cell-main").scrollTop();

let myh = $("#luckysheet-modal-dialog-activeImage").outerHeight(),
myw = $("#luckysheet-modal-dialog-activeImage").outerWidth();

let top = y - imageCtrl.moveXY[1],
left = x - imageCtrl.moveXY[0];

if (top < 0) {
top = 0;
}

if (top + myh + 42 + 6 > imageCtrl.currentWinH) {
top = imageCtrl.currentWinH - myh - 42 - 6;
}

if (left < 0) {
left = 0;
}

if (left + myw + 22 + 36 > imageCtrl.currentWinW) {
left = imageCtrl.currentWinW - myw - 22 - 36;
}

$("#luckysheet-modal-dialog-activeImage").css({ "left": left, "top": top });
}
//image resize
else if (!!imageCtrl.resize) {
let mouse = mouseposition(event.pageX, event.pageY);
let x = mouse[0] + $("#luckysheet-cell-main").scrollLeft();
let y = mouse[1] + $("#luckysheet-cell-main").scrollTop();

if (x < 0 || y < 0) {
return false;
}

let resizeXY = imageCtrl.resizeXY;

let topchange = y - resizeXY[1],
leftchange = x - resizeXY[0];

let top = resizeXY[5],
height = resizeXY[3],
left = resizeXY[4],
width = resizeXY[2];

let resize = imageCtrl.resize;

if (resize == "lm" || resize == "lt" || resize == "lb") {
left = x;
width = resizeXY[2] - leftchange;

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

if (resize == "rm" || resize == "rt" || resize == "rb") {
width = resizeXY[2] + leftchange;

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

if (resize == "mt" || resize == "lt" || resize == "rt") {
top = y;
height = resizeXY[3] - topchange;

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

if (resize == "mb" || resize == "lb" || resize == "rb") {
height = resizeXY[3] + topchange;

if (height < 60) {
height = 60;
}
else if (height >= imageCtrl.currentWinH - resizeXY[5] - 42 - 6) {
height = imageCtrl.currentWinH - resizeXY[5] - 42 - 6;
}
}

$("#luckysheet-modal-dialog-activeImage").css({
"width": width,
"height": height,
"left": left,
"top": top
});
$("#luckysheet-modal-dialog-activeImage .luckysheet-modal-dialog-content").css({
"background-size": width + "px " + height + "px",
"background-position": "0px 0px"
})
}
else if (luckysheetPostil.move) {
let mouse = mouseposition(event.pageX, event.pageY);
let x = mouse[0] + $("#luckysheet-cell-main").scrollLeft();
Expand Down Expand Up @@ -2029,7 +2143,8 @@ export default function luckysheetHandler() {
}
else if (!!formula.rangeMove) {
formula.rangeMoveDraging(event, formula.rangeMovexy, formula.rangeMoveObj.data("range"), formula.rangeMoveObj, Store.sheetBarHeight, Store.statisticBarHeight);
} else if (!!Store.chart_selection.rangeResize) {
}
else if (!!Store.chart_selection.rangeResize) {
Store.chart_selection.rangeResizeDraging(event, Store.sheetBarHeight, Store.statisticBarHeight);
}
else if (!!Store.chart_selection.rangeMove) {
Expand Down Expand Up @@ -2208,6 +2323,16 @@ export default function luckysheetHandler() {
formula.rangeResizeDragged(event, formula.rangeResizeObj, formula.rangeResize, formula.rangeResizexy, formula.rangeResizeWinW, formula.rangeResizeWinH);
}

//image move
if (imageCtrl.move) {
imageCtrl.moveImgItem();
}

//image resize
if (imageCtrl.resize) {
imageCtrl.resizeImgItem();
}

//批注框 移动
if (luckysheetPostil.move) {
luckysheetPostil.move = false;
Expand Down Expand Up @@ -3414,6 +3539,48 @@ export default function luckysheetHandler() {
splitColumn.init();
});

//菜单栏 插入图片按钮
$("#luckysheet-insertImg-btn-title").click(function () {
$("#luckysheet-imgUpload").click();
});
$("#luckysheet-imgUpload").click(function (e) {
e.stopPropagation();
});
$("#luckysheet-imgUpload").on("change", function(e){
let file = e.currentTarget.files[0];
let render = new FileReader();
render.readAsDataURL(file);

render.onload = function(event){
let src = event.target.result;

let rowIndex = Store.luckysheet_select_save[0].row_focus;
let colIndex = Store.luckysheet_select_save[0].column_focus;
let left = colIndex == 0 ? 0 : Store.visibledatacolumn[colIndex - 1];
let top = rowIndex == 0 ? 0 : Store.visibledatarow[rowIndex - 1];

let image = new Image();
image.onload = function(){
let width = image.width,
height = image.height;

let img = {
src: src,
left: left,
top: top,
originWidth: width,
originHeight: height
}

imageCtrl.addImgItem(img);
$("#luckysheet-imgUpload").val("");
}
image.src = src;
}
});



//冻结行列
$("#luckysheet-freezen-btn-horizontal").click(function () {
if ($.trim($(this).text()) == locale().freezen.freezenCancel) {
Expand Down
Loading

0 comments on commit 4232dfc

Please sign in to comment.