|
|
|
@ -1,35 +1,37 @@
|
|
|
|
|
(function () { |
|
|
|
|
var _global; |
|
|
|
|
if (typeof window !== "undefined") { |
|
|
|
|
import {each, isFunction, isNull, isObject, isPlainObject, keys, leftPad, parseDateTime, values} from "../2.base"; |
|
|
|
|
import {replaceAll} from "./string"; |
|
|
|
|
import {getFullDayName, getMonthName, getTimezone} from "./date"; |
|
|
|
|
|
|
|
|
|
var _global; |
|
|
|
|
if (typeof window !== "undefined") { |
|
|
|
|
_global = window; |
|
|
|
|
} else if (typeof global !== "undefined") { |
|
|
|
|
} else if (typeof global !== "undefined") { |
|
|
|
|
_global = global; |
|
|
|
|
} else if (typeof self !== "undefined") { |
|
|
|
|
} else if (typeof self !== "undefined") { |
|
|
|
|
_global = self; |
|
|
|
|
} else { |
|
|
|
|
} else { |
|
|
|
|
_global = this; |
|
|
|
|
} |
|
|
|
|
if (!_global.BI) { |
|
|
|
|
} |
|
|
|
|
if (!_global.BI) { |
|
|
|
|
_global.BI = {}; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function isEmpty (value) { |
|
|
|
|
function isEmpty(value) { |
|
|
|
|
// 判断是否为空值
|
|
|
|
|
var result = value === "" || value === null || value === undefined; |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
return value === "" || value === null || value === undefined; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 判断是否是无效的日期
|
|
|
|
|
function isInvalidDate (date) { |
|
|
|
|
return date == "Invalid Date" || date == "NaN"; |
|
|
|
|
} |
|
|
|
|
// 判断是否是无效的日期
|
|
|
|
|
function isInvalidDate(date) { |
|
|
|
|
return date === "Invalid Date" || date === "NaN"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
/** |
|
|
|
|
* CHART-1400 |
|
|
|
|
* 使用数值计算的方式来获取任意数值的科学技术表示值。 |
|
|
|
|
* 科学计数格式 |
|
|
|
|
*/ |
|
|
|
|
function _eFormat (text, fmt) { |
|
|
|
|
function _eFormat(text, fmt) { |
|
|
|
|
text = +text; |
|
|
|
|
|
|
|
|
|
return eFormat(text, fmt); |
|
|
|
@ -44,7 +46,7 @@
|
|
|
|
|
* 数量级没有规定,因为没见过实数里有用科学计数法表示之后E的后面会小于一位的情况(0无所谓)。 |
|
|
|
|
* @returns {*} |
|
|
|
|
*/ |
|
|
|
|
function eFormat (num, format) { |
|
|
|
|
function eFormat(num, format) { |
|
|
|
|
var neg = num < 0 ? (num *= -1, "-") : "", |
|
|
|
|
magnitudeNeg = ""; |
|
|
|
|
|
|
|
|
@ -90,7 +92,7 @@
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 获取format格式规定的数量级的形式
|
|
|
|
|
function formatExponential (format, num, magnitudeNeg) { |
|
|
|
|
function formatExponential(format, num, magnitudeNeg) { |
|
|
|
|
num += ""; |
|
|
|
|
if (!/e/ig.test(format)) { |
|
|
|
|
return num; |
|
|
|
@ -115,7 +117,7 @@
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 获取format规定的科学计数法精确到的位数
|
|
|
|
|
function getPrecision (format) { |
|
|
|
|
function getPrecision(format) { |
|
|
|
|
if (!/e/ig.test(format)) { |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
@ -126,7 +128,7 @@
|
|
|
|
|
|
|
|
|
|
// 获取数值科学计数法表示之后整数的位数
|
|
|
|
|
// 这边我们还需要考虑#和0的问题
|
|
|
|
|
function getInteger (magnitude, format) { |
|
|
|
|
function getInteger(magnitude, format) { |
|
|
|
|
if (!/e/ig.test(format)) { |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
@ -147,16 +149,16 @@
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 判断num通过round函数之后是否有进位
|
|
|
|
|
function isValueCarried (num) { |
|
|
|
|
function isValueCarried(num) { |
|
|
|
|
var roundNum = Math.round(num); |
|
|
|
|
num = (num + "").split(".")[0]; |
|
|
|
|
roundNum = (roundNum + "").split(".")[0]; |
|
|
|
|
return num.length !== roundNum.length; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//'#.##'之类的格式处理 1.324e-18 这种的科学数字
|
|
|
|
|
function _dealNumberPrecision (text, fright) { |
|
|
|
|
//'#.##'之类的格式处理 1.324e-18 这种的科学数字
|
|
|
|
|
function _dealNumberPrecision(text, fright) { |
|
|
|
|
if (/[eE]/.test(text)) { |
|
|
|
|
var precision = 0, i = 0, ch; |
|
|
|
|
|
|
|
|
@ -173,12 +175,12 @@
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return text; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
/** |
|
|
|
|
* 数字格式 |
|
|
|
|
*/ |
|
|
|
|
function _numberFormat (text, format) { |
|
|
|
|
function _numberFormat(text, format) { |
|
|
|
|
var text = text + ""; |
|
|
|
|
|
|
|
|
|
//在调用数字格式的时候如果text里没有任何数字则不处理
|
|
|
|
@ -192,7 +194,7 @@
|
|
|
|
|
if (text >= 0) { |
|
|
|
|
return _numberFormat(text + "", format.substring(0, numMod)); |
|
|
|
|
} |
|
|
|
|
return _numberFormat((-text) + "", format.substr(numMod + 1)); |
|
|
|
|
return _numberFormat((-text) + "", format.substring(numMod + 1)); |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
// 兼容格式处理负数的情况(copy:fr-jquery.format.js)
|
|
|
|
@ -209,9 +211,9 @@
|
|
|
|
|
if (/[%‰]$/.test(format)) { |
|
|
|
|
var paddingZero = /[%]$/.test(format) ? "00" : "000"; |
|
|
|
|
tright += paddingZero; |
|
|
|
|
tleft += tright.substr(0, paddingZero.length); |
|
|
|
|
tleft += tright.substring(0, paddingZero.length); |
|
|
|
|
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); |
|
|
|
|
if (right.leftPlus) { |
|
|
|
@ -230,16 +232,16 @@
|
|
|
|
|
} else { |
|
|
|
|
return left + "." + right; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
/** |
|
|
|
|
* 处理小数点右边小数部分 |
|
|
|
|
* @param tright 右边内容 |
|
|
|
|
* @param fright 右边格式 |
|
|
|
|
* @returns {JSON} 返回处理结果和整数部分是否需要进位 |
|
|
|
|
* @private |
|
|
|
|
*/ |
|
|
|
|
function _dealWithRight (tright, fright) { |
|
|
|
|
function _dealWithRight(tright, fright) { |
|
|
|
|
var right = "", j = 0, i = 0; |
|
|
|
|
for (var len = fright.length; i < len; i++) { |
|
|
|
|
var ch = fright.charAt(i); |
|
|
|
@ -261,7 +263,7 @@
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
var rll = tright.substr(j); |
|
|
|
|
var rll = tright.substring(j); |
|
|
|
|
var result = {}; |
|
|
|
|
if (!isEmpty(rll) && rll.charAt(0) > 4) { |
|
|
|
|
// 有多余字符,需要四舍五入
|
|
|
|
@ -273,9 +275,9 @@
|
|
|
|
|
var newnum = parseInt(num) + 1 + ""; |
|
|
|
|
// 进位到整数部分
|
|
|
|
|
if (newnum.length > orilen) { |
|
|
|
|
newnum = newnum.substr(1); |
|
|
|
|
newnum = newnum.substring(1); |
|
|
|
|
} else { |
|
|
|
|
newnum = BI.leftPad(newnum, orilen, "0"); |
|
|
|
|
newnum = leftPad(newnum, orilen, "0"); |
|
|
|
|
result.leftPlus = false; |
|
|
|
|
} |
|
|
|
|
right = right.replace(/^[0-9]+/, newnum); |
|
|
|
@ -283,16 +285,16 @@
|
|
|
|
|
} |
|
|
|
|
result.num = right; |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
/** |
|
|
|
|
* 处理小数点左边整数部分 |
|
|
|
|
* @param tleft 左边内容 |
|
|
|
|
* @param fleft 左边格式 |
|
|
|
|
* @returns {string} 返回处理结果 |
|
|
|
|
* @private |
|
|
|
|
*/ |
|
|
|
|
function _dealWithLeft (tleft, fleft) { |
|
|
|
|
function _dealWithLeft(tleft, fleft) { |
|
|
|
|
var left = ""; |
|
|
|
|
var j = tleft.length - 1; |
|
|
|
|
var combo = -1, last = -1; |
|
|
|
@ -331,8 +333,8 @@
|
|
|
|
|
} |
|
|
|
|
if (last > -1) { |
|
|
|
|
// 处理剩余字符
|
|
|
|
|
var tll = tleft.substr(0, j + 1); |
|
|
|
|
left = left.substr(0, last) + tll + left.substr(last); |
|
|
|
|
var tll = tleft.substring(0, j + 1); |
|
|
|
|
left = left.substring(0, last) + tll + left.substring(last); |
|
|
|
|
} |
|
|
|
|
if (combo > 0) { |
|
|
|
|
// 处理,分隔区间
|
|
|
|
@ -341,9 +343,9 @@
|
|
|
|
|
res = res[0]; |
|
|
|
|
var newstr = "", n = res.length - 1 - 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); |
|
|
|
|
var lres = res.substring(0, n + combo); |
|
|
|
|
if (!isEmpty(lres)) { |
|
|
|
|
newstr = lres + "," + newstr; |
|
|
|
|
} |
|
|
|
@ -351,10 +353,9 @@
|
|
|
|
|
left = left.replace(/[0-9]+,/, newstr); |
|
|
|
|
} |
|
|
|
|
return left; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BI.cjkEncode = function (text) { |
|
|
|
|
export const cjkEncode = function (text) { |
|
|
|
|
// alex:如果非字符串,返回其本身(cjkEncode(234) 返回 ""是不对的)
|
|
|
|
|
if (typeof text !== "string") { |
|
|
|
|
return text; |
|
|
|
@ -371,16 +372,16 @@
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return newText; |
|
|
|
|
}; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
/** |
|
|
|
|
* 将cjkEncode处理过的字符串转化为原始字符串 |
|
|
|
|
* |
|
|
|
|
* @static |
|
|
|
|
* @param text 需要做解码的字符串 |
|
|
|
|
* @return {String} 解码后的字符串 |
|
|
|
|
*/ |
|
|
|
|
BI.cjkDecode = function (text) { |
|
|
|
|
export const cjkDecode = function (text) { |
|
|
|
|
if (text == null) { |
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
@ -409,25 +410,25 @@
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return newText; |
|
|
|
|
}; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// replace the html special tags
|
|
|
|
|
var SPECIAL_TAGS = { |
|
|
|
|
// replace the html special tags
|
|
|
|
|
const SPECIAL_TAGS = { |
|
|
|
|
"&": "&", |
|
|
|
|
"\"": """, |
|
|
|
|
"<": "<", |
|
|
|
|
">": ">", |
|
|
|
|
"\x20": " ", |
|
|
|
|
"\n": " " |
|
|
|
|
}; |
|
|
|
|
BI.htmlEncode = function (text) { |
|
|
|
|
return BI.isNull(text) ? "" : BI.replaceAll(text + "", BI.keys(SPECIAL_TAGS).join("|"), function (v) { |
|
|
|
|
}; |
|
|
|
|
export const htmlEncode = function (text) { |
|
|
|
|
return isNull(text) ? "" : replaceAll(text + "", keys(SPECIAL_TAGS).join("|"), function (v) { |
|
|
|
|
return SPECIAL_TAGS[v] ? SPECIAL_TAGS[v] : v; |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
// html decode
|
|
|
|
|
BI.htmlDecode = function (text) { |
|
|
|
|
return BI.isNull(text) ? "" : BI.replaceAll(text + "", BI.values(SPECIAL_TAGS).join("|"), function (v) { |
|
|
|
|
}; |
|
|
|
|
// html decode
|
|
|
|
|
export const htmlDecode = function (text) { |
|
|
|
|
return isNull(text) ? "" : replaceAll(text + "", values(SPECIAL_TAGS).join("|"), function (v) { |
|
|
|
|
switch (v) { |
|
|
|
|
case "&": |
|
|
|
|
return "&"; |
|
|
|
@ -445,25 +446,25 @@
|
|
|
|
|
return v; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
BI.cjkEncodeDO = function (o) { |
|
|
|
|
if (BI.isPlainObject(o)) { |
|
|
|
|
export const cjkEncodeDO = function (o) { |
|
|
|
|
if (isPlainObject(o)) { |
|
|
|
|
var result = {}; |
|
|
|
|
BI._.each(o, function (v, k) { |
|
|
|
|
each(o, function (v, k) { |
|
|
|
|
if (!(typeof v === "string")) { |
|
|
|
|
v = BI.jsonEncode(v); |
|
|
|
|
v = jsonEncode(v); |
|
|
|
|
} |
|
|
|
|
// wei:bug 43338,如果key是中文,cjkencode后o的长度就加了1,ie9以下版本死循环,所以新建对象result。
|
|
|
|
|
k = BI.cjkEncode(k); |
|
|
|
|
result[k] = BI.cjkEncode(v); |
|
|
|
|
k = cjkEncode(k); |
|
|
|
|
result[k] = cjkEncode(v); |
|
|
|
|
}); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
return o; |
|
|
|
|
}; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
BI.jsonEncode = function (o) { |
|
|
|
|
export const jsonEncode = function (o) { |
|
|
|
|
// james:这个Encode是抄的EXT的
|
|
|
|
|
var useHasOwn = !!{}.hasOwnProperty; |
|
|
|
|
|
|
|
|
@ -509,7 +510,7 @@
|
|
|
|
|
if (b) { |
|
|
|
|
a.push(","); |
|
|
|
|
} |
|
|
|
|
a.push(v === null ? "null" : BI.jsonEncode(v)); |
|
|
|
|
a.push(v === null ? "null" : jsonEncode(v)); |
|
|
|
|
b = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -519,14 +520,14 @@
|
|
|
|
|
|
|
|
|
|
if (typeof o === "undefined" || o === null) { |
|
|
|
|
return "null"; |
|
|
|
|
} else if (BI.isArray(o)) { |
|
|
|
|
} else if (isArray(o)) { |
|
|
|
|
return encodeArray(o); |
|
|
|
|
} else if (o instanceof Date) { |
|
|
|
|
/* |
|
|
|
|
* alex:原来只是把年月日时分秒简单地拼成一个String,无法decode |
|
|
|
|
* 现在这么处理就可以decode了,但是JS.jsonDecode和Java.JSONObject也要跟着改一下 |
|
|
|
|
*/ |
|
|
|
|
return BI.jsonEncode({ |
|
|
|
|
return jsonEncode({ |
|
|
|
|
__time__: o.getTime() |
|
|
|
|
}); |
|
|
|
|
} else if (typeof o === "string") { |
|
|
|
@ -535,7 +536,7 @@
|
|
|
|
|
return isFinite(o) ? String(o) : "null"; |
|
|
|
|
} else if (typeof o === "boolean") { |
|
|
|
|
return String(o); |
|
|
|
|
} else if (BI.isFunction(o)) { |
|
|
|
|
} else if (isFunction(o)) { |
|
|
|
|
return String(o); |
|
|
|
|
} |
|
|
|
|
var a = ["{"], b, i, v; |
|
|
|
@ -550,8 +551,8 @@
|
|
|
|
|
if (b) { |
|
|
|
|
a.push(","); |
|
|
|
|
} |
|
|
|
|
a.push(BI.jsonEncode(i), ":", |
|
|
|
|
v === null ? "null" : BI.jsonEncode(v)); |
|
|
|
|
a.push(jsonEncode(i), ":", |
|
|
|
|
v === null ? "null" : jsonEncode(v)); |
|
|
|
|
b = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -559,14 +560,12 @@
|
|
|
|
|
a.push("}"); |
|
|
|
|
return a.join(""); |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
BI.jsonDecode = function (text) { |
|
|
|
|
export const jsonDecode = function (text) { |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
// 注意0啊
|
|
|
|
|
// var jo = $.parseJSON(text) || {};
|
|
|
|
|
var jo = BI.$ ? BI.$.parseJSON(text) : _global.JSON.parse(text); |
|
|
|
|
var jo = JSON.parse(text); |
|
|
|
|
if (jo == null) { |
|
|
|
|
jo = {}; |
|
|
|
|
} |
|
|
|
@ -588,14 +587,14 @@
|
|
|
|
|
return jo; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function _hasDateInJson (json) { |
|
|
|
|
function _hasDateInJson(json) { |
|
|
|
|
if (!json || typeof json !== "string") { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
return json.indexOf("__time__") != -1; |
|
|
|
|
return json.indexOf("__time__") !== -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return (function (o) { |
|
|
|
|
return (function parse(o) { |
|
|
|
|
if (typeof o === "string") { |
|
|
|
|
return o; |
|
|
|
|
} |
|
|
|
@ -603,17 +602,17 @@
|
|
|
|
|
return new Date(o.__time__); |
|
|
|
|
} |
|
|
|
|
for (var 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; |
|
|
|
|
} |
|
|
|
|
o[a] = arguments.callee(o[a]); |
|
|
|
|
o[a] = parse(o[a]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return o; |
|
|
|
|
})(jo); |
|
|
|
|
}; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
/** |
|
|
|
|
* 获取编码后的url |
|
|
|
|
* @param urlTemplate url模板 |
|
|
|
|
* @param param 参数 |
|
|
|
@ -621,16 +620,16 @@
|
|
|
|
|
* @example |
|
|
|
|
* BI.getEncodeURL("design/{tableName}/{fieldName}",{tableName: "A", fieldName: "a"}) // design/A/a
|
|
|
|
|
*/ |
|
|
|
|
BI.getEncodeURL = function (urlTemplate, param) { |
|
|
|
|
return BI.replaceAll(urlTemplate, "\\{(.*?)\\}", function (ori, str) { |
|
|
|
|
return BI.encodeURIComponent(BI.isObject(param) ? param[str] : param); |
|
|
|
|
export const getEncodeURL = function (urlTemplate, param) { |
|
|
|
|
return replaceAll(urlTemplate, "\\{(.*?)\\}", function (ori, str) { |
|
|
|
|
return encodeURIComponent(isObject(param) ? param[str] : param); |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
BI.encodeURIComponent = function (url) { |
|
|
|
|
export const encodeURIComponent = function (url) { |
|
|
|
|
BI.specialCharsMap = BI.specialCharsMap || {}; |
|
|
|
|
url = url || ""; |
|
|
|
|
url = BI.replaceAll(url + "", BI.keys(BI.specialCharsMap || []).join("|"), function (str) { |
|
|
|
|
url = replaceAll(url + "", keys(BI.specialCharsMap || []).join("|"), function (str) { |
|
|
|
|
switch (str) { |
|
|
|
|
case "\\": |
|
|
|
|
return BI.specialCharsMap["\\\\"] || str; |
|
|
|
@ -639,21 +638,21 @@
|
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
return _global.encodeURIComponent(url); |
|
|
|
|
}; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
BI.decodeURIComponent = function (url) { |
|
|
|
|
export const decodeURIComponent = function (url) { |
|
|
|
|
var reserveSpecialCharsMap = {}; |
|
|
|
|
BI.each(BI.specialCharsMap, function (initialChar, encodeChar) { |
|
|
|
|
each(BI.specialCharsMap, function (initialChar, encodeChar) { |
|
|
|
|
reserveSpecialCharsMap[encodeChar] = initialChar === "\\\\" ? "\\" : initialChar; |
|
|
|
|
}); |
|
|
|
|
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 _global.decodeURIComponent(url); |
|
|
|
|
}; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
BI.contentFormat = function (cv, fmt) { |
|
|
|
|
export const contentFormat = function (cv, fmt) { |
|
|
|
|
if (isEmpty(cv)) { |
|
|
|
|
// 原值为空,返回空字符
|
|
|
|
|
return ""; |
|
|
|
@ -677,9 +676,9 @@
|
|
|
|
|
cv = new Date(Date.parse(("" + cv).replace(/-|\./g, "/"))); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (!isInvalidDate(cv) && !BI.isNull(cv)) { |
|
|
|
|
if (!isInvalidDate(cv) && !isNull(cv)) { |
|
|
|
|
var 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/)) { |
|
|
|
|
// 科学计数格式
|
|
|
|
@ -691,15 +690,14 @@
|
|
|
|
|
// ¤ - 货币格式
|
|
|
|
|
text = text.replace(/¤/g, "¥"); |
|
|
|
|
return text; |
|
|
|
|
}; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
/** |
|
|
|
|
* 将Java提供的日期格式字符串装换为JS识别的日期格式字符串 |
|
|
|
|
* @class FR.parseFmt |
|
|
|
|
* @param fmt 日期格式 |
|
|
|
|
* @returns {String} |
|
|
|
|
* @returns {string} |
|
|
|
|
*/ |
|
|
|
|
BI.parseFmt = function (fmt) { |
|
|
|
|
export const parseFmt = function (fmt) { |
|
|
|
|
if (!fmt) { |
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
@ -736,40 +734,35 @@
|
|
|
|
|
.replace(/s{2,}/g, "%S"); |
|
|
|
|
|
|
|
|
|
return fmt; |
|
|
|
|
}; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
/** |
|
|
|
|
* 把字符串按照对应的格式转化成日期对象 |
|
|
|
|
* |
|
|
|
|
* @example |
|
|
|
|
* 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 format 日期格式 |
|
|
|
|
* @returns {*} |
|
|
|
|
* @returns {Date} |
|
|
|
|
*/ |
|
|
|
|
BI.str2Date = function (str, format) { |
|
|
|
|
export const str2Date = function (str, format) { |
|
|
|
|
if (typeof str != "string" || typeof format != "string") { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
var fmt = BI.parseFmt(format); |
|
|
|
|
return BI.parseDateTime(str, fmt); |
|
|
|
|
}; |
|
|
|
|
var fmt = parseFmt(format); |
|
|
|
|
return parseDateTime(str, fmt); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
/** |
|
|
|
|
* 把日期对象按照指定格式转化成字符串 |
|
|
|
|
* |
|
|
|
|
* @example |
|
|
|
|
*@example |
|
|
|
|
* var date = new Date('Thu Dec 12 2013 00:00:00 GMT+0800'); |
|
|
|
|
* var result = BI.date2Str(date, 'yyyy-MM-dd');//2013-12-12
|
|
|
|
|
* |
|
|
|
|
* @class BI.date2Str |
|
|
|
|
* @param date 日期 |
|
|
|
|
* @param format 日期格式 |
|
|
|
|
* @returns {String} |
|
|
|
|
* @param date |
|
|
|
|
* @param format |
|
|
|
|
* @returns {string} |
|
|
|
|
*/ |
|
|
|
|
BI.date2Str = function (date, format) { |
|
|
|
|
export const date2Str = function (date, format) { |
|
|
|
|
if (!date) { |
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
@ -800,11 +793,11 @@
|
|
|
|
|
} |
|
|
|
|
return result; |
|
|
|
|
|
|
|
|
|
function compileJFmt (jfmt, date) { |
|
|
|
|
function compileJFmt(jfmt, date) { |
|
|
|
|
var str = jfmt.str, len = jfmt.len, ch = jfmt["char"]; |
|
|
|
|
switch (ch) { |
|
|
|
|
case "E": // 星期
|
|
|
|
|
str = BI.getFullDayName(date.getDay()); |
|
|
|
|
str = getFullDayName(date.getDay()); |
|
|
|
|
break; |
|
|
|
|
case "y": // 年
|
|
|
|
|
if (len <= 3) { |
|
|
|
@ -815,16 +808,16 @@
|
|
|
|
|
break; |
|
|
|
|
case "M": // 月
|
|
|
|
|
if (len > 2) { |
|
|
|
|
str = BI.getMonthName(date.getMonth()); |
|
|
|
|
str = getMonthName(date.getMonth()); |
|
|
|
|
} else if (len < 2) { |
|
|
|
|
str = date.getMonth() + 1; |
|
|
|
|
} else { |
|
|
|
|
str = BI.leftPad(date.getMonth() + 1 + "", 2, "0"); |
|
|
|
|
str = leftPad(date.getMonth() + 1 + "", 2, "0"); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case "d": // 日
|
|
|
|
|
if (len > 1) { |
|
|
|
|
str = BI.leftPad(date.getDate() + "", 2, "0"); |
|
|
|
|
str = leftPad(date.getDate() + "", 2, "0"); |
|
|
|
|
} else { |
|
|
|
|
str = date.getDate(); |
|
|
|
|
} |
|
|
|
@ -835,28 +828,28 @@
|
|
|
|
|
hour = 12; |
|
|
|
|
} |
|
|
|
|
if (len > 1) { |
|
|
|
|
str = BI.leftPad(hour + "", 2, "0"); |
|
|
|
|
str = leftPad(hour + "", 2, "0"); |
|
|
|
|
} else { |
|
|
|
|
str = hour; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case "H": // 时(24)
|
|
|
|
|
if (len > 1) { |
|
|
|
|
str = BI.leftPad(date.getHours() + "", 2, "0"); |
|
|
|
|
str = leftPad(date.getHours() + "", 2, "0"); |
|
|
|
|
} else { |
|
|
|
|
str = date.getHours(); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case "m": |
|
|
|
|
if (len > 1) { |
|
|
|
|
str = BI.leftPad(date.getMinutes() + "", 2, "0"); |
|
|
|
|
str = leftPad(date.getMinutes() + "", 2, "0"); |
|
|
|
|
} else { |
|
|
|
|
str = date.getMinutes(); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case "s": |
|
|
|
|
if (len > 1) { |
|
|
|
|
str = BI.leftPad(date.getSeconds() + "", 2, "0"); |
|
|
|
|
str = leftPad(date.getSeconds() + "", 2, "0"); |
|
|
|
|
} else { |
|
|
|
|
str = date.getSeconds(); |
|
|
|
|
} |
|
|
|
@ -865,7 +858,7 @@
|
|
|
|
|
str = date.getHours() < 12 ? "am" : "pm"; |
|
|
|
|
break; |
|
|
|
|
case "z": |
|
|
|
|
str = BI.getTimezone(date); |
|
|
|
|
str = getTimezone(date); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
str = jfmt.str; |
|
|
|
@ -873,9 +866,9 @@
|
|
|
|
|
} |
|
|
|
|
return str; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
BI.object2Number = function (value) { |
|
|
|
|
export const object2Number = function (value) { |
|
|
|
|
if (value == null) { |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
@ -887,9 +880,9 @@
|
|
|
|
|
return parseInt(str); |
|
|
|
|
} |
|
|
|
|
return parseFloat(str); |
|
|
|
|
}; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
BI.object2Date = function (obj) { |
|
|
|
|
export const object2Date = function (obj) { |
|
|
|
|
if (obj == null) { |
|
|
|
|
return new Date(); |
|
|
|
|
} |
|
|
|
@ -907,9 +900,9 @@
|
|
|
|
|
|
|
|
|
|
return new Date(); |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
BI.object2Time = function (obj) { |
|
|
|
|
export const object2Time = function (obj) { |
|
|
|
|
if (obj == null) { |
|
|
|
|
return new Date(); |
|
|
|
|
} |
|
|
|
@ -928,11 +921,10 @@
|
|
|
|
|
return dt; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
dt = BI.parseDateTime(str, "HH:mm:ss"); |
|
|
|
|
dt = parseDateTime(str, "HH:mm:ss"); |
|
|
|
|
if (!isInvalidDate(dt)) { |
|
|
|
|
return dt; |
|
|
|
|
} |
|
|
|
|
return new Date(); |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
})(); |
|
|
|
|
}; |
|
|
|
|