|
|
|
@ -53,16 +53,16 @@ function getObjType(obj) { |
|
|
|
let toString = Object.prototype.toString; |
|
|
|
|
|
|
|
let map = { |
|
|
|
'[object Boolean]': 'boolean', |
|
|
|
'[object Number]': 'number', |
|
|
|
'[object String]': 'string', |
|
|
|
'[object Boolean]': 'boolean', |
|
|
|
'[object Number]': 'number', |
|
|
|
'[object String]': 'string', |
|
|
|
'[object Function]': 'function', |
|
|
|
'[object Array]': 'array', |
|
|
|
'[object Date]': 'date', |
|
|
|
'[object RegExp]': 'regExp', |
|
|
|
'[object Undefined]':'undefined', |
|
|
|
'[object Null]': 'null', |
|
|
|
'[object Object]': 'object' |
|
|
|
'[object Array]': 'array', |
|
|
|
'[object Date]': 'date', |
|
|
|
'[object RegExp]': 'regExp', |
|
|
|
'[object Undefined]': 'undefined', |
|
|
|
'[object Null]': 'null', |
|
|
|
'[object Object]': 'object' |
|
|
|
} |
|
|
|
|
|
|
|
// if(obj instanceof Element){
|
|
|
|
@ -99,10 +99,10 @@ function hexToRgb(hex) { |
|
|
|
function rgbTohex(color) { |
|
|
|
let rgb; |
|
|
|
|
|
|
|
if(color.indexOf("rgba") > -1){ |
|
|
|
if (color.indexOf("rgba") > -1) { |
|
|
|
rgb = color.replace("rgba(", "").replace(")", "").split(','); |
|
|
|
} |
|
|
|
else{ |
|
|
|
else { |
|
|
|
rgb = color.replace("rgb(", "").replace(")", "").split(','); |
|
|
|
} |
|
|
|
|
|
|
|
@ -256,7 +256,7 @@ function createABCdim(x, count) { |
|
|
|
|
|
|
|
//计算字符串字节长度
|
|
|
|
function getByteLen(val) { |
|
|
|
if(val == null){ |
|
|
|
if (val == null) { |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
@ -279,9 +279,9 @@ function getByteLen(val) { |
|
|
|
function ArrayUnique(dataArr) { |
|
|
|
let arr = []; |
|
|
|
|
|
|
|
if(dataArr.length > 0){ |
|
|
|
for(let i = 0; i < dataArr.length; i++){ |
|
|
|
if(arr.indexOf(dataArr[i]) == -1){ |
|
|
|
if (dataArr.length > 0) { |
|
|
|
for (let i = 0; i < dataArr.length; i++) { |
|
|
|
if (arr.indexOf(dataArr[i]) == -1) { |
|
|
|
arr.push(dataArr[i]); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -292,14 +292,14 @@ function ArrayUnique(dataArr) { |
|
|
|
|
|
|
|
//获取字体配置
|
|
|
|
function luckysheetfontformat(format) { |
|
|
|
if(getObjType(format) == "object"){ |
|
|
|
if (getObjType(format) == "object") { |
|
|
|
let font = ""; |
|
|
|
|
|
|
|
//font-style
|
|
|
|
if(format.it == "0" || format.it == null){ |
|
|
|
if (format.it == "0" || format.it == null) { |
|
|
|
font += "normal "; |
|
|
|
} |
|
|
|
else{ |
|
|
|
else { |
|
|
|
font += "italic "; |
|
|
|
} |
|
|
|
|
|
|
|
@ -307,36 +307,36 @@ function luckysheetfontformat(format) { |
|
|
|
font += "normal "; |
|
|
|
|
|
|
|
//font-weight
|
|
|
|
if(format.bl == "0" || format.bl == null){ |
|
|
|
if (format.bl == "0" || format.bl == null) { |
|
|
|
font += "normal "; |
|
|
|
} |
|
|
|
else{ |
|
|
|
else { |
|
|
|
font += "bold "; |
|
|
|
} |
|
|
|
|
|
|
|
//font-size/line-height
|
|
|
|
if(!format.fs){ |
|
|
|
if (!format.fs) { |
|
|
|
font += Math.ceil(10 * Store.devicePixelRatio) + "pt "; |
|
|
|
} |
|
|
|
else{ |
|
|
|
else { |
|
|
|
font += Math.ceil(format.fs * Store.devicePixelRatio) + "pt "; |
|
|
|
} |
|
|
|
|
|
|
|
if(!format.ff){ |
|
|
|
if (!format.ff) { |
|
|
|
font += '微软雅黑, "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "Heiti SC", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif'; |
|
|
|
} |
|
|
|
else{ |
|
|
|
else { |
|
|
|
let fontarray = menuButton.fontarray; |
|
|
|
let fontfamily = null; |
|
|
|
|
|
|
|
if(isdatatypemulti(format.ff)["num"]){ |
|
|
|
if (isdatatypemulti(format.ff)["num"]) { |
|
|
|
fontfamily = fontarray[parseInt(format.ff)]; |
|
|
|
} |
|
|
|
else{ |
|
|
|
else { |
|
|
|
fontfamily = fontarray[menuButton.fontjson[format.ff]]; |
|
|
|
} |
|
|
|
|
|
|
|
if(fontfamily == null){ |
|
|
|
if (fontfamily == null) { |
|
|
|
fontfamily = "微软雅黑"; |
|
|
|
} |
|
|
|
|
|
|
|
@ -345,7 +345,7 @@ function luckysheetfontformat(format) { |
|
|
|
|
|
|
|
return font; |
|
|
|
} |
|
|
|
else{ |
|
|
|
else { |
|
|
|
return luckysheetdefaultstyle.font; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -414,10 +414,10 @@ function numFormat(num, type) { |
|
|
|
format = "[" + format + "]"; |
|
|
|
} |
|
|
|
|
|
|
|
if(num >= 1e+21){ |
|
|
|
if (num >= 1e+21) { |
|
|
|
value = parseFloat(numeral(num).value()); |
|
|
|
} |
|
|
|
else{ |
|
|
|
else { |
|
|
|
value = parseFloat(numeral(num).format("0." + format)); |
|
|
|
} |
|
|
|
|
|
|
|
@ -467,6 +467,148 @@ function mouseclickposition($menu, x, y, p) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 元素选择器 |
|
|
|
* @param {String} selector css选择器 |
|
|
|
* @param {String} context 指定父级DOM |
|
|
|
*/ |
|
|
|
function $$(selector, context) { |
|
|
|
context = context || document |
|
|
|
var elements = context.querySelectorAll(selector) |
|
|
|
return elements.length == 1 |
|
|
|
? Array.prototype.slice.call(elements)[0] |
|
|
|
: Array.prototype.slice.call(elements) |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 串行加载指定的脚本 |
|
|
|
* 串行加载[异步]逐个加载,每个加载完成后加载下一个 |
|
|
|
* 全部加载完成后执行回调 |
|
|
|
* @param {Array|String} scripts 指定要加载的脚本 |
|
|
|
* @param {Object} options 属性设置 |
|
|
|
* @param {Function} callback 成功后回调的函数 |
|
|
|
* @return {Array} 所有生成的脚本元素对象数组 |
|
|
|
*/ |
|
|
|
|
|
|
|
function seriesLoadScripts(scripts, options, callback) { |
|
|
|
if (typeof (scripts) !== 'object') { |
|
|
|
var scripts = [scripts]; |
|
|
|
} |
|
|
|
var HEAD = document.getElementsByTagName('head')[0] || document.documentElement; |
|
|
|
var s = []; |
|
|
|
var last = scripts.length - 1; |
|
|
|
//递归
|
|
|
|
var recursiveLoad = function (i) { |
|
|
|
s[i] = document.createElement('script'); |
|
|
|
s[i].setAttribute('type', 'text/javascript'); |
|
|
|
// Attach handlers for all browsers
|
|
|
|
// 异步
|
|
|
|
s[i].onload = s[i].onreadystatechange = function () { |
|
|
|
if (!/*@cc_on!@*/0 || this.readyState === 'loaded' || this.readyState === 'complete') { |
|
|
|
this.onload = this.onreadystatechange = null; |
|
|
|
this.parentNode.removeChild(this); |
|
|
|
if (i !== last) { |
|
|
|
recursiveLoad(i + 1); |
|
|
|
} else if (typeof (callback) === 'function') { |
|
|
|
callback() |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
// 同步
|
|
|
|
s[i].setAttribute('src', scripts[i]); |
|
|
|
|
|
|
|
// 设置属性
|
|
|
|
if (typeof options === 'object') { |
|
|
|
for (var attr in options) { |
|
|
|
s[i].setAttribute(attr, options[attr]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
HEAD.appendChild(s[i]); |
|
|
|
}; |
|
|
|
recursiveLoad(0); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 并行加载指定的脚本 |
|
|
|
* 并行加载[同步]同时加载,不管上个是否加载完成,直接加载全部 |
|
|
|
* 全部加载完成后执行回调 |
|
|
|
* @param {Array|String} scripts 指定要加载的脚本 |
|
|
|
* @param {Object} options 属性设置 |
|
|
|
* @param {Function} callback 成功后回调的函数 |
|
|
|
* @return {Array} 所有生成的脚本元素对象数组 |
|
|
|
*/ |
|
|
|
|
|
|
|
function parallelLoadScripts(scripts, options, callback) { |
|
|
|
if (typeof (scripts) !== 'object') { |
|
|
|
var scripts = [scripts]; |
|
|
|
} |
|
|
|
var HEAD = document.getElementsByTagName('head')[0] || document.documentElement; |
|
|
|
var s = []; |
|
|
|
var loaded = 0; |
|
|
|
for (var i = 0; i < scripts.length; i++) { |
|
|
|
s[i] = document.createElement('script'); |
|
|
|
s[i].setAttribute('type', 'text/javascript'); |
|
|
|
// Attach handlers for all browsers
|
|
|
|
// 异步
|
|
|
|
s[i].onload = s[i].onreadystatechange = function () { |
|
|
|
if (!/*@cc_on!@*/0 || this.readyState === 'loaded' || this.readyState === 'complete') { |
|
|
|
loaded++; |
|
|
|
this.onload = this.onreadystatechange = null; |
|
|
|
this.parentNode.removeChild(this); |
|
|
|
if (loaded === scripts.length && typeof (callback) === 'function') callback(); |
|
|
|
} |
|
|
|
}; |
|
|
|
// 同步
|
|
|
|
s[i].setAttribute('src', scripts[i]); |
|
|
|
|
|
|
|
// 设置属性
|
|
|
|
if (typeof options === 'object') { |
|
|
|
for (var attr in options) { |
|
|
|
s[i].setAttribute(attr, options[attr]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
HEAD.appendChild(s[i]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 动态添加css |
|
|
|
* @param {String} url 指定要加载的css地址 |
|
|
|
*/ |
|
|
|
function loadLink(url) { |
|
|
|
var doc = document; |
|
|
|
var link = doc.createElement("link"); |
|
|
|
link.setAttribute("rel", "stylesheet"); |
|
|
|
link.setAttribute("type", "text/css"); |
|
|
|
link.setAttribute("href", url); |
|
|
|
|
|
|
|
var heads = doc.getElementsByTagName("head"); |
|
|
|
if (heads.length) { |
|
|
|
heads[0].appendChild(link); |
|
|
|
} |
|
|
|
else { |
|
|
|
doc.documentElement.appendChild(link); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 动态添加一组css |
|
|
|
* @param {String} url 指定要加载的css地址 |
|
|
|
*/ |
|
|
|
function loadLinks(urls) { |
|
|
|
if (typeof (urls) !== 'object') { |
|
|
|
urls = [urls]; |
|
|
|
} |
|
|
|
if(urls.length){ |
|
|
|
urls.forEach(url => { |
|
|
|
loadLink(url); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
export { |
|
|
|
isJsonString, |
|
|
|
common_extend, |
|
|
|
@ -486,4 +628,8 @@ export { |
|
|
|
numFormat, |
|
|
|
numfloatlen, |
|
|
|
mouseclickposition, |
|
|
|
$$, |
|
|
|
seriesLoadScripts, |
|
|
|
parallelLoadScripts, |
|
|
|
loadLinks |
|
|
|
} |