|
|
|
@ -3,7 +3,19 @@
|
|
|
|
|
* Create By GUY 2014\11\17 |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
function traverse (func, context) { |
|
|
|
|
import _ from "./1.lodash"; |
|
|
|
|
import { Widget } from "./4.widget"; |
|
|
|
|
import { createWidget } from "./5.inject"; |
|
|
|
|
import { prepares, _global } from "./0.foundation"; |
|
|
|
|
import { CRYPT_TYPE, aesDecrypt, aesEncrypt } from "./structure/aes"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* todo: 理论这么写,逻辑没问题,摇个人把这个 BI 干掉 |
|
|
|
|
*/ |
|
|
|
|
const BI = { _ }; |
|
|
|
|
|
|
|
|
|
function traverse(func, context) { |
|
|
|
|
return function (value, key, obj) { |
|
|
|
|
return func.call(context, key, value, obj); |
|
|
|
|
}; |
|
|
|
@ -16,7 +28,9 @@ function _apply(name) {
|
|
|
|
|
function _applyFunc(name) { |
|
|
|
|
return function () { |
|
|
|
|
const args = Array.prototype.slice.call(arguments, 0); |
|
|
|
|
args[1] = BI._.isFunction(args[1]) ? traverse(args[1], args[2]) : args[1]; |
|
|
|
|
args[1] = BI._.isFunction(args[1]) |
|
|
|
|
? traverse(args[1], args[2]) |
|
|
|
|
: args[1]; |
|
|
|
|
|
|
|
|
|
return BI._[name](...args); |
|
|
|
|
}; |
|
|
|
@ -45,7 +59,24 @@ export function warn(message) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function UUID() { |
|
|
|
|
const f = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"]; |
|
|
|
|
const f = [ |
|
|
|
|
"0", |
|
|
|
|
"1", |
|
|
|
|
"2", |
|
|
|
|
"3", |
|
|
|
|
"4", |
|
|
|
|
"5", |
|
|
|
|
"6", |
|
|
|
|
"7", |
|
|
|
|
"8", |
|
|
|
|
"9", |
|
|
|
|
"a", |
|
|
|
|
"b", |
|
|
|
|
"c", |
|
|
|
|
"d", |
|
|
|
|
"e", |
|
|
|
|
"f" |
|
|
|
|
]; |
|
|
|
|
let str = ""; |
|
|
|
|
for (let i = 0; i < 16; i++) { |
|
|
|
|
const r = _global.parseInt(f.length * Math.random(), 10); |
|
|
|
@ -56,7 +87,7 @@ export function UUID() {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function isWidget(widget) { |
|
|
|
|
return widget instanceof BI.Widget; |
|
|
|
|
return widget instanceof Widget; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function createWidgets(items, options, context) { |
|
|
|
@ -70,31 +101,37 @@ export function createWidgets(items, options, context) {
|
|
|
|
|
options || (options = {}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return map(flatten(items), (i, item) => BI.createWidget(item, deepClone(options), context)); |
|
|
|
|
return map(flatten(items), (i, item) => |
|
|
|
|
createWidget(item, deepClone(options), context) |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function createItems(data, innerAttr, outerAttr) { |
|
|
|
|
innerAttr = isArray(innerAttr) ? innerAttr : makeArray(flatten(data).length, innerAttr || {}); |
|
|
|
|
outerAttr = isArray(outerAttr) ? outerAttr : makeArray(flatten(data).length, outerAttr || {}); |
|
|
|
|
innerAttr = isArray(innerAttr) |
|
|
|
|
? innerAttr |
|
|
|
|
: makeArray(flatten(data).length, innerAttr || {}); |
|
|
|
|
outerAttr = isArray(outerAttr) |
|
|
|
|
? outerAttr |
|
|
|
|
: makeArray(flatten(data).length, outerAttr || {}); |
|
|
|
|
|
|
|
|
|
return map(data, (i, item) => { |
|
|
|
|
if (isArray(item)) { |
|
|
|
|
return createItems(item, innerAttr, outerAttr); |
|
|
|
|
} |
|
|
|
|
if (item instanceof BI.Widget) { |
|
|
|
|
if (item instanceof Widget) { |
|
|
|
|
return extend({}, innerAttr.shift(), outerAttr.shift(), { |
|
|
|
|
type: null, |
|
|
|
|
el: item, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
if (innerAttr[0] instanceof BI.Widget) { |
|
|
|
|
if (innerAttr[0] instanceof Widget) { |
|
|
|
|
outerAttr.shift(); |
|
|
|
|
|
|
|
|
|
return extend({}, item, { |
|
|
|
|
el: innerAttr.shift(), |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
if (item.el instanceof BI.Widget) { |
|
|
|
|
if (item.el instanceof Widget) { |
|
|
|
|
innerAttr.shift(); |
|
|
|
|
|
|
|
|
|
return extend({}, outerAttr.shift(), { type: null }, item); |
|
|
|
@ -114,13 +151,15 @@ export function createItems(data, innerAttr, outerAttr) {
|
|
|
|
|
// 用容器包装items
|
|
|
|
|
export function packageItems(items, layouts) { |
|
|
|
|
for (let i = layouts.length - 1; i >= 0; i--) { |
|
|
|
|
items = map(items, (k, it) => extend({}, layouts[i], { |
|
|
|
|
items: [ |
|
|
|
|
extend({}, layouts[i].el, { |
|
|
|
|
el: it, |
|
|
|
|
}) |
|
|
|
|
], |
|
|
|
|
})); |
|
|
|
|
items = map(items, (k, it) => |
|
|
|
|
extend({}, layouts[i], { |
|
|
|
|
items: [ |
|
|
|
|
extend({}, layouts[i].el, { |
|
|
|
|
el: it, |
|
|
|
|
}) |
|
|
|
|
], |
|
|
|
|
}) |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return items; |
|
|
|
@ -138,7 +177,7 @@ export function formatEL(obj) {
|
|
|
|
|
|
|
|
|
|
// 剥开EL
|
|
|
|
|
export function stripEL(obj) { |
|
|
|
|
return obj.type && obj || obj.el || obj; |
|
|
|
|
return (obj.type && obj) || obj.el || obj; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function trans2Element(widgets) { |
|
|
|
@ -146,19 +185,53 @@ export function trans2Element(widgets) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 集合相关方法
|
|
|
|
|
BI._.each(["where", "findWhere", "invoke", "pluck", "shuffle", "sample", "toArray", "size"], name => { |
|
|
|
|
BI[name] = _apply(name); |
|
|
|
|
}); |
|
|
|
|
BI._.each([ |
|
|
|
|
"get", "set", "each", "map", "reduce", "reduceRight", "find", "filter", "reject", "every", "all", "some", "any", "max", "min", |
|
|
|
|
"sortBy", "groupBy", "indexBy", "countBy", "partition", "clamp" |
|
|
|
|
], name => { |
|
|
|
|
if (name === "any") { |
|
|
|
|
BI[name] = _applyFunc("some"); |
|
|
|
|
} else { |
|
|
|
|
BI[name] = _applyFunc(name); |
|
|
|
|
BI._.each( |
|
|
|
|
[ |
|
|
|
|
"where", |
|
|
|
|
"findWhere", |
|
|
|
|
"invoke", |
|
|
|
|
"pluck", |
|
|
|
|
"shuffle", |
|
|
|
|
"sample", |
|
|
|
|
"toArray", |
|
|
|
|
"size" |
|
|
|
|
], |
|
|
|
|
name => { |
|
|
|
|
BI[name] = _apply(name); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
BI._.each( |
|
|
|
|
[ |
|
|
|
|
"get", |
|
|
|
|
"set", |
|
|
|
|
"each", |
|
|
|
|
"map", |
|
|
|
|
"reduce", |
|
|
|
|
"reduceRight", |
|
|
|
|
"find", |
|
|
|
|
"filter", |
|
|
|
|
"reject", |
|
|
|
|
"every", |
|
|
|
|
"all", |
|
|
|
|
"some", |
|
|
|
|
"any", |
|
|
|
|
"max", |
|
|
|
|
"min", |
|
|
|
|
"sortBy", |
|
|
|
|
"groupBy", |
|
|
|
|
"indexBy", |
|
|
|
|
"countBy", |
|
|
|
|
"partition", |
|
|
|
|
"clamp" |
|
|
|
|
], |
|
|
|
|
name => { |
|
|
|
|
if (name === "any") { |
|
|
|
|
BI[name] = _applyFunc("some"); |
|
|
|
|
} else { |
|
|
|
|
BI[name] = _applyFunc(name); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
); |
|
|
|
|
export const where = BI.where; |
|
|
|
|
export const findWhere = BI.findWhere; |
|
|
|
|
export const invoke = BI.invoke; |
|
|
|
@ -323,13 +396,23 @@ export function remove(obj, target, context) {
|
|
|
|
|
let i; |
|
|
|
|
if (isArray(obj)) { |
|
|
|
|
for (i = 0; i < obj.length; i++) { |
|
|
|
|
if ((targetIsFunction && (target === obj[i] || target.apply(context, [i, obj[i]]) === true)) || (!targetIsFunction && contains(target, obj[i]))) { |
|
|
|
|
if ( |
|
|
|
|
(targetIsFunction && |
|
|
|
|
(target === obj[i] || |
|
|
|
|
target.apply(context, [i, obj[i]]) === true)) || |
|
|
|
|
(!targetIsFunction && contains(target, obj[i])) |
|
|
|
|
) { |
|
|
|
|
obj.splice(i--, 1); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
each(obj, (i, v) => { |
|
|
|
|
if ((targetIsFunction && (target === obj[i] || target.apply(context, [i, obj[i]]) === true)) || (!targetIsFunction && contains(target, obj[i]))) { |
|
|
|
|
if ( |
|
|
|
|
(targetIsFunction && |
|
|
|
|
(target === obj[i] || |
|
|
|
|
target.apply(context, [i, obj[i]]) === true)) || |
|
|
|
|
(!targetIsFunction && contains(target, obj[i])) |
|
|
|
|
) { |
|
|
|
|
delete obj[i]; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
@ -362,10 +445,15 @@ export function array2String(array) {
|
|
|
|
|
|
|
|
|
|
export function abc2Int(string) { |
|
|
|
|
let idx = 0; |
|
|
|
|
const start = "A", str = string.toUpperCase(); |
|
|
|
|
const start = "A", |
|
|
|
|
str = string.toUpperCase(); |
|
|
|
|
for (let i = 0, len = str.length; i < len; ++i) { |
|
|
|
|
idx = str.charAt(i).charCodeAt(0) - start.charCodeAt(0) + 26 * idx + 1; |
|
|
|
|
if (idx > (2147483646 - str.charAt(i).charCodeAt(0) + start.charCodeAt(0)) / 26) { |
|
|
|
|
if ( |
|
|
|
|
idx > |
|
|
|
|
(2147483646 - str.charAt(i).charCodeAt(0) + start.charCodeAt(0)) / |
|
|
|
|
26 |
|
|
|
|
) { |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -374,8 +462,36 @@ export function abc2Int(string) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function int2Abc(num) { |
|
|
|
|
const DIGITS = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]; |
|
|
|
|
let idx = num, str = ""; |
|
|
|
|
const DIGITS = [ |
|
|
|
|
"A", |
|
|
|
|
"B", |
|
|
|
|
"C", |
|
|
|
|
"D", |
|
|
|
|
"E", |
|
|
|
|
"F", |
|
|
|
|
"G", |
|
|
|
|
"H", |
|
|
|
|
"I", |
|
|
|
|
"J", |
|
|
|
|
"K", |
|
|
|
|
"L", |
|
|
|
|
"M", |
|
|
|
|
"N", |
|
|
|
|
"O", |
|
|
|
|
"P", |
|
|
|
|
"Q", |
|
|
|
|
"R", |
|
|
|
|
"S", |
|
|
|
|
"T", |
|
|
|
|
"U", |
|
|
|
|
"V", |
|
|
|
|
"W", |
|
|
|
|
"X", |
|
|
|
|
"Y", |
|
|
|
|
"Z" |
|
|
|
|
]; |
|
|
|
|
let idx = num, |
|
|
|
|
str = ""; |
|
|
|
|
if (num === 0) { |
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
@ -392,12 +508,33 @@ export function int2Abc(num) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 数组相关的方法
|
|
|
|
|
BI._.each([ |
|
|
|
|
"first", "initial", "last", "rest", "compact", "flatten", "without", "union", "intersection", |
|
|
|
|
"difference", "zip", "unzip", "object", "indexOf", "lastIndexOf", "sortedIndex", "range", "take", "takeRight", "uniqBy" |
|
|
|
|
], name => { |
|
|
|
|
BI[name] = _apply(name); |
|
|
|
|
}); |
|
|
|
|
BI._.each( |
|
|
|
|
[ |
|
|
|
|
"first", |
|
|
|
|
"initial", |
|
|
|
|
"last", |
|
|
|
|
"rest", |
|
|
|
|
"compact", |
|
|
|
|
"flatten", |
|
|
|
|
"without", |
|
|
|
|
"union", |
|
|
|
|
"intersection", |
|
|
|
|
"difference", |
|
|
|
|
"zip", |
|
|
|
|
"unzip", |
|
|
|
|
"object", |
|
|
|
|
"indexOf", |
|
|
|
|
"lastIndexOf", |
|
|
|
|
"sortedIndex", |
|
|
|
|
"range", |
|
|
|
|
"take", |
|
|
|
|
"takeRight", |
|
|
|
|
"uniqBy" |
|
|
|
|
], |
|
|
|
|
name => { |
|
|
|
|
BI[name] = _apply(name); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
BI._.each(["findIndex", "findLastIndex"], name => { |
|
|
|
|
BI[name] = _applyFunc(name); |
|
|
|
|
}); |
|
|
|
@ -484,14 +621,48 @@ export function uniq(array, isSorted, iteratee, context) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 对象相关方法
|
|
|
|
|
BI._.each([ |
|
|
|
|
"keys", "allKeys", "values", "pairs", "invert", "create", "functions", "extend", "extendOwn", |
|
|
|
|
"defaults", "clone", "property", "propertyOf", "matcher", "isEqual", "isMatch", "isEmpty", |
|
|
|
|
"isElement", "isNumber", "isString", "isArray", "isObject", "isPlainObject", "isArguments", "isFunction", "isFinite", |
|
|
|
|
"isBoolean", "isDate", "isRegExp", "isError", "isNaN", "isUndefined", "zipObject", "cloneDeep", "pickBy" |
|
|
|
|
], name => { |
|
|
|
|
BI[name] = _apply(name); |
|
|
|
|
}); |
|
|
|
|
BI._.each( |
|
|
|
|
[ |
|
|
|
|
"keys", |
|
|
|
|
"allKeys", |
|
|
|
|
"values", |
|
|
|
|
"pairs", |
|
|
|
|
"invert", |
|
|
|
|
"create", |
|
|
|
|
"functions", |
|
|
|
|
"extend", |
|
|
|
|
"extendOwn", |
|
|
|
|
"defaults", |
|
|
|
|
"clone", |
|
|
|
|
"property", |
|
|
|
|
"propertyOf", |
|
|
|
|
"matcher", |
|
|
|
|
"isEqual", |
|
|
|
|
"isMatch", |
|
|
|
|
"isEmpty", |
|
|
|
|
"isElement", |
|
|
|
|
"isNumber", |
|
|
|
|
"isString", |
|
|
|
|
"isArray", |
|
|
|
|
"isObject", |
|
|
|
|
"isPlainObject", |
|
|
|
|
"isArguments", |
|
|
|
|
"isFunction", |
|
|
|
|
"isFinite", |
|
|
|
|
"isBoolean", |
|
|
|
|
"isDate", |
|
|
|
|
"isRegExp", |
|
|
|
|
"isError", |
|
|
|
|
"isNaN", |
|
|
|
|
"isUndefined", |
|
|
|
|
"zipObject", |
|
|
|
|
"cloneDeep", |
|
|
|
|
"pickBy" |
|
|
|
|
], |
|
|
|
|
name => { |
|
|
|
|
BI[name] = _apply(name); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
export const keys = BI.keys; |
|
|
|
|
export const allKeys = BI.allKeys; |
|
|
|
|
export const values = BI.values; |
|
|
|
@ -538,10 +709,10 @@ export const omit = BI.omit;
|
|
|
|
|
export const tap = BI.tap; |
|
|
|
|
|
|
|
|
|
export function inherit(sp, overrides) { |
|
|
|
|
function sb () { |
|
|
|
|
function sb() { |
|
|
|
|
return sp.apply(this, arguments); |
|
|
|
|
} |
|
|
|
|
function F () {} |
|
|
|
|
function F() {} |
|
|
|
|
const spp = sp.prototype; |
|
|
|
|
F.prototype = spp; |
|
|
|
|
sb.prototype = new F(); |
|
|
|
@ -555,10 +726,13 @@ export function inherit(sp, overrides) {
|
|
|
|
|
|
|
|
|
|
export function init() { |
|
|
|
|
// 先把准备环境准备好
|
|
|
|
|
while (BI.prepares && BI.prepares.length > 0) { |
|
|
|
|
BI.prepares.shift()(); |
|
|
|
|
while (prepares && prepares.length > 0) { |
|
|
|
|
prepares.shift()(); |
|
|
|
|
} |
|
|
|
|
while (_global.___fineuiExposedFunction && _global.___fineuiExposedFunction.length > 0) { |
|
|
|
|
while ( |
|
|
|
|
_global.___fineuiExposedFunction && |
|
|
|
|
_global.___fineuiExposedFunction.length > 0 |
|
|
|
|
) { |
|
|
|
|
_global.___fineuiExposedFunction.shift()(); |
|
|
|
|
} |
|
|
|
|
BI.initialized = true; |
|
|
|
@ -593,8 +767,8 @@ export function isKey(key) {
|
|
|
|
|
|
|
|
|
|
// 忽略大小写的等于
|
|
|
|
|
export function isCapitalEqual(a, b) { |
|
|
|
|
a = isNull(a) ? a : (`${a}`).toLowerCase(); |
|
|
|
|
b = isNull(b) ? b : (`${b}`).toLowerCase(); |
|
|
|
|
a = isNull(a) ? a : `${a}`.toLowerCase(); |
|
|
|
|
b = isNull(b) ? b : `${b}`.toLowerCase(); |
|
|
|
|
|
|
|
|
|
return isEqual(a, b); |
|
|
|
|
} |
|
|
|
@ -603,7 +777,12 @@ export function isWidthOrHeight(w) {
|
|
|
|
|
if (typeof w === "number") { |
|
|
|
|
return w >= 0; |
|
|
|
|
} else if (typeof w === "string") { |
|
|
|
|
return /^\d{1,3}(\.\d)?%$/.test(w) || w === "auto" || /^\d+(\.\d+)?px$/.test(w) || /^calc/.test(w); |
|
|
|
|
return ( |
|
|
|
|
/^\d{1,3}(\.\d)?%$/.test(w) || |
|
|
|
|
w === "auto" || |
|
|
|
|
/^\d+(\.\d+)?px$/.test(w) || |
|
|
|
|
/^calc/.test(w) |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -643,7 +822,8 @@ export const deepClone = BI._.cloneDeep;
|
|
|
|
|
export const deepExtend = BI._.merge; |
|
|
|
|
|
|
|
|
|
export function isDeepMatch(object, attrs) { |
|
|
|
|
const attrsKeys = keys(attrs), length = attrsKeys.length; |
|
|
|
|
const attrsKeys = keys(attrs), |
|
|
|
|
length = attrsKeys.length; |
|
|
|
|
if (object === null) { |
|
|
|
|
return !length; |
|
|
|
|
} |
|
|
|
@ -661,7 +841,9 @@ export function isDeepMatch(object, attrs) {
|
|
|
|
|
export function contains(obj, target, fromIndex) { |
|
|
|
|
if (!BI._.isArrayLike(obj)) obj = values(obj); |
|
|
|
|
|
|
|
|
|
return indexOf(obj, target, typeof fromIndex === "number" && fromIndex) >= 0; |
|
|
|
|
return ( |
|
|
|
|
indexOf(obj, target, typeof fromIndex === "number" && fromIndex) >= 0 |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function deepContains(obj, copy) { |
|
|
|
@ -760,9 +942,21 @@ export function deepDiff(object, other) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 通用方法
|
|
|
|
|
BI._.each(["uniqueId", "result", "chain", "iteratee", "unescape", "before", "after", "chunk"], name => { |
|
|
|
|
BI[name] = (...args) => BI._[name](...args); |
|
|
|
|
}); |
|
|
|
|
BI._.each( |
|
|
|
|
[ |
|
|
|
|
"uniqueId", |
|
|
|
|
"result", |
|
|
|
|
"chain", |
|
|
|
|
"iteratee", |
|
|
|
|
"unescape", |
|
|
|
|
"before", |
|
|
|
|
"after", |
|
|
|
|
"chunk" |
|
|
|
|
], |
|
|
|
|
name => { |
|
|
|
|
BI[name] = (...args) => BI._[name](...args); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
export const uniqueId = BI.uniqueId; |
|
|
|
|
export const result = BI.result; |
|
|
|
|
export const chain = BI.chain; |
|
|
|
@ -773,9 +967,21 @@ export const after = BI.after;
|
|
|
|
|
export const chunk = BI.chunk; |
|
|
|
|
|
|
|
|
|
// 事件相关方法
|
|
|
|
|
BI._.each(["bind", "once", "partial", "debounce", "throttle", "delay", "defer", "wrap"], name => { |
|
|
|
|
BI[name] = (...args) => BI._[name](...args); |
|
|
|
|
}); |
|
|
|
|
BI._.each( |
|
|
|
|
[ |
|
|
|
|
"bind", |
|
|
|
|
"once", |
|
|
|
|
"partial", |
|
|
|
|
"debounce", |
|
|
|
|
"throttle", |
|
|
|
|
"delay", |
|
|
|
|
"defer", |
|
|
|
|
"wrap" |
|
|
|
|
], |
|
|
|
|
name => { |
|
|
|
|
BI[name] = (...args) => BI._[name](...args); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
export const bind = BI.bind; |
|
|
|
|
export const once = BI.once; |
|
|
|
|
export const partial = BI.partial; |
|
|
|
@ -846,9 +1052,9 @@ export const nextTick = (function () {
|
|
|
|
|
} |
|
|
|
|
// $flow-disable-line
|
|
|
|
|
if (!cb && typeof Promise !== "undefined") { |
|
|
|
|
return new Promise(((resolve, reject) => { |
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
_resolve = resolve; |
|
|
|
|
})); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
}()); |
|
|
|
@ -876,7 +1082,9 @@ export function parseSafeInt(value) {
|
|
|
|
|
|
|
|
|
|
return value |
|
|
|
|
? clamp(parseInt(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER) |
|
|
|
|
: (value === 0 ? value : 0); |
|
|
|
|
: value === 0 |
|
|
|
|
? value |
|
|
|
|
: 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function parseFloat(number) { |
|
|
|
@ -904,7 +1112,9 @@ export function isInteger(number) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function isNumeric(number) { |
|
|
|
|
return !_global.isNaN(_global.parseFloat(number)) && _global.isFinite(number); |
|
|
|
|
return ( |
|
|
|
|
!_global.isNaN(_global.parseFloat(number)) && _global.isFinite(number) |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function isFloat(number) { |
|
|
|
@ -951,11 +1161,11 @@ export function trim(...args) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function toUpperCase(string) { |
|
|
|
|
return (`${string}`).toLocaleUpperCase(); |
|
|
|
|
return `${string}`.toLocaleUpperCase(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function toLowerCase(string) { |
|
|
|
|
return (`${string}`).toLocaleLowerCase(); |
|
|
|
|
return `${string}`.toLocaleLowerCase(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function isEndWithBlank(string) { |
|
|
|
@ -970,9 +1180,7 @@ export function stripQuotes(str) {
|
|
|
|
|
const a = str.charCodeAt(0); |
|
|
|
|
const b = str.charCodeAt(str.length - 1); |
|
|
|
|
|
|
|
|
|
return a === b && (a === 0x22 || a === 0x27) |
|
|
|
|
? str.slice(1, -1) |
|
|
|
|
: str; |
|
|
|
|
return a === b && (a === 0x22 || a === 0x27) ? str.slice(1, -1) : str; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// background-color => backgroundColor
|
|
|
|
@ -1002,9 +1210,9 @@ export function isEmptyString(str) {
|
|
|
|
|
*/ |
|
|
|
|
export function encrypt(type, text, key) { |
|
|
|
|
switch (type) { |
|
|
|
|
case BI.CRYPT_TYPE.AES: |
|
|
|
|
default: |
|
|
|
|
return BI.aesEncrypt(text, key); |
|
|
|
|
case CRYPT_TYPE.AES: |
|
|
|
|
default: |
|
|
|
|
return aesEncrypt(text, key); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1017,9 +1225,9 @@ export function encrypt(type, text, key) {
|
|
|
|
|
*/ |
|
|
|
|
export function decrypt(type, text, key) { |
|
|
|
|
switch (type) { |
|
|
|
|
case BI.CRYPT_TYPE.AES: |
|
|
|
|
default: |
|
|
|
|
return BI.aesDecrypt(text, key); |
|
|
|
|
case CRYPT_TYPE.AES: |
|
|
|
|
default: |
|
|
|
|
return aesDecrypt(text, key); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1033,7 +1241,6 @@ export function escape(string) {
|
|
|
|
|
return string.replace(/('|\\)/g, "\\$1"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 让字符串通过指定字符做补齐的函数 |
|
|
|
|
* |
|
|
|
@ -1130,7 +1337,9 @@ export function checkDateVoid(YY, MM, DD, minDate, maxDate) {
|
|
|
|
|
|
|
|
|
|
export function checkDateLegal(str) { |
|
|
|
|
const ar = str.match(/\d+/g); |
|
|
|
|
const YY = ar[0] | 0, MM = ar[1] | 0, DD = ar[2] | 0; |
|
|
|
|
const YY = ar[0] | 0, |
|
|
|
|
MM = ar[1] | 0, |
|
|
|
|
DD = ar[2] | 0; |
|
|
|
|
if (ar.length <= 1) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
@ -1162,69 +1371,77 @@ export function parseDateTime(str, fmt) {
|
|
|
|
|
const otherlength = 2; |
|
|
|
|
a[0] = str.substring(0, yearlength); |
|
|
|
|
a[1] = str.substring(yearlength, yearlength + otherlength); |
|
|
|
|
a[2] = str.substring(yearlength + otherlength, yearlength + otherlength * 2); |
|
|
|
|
a[2] = str.substring( |
|
|
|
|
yearlength + otherlength, |
|
|
|
|
yearlength + otherlength * 2 |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
const b = fmt.match(/%./g); |
|
|
|
|
let i = 0, j = 0; |
|
|
|
|
let i = 0, |
|
|
|
|
j = 0; |
|
|
|
|
let hr = 0; |
|
|
|
|
let min = 0; |
|
|
|
|
let sec = 0; |
|
|
|
|
for (i = 0; i < a.length; ++i) { |
|
|
|
|
switch (b[i]) { |
|
|
|
|
case "%d": |
|
|
|
|
case "%e": |
|
|
|
|
d = _global.parseInt(a[i], 10); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case "%X": |
|
|
|
|
m = _global.parseInt(a[i], 10) - 1; |
|
|
|
|
break; |
|
|
|
|
case "%x": |
|
|
|
|
m = _global.parseInt(a[i], 10) - 1; |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case "%Y": |
|
|
|
|
case "%y": |
|
|
|
|
y = _global.parseInt(a[i], 10); |
|
|
|
|
(y < 100) && (y += (y > 29) ? 1900 : 2000); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case "%b": |
|
|
|
|
case "%B": |
|
|
|
|
for (j = 0; j < 12; ++j) { |
|
|
|
|
if (BI.getMonthName(j).substr(0, a[i].length).toLowerCase() === a[i].toLowerCase()) { |
|
|
|
|
m = j; |
|
|
|
|
break; |
|
|
|
|
case "%d": |
|
|
|
|
case "%e": |
|
|
|
|
d = _global.parseInt(a[i], 10); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case "%X": |
|
|
|
|
m = _global.parseInt(a[i], 10) - 1; |
|
|
|
|
break; |
|
|
|
|
case "%x": |
|
|
|
|
m = _global.parseInt(a[i], 10) - 1; |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case "%Y": |
|
|
|
|
case "%y": |
|
|
|
|
y = _global.parseInt(a[i], 10); |
|
|
|
|
y < 100 && (y += y > 29 ? 1900 : 2000); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case "%b": |
|
|
|
|
case "%B": |
|
|
|
|
for (j = 0; j < 12; ++j) { |
|
|
|
|
if ( |
|
|
|
|
BI.getMonthName(j) |
|
|
|
|
.substr(0, a[i].length) |
|
|
|
|
.toLowerCase() === a[i].toLowerCase() |
|
|
|
|
) { |
|
|
|
|
m = j; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case "%H": |
|
|
|
|
case "%I": |
|
|
|
|
case "%k": |
|
|
|
|
case "%l": |
|
|
|
|
hr = _global.parseInt(a[i], 10); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case "%P": |
|
|
|
|
case "%p": |
|
|
|
|
if (/pm/i.test(a[i]) && hr < 12) { |
|
|
|
|
hr += 12; |
|
|
|
|
} else if (/am/i.test(a[i]) && hr >= 12) { |
|
|
|
|
hr -= 12; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case "%Q": |
|
|
|
|
case "%q": |
|
|
|
|
m = (_global.parseInt(a[i], 10) - 1) * 3; |
|
|
|
|
break; |
|
|
|
|
case "%M": |
|
|
|
|
min = _global.parseInt(a[i], 10); |
|
|
|
|
break; |
|
|
|
|
case "%S": |
|
|
|
|
sec = _global.parseInt(a[i], 10); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case "%H": |
|
|
|
|
case "%I": |
|
|
|
|
case "%k": |
|
|
|
|
case "%l": |
|
|
|
|
hr = _global.parseInt(a[i], 10); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case "%P": |
|
|
|
|
case "%p": |
|
|
|
|
if (/pm/i.test(a[i]) && hr < 12) { |
|
|
|
|
hr += 12; |
|
|
|
|
} else if (/am/i.test(a[i]) && hr >= 12) { |
|
|
|
|
hr -= 12; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case "%Q": |
|
|
|
|
case "%q": |
|
|
|
|
m = (_global.parseInt(a[i], 10) - 1) * 3; |
|
|
|
|
break; |
|
|
|
|
case "%M": |
|
|
|
|
min = _global.parseInt(a[i], 10); |
|
|
|
|
break; |
|
|
|
|
case "%S": |
|
|
|
|
sec = _global.parseInt(a[i], 10); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// if (!a[i]) {
|
|
|
|
@ -1258,7 +1475,10 @@ export function parseDateTime(str, fmt) {
|
|
|
|
|
if (a[i].search(/[a-zA-Z]+/) !== -1) { |
|
|
|
|
let t = -1; |
|
|
|
|
for (j = 0; j < 12; ++j) { |
|
|
|
|
if (BI.getMonthName(j).substr(0, a[i].length).toLowerCase() === a[i].toLowerCase()) { |
|
|
|
|
if ( |
|
|
|
|
BI.getMonthName(j).substr(0, a[i].length).toLowerCase() === |
|
|
|
|
a[i].toLowerCase() |
|
|
|
|
) { |
|
|
|
|
t = j; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
@ -1273,7 +1493,7 @@ export function parseDateTime(str, fmt) {
|
|
|
|
|
m = a[i] - 1; |
|
|
|
|
} else if (_global.parseInt(a[i], 10) > 31 && y === 0) { |
|
|
|
|
y = _global.parseInt(a[i], 10); |
|
|
|
|
(y < 100) && (y += (y > 29) ? 1900 : 2000); |
|
|
|
|
y < 100 && (y += y > 29 ? 1900 : 2000); |
|
|
|
|
} else if (d === 0) { |
|
|
|
|
d = a[i]; |
|
|
|
|
} |
|
|
|
@ -1295,49 +1515,61 @@ export function getDate(...args) {
|
|
|
|
|
const length = args.length; |
|
|
|
|
let dt; |
|
|
|
|
switch (length) { |
|
|
|
|
// new Date()
|
|
|
|
|
case 0: |
|
|
|
|
dt = new Date(); |
|
|
|
|
break; |
|
|
|
|
// new Date()
|
|
|
|
|
case 0: |
|
|
|
|
dt = new Date(); |
|
|
|
|
break; |
|
|
|
|
// new Date(long)
|
|
|
|
|
case 1: |
|
|
|
|
dt = new Date(args[0]); |
|
|
|
|
break; |
|
|
|
|
case 1: |
|
|
|
|
dt = new Date(args[0]); |
|
|
|
|
break; |
|
|
|
|
// new Date(year, month)
|
|
|
|
|
case 2: |
|
|
|
|
dt = new Date(args[0], args[1]); |
|
|
|
|
break; |
|
|
|
|
case 2: |
|
|
|
|
dt = new Date(args[0], args[1]); |
|
|
|
|
break; |
|
|
|
|
// new Date(year, month, day)
|
|
|
|
|
case 3: |
|
|
|
|
dt = new Date(args[0], args[1], args[2]); |
|
|
|
|
break; |
|
|
|
|
case 3: |
|
|
|
|
dt = new Date(args[0], args[1], args[2]); |
|
|
|
|
break; |
|
|
|
|
// new Date(year, month, day, hour)
|
|
|
|
|
case 4: |
|
|
|
|
dt = new Date(args[0], args[1], args[2], args[3]); |
|
|
|
|
break; |
|
|
|
|
case 4: |
|
|
|
|
dt = new Date(args[0], args[1], args[2], args[3]); |
|
|
|
|
break; |
|
|
|
|
// new Date(year, month, day, hour, minute)
|
|
|
|
|
case 5: |
|
|
|
|
dt = new Date(args[0], args[1], args[2], args[3], args[4]); |
|
|
|
|
break; |
|
|
|
|
case 5: |
|
|
|
|
dt = new Date(args[0], args[1], args[2], args[3], args[4]); |
|
|
|
|
break; |
|
|
|
|
// new Date(year, month, day, hour, minute, second)
|
|
|
|
|
case 6: |
|
|
|
|
dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5]); |
|
|
|
|
break; |
|
|
|
|
case 6: |
|
|
|
|
dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5]); |
|
|
|
|
break; |
|
|
|
|
// new Date(year, month, day, hour, minute, second, millisecond)
|
|
|
|
|
case 7: |
|
|
|
|
dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
dt = new Date(); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
if (isNotNull(BI.timeZone) && (arguments.length === 0 || (arguments.length === 1 && isNumber(arguments[0])))) { |
|
|
|
|
case 7: |
|
|
|
|
dt = new Date( |
|
|
|
|
args[0], |
|
|
|
|
args[1], |
|
|
|
|
args[2], |
|
|
|
|
args[3], |
|
|
|
|
args[4], |
|
|
|
|
args[5], |
|
|
|
|
args[6] |
|
|
|
|
); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
dt = new Date(); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
if ( |
|
|
|
|
isNotNull(BI.timeZone) && |
|
|
|
|
(arguments.length === 0 || |
|
|
|
|
(arguments.length === 1 && isNumber(arguments[0]))) |
|
|
|
|
) { |
|
|
|
|
const localTime = dt.getTime(); |
|
|
|
|
// BI-33791 1901年以前的东8区标准是GMT+0805, 统一无论是什么时间,都以整的0800这样的为基准
|
|
|
|
|
const localOffset = dt.getTimezoneOffset() * 60000; // 获得当地时间偏移的毫秒数
|
|
|
|
|
const utc = localTime + localOffset; // utc即GMT时间标准时区
|
|
|
|
|
|
|
|
|
|
return new Date(utc + BI.timeZone);// + Pool.timeZone.offset);
|
|
|
|
|
return new Date(utc + BI.timeZone); // + Pool.timeZone.offset);
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return dt; |
|
|
|
@ -1348,47 +1580,59 @@ export function getTime() {
|
|
|
|
|
const args = arguments; |
|
|
|
|
let dt; |
|
|
|
|
switch (length) { |
|
|
|
|
// new Date()
|
|
|
|
|
case 0: |
|
|
|
|
dt = new Date(); |
|
|
|
|
break; |
|
|
|
|
// new Date()
|
|
|
|
|
case 0: |
|
|
|
|
dt = new Date(); |
|
|
|
|
break; |
|
|
|
|
// new Date(long)
|
|
|
|
|
case 1: |
|
|
|
|
dt = new Date(args[0]); |
|
|
|
|
break; |
|
|
|
|
case 1: |
|
|
|
|
dt = new Date(args[0]); |
|
|
|
|
break; |
|
|
|
|
// new Date(year, month)
|
|
|
|
|
case 2: |
|
|
|
|
dt = new Date(args[0], args[1]); |
|
|
|
|
break; |
|
|
|
|
case 2: |
|
|
|
|
dt = new Date(args[0], args[1]); |
|
|
|
|
break; |
|
|
|
|
// new Date(year, month, day)
|
|
|
|
|
case 3: |
|
|
|
|
dt = new Date(args[0], args[1], args[2]); |
|
|
|
|
break; |
|
|
|
|
case 3: |
|
|
|
|
dt = new Date(args[0], args[1], args[2]); |
|
|
|
|
break; |
|
|
|
|
// new Date(year, month, day, hour)
|
|
|
|
|
case 4: |
|
|
|
|
dt = new Date(args[0], args[1], args[2], args[3]); |
|
|
|
|
break; |
|
|
|
|
case 4: |
|
|
|
|
dt = new Date(args[0], args[1], args[2], args[3]); |
|
|
|
|
break; |
|
|
|
|
// new Date(year, month, day, hour, minute)
|
|
|
|
|
case 5: |
|
|
|
|
dt = new Date(args[0], args[1], args[2], args[3], args[4]); |
|
|
|
|
break; |
|
|
|
|
case 5: |
|
|
|
|
dt = new Date(args[0], args[1], args[2], args[3], args[4]); |
|
|
|
|
break; |
|
|
|
|
// new Date(year, month, day, hour, minute, second)
|
|
|
|
|
case 6: |
|
|
|
|
dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5]); |
|
|
|
|
break; |
|
|
|
|
case 6: |
|
|
|
|
dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5]); |
|
|
|
|
break; |
|
|
|
|
// new Date(year, month, day, hour, minute, second, millisecond)
|
|
|
|
|
case 7: |
|
|
|
|
dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
dt = new Date(); |
|
|
|
|
break; |
|
|
|
|
case 7: |
|
|
|
|
dt = new Date( |
|
|
|
|
args[0], |
|
|
|
|
args[1], |
|
|
|
|
args[2], |
|
|
|
|
args[3], |
|
|
|
|
args[4], |
|
|
|
|
args[5], |
|
|
|
|
args[6] |
|
|
|
|
); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
dt = new Date(); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
if (isNotNull(BI.timeZone)) { |
|
|
|
|
// BI-33791 1901年以前的东8区标准是GMT+0805, 统一无论是什么时间,都以整的0800这样的为基准
|
|
|
|
|
return dt.getTime() - BI.timeZone - new Date().getTimezoneOffset() * 60000; |
|
|
|
|
return ( |
|
|
|
|
dt.getTime() - BI.timeZone - new Date().getTimezoneOffset() * 60000 |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return dt.getTime(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const lodashUtils = BI._; |
|
|
|
|