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

Commit

Permalink
Merge pull request #430 from ZCF1024/zcf
Browse files Browse the repository at this point in the history
图表拖动时鼠标高亮效果
  • Loading branch information
mengshukeji committed Jan 6, 2021
2 parents 7f6ea99 + 9f72f37 commit c17f69a
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 1 deletion.
45 changes: 45 additions & 0 deletions src/controllers/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -1465,12 +1465,57 @@ export default function luckysheetHandler() {
imageCtrl.inserImg(src);
}
}
handleCellDragStopEvent(e);
}, false);
document.getElementById('luckysheet-cell-main').addEventListener('dragover', function(e){
e.preventDefault();
e.stopPropagation();
}, false);

/**
* 处理单元格上鼠标拖拽停止事件
* @param {DragEvent} event
*/
function handleCellDragStopEvent(event) {
if (luckysheetConfigsetting && luckysheetConfigsetting.hook && luckysheetConfigsetting.hook.cellDragStop) {
let mouse = mouseposition(event.pageX, event.pageY);
let x = mouse[0] + $("#luckysheet-cell-main").scrollLeft();
let y = mouse[1] + $("#luckysheet-cell-main").scrollTop();

let row_location = rowLocation(y),
row = row_location[1],
row_pre = row_location[0],
row_index = row_location[2];
let col_location = colLocation(x),
col = col_location[1],
col_pre = col_location[0],
col_index = col_location[2];

let margeset = menuButton.mergeborer(Store.flowdata, row_index, col_index);
if (!!margeset) {
row = margeset.row[1];
row_pre = margeset.row[0];
row_index = margeset.row[2];

col = margeset.column[1];
col_pre = margeset.column[0];
col_index = margeset.column[2];
}

let sheetFile = sheetmanage.getSheetByIndex();

let luckysheetTableContent = $("#luckysheetTableContent").get(0).getContext("2d");
method.createHookFunction("cellDragStop", Store.flowdata[row_index][col_index], {
r: row_index,
c: col_index,
"start_r": row_pre,
"start_c": col_pre,
"end_r": row,
"end_c": col
}, sheetFile, luckysheetTableContent, event);
}
}

//表格mousemove
$(document).on("mousemove.luckysheetEvent",function (event) {
luckysheetPostil.overshow(event); //有批注显示
Expand Down
4 changes: 4 additions & 0 deletions src/css/luckysheet-core.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
user-select: none;
}

.chart-moveable{
cursor: move;
}

.luckysheet {
position: absolute;
/* width: 100%;
Expand Down
24 changes: 23 additions & 1 deletion src/expendPlugins/chart/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { rowLocation, colLocation, mouseposition } from '../../global/location'
import { setluckysheet_scroll_status } from '../../methods/set'
import {
luckysheetMoveHighlightCell,
luckysheetMoveHighlightCell2,
luckysheetMoveHighlightCell2,
luckysheetMoveHighlightRange,
luckysheetMoveHighlightRange2,
luckysheetMoveEndCell
Expand Down Expand Up @@ -132,6 +132,8 @@ function renderCharts(chartLists, isDemo) {
})
).appendTo($('.luckysheet-cell-main'))

setChartMoveableEffect($t);

$(`#${chart_id_c}`).children('.luckysheet-modal-dialog-content')[0].id = chart_id

let container = document.getElementById(chart_id_c)
Expand Down Expand Up @@ -1217,6 +1219,8 @@ function createLuckyChart(width, height, left, top) {
delChart(chart_id)
})

setChartMoveableEffect($t);

// edit current chart
$(`#${chart_id}_c .luckysheet-modal-controll-update`).click(function (e) {
showChartSettingComponent()
Expand Down Expand Up @@ -1329,6 +1333,24 @@ function createLuckyChart(width, height, left, top) {
})
}

/**
* 设置图表可拖动区域高亮效果,鼠标经过可拖动区域时鼠标显示“十字”,不可拖动区域显示箭头
* @param {JQuery} $container 图表的容器DIV
*/
function setChartMoveableEffect($container) {
$container.find('.luckysheet-modal-dialog-content').hover(function () {
$container.removeClass("chart-moveable");
}, function () {
$container.addClass("chart-moveable");
});

$container.hover(function () {
$container.addClass("chart-moveable");
}, function () {
$container.removeClass("chart-moveable");
});
}

// delete chart
function delChart(chart_id) {
// delete container
Expand Down
3 changes: 3 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@
}
],
hook:{
cellDragStop: function (cell, postion, sheetFile, moveState, ctx, event) {
console.info(cell, postion, sheetFile, ctx, event);
},
rowTitleCellRenderBefore:function(rowNum,postion,ctx){
// console.log(rowNum);
},
Expand Down

0 comments on commit c17f69a

Please sign in to comment.