captain-ui
Version:
有赞vue wap业务组件库
249 lines (229 loc) • 6.83 kB
JavaScript
import "vant/es/dialog/style";
import _Dialog from "vant/es/dialog";
import "vant/es/toast/style";
import _Toast from "vant/es/toast";
import _extends from "@babel/runtime/helpers/esm/extends";
import aes from '@youzan/yz-aes';
import ajax from '../utils/ajax';
import PageMixin from '../mixins/page-mixin';
export default {
render: function render() {
var _vm = this;
var _h = _vm.$createElement;
var _c = _vm._self._c || _h;
return _c('div', {
staticClass: "cap-login__form cap-login__forget-password"
}, [_c('van-cell-group', [_vm.showCountrySelect ? _c('vm-form-item', {
attrs: {
"title": "国家",
"is-link": ""
},
on: {
"click": _vm.doSelectCountry
}
}, [_vm._v("\n " + _vm._s(_vm.country.name) + " " + _vm._s(_vm.country.code) + "\n ")]) : _vm._e(), _c('vm-form-item', {
attrs: {
"title": "手机号"
}
}, [_c('vm-input', {
attrs: {
"type": "tel",
"placeholder": "请输入手机号"
},
model: {
value: _vm.loginData.phone,
callback: function callback($$v) {
_vm.$set(_vm.loginData, "phone", $$v);
},
expression: "loginData.phone"
}
})], 1), _c('vm-form-item', {
staticClass: "cap-login__captcha-item",
attrs: {
"title": "验证码"
}
}, [_c('vm-captcha', {
attrs: {
"placeholder": "请输入验证码",
"captcha-url": _vm.captchaUrl,
"image-captcha-url": _vm.imageCaptchaUrl,
"check-image-captcha-url": _vm.checkImageCaptchaUrl,
"token-url": _vm.tokenUrl,
"phone": _vm.phone,
"country": _vm.country,
"send-msg-after-confirm": _vm.sendMsgAfterConfirm,
"send-msg-confirm-callback": _vm.autoConfirm
},
on: {
"statusChange": _vm.handleCaptchaStatusChange,
"logger": _vm.handleCaptchaLogger
},
model: {
value: _vm.loginData.code,
callback: function callback($$v) {
_vm.$set(_vm.loginData, "code", $$v);
},
expression: "loginData.code"
}
})], 1), _c('vm-form-item', {
attrs: {
"title": "密码"
}
}, [_c('vm-password', {
attrs: {
"placeholder": "请设置8~16个字符的密码"
},
model: {
value: _vm.loginData.password,
callback: function callback($$v) {
_vm.$set(_vm.loginData, "password", $$v);
},
expression: "loginData.password"
}
})], 1)], 1), _c('p', {
directives: [{
name: "show",
rawName: "v-show",
value: _vm.captchaStatus === 'disabled',
expression: "captchaStatus === 'disabled'"
}],
staticClass: "cap-login__tip"
}, [_vm._v("\n 验证码已发送至手机号 " + _vm._s(_vm.country.code) + " " + _vm._s(_vm.loginData.phone) + "\n ")]), _c('vm-actions', [_c('template', {
slot: "button"
}, [_c('van-button', {
attrs: {
"type": "danger",
"block": ""
},
on: {
"click": _vm.handleSubmit
}
}, [_vm._v("\n 确定\n ")])], 1), _c('template', {
slot: "tips"
}, [_c('span', {
staticClass: "cap-login--pull-right",
on: {
"click": _vm.goLogin
}
}, [_vm._v("\n 去登录\n ")])])], 2)], 1);
},
mixins: [PageMixin],
props: {
autoConfirmUrl: String,
registerUrl: String,
captchaUrl: String,
imageCaptchaUrl: String,
checkImageCaptchaUrl: String,
tokenUrl: String,
source: String
},
data: function data() {
return {
loginData: {
phone: this.phone || '',
code: '',
password: ''
},
captchaStatus: '',
sendMsgAfterConfirm: true
};
},
methods: {
handleSubmit: function handleSubmit() {
var _this2 = this;
this.$emit('logger', {
type: 'register'
});
var source = this.source;
var phoneReg = /^\d{1,20}$/;
var loginData = _extends({}, this.loginData);
var phone = loginData.phone;
if (!phone) {
_Toast('请输入手机号');
return;
}
if (!phoneReg.test(phone)) {
_Toast('手机号格式不正确');
return;
}
if (!loginData.code) {
_Toast('请输入验证码');
return;
}
if (!loginData.password) {
_Toast('请输入密码');
return;
}
this.autoConfirm().then(function () {
ajax({
url: _this2.registerUrl,
method: 'POST',
data: _extends({}, loginData, {
phone: _this2.phone,
country_code: _this2.country && _this2.country.code,
password: aes.encrypt(loginData.password),
source: source
})
}).then(function () {
_this2.$emit('typeChange', 'login');
}, function (res) {
_Toast(res.msg || '网络错误');
});
});
},
handleCaptchaStatusChange: function handleCaptchaStatusChange(status) {
this.captchaStatus = status;
},
goLogin: function goLogin() {
this.$emit('typeChange', 'login');
},
goForgetPassword: function goForgetPassword() {
this.$emit('typeChange', 'forget-password');
},
// 校验当前号码是否已经注册过
autoConfirm: function autoConfirm() {
var _this3 = this;
var source = this.source;
var _this = this;
var phoneReg = /^\d{1,20}$/;
return new Promise(function (resolve, reject) {
if (!phoneReg.test(_this3.loginData.phone)) {
_Toast('手机号格式不正确');
reject();
} else {
ajax({
url: _this3.autoConfirmUrl,
method: 'POST',
data: _extends({}, _this3.loginData, {
country_code: _this3.country && _this3.country.code,
source: source
})
}).then(function (res) {
_Dialog.confirm({
message: '该手机号码已注册过有赞帐号',
confirmButtonText: '立即登录',
cancelButtonText: '忘记密码?'
}).then(function (action) {
if (action === 'confirm') {
_this.goLogin();
}
}).catch(function () {
_this.goForgetPassword();
});
}, function (res) {
if (+res.code !== 135000003) {
_Toast(res.msg || '网络错误');
reject();
} else {
// 没有注册过
resolve();
}
});
}
});
},
handleCaptchaLogger: function handleCaptchaLogger(detail) {
this.$emit('logger', detail);
}
}
};