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

Commit

Permalink
feat(hyperlink): perfect hyperlink function
Browse files Browse the repository at this point in the history
n
  • Loading branch information
wpxp123456 committed Oct 29, 2020
1 parent 8cfa6ac commit 5adfc60
Show file tree
Hide file tree
Showing 5 changed files with 246 additions and 17 deletions.
18 changes: 12 additions & 6 deletions src/controllers/controlHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ const controlHistory = {
ctr.cf,
ctr.af,
ctr.freezen,
ctr.dataVerification
ctr.dataVerification,
ctr.hyperlink
);
}
else if (ctr.type == "delRC") { //删除行列撤销操作
Expand All @@ -185,7 +186,8 @@ const controlHistory = {
ctr.cf,
ctr.af,
ctr.freezen,
ctr.dataVerification
ctr.dataVerification,
ctr.hyperlink
);
}
else if (ctr.type == "deleteCell") { //删除单元格撤销操作
Expand All @@ -196,7 +198,8 @@ const controlHistory = {
ctr.calc,
ctr.filterObj,
ctr.cf,
ctr.dataVerification
ctr.dataVerification,
ctr.hyperlink
);
}
else if (ctr.type == "showHidRows") { // 隐藏、显示行 撤销操作
Expand Down Expand Up @@ -497,7 +500,8 @@ const controlHistory = {
ctr.curCf,
ctr.curAf,
ctr.curFreezen,
ctr.curDataVerification
ctr.curDataVerification,
ctr.curHyperlink
);
}
else if (ctr.type == "delRC") { //删除行列重做操作
Expand All @@ -511,7 +515,8 @@ const controlHistory = {
ctr.curCf,
ctr.curAf,
ctr.curFreezen,
ctr.curDataVerification
ctr.curDataVerification,
ctr.curHyperlink
);
}
else if (ctr.type == "deleteCell") { //删除单元格重做操作
Expand All @@ -522,7 +527,8 @@ const controlHistory = {
ctr.curCalc,
ctr.curFilterObj,
ctr.curCf,
ctr.curDataVerification
ctr.curDataVerification,
ctr.curHyperlink
);
}
else if (ctr.type == "showHidRows") { // 隐藏、显示行 重做操作
Expand Down
10 changes: 7 additions & 3 deletions src/controllers/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,6 @@ export default function luckysheetHandler() {
//数据验证 单元格聚焦
dataVerificationCtrl.cellFocus(row_index, col_index, true);

//链接 单元格聚焦
hyperlinkCtrl.cellFocus(row_index, col_index);

//若点击单元格部分不在视图内
if (col_pre < $("#luckysheet-cell-main").scrollLeft()) {
$("#luckysheet-scrollbar-x").scrollLeft(col_pre);
Expand Down Expand Up @@ -377,6 +374,12 @@ export default function luckysheetHandler() {
}
}

//链接 单元格聚焦
if(hyperlinkCtrl.hyperlink && hyperlinkCtrl.hyperlink[row_index + "_" + col_index] && event.which != "3"){
hyperlinkCtrl.cellFocus(row_index, col_index);
return;
}

Store.luckysheet_scroll_status = true;

//公式相关
Expand Down Expand Up @@ -1346,6 +1349,7 @@ export default function luckysheetHandler() {
//表格mousemove
$(document).on("mousemove.luckysheetEvent",function (event) {
luckysheetPostil.overshow(event); //有批注显示
hyperlinkCtrl.overshow(event); //链接提示显示

window.cancelAnimationFrame(Store.jfautoscrollTimeout);

Expand Down
98 changes: 97 additions & 1 deletion src/controllers/hyperlinkCtrl.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { replaceHtml } from '../utils/util';
import { getcellvalue } from '../global/getdata';
import { luckysheetrefreshgrid } from '../global/refresh';
import { rowLocation, colLocation, mouseposition } from '../global/location';
import formula from '../global/formula';
import tooltip from '../global/tooltip';
import editor from '../global/editor';
import { modelHTML } from './constant';
import { selectHightlightShow } from './select';
import server from './server';
import sheetmanage from './sheetmanage';
import luckysheetFreezen from './freezen';
import menuButton from './menuButton';
import { getSheetIndex } from '../methods/get';
import locale from '../locale/locale';
import Store from '../store';
Expand Down Expand Up @@ -224,7 +229,98 @@ const hyperlinkCtrl = {
return;
}


let item = _this.hyperlink[r + '_' + c];

if(item.linkType == 'external'){
window.open(item.linkAddress);
}
else{
let cellrange = formula.getcellrange(item.linkAddress);
let sheetIndex = cellrange.sheetIndex;
let range = [{
row: cellrange.row,
column: cellrange.column
}];

if(sheetIndex != Store.currentSheetIndex){
$("#luckysheet-sheet-area div.luckysheet-sheets-item").removeClass("luckysheet-sheets-item-active");
$("#luckysheet-sheets-item" + sheetIndex).addClass("luckysheet-sheets-item-active");

sheetmanage.changeSheet(sheetIndex);
}

Store.luckysheet_select_save = range;
selectHightlightShow(true);

let row_pre = cellrange.row[0] - 1 == -1 ? 0 : Store.visibledatarow[cellrange.row[0] - 1];
let col_pre = cellrange.column[0] - 1 == -1 ? 0 : Store.visibledatacolumn[cellrange.column[0] - 1];

$("#luckysheet-scrollbar-x").scrollLeft(col_pre);
$("#luckysheet-scrollbar-y").scrollTop(row_pre);
}
},
overshow: function(event){
let _this = this;

$("#luckysheet-hyperlink-overshow").remove();

if($(event.target).closest("#luckysheet-cell-main").length == 0){
return;
}

let mouse = mouseposition(event.pageX, event.pageY);
let scrollLeft = $("#luckysheet-cell-main").scrollLeft();
let scrollTop = $("#luckysheet-cell-main").scrollTop();
let x = mouse[0] + scrollLeft;
let y = mouse[1] + scrollTop;

if(luckysheetFreezen.freezenverticaldata != null && mouse[0] < (luckysheetFreezen.freezenverticaldata[0] - luckysheetFreezen.freezenverticaldata[2])){
return;
}

if(luckysheetFreezen.freezenhorizontaldata != null && mouse[1] < (luckysheetFreezen.freezenhorizontaldata[0] - luckysheetFreezen.freezenhorizontaldata[2])){
return;
}

let row_index = rowLocation(y)[2];
let col_index = colLocation(x)[2];

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

if(_this.hyperlink == null || _this.hyperlink[row_index + "_" + col_index] == null){
return;
}

let item = _this.hyperlink[row_index + "_" + col_index];
let linkTooltip = item.linkTooltip;

if(linkTooltip == null || linkTooltip.replace(/\s/g, '') == ''){
linkTooltip = item.linkAddress;
}

let row = Store.visibledatarow[row_index],
row_pre = row_index - 1 == -1 ? 0 : Store.visibledatarow[row_index - 1];
let col = Store.visibledatacolumn[col_index],
col_pre = col_index - 1 == -1 ? 0 : Store.visibledatacolumn[col_index - 1];

if(!!margeset){
row = margeset.row[1];
row_pre = margeset.row[0];

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

let html = `<div id="luckysheet-hyperlink-overshow" style="background:#fff;padding:5px 10px;border:1px solid #000;box-shadow:2px 2px #999;position:absolute;left:${col_pre}px;top:${row + 5}px;z-index:100;">
<div>${linkTooltip}</div>
<div>单击鼠标可以追踪</div>
</div>`;

$(html).appendTo($("#luckysheet-cell-main"));
},
ref: function(historyHyperlink, currentHyperlink, sheetIndex, d, range){
let _this = this;
Expand Down
114 changes: 111 additions & 3 deletions src/global/extend.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,50 @@ function luckysheetextendtable(type, index, value, direction, sheetIndex) {
}
}

//超链接配置变动
let hyperlink = file.hyperlink;
let newHyperlink = {};
if(hyperlink != null){
for(let key in hyperlink){
let r = Number(key.split('_')[0]),
c = Number(key.split('_')[1]);
let item = hyperlink[key];

if(type == "row"){
if(index < r){
newHyperlink[(r + value) + "_" + c] = item;
}
else if(index == r){
if(direction == "lefttop"){
newHyperlink[(r + value) + "_" + c] = item;
}
else{
newHyperlink[r + "_" + c] = item;
}
}
else{
newHyperlink[r + "_" + c] = item;
}
}
else if(type == "column"){
if(index < c){
newHyperlink[r + "_" + (c + value)] = item;
}
else if(index == c){
if(direction == "lefttop"){
newHyperlink[r + "_" + (c + value)] = item;
}
else{
newHyperlink[r + "_" + c] = item;
}
}
else{
newHyperlink[r + "_" + c] = item;
}
}
}
}

let type1;
if (type == "row") {
type1 = "r";
Expand Down Expand Up @@ -845,7 +889,8 @@ function luckysheetextendtable(type, index, value, direction, sheetIndex) {
newCFarr,
newAFarr,
newFreezen,
newDataVerification
newDataVerification,
newHyperlink
);
}
else{
Expand All @@ -857,6 +902,7 @@ function luckysheetextendtable(type, index, value, direction, sheetIndex) {
file.luckysheet_conditionformat_save = newCFarr;
file.luckysheet_alternateformat_save = newAFarr;
file.dataVerification = newDataVerification;
file.hyperlink = newHyperlink;
}

let range = null;
Expand Down Expand Up @@ -1450,6 +1496,34 @@ function luckysheetdeletetable(type, st, ed, sheetIndex) {
}
}

//超链接配置变动
let hyperlink = file.hyperlink;
let newHyperlink = {};
if(hyperlink != null){
for(let key in hyperlink){
let r = Number(key.split('_')[0]),
c = Number(key.split('_')[1]);
let item = hyperlink[key];

if(type == "row"){
if(r < st){
newHyperlink[r + "_" + c] = item;
}
else if(r > ed){
newHyperlink[(r - slen) + "_" + c] = item;
}
}
else if(type == "column"){
if(c < st){
newHyperlink[r + "_" + c] = item;
}
else if(c > ed){
newHyperlink[r + "_" + (c - slen)] = item;
}
}
}
}

//主逻辑
let type1;
if (type == "row") {
Expand Down Expand Up @@ -1686,7 +1760,8 @@ function luckysheetdeletetable(type, st, ed, sheetIndex) {
newCFarr,
newAFarr,
newFreezen,
newDataVerification
newDataVerification,
newHyperlink
);
}
else{
Expand All @@ -1698,6 +1773,7 @@ function luckysheetdeletetable(type, st, ed, sheetIndex) {
file.luckysheet_conditionformat_save = newCFarr;
file.luckysheet_alternateformat_save = newAFarr;
file.dataVerification = newDataVerification;
file.hyperlink = newHyperlink;
}
}

Expand Down Expand Up @@ -2089,6 +2165,36 @@ function luckysheetDeleteCell(type, str, edr, stc, edc, sheetIndex) {
}
}

//超链接配置变动
let hyperlink = file.hyperlink;
let newHyperlink = {};
if(hyperlink != null){
for(let key in hyperlink){
let r = Number(key.split('_')[0]),
c = Number(key.split('_')[1]);
let item = hyperlink[key];

if(r < str || r > edr || c < stc || c > edc){
if(type == "moveLeft"){
if(c > edc && r >= str && r <= edr){
newHyperlink[r + "_" + (c - clen)] = item;
}
else{
newHyperlink[r + "_" + c] = item;
}
}
else if(type == "moveUp"){
if(r > edr && c >= stc && c <= edc){
newHyperlink[(r - rlen) + "_" + c] = item;
}
else{
newHyperlink[r + "_" + c] = item;
}
}
}
}
}

//边框配置变动
if(cfg["borderInfo"] && cfg["borderInfo"].length > 0){
let borderInfo = [];
Expand Down Expand Up @@ -2200,7 +2306,8 @@ function luckysheetDeleteCell(type, str, edr, stc, edc, sheetIndex) {
newCalcChain,
newFilterObj,
newCFarr,
newDataVerification
newDataVerification,
newHyperlink
);
}
else{
Expand All @@ -2211,6 +2318,7 @@ function luckysheetDeleteCell(type, str, edr, stc, edc, sheetIndex) {
file.filter_select = newFilterObj.filter_select;
file.luckysheet_conditionformat_save = newCFarr;
file.dataVerification = newDataVerification;
file.hyperlink = newHyperlink;
}
}

Expand Down
Loading

0 comments on commit 5adfc60

Please sign in to comment.