| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 |
- import {
- rePass,
- nextStep,
- smsCode,
- registerConfig
- } from "@/api/auth/login"
- import {
- captcha
- } from "@/api/website"
- export default {
- data() {
- var isMobile = (rule, value, callback) => {
- if (!value) {
- return callback(new Error("手机号不能为空"))
- } else {
- if (/^\d{11}$/.test(value)) {
- callback()
- } else {
- callback(new Error("请输入正确的手机号"))
- }
- }
- }
- let self = this
- var setPass = function(rule, value, callback) {
- let regConfig = self.registerConfig
- if (!value) {
- return callback(new Error("请输入新的登录密码"))
- } else {
- if (regConfig.pwd_len > 0) {
- if (value.length < regConfig.pwd_len) {
- return callback(new Error("密码长度不能小于" + regConfig.pwd_len + "位"))
- } else {
- callback()
- }
- } else {
- if (regConfig.pwd_complexity != "") {
- let passwordErrorMsg = "密码需包含",
- reg = ""
- if (regConfig.pwd_complexity.indexOf("number") != -1) {
- reg += "(?=.*?[0-9])"
- passwordErrorMsg += "数字"
- } else if (regConfig.pwd_complexity.indexOf("letter") != -1) {
- reg += "(?=.*?[a-z])"
- passwordErrorMsg += "、小写字母"
- } else if (regConfig.pwd_complexity.indexOf("upper_case") != -1) {
- reg += "(?=.*?[A-Z])"
- passwordErrorMsg += "、大写字母"
- } else if (regConfig.pwd_complexity.indexOf("symbol") != -1) {
- reg += "(?=.*?[#?!@$%^&*-])"
- passwordErrorMsg += "、特殊字符"
- } else {
- reg += ""
- passwordErrorMsg += ""
- }
- if (reg.test(value)) {
- return callback(new Error(passwordErrorMsg))
- } else {
- callback()
- }
- }
- }
- }
- }
- var checkPass = function(rule, value, callback) {
- if (!value) {
- return callback(new Error("请输入确认密码"))
- } else {
- if (value !== self.formData.pass) {
- callback(new Error("两次密码输入不一致"))
- } else {
- callback()
- }
- }
- }
- return {
- formData: {
- mobile: "",
- vercode: "",
- dynacode: "",
- pass: "",
- repass: "",
- key: ""
- },
- step: 1,
- activeName: "first",
- isShowPhone: "",
- captcha: {
- id: "",
- img: ""
- }, // 验证码
- dynacodeData: {
- seconds: 120,
- timer: null,
- codeText: "获取动态码",
- isSend: false
- }, // 动态码
- registerConfig: {},
- rules: {
- mobile: [{
- required: true,
- validator: isMobile,
- trigger: "blur"
- }],
- vercode: [{
- required: true,
- message: "请输入验证码",
- trigger: "blur"
- }],
- dynacode: [{
- required: true,
- message: "请输入短信动态码",
- trigger: "blur"
- }],
- pass: [{
- required: true,
- validator: setPass,
- trigger: "blur"
- }],
- repass: [{
- required: true,
- validator: checkPass,
- trigger: "blur"
- }]
- }
- }
- },
- created() {
- this.getCaptcha()
- this.getRegisterConfig()
- },
- head() {
- return {
- title: '找回密码-' +this.$store.state.site.siteInfo.site_name
- }
- },
- watch: {
- "dynacodeData.seconds": {
- handler(newValue, oldValue) {
- if (newValue == 0) {
- clearInterval(this.dynacodeData.timer)
- this.dynacodeData = {
- seconds: 120,
- timer: null,
- codeText: "获取动态码",
- isSend: false
- }
- }
- },
- immediate: true,
- deep: true
- }
- },
- methods: {
- /**
- * 下一步
- */
- nextStep(formName) {
- this.$refs[formName].validate(valid => {
- if (valid) {
- nextStep({
- mobile: this.formData.mobile
- })
- .then(res => {
- if (res.code == -1) {
- this.step = 2
- } else {
- this.$message({
- message: res.message,
- type: "warning"
- })
- }
- })
- .catch(err => {
- if (err.code == 0) {
- this.$message({
- message: "该手机号未注册",
- type: "warning"
- })
- } else {
- this.$message.error(err.message)
- }
- })
- } else {
- return false
- }
- })
- },
- /**
- * 获取动态验证码 下一步
- */
- nextStepToSetPass(formName) {
- this.$refs[formName].validate(valid => {
- if (valid) {
- this.step = 3
- } else {
- return false
- }
- })
- },
- /**
- * 重置密码
- */
- resetPass(formName) {
- this.$refs[formName].validate(valid => {
- if (valid) {
- rePass({
- password: this.formData.pass,
- code: this.formData.dynacode,
- key: this.formData.key,
- mobile: this.formData.mobile
- })
- .then(res => {
- if (res.code >= 0) {
- this.step = 4
- this.$message({
- message: res.message,
- type: "success"
- })
- }
- })
- .catch(err => {
- this.$message.error(err.message)
- })
- } else {
- return false
- }
- })
- },
- /**
- * 获取验证码
- */
- getCaptcha() {
- captcha({
- captcha_id: this.captcha.id
- })
- .then(res => {
- if (res.code >= 0) {
- this.captcha.id = res.data.id
- this.captcha.img = res.data.img
- this.captcha.img = this.captcha.img.replace(/\r\n/g, "")
- }
- })
- .catch(err => {
- this.$message.error(err.message)
- })
- },
- /**
- * 发送手机动态码
- */
- sendMobileCode(formName) {
- if (this.dynacodeData.seconds != 120) return
- this.$refs[formName].clearValidate("dynacode")
- this.$refs[formName].validateField("vercode", valid => {
- if (!valid) {
- if (this.isSend) return
- this.isSend = true
- smsCode({
- captcha_id: this.captcha.id,
- captcha_code: this.formData.vercode,
- mobile: this.formData.mobile
- })
- .then(res => {
- if (res.code >= 0) {
- this.formData.key = res.data.key
- if (this.dynacodeData.seconds == 120 && this.dynacodeData.timer == null) {
- this.dynacodeData.timer = setInterval(() => {
- this.dynacodeData.seconds--
- this.dynacodeData.codeText = this.dynacodeData.seconds + "s后可重新获取"
- }, 1000)
- } else {
- this.$message({
- message: res.message,
- type: "warning"
- })
- this.isSend = false
- this.getCaptcha()
- }
- }
- })
- .catch(err => {
- this.isSend = false
- this.getCaptcha()
- this.$message.error(err.message)
- })
- } else {
- return false
- }
- })
- },
- /**
- * 获取注册配置
- */
- getRegisterConfig() {
- registerConfig()
- .then(res => {
- if (res.code >= 0) {
- this.registerConfig = res.data.value
- }
- })
- .catch(err => {
- console.log(err.message)
- })
- }
- }
- }
|