feat: Add multi-language user name display to the profile menu.
Some checks failed
Spell Check / Spell Check with Typos (push) Failing after 9s
Some checks failed
Spell Check / Spell Check with Typos (push) Failing after 9s
This commit is contained in:
parent
f4db5ad855
commit
9994366c74
2 changed files with 22 additions and 9 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
import { ref, onMounted, computed, reactive } from 'vue';
|
import { ref, onMounted, computed, reactive } from 'vue';
|
||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
import { useQuasar } from 'quasar';
|
import { useQuasar } from 'quasar';
|
||||||
import { getUserId, getUsername, logout, getRole } from 'src/services/keycloak';
|
import { getUserId, getUsername, getName, logout, getRole } from 'src/services/keycloak';
|
||||||
import { Icon } from '@iconify/vue';
|
import { Icon } from '@iconify/vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
|
@ -39,7 +39,7 @@ const configStore = useConfigStore();
|
||||||
const { data: notificationData } = storeToRefs(notificationStore);
|
const { data: notificationData } = storeToRefs(notificationStore);
|
||||||
|
|
||||||
const { visible } = storeToRefs(loaderStore);
|
const { visible } = storeToRefs(loaderStore);
|
||||||
const { t } = useI18n({ useScope: 'global' });
|
const { t, locale } = useI18n({ useScope: 'global' });
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
|
|
||||||
const canvasModal = ref(false);
|
const canvasModal = ref(false);
|
||||||
|
|
@ -52,8 +52,14 @@ const unread = computed<number>(
|
||||||
);
|
);
|
||||||
const userImage = ref<string>();
|
const userImage = ref<string>();
|
||||||
const userGender = ref('');
|
const userGender = ref('');
|
||||||
|
const userName = ref({ th: '', en: '' });
|
||||||
const canvasRef = ref();
|
const canvasRef = ref();
|
||||||
|
|
||||||
|
const displayName = computed(() => {
|
||||||
|
if (!userName.value.th && !userName.value.en) return getName() || 'Guest';
|
||||||
|
return locale.value === 'eng' ? userName.value.en : userName.value.th;
|
||||||
|
});
|
||||||
|
|
||||||
const language: {
|
const language: {
|
||||||
value: Lang;
|
value: Lang;
|
||||||
label: string;
|
label: string;
|
||||||
|
|
@ -161,9 +167,14 @@ onMounted(async () => {
|
||||||
if (user === 'admin') return;
|
if (user === 'admin') return;
|
||||||
if (uid) {
|
if (uid) {
|
||||||
const res = await userStore.fetchById(uid);
|
const res = await userStore.fetchById(uid);
|
||||||
if (res && res.gender) {
|
if (res) {
|
||||||
userGender.value = res.gender;
|
if (res.gender) {
|
||||||
userImage.value = `${baseUrl}/user/${uid}/profile-image/${res.selectedImage}`;
|
userGender.value = res.gender;
|
||||||
|
userImage.value = `${baseUrl}/user/${uid}/profile-image/${res.selectedImage}`;
|
||||||
|
}
|
||||||
|
// เก็บชื่อทั้งสองภาษา
|
||||||
|
userName.value.th = `${res.firstName || ''} ${res.lastName || ''}`.trim();
|
||||||
|
userName.value.en = `${res.firstNameEN || ''} ${res.lastNameEN || ''}`.trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -484,6 +495,7 @@ onMounted(async () => {
|
||||||
<!-- User -->
|
<!-- User -->
|
||||||
<ProfileMenu
|
<ProfileMenu
|
||||||
id="btn-profile-menu"
|
id="btn-profile-menu"
|
||||||
|
:user-name="displayName"
|
||||||
@logout="doLogout"
|
@logout="doLogout"
|
||||||
@edit-personal-info="console.log('edit')"
|
@edit-personal-info="console.log('edit')"
|
||||||
@signature="
|
@signature="
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ const filterRole = ref<string[]>();
|
||||||
defineProps<{
|
defineProps<{
|
||||||
userImage?: string;
|
userImage?: string;
|
||||||
gender?: string;
|
gender?: string;
|
||||||
|
userName?: string;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const inputFile = document.createElement('input');
|
const inputFile = document.createElement('input');
|
||||||
|
|
@ -147,9 +148,9 @@ onMounted(async () => {
|
||||||
class="text-weight-bold ellipsis"
|
class="text-weight-bold ellipsis"
|
||||||
style="max-width: 9vw"
|
style="max-width: 9vw"
|
||||||
>
|
>
|
||||||
{{ getName() }}
|
{{ userName || getName() }}
|
||||||
<q-tooltip>
|
<q-tooltip>
|
||||||
{{ getName() }}
|
{{ userName || getName() }}
|
||||||
</q-tooltip>
|
</q-tooltip>
|
||||||
</span>
|
</span>
|
||||||
<span
|
<span
|
||||||
|
|
@ -234,12 +235,12 @@ onMounted(async () => {
|
||||||
style="margin-top: 58px"
|
style="margin-top: 58px"
|
||||||
>
|
>
|
||||||
<span v-if="isLoggedIn()">
|
<span v-if="isLoggedIn()">
|
||||||
{{ getName() }}
|
{{ userName || getName() }}
|
||||||
</span>
|
</span>
|
||||||
<span v-else>{{ 'Guest' }}</span>
|
<span v-else>{{ 'Guest' }}</span>
|
||||||
<q-tooltip>
|
<q-tooltip>
|
||||||
<span v-if="isLoggedIn()">
|
<span v-if="isLoggedIn()">
|
||||||
{{ getName() }}
|
{{ userName || getName() }}
|
||||||
</span>
|
</span>
|
||||||
<span v-else>{{ 'Guest' }}</span>
|
<span v-else>{{ 'Guest' }}</span>
|
||||||
</q-tooltip>
|
</q-tooltip>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue