|
|
@@ -1,7 +1,7 @@
|
|
|
/**
|
|
|
* 混入对象,抽取Vue中公共的部分
|
|
|
*/
|
|
|
-import { getPubkey, getCaptchaCode, getVerifyCode, login, logout } from '@/api/account'
|
|
|
+import {getPubkey, getCaptchaCode, getVerifyCode, login, logout, register, forgot } from '@/api/account'
|
|
|
import { setUserToken, removeAll } from '@/utils/auth'
|
|
|
import { JSEncrypt } from 'jsencrypt'
|
|
|
import Vue from 'vue'
|
|
|
@@ -19,6 +19,19 @@ export const userMixin = {
|
|
|
loginType: 2,
|
|
|
plat: 2
|
|
|
},
|
|
|
+ userRegistry: {
|
|
|
+ principal: null,
|
|
|
+ verifyCode: null,
|
|
|
+ credential: null,
|
|
|
+ captchaCode: null,
|
|
|
+ plat: 2
|
|
|
+ },
|
|
|
+ userForgot: {
|
|
|
+ principal: null,
|
|
|
+ verifyCode: null,
|
|
|
+ newCredential: null,
|
|
|
+ captchaCode: null,
|
|
|
+ },
|
|
|
loginDialog: false,
|
|
|
registerDialog: false,
|
|
|
dialogVisible: false,
|
|
|
@@ -39,8 +52,8 @@ export const userMixin = {
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
- fetchPubkey() {
|
|
|
- getPubkey().then(resp => {
|
|
|
+ fetchPubkey(channel) {
|
|
|
+ getPubkey(channel).then(resp => {
|
|
|
if (resp.code === 0) {
|
|
|
this.pubkey = resp.data.pubkey
|
|
|
this.pubkeyR = resp.data.r
|
|
|
@@ -71,12 +84,31 @@ export const userMixin = {
|
|
|
encryptor.setPublicKey(pubkey)
|
|
|
return encryptor.encrypt(pubkeyR + password)
|
|
|
},
|
|
|
- fetchVerifyCode() {
|
|
|
+ loginVerifyCode() {
|
|
|
if (this.userLogin.principal === null || this.userLogin.principal === '') {
|
|
|
- this.$message.success('请填写手机号')
|
|
|
+ this.$message.success('请填写邮箱或手机号')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ getVerifyCode(1, this.userRegistry.principal)
|
|
|
+ },
|
|
|
+ registerVerifyCode() {
|
|
|
+ if (this.userRegistry.principal === null || this.userRegistry.principal === '') {
|
|
|
+ this.$message.success('请填写邮箱或手机号')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ this.getVerifyCode(2, this.userRegistry.principal)
|
|
|
+ },
|
|
|
+ forgotVerifyCode() {
|
|
|
+ if (this.userForgot.principal === null || this.userForgot.principal === '') {
|
|
|
+ this.$message.success('请填写邮箱或手机号')
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ this.getVerifyCode(3, this.userForgot.principal)
|
|
|
+ },
|
|
|
+ getVerifyCode(channel, receiver) {
|
|
|
this.isBtn = true
|
|
|
let time = 60
|
|
|
const timeout = setInterval(() => {
|
|
|
@@ -91,8 +123,8 @@ export const userMixin = {
|
|
|
}, 1000)
|
|
|
|
|
|
const verifyCodeReq = {}
|
|
|
- verifyCodeReq.receiver = this.userLogin.principal
|
|
|
- verifyCodeReq.notifyType = 2
|
|
|
+ verifyCodeReq.receiver = receiver
|
|
|
+ verifyCodeReq.channel = channel
|
|
|
getVerifyCode(verifyCodeReq).then(resp => {
|
|
|
if (resp.code === 0) {
|
|
|
this.$message.success('验证码已发送, 请注意查收')
|
|
|
@@ -116,9 +148,7 @@ export const userMixin = {
|
|
|
}
|
|
|
},
|
|
|
loginBtn() {
|
|
|
- // 显示加载效果
|
|
|
- this.isLoading = true
|
|
|
- if (this.userLogin.principal === '') {
|
|
|
+ if (this.userLogin.principal === '' || this.userLogin.principal === null) {
|
|
|
this.$message.warning('手机号不能为空')
|
|
|
return
|
|
|
}
|
|
|
@@ -126,12 +156,14 @@ export const userMixin = {
|
|
|
this.$message.warning('短信验证码不能为空')
|
|
|
return
|
|
|
}
|
|
|
- if (this.userLogin.captchaCode === '') {
|
|
|
+ if (this.userLogin.captchaCode === '' || this.userLogin.captchaCode === null) {
|
|
|
this.$message.warning('图形验证码不能为空')
|
|
|
return
|
|
|
}
|
|
|
|
|
|
this.userLogin.credential = this.encryptPassword(this.userLogin.credential, this.pubkey, this.pubkeyR)
|
|
|
+ // 显示加载效果
|
|
|
+ this.isLoading = true
|
|
|
login(this.userLogin).then(resp => {
|
|
|
if (resp.code === 0) {
|
|
|
const respData = resp.data
|
|
|
@@ -152,6 +184,7 @@ export const userMixin = {
|
|
|
// 登录请求错误
|
|
|
this.$message.error(error)
|
|
|
}).finally(() => {
|
|
|
+ this.isLoading = false
|
|
|
this.userLogin = {
|
|
|
principal: null,
|
|
|
credential: null,
|
|
|
@@ -161,6 +194,92 @@ export const userMixin = {
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
+ registerBtn() {
|
|
|
+ if (this.userRegistry.principal === '' || this.userRegistry.principal === null) {
|
|
|
+ this.$message.warning('手机号不能为空')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (this.userRegistry.credential === '' || this.userRegistry.credential === null) {
|
|
|
+ this.$message.warning('密码不能为空')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (this.userRegistry.verifyCode === '' || this.userRegistry.verifyCode === null) {
|
|
|
+ this.$message.warning('短信验证码不能为空')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (this.userRegistry.captchaCode === '' || this.userRegistry.captchaCode === null) {
|
|
|
+ this.$message.warning('图形验证码不能为空')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ this.userRegistry.credential = this.encryptPassword(this.userRegistry.credential, this.pubkey, this.pubkeyR)
|
|
|
+ // 显示加载效果
|
|
|
+ this.isLoading = true
|
|
|
+ register(this.userRegistry).then(resp => {
|
|
|
+ if (resp.code === 0) {
|
|
|
+ // 关闭弹窗并刷新页面
|
|
|
+ this.dialogVisible = false
|
|
|
+ this.$message.info('帐号已注册, 请返回登录页面登录帐号')
|
|
|
+ } else {
|
|
|
+ this.$message.warning(resp.msg)
|
|
|
+ }
|
|
|
+ }).catch(error => {
|
|
|
+ this.$message.error(error)
|
|
|
+ }).finally(() => {
|
|
|
+ this.isLoading = false
|
|
|
+ this.userRegistry = {
|
|
|
+ principal: null,
|
|
|
+ credential: null,
|
|
|
+ captchaCode: null,
|
|
|
+ loginType: 2,
|
|
|
+ plat: 1
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ forgotBtn() {
|
|
|
+ if (this.userForgot.principal === '' || this.userForgot.principal === null) {
|
|
|
+ this.$message.warning('手机号不能为空')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (this.userForgot.newCredential === '' || this.userForgot.newCredential === null) {
|
|
|
+ this.$message.warning('密码不能为空')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (this.userForgot.verifyCode === '' || this.userForgot.verifyCode === null) {
|
|
|
+ this.$message.warning('短信验证码不能为空')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (this.userForgot.captchaCode === '' || this.userForgot.captchaCode === null) {
|
|
|
+ this.$message.warning('图形验证码不能为空')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ this.userForgot.newCredential = this.encryptPassword(this.userForgot.newCredential, this.pubkey, this.pubkeyR)
|
|
|
+ // 显示加载效果
|
|
|
+ this.isLoading = true
|
|
|
+ forgot(this.userForgot).then(resp => {
|
|
|
+ if (resp.code === 0) {
|
|
|
+ // 关闭弹窗并刷新页面
|
|
|
+ this.dialogVisible = false
|
|
|
+ this.$message.info('密码已重置, 请返回登录页面登录帐号')
|
|
|
+ } else {
|
|
|
+ this.$message.warning(resp.msg)
|
|
|
+ }
|
|
|
+ }).catch(error => {
|
|
|
+ this.$message.error(error)
|
|
|
+ }).finally(() => {
|
|
|
+ this.isLoading = false
|
|
|
+ this.userForgot = {
|
|
|
+ principal: null,
|
|
|
+ verifyCode: null,
|
|
|
+ newCredential: null,
|
|
|
+ captchaCode: null
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ goToHome() {
|
|
|
+ this.$router.push('/')
|
|
|
+ },
|
|
|
goToLogout() {
|
|
|
this.$confirm('退出登录, 是否继续?', '提示', {
|
|
|
confirmButtonText: '确定',
|