| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622 |
- import {
- passWord,
- emailCode,
- checkEmail,
- email,
- tellCode,
- tell,
- verifypaypwdcode,
- modifypaypassword,
- paypwdcode,
- pwdmobliecode
- } from "@/api/member/security"
- import {
- info
- } from "@/api/member/info"
- import {
- captcha
- } from "@/api/website"
- export default {
- name: "security",
- components: {},
- data() {
- var validatePass = (rule, value, callback) => {
- if (value === "") {
- callback(new Error("请输入新密码"))
- } else if (value == this.passWordForm.oldPass) {
- callback(new Error("新密码不能与原密码相同!"))
- } else {
- if (this.passWordForm.checkPass !== "") {
- this.$refs.passWordRef.validateField("checkPass")
- }
- callback()
- }
- }
- var validatePass2 = (rule, value, callback) => {
- if (value === "") {
- callback(new Error("请再次输入密码"))
- } else if (value !== this.passWordForm.pass) {
- callback(new Error("两次输入密码不一致!"))
- } else {
- callback()
- }
- }
- var validateTellPass = (rule, value, callback) => {
- if (value === "") {
- callback(new Error("请输入新密码"))
- } else if (value == this.tellPassForm.oldPass) {
- callback(new Error("新密码不能与原密码相同!"))
- } else {
- if (this.tellPassForm.checkPass !== "") {
- this.$refs.tellPassRef.validateField("checkPass")
- }
- callback()
- }
- }
- var validateTellPass2 = (rule, value, callback) => {
- if (value === "") {
- callback(new Error("请再次输入密码"))
- } else if (value !== this.tellPassForm.pass) {
- callback(new Error("两次输入密码不一致!"))
- } else {
- callback()
- }
- }
- var checkemail = (rules, value, callback) => {
- const regEmail = /^\w+@\w+(\.\w+)+$/
- if (regEmail.test(value)) {
- return callback()
- }
- callback(new Error("请输入正确的的邮箱"))
- }
- var checkTell = (rules, value, callback) => {
- const regMobile = /^1[3|4|5|6|7|8|9][0-9]{9}$/
- if (regMobile.test(value)) {
- return callback()
- }
- callback(new Error("请输入正确的手机号"))
- }
- return {
- type: "all",
- passWordForm: {
- oldPass: "",
- pass: "",
- checkPass: ""
- },
- emailForm: {
- email: "",
- code: "", //邮箱验证码
- emailDynacode: "", //邮箱动态验证码
- emailCodeText: "",
- key: "",
- currEmail: ""
- },
- passWordRules: {
- oldPass: [{
- required: true,
- message: "请输入原密码",
- trigger: "blur"
- }],
- pass: [{
- required: true,
- validator: validatePass,
- trigger: "blur"
- }],
- checkPass: [{
- required: true,
- validator: validatePass2,
- trigger: "blur"
- }]
- },
- emailRules: {
- email: [{
- required: true,
- message: "请输入正确的邮箱",
- trigger: "blur"
- },
- {
- validator: checkemail,
- trigger: "blur"
- }
- ],
- code: [{
- required: true,
- message: "请输入验证码",
- trigger: "blur"
- }],
- emailDynacode: [{
- required: true,
- message: "请输入动态验证码",
- trigger: "blur"
- }]
- },
- captcha: {
- id: "",
- img: ""
- },
- seconds: 120,
- timer: null,
- isSend: false,
- isMobileSend: false,
- tellForm: {
- tell: "",
- code: "", //邮箱验证码
- tellDynacode: "", //邮箱动态验证码
- tellCodeText: "",
- key: "",
- currTell: ""
- },
- tellRules: {
- tell: [{
- required: true,
- message: "请输入正确的手机号",
- trigger: "blur"
- },
- {
- validator: checkTell,
- trigger: "blur"
- }
- ],
- code: [{
- required: true,
- message: "请输入验证码",
- trigger: "blur"
- }],
- tellDynacode: [{
- required: true,
- message: "请输入动态验证码",
- trigger: "blur"
- }]
- },
- isClick: true,
- payCodeText: '获取验证码',
- step: 0,
- payCode: '', // 动态码
- payPassword: '', // 支付密码
- payRepassword: '', // 重复支付密码
- payKey: '', // 短信key
- payInput: '',
- palceText: '输入短信验证码',
- memberInfo: {},
- tellPassForm: {
- code: "",
- tellPassCodeText: "",
- key: "",
- tellPassDynacode: "",
- pass: '',
- checkPass: ''
- },
- tellPassRules: {
- code: [{
- required: true,
- message: "请输入验证码",
- trigger: "blur"
- }],
- tellPassDynacode: [{
- required: true,
- message: "请输入动态验证码",
- trigger: "blur"
- }],
- pass: [{
- required: true,
- validator: validateTellPass,
- trigger: "blur"
- }],
- checkPass: [{
- required: true,
- validator: validateTellPass2,
- trigger: "blur"
- }]
- },
- loading: true,
- yes: true
- }
- },
- created() {
- this.getcaptcha()
- this.seconds = 120
- this.tellForm.tellCodeText = "获取动态码"
- this.emailForm.emailCodeText = "获取动态码"
- this.tellPassForm.tellPassCodeText = "获取动态码"
- this.isSend = false
- this.isMobileSend = false
- clearInterval(this.timer)
- this.getInfo()
- },
- mounted() {
- let self = this;
- setTimeout(function() {
- self.yes = false
- }, 300)
- },
- methods: {
- //获取个人信息
- async getInfo() {
- await info()
- .then(res => {
- if (res.code == 0) {
- this.memberInfo = res.data
- this.emailForm.currEmail = res.data.email
- this.tellForm.currTell = res.data.mobile
- }
- this.loading = false
- })
- .catch(err => {
- this.loading = false
- this.$message.error(err.message)
- })
- },
- async edit(type) {
- await this.getInfo()
- if (type == 'payPassWord') {
- if (!this.tellForm.currTell) {
- this.$confirm("你还未绑定手机号,请先绑定手机号?", "提示信息", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning"
- }).then(res => {
- if (res = 'confirm') {
- this.type = 'tell'
- } else {
- this.type = 'all'
- }
- })
- } else {
- this.type = type
- }
- } else {
- this.type = type
- }
- },
- //获取验证码
- getcaptcha() {
- captcha({
- captcha_id: this.captcha.id
- })
- .then(res => {
- if (res.code >= 0) {
- this.captcha = res.data
- this.captcha.img = this.captcha.img.replace(/\r\n/g, "")
- }
- })
- .catch(err => {
- this.$message.error(err.message)
- })
- },
- //修改密码
- save() {
- this.$refs.passWordRef.validate(valid => {
- if (valid) {
- passWord({
- new_password: this.passWordForm.pass,
- old_password: this.passWordForm.oldPass
- })
- .then(res => {
- this.$message({
- message: "修改密码成功",
- type: "success"
- })
- this.type = "all"
- this.$store.dispatch("member/member_detail", {
- refresh: 1
- })
- this.passWordForm.pass = ""
- this.passWordForm.oldPass = ""
- this.passWordForm.checkPass = ""
- })
- .catch(err => {
- this.$message.error(err.message)
- })
- } else {
- return false
- }
- })
- },
- // 检测邮箱是否存在
- async getCheckEmail() {
- let result = await checkEmail({
- email: this.emailForm.email
- })
- .then(res => {
- if (res.code != 0) {
- this.$message({
- message: res.message,
- type: "success"
- })
- return false
- }
- return true
- })
- .catch(err => {
- this.$message.error(err.message)
- })
- return result
- },
- //绑定邮箱
- async bindEmail() {
- this.$refs.emailRef.validate(valid => {
- if (valid) {
- email({
- email: this.emailForm.email,
- captcha_id: this.captcha.id,
- captcha_code: this.emailForm.code,
- code: this.emailForm.emailDynacode,
- key: this.emailForm.key
- })
- .then(res => {
- if (res.code == 0) {
- this.$message({
- message: "邮箱绑定成功",
- type: "success"
- })
- this.type = "all"
- this.emailForm.email = ""
- this.emailForm.code = ""
- this.emailForm.emailDynacode = ""
- clearInterval(this.timer)
- this.getcaptcha()
- }
- })
- .catch(err => {
- this.getcaptcha()
- this.$message.error(err.message)
- })
- } else {
- return false
- }
- })
- },
- //获取手机验证码
- async gettellCode() {
- if (!this.isMobileSend) {
- this.isMobileSend = true
- await tellCode({
- mobile: this.tellForm.tell,
- captcha_id: this.captcha.id,
- captcha_code: this.tellForm.code
- })
- .then(res => {
- let data = res.data
- if (data.key) {
- if (this.seconds == 120 && this.timer == null) {
- this.timer = setInterval(() => {
- this.seconds--
- this.tellForm.tellCodeText = "已发送(" + this.seconds + "s)"
- }, 1000)
- }
- this.tellForm.key = data.key
- } else {
- this.$message({
- message: res.message,
- type: "warning"
- })
- this.isMobileSend = false
- }
- })
- .catch(err => {
- this.getcaptcha()
- this.$message.error(err.message)
- if(err.message == '当前手机号已存在'){
- this.isMobileSend = false
- }
- })
- } else {
- this.$message({
- message: "请勿重复点击",
- type: "warning"
- })
- }
- },
- //绑定手机号
- bindtell() {
- this.$refs.tellRef.validate(valid => {
- if (valid) {
- tell({
- mobile: this.tellForm.tell,
- captcha_id: this.captcha.id,
- captcha_code: this.tellForm.code,
- code: this.tellForm.tellDynacode,
- key: this.tellForm.key
- })
- .then(res => {
- if (res.code == 0) {
- this.$message({
- message: "手机号绑定成功",
- type: "success"
- })
- this.type = "all"
- this.tellForm.email = ""
- this.tellForm.code = ""
- this.tellForm.emailDynacode = ""
- clearInterval(this.timer)
- this.getcaptcha()
- }
- })
- .catch(err => {
- this.getcaptcha()
- this.$message.error(err.message)
- })
- } else {
- return false
- }
- })
- },
- //获取输入框数据
- input(val) {
- this.isClick = false
- if (this.step == 0 && val.length == 4) {
- this.payCode = val;
- } else if (this.step == 1 && val.length == 6) {
- this.payPassword = val;
- } else if (val.length == 6) {
- this.payRepassword = val;
- }
- },
- //获取支付验证码
- sendMobileCode() {
- if (!this.isSend) {
- paypwdcode().then(res => {
- let data = res.data;
- if (data.key) {
- if (this.seconds == 120 && this.timer == null) {
- this.timer = setInterval(() => {
- this.seconds--;
- this.payCodeText =
- "已发送(" + this.seconds + "s)";
- }, 1000);
- }
- this.payKey = data.key;
- } else {
- this.$message({
- message: res.message,
- type: 'warning'
- });
- this.isSend = false;
- }
- })
- .catch(err => {
- this.$message.error(err.message);
- });
- }
- },
- //点击确定
- bindPayPwd() {
- clearInterval(this.timer)
- const reg = /^[0-9]*$/
- if (this.step == 0) {
- verifypaypwdcode({
- code: this.payCode,
- key: this.payKey
- }).then(res => {
- if (res.code == 0) {
- this.$refs.input.clear();
- this.step = 1;
- this.palceText = '请设置支付密码'
- }
- }).catch(err => {
- this.$message.error(err.message);
- })
- } else if (this.step == 1) {
- if (reg.test(this.$refs.input.value)) {
- this.$refs.input.clear();
- this.step = 2;
- this.palceText = '请再次输入'
- } else {
- this.$message.error('请输入数字')
- this.step = 1;
- this.$refs.input.clear();
- }
- } else {
- if (this.payPassword == this.payRepassword) {
- if (this.isSub) return;
- this.isSub = true;
- modifypaypassword({
- key: this.payKey,
- code: this.payCode,
- password: this.payPassword
- }).then(res => {
- if (res.code >= 0) {
- this.$message({
- message: "修改支付密码成功",
- type: "success"
- })
- this.type = 'all'
- this.step = 0,
- this.$refs.input.clear();
- clearInterval(this.timer)
- }
- }).catch(err => {
- this.$message.error(err.message);
- })
- } else {
- this.$message.error('两次密码输入不一样');
- this.initInfo();
- }
- }
- },
- //初始化信息
- initInfo() {
- this.step = 1;
- this.palceText = '请设置支付密码'
- this.password = '';
- this.repassword = '';
- this.oldpassword = '';
- this.isSub = false;
- this.$refs.input.clear();
- },
- //获取动态码
- getTellPassCode() {
- if (!this.isSend) {
- this.isSend = true
- pwdmobliecode({
- captcha_id: this.captcha.id,
- captcha_code: this.tellPassForm.code,
- })
- .then(res => {
- let data = res.data
- if (data.key) {
- if (this.seconds == 120 && this.timer == null) {
- this.timer = setInterval(() => {
- this.seconds--
- this.tellPassForm.tellPassCodeText = "已发送(" + this.seconds + "s)"
- }, 1000)
- }
- this.tellPassForm.key = data.key
- } else {
- this.$message({
- message: res.message,
- type: "warning"
- })
- this.isSend = false
- }
- })
- .catch(err => {
- this.getcaptcha()
- this.$message.error(err.message)
- })
- } else {
- this.$message({
- message: "请勿重复点击",
- type: "warning"
- })
- }
- },
- //修改密码
- tellPassSave() {
- this.$refs.tellPassRef.validate(valid => {
- if (valid) {
- passWord({
- new_password: this.tellPassForm.pass,
- code: this.tellPassForm.tellPassDynacode,
- key: this.tellPassForm.key,
- })
- .then(res => {
- this.$message({
- message: "修改密码成功",
- type: "success"
- })
- this.type = "all"
- this.$store.dispatch("member/member_detail", {
- refresh: 1
- })
- this.tellPassForm.pass = ""
- this.tellPassForm.checkPass = ""
- this.tellPassForm.key = ""
- this.tellPassForm.tellPassDynacode = ""
- })
- .catch(err => {
- this.$message.error(err.message)
- })
- } else {
- return false
- }
- })
- },
- },
- filters: {
- mobile(mobile) {
- return mobile.substring(0, 4 - 1) + '****' + mobile.substring(6 + 1);
- }
- },
- }
|