diff --git a/src/components/jp-verification-literalness/jp-verification-literalness.vue b/src/components/jp-verification-literalness/jp-verification-literalness.vue new file mode 100644 index 0000000..4abf2a3 --- /dev/null +++ b/src/components/jp-verification-literalness/jp-verification-literalness.vue @@ -0,0 +1,169 @@ + + + + + \ No newline at end of file diff --git a/src/pages/login/login.vue b/src/pages/login/login.vue index aa9e960..dfa7bed 100644 --- a/src/pages/login/login.vue +++ b/src/pages/login/login.vue @@ -25,6 +25,22 @@ v-model="password" /> + + 验证码 + + + + + 登 录 @@ -43,15 +59,41 @@ import { } from '@/com/utils.js' import jwt from '@/api/jwt.js' import md5 from 'js-md5' +import Security from '@/components/jp-verification-literalness/jp-verification-literalness.vue' export default { + components: { + Security, + }, data() { return { + identify: '', username: '', //手机号码 password: '', //密码 + identifyCode: '', } }, - onLoad() {}, + onLoad() { + this.makeCode() + }, methods: { + randomNum(min, max) { + return Math.floor(Math.random() * (max - min) + min) + }, + + refreshCode() { + this.identifyCode = '' + this.makeCode() + }, + + makeCode(l = 4) { + const identifyCodes = '1234567890abcdef' + let code = '' + + for (let i = 0; i < l; i++) { + code += identifyCodes[this.randomNum(0, identifyCodes.length)] + } + this.identify = code + }, //当前登录按钮操作 login() { if (!this.username) { @@ -63,9 +105,18 @@ export default { uni.showToast({ title: '请输入您的密码', icon: 'none' }) return } + if (!this.identifyCode) { + uni.showToast({ title: '请输入验证码', icon: 'none' }) + return + } + if(this.identifyCode != this.identify){ + uni.showToast({ title: '验证码不正确', icon: 'none' }) + return + } let params = { username: this.username, password: md5(this.password), + identifyCode: this.identifyCode, } this.$http