Files
syops/frontend/src/features/workspace/pages/ProfilePage.vue
T

200 lines
12 KiB
Vue

<script setup lang="ts">
/**
* features/workspace/pages/ProfilePage.vue
* 个人中心:用户资料展示与编辑、语言/主题偏好、修改密码入口。
*/
import { inject } from 'vue';
import {
User, Mail, Building, CreditCard, Globe, Save, Palette,
} from 'lucide-vue-next';
import { WORKSPACE_KEY } from '../composables/workspace.context';
const ws = inject(WORKSPACE_KEY)! as any;
</script>
<template>
<div v-if="ws.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="ws.isMobile ? 'h-14 w-14 text-2xl' : ''">
{{ (ws.profileUser.real_name || ws.profileUser.username || 'U').charAt(0).toUpperCase() }}
</div>
<div class="grid flex-1 text-left" :class="ws.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="ws.isMobile ? '' : ''">
<div :class="ws.isMobile ? 'text-xs text-muted' : 'text-lg font-semibold text-primary'">{{ ws.isMobile ? $t('profile.realName') : (ws.profileUser.username || '-') }}</div>
<div v-if="ws.isMobile" class="text-sm font-medium text-primary truncate">{{ ws.profileUser.real_name || ws.profileUser.username || '-' }}</div>
</div>
<div>
<div :class="ws.isMobile ? 'text-xs text-muted' : 'text-lg font-semibold text-primary'">{{ ws.isMobile ? $t('profile.employeeId') : (ws.profileUser.employee_id || '-') }}</div>
<div v-if="ws.isMobile" class="text-sm font-medium text-primary truncate">{{ ws.profileUser.employee_id || '-' }}</div>
</div>
<div>
<div :class="ws.isMobile ? 'text-xs text-muted' : 'text-lg font-semibold text-primary'">{{ ws.isMobile ? $t('profile.department') : (ws.profileUser.department || '-') }}</div>
<div v-if="ws.isMobile" class="text-sm font-medium text-primary truncate">{{ ws.profileUser.department || '-' }}</div>
</div>
<div>
<div :class="ws.isMobile ? 'text-xs text-muted' : 'text-lg font-semibold text-primary'">{{ ws.isMobile ? $t('profile.role') : (ws.profileUser.role === 'admin' ? ($t('profile.roleAdmin') || 'Administrator') : ($t('profile.roleUser') || 'User')) }}</div>
<div v-if="ws.isMobile" class="text-sm font-medium text-primary truncate">{{ ws.profileUser.role === 'admin' ? ($t('profile.roleAdmin') || 'Administrator') : ($t('profile.roleUser') || 'User') }}</div>
</div>
<div :class="ws.isMobile ? 'col-span-2' : 'sm:col-span-2'">
<div :class="ws.isMobile ? 'text-xs text-muted' : 'break-all text-lg font-semibold text-primary'">{{ ws.isMobile ? $t('profile.email') : (ws.profileUser.email || '-') }}</div>
<div v-if="ws.isMobile" class="text-sm font-medium text-primary truncate">{{ ws.profileUser.email || '-' }}</div>
</div>
</div>
</div>
<div v-if="!ws.isMobile" class="flex shrink-0 items-center gap-2 self-start lg:ml-6">
<button @click="ws.handleChangePasswordClick" class="btn-primary px-6 py-3 text-base">
{{ $t('profile.changePassword') }}
</button>
</div>
</div>
<div v-if="ws.isMobile" class="mt-4 flex items-center justify-center gap-4">
<button @click="ws.handleChangePasswordClick" class="btn-primary flex-1 py-2.5 text-sm text-center">
{{ $t('profile.changePassword') }}
</button>
<button @click="ws.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="ws.isMobile ? 'p-4' : ''">
<div class="mb-8 flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between" :class="ws.isMobile ? 'mb-4 gap-2' : ''">
<div class="flex items-center" :class="ws.isMobile ? 'w-full justify-center gap-2' : ''">
<h3 class="flex items-center gap-3 text-3xl font-bold text-primary" :class="ws.isMobile ? 'text-lg gap-2' : ''">
<User class="h-6 w-6 text-brand-500" :class="ws.isMobile ? 'h-4 w-4' : ''" />
{{ $t('profile.basicInfo') }}
</h3>
<button v-if="ws.isMobile && !ws.isProfileEditing" @click="ws.startProfileEditing" class="btn-secondary px-3 py-1 text-xs">
{{ $t('profile.edit') }}
</button>
</div>
<p v-if="!ws.isMobile" class="mt-2 text-sm text-muted">
{{ ws.isProfileEditing ? $t('profile.directEditHint') : $t('profile.switchEditHint') }}
</p>
<div v-if="!ws.isMobile" class="flex items-center gap-2">
<button v-if="!ws.isProfileEditing" @click="ws.startProfileEditing" class="btn-secondary px-5 py-2.5 text-sm">
{{ $t('profile.edit') }}
</button>
<template v-else>
<button @click="ws.cancelProfileEditing" class="btn-secondary px-5 py-2.5 text-sm">
{{ $t('profile.cancel') || 'Cancel' }}
</button>
<button
@click="ws.saveProfile"
:disabled="ws.isProfileSaving || !ws.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>{{ ws.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="ws.isMobile ? 'gap-3' : ''">
<div>
<label class="mb-2 flex items-center gap-2 text-sm font-medium text-muted" :class="ws.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="ws.isMobile ? 'px-3 py-2 text-sm rounded-xl' : ''">
{{ ws.profileUser.username || '-' }}
</div>
</div>
<div>
<label class="mb-2 flex items-center gap-2 text-sm font-medium text-muted" :class="ws.isMobile ? 'text-xs mb-1' : ''">
<CreditCard class="h-4 w-4" /> {{ $t('profile.employeeId') }}
</label>
<input v-if="ws.isProfileEditing" v-model="ws.profileUser.employee_id" type="text" class="input-field" :class="ws.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="ws.isMobile ? 'px-3 py-2 text-sm rounded-xl' : ''">
{{ ws.profileUser.employee_id || '-' }}
</div>
</div>
<div>
<label class="mb-2 flex items-center gap-2 text-sm font-medium text-muted" :class="ws.isMobile ? 'text-xs mb-1' : ''">
<User class="h-4 w-4" /> {{ $t('profile.realName') }}
</label>
<input v-if="ws.isProfileEditing" v-model="ws.profileUser.real_name" type="text" class="input-field" :class="ws.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="ws.isMobile ? 'px-3 py-2 text-sm rounded-xl' : ''">
{{ ws.profileUser.real_name || '-' }}
</div>
</div>
<div>
<label class="mb-2 flex items-center gap-2 text-sm font-medium text-muted" :class="ws.isMobile ? 'text-xs mb-1' : ''">
<Building class="h-4 w-4" /> {{ $t('profile.department') }}
</label>
<input v-if="ws.isProfileEditing" v-model="ws.profileUser.department" type="text" class="input-field" :class="ws.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="ws.isMobile ? 'px-3 py-2 text-sm rounded-xl' : ''">
{{ ws.profileUser.department || '-' }}
</div>
</div>
<div>
<label class="mb-2 flex items-center gap-2 text-sm font-medium text-muted" :class="ws.isMobile ? 'text-xs mb-1' : ''">
<Mail class="h-4 w-4" /> {{ $t('profile.email') }}
</label>
<input v-if="ws.isProfileEditing" v-model="ws.profileUser.email" type="email" class="input-field" :class="ws.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="ws.isMobile ? 'px-3 py-2 text-sm rounded-xl' : ''">
{{ ws.profileUser.email || '-' }}
</div>
</div>
<div>
<label class="mb-2 flex items-center gap-2 text-sm font-medium text-muted" :class="ws.isMobile ? 'text-xs mb-1' : ''">
<Globe class="h-4 w-4" /> {{ $t('profile.phoneNumber') }}
</label>
<input v-if="ws.isProfileEditing" v-model="ws.profileUser.phone_number" type="text" class="input-field" :class="ws.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="ws.isMobile ? 'px-3 py-2 text-sm rounded-xl' : ''">
{{ ws.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="ws.profileUser.language" :disabled="!ws.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">ไทย</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 ws.themeOptions"
:key="item.value"
type="button"
role="radio"
:aria-checked="ws.profileUser.theme_preference === item.value"
:disabled="!ws.isProfileEditing"
class="segment-item"
:class="ws.profileUser.theme_preference === item.value ? 'segment-item--active' : ''"
@click="ws.profileUser.theme_preference = item.value"
>
{{ item.label() }}
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</template>