199 lines
13 KiB
Vue
199 lines
13 KiB
Vue
<script setup lang="ts">
|
|
/**
|
|
* features/user/views/UserProfilePage.vue
|
|
* 閻劑鈧棑绱扮仦鏇犮仛閸滃瞼绱潏鎴濈秼閸撳秶鏁ら幋鐤カ閺傛瑣鈧浇顕㈢懛鈧?娑撳顣介崑蹇撱偨閿涘苯鑻熼幓鎰返娣囶喗鏁肩€靛棛鐖滈崗銉ュ經閵? * 娓氭繆绂嗛敍姝秙er-profile.context閵嗕勾ucide 閸ョ偓鐖i妴涔倁e i18n閵? * 闁槒绶敍姘矝閻?/workspace/profile 鐠侯垳鏁遍幍鑳祰閿涘奔绲炬い鐢告桨閸滃奔绗熼崝鈥崇秺鐏?user feature閵? */
|
|
import { inject } from 'vue';
|
|
import {
|
|
User, Mail, Building, CreditCard, Globe, Save, Palette,
|
|
} from 'lucide-vue-next';
|
|
import { USER_PROFILE_KEY } from '../composables/user-profile.context';
|
|
|
|
const userProfile = inject(USER_PROFILE_KEY)!;
|
|
</script>
|
|
|
|
<template>
|
|
<div v-if="userProfile.isProfileLoading" class="flex justify-center py-20">
|
|
<div class="animate-spin rounded-full h-8 w-8 border-b-2 border-brand-600"></div>
|
|
</div>
|
|
|
|
<div v-else class="space-y-6">
|
|
<div class="rounded-3xl border border-default bg-surface px-6 py-6 shadow-sm md:px-8">
|
|
<div class="flex flex-col gap-6 lg:flex-row lg:items-start lg:justify-between">
|
|
<div class="flex flex-1 flex-col gap-6 sm:flex-row sm:items-center sm:justify-start">
|
|
<div class="flex h-24 w-24 shrink-0 items-center justify-center rounded-full bg-brand-100 text-4xl font-bold text-brand-600" :class="userProfile.isMobile ? 'h-14 w-14 text-2xl' : ''">
|
|
{{ (userProfile.profileUser.real_name || userProfile.profileUser.username || 'U').charAt(0).toUpperCase() }}
|
|
</div>
|
|
<div class="grid flex-1 text-left" :class="userProfile.isMobile ? 'grid-cols-2 gap-x-4 gap-y-1' : 'grid-cols-1 gap-x-12 gap-y-3 sm:grid-cols-2'">
|
|
<div :class="userProfile.isMobile ? '' : ''">
|
|
<div :class="userProfile.isMobile ? 'text-xs text-muted' : 'text-lg font-semibold text-primary'">{{ userProfile.isMobile ? $t('profile.realName') : (userProfile.profileUser.username || '-') }}</div>
|
|
<div v-if="userProfile.isMobile" class="text-sm font-medium text-primary truncate">{{ userProfile.profileUser.real_name || userProfile.profileUser.username || '-' }}</div>
|
|
</div>
|
|
<div>
|
|
<div :class="userProfile.isMobile ? 'text-xs text-muted' : 'text-lg font-semibold text-primary'">{{ userProfile.isMobile ? $t('profile.employeeId') : (userProfile.profileUser.employee_id || '-') }}</div>
|
|
<div v-if="userProfile.isMobile" class="text-sm font-medium text-primary truncate">{{ userProfile.profileUser.employee_id || '-' }}</div>
|
|
</div>
|
|
<div>
|
|
<div :class="userProfile.isMobile ? 'text-xs text-muted' : 'text-lg font-semibold text-primary'">{{ userProfile.isMobile ? $t('profile.department') : (userProfile.profileUser.department || '-') }}</div>
|
|
<div v-if="userProfile.isMobile" class="text-sm font-medium text-primary truncate">{{ userProfile.profileUser.department || '-' }}</div>
|
|
</div>
|
|
<div>
|
|
<div :class="userProfile.isMobile ? 'text-xs text-muted' : 'text-lg font-semibold text-primary'">{{ userProfile.isMobile ? $t('profile.role') : (userProfile.profileUser.role === 'admin' ? ($t('profile.roleAdmin') || 'Administrator') : ($t('profile.roleUser') || 'User')) }}</div>
|
|
<div v-if="userProfile.isMobile" class="text-sm font-medium text-primary truncate">{{ userProfile.profileUser.role === 'admin' ? ($t('profile.roleAdmin') || 'Administrator') : ($t('profile.roleUser') || 'User') }}</div>
|
|
</div>
|
|
<div :class="userProfile.isMobile ? 'col-span-2' : 'sm:col-span-2'">
|
|
<div :class="userProfile.isMobile ? 'text-xs text-muted' : 'break-all text-lg font-semibold text-primary'">{{ userProfile.isMobile ? $t('profile.email') : (userProfile.profileUser.email || '-') }}</div>
|
|
<div v-if="userProfile.isMobile" class="text-sm font-medium text-primary truncate">{{ userProfile.profileUser.email || '-' }}</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div v-if="!userProfile.isMobile" class="flex shrink-0 items-center gap-2 self-start lg:ml-6">
|
|
<button @click="userProfile.handleChangePasswordClick" class="btn-primary px-6 py-3 text-base">
|
|
{{ $t('profile.changePassword') }}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<div v-if="userProfile.isMobile" class="mt-4 flex items-center justify-center gap-4">
|
|
<button @click="userProfile.handleChangePasswordClick" class="btn-primary flex-1 py-2.5 text-sm text-center">
|
|
{{ $t('profile.changePassword') }}
|
|
</button>
|
|
<button @click="userProfile.handleLogout" class="btn-secondary flex-1 py-2.5 text-sm text-center text-red-600 hover:bg-red-50">
|
|
{{ $t('workspace.nav.logout') }}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="space-y-6">
|
|
<div class="rounded-3xl border border-default bg-surface p-8 shadow-sm" :class="userProfile.isMobile ? 'p-4' : ''">
|
|
<div class="mb-8 flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between" :class="userProfile.isMobile ? 'mb-4 gap-2' : ''">
|
|
<div class="flex items-center" :class="userProfile.isMobile ? 'w-full justify-center gap-2' : ''">
|
|
<h3 class="flex items-center gap-3 text-3xl font-bold text-primary" :class="userProfile.isMobile ? 'text-lg gap-2' : ''">
|
|
<User class="h-6 w-6 text-brand-500" :class="userProfile.isMobile ? 'h-4 w-4' : ''" />
|
|
{{ $t('profile.basicInfo') }}
|
|
</h3>
|
|
<button v-if="userProfile.isMobile && !userProfile.isProfileEditing" @click="userProfile.startProfileEditing" class="btn-secondary px-3 py-1 text-xs">
|
|
{{ $t('profile.edit') }}
|
|
</button>
|
|
</div>
|
|
<p v-if="!userProfile.isMobile" class="mt-2 text-sm text-muted">
|
|
{{ userProfile.isProfileEditing ? $t('profile.directEditHint') : $t('profile.switchEditHint') }}
|
|
</p>
|
|
<div v-if="!userProfile.isMobile" class="flex items-center gap-2">
|
|
<button v-if="!userProfile.isProfileEditing" @click="userProfile.startProfileEditing" class="btn-secondary px-5 py-2.5 text-sm">
|
|
{{ $t('profile.edit') }}
|
|
</button>
|
|
<template v-else>
|
|
<button @click="userProfile.cancelProfileEditing" class="btn-secondary px-5 py-2.5 text-sm">
|
|
{{ $t('profile.cancel') || 'Cancel' }}
|
|
</button>
|
|
<button
|
|
@click="userProfile.saveProfile"
|
|
:disabled="userProfile.isProfileSaving || !userProfile.hasProfileUnsavedChanges"
|
|
class="btn-primary px-5 py-2.5 text-sm disabled:opacity-50 disabled:cursor-not-allowed"
|
|
>
|
|
<Save class="w-4 h-4" />
|
|
<span>{{ userProfile.isProfileSaving ? $t('profile.saving') : $t('workspace.save') }}</span>
|
|
</button>
|
|
</template>
|
|
</div>
|
|
</div>
|
|
<div class="grid grid-cols-1 gap-5 md:grid-cols-2" :class="userProfile.isMobile ? 'gap-3' : ''">
|
|
<div>
|
|
<label class="mb-2 flex items-center gap-2 text-sm font-medium text-muted" :class="userProfile.isMobile ? 'text-xs mb-1' : ''">
|
|
<User class="h-4 w-4" /> {{ $t('profile.username') }}
|
|
</label>
|
|
<div class="rounded-2xl border border-default bg-surface-soft px-4 py-4 text-lg font-medium text-secondary" :class="userProfile.isMobile ? 'px-3 py-2 text-sm rounded-xl' : ''">
|
|
{{ userProfile.profileUser.username || '-' }}
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<label class="mb-2 flex items-center gap-2 text-sm font-medium text-muted" :class="userProfile.isMobile ? 'text-xs mb-1' : ''">
|
|
<CreditCard class="h-4 w-4" /> {{ $t('profile.employeeId') }}
|
|
</label>
|
|
<input v-if="userProfile.isProfileEditing" v-model="userProfile.profileUser.employee_id" type="text" class="input-field" :class="userProfile.isMobile ? 'h-10 text-sm' : 'h-[58px]'" />
|
|
<div v-else class="rounded-2xl border border-default bg-surface-soft px-4 py-4 text-lg font-medium text-secondary" :class="userProfile.isMobile ? 'px-3 py-2 text-sm rounded-xl' : ''">
|
|
{{ userProfile.profileUser.employee_id || '-' }}
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<label class="mb-2 flex items-center gap-2 text-sm font-medium text-muted" :class="userProfile.isMobile ? 'text-xs mb-1' : ''">
|
|
<User class="h-4 w-4" /> {{ $t('profile.realName') }}
|
|
</label>
|
|
<input v-if="userProfile.isProfileEditing" v-model="userProfile.profileUser.real_name" type="text" class="input-field" :class="userProfile.isMobile ? 'h-10 text-sm' : 'h-[58px]'" />
|
|
<div v-else class="rounded-2xl border border-default bg-surface-soft px-4 py-4 text-lg font-medium text-secondary" :class="userProfile.isMobile ? 'px-3 py-2 text-sm rounded-xl' : ''">
|
|
{{ userProfile.profileUser.real_name || '-' }}
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<label class="mb-2 flex items-center gap-2 text-sm font-medium text-muted" :class="userProfile.isMobile ? 'text-xs mb-1' : ''">
|
|
<Building class="h-4 w-4" /> {{ $t('profile.department') }}
|
|
</label>
|
|
<input v-if="userProfile.isProfileEditing" v-model="userProfile.profileUser.department" type="text" class="input-field" :class="userProfile.isMobile ? 'h-10 text-sm' : 'h-[58px]'" />
|
|
<div v-else class="rounded-2xl border border-default bg-surface-soft px-4 py-4 text-lg font-medium text-secondary" :class="userProfile.isMobile ? 'px-3 py-2 text-sm rounded-xl' : ''">
|
|
{{ userProfile.profileUser.department || '-' }}
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<label class="mb-2 flex items-center gap-2 text-sm font-medium text-muted" :class="userProfile.isMobile ? 'text-xs mb-1' : ''">
|
|
<Mail class="h-4 w-4" /> {{ $t('profile.email') }}
|
|
</label>
|
|
<input v-if="userProfile.isProfileEditing" v-model="userProfile.profileUser.email" type="email" class="input-field" :class="userProfile.isMobile ? 'h-10 text-sm' : 'h-[58px]'" />
|
|
<div v-else class="rounded-2xl border border-default bg-surface-soft px-4 py-4 text-lg font-medium text-secondary" :class="userProfile.isMobile ? 'px-3 py-2 text-sm rounded-xl' : ''">
|
|
{{ userProfile.profileUser.email || '-' }}
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<label class="mb-2 flex items-center gap-2 text-sm font-medium text-muted" :class="userProfile.isMobile ? 'text-xs mb-1' : ''">
|
|
<Globe class="h-4 w-4" /> {{ $t('profile.phoneNumber') }}
|
|
</label>
|
|
<input v-if="userProfile.isProfileEditing" v-model="userProfile.profileUser.phone_number" type="text" class="input-field" :class="userProfile.isMobile ? 'h-10 text-sm' : 'h-[58px]'" />
|
|
<div v-else class="rounded-2xl border border-default bg-surface-soft px-4 py-4 text-lg font-medium text-secondary" :class="userProfile.isMobile ? 'px-3 py-2 text-sm rounded-xl' : ''">
|
|
{{ userProfile.profileUser.phone_number || '-' }}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="rounded-3xl border border-default bg-surface p-8 shadow-sm">
|
|
<h3 class="mb-6 flex items-center gap-3 text-2xl font-bold text-primary">
|
|
<Palette class="h-5 w-5 text-brand-500" />
|
|
{{ $t('profile.preferences') }}
|
|
</h3>
|
|
<div class="grid grid-cols-1 gap-6 md:grid-cols-2">
|
|
<div>
|
|
<label class="mb-2 block text-sm font-medium text-muted">{{ $t('workspace.languageLabel') }}</label>
|
|
<select v-model="userProfile.profileUser.language" :disabled="!userProfile.isProfileEditing" class="input-field h-[58px]">
|
|
<option value="en">English</option>
|
|
<option value="zh-CN">{{ $t('workspace.lang.zhCN') }}</option>
|
|
<option value="zh-TW">{{ $t('workspace.lang.zhTW') }}</option>
|
|
<option value="th">Thai</option>
|
|
</select>
|
|
</div>
|
|
<div>
|
|
<label class="mb-2 block text-sm font-medium text-muted">{{ $t('profile.theme') }}</label>
|
|
<div
|
|
class="segment-control segment-control--cols-3 segment-control--md"
|
|
role="radiogroup"
|
|
:aria-label="$t('profile.theme')"
|
|
>
|
|
<button
|
|
v-for="item in userProfile.themeOptions"
|
|
:key="item.value"
|
|
type="button"
|
|
role="radio"
|
|
:aria-checked="userProfile.profileUser.theme_preference === item.value"
|
|
:disabled="!userProfile.isProfileEditing"
|
|
class="segment-item"
|
|
:class="userProfile.profileUser.theme_preference === item.value ? 'segment-item--active' : ''"
|
|
@click="userProfile.profileUser.theme_preference = item.value"
|
|
>
|
|
{{ item.label() }}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
</template>
|