v4.0
Pan 2018-10-29 15:30:29 +08:00
parent 0caf5580ac
commit 192f5028fb
3 changed files with 13 additions and 13 deletions

View File

@ -2,7 +2,7 @@
* Created by jiachenpan on 16/11/18. * Created by jiachenpan on 16/11/18.
*/ */
export function isvalidUsername(str) { export function validUsername(str) {
const valid_map = ['admin', 'editor'] const valid_map = ['admin', 'editor']
return valid_map.indexOf(str.trim()) >= 0 return valid_map.indexOf(str.trim()) >= 0
} }
@ -26,7 +26,7 @@ export function validateUpperCase(str) {
} }
/* 大小写字母*/ /* 大小写字母*/
export function validatAlphabets(str) { export function validateAlphabets(str) {
const reg = /^[A-Za-z]+$/ const reg = /^[A-Za-z]+$/
return reg.test(str) return reg.test(str)
} }

View File

@ -37,13 +37,13 @@
</template> </template>
<script> <script>
import { isvalidUsername } from '@/utils/validate' import { validUsername } from '@/utils/validate'
export default { export default {
name: 'Login', name: 'Login',
data() { data() {
const validateUsername = (rule, value, callback) => { const validateUsername = (rule, value, callback) => {
if (!isvalidUsername(value)) { if (!validUsername(value)) {
callback(new Error('请输入正确的用户名')) callback(new Error('请输入正确的用户名'))
} else { } else {
callback() callback()

View File

@ -1,9 +1,9 @@
import { isvalidUsername, validateURL, validateLowerCase, validateUpperCase, validatAlphabets } from '@/utils/validate.js' import { validUsername, validateURL, validateLowerCase, validateUpperCase, validateAlphabets } from '@/utils/validate.js'
describe('Utils:validate', () => { describe('Utils:validate', () => {
it('isvalidUsername', () => { it('validUsername', () => {
expect(isvalidUsername('admin')).toBe(true) expect(validUsername('admin')).toBe(true)
expect(isvalidUsername('editor')).toBe(true) expect(validUsername('editor')).toBe(true)
expect(isvalidUsername('xxxx')).toBe(false) expect(validUsername('xxxx')).toBe(false)
}) })
it('validateURL', () => { it('validateURL', () => {
expect(validateURL('https://github.com/PanJiaChen/vue-element-admin')).toBe(true) expect(validateURL('https://github.com/PanJiaChen/vue-element-admin')).toBe(true)
@ -20,9 +20,9 @@ describe('Utils:validate', () => {
expect(validateUpperCase('Abc')).toBe(false) expect(validateUpperCase('Abc')).toBe(false)
expect(validateUpperCase('123ABC')).toBe(false) expect(validateUpperCase('123ABC')).toBe(false)
}) })
it(' validatAlphabets', () => { it('validateAlphabets', () => {
expect(validatAlphabets('ABC')).toBe(true) expect(validateAlphabets('ABC')).toBe(true)
expect(validatAlphabets('Abc')).toBe(true) expect(validateAlphabets('Abc')).toBe(true)
expect(validatAlphabets('123aBC')).toBe(false) expect(validateAlphabets('123aBC')).toBe(false)
}) })
}) })