|
|
@ -1,5 +1,8 @@ |
|
|
|
(function () { |
|
|
|
import {each, isFunction, isNull, isObject, isPlainObject, keys, leftPad, parseDateTime, values} from "../2.base"; |
|
|
|
var _global; |
|
|
|
import {replaceAll} from "./string"; |
|
|
|
|
|
|
|
import {getFullDayName, getMonthName, getTimezone} from "./date"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let _global; |
|
|
|
if (typeof window !== "undefined") { |
|
|
|
if (typeof window !== "undefined") { |
|
|
|
_global = window; |
|
|
|
_global = window; |
|
|
|
} else if (typeof global !== "undefined") { |
|
|
|
} else if (typeof global !== "undefined") { |
|
|
@ -15,13 +18,12 @@ |
|
|
|
|
|
|
|
|
|
|
|
function isEmpty(value) { |
|
|
|
function isEmpty(value) { |
|
|
|
// 判断是否为空值
|
|
|
|
// 判断是否为空值
|
|
|
|
var result = value === "" || value === null || value === undefined; |
|
|
|
return value === "" || value === null || value === undefined; |
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 判断是否是无效的日期
|
|
|
|
// 判断是否是无效的日期
|
|
|
|
function isInvalidDate(date) { |
|
|
|
function isInvalidDate(date) { |
|
|
|
return date == "Invalid Date" || date == "NaN"; |
|
|
|
return date === "Invalid Date" || date === "NaN"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -45,12 +47,12 @@ |
|
|
|
* @returns {*} |
|
|
|
* @returns {*} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function eFormat(num, format) { |
|
|
|
function eFormat(num, format) { |
|
|
|
var neg = num < 0 ? (num *= -1, "-") : "", |
|
|
|
let neg = num < 0 ? (num *= -1, "-") : "", |
|
|
|
magnitudeNeg = ""; |
|
|
|
magnitudeNeg = ""; |
|
|
|
|
|
|
|
|
|
|
|
var funcName = num > 0 && num < 1 ? "floor" : "ceil"; // -0.9999->-1
|
|
|
|
const funcName = num > 0 && num < 1 ? "floor" : "ceil"; // -0.9999->-1
|
|
|
|
// 数量级
|
|
|
|
// 数量级
|
|
|
|
var magnitude = Math[funcName](Math.log(num) / Math.log(10)); |
|
|
|
let magnitude = Math[funcName](Math.log(num) / Math.log(10)); |
|
|
|
|
|
|
|
|
|
|
|
if (!isFinite(magnitude)) { |
|
|
|
if (!isFinite(magnitude)) { |
|
|
|
return format.replace(/#/ig, "").replace(/\.e/ig, "E"); |
|
|
|
return format.replace(/#/ig, "").replace(/\.e/ig, "E"); |
|
|
@ -65,15 +67,15 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 计算出format中需要显示的整数部分的位数,然后更新这个数值,也更新数量级
|
|
|
|
// 计算出format中需要显示的整数部分的位数,然后更新这个数值,也更新数量级
|
|
|
|
var integerLen = getInteger(magnitude, format); |
|
|
|
const integerLen = getInteger(magnitude, format); |
|
|
|
integerLen > 1 && (magnitude -= integerLen - 1, num *= Math.pow(10, integerLen - 1)); |
|
|
|
integerLen > 1 && (magnitude -= integerLen - 1, num *= Math.pow(10, integerLen - 1)); |
|
|
|
|
|
|
|
|
|
|
|
magnitude < 0 && (magnitudeNeg = "-", magnitude *= -1); |
|
|
|
magnitude < 0 && (magnitudeNeg = "-", magnitude *= -1); |
|
|
|
|
|
|
|
|
|
|
|
// 获取科学计数法精确到的位数
|
|
|
|
// 获取科学计数法精确到的位数
|
|
|
|
var precision = getPrecision(format); |
|
|
|
const precision = getPrecision(format); |
|
|
|
// 判断num经过四舍五入之后是否有进位
|
|
|
|
// 判断num经过四舍五入之后是否有进位
|
|
|
|
var isValueCarry = isValueCarried(num); |
|
|
|
const isValueCarry = isValueCarried(num); |
|
|
|
|
|
|
|
|
|
|
|
num *= Math.pow(10, precision); |
|
|
|
num *= Math.pow(10, precision); |
|
|
|
num = Math.round(num); |
|
|
|
num = Math.round(num); |
|
|
@ -102,8 +104,8 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 如果magnitudeNeg是一个"-",而且num正好全是0,那么就别显示负号了
|
|
|
|
// 如果magnitudeNeg是一个"-",而且num正好全是0,那么就别显示负号了
|
|
|
|
var isAllZero = true; |
|
|
|
let isAllZero = true; |
|
|
|
for (var i = 0, len = num.length; i < len; i++) { |
|
|
|
for (let i = 0, len = num.length; i < len; i++) { |
|
|
|
if (!isAllZero) { |
|
|
|
if (!isAllZero) { |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
@ -119,7 +121,7 @@ |
|
|
|
if (!/e/ig.test(format)) { |
|
|
|
if (!/e/ig.test(format)) { |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
var arr = format.split(/e/ig)[0].split("."); |
|
|
|
const arr = format.split(/e/ig)[0].split("."); |
|
|
|
|
|
|
|
|
|
|
|
return arr.length > 1 ? arr[1].length : 0; |
|
|
|
return arr.length > 1 ? arr[1].length : 0; |
|
|
|
} |
|
|
|
} |
|
|
@ -132,8 +134,8 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
// return format.split(/e/ig)[0].split(".")[0].length;
|
|
|
|
// return format.split(/e/ig)[0].split(".")[0].length;
|
|
|
|
|
|
|
|
|
|
|
|
var formatLeft = format.split(/e/ig)[0].split(".")[0], i, f, len = formatLeft.length; |
|
|
|
let formatLeft = format.split(/e/ig)[0].split(".")[0], i, f, len = formatLeft.length; |
|
|
|
var valueLeftLen = 0; |
|
|
|
let valueLeftLen = 0; |
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) { |
|
|
|
for (i = 0; i < len; i++) { |
|
|
|
f = formatLeft.charAt(i); |
|
|
|
f = formatLeft.charAt(i); |
|
|
@ -148,7 +150,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
// 判断num通过round函数之后是否有进位
|
|
|
|
// 判断num通过round函数之后是否有进位
|
|
|
|
function isValueCarried(num) { |
|
|
|
function isValueCarried(num) { |
|
|
|
var roundNum = Math.round(num); |
|
|
|
let roundNum = Math.round(num); |
|
|
|
num = (num + "").split(".")[0]; |
|
|
|
num = (num + "").split(".")[0]; |
|
|
|
roundNum = (roundNum + "").split(".")[0]; |
|
|
|
roundNum = (roundNum + "").split(".")[0]; |
|
|
|
return num.length !== roundNum.length; |
|
|
|
return num.length !== roundNum.length; |
|
|
@ -158,13 +160,13 @@ |
|
|
|
//'#.##'之类的格式处理 1.324e-18 这种的科学数字
|
|
|
|
//'#.##'之类的格式处理 1.324e-18 这种的科学数字
|
|
|
|
function _dealNumberPrecision(text, fright) { |
|
|
|
function _dealNumberPrecision(text, fright) { |
|
|
|
if (/[eE]/.test(text)) { |
|
|
|
if (/[eE]/.test(text)) { |
|
|
|
var precision = 0, i = 0, ch; |
|
|
|
let precision = 0, i = 0, ch; |
|
|
|
|
|
|
|
|
|
|
|
if (/[%‰]$/.test(fright)) { |
|
|
|
if (/[%‰]$/.test(fright)) { |
|
|
|
precision = /[%]$/.test(fright) ? 2 : 3; |
|
|
|
precision = /[%]$/.test(fright) ? 2 : 3; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (var len = fright.length; i < len; i++) { |
|
|
|
for (let len = fright.length; i < len; i++) { |
|
|
|
if ((ch = fright.charAt(i)) == "0" || ch == "#") { |
|
|
|
if ((ch = fright.charAt(i)) == "0" || ch == "#") { |
|
|
|
precision++; |
|
|
|
precision++; |
|
|
|
} |
|
|
|
} |
|
|
@ -179,7 +181,7 @@ |
|
|
|
* 数字格式 |
|
|
|
* 数字格式 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function _numberFormat(text, format) { |
|
|
|
function _numberFormat(text, format) { |
|
|
|
var text = text + ""; |
|
|
|
text = text + ""; |
|
|
|
|
|
|
|
|
|
|
|
//在调用数字格式的时候如果text里没有任何数字则不处理
|
|
|
|
//在调用数字格式的时候如果text里没有任何数字则不处理
|
|
|
|
if (!(/[0-9]/.test(text)) || !format) { |
|
|
|
if (!(/[0-9]/.test(text)) || !format) { |
|
|
@ -187,12 +189,12 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 数字格式,区分正负数
|
|
|
|
// 数字格式,区分正负数
|
|
|
|
var numMod = format.indexOf(";"); |
|
|
|
const numMod = format.indexOf(";"); |
|
|
|
if (numMod > -1) { |
|
|
|
if (numMod > -1) { |
|
|
|
if (text >= 0) { |
|
|
|
if (text >= 0) { |
|
|
|
return _numberFormat(text + "", format.substring(0, numMod)); |
|
|
|
return _numberFormat(text + "", format.substring(0, numMod)); |
|
|
|
} |
|
|
|
} |
|
|
|
return _numberFormat((-text) + "", format.substr(numMod + 1)); |
|
|
|
return _numberFormat((-text) + "", format.substring(numMod + 1)); |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// 兼容格式处理负数的情况(copy:fr-jquery.format.js)
|
|
|
|
// 兼容格式处理负数的情况(copy:fr-jquery.format.js)
|
|
|
@ -201,19 +203,19 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var fp = format.split("."), fleft = fp[0] || "", fright = fp[1] || ""; |
|
|
|
const fp = format.split("."), fleft = fp[0] || "", fright = fp[1] || ""; |
|
|
|
text = _dealNumberPrecision(text, fright); |
|
|
|
text = _dealNumberPrecision(text, fright); |
|
|
|
var tp = text.split("."), tleft = tp[0] || "", tright = tp[1] || ""; |
|
|
|
let tp = text.split("."), tleft = tp[0] || "", tright = tp[1] || ""; |
|
|
|
|
|
|
|
|
|
|
|
// 百分比,千分比的小数点移位处理
|
|
|
|
// 百分比,千分比的小数点移位处理
|
|
|
|
if (/[%‰]$/.test(format)) { |
|
|
|
if (/[%‰]$/.test(format)) { |
|
|
|
var paddingZero = /[%]$/.test(format) ? "00" : "000"; |
|
|
|
const paddingZero = /[%]$/.test(format) ? "00" : "000"; |
|
|
|
tright += paddingZero; |
|
|
|
tright += paddingZero; |
|
|
|
tleft += tright.substr(0, paddingZero.length); |
|
|
|
tleft += tright.substring(0, paddingZero.length); |
|
|
|
tleft = tleft.replace(/^0+/gi, ""); |
|
|
|
tleft = tleft.replace(/^0+/gi, ""); |
|
|
|
tright = tright.substr(paddingZero.length).replace(/0+$/gi, ""); |
|
|
|
tright = tright.substring(paddingZero.length).replace(/0+$/gi, ""); |
|
|
|
} |
|
|
|
} |
|
|
|
var right = _dealWithRight(tright, fright); |
|
|
|
let right = _dealWithRight(tright, fright); |
|
|
|
if (right.leftPlus) { |
|
|
|
if (right.leftPlus) { |
|
|
|
// 小数点后有进位
|
|
|
|
// 小数点后有进位
|
|
|
|
tleft = parseInt(tleft) + 1 + ""; |
|
|
|
tleft = parseInt(tleft) + 1 + ""; |
|
|
@ -221,7 +223,7 @@ |
|
|
|
tleft = isNaN(tleft) ? "1" : tleft; |
|
|
|
tleft = isNaN(tleft) ? "1" : tleft; |
|
|
|
} |
|
|
|
} |
|
|
|
right = right.num; |
|
|
|
right = right.num; |
|
|
|
var left = _dealWithLeft(tleft, fleft); |
|
|
|
let left = _dealWithLeft(tleft, fleft); |
|
|
|
if (!(/[0-9]/.test(left))) { |
|
|
|
if (!(/[0-9]/.test(left))) { |
|
|
|
left = left + "0"; |
|
|
|
left = left + "0"; |
|
|
|
} |
|
|
|
} |
|
|
@ -240,10 +242,10 @@ |
|
|
|
* @private |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function _dealWithRight(tright, fright) { |
|
|
|
function _dealWithRight(tright, fright) { |
|
|
|
var right = "", j = 0, i = 0; |
|
|
|
let right = "", j = 0, i = 0; |
|
|
|
for (var len = fright.length; i < len; i++) { |
|
|
|
for (let len = fright.length; i < len; i++) { |
|
|
|
var ch = fright.charAt(i); |
|
|
|
const ch = fright.charAt(i); |
|
|
|
var c = tright.charAt(j); |
|
|
|
let c = tright.charAt(j); |
|
|
|
switch (ch) { |
|
|
|
switch (ch) { |
|
|
|
case "0": |
|
|
|
case "0": |
|
|
|
if (isEmpty(c)) { |
|
|
|
if (isEmpty(c)) { |
|
|
@ -261,21 +263,21 @@ |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
var rll = tright.substr(j); |
|
|
|
const rll = tright.substring(j); |
|
|
|
var result = {}; |
|
|
|
const result = {}; |
|
|
|
if (!isEmpty(rll) && rll.charAt(0) > 4) { |
|
|
|
if (!isEmpty(rll) && rll.charAt(0) > 4) { |
|
|
|
// 有多余字符,需要四舍五入
|
|
|
|
// 有多余字符,需要四舍五入
|
|
|
|
result.leftPlus = true; |
|
|
|
result.leftPlus = true; |
|
|
|
var numReg = right.match(/^[0-9]+/); |
|
|
|
const numReg = right.match(/^[0-9]+/); |
|
|
|
if (numReg) { |
|
|
|
if (numReg) { |
|
|
|
var num = numReg[0]; |
|
|
|
const num = numReg[0]; |
|
|
|
var orilen = num.length; |
|
|
|
const orilen = num.length; |
|
|
|
var newnum = parseInt(num) + 1 + ""; |
|
|
|
let newnum = parseInt(num) + 1 + ""; |
|
|
|
// 进位到整数部分
|
|
|
|
// 进位到整数部分
|
|
|
|
if (newnum.length > orilen) { |
|
|
|
if (newnum.length > orilen) { |
|
|
|
newnum = newnum.substr(1); |
|
|
|
newnum = newnum.substring(1); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
newnum = BI.leftPad(newnum, orilen, "0"); |
|
|
|
newnum = leftPad(newnum, orilen, "0"); |
|
|
|
result.leftPlus = false; |
|
|
|
result.leftPlus = false; |
|
|
|
} |
|
|
|
} |
|
|
|
right = right.replace(/^[0-9]+/, newnum); |
|
|
|
right = right.replace(/^[0-9]+/, newnum); |
|
|
@ -293,13 +295,14 @@ |
|
|
|
* @private |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function _dealWithLeft(tleft, fleft) { |
|
|
|
function _dealWithLeft(tleft, fleft) { |
|
|
|
var left = ""; |
|
|
|
let newstr; |
|
|
|
var j = tleft.length - 1; |
|
|
|
let left = ""; |
|
|
|
var combo = -1, last = -1; |
|
|
|
let j = tleft.length - 1; |
|
|
|
var i = fleft.length - 1; |
|
|
|
let combo = -1, last = -1; |
|
|
|
|
|
|
|
let i = fleft.length - 1; |
|
|
|
for (; i >= 0; i--) { |
|
|
|
for (; i >= 0; i--) { |
|
|
|
var ch = fleft.charAt(i); |
|
|
|
const ch = fleft.charAt(i); |
|
|
|
var c = tleft.charAt(j); |
|
|
|
let c = tleft.charAt(j); |
|
|
|
switch (ch) { |
|
|
|
switch (ch) { |
|
|
|
case "0": |
|
|
|
case "0": |
|
|
|
if (isEmpty(c)) { |
|
|
|
if (isEmpty(c)) { |
|
|
@ -317,7 +320,7 @@ |
|
|
|
case ",": |
|
|
|
case ",": |
|
|
|
if (!isEmpty(c)) { |
|
|
|
if (!isEmpty(c)) { |
|
|
|
// 计算一个,分隔区间的长度
|
|
|
|
// 计算一个,分隔区间的长度
|
|
|
|
var com = fleft.match(/,[#0]+/); |
|
|
|
const com = fleft.match(/,[#0]+/); |
|
|
|
if (com) { |
|
|
|
if (com) { |
|
|
|
combo = com[0].length - 1; |
|
|
|
combo = com[0].length - 1; |
|
|
|
} |
|
|
|
} |
|
|
@ -331,19 +334,20 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
if (last > -1) { |
|
|
|
if (last > -1) { |
|
|
|
// 处理剩余字符
|
|
|
|
// 处理剩余字符
|
|
|
|
var tll = tleft.substr(0, j + 1); |
|
|
|
const tll = tleft.substring(0, j + 1); |
|
|
|
left = left.substr(0, last) + tll + left.substr(last); |
|
|
|
left = left.substring(0, last) + tll + left.substring(last); |
|
|
|
} |
|
|
|
} |
|
|
|
if (combo > 0) { |
|
|
|
if (combo > 0) { |
|
|
|
// 处理,分隔区间
|
|
|
|
// 处理,分隔区间
|
|
|
|
var res = left.match(/[0-9]+,/); |
|
|
|
let res = left.match(/[0-9]+,/); |
|
|
|
if (res) { |
|
|
|
if (res) { |
|
|
|
res = res[0]; |
|
|
|
res = res[0]; |
|
|
|
var newstr = "", n = res.length - 1 - combo; |
|
|
|
newstr = ""; |
|
|
|
|
|
|
|
let n = res.length - 1 - combo; |
|
|
|
for (; n >= 0; n = n - combo) { |
|
|
|
for (; n >= 0; n = n - combo) { |
|
|
|
newstr = res.substr(n, combo) + "," + newstr; |
|
|
|
newstr = res.substring(n, combo) + "," + newstr; |
|
|
|
} |
|
|
|
} |
|
|
|
var lres = res.substr(0, n + combo); |
|
|
|
const lres = res.substring(0, n + combo); |
|
|
|
if (!isEmpty(lres)) { |
|
|
|
if (!isEmpty(lres)) { |
|
|
|
newstr = lres + "," + newstr; |
|
|
|
newstr = lres + "," + newstr; |
|
|
|
} |
|
|
|
} |
|
|
@ -353,16 +357,15 @@ |
|
|
|
return left; |
|
|
|
return left; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const cjkEncode = function (text) { |
|
|
|
BI.cjkEncode = function (text) { |
|
|
|
|
|
|
|
// alex:如果非字符串,返回其本身(cjkEncode(234) 返回 ""是不对的)
|
|
|
|
// alex:如果非字符串,返回其本身(cjkEncode(234) 返回 ""是不对的)
|
|
|
|
if (typeof text !== "string") { |
|
|
|
if (typeof text !== "string") { |
|
|
|
return text; |
|
|
|
return text; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var newText = ""; |
|
|
|
let newText = ""; |
|
|
|
for (var i = 0; i < text.length; i++) { |
|
|
|
for (let i = 0; i < text.length; i++) { |
|
|
|
var code = text.charCodeAt(i); |
|
|
|
const code = text.charCodeAt(i); |
|
|
|
if (code >= 128 || code === 91 || code === 93) {// 91 is "[", 93 is "]".
|
|
|
|
if (code >= 128 || code === 91 || code === 93) {// 91 is "[", 93 is "]".
|
|
|
|
newText += "[" + code.toString(16) + "]"; |
|
|
|
newText += "[" + code.toString(16) + "]"; |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -380,22 +383,22 @@ |
|
|
|
* @param text 需要做解码的字符串 |
|
|
|
* @param text 需要做解码的字符串 |
|
|
|
* @return {String} 解码后的字符串 |
|
|
|
* @return {String} 解码后的字符串 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
BI.cjkDecode = function (text) { |
|
|
|
export const cjkDecode = function (text) { |
|
|
|
if (text == null) { |
|
|
|
if (text == null) { |
|
|
|
return ""; |
|
|
|
return ""; |
|
|
|
} |
|
|
|
} |
|
|
|
// 查找没有 "[", 直接返回. kunsnat:数字的时候, 不支持indexOf方法, 也是直接返回.
|
|
|
|
// 查找没有 "[", 直接返回. kunsnat:数字的时候, 不支持indexOf方法, 也是直接返回.
|
|
|
|
if (!isNaN(text) || text.indexOf("[") == -1) { |
|
|
|
if (!isNaN(text) || text.indexOf("[") === -1) { |
|
|
|
return text; |
|
|
|
return text; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var newText = ""; |
|
|
|
let newText = ""; |
|
|
|
for (var i = 0; i < text.length; i++) { |
|
|
|
for (let i = 0; i < text.length; i++) { |
|
|
|
var ch = text.charAt(i); |
|
|
|
let ch = text.charAt(i); |
|
|
|
if (ch == "[") { |
|
|
|
if (ch === "[") { |
|
|
|
var rightIdx = text.indexOf("]", i + 1); |
|
|
|
const rightIdx = text.indexOf("]", i + 1); |
|
|
|
if (rightIdx > i + 1) { |
|
|
|
if (rightIdx > i + 1) { |
|
|
|
var subText = text.substring(i + 1, rightIdx); |
|
|
|
const subText = text.substring(i + 1, rightIdx); |
|
|
|
// james:主要是考虑[CDATA[]]这样的值的出现
|
|
|
|
// james:主要是考虑[CDATA[]]这样的值的出现
|
|
|
|
if (subText.length > 0) { |
|
|
|
if (subText.length > 0) { |
|
|
|
ch = String.fromCharCode(eval("0x" + subText)); |
|
|
|
ch = String.fromCharCode(eval("0x" + subText)); |
|
|
@ -412,22 +415,22 @@ |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// replace the html special tags
|
|
|
|
// replace the html special tags
|
|
|
|
var SPECIAL_TAGS = { |
|
|
|
const SPECIAL_TAGS = { |
|
|
|
"&": "&", |
|
|
|
"&": "&", |
|
|
|
"\"": """, |
|
|
|
"\"": """, |
|
|
|
"<": "<", |
|
|
|
"<": "<", |
|
|
|
">": ">", |
|
|
|
">": ">", |
|
|
|
"\x20": " ", |
|
|
|
"\x20": " ", |
|
|
|
"\n": " " |
|
|
|
"\n": " ", |
|
|
|
}; |
|
|
|
}; |
|
|
|
BI.htmlEncode = function (text) { |
|
|
|
export const htmlEncode = function (text) { |
|
|
|
return BI.isNull(text) ? "" : BI.replaceAll(text + "", BI.keys(SPECIAL_TAGS).join("|"), function (v) { |
|
|
|
return isNull(text) ? "" : replaceAll(text + "", keys(SPECIAL_TAGS).join("|"), function (v) { |
|
|
|
return SPECIAL_TAGS[v] ? SPECIAL_TAGS[v] : v; |
|
|
|
return SPECIAL_TAGS[v] ? SPECIAL_TAGS[v] : v; |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|
}; |
|
|
|
// html decode
|
|
|
|
// html decode
|
|
|
|
BI.htmlDecode = function (text) { |
|
|
|
export const htmlDecode = function (text) { |
|
|
|
return BI.isNull(text) ? "" : BI.replaceAll(text + "", BI.values(SPECIAL_TAGS).join("|"), function (v) { |
|
|
|
return isNull(text) ? "" : replaceAll(text + "", values(SPECIAL_TAGS).join("|"), function (v) { |
|
|
|
switch (v) { |
|
|
|
switch (v) { |
|
|
|
case "&": |
|
|
|
case "&": |
|
|
|
return "&"; |
|
|
|
return "&"; |
|
|
@ -447,43 +450,43 @@ |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
BI.cjkEncodeDO = function (o) { |
|
|
|
export const cjkEncodeDO = function (o) { |
|
|
|
if (BI.isPlainObject(o)) { |
|
|
|
if (isPlainObject(o)) { |
|
|
|
var result = {}; |
|
|
|
const result = {}; |
|
|
|
BI._.each(o, function (v, k) { |
|
|
|
each(o, function (v, k) { |
|
|
|
if (!(typeof v === "string")) { |
|
|
|
if (!(typeof v === "string")) { |
|
|
|
v = BI.jsonEncode(v); |
|
|
|
v = jsonEncode(v); |
|
|
|
} |
|
|
|
} |
|
|
|
// wei:bug 43338,如果key是中文,cjkencode后o的长度就加了1,ie9以下版本死循环,所以新建对象result。
|
|
|
|
// wei:bug 43338,如果key是中文,cjkencode后o的长度就加了1,ie9以下版本死循环,所以新建对象result。
|
|
|
|
k = BI.cjkEncode(k); |
|
|
|
k = cjkEncode(k); |
|
|
|
result[k] = BI.cjkEncode(v); |
|
|
|
result[k] = cjkEncode(v); |
|
|
|
}); |
|
|
|
}); |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
return o; |
|
|
|
return o; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
BI.jsonEncode = function (o) { |
|
|
|
export const jsonEncode = function (o) { |
|
|
|
// james:这个Encode是抄的EXT的
|
|
|
|
// james:这个Encode是抄的EXT的
|
|
|
|
var useHasOwn = !!{}.hasOwnProperty; |
|
|
|
const useHasOwn = !!{}.hasOwnProperty; |
|
|
|
|
|
|
|
|
|
|
|
// crashes Safari in some instances
|
|
|
|
// crashes Safari in some instances
|
|
|
|
// var validRE = /^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/;
|
|
|
|
// var validRE = /^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/;
|
|
|
|
|
|
|
|
|
|
|
|
var m = { |
|
|
|
const m = { |
|
|
|
"\b": "\\b", |
|
|
|
"\b": "\\b", |
|
|
|
"\t": "\\t", |
|
|
|
"\t": "\\t", |
|
|
|
"\n": "\\n", |
|
|
|
"\n": "\\n", |
|
|
|
"\f": "\\f", |
|
|
|
"\f": "\\f", |
|
|
|
"\r": "\\r", |
|
|
|
"\r": "\\r", |
|
|
|
"\"": "\\\"", |
|
|
|
"\"": "\\\"", |
|
|
|
"\\": "\\\\" |
|
|
|
"\\": "\\\\", |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var encodeString = function (s) { |
|
|
|
const encodeString = function (s) { |
|
|
|
if (/["\\\x00-\x1f]/.test(s)) { |
|
|
|
if (/["\\\x00-\x1f]/.test(s)) { |
|
|
|
return "\"" + s.replace(/([\x00-\x1f\\"])/g, function (a, b) { |
|
|
|
return "\"" + s.replace(/([\x00-\x1f\\"])/g, function (a, b) { |
|
|
|
var c = m[b]; |
|
|
|
let c = m[b]; |
|
|
|
if (c) { |
|
|
|
if (c) { |
|
|
|
return c; |
|
|
|
return c; |
|
|
|
} |
|
|
|
} |
|
|
@ -496,8 +499,8 @@ |
|
|
|
return "\"" + s + "\""; |
|
|
|
return "\"" + s + "\""; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var encodeArray = function (o) { |
|
|
|
const encodeArray = function (o) { |
|
|
|
var a = ["["], b, i, l = o.length, v; |
|
|
|
let a = ["["], b, i, l = o.length, v; |
|
|
|
for (i = 0; i < l; i += 1) { |
|
|
|
for (i = 0; i < l; i += 1) { |
|
|
|
v = o[i]; |
|
|
|
v = o[i]; |
|
|
|
switch (typeof v) { |
|
|
|
switch (typeof v) { |
|
|
@ -509,7 +512,7 @@ |
|
|
|
if (b) { |
|
|
|
if (b) { |
|
|
|
a.push(","); |
|
|
|
a.push(","); |
|
|
|
} |
|
|
|
} |
|
|
|
a.push(v === null ? "null" : BI.jsonEncode(v)); |
|
|
|
a.push(v === null ? "null" : jsonEncode(v)); |
|
|
|
b = true; |
|
|
|
b = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -519,15 +522,15 @@ |
|
|
|
|
|
|
|
|
|
|
|
if (typeof o === "undefined" || o === null) { |
|
|
|
if (typeof o === "undefined" || o === null) { |
|
|
|
return "null"; |
|
|
|
return "null"; |
|
|
|
} else if (BI.isArray(o)) { |
|
|
|
} else if (isArray(o)) { |
|
|
|
return encodeArray(o); |
|
|
|
return encodeArray(o); |
|
|
|
} else if (o instanceof Date) { |
|
|
|
} else if (o instanceof Date) { |
|
|
|
/* |
|
|
|
/* |
|
|
|
* alex:原来只是把年月日时分秒简单地拼成一个String,无法decode |
|
|
|
* alex:原来只是把年月日时分秒简单地拼成一个String,无法decode |
|
|
|
* 现在这么处理就可以decode了,但是JS.jsonDecode和Java.JSONObject也要跟着改一下 |
|
|
|
* 现在这么处理就可以decode了,但是JS.jsonDecode和Java.JSONObject也要跟着改一下 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
return BI.jsonEncode({ |
|
|
|
return jsonEncode({ |
|
|
|
__time__: o.getTime() |
|
|
|
__time__: o.getTime(), |
|
|
|
}); |
|
|
|
}); |
|
|
|
} else if (typeof o === "string") { |
|
|
|
} else if (typeof o === "string") { |
|
|
|
return encodeString(o); |
|
|
|
return encodeString(o); |
|
|
@ -535,10 +538,10 @@ |
|
|
|
return isFinite(o) ? String(o) : "null"; |
|
|
|
return isFinite(o) ? String(o) : "null"; |
|
|
|
} else if (typeof o === "boolean") { |
|
|
|
} else if (typeof o === "boolean") { |
|
|
|
return String(o); |
|
|
|
return String(o); |
|
|
|
} else if (BI.isFunction(o)) { |
|
|
|
} else if (isFunction(o)) { |
|
|
|
return String(o); |
|
|
|
return String(o); |
|
|
|
} |
|
|
|
} |
|
|
|
var a = ["{"], b, i, v; |
|
|
|
let a = ["{"], b, i, v; |
|
|
|
for (i in o) { |
|
|
|
for (i in o) { |
|
|
|
if (!useHasOwn || o.hasOwnProperty(i)) { |
|
|
|
if (!useHasOwn || o.hasOwnProperty(i)) { |
|
|
|
v = o[i]; |
|
|
|
v = o[i]; |
|
|
@ -550,8 +553,8 @@ |
|
|
|
if (b) { |
|
|
|
if (b) { |
|
|
|
a.push(","); |
|
|
|
a.push(","); |
|
|
|
} |
|
|
|
} |
|
|
|
a.push(BI.jsonEncode(i), ":", |
|
|
|
a.push(jsonEncode(i), ":", |
|
|
|
v === null ? "null" : BI.jsonEncode(v)); |
|
|
|
v === null ? "null" : jsonEncode(v)); |
|
|
|
b = true; |
|
|
|
b = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -561,12 +564,11 @@ |
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
BI.jsonDecode = function (text) { |
|
|
|
export const jsonDecode = function (text) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let jo; |
|
|
|
try { |
|
|
|
try { |
|
|
|
// 注意0啊
|
|
|
|
jo = JSON.parse(text); |
|
|
|
// var jo = $.parseJSON(text) || {};
|
|
|
|
|
|
|
|
var jo = BI.$ ? BI.$.parseJSON(text) : _global.JSON.parse(text); |
|
|
|
|
|
|
|
if (jo == null) { |
|
|
|
if (jo == null) { |
|
|
|
jo = {}; |
|
|
|
jo = {}; |
|
|
|
} |
|
|
|
} |
|
|
@ -592,21 +594,21 @@ |
|
|
|
if (!json || typeof json !== "string") { |
|
|
|
if (!json || typeof json !== "string") { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
return json.indexOf("__time__") != -1; |
|
|
|
return json.indexOf("__time__") !== -1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return (function (o) { |
|
|
|
return (function parse(o) { |
|
|
|
if (typeof o === "string") { |
|
|
|
if (typeof o === "string") { |
|
|
|
return o; |
|
|
|
return o; |
|
|
|
} |
|
|
|
} |
|
|
|
if (o && o.__time__ != null) { |
|
|
|
if (o && o.__time__ != null) { |
|
|
|
return new Date(o.__time__); |
|
|
|
return new Date(o.__time__); |
|
|
|
} |
|
|
|
} |
|
|
|
for (var a in o) { |
|
|
|
for (const a in o) { |
|
|
|
if (o[a] == o || typeof o[a] === "object" || BI._.isFunction(o[a])) { |
|
|
|
if (o[a] === o || typeof o[a] === "object" || isFunction(o[a])) { |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
o[a] = arguments.callee(o[a]); |
|
|
|
o[a] = parse(o[a]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return o; |
|
|
|
return o; |
|
|
@ -621,16 +623,16 @@ |
|
|
|
* @example |
|
|
|
* @example |
|
|
|
* BI.getEncodeURL("design/{tableName}/{fieldName}",{tableName: "A", fieldName: "a"}) // design/A/a
|
|
|
|
* BI.getEncodeURL("design/{tableName}/{fieldName}",{tableName: "A", fieldName: "a"}) // design/A/a
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
BI.getEncodeURL = function (urlTemplate, param) { |
|
|
|
export const getEncodeURL = function (urlTemplate, param) { |
|
|
|
return BI.replaceAll(urlTemplate, "\\{(.*?)\\}", function (ori, str) { |
|
|
|
return replaceAll(urlTemplate, "\\{(.*?)\\}", function (ori, str) { |
|
|
|
return BI.encodeURIComponent(BI.isObject(param) ? param[str] : param); |
|
|
|
return encodeURIComponent(isObject(param) ? param[str] : param); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
BI.encodeURIComponent = function (url) { |
|
|
|
export const encodeURIComponent = function (url) { |
|
|
|
BI.specialCharsMap = BI.specialCharsMap || {}; |
|
|
|
BI.specialCharsMap = BI.specialCharsMap || {}; |
|
|
|
url = url || ""; |
|
|
|
url = url || ""; |
|
|
|
url = BI.replaceAll(url + "", BI.keys(BI.specialCharsMap || []).join("|"), function (str) { |
|
|
|
url = replaceAll(url + "", keys(BI.specialCharsMap || []).join("|"), function (str) { |
|
|
|
switch (str) { |
|
|
|
switch (str) { |
|
|
|
case "\\": |
|
|
|
case "\\": |
|
|
|
return BI.specialCharsMap["\\\\"] || str; |
|
|
|
return BI.specialCharsMap["\\\\"] || str; |
|
|
@ -641,24 +643,24 @@ |
|
|
|
return _global.encodeURIComponent(url); |
|
|
|
return _global.encodeURIComponent(url); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
BI.decodeURIComponent = function (url) { |
|
|
|
export const decodeURIComponent = function (url) { |
|
|
|
var reserveSpecialCharsMap = {}; |
|
|
|
const reserveSpecialCharsMap = {}; |
|
|
|
BI.each(BI.specialCharsMap, function (initialChar, encodeChar) { |
|
|
|
each(BI.specialCharsMap, function (initialChar, encodeChar) { |
|
|
|
reserveSpecialCharsMap[encodeChar] = initialChar === "\\\\" ? "\\" : initialChar; |
|
|
|
reserveSpecialCharsMap[encodeChar] = initialChar === "\\\\" ? "\\" : initialChar; |
|
|
|
}); |
|
|
|
}); |
|
|
|
url = url || ""; |
|
|
|
url = url || ""; |
|
|
|
url = BI.replaceAll(url + "", BI.keys(reserveSpecialCharsMap || []).join("|"), function (str) { |
|
|
|
url = replaceAll(url + "", keys(reserveSpecialCharsMap || []).join("|"), function (str) { |
|
|
|
return reserveSpecialCharsMap[str] || str; |
|
|
|
return reserveSpecialCharsMap[str] || str; |
|
|
|
}); |
|
|
|
}); |
|
|
|
return _global.decodeURIComponent(url); |
|
|
|
return _global.decodeURIComponent(url); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
BI.contentFormat = function (cv, fmt) { |
|
|
|
export const contentFormat = function (cv, fmt) { |
|
|
|
if (isEmpty(cv)) { |
|
|
|
if (isEmpty(cv)) { |
|
|
|
// 原值为空,返回空字符
|
|
|
|
// 原值为空,返回空字符
|
|
|
|
return ""; |
|
|
|
return ""; |
|
|
|
} |
|
|
|
} |
|
|
|
var text = cv.toString(); |
|
|
|
let text = cv.toString(); |
|
|
|
if (isEmpty(fmt)) { |
|
|
|
if (isEmpty(fmt)) { |
|
|
|
// 格式为空,返回原字符
|
|
|
|
// 格式为空,返回原字符
|
|
|
|
return text; |
|
|
|
return text; |
|
|
@ -677,9 +679,9 @@ |
|
|
|
cv = new Date(Date.parse(("" + cv).replace(/-|\./g, "/"))); |
|
|
|
cv = new Date(Date.parse(("" + cv).replace(/-|\./g, "/"))); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (!isInvalidDate(cv) && !BI.isNull(cv)) { |
|
|
|
if (!isInvalidDate(cv) && !isNull(cv)) { |
|
|
|
var needTrim = fmt.match(/^DT/); |
|
|
|
const needTrim = fmt.match(/^DT/); |
|
|
|
text = BI.date2Str(cv, fmt.substring(needTrim ? 2 : 1)); |
|
|
|
text = date2Str(cv, fmt.substring(needTrim ? 2 : 1)); |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (fmt.match(/E/)) { |
|
|
|
} else if (fmt.match(/E/)) { |
|
|
|
// 科学计数格式
|
|
|
|
// 科学计数格式
|
|
|
@ -695,11 +697,10 @@ |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 将Java提供的日期格式字符串装换为JS识别的日期格式字符串 |
|
|
|
* 将Java提供的日期格式字符串装换为JS识别的日期格式字符串 |
|
|
|
* @class FR.parseFmt |
|
|
|
|
|
|
|
* @param fmt 日期格式 |
|
|
|
* @param fmt 日期格式 |
|
|
|
* @returns {String} |
|
|
|
* @returns {string} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
BI.parseFmt = function (fmt) { |
|
|
|
export const parseFmt = function (fmt) { |
|
|
|
if (!fmt) { |
|
|
|
if (!fmt) { |
|
|
|
return ""; |
|
|
|
return ""; |
|
|
|
} |
|
|
|
} |
|
|
@ -743,47 +744,42 @@ |
|
|
|
* |
|
|
|
* |
|
|
|
* @example |
|
|
|
* @example |
|
|
|
* var result = BI.str2Date('2013-12-12', 'yyyy-MM-dd');//Thu Dec 12 2013 00:00:00 GMT+0800
|
|
|
|
* var result = BI.str2Date('2013-12-12', 'yyyy-MM-dd');//Thu Dec 12 2013 00:00:00 GMT+0800
|
|
|
|
* |
|
|
|
|
|
|
|
* @class BI.str2Date |
|
|
|
|
|
|
|
* @param str 字符串 |
|
|
|
* @param str 字符串 |
|
|
|
* @param format 日期格式 |
|
|
|
* @param format 日期格式 |
|
|
|
* @returns {*} |
|
|
|
* @returns {Date} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
BI.str2Date = function (str, format) { |
|
|
|
export const str2Date = function (str, format) { |
|
|
|
if (typeof str != "string" || typeof format != "string") { |
|
|
|
if (typeof str != "string" || typeof format != "string") { |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
var fmt = BI.parseFmt(format); |
|
|
|
const fmt = parseFmt(format); |
|
|
|
return BI.parseDateTime(str, fmt); |
|
|
|
return parseDateTime(str, fmt); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 把日期对象按照指定格式转化成字符串 |
|
|
|
* 把日期对象按照指定格式转化成字符串 |
|
|
|
* |
|
|
|
|
|
|
|
*@example |
|
|
|
*@example |
|
|
|
* var date = new Date('Thu Dec 12 2013 00:00:00 GMT+0800'); |
|
|
|
* var date = new Date('Thu Dec 12 2013 00:00:00 GMT+0800'); |
|
|
|
* var result = BI.date2Str(date, 'yyyy-MM-dd');//2013-12-12
|
|
|
|
* var result = BI.date2Str(date, 'yyyy-MM-dd');//2013-12-12
|
|
|
|
* |
|
|
|
* @param date |
|
|
|
* @class BI.date2Str |
|
|
|
* @param format |
|
|
|
* @param date 日期 |
|
|
|
* @returns {string} |
|
|
|
* @param format 日期格式 |
|
|
|
|
|
|
|
* @returns {String} |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
BI.date2Str = function (date, format) { |
|
|
|
export const date2Str = function (date, format) { |
|
|
|
if (!date) { |
|
|
|
if (!date) { |
|
|
|
return ""; |
|
|
|
return ""; |
|
|
|
} |
|
|
|
} |
|
|
|
// O(len(format))
|
|
|
|
// O(len(format))
|
|
|
|
var len = format.length, result = ""; |
|
|
|
let len = format.length, result = ""; |
|
|
|
if (len > 0) { |
|
|
|
if (len > 0) { |
|
|
|
var flagch = format.charAt(0), start = 0, str = flagch; |
|
|
|
let flagch = format.charAt(0), start = 0, str = flagch; |
|
|
|
for (var i = 1; i < len; i++) { |
|
|
|
for (let i = 1; i < len; i++) { |
|
|
|
var ch = format.charAt(i); |
|
|
|
const ch = format.charAt(i); |
|
|
|
if (flagch !== ch) { |
|
|
|
if (flagch !== ch) { |
|
|
|
result += compileJFmt({ |
|
|
|
result += compileJFmt({ |
|
|
|
char: flagch, |
|
|
|
char: flagch, |
|
|
|
str: str, |
|
|
|
str: str, |
|
|
|
len: i - start |
|
|
|
len: i - start, |
|
|
|
}, date); |
|
|
|
}, date); |
|
|
|
flagch = ch; |
|
|
|
flagch = ch; |
|
|
|
start = i; |
|
|
|
start = i; |
|
|
@ -795,16 +791,16 @@ |
|
|
|
result += compileJFmt({ |
|
|
|
result += compileJFmt({ |
|
|
|
char: flagch, |
|
|
|
char: flagch, |
|
|
|
str: str, |
|
|
|
str: str, |
|
|
|
len: len - start |
|
|
|
len: len - start, |
|
|
|
}, date); |
|
|
|
}, date); |
|
|
|
} |
|
|
|
} |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
|
|
|
|
|
|
|
|
function compileJFmt(jfmt, date) { |
|
|
|
function compileJFmt(jfmt, date) { |
|
|
|
var str = jfmt.str, len = jfmt.len, ch = jfmt["char"]; |
|
|
|
let str = jfmt.str, len = jfmt.len, ch = jfmt["char"]; |
|
|
|
switch (ch) { |
|
|
|
switch (ch) { |
|
|
|
case "E": // 星期
|
|
|
|
case "E": // 星期
|
|
|
|
str = BI.getFullDayName(date.getDay()); |
|
|
|
str = getFullDayName(date.getDay()); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case "y": // 年
|
|
|
|
case "y": // 年
|
|
|
|
if (len <= 3) { |
|
|
|
if (len <= 3) { |
|
|
@ -815,48 +811,48 @@ |
|
|
|
break; |
|
|
|
break; |
|
|
|
case "M": // 月
|
|
|
|
case "M": // 月
|
|
|
|
if (len > 2) { |
|
|
|
if (len > 2) { |
|
|
|
str = BI.getMonthName(date.getMonth()); |
|
|
|
str = getMonthName(date.getMonth()); |
|
|
|
} else if (len < 2) { |
|
|
|
} else if (len < 2) { |
|
|
|
str = date.getMonth() + 1; |
|
|
|
str = date.getMonth() + 1; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
str = BI.leftPad(date.getMonth() + 1 + "", 2, "0"); |
|
|
|
str = leftPad(date.getMonth() + 1 + "", 2, "0"); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case "d": // 日
|
|
|
|
case "d": // 日
|
|
|
|
if (len > 1) { |
|
|
|
if (len > 1) { |
|
|
|
str = BI.leftPad(date.getDate() + "", 2, "0"); |
|
|
|
str = leftPad(date.getDate() + "", 2, "0"); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
str = date.getDate(); |
|
|
|
str = date.getDate(); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case "h": // 时(12)
|
|
|
|
case "h": // 时(12)
|
|
|
|
var hour = date.getHours() % 12; |
|
|
|
let hour = date.getHours() % 12; |
|
|
|
if (hour === 0) { |
|
|
|
if (hour === 0) { |
|
|
|
hour = 12; |
|
|
|
hour = 12; |
|
|
|
} |
|
|
|
} |
|
|
|
if (len > 1) { |
|
|
|
if (len > 1) { |
|
|
|
str = BI.leftPad(hour + "", 2, "0"); |
|
|
|
str = leftPad(hour + "", 2, "0"); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
str = hour; |
|
|
|
str = hour; |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case "H": // 时(24)
|
|
|
|
case "H": // 时(24)
|
|
|
|
if (len > 1) { |
|
|
|
if (len > 1) { |
|
|
|
str = BI.leftPad(date.getHours() + "", 2, "0"); |
|
|
|
str = leftPad(date.getHours() + "", 2, "0"); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
str = date.getHours(); |
|
|
|
str = date.getHours(); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case "m": |
|
|
|
case "m": |
|
|
|
if (len > 1) { |
|
|
|
if (len > 1) { |
|
|
|
str = BI.leftPad(date.getMinutes() + "", 2, "0"); |
|
|
|
str = leftPad(date.getMinutes() + "", 2, "0"); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
str = date.getMinutes(); |
|
|
|
str = date.getMinutes(); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case "s": |
|
|
|
case "s": |
|
|
|
if (len > 1) { |
|
|
|
if (len > 1) { |
|
|
|
str = BI.leftPad(date.getSeconds() + "", 2, "0"); |
|
|
|
str = leftPad(date.getSeconds() + "", 2, "0"); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
str = date.getSeconds(); |
|
|
|
str = date.getSeconds(); |
|
|
|
} |
|
|
|
} |
|
|
@ -865,7 +861,7 @@ |
|
|
|
str = date.getHours() < 12 ? "am" : "pm"; |
|
|
|
str = date.getHours() < 12 ? "am" : "pm"; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case "z": |
|
|
|
case "z": |
|
|
|
str = BI.getTimezone(date); |
|
|
|
str = getTimezone(date); |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
str = jfmt.str; |
|
|
|
str = jfmt.str; |
|
|
@ -875,21 +871,21 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
BI.object2Number = function (value) { |
|
|
|
export const object2Number = function (value) { |
|
|
|
if (value == null) { |
|
|
|
if (value == null) { |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
if (typeof value === "number") { |
|
|
|
if (typeof value === "number") { |
|
|
|
return value; |
|
|
|
return value; |
|
|
|
} |
|
|
|
} |
|
|
|
var str = value + ""; |
|
|
|
const str = value + ""; |
|
|
|
if (str.indexOf(".") === -1) { |
|
|
|
if (str.indexOf(".") === -1) { |
|
|
|
return parseInt(str); |
|
|
|
return parseInt(str); |
|
|
|
} |
|
|
|
} |
|
|
|
return parseFloat(str); |
|
|
|
return parseFloat(str); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
BI.object2Date = function (obj) { |
|
|
|
export const object2Date = function (obj) { |
|
|
|
if (obj == null) { |
|
|
|
if (obj == null) { |
|
|
|
return new Date(); |
|
|
|
return new Date(); |
|
|
|
} |
|
|
|
} |
|
|
@ -898,9 +894,9 @@ |
|
|
|
} else if (typeof obj === "number") { |
|
|
|
} else if (typeof obj === "number") { |
|
|
|
return new Date(obj); |
|
|
|
return new Date(obj); |
|
|
|
} |
|
|
|
} |
|
|
|
var str = obj + ""; |
|
|
|
let str = obj + ""; |
|
|
|
str = str.replace(/-/g, "/"); |
|
|
|
str = str.replace(/-/g, "/"); |
|
|
|
var dt = new Date(str); |
|
|
|
const dt = new Date(str); |
|
|
|
if (!isInvalidDate(dt)) { |
|
|
|
if (!isInvalidDate(dt)) { |
|
|
|
return dt; |
|
|
|
return dt; |
|
|
|
} |
|
|
|
} |
|
|
@ -909,16 +905,16 @@ |
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
BI.object2Time = function (obj) { |
|
|
|
export const object2Time = function (obj) { |
|
|
|
if (obj == null) { |
|
|
|
if (obj == null) { |
|
|
|
return new Date(); |
|
|
|
return new Date(); |
|
|
|
} |
|
|
|
} |
|
|
|
if (obj instanceof Date) { |
|
|
|
if (obj instanceof Date) { |
|
|
|
return obj; |
|
|
|
return obj; |
|
|
|
} |
|
|
|
} |
|
|
|
var str = obj + ""; |
|
|
|
let str = obj + ""; |
|
|
|
str = str.replace(/-/g, "/"); |
|
|
|
str = str.replace(/-/g, "/"); |
|
|
|
var dt = new Date(str); |
|
|
|
let dt = new Date(str); |
|
|
|
if (!isInvalidDate(dt)) { |
|
|
|
if (!isInvalidDate(dt)) { |
|
|
|
return dt; |
|
|
|
return dt; |
|
|
|
} |
|
|
|
} |
|
|
@ -928,11 +924,10 @@ |
|
|
|
return dt; |
|
|
|
return dt; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
dt = BI.parseDateTime(str, "HH:mm:ss"); |
|
|
|
dt = parseDateTime(str, "HH:mm:ss"); |
|
|
|
if (!isInvalidDate(dt)) { |
|
|
|
if (!isInvalidDate(dt)) { |
|
|
|
return dt; |
|
|
|
return dt; |
|
|
|
} |
|
|
|
} |
|
|
|
return new Date(); |
|
|
|
return new Date(); |
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
})(); |
|
|
|
|
|
|
|