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

Commit

Permalink
fix(fix #209 ,fix #219): highlight follow checkout keep highlight
Browse files Browse the repository at this point in the history
highlight follow cell change, checkout keep highlight
  • Loading branch information
renxxing committed Dec 4, 2020
1 parent 385bc03 commit c547596
Show file tree
Hide file tree
Showing 8 changed files with 400 additions and 205 deletions.
9 changes: 3 additions & 6 deletions src/controllers/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ export default function luckysheetHandler() {
if(isMobile){
mobileinit();
}


if (!Date.now)
Date.now = function() { return new Date().getTime(); };
//requestAnimationFrame method
Expand Down Expand Up @@ -3267,7 +3265,6 @@ export default function luckysheetHandler() {
});
//表格mouseup
$(document).on("mouseup.luckysheetEvent",function (event) {

if(luckysheetConfigsetting && luckysheetConfigsetting.hook && luckysheetConfigsetting.hook.sheetMouseup){
let mouse = mouseposition(event.pageX, event.pageY);
let x = mouse[0] + $("#luckysheet-cell-main").scrollLeft();
Expand Down Expand Up @@ -3665,14 +3662,14 @@ export default function luckysheetHandler() {

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

//改变列宽
if (Store.luckysheet_cols_change_size) {
Store.luckysheet_cols_change_size = false;
$("#luckysheet-change-size-line").hide();
$("#luckysheet-cols-change-size").css("opacity", 0);
$("#luckysheet-sheettable, #luckysheet-cols-h-c, .luckysheet-cols-h-cells, .luckysheet-cols-h-cells canvas").css("cursor", "default");

let mouse = mouseposition(event.pageX, event.pageY);
let scrollLeft = $("#luckysheet-cols-h-c").scrollLeft();
let x = mouse[0] + scrollLeft;
Expand All @@ -3685,9 +3682,9 @@ export default function luckysheetHandler() {
col = col_location[1],
col_pre = col_location[0],
col_index = col_location[2];

let size = (x + 3) - Store.luckysheet_cols_change_size_start[0];


let firstcolumnlen = Store.defaultcollen;
if (Store.config["columnlen"] != null && Store.config["columnlen"][Store.luckysheet_cols_change_size_start[1]] != null) {
firstcolumnlen = Store.config["columnlen"][Store.luckysheet_cols_change_size_start[1]];
Expand Down
422 changes: 263 additions & 159 deletions src/controllers/select.js

Large diffs are not rendered by default.

142 changes: 114 additions & 28 deletions src/controllers/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import luckysheetPostil from './postil';
import { getObjType, replaceHtml, getByteLen } from '../utils/util';
import { getSheetIndex } from '../methods/get';
import Store from '../store';
import { collaborativeEditBox } from './select'
import locale from '../locale/locale';
import dayjs from "dayjs";
import imageCtrl from './imageCtrl';
import method from '../global/method';
import json from '../global/json';

const server = {
gridKey: null,
Expand Down Expand Up @@ -77,7 +78,6 @@ const server = {
}
},
saveParam: function (type, index, value, params) {

let _this = this;

if(!_this.allowUpdate){
Expand All @@ -98,7 +98,6 @@ const server = {
return;
}


if (type == "rv") { //单元格批量更新
d.range = params.range;
}
Expand Down Expand Up @@ -155,10 +154,10 @@ const server = {

//连接建立时触发
_this.websocket.onopen = function() {
console.info('WebSocket连接成功');
console.info('WebSocket连接成功');
hideloading();
_this.wxErrorCount = 0;

_this.wxErrorCount = 0;
//防止websocket长时间不发送消息导致断连
setInterval(function(){
_this.websocket.send("rub");
Expand All @@ -168,13 +167,19 @@ const server = {
//客户端接收服务端数据时触发
_this.websocket.onmessage = function(result){
Store.result = result
let data = new Function("return " + result.data )();
console.info(data);
let data = eval('(' + result.data + ')');
console.info(data);
let type = data.type;
let {message,id} = data;
// 用户退出时,关闭协同编辑时其提示框
if(message === '用户退出') {
$("#luckysheet-multipleRange-show-" + id).hide();
Store.cooperativeEdit.changeCollaborationSize = Store.cooperativeEdit.changeCollaborationSize.filter(value => {
return value.id != id
})
Store.cooperativeEdit.checkoutData = Store.cooperativeEdit.checkoutData.filter(value => {
return value.id != id
})
}
if(type == 1){ //send 成功或失败

Expand All @@ -187,33 +192,98 @@ const server = {
let id = data.id;
let username = data.username;
let item = JSON.parse(data.data);

let type = item.t,
index = item.i,
value = item.v;

if(Store.cooperativeEdit.changeCollaborationSize.length === 0) {
Store.cooperativeEdit.changeCollaborationSize.push({id:id,v:item.v[0],i:index})
}
let flag = Store.cooperativeEdit.changeCollaborationSize.some(value1 => {
return value1.id == id
})
if(flag) {
Store.cooperativeEdit.changeCollaborationSize.forEach(val => {
if(val.id == id) {
val.v = item.v[0]
val.i = index
}
})
} else {
Store.cooperativeEdit.changeCollaborationSize.push({id:id,v:item.v[0],i:index})
}
if(getObjType(value) != "array" && getObjType(value) !== "object"){
value = JSON.parse(value);
}

}
let r = 0
let c = 0
if(index == Store.currentSheetIndex){//发送消息者在当前页面

if(getObjType(value) === "object" && value.op === 'enterEdit'){

let r = value.range[value.range.length - 1].row[0];
let c = value.range[value.range.length - 1].column[0];

r = value.range[value.range.length - 1].row[0];
c = value.range[value.range.length - 1].column[0];
_this.multipleRangeShow(id, username, r, c, value.op);

}else{
}else {

let r = value[value.length - 1].row[0];
let c = value[value.length - 1].column[0];
r = value[value.length - 1].row[0];
c = value[value.length - 1].column[0];

_this.multipleRangeShow(id, username, r, c);

}
}

} else {
if(getObjType(value) === "object" && value.op === 'enterEdit'){
r = value.range[value.range.length - 1].row[0];
c = value.range[value.range.length - 1].column[0];
}else {
r = value[value.length - 1].row[0];
c = value[value.length - 1].column[0];
}
}

if(Store.cooperativeEdit.checkoutData.length === 0) {
if(value.op) {
Store.cooperativeEdit.checkoutData.push({id,username,r,c,op:value.op,index})
} else {
Store.cooperativeEdit.checkoutData.push({id,username,r,c,index})
}
}
let checkoutFlag = Store.cooperativeEdit.checkoutData.some(item => {
return item.id == id
})
if(checkoutFlag) {
Store.cooperativeEdit.checkoutData.forEach(item => {
if(item.id == id) {
item.username = username
item.r = r
item.c = c
item.index = index
if (value.op === 'enterEdit') {
item.op = value.op
}
}
})
} else {
if(value.op === 'enterEdit') {
Store.cooperativeEdit.checkoutData.push({id,username,r,c,op:value.op,index})
} else {
Store.cooperativeEdit.checkoutData.push({id,username,r,c,index})
}
}

//其他客户端切换页面时
Store.cooperativeEdit.checkoutData.forEach(item => {
if(item.index != Store.currentSheetIndex) {
$("#luckysheet-multipleRange-show-" + item.id).hide();
item.op == ''
}
})

if($("#luckysheet-multipleRange-show-" + id)[0]) {
let change_bottom = $("#luckysheet-multipleRange-show-" + id)[0].offsetHeight - 1
$("#luckysheet-multipleRange-show-" + id + ">.username").css({"bottom":change_bottom + 'px'})
}
}
else if(type == 4){ //批量指令更新
let items = JSON.parse(data.data);
Expand Down Expand Up @@ -282,7 +352,12 @@ const server = {
}, 1);
}
}
else if(type == "rv"){ //范围单元格数据更新
else if(type == "rv"){ //范围单元格数据更新
if(Object.keys(item.range).length > 0) {
Store.cooperativeEdit.merge_range = item.range
Store.cooperativeEdit.merge_range.v = item.v
collaborativeEditBox();
}
if(file.data == null || file.data.length == 0){
return;
}
Expand All @@ -298,7 +373,7 @@ const server = {

if(index == Store.currentSheetIndex){//更新数据为当前表格数据
Store.flowdata = file.data;

//如果更新的单元格有批注
for(let r = r1; r <= r2; r++){
for(let c = c1; c <= c2; c++){
Expand All @@ -314,13 +389,13 @@ const server = {
setTimeout(function () {
luckysheetrefreshgrid();
}, 1);
}
}
}
else if(type == "cg"){ //config更新(rowhidden,rowlen,columnlen,merge,borderInfo)
let k = item.k;

if(k == "borderInfo"){
file["config"]["borderInfo"] = value;
file["config"]["borderInfo"] = value;
}
else{
if(!(k in file["config"])){
Expand Down Expand Up @@ -433,7 +508,7 @@ const server = {
let op = item.op, pos = item.pos;

if(getObjType(value) != "object"){
value = new Function("return "+ value)();
value = eval('('+ value +')');
}

let r = value.r, c = value.c;
Expand Down Expand Up @@ -546,7 +621,7 @@ const server = {
arr.push(JSON.stringify(addData[i]));
}

new Function("return " + 'data.splice(' + st_i + ', 0, ' + arr.join(",") + ')')();
eval('data.splice(' + st_i + ', 0, ' + arr.join(",") + ')');
}
else{
file["column"] += len;
Expand Down Expand Up @@ -906,7 +981,7 @@ const server = {
console.log("request");
if(_this.updateUrl != ""){
$.post(_this.updateUrl, { compress: iscommpress, gridKey: _this.gridKey, data: params }, function (data) {
let re = new Function("return " + data)();
let re = eval('('+ data +')')
if(re.status){
$("#luckysheet_info_detail_update").html("最近存档时间:"+ dayjs().format("M-D H:m:s"));
$("#luckysheet_info_detail_save").html("同步成功");
Expand Down Expand Up @@ -966,7 +1041,7 @@ const server = {
if(_this.updateImageUrl != ""){
// $.post(_this.updateImageUrl, { compress: true, gridKey: _this.gridKey, data:data1 }, function (data) {
$.post(_this.updateImageUrl, { compress: false, gridKey: _this.gridKey, data:data1 }, function (data) {
let re = new Function("return " + data)();
let re = eval('('+ data +')')
if(re.status){
imageRequestLast = dayjs();
}
Expand Down Expand Up @@ -1179,6 +1254,17 @@ const server = {
// });
});
});
},
keepHighLightBox: function() {
Store.cooperativeEdit.checkoutData.forEach(value => {
if(value.index == Store.currentSheetIndex) {
if(value.op === 'enterEdit') {
server.multipleRangeShow(value.id, value.username, value.r, value.c, value.op);
} else {
server.multipleRangeShow(value.id, value.username, value.r, value.c);
}
}
})
}
}

Expand Down
11 changes: 6 additions & 5 deletions src/controllers/sheetBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function showsheetconfigmenu() {
redo["oldcolor"] = oldcolor;
redo["color"] = color;

Store.jfundo.length = 0;
Store.jfundo = [];
Store.jfredo.push(redo);
}
}
Expand All @@ -96,7 +96,7 @@ function showsheetconfigmenu() {
redo["oldcolor"] = oldcolor;
redo["color"] = null;

Store.jfundo.length = 0;
Store.jfundo = [];
Store.jfredo.push(redo);
}
});
Expand Down Expand Up @@ -199,15 +199,15 @@ export function initialSheetBar(){
}, 200);
}
}).on("click", "div.luckysheet-sheets-item", function (e) {

if(isEditMode()){
// alert("非编辑模式下不允许该操作!");
return;
}

let $t = $(this), $cur = $(e.target);
luckysheetsheetrightclick($t, $cur, e);
// let result = Store.result
// server.websocket.onmessage(result)
server.keepHighLightBox()
});

let luckysheetsheetnameeditor = function ($t) {
Expand Down Expand Up @@ -266,7 +266,7 @@ export function initialSheetBar(){
redo["oldtxt"] = oldtxt;
redo["txt"] = txt;

Store.jfundo.length = 0;
Store.jfundo = [];
Store.jfredo.push(redo);
}
});
Expand Down Expand Up @@ -443,6 +443,7 @@ export function initialSheetBar(){
sheetmanage.setSheetShow(index);
sheetmanage.locationSheet();
}
server.keepHighLightBox()
});

initialOpenSheet = false;
Expand Down
Loading

0 comments on commit c547596

Please sign in to comment.