Skip to content

Commit

Permalink
feat: 修改login表单校验
Browse files Browse the repository at this point in the history
  • Loading branch information
cadecode committed Apr 15, 2023
1 parent 79d45b4 commit 8105a76
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
10 changes: 0 additions & 10 deletions src/utils/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,3 @@
export function isExternal(path) {
return /^(https?:|mailto:|tel:)/.test(path)
}

/**
* TODO
* @param {string} str
* @returns {Boolean}
*/
export function validUsername(str) {
const valid_map = ['admin', 'editor']
return valid_map.indexOf(str.trim()) >= 0
}
8 changes: 3 additions & 5 deletions src/views/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,19 @@
</template>

<script>
import { validUsername } from '@/utils/validate'
export default {
name: 'Login',
data() {
const validateUsername = (rule, value, callback) => {
if (!validUsername(value)) {
callback(new Error('Please enter the correct username'))
if (value.length < 1) {
callback(new Error('用户名不能为空'))
} else {
callback()
}
}
const validatePassword = (rule, value, callback) => {
if (value.length < 1) {
callback(new Error('The password can not be empty'))
callback(new Error('密码不能为空'))
} else {
callback()
}
Expand Down

0 comments on commit 8105a76

Please sign in to comment.