feat(ui): 工作台界面全部替换为element plus
This commit is contained in:
1 parent
26d213c05b
commit
d5f988a16c
38 files changed
+4501
-3087
No files matched your search
@@ -1,30 +1,50 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/user/views/UserProfilePage.vue
|
||||
* 用途:工作台个人中心,展示与编辑当前用户资料、语言/主题偏好,并提供修改密码入口。
|
||||
* 依赖:workspace.context(WORKSPACE_KEY)、lucide 图标、vue-i18n、isPlatformAdminUser。
|
||||
* 逻辑:路由 /workspace/profile 懒加载本页;资料状态由 useWorkspaceProfile 经工作台注入。
|
||||
* 角色展示优先用权限组名称;旧会话缺 role_name 时再按 is_platform_admin 回退。
|
||||
* 依赖:workspace.context(WORKSPACE_KEY)、element-plus、element-theme.css、vue-i18n、isPlatformAdminUser、getUserAvatarLabel。
|
||||
* 逻辑:路由 /workspace/profile 懒加载本页。资料状态由 useWorkspaceProfile 经工作台注入。
|
||||
* 角色展示优先用权限组名称;旧会话缺 role_name 时再按 is_platform_admin 回退。
|
||||
* 改密弹窗在 WorkspaceModals。头像继续用品牌圆标,不用 ElAvatar。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { computed, inject } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { Check, Edit } from '@element-plus/icons-vue';
|
||||
import {
|
||||
User, Mail, Building, CreditCard, Globe, Save, Palette,
|
||||
} from 'lucide-vue-next';
|
||||
ElButton,
|
||||
ElCard,
|
||||
ElForm,
|
||||
ElFormItem,
|
||||
ElInput,
|
||||
ElLoading,
|
||||
ElOption,
|
||||
ElRadioButton,
|
||||
ElRadioGroup,
|
||||
ElSelect,
|
||||
ElText,
|
||||
} from 'element-plus';
|
||||
import 'element-plus/dist/index.css';
|
||||
import 'element-plus/theme-chalk/dark/css-vars.css';
|
||||
import '@/shared/styles/element-theme.css';
|
||||
import { getUserAvatarLabel } from '@/shared/utils/user-avatar';
|
||||
import { WORKSPACE_KEY } from '@/features/workspace/composables/workspace.context';
|
||||
import { isPlatformAdminUser } from '@/shared/utils/auth';
|
||||
|
||||
const vLoading = ElLoading.directive;
|
||||
|
||||
const { t } = useI18n();
|
||||
const userProfile = inject(WORKSPACE_KEY)!;
|
||||
|
||||
/** 只读字段值:与 input-field 同高,正文统一 14px。 */
|
||||
const fieldValueClass = 'flex min-h-11 items-center rounded-xl border border-default bg-surface-soft px-4 text-sm font-medium text-secondary';
|
||||
/** 表单标签:与分区标题区分层级,全页统一 14px。 */
|
||||
const fieldLabelClass = 'mb-1.5 flex items-center gap-1.5 text-sm font-medium text-muted';
|
||||
const languageOptions = computed(() => [
|
||||
{ value: 'zh-CN', label: t('workspace.lang.zhCN') },
|
||||
{ value: 'zh-TW', label: t('workspace.lang.zhTW') },
|
||||
{ value: 'en', label: 'English' },
|
||||
{ value: 'th', label: 'Thai' },
|
||||
]);
|
||||
|
||||
/**
|
||||
* 身份主标题:优先真实姓名,缺失时回退用户名。
|
||||
* @returns 展示姓名
|
||||
*/
|
||||
const displayName = computed(() => {
|
||||
return userProfile.profileUser.real_name || userProfile.profileUser.username || '-';
|
||||
@@ -33,6 +53,7 @@ const displayName = computed(() => {
|
||||
/**
|
||||
* 个人中心角色标签。
|
||||
* 核心逻辑:有权限组名称就展示名称;否则按 is_platform_admin 回退内置文案。
|
||||
* @returns 角色文案
|
||||
*/
|
||||
const profileRoleLabel = computed(() => {
|
||||
const user = userProfile.profileUser || {};
|
||||
@@ -42,6 +63,7 @@ const profileRoleLabel = computed(() => {
|
||||
|
||||
/**
|
||||
* 身份副标题:用户名(与主标题不同时)、部门、角色用间隔点拼接,空项省略。
|
||||
* @returns 副标题;没有可展示项时为空字符串
|
||||
*/
|
||||
const identityMeta = computed(() => {
|
||||
const username = userProfile.profileUser.username;
|
||||
@@ -50,222 +72,268 @@ const identityMeta = computed(() => {
|
||||
.filter(Boolean)
|
||||
.join(' · ');
|
||||
});
|
||||
|
||||
/**
|
||||
* 只读时用短横线占位,编辑时保留空字符串以便继续输入。
|
||||
* @param value - 资料字段当前值
|
||||
* @returns 输入框展示文字
|
||||
*/
|
||||
function fieldText(value: string | undefined): string {
|
||||
if (userProfile.isProfileEditing) return value || '';
|
||||
return value || '-';
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑态写回资料字段。只读时忽略输入框回写,避免把占位短横线存进去。
|
||||
* @param key - 可编辑的资料字段
|
||||
* @param value - 输入框新值
|
||||
*/
|
||||
function onProfileField(
|
||||
key: 'employee_id' | 'real_name' | 'department' | 'email' | 'phone_number',
|
||||
value: string,
|
||||
): void {
|
||||
if (!userProfile.isProfileEditing) return;
|
||||
userProfile.profileUser[key] = value;
|
||||
}
|
||||
</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' : ''">
|
||||
{{ getUserAvatarLabel(userProfile.profileUser) }}
|
||||
</div>
|
||||
<div class="min-w-0 space-y-0.5">
|
||||
<div class="truncate text-lg font-semibold text-primary">{{ displayName }}</div>
|
||||
<div v-if="identityMeta" class="truncate text-sm text-muted">{{ identityMeta }}</div>
|
||||
<div v-if="userProfile.profileUser.email" class="break-all text-sm text-muted">
|
||||
{{ userProfile.profileUser.email }}
|
||||
<div v-loading="userProfile.isProfileLoading" class="profile-page">
|
||||
<template v-if="!userProfile.isProfileLoading">
|
||||
<ElCard shadow="never" class="profile-identity">
|
||||
<div class="profile-identity__body">
|
||||
<div class="profile-identity__person">
|
||||
<div class="profile-avatar" :class="userProfile.isMobile ? 'profile-avatar--compact' : ''">
|
||||
{{ getUserAvatarLabel(userProfile.profileUser) }}
|
||||
</div>
|
||||
<div class="profile-identity__text">
|
||||
<div class="section-title">{{ displayName }}</div>
|
||||
<ElText v-if="identityMeta" type="info">{{ identityMeta }}</ElText>
|
||||
<ElText v-if="userProfile.profileUser.email" type="info" class="profile-identity__email">
|
||||
{{ userProfile.profileUser.email }}
|
||||
</ElText>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="!userProfile.isMobile" class="shrink-0">
|
||||
<button type="button" class="btn-primary btn-sm" @click="userProfile.handleChangePasswordClick">
|
||||
{{ $t('profile.changePassword') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="userProfile.isMobile" class="mt-4 flex items-center gap-3">
|
||||
<button
|
||||
type="button"
|
||||
class="btn-primary btn-sm flex-1"
|
||||
@click="userProfile.handleChangePasswordClick"
|
||||
>
|
||||
{{ $t('profile.changePassword') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="btn-secondary btn-sm flex-1 text-red-600 hover:bg-red-50"
|
||||
@click="userProfile.handleLogout"
|
||||
>
|
||||
{{ $t('workspace.nav.logout') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="space-y-6">
|
||||
<div class="rounded-2xl border border-default bg-surface p-5 shadow-sm md:p-6">
|
||||
<div class="mb-5 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div class="flex items-center gap-2" :class="userProfile.isMobile ? 'w-full justify-between' : ''">
|
||||
<h3 class="section-title flex items-center gap-2">
|
||||
<User class="h-5 w-5 text-brand-500" />
|
||||
{{ $t('profile.basicInfo') }}
|
||||
</h3>
|
||||
<button
|
||||
v-if="userProfile.isMobile && !userProfile.isProfileEditing"
|
||||
type="button"
|
||||
class="btn-secondary btn-sm"
|
||||
@click="userProfile.startProfileEditing"
|
||||
>
|
||||
{{ $t('profile.edit') }}
|
||||
</button>
|
||||
<div class="profile-identity__actions">
|
||||
<ElButton type="primary" @click="userProfile.handleChangePasswordClick">
|
||||
{{ t('profile.changePassword') }}
|
||||
</ElButton>
|
||||
<ElButton v-if="userProfile.isMobile" type="danger" plain @click="userProfile.handleLogout">
|
||||
{{ t('workspace.nav.logout') }}
|
||||
</ElButton>
|
||||
</div>
|
||||
<p v-if="!userProfile.isMobile" class="section-desc">
|
||||
{{ 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"
|
||||
type="button"
|
||||
class="btn-secondary btn-sm"
|
||||
@click="userProfile.startProfileEditing"
|
||||
>
|
||||
{{ $t('profile.edit') }}
|
||||
</button>
|
||||
<template v-else>
|
||||
<button type="button" class="btn-secondary btn-sm" @click="userProfile.cancelProfileEditing">
|
||||
{{ $t('profile.cancel') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="btn-primary btn-sm disabled:cursor-not-allowed disabled:opacity-50"
|
||||
:disabled="userProfile.isProfileSaving || !userProfile.hasProfileUnsavedChanges"
|
||||
@click="userProfile.saveProfile"
|
||||
</div>
|
||||
</ElCard>
|
||||
|
||||
<ElCard shadow="never">
|
||||
<template #header>
|
||||
<div class="profile-card-head">
|
||||
<div>
|
||||
<h3 class="section-title">{{ t('profile.basicInfo') }}</h3>
|
||||
<p v-if="!userProfile.isMobile" class="section-desc">
|
||||
{{ userProfile.isProfileEditing ? t('profile.directEditHint') : t('profile.switchEditHint') }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="profile-card-head__actions">
|
||||
<ElButton
|
||||
v-if="!userProfile.isProfileEditing"
|
||||
:icon="Edit"
|
||||
@click="userProfile.startProfileEditing"
|
||||
>
|
||||
<Save class="h-4 w-4" />
|
||||
<span>{{ userProfile.isProfileSaving ? $t('profile.saving') : $t('workspace.save') }}</span>
|
||||
</button>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||
<div>
|
||||
<label :class="fieldLabelClass">
|
||||
<User class="h-4 w-4" /> {{ $t('profile.username') }}
|
||||
</label>
|
||||
<div :class="fieldValueClass">
|
||||
{{ userProfile.profileUser.username || '-' }}
|
||||
{{ t('profile.edit') }}
|
||||
</ElButton>
|
||||
<template v-else>
|
||||
<ElButton @click="userProfile.cancelProfileEditing">{{ t('profile.cancel') }}</ElButton>
|
||||
<ElButton
|
||||
type="primary"
|
||||
:icon="Check"
|
||||
:loading="userProfile.isProfileSaving"
|
||||
:disabled="!userProfile.hasProfileUnsavedChanges"
|
||||
@click="userProfile.saveProfile"
|
||||
>
|
||||
{{ userProfile.isProfileSaving ? t('profile.saving') : t('workspace.save') }}
|
||||
</ElButton>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label :class="fieldLabelClass">
|
||||
<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 text-sm"
|
||||
>
|
||||
<div v-else :class="fieldValueClass">
|
||||
{{ userProfile.profileUser.employee_id || '-' }}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label :class="fieldLabelClass">
|
||||
<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 text-sm"
|
||||
>
|
||||
<div v-else :class="fieldValueClass">
|
||||
{{ userProfile.profileUser.real_name || '-' }}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label :class="fieldLabelClass">
|
||||
<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 text-sm"
|
||||
>
|
||||
<div v-else :class="fieldValueClass">
|
||||
{{ userProfile.profileUser.department || '-' }}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label :class="fieldLabelClass">
|
||||
<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 text-sm"
|
||||
>
|
||||
<div v-else :class="fieldValueClass">
|
||||
{{ userProfile.profileUser.email || '-' }}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label :class="fieldLabelClass">
|
||||
<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 text-sm"
|
||||
>
|
||||
<div v-else :class="fieldValueClass">
|
||||
{{ userProfile.profileUser.phone_number || '-' }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="rounded-2xl border border-default bg-surface p-5 shadow-sm md:p-6">
|
||||
<h3 class="section-title mb-5 flex items-center gap-2">
|
||||
<Palette class="h-5 w-5 text-brand-500" />
|
||||
{{ $t('profile.preferences') }}
|
||||
</h3>
|
||||
<div class="grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||
<div>
|
||||
<label class="mb-1.5 block text-sm font-medium text-muted">{{ $t('workspace.languageLabel') }}</label>
|
||||
<select
|
||||
v-model="userProfile.profileUser.language"
|
||||
class="select-field text-sm"
|
||||
:disabled="!userProfile.isProfileEditing"
|
||||
>
|
||||
<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-1.5 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"
|
||||
class="segment-item"
|
||||
:aria-checked="userProfile.profileUser.theme_preference === item.value"
|
||||
</template>
|
||||
<ElForm label-position="top" class="profile-form">
|
||||
<div class="profile-form__grid">
|
||||
<ElFormItem :label="t('profile.username')">
|
||||
<ElInput :model-value="userProfile.profileUser.username || '-'" disabled />
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('profile.employeeId')">
|
||||
<ElInput
|
||||
:model-value="fieldText(userProfile.profileUser.employee_id)"
|
||||
:disabled="!userProfile.isProfileEditing"
|
||||
:class="userProfile.profileUser.theme_preference === item.value ? 'segment-item--active' : ''"
|
||||
@click="userProfile.profileUser.theme_preference = item.value"
|
||||
>
|
||||
{{ item.label() }}
|
||||
</button>
|
||||
</div>
|
||||
@update:model-value="onProfileField('employee_id', $event)"
|
||||
/>
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('profile.realName')">
|
||||
<ElInput
|
||||
:model-value="fieldText(userProfile.profileUser.real_name)"
|
||||
:disabled="!userProfile.isProfileEditing"
|
||||
@update:model-value="onProfileField('real_name', $event)"
|
||||
/>
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('profile.department')">
|
||||
<ElInput
|
||||
:model-value="fieldText(userProfile.profileUser.department)"
|
||||
:disabled="!userProfile.isProfileEditing"
|
||||
@update:model-value="onProfileField('department', $event)"
|
||||
/>
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('profile.email')">
|
||||
<ElInput
|
||||
:model-value="fieldText(userProfile.profileUser.email)"
|
||||
:disabled="!userProfile.isProfileEditing"
|
||||
@update:model-value="onProfileField('email', $event)"
|
||||
/>
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('profile.phoneNumber')">
|
||||
<ElInput
|
||||
:model-value="fieldText(userProfile.profileUser.phone_number)"
|
||||
:disabled="!userProfile.isProfileEditing"
|
||||
@update:model-value="onProfileField('phone_number', $event)"
|
||||
/>
|
||||
</ElFormItem>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ElForm>
|
||||
</ElCard>
|
||||
|
||||
<ElCard shadow="never">
|
||||
<template #header>
|
||||
<h3 class="section-title">{{ t('profile.preferences') }}</h3>
|
||||
</template>
|
||||
<ElForm label-position="top" class="profile-form">
|
||||
<div class="profile-form__grid">
|
||||
<ElFormItem :label="t('workspace.languageLabel')">
|
||||
<ElSelect
|
||||
v-model="userProfile.profileUser.language"
|
||||
class="profile-control"
|
||||
:disabled="!userProfile.isProfileEditing"
|
||||
>
|
||||
<ElOption
|
||||
v-for="item in languageOptions"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
/>
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem :label="t('profile.theme')">
|
||||
<ElRadioGroup
|
||||
v-model="userProfile.profileUser.theme_preference"
|
||||
:disabled="!userProfile.isProfileEditing"
|
||||
>
|
||||
<ElRadioButton
|
||||
v-for="item in userProfile.themeOptions"
|
||||
:key="item.value"
|
||||
:value="item.value"
|
||||
>
|
||||
{{ item.label() }}
|
||||
</ElRadioButton>
|
||||
</ElRadioGroup>
|
||||
</ElFormItem>
|
||||
</div>
|
||||
</ElForm>
|
||||
</ElCard>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.profile-page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
min-height: 16rem;
|
||||
}
|
||||
|
||||
.profile-identity__body,
|
||||
.profile-card-head,
|
||||
.profile-identity__person,
|
||||
.profile-identity__actions,
|
||||
.profile-card-head__actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.profile-identity__body,
|
||||
.profile-card-head {
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.profile-identity__person {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.profile-identity__text {
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.profile-identity__email {
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.profile-avatar {
|
||||
display: flex;
|
||||
width: 72px;
|
||||
height: 72px;
|
||||
flex: none;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 999px;
|
||||
background: var(--el-color-primary-light-9);
|
||||
color: var(--el-color-primary);
|
||||
font-size: var(--el-font-size-extra-large);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.profile-avatar--compact {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
font-size: var(--el-font-size-large);
|
||||
}
|
||||
|
||||
.profile-identity__actions,
|
||||
.profile-card-head__actions {
|
||||
flex: none;
|
||||
}
|
||||
|
||||
.profile-form__grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
gap: 0 16px;
|
||||
}
|
||||
|
||||
.profile-control {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.profile-form__grid {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.profile-identity__body,
|
||||
.profile-card-head {
|
||||
align-items: stretch;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.profile-identity__actions {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.profile-identity__actions :deep(.el-button) {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user