tplus-pos
Version:
pos module
171 lines (144 loc) • 6.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _regenerator = require('babel-runtime/regenerator');
var _regenerator2 = _interopRequireDefault(_regenerator);
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
var _stringify = require('babel-runtime/core-js/json/stringify');
var _stringify2 = _interopRequireDefault(_stringify);
exports.default = operationLog;
var _OperationLogApi = require('../../api/OperationLogApi');
var _OperationLogApi2 = _interopRequireDefault(_OperationLogApi);
var _OperationConfig = require('./OperationConfig');
var _OperationConfig2 = _interopRequireDefault(_OperationConfig);
var _mobx = require('mobx');
var _isArray2 = require('lodash/isArray');
var _isArray3 = _interopRequireDefault(_isArray2);
var _isObject2 = require('lodash/isObject');
var _isObject3 = _interopRequireDefault(_isObject2);
require('../../commom/Challenger');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _toJS(obj) {
return (0, _mobx.isObservable)(obj) ? (0, _mobx.toJS)(obj) : obj;
}
function _getArgument(argsNames, argsValues) {
if (argsNames.length != argsValues.length) {
throw new Error('参数名称和参数值的长度不一致!');
}
var i = void 0,
length = argsNames.length;
var args = [];
for (i = 0; i < length; i++) {
var argValue = _toJS(argsValues[i]);
if ((0, _isObject3.default)(argValue)) {
argValue = (0, _stringify2.default)(argValue);
}
args.push('\u53C2\u6570' + (i + 1) + ' ' + argsNames[i] + ': ' + argValue);
}
return args.join(' / ');
}
function _getDesc(actionDesc, argsNames, argsValues, retailDto) {
var args = [];
var argValue = '';
try {
if (argsNames) {
argsNames.forEach(function (argName) {
if (argName.indexOf('-') > 0) {
if (retailDto) {
var rowindex = argName.split('-')[0];
var field = argName.split('-')[1];
argValue = JSON.getCellValue(retailDto.RetailDetails[argsValues[rowindex]], field);
}
} else {
argValue = _toJS(argsValues[argName]);
}
if ((0, _isObject3.default)(argValue)) {
argValue = (0, _stringify2.default)(argValue);
}
args.push(argValue);
});
} else {
if (argsValues && argsValues.length > 0) {
argValue = _toJS(argsValues[0]);
if ((0, _isObject3.default)(argValue)) {
argValue = (0, _stringify2.default)(argValue);
}
args.push(argValue);
}
}
return actionDesc.Format.apply(actionDesc, args);
} catch (e) {
console.error('获取操作日志描述信息异常');
}
return actionDesc;
}
function operationLog(actionName, actionDesc, argsNames) {
var operationItem = {};
var operationName = _OperationConfig2.default[actionName];
operationItem.name = operationName;
operationItem.docno = "";
operationItem.description = actionDesc;
// if (!_isArray(actionParamNames)) {
// throw new Error('第二个参数【方法的参数名称】应该是数组!');
// }
// 返回装饰器函数
return function (target, key, descriptor) {
var originFun = descriptor.value;
descriptor.value = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee() {
var result,
_args = arguments;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
//处理描述数据
operationItem.description = _getDesc(actionDesc, argsNames, _args, this.data);
_context.next = 3;
return originFun.apply(this, _args);
case 3:
result = _context.sent;
if (this.data) {
operationItem.docno = this.data.Code;
}
if (process.env.NODE_ENV == 'development') {
console.log(operationItem.name + '[async]\u65B9\u6CD5\u6267\u884C\u60C5\u51B5:', operationItem);
}
try {
_OperationLogApi2.default.addPosLog(operationItem.name, operationItem.docno, operationItem.description);
} catch (e) {
console.error('操作日志接口调用异常');
}
return _context.abrupt('return', result);
case 8:
case 'end':
return _context.stop();
}
}
}, _callee, this);
}));
// } else {
// descriptor.value = function () {
// const startTime = new Date().getTime();
// let result = originFun.apply(this, arguments);
// const endTime = new Date().getTime();
// operationItem.params = _getArgument(actionParamNames, arguments);
// operationItem.result = _toJS(result);
// operationItem.exeTime = `${endTime - startTime} ms`;
// if (process.env.NODE_ENV == 'development') {
// console.log(`${operationItem.name}方法执行情况:`, operationItem);
// }
// try {
// SysLogApi.logWarn({
// logContent: JSON.stringify(operationItem),
// });
// } catch (e) {
// console.error('操作日志接口调用异常');
// }
// return result;
// }
// }
};
}
//# sourceMappingURL=OperationLog.js.map