-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
417 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import request from '@/utils/request' | ||
|
||
export function login (data) { | ||
return request({ | ||
url: '/user/login', | ||
method: 'post', | ||
data | ||
}) | ||
} | ||
|
||
export function getInfo (token) { | ||
return request({ | ||
url: '/user/info', | ||
method: 'get', | ||
params: { token } | ||
}) | ||
} | ||
|
||
export function logout () { | ||
return request({ | ||
url: '/user/logout', | ||
method: 'post' | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<template> | ||
<van-button class="verify-btn" | ||
@click="btnClick" | ||
size="mini" | ||
type="primary" | ||
:disabled="!!codeRestTime"> | ||
{{codeRestTime ? `${codeRestTime}S` : '发送验证码'}} | ||
</van-button> | ||
</template> | ||
<script> | ||
import { Button } from 'vant' | ||
export default { | ||
name: 'VerifyCodeBtn', | ||
components: { | ||
[Button.name]: Button | ||
}, | ||
props: { | ||
btnMsg: { | ||
type: String, | ||
default: '发送验证码' | ||
}, | ||
restTime: { | ||
type: Number, | ||
default: 30 | ||
} | ||
}, | ||
data () { | ||
return { | ||
codeRestTime: 0 | ||
} | ||
}, | ||
methods: { | ||
btnClick () { | ||
this.codeRestTime = this.restTime | ||
let timer = setInterval(() => { | ||
--this.codeRestTime | ||
if (!this.codeRestTime) { | ||
clearInterval(timer) | ||
timer = null | ||
} | ||
}, 1000) | ||
this.$emit('sendVerifyCode') | ||
} | ||
} | ||
} | ||
</script> | ||
<style lang="scss" scoped> | ||
.verify-btn{ | ||
padding: 0 5px; | ||
min-width: 6.5em; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export default [ | ||
{ | ||
path: '/login', | ||
name: 'login', | ||
component: () => import(/* webpackChunkName: "login" */ 'views/user/Login.vue'), | ||
meta: { | ||
title: '登录' | ||
// auth: true, | ||
// keepAlive: true | ||
} | ||
}, | ||
{ | ||
path: '/register', | ||
name: 'register', | ||
component: () => import(/* webpackChunkName: "register" */ 'views/user/Register.vue'), | ||
meta: { | ||
title: '注册' | ||
// auth: true, | ||
// keepAlive: true | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { login } from 'api/user' | ||
import { Toast } from 'vant' | ||
|
||
const LOGIN = 'LOGIN'// 获取用户信息 | ||
|
||
export default { | ||
namespaced: true, | ||
state: { | ||
token: localStorage.getItem('token') || '', | ||
user: JSON.parse(localStorage.getItem('userDate')) || {} | ||
}, | ||
mutations: { | ||
|
||
[LOGIN] (state, data) { | ||
let userDate = data.data | ||
state.token = userDate.token | ||
state.user = userDate | ||
localStorage.setItem('token', userDate.token) | ||
localStorage.setItem('userDate', JSON.stringify(userDate)) | ||
} | ||
|
||
}, | ||
actions: { | ||
async login (state, data) { | ||
try { | ||
let res = await login({ | ||
phoneNumber: data.phoneNumber, | ||
password: data.password | ||
}) | ||
state.commit(LOGIN, res) | ||
Toast({ | ||
message: '登录成功', | ||
position: 'middle', | ||
duration: 2000 | ||
}) | ||
setTimeout(() => { | ||
const redirect = data.$route.query.redirect || '/' | ||
data.$router.replace({ | ||
path: redirect | ||
}) | ||
}, 3000) | ||
} catch (error) { | ||
} | ||
} | ||
}, | ||
getters: { | ||
token (state) { | ||
return state.token | ||
}, | ||
user (state) { | ||
console.log('state', state) | ||
return state.user | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/** | ||
* Created by PanJiaChen on 16/11/18. | ||
*/ | ||
|
||
/** | ||
* @param {string} path | ||
* @returns {Boolean} | ||
*/ | ||
export function isExternal (path) { | ||
return /^(https?:|mailto:|tel:)/.test(path) | ||
} | ||
|
||
/** | ||
* @param {string} str | ||
* @returns {Boolean} | ||
*/ | ||
export function validUsername (str) { | ||
const validMap = ['admin', 'editor'] | ||
return validMap.indexOf(str.trim()) >= 0 | ||
} | ||
|
||
/** | ||
* @param {string} url | ||
* @returns {Boolean} | ||
*/ | ||
export function validURL (url) { | ||
const reg = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/ | ||
return reg.test(url) | ||
} | ||
|
||
/** | ||
* @param {string} str | ||
* @returns {Boolean} | ||
*/ | ||
export function validLowerCase (str) { | ||
const reg = /^[a-z]+$/ | ||
return reg.test(str) | ||
} | ||
|
||
/** | ||
* @param {string} str | ||
* @returns {Boolean} | ||
*/ | ||
export function validUpperCase (str) { | ||
const reg = /^[A-Z]+$/ | ||
return reg.test(str) | ||
} | ||
|
||
/** | ||
* @param {string} str | ||
* @returns {Boolean} | ||
*/ | ||
export function validAlphabets (str) { | ||
const reg = /^[A-Za-z]+$/ | ||
return reg.test(str) | ||
} | ||
|
||
/** | ||
* @param {string} email | ||
* @returns {Boolean} | ||
*/ | ||
export function validEmail (email) { | ||
const reg = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ | ||
return reg.test(email) | ||
} | ||
|
||
/** | ||
* @param {string} str | ||
* @returns {Boolean} | ||
*/ | ||
export function isString (str) { | ||
if (typeof str === 'string' || str instanceof String) { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
/** | ||
* @param {Array} arg | ||
* @returns {Boolean} | ||
*/ | ||
export function isArray (arg) { | ||
if (typeof Array.isArray === 'undefined') { | ||
return Object.prototype.toString.call(arg) === '[object Array]' | ||
} | ||
return Array.isArray(arg) | ||
} |
Oops, something went wrong.