Browse Source

feat(inline string): when focus cell, show inline string content

master
wbfsa 5 years ago
parent
commit
713805cd03
  1. 231
      src/controllers/menuButton.js
  2. 7
      src/controllers/updateCell.js
  3. 7
      src/global/formula.js
  4. 16
      src/global/getRowlen.js
  5. 240
      src/global/getdata.js
  6. 80
      src/index.html

231
src/controllers/menuButton.js

@ -26,6 +26,7 @@ import { rowLocationByIndex, colLocationByIndex } from '../global/location';
import { isdatatypemulti } from '../global/datecontroll';
import { rowlenByRange, getCellTextSplitArr } from '../global/getRowlen';
import { setcellvalue } from '../global/setdata';
import { getFontStyleByCell, checkstatusByCell} from '../global/getdata';
import { countfunc } from '../global/count';
import { getSheetIndex, getRangetxt, getluckysheetfile } from '../methods/get';
import { setluckysheetfile } from '../methods/set';
@ -3312,165 +3313,9 @@ const menuButton = {
}
}
},
checkstatusByCell:function(cell, a){
let foucsStatus =cell;
let tf = {"bl":1, "it":1 , "ff":1, "cl":1, "un":1};
if(a in tf){
if(foucsStatus == null){
foucsStatus = "0";
}
else{
foucsStatus = foucsStatus[a];
if(foucsStatus == null){
foucsStatus = "0";
}
}
}
else if(a == "fc"){
if(foucsStatus == null){
foucsStatus = "#000000";
}
else{
foucsStatus = foucsStatus[a];
if(foucsStatus == null){
foucsStatus = "#000000";
}
if(foucsStatus.indexOf("rgba") > -1){
foucsStatus = rgbTohex(foucsStatus);
}
}
}
else if(a == "bg"){
if(foucsStatus == null){
foucsStatus = null;
}
else{
foucsStatus = foucsStatus[a];
if(foucsStatus == null){
foucsStatus = null;
}
else if(foucsStatus.toString().indexOf("rgba") > -1){
foucsStatus = rgbTohex(foucsStatus);
}
}
}
else if(a.substr(0, 2) == "bs"){
if(foucsStatus == null){
foucsStatus = "none";
}
else{
foucsStatus = foucsStatus[a];
if(foucsStatus == null){
foucsStatus = "none";
}
}
}
else if(a.substr(0, 2) == "bc"){
if(foucsStatus == null){
foucsStatus = "#000000";
}
else{
foucsStatus = foucsStatus[a];
if(foucsStatus == null){
foucsStatus = "#000000";
}
}
}
else if(a == "ht"){
if(foucsStatus == null){
foucsStatus = "1";
}
else{
foucsStatus = foucsStatus[a];
if(foucsStatus == null){
foucsStatus = "1";
}
}
if(["0", "1", "2"].indexOf(foucsStatus.toString()) == -1){
foucsStatus = "1";
}
}
else if(a == "vt"){
if(foucsStatus == null){
foucsStatus = "2";
}
else{
foucsStatus = foucsStatus[a];
if(foucsStatus == null){
foucsStatus = "2";
}
}
if(["0", "1", "2"].indexOf(foucsStatus.toString()) == -1){
foucsStatus = "2";
}
}
else if(a == "ct"){
if(foucsStatus == null){
foucsStatus = null;
}
else{
foucsStatus = foucsStatus[a];
if(foucsStatus == null){
foucsStatus = null;
}
}
}
else if(a == "fs"){
if(foucsStatus == null){
foucsStatus = "10";
}
else{
foucsStatus = foucsStatus[a];
if(foucsStatus == null){
foucsStatus = "10";
}
}
}
else if(a == "tb"){
if(foucsStatus == null){
foucsStatus = "0";
}
else{
foucsStatus = foucsStatus[a];
if(foucsStatus == null){
foucsStatus = "0";
}
}
}
else if(a == "tr"){
if(foucsStatus == null){
foucsStatus = "0";
}
else{
foucsStatus = foucsStatus[a];
if(foucsStatus == null){
foucsStatus = "0";
}
}
}
else if(a == "rt"){
if(foucsStatus == null){
foucsStatus = null;
}
else{
foucsStatus = foucsStatus[a];
if(foucsStatus == null){
foucsStatus = null;
}
}
}
return foucsStatus;
},
checkstatus: function(d, r, c, a){
let foucsStatus = d[r][c];
return this.checkstatusByCell(foucsStatus, a);
return checkstatusByCell(foucsStatus, a);
},
setLineDash: function(canvasborder, type, hv, m_st, m_ed, line_st, line_ed){
let borderType = {
@ -4232,6 +4077,10 @@ const menuButton = {
const locale_fontarray = locale().fontarray;
let cell = d[r][c];
let ct = cell.ct, isInline=false;
if(ct!=null && ct.t=="inlineStr" && ct.s!=null && ct.s.length>0){
isInline = true;
}
for(let key in cell){
let value = _this.checkstatus(d, r, c , key);
@ -4260,37 +4109,39 @@ const menuButton = {
}
}
if(key == "bl" && value != "0"){
style += "font-weight: bold;";
}
if(key == "it" && value != "0"){
style += "font-style:italic;";
}
if(key == "ff" && value != "0"){
let f = value;
if(!isNaN(parseInt(value))){
f = locale_fontarray[parseInt(value)];
}
style += "font-family: " + f + ";";
}
if(key == "fs" && value != "10"){
style += "font-size: "+ value + "pt;";
}
if((key == "fc" && value != "#000000") || checksAF != null || (checksCF != null && checksCF["textColor"] != null)){
if(checksCF != null && checksCF["textColor"] != null){
style += "color: " + checksCF["textColor"] + ";";
}
else if(checksAF != null){
style += "color: " + checksAF[0] + ";";
}
else{
style += "color: " + value + ";";
}
}
// if(!isInline){
// if(key == "bl" && value != "0"){
// style += "font-weight: bold;";
// }
// if(key == "it" && value != "0"){
// style += "font-style:italic;";
// }
// if(key == "ff" && value != "0"){
// let f = value;
// if(!isNaN(parseInt(value))){
// f = locale_fontarray[parseInt(value)];
// }
// style += "font-family: " + f + ";";
// }
// if(key == "fs" && value != "10"){
// style += "font-size: "+ value + "pt;";
// }
// if((key == "fc" && value != "#000000") || checksAF != null || (checksCF != null && checksCF["textColor"] != null)){
// if(checksCF != null && checksCF["textColor"] != null){
// style += "color: " + checksCF["textColor"] + ";";
// }
// else if(checksAF != null){
// style += "color: " + checksAF[0] + ";";
// }
// else{
// style += "color: " + value + ";";
// }
// }
// }
if(key == "ht" && value != "1"){
if(value == "0"){
@ -4311,6 +4162,10 @@ const menuButton = {
}
}
if(!isInline){
style += getFontStyleByCell(cell,checksAF,checksCF);
}
return style;
}
}

7
src/controllers/updateCell.js

@ -6,7 +6,7 @@ import alternateformat from './alternateformat';
import dataVerificationCtrl from './dataVerificationCtrl';
import { chatatABC } from '../utils/util';
import { isEditMode } from '../global/validate';
import { getcellvalue } from '../global/getdata';
import { getcellvalue,getInlineStringStyle } from '../global/getdata';
import { valueShowEs } from '../global/format';
import formula from '../global/formula';
import { luckysheetRangeLast } from '../global/cursorPos';
@ -135,7 +135,10 @@ export function luckysheetupdateCell(row_index1, col_index1, d, cover, isnotfocu
if (!cover) {
if(cell.f!=null){
if(cell.ct!=null && cell.ct.t=="inlineStr" && cell.ct.s!=null && cell.ct.s.length>0){
value = getInlineStringStyle(row_index, col_index, d);
}
else if(cell.f!=null){
value = getcellvalue(row_index, col_index, d, "f");
}
else{

7
src/global/formula.js

@ -10,7 +10,7 @@ import { seletedHighlistByindex, luckysheet_count_show } from '../controllers/se
import { isRealNum, isRealNull, valueIsError, isEditMode } from './validate';
import { isdatetime, isdatatype } from './datecontroll';
import { getCellTextSplitArr } from '../global/getRowlen';
import { getcellvalue,getcellFormula } from './getdata';
import { getcellvalue,getcellFormula,getInlineStringNoStyle } from './getdata';
import { setcellvalue } from './setdata';
import { genarate, valueShowEs } from './format';
import editor from './editor';
@ -325,7 +325,10 @@ const luckysheetformula = {
if (d[r] != null && d[r][c] != null) {
let cell = d[r][c];
if(cell.f != null){
if(cell.ct!=null && cell.ct.t=="inlineStr" && cell.ct.s!=null && cell.ct.s.length>0){
value = getInlineStringNoStyle(r, c);
}
else if(cell.f != null){
value = getcellvalue(r, c, d, "f");
}
else{

16
src/global/getRowlen.js

@ -1,6 +1,6 @@
import { luckysheetfontformat } from '../utils/util';
import menuButton from '../controllers/menuButton';
import { getcellvalue } from './getdata';
import { getcellvalue,checkstatusByCell } from './getdata';
import { colLocationByIndex } from './location';
import { hasChinaword, isRealNull } from './validate';
import Store from '../store';
@ -277,13 +277,13 @@ function getCellTextInfo(cell , ctx, option){
}
//水平对齐
let horizonAlign = menuButton.checkstatusByCell(cell, "ht");
let horizonAlign = checkstatusByCell(cell, "ht");
//垂直对齐
let verticalAlign = menuButton.checkstatusByCell(cell, "vt");
let verticalAlign = checkstatusByCell(cell, "vt");
let tb = menuButton.checkstatusByCell(cell ,"tb");//wrap overflow
let tr = menuButton.checkstatusByCell(cell ,"tr");//rotate
let rt = menuButton.checkstatusByCell(cell ,"rt");//rotate angle
let tb = checkstatusByCell(cell ,"tb");//wrap overflow
let tr = checkstatusByCell(cell ,"tr");//rotate
let rt = checkstatusByCell(cell ,"rt");//rotate angle
let isRotateUp = 1, isRotateDown=0;
@ -388,8 +388,8 @@ function getCellTextInfo(cell , ctx, option){
fontset = luckysheetfontformat(cell);
ctx.font = fontset;
cancelLine = menuButton.checkstatusByCell(cell ,"cl");//cancelLine
underLine = menuButton.checkstatusByCell(cell ,"un");//underLine
cancelLine = checkstatusByCell(cell ,"cl");//cancelLine
underLine = checkstatusByCell(cell ,"un");//underLine
if(cell instanceof Object){
value = cell.m;

240
src/global/getdata.js

@ -5,6 +5,7 @@ import formula from './formula';
import editor from './editor';
import { dynamicArrayCompute } from './dynamicArray';
import sheetmanage from '../controllers/sheetmanage';
import locale from '../locale/locale';
import Store from '../store';
//Get selection range value
@ -277,3 +278,242 @@ export function getRealCellValue(r, c){
return value;
}
export function getInlineStringNoStyle(r, c){
let ct = getcellvalue(r, c, null, "ct");
if(ct!=null && ct.t=="inlineStr" && ct.s!=null && ct.s.length>0){
let strings = ct.s, value="";
for(let i=0;i<strings.length;i++){
let strObj = strings[i];
if(strObj.v!=null){
value += strObj.v;
}
}
return value;
}
return "";
}
export function getInlineStringStyle(r, c, data){
let ct = getcellvalue(r, c, data, "ct");
if (data == null) {
data = Store.flowdata;
}
let cell = data[r][c];
if(ct!=null && ct.t=="inlineStr" && ct.s!=null && ct.s.length>0){
let strings = ct.s, value="";
for(let i=0;i<strings.length;i++){
let strObj = strings[i];
if(strObj.v!=null){
let style = getFontStyleByCell(strObj);
value += "<span style='"+ style +"'>" + strObj.v + "</span>";
}
}
return value;
}
return "";
}
export function getFontStyleByCell(cell,checksAF,checksCF){
if(cell==null){
return;
}
let style = "";
const _locale = locale();
const locale_fontarray = _locale.fontarray;
for(let key in cell){
let value = checkstatusByCell(cell, key);
if(key == "bl" && value != "0"){
style += "font-weight: bold;";
}
if(key == "it" && value != "0"){
style += "font-style:italic;";
}
if(key == "ff" && value != "0"){
let f = value;
if(!isNaN(parseInt(value))){
f = locale_fontarray[parseInt(value)];
}
style += "font-family: " + f + ";";
}
if(key == "fs" && value != "10"){
style += "font-size: "+ value + "pt;";
}
if((key == "fc" && value != "#000000") || checksAF != null || (checksCF != null && checksCF["textColor"] != null)){
if(checksCF != null && checksCF["textColor"] != null){
style += "color: " + checksCF["textColor"] + ";";
}
else if(checksAF != null){
style += "color: " + checksAF[0] + ";";
}
else{
style += "color: " + value + ";";
}
}
}
return style;
}
export function checkstatusByCell(cell, a){
let foucsStatus =cell;
let tf = {"bl":1, "it":1 , "ff":1, "cl":1, "un":1};
if(a in tf){
if(foucsStatus == null){
foucsStatus = "0";
}
else{
foucsStatus = foucsStatus[a];
if(foucsStatus == null){
foucsStatus = "0";
}
}
}
else if(a == "fc"){
if(foucsStatus == null){
foucsStatus = "#000000";
}
else{
foucsStatus = foucsStatus[a];
if(foucsStatus == null){
foucsStatus = "#000000";
}
if(foucsStatus.indexOf("rgba") > -1){
foucsStatus = rgbTohex(foucsStatus);
}
}
}
else if(a == "bg"){
if(foucsStatus == null){
foucsStatus = null;
}
else{
foucsStatus = foucsStatus[a];
if(foucsStatus == null){
foucsStatus = null;
}
else if(foucsStatus.toString().indexOf("rgba") > -1){
foucsStatus = rgbTohex(foucsStatus);
}
}
}
else if(a.substr(0, 2) == "bs"){
if(foucsStatus == null){
foucsStatus = "none";
}
else{
foucsStatus = foucsStatus[a];
if(foucsStatus == null){
foucsStatus = "none";
}
}
}
else if(a.substr(0, 2) == "bc"){
if(foucsStatus == null){
foucsStatus = "#000000";
}
else{
foucsStatus = foucsStatus[a];
if(foucsStatus == null){
foucsStatus = "#000000";
}
}
}
else if(a == "ht"){
if(foucsStatus == null){
foucsStatus = "1";
}
else{
foucsStatus = foucsStatus[a];
if(foucsStatus == null){
foucsStatus = "1";
}
}
if(["0", "1", "2"].indexOf(foucsStatus.toString()) == -1){
foucsStatus = "1";
}
}
else if(a == "vt"){
if(foucsStatus == null){
foucsStatus = "2";
}
else{
foucsStatus = foucsStatus[a];
if(foucsStatus == null){
foucsStatus = "2";
}
}
if(["0", "1", "2"].indexOf(foucsStatus.toString()) == -1){
foucsStatus = "2";
}
}
else if(a == "ct"){
if(foucsStatus == null){
foucsStatus = null;
}
else{
foucsStatus = foucsStatus[a];
if(foucsStatus == null){
foucsStatus = null;
}
}
}
else if(a == "fs"){
if(foucsStatus == null){
foucsStatus = "10";
}
else{
foucsStatus = foucsStatus[a];
if(foucsStatus == null){
foucsStatus = "10";
}
}
}
else if(a == "tb"){
if(foucsStatus == null){
foucsStatus = "0";
}
else{
foucsStatus = foucsStatus[a];
if(foucsStatus == null){
foucsStatus = "0";
}
}
}
else if(a == "tr"){
if(foucsStatus == null){
foucsStatus = "0";
}
else{
foucsStatus = foucsStatus[a];
if(foucsStatus == null){
foucsStatus = "0";
}
}
}
else if(a == "rt"){
if(foucsStatus == null){
foucsStatus = null;
}
else{
foucsStatus = foucsStatus[a];
if(foucsStatus == null){
foucsStatus = null;
}
}
}
return foucsStatus;
}

80
src/index.html

@ -78,46 +78,46 @@
forceCalculation:false,
plugins: ['chart'],
data:
// [sheetCell,sheetFormula,sheetConditionFormat,sheetSparkline,sheetTable,sheetComment,sheetPivotTableData,sheetPivotTable,sheetChart]
[{"name":"Sheet1","config":{"columnlen":{"0":241},"rowlen":{"0":81}},"index":"1","status":"1","order":"0","luckysheet_select_save":[{"row":[0,0],"column":[4,4],"sheetIndex":1}],"zoomRatio":1,"showGridLines":"1","defaultColWidth":72,"defaultRowHeight":18,"celldata":[
{"r":0,"c":0,
"v":{
"ct":{
"fa":"General",
"t":"inlineStr",
"s":[
{
"ff":"等线", //font family
"fc":"#fff000",//font color
"fs":12,//font size
"cl":0,//strike
"un":0,//underline
"bl":0,//blod
"it":1,//italic
v:"我在马路\r\n边捡到\r\n\r\n一分钱"
},
{
"ff":"等线", //font family
"fc":"#ff0000",//font color
"fs":14,//font size
"cl":"1",//strike
"un":"1",//underline
"bl":"1",//blod
"it":"0",//italic
v:"交给警\r\n察叔叔\r\n"
},
]
},
"fs":11,
"ff":"等线",
"vt":0,
"tb":2,
"v":"",
"qp":1,
}
},
{"r":17,"c":2,"v":{"v":"Luckysheet","ct":{"fa":"General","t":"g"},"bg":null,"bl":0,"it":0,"ff":0,"fs":"11","fc":"rgb(51, 51, 51)","ht":1,"vt":1,"m":"Luckysheet"}}
],"calcChain":[]}]
[sheetCell,sheetFormula,sheetConditionFormat,sheetSparkline,sheetTable,sheetComment,sheetPivotTableData,sheetPivotTable,sheetChart]
// [{"name":"Sheet1","config":{"columnlen":{"0":241},"rowlen":{"0":81}},"index":"1","status":"1","order":"0","luckysheet_select_save":[{"row":[0,0],"column":[4,4],"sheetIndex":1}],"zoomRatio":1,"showGridLines":"1","defaultColWidth":72,"defaultRowHeight":18,"celldata":[
// {"r":0,"c":0,
// "v":{
// "ct":{
// "fa":"General",
// "t":"inlineStr",
// "s":[
// {
// "ff":"等线", //font family
// "fc":"#fff000",//font color
// "fs":12,//font size
// "cl":0,//strike
// "un":0,//underline
// "bl":0,//blod
// "it":1,//italic
// v:"我在马路\r\n边捡到\r\n\r\n一分钱"
// },
// {
// "ff":"等线", //font family
// "fc":"#ff0000",//font color
// "fs":14,//font size
// "cl":"1",//strike
// "un":"1",//underline
// "bl":"1",//blod
// "it":"0",//italic
// v:"交给警\r\n察叔叔\r\n"
// },
// ]
// },
// "fs":11,
// "ff":"等线",
// "vt":0,
// "tb":2,
// "v":"",
// "qp":1,
// }
// },
// {"r":17,"c":2,"v":{"v":"Luckysheet","ct":{"fa":"General","t":"g"},"bg":null,"bl":0,"it":0,"ff":0,"fs":"11","fc":"rgb(51, 51, 51)","ht":1,"vt":1,"m":"Luckysheet"}}
// ],"calcChain":[]}]
})
})

Loading…
Cancel
Save