Updated components to composition API
This commit is contained in:
parent
e89e325cad
commit
b89163704d
|
@ -27,7 +27,7 @@
|
||||||
<q-btn dense flat no-wrap>
|
<q-btn dense flat no-wrap>
|
||||||
<q-avatar size="lg">
|
<q-avatar size="lg">
|
||||||
<q-img
|
<q-img
|
||||||
:src="`/api/Images/user/160x160/${user.id}/download?access_token=${token}`"
|
:src="`/api/Images/user/160x160/${user.id}/download?access_token=${user.token}`"
|
||||||
spinner-color="white"
|
spinner-color="white"
|
||||||
/>
|
/>
|
||||||
</q-avatar>
|
</q-avatar>
|
||||||
|
@ -40,8 +40,9 @@
|
||||||
</q-header>
|
</q-header>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts" setup>
|
||||||
import { Options, Vue } from 'vue-class-component';
|
import { computed } from 'vue';
|
||||||
|
import { useStore } from 'vuex';
|
||||||
import UserPanel from '@/components/UserPanel.vue';
|
import UserPanel from '@/components/UserPanel.vue';
|
||||||
|
|
||||||
interface UserProfile {
|
interface UserProfile {
|
||||||
|
@ -51,18 +52,13 @@ interface UserProfile {
|
||||||
token: string;
|
token: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Options({
|
const store = useStore();
|
||||||
components: {
|
const user = computed((): UserProfile => {
|
||||||
UserPanel,
|
return {
|
||||||
},
|
id: store.state.user.id,
|
||||||
})
|
username: store.state.user.username,
|
||||||
export default class Topbar extends Vue {
|
nickname: store.state.user.nickname,
|
||||||
get user(): UserProfile {
|
token: store.getters.token,
|
||||||
return this.$store.state.user;
|
};
|
||||||
}
|
});
|
||||||
|
|
||||||
get token(): string {
|
|
||||||
return this.$store.getters.token;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -2,16 +2,16 @@
|
||||||
<q-menu>
|
<q-menu>
|
||||||
<div class="row no-wrap q-pa-md">
|
<div class="row no-wrap q-pa-md">
|
||||||
<div class="column">
|
<div class="column">
|
||||||
<div class="text-h6 q-mb-md">{{ $t('components.userPanel.settings') }}</div>
|
<div class="text-h6 q-mb-md">{{ t('components.userPanel.settings') }}</div>
|
||||||
<q-toggle
|
<q-toggle
|
||||||
:label="$t(`globals.lang['${language}']`)"
|
:label="t(`globals.lang['${locale}']`)"
|
||||||
icon="public"
|
icon="public"
|
||||||
color="orange"
|
color="orange"
|
||||||
false-value="es"
|
false-value="es"
|
||||||
true-value="en"
|
true-value="en"
|
||||||
v-model="language"
|
v-model="locale"
|
||||||
/>
|
/>
|
||||||
<q-toggle v-model="mode" checked-icon="dark_mode" color="orange" unchecked-icon="light_mode" />
|
<q-toggle v-model="darkMode" checked-icon="dark_mode" color="orange" unchecked-icon="light_mode" />
|
||||||
|
|
||||||
<q-btn color="orange" outline size="sm" label="Settings" icon="settings" />
|
<q-btn color="orange" outline size="sm" label="Settings" icon="settings" />
|
||||||
</div>
|
</div>
|
||||||
|
@ -21,7 +21,7 @@
|
||||||
<div class="column items-center" style="min-width: 150px">
|
<div class="column items-center" style="min-width: 150px">
|
||||||
<q-avatar size="80px">
|
<q-avatar size="80px">
|
||||||
<q-img
|
<q-img
|
||||||
:src="`/api/Images/user/160x160/${user.id}/download?access_token=${token}`"
|
:src="`/api/Images/user/160x160/${user.id}/download?access_token=${user.token}`"
|
||||||
spinner-color="white"
|
spinner-color="white"
|
||||||
/>
|
/>
|
||||||
</q-avatar>
|
</q-avatar>
|
||||||
|
@ -37,10 +37,18 @@
|
||||||
</q-menu>
|
</q-menu>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts" setup>
|
||||||
import { Options, Vue } from 'vue-class-component';
|
import { onMounted, computed } from 'vue';
|
||||||
|
import { Dark, useQuasar } from 'quasar';
|
||||||
|
import { useStore } from 'vuex';
|
||||||
|
import { useI18n } from 'vue-i18n';
|
||||||
|
import { useRouter } from 'vue-router';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { Dark } from 'quasar';
|
|
||||||
|
const quasar = useQuasar();
|
||||||
|
const store = useStore();
|
||||||
|
const router = useRouter();
|
||||||
|
const { t, locale } = useI18n();
|
||||||
|
|
||||||
interface UserProfile {
|
interface UserProfile {
|
||||||
id: number;
|
id: number;
|
||||||
|
@ -49,54 +57,42 @@ interface UserProfile {
|
||||||
token: string;
|
token: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Options({})
|
const darkMode = computed({
|
||||||
export default class UserPanel extends Vue {
|
get(): boolean {
|
||||||
private lang = 'es';
|
|
||||||
|
|
||||||
mounted(): void {
|
|
||||||
axios
|
|
||||||
.get('/api/accounts/acl')
|
|
||||||
.then((response) => {
|
|
||||||
this.$store.dispatch('updateUserData', response.data);
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
this.$q.notify({
|
|
||||||
message: this.$t('errors.statusUnauthorized'),
|
|
||||||
type: 'negative',
|
|
||||||
});
|
|
||||||
this.$store.dispatch('logOut');
|
|
||||||
this.$router.push('/login');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
logout(): void {
|
|
||||||
this.$store.dispatch('logOut');
|
|
||||||
this.$router.push('/login');
|
|
||||||
}
|
|
||||||
|
|
||||||
get user(): UserProfile {
|
|
||||||
return this.$store.state.user;
|
|
||||||
}
|
|
||||||
|
|
||||||
get token(): string {
|
|
||||||
return this.$store.getters.token;
|
|
||||||
}
|
|
||||||
|
|
||||||
get mode(): boolean {
|
|
||||||
return Dark.isActive;
|
return Dark.isActive;
|
||||||
}
|
},
|
||||||
|
set(value: boolean): void {
|
||||||
set mode(value: boolean) {
|
|
||||||
Dark.set(value);
|
Dark.set(value);
|
||||||
}
|
},
|
||||||
|
});
|
||||||
|
|
||||||
get language(): string {
|
const user = computed((): UserProfile => {
|
||||||
return this.lang;
|
return {
|
||||||
}
|
id: store.state.user.id,
|
||||||
|
username: store.state.user.username,
|
||||||
|
nickname: store.state.user.nickname,
|
||||||
|
token: store.getters.token,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
set language(value: string) {
|
onMounted(() => {
|
||||||
this.lang = value;
|
axios
|
||||||
this.$i18n.locale = value;
|
.get('/api/accounts/acl')
|
||||||
}
|
.then((response) => {
|
||||||
|
store.dispatch('updateUserData', response.data);
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
quasar.notify({
|
||||||
|
message: t('errors.statusUnauthorized'),
|
||||||
|
type: 'negative',
|
||||||
|
});
|
||||||
|
store.dispatch('logOut');
|
||||||
|
router.push('/login');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function logout(): void {
|
||||||
|
store.dispatch('logOut');
|
||||||
|
router.push('/login');
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue