var _default = {
data: function data() {
return {
username: '',
password: '',
codes: [{
num: 1,
color: '#000',
rotate: '10deg',
size: '16px'
}, {
num: 2,
color: '#000',
rotate: '10deg',
size: '16px'
}, {
num: 3,
color: '#000',
rotate: '10deg',
size: '16px'
}, {
num: 4,
color: '#000',
rotate: '10deg',
size: '16px'
}],
options: ['请选择登录用户类型'],
optionsValues: ['', 'yonghu'],
index: 0,
roleNum: 0
};
},
onLoad: function onLoad() {
var options = ['请选择登录用户类型'];
var menus = _menu.default.list();
this.menuList = menus;
for (var i = 0; i < this.menuList.length; i++) {
if (this.menuList[i].hasFrontLogin == '是') {
options.push(this.menuList[i].roleName);
this.roleNum++;
}
}
if (this.roleNum == 1) {
this.index = 1;
}
this.options = options;
this.randomString(4);
this.styleChange();
},
methods: {
randomString: function randomString() {
var len = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 4;
var chars = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
var colors = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
var sizes = ['28', '30', '32', '34', '36'];
for (var i = 0; i < len; i++) {
var key = Math.floor(Math.random() * chars.length);
this.codes[i].num = chars[key];
var code = '#';
for (var j = 0; j < 6; j++) {
var _key = Math.floor(Math.random() * colors.length);
code += colors[_key];
}
this.codes[i].color = code;
var rotate = Math.floor(Math.random() * 30);
var plus = Math.floor(Math.random() * 2);
if (plus == 1) rotate = '-' + rotate;
this.codes[i].rotate = 'rotate(' + rotate + 'deg)';
var size = Math.floor(Math.random() * sizes.length);
this.codes[i].size = sizes[size] + 'rpx';
}
},
styleChange: function styleChange() {
this.$nextTick(function () {
});
},
onRegisterTap: function onRegisterTap(tableName) {
uni.setStorageSync("loginTable", tableName);
this.$utils.jump('../register/register');
},
onForgetTap: function onForgetTap() {
this.$utils.jump('../forget/forget');
},
onLoginTap: function onLoginTap() {
var _this = this;
return (0, _asyncToGenerator2.default)( _regenerator.default.mark(function _callee() {
var res;
return _regenerator.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
if (_this.optionsValues[_this.index]) {
_context.next = 3;
break;
}
_this.$utils.msg("请选择登陆人类型");
return _context.abrupt("return");
case 3:
if (true) {
_context.next = 6;
break;
}
_this.$utils.msg("请输入正确的验证码");
return _context.abrupt("return");
case 6:
_context.next = 8;
return _this.$api.login("".concat(_this.optionsValues[_this.index]), {
username: _this.username,
password: _this.password
});
case 8:
res = _context.sent;
uni.setStorageSync("token", res.token);
uni.setStorageSync("nickname", _this.username);
uni.setStorageSync("nowTable", "".concat(_this.optionsValues[_this.index]));
_context.next = 14;
return _this.$api.session("".concat(_this.optionsValues[_this.index]));
case 14:
res = _context.sent;
uni.setStorageSync("userid", res.data.id);
if (res.data.vip) {
uni.setStorageSync("vip", res.data.vip);
}
uni.setStorageSync("role", "".concat(_this.options[_this.index]));
_this.$utils.tab("../index/index");
case 19:
case "end":
return _context.stop();
}
}
}, _callee);
}))();
},
optionsChange: function optionsChange(e) {
this.index = e.target.value;
}
}
};