Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
html
/
poolin_app
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
42f40dbb
authored
Feb 10, 2018
by
zhanghui1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
未完成错误版
parent
8e97b441
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
141 additions
and
58 deletions
+141
-58
src/components/ucenter/helpers.js
+74
-46
src/components/ucenter/index.vue
+6
-6
src/store/index.js
+61
-6
No files found.
src/components/ucenter/helpers.js
View file @
42f40dbb
...
@@ -17,7 +17,7 @@ import axios from 'axios';
...
@@ -17,7 +17,7 @@ import axios from 'axios';
// let regExp = new RegExp('\{'+_key+'\}', 'igm');
// let regExp = new RegExp('\{'+_key+'\}', 'igm');
// url = url.replace(regExp, value);
// url = url.replace(regExp, value);
// }
// }
// // 获取token
// // 获取token
// let access_token = localStorage.getItem('access_token');
// let access_token = localStorage.getItem('access_token');
// return new Promise((resolve, reject) => {
// return new Promise((resolve, reject) => {
...
@@ -93,7 +93,7 @@ import axios from 'axios';
...
@@ -93,7 +93,7 @@ import axios from 'axios';
// break;
// break;
// }
// }
// }
// }
// lolpool && lolpool.$message && lolpool.$message.error(errorMsg, 5);
// lolpool && lolpool.$message && lolpool.$message.error(errorMsg, 5);
// });
// });
// });
// });
...
@@ -111,59 +111,88 @@ import axios from 'axios';
...
@@ -111,59 +111,88 @@ import axios from 'axios';
// }
// }
export
const
apiErrMap
=
(
errNo
,
errMsg
)
=>
{
export
const
apiErrMap
=
(
errNo
,
errMsg
)
=>
{
if
(
errNo
==
0
)
{
if
(
errNo
==
0
)
{
return
{
return
{
errNo
:
0
,
errNo
:
0
,
errMsg
:
''
errMsg
:
''
};
};
}
}
if
(
errNo
==
-
1
)
{
if
(
errNo
==
-
1
)
{
return
{
return
{
errNo
:
-
1
,
errNo
:
-
1
,
errMsg
errMsg
};
};
}
}
// todo: 翻译
// todo: 翻译
const
errMap
=
new
Map
()
const
errMap
=
new
Map
()
.
set
(
100
,
'步骤不正确'
)
.
set
(
100
,
'步骤不正确'
)
.
set
(
1000
,
'请输入验证码'
)
.
set
(
1000
,
'请输入验证码'
)
.
set
(
1001
,
'验证码错误'
)
.
set
(
1001
,
'验证码错误'
)
.
set
(
1010
,
'用户已存在'
)
.
set
(
1010
,
'用户已存在'
)
.
set
(
1011
,
'用户不存在'
)
.
set
(
1011
,
'用户不存在'
)
.
set
(
1012
,
'用户被锁定'
)
.
set
(
1012
,
'用户被锁定'
)
.
set
(
1013
,
'登录次数过多'
)
.
set
(
1013
,
'登录次数过多'
)
.
set
(
1014
,
'密码错误'
)
.
set
(
1014
,
'密码错误'
)
.
set
(
1015
,
'invalid totp code'
)
.
set
(
1015
,
'invalid totp code'
)
.
set
(
1020
,
'验证码过多'
)
.
set
(
1020
,
'验证码过多'
)
.
set
(
1021
,
'无效手机号'
)
.
set
(
1021
,
'无效手机号'
)
.
set
(
1022
,
'邮箱地址无效'
)
.
set
(
1022
,
'邮箱地址无效'
)
.
set
(
1023
,
'电话号码不支持'
)
.
set
(
1023
,
'电话号码不支持'
)
.
set
(
1024
,
'sms rate limited'
);
.
set
(
1024
,
'sms rate limited'
);
errMsg
=
errMap
.
get
(
errNo
);
if
(
errMsg
)
{
return
{
errNo
,
errMsg
}
}
errMsg
=
errMap
.
get
(
errNo
);
if
(
errMsg
)
{
return
{
return
{
errNo
,
errNo
,
errMsg
:
'网络错误'
errMsg
}
}
}
return
{
errNo
,
errMsg
:
'网络错误'
}
}
}
export
const
isEmailAddress
=
(
str
)
=>
{
export
const
isEmailAddress
=
(
str
)
=>
{
return
new
RegExp
(
'^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$'
).
test
(
str
);
return
new
RegExp
(
'^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$'
).
test
(
str
);
}
}
export
const
isVerifyCode
=
(
str
)
=>
{
export
const
isVerifyCode
=
(
str
)
=>
{
return
new
RegExp
(
'^[a-z0-9A-Z]{4}$'
).
test
(
str
);
return
new
RegExp
(
'^[a-z0-9A-Z]{4}$'
).
test
(
str
);
}
}
export
const
api
=
{
// 邮箱注册api
'post-register-email-start'
:
'/register/email/start'
,
'post-register-email-verify-code'
:
'/register/email/verify-code'
,
'post-register-email-password'
:
'/register/email/password'
,
// 手机注册api
'post-register-mobile-start'
:
'/register/mobile/start'
,
'post-register-mobile-verify-code'
:
'/register/mobile/verify-code'
,
'post-register-mobile-password'
:
'/register/mobile/password'
,
// 登录
'post-login-start'
:
'/login/start'
,
'post-login-mobile'
:
'/login/start/mobile'
,
'post-login-password'
:
'/login/password'
,
'post-login-totp'
:
'/login/totp'
,
'post-login-code'
:
'/login/code'
,
// 重置密码
'post-reset-start'
:
'/reset/start'
,
'post-reset-send-code'
:
'/reset/send-code'
,
'post-reset-verify'
:
'/reset/verify'
,
'post-reset-password'
:
'/reset/password'
,
// 登出
'get-logout-do'
:
'/logout/do'
,
// 获取用户信息
'get-userinfo'
:
'/userinfo'
,
}
// export const getServices = (serviceName) => {
// export const getServices = (serviceName) => {
// }
// }
\ No newline at end of file
src/components/ucenter/index.vue
View file @
42f40dbb
...
@@ -41,7 +41,7 @@
...
@@ -41,7 +41,7 @@
import
{
mapState
}
from
'vuex'
import
{
mapState
}
from
'vuex'
import
countryInfo
from
'./country_info.json'
import
countryInfo
from
'./country_info.json'
import
captcha
from
'./captcha.vue'
import
captcha
from
'./captcha.vue'
import
{
apiErrMap
,
isEmailAddress
,
isVerifyCode
}
from
'./helpers.js'
;
import
{
apiErrMap
,
isEmailAddress
,
isVerifyCode
,
api
}
from
'./helpers.js'
;
export
default
{
export
default
{
components
:
{
components
:
{
captcha
captcha
...
@@ -108,7 +108,7 @@ export default {
...
@@ -108,7 +108,7 @@ export default {
email
=
this
.
form
.
email
;
email
=
this
.
form
.
email
;
const
{
data
:
accountResponse
}
=
await
this
.
$axios
const
{
data
:
accountResponse
}
=
await
this
.
$axios
.
post
(
config
.
apiDomain
+
config
.
api
[
'post-login-start'
],
{
.
post
(
this
.
UC_BASEURL
+
'/auth/api'
+
api
[
'post-login-start'
],
{
captcha
:
this
.
showEmailCaptcha
?
this
.
form
.
captcha
:
''
,
// todo: 登录验证码
captcha
:
this
.
showEmailCaptcha
?
this
.
form
.
captcha
:
''
,
// todo: 登录验证码
email
,
email
,
type
:
'email'
type
:
'email'
...
@@ -127,7 +127,7 @@ export default {
...
@@ -127,7 +127,7 @@ export default {
}
}
const
{
data
:
passwordResponse
}
=
await
this
.
$axios
const
{
data
:
passwordResponse
}
=
await
this
.
$axios
.
post
(
config
.
apiDomain
+
config
.
api
[
'post-login-password'
],
{
.
post
(
this
.
UC_BASEURL
+
"/auth/api"
+
api
[
'post-login-password'
],
{
password
:
this
.
form
.
password
password
:
this
.
form
.
password
});
});
...
@@ -154,7 +154,7 @@ export default {
...
@@ -154,7 +154,7 @@ export default {
email
=
this
.
form
.
country
+
'|'
+
this
.
form
.
email
;
email
=
this
.
form
.
country
+
'|'
+
this
.
form
.
email
;
const
{
data
:
accountResponse
}
=
await
this
.
$axios
const
{
data
:
accountResponse
}
=
await
this
.
$axios
.
post
(
config
.
apiDomain
+
config
.
api
[
'post-login-start'
],
{
.
post
(
apiDomain
+
'/auth/api'
+
api
[
'post-login-start'
],
{
captcha
:
this
.
showMobileCaptcha
?
this
.
form
.
captcha
:
''
,
// todo: 登录验证码
captcha
:
this
.
showMobileCaptcha
?
this
.
form
.
captcha
:
''
,
// todo: 登录验证码
email
,
email
,
type
:
'mobile'
type
:
'mobile'
...
@@ -174,7 +174,7 @@ export default {
...
@@ -174,7 +174,7 @@ export default {
}
}
const
{
data
:
passwordResponse
}
=
await
this
.
$axios
const
{
data
:
passwordResponse
}
=
await
this
.
$axios
.
post
(
config
.
apiDomain
+
config
.
api
[
'post-login-password'
],
{
.
post
(
apiDomain
+
'/auth/api'
+
api
[
'post-login-password'
],
{
password
:
this
.
form
.
password
password
:
this
.
form
.
password
});
});
...
@@ -187,7 +187,7 @@ export default {
...
@@ -187,7 +187,7 @@ export default {
}
}
// 获取用户信息
// 获取用户信息
const
userinfo
=
await
this
.
$store
.
dispatch
(
"
Auth/
fetchUser"
);
const
userinfo
=
await
this
.
$store
.
dispatch
(
"fetchUser"
);
this
.
showLoading
=
false
;
this
.
showLoading
=
false
;
// 跳转用户中心
// 跳转用户中心
...
...
src/store/index.js
View file @
42f40dbb
import
Vue
from
'vue'
;
import
Vue
from
'vue'
;
import
Vuex
from
'vuex'
;
import
Vuex
from
'vuex'
;
import
{
api
}
from
'@/components/ucenter/helpers.js'
;
Vue
.
use
(
Vuex
);
Vue
.
use
(
Vuex
);
import
dictionaries
from
'@/utils/dictionaries.js'
;
//字典
import
dictionaries
from
'@/utils/dictionaries.js'
;
//字典
...
@@ -27,6 +28,7 @@ const state = {
...
@@ -27,6 +28,7 @@ const state = {
tab_bar
:
0
,
tab_bar
:
0
,
UC_BASEURL
:
'https://ucdev1212.blockin.com'
,
UC_BASEURL
:
'https://ucdev1212.blockin.com'
,
user
:
null
,
}
}
const
mutations
=
{
const
mutations
=
{
setEnterPannel
(
state
,
v
)
{
setEnterPannel
(
state
,
v
)
{
...
@@ -57,18 +59,71 @@ const mutations = {
...
@@ -57,18 +59,71 @@ const mutations = {
setLanguage
(
state
,
v
)
{
setLanguage
(
state
,
v
)
{
state
.
language
=
v
state
.
language
=
v
localStorage
.
setItem
(
"language"
,
v
);
localStorage
.
setItem
(
"language"
,
v
);
},
FETCH_USER_SUCCESS
(
state
,
{
user
})
{
window
.
config
.
user
=
user
;
state
.
user
=
user
;
},
FETCH_USER_FAILURE
(
state
)
{},
LOGOUT
(
state
)
{
state
.
user
=
null
},
UPDATE_USER
(
state
,
{
user
})
{
state
.
user
=
user
}
}
}
}
const
getters
=
{
const
getters
=
{
// count: function(state) {
user
:
state
=>
{
// return state.count += 100;
return
state
.
user
// }
},
check
:
state
=>
{
let
hasLogged
=
state
.
user
&&
Boolean
(
state
.
user
.
uid
);
if
(
!
hasLogged
)
{
hasLogged
=
Boolean
(
JSON
.
parse
(
window
.
config
.
register
));
}
return
hasLogged
;
}
}
}
const
actions
=
{
const
actions
=
{
// addAction(context) {
async
fetchUser
({
commit
})
{
// context.commit('add', 10)
try
{
// }
const
{
data
}
=
await
axios
.
get
(
config
.
apiDomain
+
api
[
'get-userinfo'
]);
if
(
data
.
err_no
)
{
throw
new
Error
(
'get userinfo fail'
);
}
commit
(
'FETCH_USER_SUCCESS'
,
{
user
:
data
.
data
.
userinfo
});
return
data
.
data
.
userinfo
;
}
catch
(
e
)
{
commit
(
'FETCH_USER_FAILURE'
)
return
null
;
}
},
updateUser
({
commit
},
payload
)
{
commit
(
'UPDATE_USER'
,
payload
)
},
async
logout
({
commit
})
{
try
{
await
axios
.
get
(
'/logout'
)
}
catch
(
e
)
{}
commit
(
'LOGOUT'
)
}
}
}
export
default
new
Vuex
.
Store
({
export
default
new
Vuex
.
Store
({
state
,
state
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment