export default class { /** * 返回本地化 * * @static * @param {number} iLangCode * @returns {string} */ static upLang(iLangCode: number): string { let lang = { "12001": "确定", "12002": "取消", "12003": "关闭", "12041": "选择日期", "12191": "请选择", "12192": "选择相册", "12193": "拍照", "12201": "暂无数据", "12301": "未定义正则错误", "12302": "不能为空", "12303": "必须为数字", "12304": "格式错误", "12310":"更新失败,请联系技术" } return lang[iLangCode]; } /** * 返回对象是否不为空 * * @static * @param {any} oObject * @returns {boolean} */ static flagNull(oObject): boolean { return oObject != undefined && oObject != null; } /** * 对象如果未定义 返回默认值 * * @static * @param {any} oObject * @param {any} oDefault * @returns {*} */ static objectNullDefault(oObject, oDefault): any { return this.flagNull(oObject) ? oObject : oDefault; } /** * 字符串默认值 * * @static * @param {any} sString * @param {any} sDefault * @returns */ static stringEmptyDefault(sString, sDefault) { if (!sString) { sString = sDefault; } return sString; } static stringIsEmpty(cs) { return cs == undefined || cs == null || cs.length == 0; } static stringSplit(sSource) { let aSourceArray = sSource.split(','); if (this.stringIsEmpty(sSource)) { aSourceArray = []; } return aSourceArray; } /** * 字符串逗号分隔的操作 * * @static * @param {string} sSource * @param {string} sInText * @param {number} iOption 5为判断是否存在如果存在返回intext否则返回空 1为添加 4为删除 3为自动增删 * @returns {(boolean | string)} */ static stringArrayOption(sSource: string, sInText: string, iOption: number): string { let oReturn: boolean = false; let aSourceArray = this.stringSplit(sSource); let iNowIndex = -1; for (let i = 0, j = aSourceArray.length; i < j; i++) { if (aSourceArray[i] === sInText) { oReturn = true; iNowIndex = i; } } //如果是判断是否存在 则直接返回存在结果 if (iOption == 5) { return oReturn ? sInText : ''; } if (iOption === 1 || iOption === 3) { if (!oReturn) { aSourceArray.push(sInText); } } if (iOption === 4 || iOption === 3) { if (oReturn) { aSourceArray.splice(iNowIndex, 1); } } return aSourceArray.join(','); } static mapToObject(oMap: Map) { let oReturn = {}; oMap.forEach((v, k) => oReturn[k] = v); return oReturn; } static stringToMap(sParm) { let oReturn = new Map(); sParm.split('&').forEach((fItem) => { if (!this.stringIsEmpty(fItem)) { let sKey = fItem.split('=')[0]; let sValue = fItem.substr(sKey.length + 1); oReturn.set(sKey, sValue); } }); return oReturn; } static replaceWithObject(sInput: string, oObject: any) { var re = new RegExp("\\[\\w*\\]", "gi"); var sReturn = sInput; var aExec = sReturn.match(re); if (aExec != null) { for (var i = 0; i < aExec.length; i++) { var sMathText = aExec[i]; var aSplit = sMathText.replace('[', '').replace(']', ''); let sVal = ''; if (oObject[aSplit] != undefined) { sVal = oObject[aSplit]; } sReturn = sReturn.replace(sMathText, sVal); } } return sReturn; } }