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

Commit

Permalink
feat(feature): closeWebsocket api and ctrl ;
Browse files Browse the repository at this point in the history
feature

fix #328, fix #326
  • Loading branch information
wpxp123456 committed Dec 11, 2020
1 parent 0e6e341 commit 9153bc7
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 5 deletions.
6 changes: 6 additions & 0 deletions docs/zh/guide/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2550,6 +2550,12 @@ Luckysheet针对常用的数据操作需求,开放了主要功能的API,开

传入目标语言,切换到对应的语言界面

### closeWebsocket()

- **说明**

关闭websocket连接

### getRangeByTxt([txt])

- **说明**
Expand Down
37 changes: 36 additions & 1 deletion src/controllers/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ import imageCtrl from './imageCtrl';

import {
getByteLen,
getNowDateTime,
luckysheetactiveCell,
} from '../utils/util';
import { getSheetIndex } from '../methods/get';
import { hasPartMC, isEditMode } from '../global/validate';
import { luckysheetRangeLast } from '../global/cursorPos';
import formula from '../global/formula';
import cleargridelement from '../global/cleargridelement';
import tooltip from '../global/tooltip';
Expand Down Expand Up @@ -273,7 +275,7 @@ export function keyboardInitial(){
let altKey = event.altKey;
let shiftKey = event.shiftKey;
let kcode = event.keyCode;

if ($("#luckysheet-modal-dialog-mask").is(":visible") || $(event.target).hasClass("luckysheet-mousedown-cancel") || $(event.target).hasClass("sp-input") || (parseInt($("#luckysheet-input-box").css("top")) > 0 && $(event.target).closest(".luckysheet-input-box").length > 0 && kcode != keycode.ENTER && kcode != keycode.TAB && kcode != keycode.UP && kcode != keycode.DOWN && kcode != keycode.LEFT && kcode != keycode.RIGHT)) {
let anchor = $(window.getSelection().anchorNode);

Expand Down Expand Up @@ -435,6 +437,17 @@ export function keyboardInitial(){

luckysheetMoveHighlightRange2("right", "rangeOfSelect");
}
else if (kcode == 186 || kcode == 222) {
let last = Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1];
let row_index = last["row_focus"],
col_index = last["column_focus"];
luckysheetupdateCell(row_index, col_index, Store.flowdata, true);

let value = getNowDateTime(2);
$("#luckysheet-rich-text-editor").html(value);
luckysheetRangeLast($("#luckysheet-rich-text-editor")[0]);
formula.functionInputHanddler($("#luckysheet-functionbox-cell"), $("#luckysheet-rich-text-editor"), kcode);
}
}
else if (kcode == 66) {//Ctrl + B 加粗
$("#luckysheet-icon-bold").click();
Expand Down Expand Up @@ -695,6 +708,28 @@ export function keyboardInitial(){

luckysheetMoveHighlightCell2("right", "rangeOfSelect");
}
else if (kcode == 186) {//Ctrl + ; 填充系统日期
let last = Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1];
let row_index = last["row_focus"],
col_index = last["column_focus"];
luckysheetupdateCell(row_index, col_index, Store.flowdata, true);

let value = getNowDateTime(1);
$("#luckysheet-rich-text-editor").html(value);
luckysheetRangeLast($("#luckysheet-rich-text-editor")[0]);
formula.functionInputHanddler($("#luckysheet-functionbox-cell"), $("#luckysheet-rich-text-editor"), kcode);
}
else if (kcode == 222) {//Ctrl + ' 填充系统时间
let last = Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1];
let row_index = last["row_focus"],
col_index = last["column_focus"];
luckysheetupdateCell(row_index, col_index, Store.flowdata, true);

let value = getNowDateTime(2);
$("#luckysheet-rich-text-editor").html(value);
luckysheetRangeLast($("#luckysheet-rich-text-editor")[0]);
formula.functionInputHanddler($("#luckysheet-functionbox-cell"), $("#luckysheet-rich-text-editor"), kcode);
}
else if (String.fromCharCode(kcode).toLocaleUpperCase() == "A") {//Ctrl + A 全选
// $("#luckysheet-left-top").trigger("mousedown");
// $(document).trigger("mouseup");
Expand Down
7 changes: 3 additions & 4 deletions src/controllers/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,9 @@ const server = {

//连接建立时触发
_this.websocket.onopen = function() {

console.info(locale().websocket.success);
hideloading();
_this.wxErrorCount = 0;
console.info(locale().websocket.success);
hideloading();
_this.wxErrorCount = 0;

//防止websocket长时间不发送消息导致断连
setInterval(function(){
Expand Down
12 changes: 12 additions & 0 deletions src/global/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -6237,6 +6237,18 @@ export function changLang(lang = 'zh'){
}


/**
* 关闭websocket连接
*/
export function closeWebsocket(){
if(server.websocket == null){
return;
}

server.websocket.close();
}


/**
* 根据范围字符串转换为range数组
* @param {String} txt 范围字符串
Expand Down
33 changes: 33 additions & 0 deletions src/utils/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,38 @@ function getObjType(obj) {
return map[toString.call(obj)];
}

//获取当前日期时间
function getNowDateTime(format) {
let now = new Date();
let year = now.getFullYear(); //得到年份
let month = now.getMonth(); //得到月份
let date = now.getDate(); //得到日期
let day = now.getDay(); //得到周几
let hour = now.getHours(); //得到小时
let minu = now.getMinutes(); //得到分钟
let sec = now.getSeconds(); //得到秒

month = month + 1;
if (month < 10) month = "0" + month;
if (date < 10) date = "0" + date;
if (hour < 10) hour = "0" + hour;
if (minu < 10) minu = "0" + minu;
if (sec < 10) sec = "0" + sec;

let time = '';

//日期
if(format == 1) {
time = year + "-" + month + "-" + date;
}
//日期时间
else if(format == 2) {
time = year + "-" + month + "-" + date+ " " + hour + ":" + minu + ":" + sec;
}

return time;
}

//颜色 16进制转rgb
function hexToRgb(hex) {
let color = [], rgb = [];
Expand Down Expand Up @@ -807,6 +839,7 @@ export {
common_extend,
replaceHtml,
getObjType,
getNowDateTime,
hexToRgb,
rgbTohex,
ABCatNum,
Expand Down

0 comments on commit 9153bc7

Please sign in to comment.