show user nickname in settings page
This commit is contained in:
+29
-3
@@ -1,23 +1,49 @@
|
||||
const tokenLocalStorageKey = 'lab_user_token';
|
||||
const userNameLocalStorageKey = 'lab_user_name';
|
||||
const userNickNameLocalStorageKey = 'lab_user_nickname';
|
||||
|
||||
function getToken() {
|
||||
return localStorage.getItem(tokenLocalStorageKey);
|
||||
}
|
||||
|
||||
function getUserName() {
|
||||
return localStorage.getItem(userNameLocalStorageKey);
|
||||
}
|
||||
|
||||
function getUserNickName() {
|
||||
return localStorage.getItem(userNickNameLocalStorageKey);
|
||||
}
|
||||
|
||||
function isUserLogined() {
|
||||
return !!getToken();
|
||||
}
|
||||
|
||||
function updateToken(token) {
|
||||
return localStorage.setItem(tokenLocalStorageKey, token);
|
||||
function updateToken(item) {
|
||||
if (typeof(item) === 'string') {
|
||||
return localStorage.setItem(tokenLocalStorageKey, item);
|
||||
} else if (typeof(item) === 'object') {
|
||||
localStorage.setItem(tokenLocalStorageKey, item.token);
|
||||
localStorage.setItem(userNameLocalStorageKey, item.username);
|
||||
localStorage.setItem(userNickNameLocalStorageKey, item.nickname);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function clearToken() {
|
||||
return localStorage.removeItem(tokenLocalStorageKey);
|
||||
localStorage.removeItem(tokenLocalStorageKey);
|
||||
localStorage.removeItem(userNameLocalStorageKey);
|
||||
localStorage.removeItem(userNickNameLocalStorageKey);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export default {
|
||||
getToken,
|
||||
getUserName,
|
||||
getUserNickName,
|
||||
isUserLogined,
|
||||
updateToken,
|
||||
clearToken
|
||||
|
||||
@@ -55,6 +55,8 @@ export default {
|
||||
'OK': 'OK',
|
||||
'Cancel': 'Cancel',
|
||||
'Done': 'Done',
|
||||
'User': 'User',
|
||||
'Application': 'Application',
|
||||
'Home': 'Home',
|
||||
'Journals': 'Journals',
|
||||
'Accounts': 'Accounts',
|
||||
@@ -90,6 +92,7 @@ export default {
|
||||
'Use a backup code': 'Use a backup code',
|
||||
'Use a passcode': 'Use a passcode',
|
||||
'Sign Up': 'Sign Up',
|
||||
'User Profile': 'User Profile',
|
||||
'Language': 'Language',
|
||||
'You have been successfully registered': 'You have been successfully registered',
|
||||
'Unable to sign up': 'Unable to sign up',
|
||||
|
||||
@@ -55,6 +55,8 @@ export default {
|
||||
'OK': '确定',
|
||||
'Cancel': '取消',
|
||||
'Done': '完成',
|
||||
'User': '用户',
|
||||
'Application': '应用',
|
||||
'Home': '首页',
|
||||
'Journals': '流水',
|
||||
'Accounts': '账户',
|
||||
@@ -90,6 +92,7 @@ export default {
|
||||
'Use a backup code': '使用备用码',
|
||||
'Use a passcode': '使用验证码',
|
||||
'Sign Up': '注册',
|
||||
'User Profile': '用户信息',
|
||||
'Language': '语言',
|
||||
'You have been successfully registered': '注册成功',
|
||||
'Unable to sign up': '无法注册',
|
||||
|
||||
@@ -170,7 +170,7 @@ export default {
|
||||
return;
|
||||
}
|
||||
|
||||
self.$user.updateToken(data.result.token);
|
||||
self.$user.updateToken(data.result);
|
||||
router.navigate('/');
|
||||
}).catch(error => {
|
||||
hasResponse = true;
|
||||
@@ -225,7 +225,7 @@ export default {
|
||||
return;
|
||||
}
|
||||
|
||||
self.$user.updateToken(data.result.token);
|
||||
self.$user.updateToken(data.result);
|
||||
app.sheet.close('#2fa-auth-sheet');
|
||||
router.navigate('/');
|
||||
}).catch(error => {
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
<template>
|
||||
<f7-page name="home">
|
||||
<f7-page name="settings">
|
||||
<f7-navbar :title="$t('Settings')" :back-link="$t('Back')"></f7-navbar>
|
||||
<f7-block-title>{{ userNickName }}</f7-block-title>
|
||||
<f7-list>
|
||||
<f7-list-item :title="$t('User Profile')" link="#"></f7-list-item>
|
||||
<f7-list-button @click="logout">{{ $t('Log Out') }}</f7-list-button>
|
||||
</f7-list>
|
||||
<f7-block-title>{{ $t('Application') }}</f7-block-title>
|
||||
<f7-list>
|
||||
<f7-list-item
|
||||
:title="$t('Language')"
|
||||
@@ -11,7 +17,6 @@
|
||||
:value="locale">{{ lang.displayName }}</option>
|
||||
</select>
|
||||
</f7-list-item>
|
||||
<f7-list-button @click="logout">{{ $t('Log Out') }}</f7-list-button>
|
||||
</f7-list>
|
||||
</f7-page>
|
||||
</template>
|
||||
@@ -26,6 +31,9 @@ export default {
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
userNickName() {
|
||||
return this.$user.getUserNickName() || this.$user.getUserName() || this.$t('User');
|
||||
},
|
||||
currentLocale: {
|
||||
get: function () {
|
||||
return this.$i18n.locale
|
||||
|
||||
@@ -107,7 +107,7 @@ export default {
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof(data.result) === 'string') {
|
||||
if (typeof(data.result) === 'object') {
|
||||
self.$user.updateToken(data.result);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user