This commit is contained in:
Ray.Hao
2025-04-03 19:59:11 +08:00
5 changed files with 314 additions and 168 deletions

View File

@@ -149,7 +149,7 @@ function handleReadNotice(id: string) {
// 查看更多
function handleViewMoreNotice() {
router.push({ path: "/myNotice" });
router.push({ name: "MyNotice" });
}
// 全部已读

View File

@@ -59,7 +59,7 @@ export const constantRoutes: RouteRecordRaw[] = [
meta: { title: "个人中心", icon: "user", hidden: true },
},
{
path: "myNotice",
path: "my-notice",
name: "MyNotice",
component: () => import("@/views/system/notice/components/MyNotice.vue"),
meta: { title: "我的通知", icon: "user", hidden: true },

View File

@@ -34,7 +34,7 @@ export const useSettingsStore = defineStore("setting", () => {
[theme, themeColor],
([newTheme, newThemeColor]) => {
toggleDarkMode(newTheme === ThemeMode.DARK);
const colors = generateThemeColors(newThemeColor);
const colors = generateThemeColors(newThemeColor, newTheme);
applyTheme(colors);
},
{ immediate: true }

View File

@@ -10,27 +10,60 @@ function rgbToHex(r: number, g: number, b: number): string {
}
// 辅助函数:调整颜色亮度
function adjustBrightness(hex: string, factor: number): string {
/** function adjustBrightness(hex: string, factor: number, theme: string): string {
const rgb = hexToRgb(hex);
// 是否是暗黑模式
const isDarkMode = theme === "dark" ? 0 : 255;
const newRgb = rgb.map((val) =>
Math.max(0, Math.min(255, Math.round(val + (255 - val) * factor)))
Math.max(0, Math.min(255, Math.round(val + (isDarkMode - val) * factor)))
) as [number, number, number];
return rgbToHex(...newRgb);
} */
/**
* 加深颜色值
* @param {String} color 颜色值字符串
* @param {Number} level 加深的程度限0-1之间
* @returns {String} 返回处理后的颜色值
*/
export function getDarkColor(color: string, level: number): string {
const rgb = hexToRgb(color);
for (let i = 0; i < 3; i++) rgb[i] = Math.round(20.5 * level + rgb[i] * (1 - level));
return rgbToHex(rgb[0], rgb[1], rgb[2]);
}
export function generateThemeColors(primary: string) {
/**
* 变浅颜色值
* @param {String} color 颜色值字符串
* @param {Number} level 加深的程度限0-1之间
* @returns {String} 返回处理后的颜色值
*/
export const getLightColor = (color: string, level: number): string => {
const rgb = hexToRgb(color);
for (let i = 0; i < 3; i++) rgb[i] = Math.round(255 * level + rgb[i] * (1 - level));
return rgbToHex(rgb[0], rgb[1], rgb[2]);
};
/**
* 生成主题色
* @param primary 主题色
* @param theme 主题类型
*/
export function generateThemeColors(primary: string, theme: string) {
const colors: Record<string, string> = {
primary,
};
// 生成浅色变体
for (let i = 1; i <= 9; i++) {
const factor = i * 0.1;
colors[`primary-light-${i}`] = adjustBrightness(primary, factor);
const primaryColor =
theme === "light" ? `${getLightColor(primary, i / 10)}` : `${getDarkColor(primary, i / 10)}`;
colors[`primary-light-${i}`] = primaryColor;
}
// 生成深色变体
colors["primary-dark-2"] = adjustBrightness(primary, -0.2);
colors["primary-dark-2"] =
theme === "light" ? `${getLightColor(primary, 0.2)}` : `${getDarkColor(primary, 0.3)}`;
return colors;
}

View File

@@ -1,16 +1,15 @@
<template>
<div class="app-container">
<el-tabs tab-position="left">
<!-- 基本设置 Tab Pane -->
<el-tab-pane label="账号信息">
<div class="w-full">
<el-card>
<!-- 头像和昵称部分 -->
<div class="relative w-100px h-100px flex-center">
<div class="profile-container">
<el-row :gutter="20">
<!-- 左侧个人信息卡片 -->
<el-col :span="8">
<el-card class="user-card">
<div class="user-info">
<div class="avatar-wrapper">
<el-avatar :src="userProfile.avatar" :size="100" />
<el-button
type="info"
class="absolute bottom-0 right-0 cursor-pointer"
class="avatar-edit-btn"
circle
:icon="Camera"
size="small"
@@ -18,152 +17,115 @@
/>
<input ref="fileInput" type="file" style="display: none" @change="handleFileChange" />
</div>
<div class="mt-5">
{{ userProfile.nickname }}
<el-icon
class="align-middle cursor-pointer"
@click="handleOpenDialog(DialogType.ACCOUNT)"
>
<div class="user-name">
<span class="nickname">{{ userProfile.nickname }}</span>
<el-icon class="edit-icon" @click="handleOpenDialog(DialogType.ACCOUNT)">
<Edit />
</el-icon>
</div>
<!-- 用户信息描述 -->
<el-descriptions :column="1" class="mt-10">
<!-- 用户名 -->
<el-descriptions-item>
<template #label>
<el-icon class="align-middle"><User /></el-icon>
用户名
</template>
{{ userProfile.username }}
<el-icon v-if="userProfile.gender === 1" class="align-middle color-blue">
<Male />
</el-icon>
<el-icon v-else class="align-middle color-pink">
<Female />
</el-icon>
</el-descriptions-item>
<el-descriptions-item>
<template #label>
<el-icon class="align-middle"><Phone /></el-icon>
手机号码
</template>
{{ userProfile.mobile }}
</el-descriptions-item>
<el-descriptions-item>
<template #label>
<el-icon class="align-middle"><Message /></el-icon>
邮箱
</template>
{{ userProfile.email }}
</el-descriptions-item>
<el-descriptions-item>
<template #label>
<div class="i-svg:tree" />
部门
</template>
{{ userProfile.deptName }}
</el-descriptions-item>
<el-descriptions-item>
<template #label>
<div class="i-svg:role" />
角色
</template>
{{ userProfile.roleNames }}
</el-descriptions-item>
<el-descriptions-item>
<template #label>
<el-icon class="align-middle"><Timer /></el-icon>
创建日期
</template>
{{ userProfile.createTime }}
</el-descriptions-item>
</el-descriptions>
</el-card>
</div>
</el-tab-pane>
<!-- 安全设置 -->
<el-tab-pane label="安全设置">
<el-card>
<!-- 账户密码 -->
<el-row>
<el-col :span="16">
<div class="font-bold">账户密码</div>
<div class="text-14px mt-2">
定期修改密码有助于保护账户安全
<el-button
type="primary"
plain
size="small"
class="ml-5"
@click="() => handleOpenDialog(DialogType.PASSWORD)"
>
修改
</el-button>
</div>
</el-col>
</el-row>
<!-- 绑定手机 -->
<div class="mt-5">
<div class="font-bold">绑定手机</div>
<div class="text-14px mt-2">
<span v-if="userProfile.mobile">已绑定手机号{{ userProfile.mobile }}</span>
<span v-else>未绑定手机</span>
<el-button
v-if="userProfile.mobile"
type="primary"
plain
size="small"
class="ml-5"
@click="() => handleOpenDialog(DialogType.MOBILE)"
>
更换
</el-button>
<el-button
v-else
type="primary"
plain
size="small"
class="ml-5"
@click="() => handleOpenDialog(DialogType.MOBILE)"
>
绑定
</el-button>
</div>
<div class="user-role">{{ userProfile.roleNames }}</div>
</div>
<!-- 绑定邮箱 -->
<div class="mt-5">
<div class="font-bold">绑定邮箱</div>
<div class="text-14px mt-2">
<span v-if="userProfile.email">已绑定邮箱{{ userProfile.email }}</span>
<span v-else>未绑定邮箱</span>
<el-button
v-if="userProfile.email"
type="primary"
plain
size="small"
class="ml-5"
@click="() => handleOpenDialog(DialogType.EMAIL)"
>
更换
</el-button>
<el-button
v-else
type="primary"
plain
size="small"
class="ml-5"
@click="() => handleOpenDialog(DialogType.EMAIL)"
>
绑定
</el-button>
<el-divider />
<div class="user-stats">
<div class="stat-item">
<div class="stat-value">0</div>
<div class="stat-label">待办</div>
</div>
<div class="stat-item">
<div class="stat-value">0</div>
<div class="stat-label">消息</div>
</div>
<div class="stat-item">
<div class="stat-value">0</div>
<div class="stat-label">通知</div>
</div>
</div>
</el-card>
</el-tab-pane>
</el-tabs>
</el-col>
<!-- 右侧信息卡片 -->
<el-col :span="16">
<el-card class="info-card">
<template #header>
<div class="card-header">
<span>账号信息</span>
</div>
</template>
<el-descriptions :column="1" border>
<el-descriptions-item label="用户名">
{{ userProfile.username }}
<el-icon v-if="userProfile.gender === 1" class="gender-icon male">
<Male />
</el-icon>
<el-icon v-else class="gender-icon female">
<Female />
</el-icon>
</el-descriptions-item>
<el-descriptions-item label="手机号码">
{{ userProfile.mobile || "未绑定" }}
<el-button
v-if="userProfile.mobile"
type="primary"
link
@click="() => handleOpenDialog(DialogType.MOBILE)"
>
更换
</el-button>
<el-button
v-else
type="primary"
link
@click="() => handleOpenDialog(DialogType.MOBILE)"
>
绑定
</el-button>
</el-descriptions-item>
<el-descriptions-item label="邮箱">
{{ userProfile.email || "未绑定" }}
<el-button
v-if="userProfile.email"
type="primary"
link
@click="() => handleOpenDialog(DialogType.EMAIL)"
>
更换
</el-button>
<el-button
v-else
type="primary"
link
@click="() => handleOpenDialog(DialogType.EMAIL)"
>
绑定
</el-button>
</el-descriptions-item>
<el-descriptions-item label="部门">
{{ userProfile.deptName }}
</el-descriptions-item>
<el-descriptions-item label="创建时间">
{{ userProfile.createTime }}
</el-descriptions-item>
</el-descriptions>
</el-card>
<el-card class="security-card">
<template #header>
<div class="card-header">
<span>安全设置</span>
</div>
</template>
<div class="security-item">
<div class="security-info">
<div class="security-title">账户密码</div>
<div class="security-desc">定期修改密码有助于保护账户安全</div>
</div>
<el-button type="primary" link @click="() => handleOpenDialog(DialogType.PASSWORD)">
修改
</el-button>
</div>
</el-card>
</el-col>
</el-row>
<!-- 弹窗 -->
<el-dialog v-model="dialog.visible" :title="dialog.title" :width="500">
@@ -200,6 +162,7 @@
<el-input v-model="passwordChangeForm.confirmPassword" type="password" show-password />
</el-form-item>
</el-form>
<!-- 绑定手机 -->
<el-form
v-else-if="dialog.type === DialogType.MOBILE"
@@ -214,7 +177,7 @@
<el-form-item label="验证码" prop="code">
<el-input v-model="mobileUpdateForm.code" style="width: 250px">
<template #append>
<el-button class="ml-5" :disabled="mobileCountdown > 0" @click="handleSendMobileCode">
<el-button :disabled="mobileCountdown > 0" @click="handleSendMobileCode">
{{ mobileCountdown > 0 ? `${mobileCountdown}s后重新发送` : "发送验证码" }}
</el-button>
</template>
@@ -236,13 +199,14 @@
<el-form-item label="验证码" prop="code">
<el-input v-model="emailUpdateForm.code" style="width: 250px">
<template #append>
<el-button class="ml-5" :disabled="emailCountdown > 0" @click="handleSendEmailCode">
<el-button :disabled="emailCountdown > 0" @click="handleSendEmailCode">
{{ emailCountdown > 0 ? `${emailCountdown}s后重新发送` : "发送验证码" }}
</el-button>
</template>
</el-input>
</el-form-item>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click="dialog.visible = false">取消</el-button>
@@ -490,18 +454,167 @@ onMounted(async () => {
</script>
<style lang="scss" scoped>
/** 关闭tag标签 */
.app-container {
/* 50px = navbar = 50px */
height: calc(100vh - 50px);
.profile-container {
min-height: calc(100vh - 84px);
padding: 20px;
background: var(--el-fill-color-blank);
}
/** 开启tag标签 */
.hasTagsView {
.app-container {
/* 84px = navbar + tags-view = 50px + 34px */
height: calc(100vh - 84px);
.user-card {
.user-info {
padding: 20px 0;
text-align: center;
.avatar-wrapper {
position: relative;
display: inline-block;
margin-bottom: 16px;
.avatar-edit-btn {
position: absolute;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
border: none;
transition: all 0.3s ease;
&:hover {
background: rgba(0, 0, 0, 0.7);
}
}
}
.user-name {
margin-bottom: 8px;
.nickname {
font-size: 18px;
font-weight: 600;
color: var(--el-text-color-primary);
}
.edit-icon {
margin-left: 8px;
color: var(--el-text-color-secondary);
cursor: pointer;
transition: all 0.3s ease;
&:hover {
color: var(--el-color-primary);
}
}
}
.user-role {
font-size: 14px;
color: var(--el-text-color-secondary);
}
}
.user-stats {
display: flex;
justify-content: space-around;
padding: 16px 0;
.stat-item {
text-align: center;
.stat-value {
font-size: 20px;
font-weight: 600;
color: var(--el-text-color-primary);
}
.stat-label {
margin-top: 4px;
font-size: 12px;
color: var(--el-text-color-secondary);
}
}
}
}
.info-card,
.security-card {
margin-bottom: 20px;
.card-header {
font-size: 16px;
font-weight: 600;
color: var(--el-text-color-primary);
}
}
.security-item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 16px 0;
.security-info {
.security-title {
margin-bottom: 4px;
font-size: 16px;
font-weight: 500;
color: var(--el-text-color-primary);
}
.security-desc {
font-size: 14px;
color: var(--el-text-color-secondary);
}
}
}
.el-descriptions {
.el-descriptions__label {
font-weight: 500;
color: var(--el-text-color-regular);
}
.el-descriptions__content {
color: var(--el-text-color-primary);
}
.gender-icon {
margin-left: 8px;
font-size: 16px;
&.male {
color: #409eff;
}
&.female {
color: #f56c6c;
}
}
}
.el-dialog {
.el-dialog__header {
padding: 20px;
margin: 0;
border-bottom: 1px solid var(--el-border-color-light);
}
.el-dialog__body {
padding: 30px 20px;
}
.el-dialog__footer {
padding: 20px;
border-top: 1px solid var(--el-border-color-light);
}
}
// 响应式适配
@media (max-width: 768px) {
.profile-container {
padding: 10px;
}
.el-col {
width: 100%;
}
}
</style>