From d1a50163e4d445bc8451cf68cf0791caf7c410e0 Mon Sep 17 00:00:00 2001 From: qin <a@163.com> Date: 星期一, 01 四月 2024 14:18:12 +0800 Subject: [PATCH] 优化代码 --- IStation.Web.LargeScreen/Scripts/common.js | 44 +++++++++++++++++++++++++------------------- 1 files changed, 25 insertions(+), 19 deletions(-) diff --git a/IStation.Web.LargeScreen/Scripts/common.js b/IStation.Web.LargeScreen/Scripts/common.js index 326dff3..9607e82 100644 --- a/IStation.Web.LargeScreen/Scripts/common.js +++ b/IStation.Web.LargeScreen/Scripts/common.js @@ -1,6 +1,6 @@ 锘�/*鍜屼笟鍔℃湁鍏崇殑杈呭姪绫�*/ class IStationCommon { - + static getCorpID() { var corpID = ""; @@ -31,17 +31,17 @@ return themeType; } } - + } /*鍜屼笟鍔℃棤鍏崇殑杈呭姪绫�*/ class Utils { constructor() { } - - + + /*妫�娴嬬被鍚�*/ - static hasClassStyle(ele, name) { + static hasClassStyle(ele, name) { return ele.className.match(new RegExp('(\\s|^)' + name + '(\\s|$)')); } @@ -75,7 +75,7 @@ } return eleMatch; } - + //鍒涘缓瀛樺偍鍞竴閿悕鐨勫嚱鏁� static createUniqueKey() { return new Date().getTime() + Math.random(); @@ -134,7 +134,7 @@ return false } } - static isPC() { //鏄惁涓篜C绔� + static isPC() { //鏄惁涓篜C绔� var userAgentInfo = navigator.userAgent; var Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", @@ -220,7 +220,13 @@ - + /** + * 鏍煎紡鍖栨暟瀛� 瑙e喅灏忔暟绮惧害 瑙e喅涓�鑸棶棰� + * @param {any} n + */ + static formatNumber(n) { + return parseFloat(parseFloat(n).toFixed(12)) + } @@ -345,7 +351,7 @@ * * @example formatTime('2018-1-29', 'yyyy-MM-dd hh:mm:ss') // -> 2018/01/29 00:00:00 */ - static formatTime(template, date) { + static formatTime(template, date) { var today = date ? new Date(date) : new Date(); var o = { "M+": today.getMonth() + 1, //鏈堜唤 @@ -377,7 +383,7 @@ * * @example formatTime('2018-1-29', '{y}/{m}/{d} {h}:{i}:{s}') // -> 2018/01/29 00:00:00 */ - static formatTime2(time, cFormat) { + static formatTime2(time, cFormat) { if (arguments.length === 0) return null if ((time + '').length === 10) { time = +time * 1000 @@ -538,7 +544,7 @@ static containsInArray(arr, val) { return arr.indexOf(val) != -1 ? true : false; } - + /** * @param {arr} 鏁扮粍 * @param {type} 1锛氫粠灏忓埌澶� 2锛氫粠澶у埌灏� 3锛氶殢鏈� @@ -599,7 +605,7 @@ return arr; } - + /*鏈�澶у��*/ static maxInArray(arr) { @@ -707,7 +713,7 @@ } /*杩囨护html浠g爜(鎶�<>杞崲)*/ - static filterHtmlTag(str) { + static filterHtmlTag(str) { str = str.replace(/&/ig, "&"); str = str.replace(/</ig, "<"); str = str.replace(/>/ig, ">"); @@ -749,7 +755,7 @@ return 0; if (value > 100) - return value.toFixed(1); + return value.toFixed(1); else if (value > 10) return value.toFixed(2); else @@ -995,7 +1001,7 @@ } /*鍒犻櫎cookie*/ - static removeCookie(name) { + static removeCookie(name) { this.setCookie(name, 1, -1); } @@ -1024,7 +1030,7 @@ } /*绉婚櫎鎵�鏈塴ocalStorage*/ - static clearLocalStorage() { + static clearLocalStorage() { window.localStorage.clear() } @@ -1060,7 +1066,7 @@ } - + //鑾峰彇瀹㈡埛绔痠p鍦板潃闇�鍒涘缓id涓篴ddress鐨勬爣绛� static getYourIP() { @@ -1170,7 +1176,7 @@ //Other /*鑾峰彇缃戝潃鍙傛暟,name涓虹綉鍧�涓殑鍙傛暟閿��*/ - static getURL(name) { + static getURL(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) return r[2]; return null; @@ -1195,7 +1201,7 @@ } /*鍒犻櫎url鎸囧畾鍙傛暟锛岃繑鍥瀠rl*/ - static delParamsUrl(url, name) { + static delParamsUrl(url, name) { var baseUrl = url.split('?')[0] + '?'; var query = url.split('?')[1]; if (query.indexOf(name) > -1) { -- Gitblit v1.9.3