Integrate update config language dropdown
gitea/hedera-web/pipeline/pr-4922-vueMigration There was a failure building this commit
Details
gitea/hedera-web/pipeline/pr-4922-vueMigration There was a failure building this commit
Details
This commit is contained in:
parent
2758dcf2c8
commit
f1a8fd2710
|
@ -99,7 +99,9 @@ onMounted(() => fetchLanguagesSql());
|
||||||
option-label="name"
|
option-label="name"
|
||||||
option-value="code"
|
option-value="code"
|
||||||
:options="langOptions"
|
:options="langOptions"
|
||||||
@update:model-value="vnFormRef.submit()"
|
@update:model-value="
|
||||||
|
userStore.updateUserLang(data.lang)
|
||||||
|
"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
<template #extraForm>
|
<template #extraForm>
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import { api, jApi } from 'boot/axios';
|
import { api, jApi } from 'boot/axios';
|
||||||
import { i18n } from 'src/boot/i18n';
|
import { i18n } from 'src/boot/i18n';
|
||||||
|
import useNotify from 'src/composables/useNotify.js';
|
||||||
|
|
||||||
const { t } = i18n.global;
|
const { t } = i18n.global;
|
||||||
|
const { notify } = useNotify();
|
||||||
|
|
||||||
export const useUserStore = defineStore('user', {
|
export const useUserStore = defineStore('user', {
|
||||||
state: () => {
|
state: () => {
|
||||||
|
@ -27,15 +29,15 @@ export const useUserStore = defineStore('user', {
|
||||||
|
|
||||||
getters: {
|
getters: {
|
||||||
loggedIn: state => state.token != null,
|
loggedIn: state => state.token != null,
|
||||||
userLang: state =>
|
userLocaleOption: state =>
|
||||||
state.localeOptions?.find(l => l.value === state?.user?.lang)?.lang
|
state.localeOptions?.find(l => l.value === state?.user?.lang)
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
async init() {
|
async init() {
|
||||||
await this.fetchUser();
|
await this.fetchUser();
|
||||||
await this.supplantInit();
|
await this.supplantInit();
|
||||||
i18n.global.locale.value = this.userLang || 'en-US';
|
this.updateSiteLocale();
|
||||||
},
|
},
|
||||||
|
|
||||||
async getToken() {
|
async getToken() {
|
||||||
|
@ -105,8 +107,12 @@ export const useUserStore = defineStore('user', {
|
||||||
await this.fetchUser();
|
await this.fetchUser();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
updateSiteLocale(locale = null) {
|
||||||
|
i18n.global.locale.value =
|
||||||
|
locale || this.userLocaleOption.lang || 'en-US';
|
||||||
|
},
|
||||||
|
|
||||||
async updateUserLang(lang) {
|
async updateUserLang(lang) {
|
||||||
console.log('lang to update: ', lang);
|
|
||||||
if (!this.user || this.user.lang === lang) return;
|
if (!this.user || this.user.lang === lang) return;
|
||||||
await jApi.execQuery(
|
await jApi.execQuery(
|
||||||
`START TRANSACTION;
|
`START TRANSACTION;
|
||||||
|
@ -116,6 +122,8 @@ export const useUserStore = defineStore('user', {
|
||||||
{ id: this.user.id, lang }
|
{ id: this.user.id, lang }
|
||||||
);
|
);
|
||||||
this.user.lang = lang;
|
this.user.lang = lang;
|
||||||
|
this.updateSiteLocale();
|
||||||
|
notify(t('dataSaved'), 'positive');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue