feat(darkMode): current darkMode value is now saved in vn.userConfig.darkMode
gitea/salix-front/pipeline/head There was a failure building this commit
Details
gitea/salix-front/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
16020e9c16
commit
345b943869
|
@ -3,6 +3,7 @@ import { onMounted, computed } from 'vue';
|
||||||
import { Dark, useQuasar } from 'quasar';
|
import { Dark, useQuasar } from 'quasar';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
import { useState } from 'src/composables/useState';
|
import { useState } from 'src/composables/useState';
|
||||||
import { useSession } from 'src/composables/useSession';
|
import { useSession } from 'src/composables/useSession';
|
||||||
|
@ -27,9 +28,11 @@ const darkMode = computed({
|
||||||
const user = state.getUser();
|
const user = state.getUser();
|
||||||
const token = session.getToken();
|
const token = session.getToken();
|
||||||
|
|
||||||
|
if (user.value.darkMode) darkMode.value = user.value.darkMode;
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
try {
|
try {
|
||||||
const stateRoles = state.getRoles().value
|
const stateRoles = state.getRoles().value;
|
||||||
if (stateRoles.length === 0) {
|
if (stateRoles.length === 0) {
|
||||||
await role.fetch();
|
await role.fetch();
|
||||||
}
|
}
|
||||||
|
@ -42,11 +45,25 @@ onMounted(async () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
async function saveDarkMode(value) {
|
||||||
|
const query = `/api/UserConfigs/${user.value.id}`;
|
||||||
|
await axios.patch(query, {
|
||||||
|
darkMode: value,
|
||||||
|
});
|
||||||
|
user.value.darkMode = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function saveLanguage(value) {
|
||||||
|
const query = `/api/Accounts/${user.value.id}`;
|
||||||
|
await axios.patch(query, {
|
||||||
|
lang: value,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function logout() {
|
function logout() {
|
||||||
session.destroy();
|
session.destroy();
|
||||||
router.push('/login');
|
router.push('/login');
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@ -55,20 +72,21 @@ function logout() {
|
||||||
<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
|
||||||
|
v-model="locale"
|
||||||
|
@update:model-value="saveLanguage"
|
||||||
:label="t(`globals.lang['${locale}']`)"
|
: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="locale"
|
|
||||||
/>
|
/>
|
||||||
<q-toggle
|
<q-toggle
|
||||||
v-model="darkMode"
|
v-model="darkMode"
|
||||||
|
@update:model-value="saveDarkMode"
|
||||||
checked-icon="dark_mode"
|
checked-icon="dark_mode"
|
||||||
color="orange"
|
color="orange"
|
||||||
unchecked-icon="light_mode"
|
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>
|
||||||
|
|
||||||
|
@ -87,15 +105,7 @@ function logout() {
|
||||||
</div>
|
</div>
|
||||||
<div class="text-subtitle3 text-grey-7 q-mb-xs">@{{ user.name }}</div>
|
<div class="text-subtitle3 text-grey-7 q-mb-xs">@{{ user.name }}</div>
|
||||||
|
|
||||||
<q-btn
|
<q-btn color="orange" flat label="Log Out" size="sm" icon="logout" @click="logout()" v-close-popup />
|
||||||
color="orange"
|
|
||||||
flat
|
|
||||||
label="Log Out"
|
|
||||||
size="sm"
|
|
||||||
icon="logout"
|
|
||||||
@click="logout()"
|
|
||||||
v-close-popup
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</q-menu>
|
</q-menu>
|
||||||
|
|
|
@ -8,7 +8,14 @@ export function useRole() {
|
||||||
const { data } = await axios.get('/api/accounts/acl');
|
const { data } = await axios.get('/api/accounts/acl');
|
||||||
const roles = data.roles.map(userRoles => userRoles.role.name);
|
const roles = data.roles.map(userRoles => userRoles.role.name);
|
||||||
|
|
||||||
state.setUser(data.user);
|
const userData = {
|
||||||
|
id: data.user.id,
|
||||||
|
name: data.user.name,
|
||||||
|
nickname: data.user.nickname,
|
||||||
|
language: data.user.lang || 'es',
|
||||||
|
darkMode: data.user.userConfig.darkMode,
|
||||||
|
}
|
||||||
|
state.setUser(userData);
|
||||||
state.setRoles(roles);
|
state.setRoles(roles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,8 @@ export function useSession() {
|
||||||
id: 0,
|
id: 0,
|
||||||
name: '',
|
name: '',
|
||||||
nickname: '',
|
nickname: '',
|
||||||
|
language: '',
|
||||||
|
darkMode: null,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@ const user = ref({
|
||||||
id: 0,
|
id: 0,
|
||||||
name: '',
|
name: '',
|
||||||
nickname: '',
|
nickname: '',
|
||||||
|
language: '',
|
||||||
|
darkMode: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
const roles = ref([]);
|
const roles = ref([]);
|
||||||
|
@ -17,6 +19,8 @@ export function useState() {
|
||||||
id: user.value.id,
|
id: user.value.id,
|
||||||
name: user.value.name,
|
name: user.value.name,
|
||||||
nickname: user.value.nickname,
|
nickname: user.value.nickname,
|
||||||
|
language: user.value.language,
|
||||||
|
darkMode: user.value.darkMode,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -26,6 +30,8 @@ export function useState() {
|
||||||
id: data.id,
|
id: data.id,
|
||||||
name: data.name,
|
name: data.name,
|
||||||
nickname: data.nickname,
|
nickname: data.nickname,
|
||||||
|
language: data.lang,
|
||||||
|
darkMode: data.darkMode,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { computed, ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
import { Dark, useQuasar } from 'quasar';
|
import { useQuasar } from 'quasar';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
@ -10,21 +10,12 @@ import { useSession } from 'src/composables/useSession';
|
||||||
const quasar = useQuasar();
|
const quasar = useQuasar();
|
||||||
const session = useSession();
|
const session = useSession();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { t, locale } = useI18n();
|
const { t } = useI18n();
|
||||||
|
|
||||||
const username = ref('');
|
const username = ref('');
|
||||||
const password = ref('');
|
const password = ref('');
|
||||||
const keepLogin = ref(true);
|
const keepLogin = ref(true);
|
||||||
|
|
||||||
const darkMode = computed({
|
|
||||||
get() {
|
|
||||||
return Dark.isActive;
|
|
||||||
},
|
|
||||||
set(value) {
|
|
||||||
Dark.set(value);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
async function onSubmit() {
|
async function onSubmit() {
|
||||||
try {
|
try {
|
||||||
const { data } = await axios.post('/api/accounts/login', {
|
const { data } = await axios.post('/api/accounts/login', {
|
||||||
|
@ -66,36 +57,11 @@ async function onSubmit() {
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<q-layout>
|
<q-layout>
|
||||||
<q-header class="transparent">
|
|
||||||
<q-toolbar>
|
|
||||||
<q-space></q-space>
|
|
||||||
<q-toggle
|
|
||||||
:label="t(`globals.lang['${locale}']`)"
|
|
||||||
icon="public"
|
|
||||||
color="orange"
|
|
||||||
false-value="es"
|
|
||||||
true-value="en"
|
|
||||||
v-model="locale"
|
|
||||||
/>
|
|
||||||
<q-toggle
|
|
||||||
v-model="darkMode"
|
|
||||||
checked-icon="dark_mode"
|
|
||||||
color="orange"
|
|
||||||
unchecked-icon="light_mode"
|
|
||||||
/>
|
|
||||||
</q-toolbar>
|
|
||||||
</q-header>
|
|
||||||
<q-page-container>
|
<q-page-container>
|
||||||
<q-page>
|
<q-page>
|
||||||
<div id="login">
|
<div id="login">
|
||||||
<q-card class="login q-pa-xl">
|
<q-card class="login q-pa-xl">
|
||||||
<q-img
|
<q-img src="~/assets/logo.svg" alt="Logo" fit="contain" :ratio="16 / 9" class="q-mb-md" />
|
||||||
src="~/assets/logo.svg"
|
|
||||||
alt="Logo"
|
|
||||||
fit="contain"
|
|
||||||
:ratio="16 / 9"
|
|
||||||
class="q-mb-md"
|
|
||||||
/>
|
|
||||||
<q-form @submit="onSubmit" class="q-gutter-md">
|
<q-form @submit="onSubmit" class="q-gutter-md">
|
||||||
<q-input
|
<q-input
|
||||||
filled
|
filled
|
||||||
|
@ -103,9 +69,7 @@ async function onSubmit() {
|
||||||
v-model="username"
|
v-model="username"
|
||||||
:label="t('login.username')"
|
:label="t('login.username')"
|
||||||
lazy-rules
|
lazy-rules
|
||||||
:rules="[
|
:rules="[(val) => (val && val.length > 0) || 'Please type something']"
|
||||||
(val) => (val && val.length > 0) || 'Please type something',
|
|
||||||
]"
|
|
||||||
/>
|
/>
|
||||||
<q-input
|
<q-input
|
||||||
filled
|
filled
|
||||||
|
@ -114,15 +78,9 @@ async function onSubmit() {
|
||||||
v-model="password"
|
v-model="password"
|
||||||
:label="t('login.password')"
|
:label="t('login.password')"
|
||||||
lazy-rules
|
lazy-rules
|
||||||
:rules="[
|
:rules="[(val) => (val && val.length > 0) || 'Please type something']"
|
||||||
(val) => (val && val.length > 0) || 'Please type something',
|
|
||||||
]"
|
|
||||||
/>
|
|
||||||
<q-toggle
|
|
||||||
v-model="keepLogin"
|
|
||||||
:label="t('login.keepLogin')"
|
|
||||||
color="orange"
|
|
||||||
/>
|
/>
|
||||||
|
<q-toggle v-model="keepLogin" :label="t('login.keepLogin')" color="orange" />
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<q-btn :label="t('login.submit')" type="submit" color="orange" />
|
<q-btn :label="t('login.submit')" type="submit" color="orange" />
|
||||||
|
|
Loading…
Reference in New Issue