tplus-poslogin
Version:
password login module
714 lines (562 loc) • 22.8 kB
JavaScript
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = undefined;
var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _regenerator = require('babel-runtime/regenerator');
var _regenerator2 = _interopRequireDefault(_regenerator);
var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray');
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
var _getIterator2 = require('babel-runtime/core-js/get-iterator');
var _getIterator3 = _interopRequireDefault(_getIterator2);
var _promise = require('babel-runtime/core-js/promise');
var _promise2 = _interopRequireDefault(_promise);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _Store = require('../model/Store');
var _Store2 = _interopRequireDefault(_Store);
var _StoreApi = require('../api/StoreApi');
var _StoreApi2 = _interopRequireDefault(_StoreApi);
var _tplusApi = require('tplus-api');
var _merge2 = require('lodash/merge');
var _merge3 = _interopRequireDefault(_merge2);
var _mutantsMicrofx = require('mutants-microfx');
var _LoginMW = require('../middleware/LoginMW');
var _LoginMW2 = _interopRequireDefault(_LoginMW);
var _mobx = require('mobx');
var _mutantsUtil = require('mutants-util');
var _tplusComponentsTouch = require('tplus-components-touch');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var user = _mutantsMicrofx.stores.user;
var hasElectron = _mutantsMicrofx.env.platform === _mutantsMicrofx.env.constant.platform.electron;
var os_mac = window.CommonLib && window.CommonLib.os;
var LoginStore = function () {
function LoginStore() {
var _this = this;
(0, _classCallCheck3.default)(this, LoginStore);
this.user = {};
this.store = {};
this.getYPKey = function () {
return new _promise2.default(function (resolve, reject) {
try {
var timer = setTimeout(function () {
resolve(null);
}, 3000);
_mutantsMicrofx.nativeMs.setIpcRendererMethod('GetSystemVolumeInfo', null, function (ret) {
clearTimeout(timer);
if (ret) {
console.log('硬盘唯一码:' + ret);
resolve(ret);
} else {
resolve(null);
}
});
} catch (ex) {
_tplusComponentsTouch.Message.warn('获取唯一码失败。');
}
});
};
this.getNodeOSMac = function () {
var arr = [];
if (!os_mac) return "";
var interfaces = os_mac.networkInterfaces();
for (var devName in interfaces) {
var iface = interfaces[devName];
for (var i = 0; i < iface.length; i++) {
var alias = iface[i];
var mac = alias.mac;
mac = mac.replace(/:/g, '-').toUpperCase();
if (!alias.internal && arr.indexOf(mac) == -1) {
arr.push(mac);
}
}
}
return arr;
};
this.getLocalMacList = function () {
return new _promise2.default(function (resolve, reject) {
try {
var timer = setTimeout(function () {
resolve(null);
}, 3000);
_mutantsMicrofx.nativeMs.setIpcRendererMethod('GetLocalMacs', null, function (ret) {
clearTimeout(timer);
if (ret) {
var arr = [];
var lists = ret.split('\r\n');
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = (0, _getIterator3.default)(lists), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var item = _step.value;
if (item) {
var items = item.split('\t');
var mac = items[2];
if (arr.indexOf(mac) == -1) {
arr.push(mac);
}
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
console.log('所有MacList:' + arr);
resolve(arr);
} else {
resolve(null);
}
});
} catch (ex) {
_tplusComponentsTouch.Message.warn('获取唯一码失败。');
}
});
};
this.getMobileOnlyKey = function () {
return new _promise2.default(function (resolve, reject) {
var _ref = _mutantsUtil.platform || {},
mobileDeviceUuid = _ref.mobileDeviceUuid;
return resolve(mobileDeviceUuid);
});
};
this.getSearchMacKey = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee() {
var arr, maclist, oKey, ykey, ret;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
arr = [];
_context.next = 3;
return _this.getLocalMacList();
case 3:
maclist = _context.sent;
if (!(maclist && maclist.length > 0)) {
_context.next = 8;
break;
}
arr = [].concat((0, _toConsumableArray3.default)(maclist));
_context.next = 12;
break;
case 8:
_context.next = 10;
return _mutantsMicrofx.nativeMs.getLocalMac();
case 10:
oKey = _context.sent;
if (oKey) arr.push(oKey);
case 12:
_context.next = 14;
return _this.getYPKey();
case 14:
ykey = _context.sent;
if (ykey) arr.push(ykey);
ret = arr && arr.length > 0 ? arr.join(',') : '';
console.log("查询key:" + ret);
return _context.abrupt('return', ret);
case 19:
case 'end':
return _context.stop();
}
}
}, _callee, _this);
}));
this.getRegisterMacKey = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2() {
var arr, maclist, okey, osKey, ret;
return _regenerator2.default.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
arr = [];
_context2.next = 3;
return _this.getLocalMacList();
case 3:
maclist = _context2.sent;
if (!(maclist && maclist.length > 0)) {
_context2.next = 8;
break;
}
arr = [].concat((0, _toConsumableArray3.default)(maclist));
_context2.next = 14;
break;
case 8:
_context2.next = 10;
return _mutantsMicrofx.nativeMs.getLocalMac();
case 10:
okey = _context2.sent;
osKey = _this.getNodeOSMac();
if (osKey && osKey.length > 0) {
if (osKey.indexOf(okey) == -1) {
arr.push(okey);
}
}
arr = [].concat((0, _toConsumableArray3.default)(arr), (0, _toConsumableArray3.default)(osKey));
case 14:
ret = arr && arr.length > 0 ? arr.join(',') : '';
console.log("注册key:" + ret);
return _context2.abrupt('return', ret);
case 17:
case 'end':
return _context2.stop();
}
}
}, _callee2, _this);
}));
}
(0, _createClass3.default)(LoginStore, [{
key: 'getOrgList',
value: function () {
var _ref4 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3(username, password) {
return _regenerator2.default.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
_context3.next = 2;
return _tplusApi.User.authentication(username, password);
case 2:
this.user = _context3.sent;
return _context3.abrupt('return', this.user);
case 4:
case 'end':
return _context3.stop();
}
}
}, _callee3, this);
}));
function getOrgList(_x, _x2) {
return _ref4.apply(this, arguments);
}
return getOrgList;
}()
}, {
key: 'login',
value: function () {
var _ref5 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee4(orgId) {
var _ref6, isHorizontalPad, isHorizontalSunMi, clientName, desc, IPMSG;
return _regenerator2.default.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
_ref6 = _mutantsUtil.platform || {}, isHorizontalPad = _ref6.isHorizontalPad, isHorizontalSunMi = _ref6.isHorizontalSunMi;
_context4.next = 3;
return this.user.initChannel(orgId);
case 3:
clientName = 'POS-PC-Web端';
if (hasElectron) {
clientName = 'POS客户端';
} else if (_mutantsMicrofx.env.os === _mutantsMicrofx.env.constant.os.ios) {
clientName = !!isHorizontalPad ? 'POS-IOS-Pad端' : !!isHorizontalSunMi ? 'POS-IOS-SunMi' : 'POS-IOS端';
} else if (_mutantsMicrofx.env.os === _mutantsMicrofx.env.constant.os.android) {
clientName = !!isHorizontalPad ? 'POS-Android-Pad端' : !!isHorizontalSunMi ? 'POS-Android-SunMi' : 'POS-Android端';
}
desc = 'POS登录';
if (!!window.localStorage.IPMSG) {
IPMSG = JSON.parse(window.localStorage.IPMSG);
if ('success' == IPMSG.status) {
desc = desc + '/国家:' + IPMSG.country + '/地区:' + IPMSG.regionName + '/IP:' + IPMSG.query;
}
}
_context4.next = 9;
return this.user.loginTplus({ clientName: clientName, desc: desc });
case 9:
case 'end':
return _context4.stop();
}
}
}, _callee4, this);
}));
function login(_x3) {
return _ref5.apply(this, arguments);
}
return login;
}()
}, {
key: 'getStoreInfos',
value: function () {
var _ref7 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee5() {
return _regenerator2.default.wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
_context5.next = 2;
return _Store2.default.getStoreInfo();
case 2:
this.store = _context5.sent;
return _context5.abrupt('return', this.store);
case 4:
case 'end':
return _context5.stop();
}
}
}, _callee5, this);
}));
function getStoreInfos() {
return _ref7.apply(this, arguments);
}
return getStoreInfos;
}()
}, {
key: 'getPosKey',
value: function () {
var _ref8 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee6() {
var key, _ref9, isHorizontalPad, isHorizontalSunMi, isMobileEnvironment, cacheStore, orgId, storeID, posCode;
return _regenerator2.default.wrap(function _callee6$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
key = undefined;
_ref9 = _mutantsUtil.platform || {}, isHorizontalPad = _ref9.isHorizontalPad, isHorizontalSunMi = _ref9.isHorizontalSunMi;
isMobileEnvironment = !!isHorizontalPad || !!isHorizontalSunMi;
if (!hasElectron) {
_context6.next = 9;
break;
}
_context6.next = 6;
return this.getSearchMacKey();
case 6:
key = _context6.sent;
_context6.next = 21;
break;
case 9:
if (!(isMobileEnvironment && (_mutantsMicrofx.env.os === _mutantsMicrofx.env.constant.os.ios || _mutantsMicrofx.env.os === _mutantsMicrofx.env.constant.os.android))) {
_context6.next = 18;
break;
}
_context6.next = 12;
return this.getMobileOnlyKey();
case 12:
key = _context6.sent;
if (key) {
_context6.next = 16;
break;
}
_tplusComponentsTouch.Message.warn('获取设备唯一参数失败。');
return _context6.abrupt('return');
case 16:
_context6.next = 21;
break;
case 18:
cacheStore = _Store2.default.restore();
orgId = cacheStore.orgId, storeID = cacheStore.storeID, posCode = cacheStore.posCode;
if (!!orgId && !!storeID && !!posCode) {
key = this.getVirtualPosKey(cacheStore);
}
case 21:
return _context6.abrupt('return', key);
case 22:
case 'end':
return _context6.stop();
}
}
}, _callee6, this);
}));
function getPosKey() {
return _ref8.apply(this, arguments);
}
return getPosKey;
}()
//在Electron客户端中:获取硬盘的唯一码
//在Electron客户端中:通过Node OS 获取mac地址
//在Electron客户端中:获取所有Mac
}, {
key: 'getVirtualPosKey',
//获取虚拟的posKey
//如果是非壳 获取不到mac地址 用orgId,storeID,posCode组成联合组件
value: function getVirtualPosKey(_ref10) {
var orgId = _ref10.orgId,
storeID = _ref10.storeID,
posCode = _ref10.posCode;
var posKey = _tplusApi.User.pwdEncrypt(orgId + '/' + storeID + '/' + posCode);
return posKey;
}
//获取移动设备唯一的key
//在Electron客户端中:获取查询的唯一码集合.
//在Electron客户端中:获取注册的唯一码集合.
}, {
key: 'getCloudPos',
//获取云端pos信息
value: function () {
var _ref11 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee7() {
var posKey, resp;
return _regenerator2.default.wrap(function _callee7$(_context7) {
while (1) {
switch (_context7.prev = _context7.next) {
case 0:
_context7.next = 2;
return this.getPosKey();
case 2:
posKey = _context7.sent;
_context7.next = 5;
return _StoreApi2.default.queryCloudPos(posKey, _mutantsMicrofx.env.platform);
case 5:
resp = _context7.sent;
return _context7.abrupt('return', resp.data.data);
case 7:
case 'end':
return _context7.stop();
}
}
}, _callee7, this);
}));
function getCloudPos() {
return _ref11.apply(this, arguments);
}
return getCloudPos;
}()
// 清除云端pos信息
}, {
key: 'cleanRegisterInfo',
value: function () {
var _ref12 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee8(info) {
var resp;
return _regenerator2.default.wrap(function _callee8$(_context8) {
while (1) {
switch (_context8.prev = _context8.next) {
case 0:
_context8.next = 2;
return _StoreApi2.default.unregister(info);
case 2:
resp = _context8.sent;
return _context8.abrupt('return', resp.data);
case 4:
case 'end':
return _context8.stop();
}
}
}, _callee8, this);
}));
function cleanRegisterInfo(_x4) {
return _ref12.apply(this, arguments);
}
return cleanRegisterInfo;
}()
}, {
key: 'loginPos',
value: function () {
var _ref13 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee9(_ref14) {
var _this2 = this;
var orgId = _ref14.orgId,
orgName = _ref14.orgName,
storeID = _ref14.storeID,
storeName = _ref14.storeName,
storeCode = _ref14.storeCode,
posCode = _ref14.posCode,
_ref14$key = _ref14.key,
key = _ref14$key === undefined ? '' : _ref14$key,
formal = _ref14.formal;
var userOptions, _ref15, isHorizontalPad, isHorizontalSunMi, isMobileEnvironment, loginContext, posContext, PosKey, StoreName, loginInfo;
return _regenerator2.default.wrap(function _callee9$(_context9) {
while (1) {
switch (_context9.prev = _context9.next) {
case 0:
if (!orgName) {
userOptions = (0, _mobx.toJS)(user.options);
orgName = userOptions.orgName;
}
_ref15 = _mutantsUtil.platform || {}, isHorizontalPad = _ref15.isHorizontalPad, isHorizontalSunMi = _ref15.isHorizontalSunMi;
isMobileEnvironment = !!isHorizontalPad || !!isHorizontalSunMi;
if (!hasElectron) {
_context9.next = 10;
break;
}
if (key) {
_context9.next = 8;
break;
}
_context9.next = 7;
return this.getRegisterMacKey();
case 7:
key = _context9.sent;
case 8:
_context9.next = 20;
break;
case 10:
if (!(isMobileEnvironment && (_mutantsMicrofx.env.os === _mutantsMicrofx.env.constant.os.ios || _mutantsMicrofx.env.os === _mutantsMicrofx.env.constant.os.android))) {
_context9.next = 19;
break;
}
_context9.next = 13;
return this.getMobileOnlyKey();
case 13:
key = _context9.sent;
if (key) {
_context9.next = 17;
break;
}
_tplusComponentsTouch.Message.warn('获取设备唯一参数失败。');
return _context9.abrupt('return');
case 17:
_context9.next = 20;
break;
case 19:
key = this.getVirtualPosKey({ orgId: orgId, storeID: storeID, posCode: posCode });
case 20:
console.log('key=======', key);
_context9.next = 23;
return _StoreApi2.default.posLogin({ key: key, storeID: storeID, posCode: posCode });
case 23:
loginContext = _context9.sent;
_context9.next = 26;
return _StoreApi2.default.posInit();
case 26:
posContext = _context9.sent;
PosKey = loginContext.PosKey, StoreName = loginContext.StoreName, loginInfo = (0, _objectWithoutProperties3.default)(loginContext, ['PosKey', 'StoreName']); // 以接口中返回的StoreName为准
this.store = (0, _merge3.default)(this.store, { orgId: orgId, orgName: orgName, PosKey: PosKey, storeID: storeID, storeName: StoreName, storeCode: loginInfo.StoreCode, posCode: posCode, formal: formal });
loginInfo = (0, _extends3.default)({}, loginInfo, posContext, this.store, { storeName: storeName });
(0, _mutantsMicrofx.runInAction)(function () {
_mutantsMicrofx.stores.posLoginStore.savePosCode(posCode);
_mutantsMicrofx.stores.user.options.set('store', _this2.store);
_mutantsMicrofx.stores.user.options.set('loginInfo', loginInfo);
});
//目前返回的key值为空 可能是没有插入狗的情况 这块后续会加校验
_Store2.default.cache(this.store);
try {
_LoginMW2.default.execute();
} catch (err) {
console.log('LoginMV.execute error >>>>>> ', err);
}
case 33:
case 'end':
return _context9.stop();
}
}
}, _callee9, this);
}));
function loginPos(_x5) {
return _ref13.apply(this, arguments);
}
return loginPos;
}()
}], [{
key: 'setCustomLogo',
value: function setCustomLogo() {
(0, _tplusApi.tApi)({}, 'chanjet.RE.NewPos.GetCustomLogo', false, false).then(function (res) {
var store = _mutantsMicrofx.stores.user.options.get('store');
_Store2.default.cache((0, _extends3.default)({}, store, { logo: res }));
rx$.changeLogo.next();
}).catch(function (err) {
return console.error(err);
});
}
}]);
return LoginStore;
}();
exports.default = LoginStore;
//# sourceMappingURL=LoginStore.js.map