@jrj-front-end/tools
Version:
jrj前端工具包
211 lines (210 loc) • 7.57 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Jrjobject = void 0;
// Jrjobject
var moment_1 = __importDefault(require("moment"));
var Jrjobject = /** @class */ (function () {
function Jrjobject(jsonObj) {
this.key = '';
this.type = '';
this.id = 0;
this.mogokey = '';
this.hasChild = false;
this.id = 0;
this.type = '';
this.properties = {};
if (jsonObj != null) {
this.type = jsonObj.type || '';
this.id = jsonObj.id || 0;
this.properties = jsonObj.properties;
this.hasChild = jsonObj.hasChild || false;
}
}
Jrjobject.prototype.GetDeletePropObj = function () {
var obj = new Jrjobject();
obj.type = this.type;
obj.id = this.id;
return obj;
};
Jrjobject.prototype.toShortObj = function () {
var shortObj = new Jrjobject();
shortObj.id = this.id;
shortObj.type = this.type;
return shortObj;
};
Jrjobject.prototype.spCopy = function (obj) {
this.type = obj.type;
this.id = obj.id;
this.key = obj.key;
this.properties = JSON.parse(JSON.stringify(obj.properties));
this.hasChild = obj.hasChild;
return this;
};
Jrjobject.prototype.copy = function (obj) {
this.type = obj.type;
this.id = obj.id;
this.key = obj.key;
this.properties = obj.properties;
this.hasChild = obj.hasChild;
return this;
};
Jrjobject.prototype.hasProp = function (prop) {
return Object.prototype.hasOwnProperty.call(this.properties, prop);
};
Jrjobject.prototype.copyProp = function (obj) {
this.properties = obj.properties;
};
Jrjobject.prototype.appendProp = function (obj) {
for (var key in obj.properties) {
if (this.properties[key.toLocaleLowerCase()] == null) {
this.SetValue(key, obj.properties[key]);
}
else {
}
}
};
Jrjobject.prototype.overRideProp = function (obj) {
for (var key in obj.properties) {
this.SetValue(key, obj.properties[key]);
}
};
Jrjobject.prototype.addPropSuffix = function (obj, suffix) {
for (var key in obj.properties) {
this.SetValue(key + suffix, obj.properties[key]);
}
};
Jrjobject.prototype.SetValue = function (key, value) {
this.properties[key.toLocaleLowerCase()] = value;
};
Jrjobject.prototype.SetObjValue = function (key, obj) {
this.properties[key.toLocaleLowerCase()] = obj;
};
Jrjobject.prototype.SetBool = function (key, value) {
if (value) {
this.properties[key.toLocaleLowerCase()] = '1';
}
else {
this.properties[key.toLocaleLowerCase()] = '0';
}
};
Jrjobject.prototype.SetNumber = function (key, value) {
this.SetValue(key, value.toString());
};
Jrjobject.prototype.GetPropVal = function (key) {
if (key.length == 0) {
return '';
}
if (this.properties[key] != null) {
return this.properties[key];
}
if (this.properties[key.toLocaleLowerCase()] != null) {
return this.properties[key.toLocaleLowerCase()];
}
if (this.properties[key.toLocaleUpperCase()] != null) {
return this.properties[key.toLocaleUpperCase()];
}
return '';
};
Jrjobject.prototype.GetMomentTime = function (key) {
if (key.length == 0) {
return (0, moment_1.default)(new Date());
}
if (this.properties[key] != null && this.properties[key].length != 0) {
return (0, moment_1.default)(this.properties[key]);
}
if (this.properties[key.toLocaleLowerCase()] != null &&
this.properties[key.toLocaleLowerCase()].length != 0) {
return (0, moment_1.default)(this.properties[key.toLocaleLowerCase()]);
}
if (this.properties[key.toLocaleUpperCase()] != null &&
this.properties[key.toLocaleUpperCase()].length != 0) {
return (0, moment_1.default)(this.properties[key.toLocaleUpperCase()]);
}
return (0, moment_1.default)(new Date());
};
Jrjobject.prototype.GetPropTime = function (key, format) {
if (key.length == 0) {
return '';
}
if (this.properties[key] != null && this.properties[key].length != 0) {
return format
? (0, moment_1.default)(this.properties[key]).format(format)
: (0, moment_1.default)(this.properties[key]).format('YYYY-MM-DD');
}
if (this.properties[key.toLocaleLowerCase()] != null &&
this.properties[key.toLocaleLowerCase()].length != 0) {
return format
? (0, moment_1.default)(this.properties[key.toLocaleLowerCase()]).format(format)
: (0, moment_1.default)(this.properties[key.toLocaleLowerCase()]).format('YYYY-MM-DD');
}
if (this.properties[key.toLocaleUpperCase()] != null &&
this.properties[key.toLocaleUpperCase()].length != 0) {
return format
? (0, moment_1.default)(this.properties[key.toLocaleUpperCase()]).format(format)
: (0, moment_1.default)(this.properties[key]).format('YYYY-MM-DD');
}
return '';
};
Jrjobject.prototype.GetPropInt = function (key) {
var num = 0;
if (this.properties[key] != null) {
num = parseInt(this.properties[key]);
}
if (this.properties[key.toLocaleLowerCase()] != null) {
num = parseInt(this.properties[key.toLocaleLowerCase()]);
}
if (isNaN(num)) {
num = 0;
}
return num;
};
Jrjobject.prototype.GetPropFloat = function (key) {
var num = 0;
if (this.properties[key] != null) {
num = parseFloat(this.properties[key]);
}
if (this.properties[key.toLocaleLowerCase()] != null) {
num = parseFloat(this.properties[key.toLocaleLowerCase()]);
}
if (isNaN(num)) {
num = 0;
}
return num;
};
Jrjobject.prototype.GetPropFloatPrecise = function (key, precise) {
var num = 0;
var valStr = '';
if (this.properties[key] != null) {
valStr = this.properties[key];
num = parseFloat(parseFloat(this.properties[key]).toFixed(precise));
}
if (this.properties[key.toLocaleLowerCase()] != null) {
valStr = this.properties[key.toLocaleLowerCase()];
num = parseFloat(parseFloat(this.properties[key.toLocaleLowerCase()]).toFixed(precise));
}
if (precise == null) {
num = parseFloat(valStr);
}
else {
num = parseFloat(parseFloat(valStr).toFixed(precise));
}
if (isNaN(num)) {
num = 0;
}
return num;
};
Jrjobject.prototype.GetPropBool = function (key) {
var val = this.GetPropVal(key);
if (val.toLocaleLowerCase() == '1'.toLocaleLowerCase()) {
return true;
}
else {
return false;
}
};
return Jrjobject;
}());
exports.Jrjobject = Jrjobject;