123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- define([
- 'api/login',
- 'api/my',
- 'plugins/blueimp-md5/js/md5',
- 'text!components/phone_pwd/index.html',
- 'css!components/phone_pwd/index.css'
- ], function(loginApi, myApi, md5, html) {
- return {
- props: {
- phonePwdVisible: {
- type: Boolean,
- default: false
- },
- phonePwd: {
- type: Boolean,
- default: true
- },
- currentPhone: {
- type: String,
- default: ''
- }
- },
- data: function () {
- return {
- state: true,
- phone: '',
- code: '',
- pwd: '',
- count: -1,
- TIME_COUNT: 60
- };
- },
- methods: {
- // 获取验证码
- getCode: function () {
- var vm = this;
- this.count = this.TIME_COUNT;
- this.timer = setInterval(function () {
- vm.count--;
- if (vm.count < 0) {
- clearInterval(vm.timer);
- vm.timer = null;
- }
- }, 1000);
- loginApi.code({
- phone: this.currentPhone
- }).then(function (res) {
- vm.$message.success(res.msg);
- }).catch(function (err) {
- vm.$message.error(err.msg);
- clearInterval(vm.timer);
- vm.timer = null;
- vm.count = -1;
- });
- },
- submit: function () {
- var vm = this;
- if (!this.state) {
- if (!this.phone) {
- return this.$message.warning('请输入手机号');
- }
- if (!/^1[3456789]\d{9}$/.test(this.phone)) {
- return this.$message.warning('手机号错误');
- }
- }
- if (!this.code) {
- return this.$message.warning('请输入验证码');
- }
- if (!/^\d{6}$/.test(this.code)) {
- return this.$message.warning('验证码错误');
- }
- if (this.timer) {
- clearInterval(this.timer);
- this.timer = null;
- }
- if (this.phonePwd) {
- if (this.state) {
- // 验证旧手机号
- myApi.validate_code({
- phone: this.currentPhone,
- code: this.code
- }).then(function () {
- vm.state = false;
- vm.phone = '';
- vm.code = '';
- }).catch(function (err) {
- vm.$message.error(err.msg);
- vm.count = -1;
- });
- return;
- }
- // 保存新手机号
- myApi.save_phone({
- phone: this.phone,
- code: this.code
- }).then(function (res) {
- vm.$message.success(res.msg);
- vm.$emit('login-again');
- }).catch(function (err) {
- vm.$message.error(err.msg);
- vm.count = -1;
- });
- }
- if (!this.pwd) {
- return this.$message.warning('请输入密码');
- }
- if (!/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,16}$/.test(this.pwd)) {
- return this.$message.warning('请输入8-16位字母加数字组合新密码');
- }
- // 修改密码
- loginApi.register({
- account: this.currentPhone,
- code: this.code,
- pwd: md5(this.pwd),
- type: 2
- }).then(function (res) {
- vm.$message.success(res.msg);
- vm.$emit('login-again');
- }).catch(function (err) {
- vm.$message.error(err.msg);
- vm.count = -1;
- });
- }
- },
- template: html
- };
- });
|