feat: enhance user profile management and security features
- Added new API functions for account information retrieval and username/password updates. - Updated AccountSecurity component to reflect password status and provide password management options. - Removed BasicInfoForm and OperationLogs components, streamlining the profile interface. - Enhanced UserInfoCard to allow username editing directly within the card. - Improved overall user experience with loading states and error handling during API calls. - Updated profile configuration to remove unused mock data and components.
This commit is contained in:
parent
e8b3eda895
commit
ad15972f20
@ -34,7 +34,7 @@
|
|||||||
|---|---|---|---|
|
|---|---|---|---|
|
||||||
| 1 | `src/views/login/index.vue` | 登录页:账号密码登录、注册、微信扫码登录 | 登录成功 → `router.push(redirect \|\| '/')`;扫码成功后 `setToken` + `userStore.$patch({token})` |
|
| 1 | `src/views/login/index.vue` | 登录页:账号密码登录、注册、微信扫码登录 | 登录成功 → `router.push(redirect \|\| '/')`;扫码成功后 `setToken` + `userStore.$patch({token})` |
|
||||||
| 2 | `src/stores/modules/user.ts` | **登录核心 store** | `login / register / getInfo / changeRole / logout / resetToken / updateToken / checkPermission` |
|
| 2 | `src/stores/modules/user.ts` | **登录核心 store** | `login / register / getInfo / changeRole / logout / resetToken / updateToken / checkPermission` |
|
||||||
| 3 | `src/api/user/user.ts` | 登录相关接口 | `user.login`、`user.loginByCode`、`user.register`、`user.info`、`user.changeRole`、`user.logout`、`user.getLoginWechatCode`(扫码)、`user.getBindWechatCode` / `user.unbindWechat`(绑定) |
|
| 3 | `src/api/user/user.ts` | 登录相关接口 | `user.login`、`user.loginByCode`、`user.register`、`user.info`、`user.getAccountInfo`(个人中心)、`user.updateUsername`(改账号)、`user.changePassword`(设置/修改密码)、`user.changeRole`、`user.logout`、`user.getLoginWechatCode`(扫码)、`user.getBindWechatCode` / `user.unbindWechat`(绑定) |
|
||||||
| 4 | `src/utils/auth.ts` | token 存取(Cookie,key=`token`) | `getToken / setToken / removeToken` |
|
| 4 | `src/utils/auth.ts` | token 存取(Cookie,key=`token`) | `getToken / setToken / removeToken` |
|
||||||
| 5 | `src/utils/request.ts` | axios 封装 | 请求头 `platform/project`、注入 `Authorization: Bearer <token>`、**响应头新 token 自动回写**、`401/50008/50012/50014` → 弹窗重登 |
|
| 5 | `src/utils/request.ts` | axios 封装 | 请求头 `platform/project`、注入 `Authorization: Bearer <token>`、**响应头新 token 自动回写**、`401/50008/50012/50014` → 弹窗重登 |
|
||||||
| 6 | `src/permission.ts` | 路由守卫(登录准入 + 动态路由) | 白名单、getToken 判定、`getInfo()` 拉菜单、失败 `resetToken()` |
|
| 6 | `src/permission.ts` | 路由守卫(登录准入 + 动态路由) | 白名单、getToken 判定、`getInfo()` 拉菜单、失败 `resetToken()` |
|
||||||
|
|||||||
@ -129,7 +129,6 @@
|
|||||||
| `views/warehouse/AreaRacksList.vue` | 库位容量占用条 |
|
| `views/warehouse/AreaRacksList.vue` | 库位容量占用条 |
|
||||||
| `views/dashboard/components/StatsCardsWarehouse.vue` | 仪表盘统计卡片进度 |
|
| `views/dashboard/components/StatsCardsWarehouse.vue` | 仪表盘统计卡片进度 |
|
||||||
| `views/dashboard/components/StatsCardsStore.vue` | 仪表盘统计卡片进度 |
|
| `views/dashboard/components/StatsCardsStore.vue` | 仪表盘统计卡片进度 |
|
||||||
| `views/profile/components/AccountSecurity.vue` | 账号安全强度条 |
|
|
||||||
| `views/test/index.vue` | 独立测试页的豹子进度条演示 |
|
| `views/test/index.vue` | 独立测试页的豹子进度条演示 |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
@ -80,6 +80,82 @@ export function getInfo(data: UserInfoParams = {}) {
|
|||||||
} as SystemApiRequestConfig<Record<string, any>>);
|
} as SystemApiRequestConfig<Record<string, any>>);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* user.getAccountInfo 入参
|
||||||
|
* 与 user.info 保持一致:后端按登录态取当前账户,参数可留空。
|
||||||
|
*/
|
||||||
|
export interface AccountInfoParams {
|
||||||
|
/** 小程序 AppID(可选) */
|
||||||
|
wechat_appId?: string
|
||||||
|
/** 其它业务参数(以后端为准) */
|
||||||
|
[key: string]: unknown
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取账户信息(个人中心)
|
||||||
|
* 返回当前登录账户的资料、账户安全等信息
|
||||||
|
*/
|
||||||
|
export function getAccountInfo(data: AccountInfoParams = {}) {
|
||||||
|
return request({
|
||||||
|
url: '/system',
|
||||||
|
method: 'post',
|
||||||
|
params: {
|
||||||
|
method: 'user.getAccountInfo',
|
||||||
|
v: '1.0',
|
||||||
|
timestamp: new Date().getTime()
|
||||||
|
},
|
||||||
|
data,
|
||||||
|
isSystemApi: true
|
||||||
|
} as SystemApiRequestConfig<AccountInfoParams>);
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UpdateUsernameParams {
|
||||||
|
/** 新的登录账号 */
|
||||||
|
username: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改登录账号(user.updateUsername)
|
||||||
|
*/
|
||||||
|
export function updateUsername(data: UpdateUsernameParams) {
|
||||||
|
return request({
|
||||||
|
url: '/system',
|
||||||
|
method: 'post',
|
||||||
|
params: {
|
||||||
|
method: 'user.updateUsername',
|
||||||
|
v: '1.0',
|
||||||
|
timestamp: new Date().getTime()
|
||||||
|
},
|
||||||
|
data,
|
||||||
|
isSystemApi: true
|
||||||
|
} as SystemApiRequestConfig<UpdateUsernameParams>);
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ChangePasswordParams {
|
||||||
|
/** 新密码 */
|
||||||
|
new_password: string
|
||||||
|
/** 旧密码:已设置过密码时必传,首次设置密码时无需传 */
|
||||||
|
old_password?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改/设置登录密码(user.changePassword)
|
||||||
|
* is_custom_password=0 表示从未设置过密码,此时不传 old_password
|
||||||
|
*/
|
||||||
|
export function changePassword(data: ChangePasswordParams) {
|
||||||
|
return request({
|
||||||
|
url: '/system',
|
||||||
|
method: 'post',
|
||||||
|
params: {
|
||||||
|
method: 'user.changePassword',
|
||||||
|
v: '1.0',
|
||||||
|
timestamp: new Date().getTime()
|
||||||
|
},
|
||||||
|
data,
|
||||||
|
isSystemApi: true
|
||||||
|
} as SystemApiRequestConfig<ChangePasswordParams>);
|
||||||
|
}
|
||||||
|
|
||||||
export function changeRole(data: Record<string, any>) {
|
export function changeRole(data: Record<string, any>) {
|
||||||
return request({
|
return request({
|
||||||
url: '/system',
|
url: '/system',
|
||||||
|
|||||||
@ -1,22 +1,22 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="account-security">
|
<div class="account-security">
|
||||||
<!-- 安全等级 -->
|
<!-- 登录密码 -->
|
||||||
<el-card class="security-level">
|
<el-card class="password-card">
|
||||||
<template #header>
|
<template #header>
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<span>安全等级</span>
|
<span>登录密码</span>
|
||||||
<el-tag :type="getStrengthType(security.passwordStrength)">
|
<el-tag :type="hasPassword ? 'success' : 'warning'" size="small">
|
||||||
{{ getStrengthText(security.passwordStrength) }}
|
{{ hasPassword ? '已设置' : '未设置' }}
|
||||||
</el-tag>
|
</el-tag>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<el-progress
|
<div class="password-body">
|
||||||
:percentage="getSecurityScore()"
|
<p class="description">
|
||||||
:stroke-width="10"
|
{{ hasPassword ? '建议定期更换登录密码,保障账号安全。' : '当前账号还未设置登录密码,设置后可使用账号密码登录。' }}
|
||||||
:color="getProgressColor"
|
</p>
|
||||||
/>
|
<el-button type="primary" @click="emit('change-password')">
|
||||||
<div class="level-tips">
|
{{ hasPassword ? '修改密码' : '设置密码' }}
|
||||||
上次修改密码:{{ security.lastPasswordChange }}
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
</el-card>
|
</el-card>
|
||||||
|
|
||||||
@ -120,9 +120,10 @@ import { ElMessageBox, ElMessage } from 'element-plus'
|
|||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
securityInfo: any
|
securityInfo: any
|
||||||
|
hasPassword?: boolean
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const emit = defineEmits(['refresh'])
|
const emit = defineEmits(['refresh', 'change-password'])
|
||||||
|
|
||||||
const security = reactive<any>({ ...props.securityInfo })
|
const security = reactive<any>({ ...props.securityInfo })
|
||||||
|
|
||||||
@ -130,38 +131,6 @@ watch(() => props.securityInfo, (newVal) => {
|
|||||||
Object.assign(security, newVal)
|
Object.assign(security, newVal)
|
||||||
}, { deep: true })
|
}, { deep: true })
|
||||||
|
|
||||||
const getStrengthType = (strength: string) => {
|
|
||||||
const map: Record<string, string> = {
|
|
||||||
weak: 'danger',
|
|
||||||
medium: 'warning',
|
|
||||||
strong: 'success'
|
|
||||||
}
|
|
||||||
return map[strength] || 'info'
|
|
||||||
}
|
|
||||||
|
|
||||||
const getStrengthText = (strength: string) => {
|
|
||||||
const map: Record<string, string> = {
|
|
||||||
weak: '弱',
|
|
||||||
medium: '中',
|
|
||||||
strong: '强'
|
|
||||||
}
|
|
||||||
return map[strength] || '未知'
|
|
||||||
}
|
|
||||||
|
|
||||||
const getSecurityScore = () => {
|
|
||||||
let score = 0
|
|
||||||
if (security.emailVerified) score += 30
|
|
||||||
if (security.phoneVerified) score += 30
|
|
||||||
if (security.twoFactorEnabled) score += 40
|
|
||||||
return score
|
|
||||||
}
|
|
||||||
|
|
||||||
const getProgressColor = (percentage: number) => {
|
|
||||||
if (percentage < 60) return '#f56c6c'
|
|
||||||
if (percentage < 80) return '#e6a23c'
|
|
||||||
return '#67c23a'
|
|
||||||
}
|
|
||||||
|
|
||||||
const getDeviceIcon = (device: string) => {
|
const getDeviceIcon = (device: string) => {
|
||||||
if (device.includes('iPhone') || device.includes('Android')) {
|
if (device.includes('iPhone') || device.includes('Android')) {
|
||||||
return Iphone
|
return Iphone
|
||||||
@ -235,11 +204,18 @@ const handleDeleteAccount = () => {
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.security-level {
|
.password-card {
|
||||||
.level-tips {
|
.password-body {
|
||||||
margin-top: 10px;
|
display: flex;
|
||||||
color: var(--el-text-color-secondary);
|
align-items: center;
|
||||||
font-size: 13px;
|
justify-content: space-between;
|
||||||
|
gap: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.description {
|
||||||
|
color: var(--el-text-color-regular);
|
||||||
|
font-size: 14px;
|
||||||
|
margin: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,187 +0,0 @@
|
|||||||
<template>
|
|
||||||
<el-form
|
|
||||||
ref="formRef"
|
|
||||||
:model="form"
|
|
||||||
:rules="rules"
|
|
||||||
label-width="100px"
|
|
||||||
class="basic-form"
|
|
||||||
>
|
|
||||||
<el-form-item label="昵称" prop="nickname">
|
|
||||||
<el-input
|
|
||||||
v-model="form.nickname"
|
|
||||||
placeholder="请输入昵称"
|
|
||||||
maxlength="20"
|
|
||||||
show-word-limit
|
|
||||||
/>
|
|
||||||
</el-form-item>
|
|
||||||
|
|
||||||
<el-form-item label="邮箱" prop="email">
|
|
||||||
<el-input
|
|
||||||
v-model="form.email"
|
|
||||||
placeholder="请输入邮箱"
|
|
||||||
type="email"
|
|
||||||
/>
|
|
||||||
<!-- <el-button
|
|
||||||
v-if="!isEmailVerified"
|
|
||||||
type="primary"
|
|
||||||
link
|
|
||||||
size="small"
|
|
||||||
@click="handleVerifyEmail"
|
|
||||||
>
|
|
||||||
验证邮箱
|
|
||||||
</el-button> -->
|
|
||||||
</el-form-item>
|
|
||||||
|
|
||||||
<el-form-item label="手机号" prop="phone">
|
|
||||||
<el-input
|
|
||||||
v-model="form.phone"
|
|
||||||
placeholder="请输入手机号"
|
|
||||||
/>
|
|
||||||
<!-- <el-button
|
|
||||||
v-if="!isPhoneVerified"
|
|
||||||
type="primary"
|
|
||||||
link
|
|
||||||
size="small"
|
|
||||||
@click="handleVerifyPhone"
|
|
||||||
>
|
|
||||||
验证手机
|
|
||||||
</el-button> -->
|
|
||||||
</el-form-item>
|
|
||||||
|
|
||||||
<el-form-item label="部门" prop="department">
|
|
||||||
<el-select
|
|
||||||
v-model="form.department"
|
|
||||||
placeholder="请选择部门"
|
|
||||||
style="width: 100%"
|
|
||||||
>
|
|
||||||
<el-option
|
|
||||||
v-for="item in DEPARTMENT_OPTIONS"
|
|
||||||
:key="item.value"
|
|
||||||
:label="item.label"
|
|
||||||
:value="item.value"
|
|
||||||
/>
|
|
||||||
</el-select>
|
|
||||||
</el-form-item>
|
|
||||||
|
|
||||||
<el-form-item label="职位" prop="position">
|
|
||||||
<el-input
|
|
||||||
v-model="form.position"
|
|
||||||
placeholder="请输入职位"
|
|
||||||
/>
|
|
||||||
</el-form-item>
|
|
||||||
|
|
||||||
<el-form-item label="个人简介" prop="bio">
|
|
||||||
<el-input
|
|
||||||
v-model="form.bio"
|
|
||||||
type="textarea"
|
|
||||||
:rows="4"
|
|
||||||
placeholder="请简要介绍自己"
|
|
||||||
maxlength="200"
|
|
||||||
show-word-limit
|
|
||||||
/>
|
|
||||||
</el-form-item>
|
|
||||||
|
|
||||||
<el-form-item>
|
|
||||||
<el-button type="primary" @click="handleSubmit">
|
|
||||||
保存修改
|
|
||||||
</el-button>
|
|
||||||
<el-button @click="handleReset">
|
|
||||||
重置
|
|
||||||
</el-button>
|
|
||||||
</el-form-item>
|
|
||||||
</el-form>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
|
||||||
import { ref, watch, reactive } from 'vue'
|
|
||||||
import type { FormInstance, FormRules } from 'element-plus'
|
|
||||||
import { ElMessage } from 'element-plus'
|
|
||||||
import { DEPARTMENT_OPTIONS } from '../profile-config'
|
|
||||||
|
|
||||||
const props = defineProps<{
|
|
||||||
user: any
|
|
||||||
}>()
|
|
||||||
|
|
||||||
const emit = defineEmits(['submit'])
|
|
||||||
|
|
||||||
const formRef = ref<FormInstance>()
|
|
||||||
|
|
||||||
const form = reactive({
|
|
||||||
nickname: '',
|
|
||||||
email: '',
|
|
||||||
phone: '',
|
|
||||||
department: '',
|
|
||||||
position: '',
|
|
||||||
bio: ''
|
|
||||||
})
|
|
||||||
|
|
||||||
const rules = reactive<FormRules>({
|
|
||||||
nickname: [
|
|
||||||
{ required: true, message: '请输入昵称', trigger: 'blur' },
|
|
||||||
{ min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur' }
|
|
||||||
],
|
|
||||||
email: [
|
|
||||||
{ required: true, message: '请输入邮箱地址', trigger: 'blur' },
|
|
||||||
{ type: 'email', message: '请输入正确的邮箱地址', trigger: 'blur' }
|
|
||||||
],
|
|
||||||
phone: [
|
|
||||||
{ required: true, message: '请输入手机号', trigger: 'blur' },
|
|
||||||
{ pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号', trigger: 'blur' }
|
|
||||||
],
|
|
||||||
department: [
|
|
||||||
{ required: true, message: '请选择部门', trigger: 'change' }
|
|
||||||
]
|
|
||||||
})
|
|
||||||
|
|
||||||
// const isEmailVerified = ref(true)
|
|
||||||
// const isPhoneVerified = ref(true)
|
|
||||||
|
|
||||||
watch(() => props.user, (newVal) => {
|
|
||||||
if (newVal) {
|
|
||||||
console.log('BasicInfoForm received user data from parent:', newVal)
|
|
||||||
form.nickname = newVal.nickname || ''
|
|
||||||
form.email = newVal.email || ''
|
|
||||||
form.phone = newVal.phone || ''
|
|
||||||
form.department = newVal.department || ''
|
|
||||||
form.position = newVal.position || ''
|
|
||||||
form.bio = newVal.bio || ''
|
|
||||||
}
|
|
||||||
}, { immediate: true, deep: true })
|
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
|
||||||
if (!formRef.value) return
|
|
||||||
await formRef.value.validate((valid, fields) => {
|
|
||||||
if (valid) {
|
|
||||||
emit('submit', { ...form })
|
|
||||||
} else {
|
|
||||||
console.log('error submit!', fields)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleReset = () => {
|
|
||||||
if (!formRef.value) return
|
|
||||||
formRef.value.resetFields()
|
|
||||||
// Reset manually to props if resetFields doesn't work as expected with watch
|
|
||||||
form.nickname = props.user.nickname || ''
|
|
||||||
form.email = props.user.email || ''
|
|
||||||
form.phone = props.user.phone || ''
|
|
||||||
form.department = props.user.department || ''
|
|
||||||
form.position = props.user.position || ''
|
|
||||||
form.bio = props.user.bio || ''
|
|
||||||
}
|
|
||||||
|
|
||||||
// const handleVerifyEmail = () => {
|
|
||||||
// ElMessage.info('发送验证邮件...')
|
|
||||||
// }
|
|
||||||
|
|
||||||
// const handleVerifyPhone = () => {
|
|
||||||
// ElMessage.info('发送验证码...')
|
|
||||||
// }
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
|
||||||
.basic-form {
|
|
||||||
max-width: 600px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@ -1,8 +1,9 @@
|
|||||||
<template>
|
<template>
|
||||||
<el-dialog
|
<el-dialog
|
||||||
title="修改密码"
|
|
||||||
v-model="visible"
|
v-model="visible"
|
||||||
|
:title="firstSet ? '设置密码' : '修改密码'"
|
||||||
width="500px"
|
width="500px"
|
||||||
|
align-center
|
||||||
@close="handleClose"
|
@close="handleClose"
|
||||||
>
|
>
|
||||||
<el-form
|
<el-form
|
||||||
@ -11,7 +12,7 @@
|
|||||||
:rules="rules"
|
:rules="rules"
|
||||||
label-width="100px"
|
label-width="100px"
|
||||||
>
|
>
|
||||||
<el-form-item label="旧密码" prop="oldPassword">
|
<el-form-item v-if="!firstSet" label="旧密码" prop="oldPassword">
|
||||||
<el-input
|
<el-input
|
||||||
v-model="form.oldPassword"
|
v-model="form.oldPassword"
|
||||||
type="password"
|
type="password"
|
||||||
@ -38,8 +39,10 @@
|
|||||||
</el-form>
|
</el-form>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<span class="dialog-footer">
|
<span class="dialog-footer">
|
||||||
<el-button @click="visible = false">取消</el-button>
|
<el-button :disabled="submitting" @click="visible = false">取消</el-button>
|
||||||
<el-button type="primary" @click="handleSubmit">确认</el-button>
|
<el-button type="primary" :loading="submitting" @click="handleSubmit">
|
||||||
|
确认
|
||||||
|
</el-button>
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
@ -49,9 +52,12 @@
|
|||||||
import { ref, reactive, computed } from 'vue'
|
import { ref, reactive, computed } from 'vue'
|
||||||
import type { FormInstance, FormRules } from 'element-plus'
|
import type { FormInstance, FormRules } from 'element-plus'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
|
import { changePassword } from '@/api/user/user'
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
modelValue: boolean
|
modelValue: boolean
|
||||||
|
/** 首次设置密码(is_custom_password=0),无需输入旧密码 */
|
||||||
|
firstSet?: boolean
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const emit = defineEmits(['update:modelValue', 'success'])
|
const emit = defineEmits(['update:modelValue', 'success'])
|
||||||
@ -62,13 +68,14 @@ const visible = computed({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const formRef = ref<FormInstance>()
|
const formRef = ref<FormInstance>()
|
||||||
|
const submitting = ref(false)
|
||||||
const form = reactive({
|
const form = reactive({
|
||||||
oldPassword: '',
|
oldPassword: '',
|
||||||
newPassword: '',
|
newPassword: '',
|
||||||
confirmPassword: ''
|
confirmPassword: ''
|
||||||
})
|
})
|
||||||
|
|
||||||
const validatePass2 = (rule: any, value: any, callback: any) => {
|
const validatePass2 = (_rule: unknown, value: string, callback: (error?: Error) => void) => {
|
||||||
if (value === '') {
|
if (value === '') {
|
||||||
callback(new Error('请再次输入密码'))
|
callback(new Error('请再次输入密码'))
|
||||||
} else if (value !== form.newPassword) {
|
} else if (value !== form.newPassword) {
|
||||||
@ -78,35 +85,47 @@ const validatePass2 = (rule: any, value: any, callback: any) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const rules = reactive<FormRules>({
|
const rules = computed<FormRules>(() => {
|
||||||
oldPassword: [
|
const base: FormRules = {
|
||||||
{ required: true, message: '请输入旧密码', trigger: 'blur' },
|
newPassword: [
|
||||||
{ min: 6, message: '密码长度不能小于6位', trigger: 'blur' }
|
{ required: true, message: '请输入新密码', trigger: 'blur' },
|
||||||
],
|
{ min: 6, message: '密码长度不能小于6位', trigger: 'blur' }
|
||||||
newPassword: [
|
],
|
||||||
{ required: true, message: '请输入新密码', trigger: 'blur' },
|
confirmPassword: [
|
||||||
{ min: 6, message: '密码长度不能小于6位', trigger: 'blur' }
|
{ required: true, validator: validatePass2, trigger: 'blur' }
|
||||||
],
|
]
|
||||||
confirmPassword: [
|
}
|
||||||
{ required: true, validator: validatePass2, trigger: 'blur' }
|
if (!props.firstSet) {
|
||||||
]
|
base.oldPassword = [
|
||||||
|
{ required: true, message: '请输入旧密码', trigger: 'blur' },
|
||||||
|
{ min: 6, message: '密码长度不能小于6位', trigger: 'blur' }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
return base
|
||||||
})
|
})
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
if (!formRef.value) return
|
if (!formRef.value || submitting.value) return
|
||||||
await formRef.value.validate((valid) => {
|
const valid = await formRef.value.validate().catch(() => false)
|
||||||
if (valid) {
|
if (!valid) return
|
||||||
// TODO: Call API to change password
|
|
||||||
emit('success')
|
submitting.value = true
|
||||||
visible.value = false
|
try {
|
||||||
ElMessage.success('密码修改成功')
|
await changePassword({
|
||||||
}
|
new_password: form.newPassword,
|
||||||
})
|
...(props.firstSet ? {} : { old_password: form.oldPassword })
|
||||||
|
})
|
||||||
|
ElMessage.success(props.firstSet ? '密码设置成功' : '密码修改成功')
|
||||||
|
emit('success')
|
||||||
|
visible.value = false
|
||||||
|
} catch {
|
||||||
|
// 错误提示由 request 拦截器统一处理
|
||||||
|
} finally {
|
||||||
|
submitting.value = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
if (formRef.value) {
|
formRef.value?.resetFields()
|
||||||
formRef.value.resetFields()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -1,329 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div class="operation-logs">
|
|
||||||
<!-- 搜索和筛选 -->
|
|
||||||
<div class="log-filters sticky-element">
|
|
||||||
<el-form :inline="true" :model="filterForm">
|
|
||||||
<el-form-item label="操作类型">
|
|
||||||
<el-select
|
|
||||||
v-model="filterForm.actionType"
|
|
||||||
placeholder="请选择"
|
|
||||||
clearable
|
|
||||||
>
|
|
||||||
<el-option label="登录" value="login" />
|
|
||||||
<el-option label="修改" value="update" />
|
|
||||||
<el-option label="删除" value="delete" />
|
|
||||||
<el-option label="导出" value="export" />
|
|
||||||
<el-option label="其他" value="other" />
|
|
||||||
</el-select>
|
|
||||||
</el-form-item>
|
|
||||||
|
|
||||||
<el-form-item label="状态">
|
|
||||||
<el-select
|
|
||||||
v-model="filterForm.status"
|
|
||||||
placeholder="请选择"
|
|
||||||
clearable
|
|
||||||
>
|
|
||||||
<el-option label="成功" value="success" />
|
|
||||||
<el-option label="失败" value="failed" />
|
|
||||||
</el-select>
|
|
||||||
</el-form-item>
|
|
||||||
|
|
||||||
<el-form-item label="时间范围">
|
|
||||||
<el-date-picker
|
|
||||||
v-model="filterForm.dateRange"
|
|
||||||
type="daterange"
|
|
||||||
range-separator="至"
|
|
||||||
start-placeholder="开始日期"
|
|
||||||
end-placeholder="结束日期"
|
|
||||||
value-format="YYYY-MM-DD"
|
|
||||||
/>
|
|
||||||
</el-form-item>
|
|
||||||
|
|
||||||
<el-form-item>
|
|
||||||
<el-button type="primary" @click="handleSearch">
|
|
||||||
搜索
|
|
||||||
</el-button>
|
|
||||||
<el-button @click="handleReset">
|
|
||||||
重置
|
|
||||||
</el-button>
|
|
||||||
</el-form-item>
|
|
||||||
</el-form>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 日志表格 -->
|
|
||||||
<el-table
|
|
||||||
:data="logs.list"
|
|
||||||
v-loading="logs.loading"
|
|
||||||
style="width: 100%"
|
|
||||||
stripe
|
|
||||||
>
|
|
||||||
<el-table-column prop="action" label="操作" width="180">
|
|
||||||
<template #default="{ row }">
|
|
||||||
<div class="action-cell">
|
|
||||||
<el-icon>
|
|
||||||
<component :is="getActionIcon(row.action)" />
|
|
||||||
</el-icon>
|
|
||||||
<span>{{ row.action }}</span>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
|
|
||||||
<el-table-column prop="ip" label="IP地址" width="150" />
|
|
||||||
|
|
||||||
<el-table-column prop="time" label="时间" width="180">
|
|
||||||
<template #default="{ row }">
|
|
||||||
<el-tooltip :content="row.time" placement="top">
|
|
||||||
<span>{{ formatTime(row.time) }}</span>
|
|
||||||
</el-tooltip>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
|
|
||||||
<el-table-column prop="status" label="状态" width="100">
|
|
||||||
<template #default="{ row }">
|
|
||||||
<el-tag
|
|
||||||
:type="row.status === '成功' ? 'success' : 'danger'"
|
|
||||||
size="small"
|
|
||||||
>
|
|
||||||
{{ row.status }}
|
|
||||||
</el-tag>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
|
|
||||||
<el-table-column label="详情">
|
|
||||||
<template #default="{ row }">
|
|
||||||
<div class="log-detail">
|
|
||||||
<div>{{ getActionDetail(row) }}</div>
|
|
||||||
<div v-if="row.location" class="location">
|
|
||||||
<el-icon><Location /></el-icon>
|
|
||||||
<span>{{ row.location }}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
|
|
||||||
<el-table-column label="操作" width="80" fixed="right">
|
|
||||||
<template #default="{ row }">
|
|
||||||
<el-button
|
|
||||||
type="primary"
|
|
||||||
link
|
|
||||||
size="small"
|
|
||||||
@click="handleViewDetail(row)"
|
|
||||||
>
|
|
||||||
详情
|
|
||||||
</el-button>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
</el-table>
|
|
||||||
|
|
||||||
<!-- 分页 -->
|
|
||||||
<div class="log-pagination sticky-element-bottom">
|
|
||||||
<el-pagination
|
|
||||||
v-model:current-page="logs.page"
|
|
||||||
:page-size="10"
|
|
||||||
:total="logs.total"
|
|
||||||
layout="total, sizes, prev, pager, next, jumper"
|
|
||||||
@current-change="handlePageChange"
|
|
||||||
@size-change="handleSizeChange"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 日志详情对话框 -->
|
|
||||||
<el-dialog
|
|
||||||
v-model="showDetailDialog"
|
|
||||||
title="日志详情"
|
|
||||||
width="500px"
|
|
||||||
>
|
|
||||||
<div v-if="currentLog" class="log-detail-content">
|
|
||||||
<div class="detail-item">
|
|
||||||
<span class="label">操作:</span>
|
|
||||||
<span class="value">{{ currentLog.action }}</span>
|
|
||||||
</div>
|
|
||||||
<div class="detail-item">
|
|
||||||
<span class="label">时间:</span>
|
|
||||||
<span class="value">{{ currentLog.time }}</span>
|
|
||||||
</div>
|
|
||||||
<div class="detail-item">
|
|
||||||
<span class="label">IP地址:</span>
|
|
||||||
<span class="value">{{ currentLog.ip }}</span>
|
|
||||||
</div>
|
|
||||||
<div class="detail-item">
|
|
||||||
<span class="label">状态:</span>
|
|
||||||
<el-tag
|
|
||||||
:type="currentLog.status === '成功' ? 'success' : 'danger'"
|
|
||||||
size="small"
|
|
||||||
>
|
|
||||||
{{ currentLog.status }}
|
|
||||||
</el-tag>
|
|
||||||
</div>
|
|
||||||
<div v-if="currentLog.userAgent" class="detail-item">
|
|
||||||
<span class="label">User Agent:</span>
|
|
||||||
<span class="value">{{ currentLog.userAgent }}</span>
|
|
||||||
</div>
|
|
||||||
<div v-if="currentLog.location" class="detail-item">
|
|
||||||
<span class="label">位置:</span>
|
|
||||||
<span class="value">{{ currentLog.location }}</span>
|
|
||||||
</div>
|
|
||||||
<div v-if="currentLog.details" class="detail-item">
|
|
||||||
<span class="label">详细信息:</span>
|
|
||||||
<pre class="value details-pre">{{ currentLog.details }}</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</el-dialog>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
|
||||||
import { ref, reactive } from 'vue'
|
|
||||||
import dayjs from 'dayjs'
|
|
||||||
import { User, Lock, Edit, Delete, Download, Document, Location } from '@element-plus/icons-vue'
|
|
||||||
|
|
||||||
const props = defineProps<{
|
|
||||||
logs: any
|
|
||||||
}>()
|
|
||||||
|
|
||||||
const emit = defineEmits(['load-more'])
|
|
||||||
|
|
||||||
const filterForm = reactive({
|
|
||||||
actionType: '',
|
|
||||||
status: '',
|
|
||||||
dateRange: []
|
|
||||||
})
|
|
||||||
|
|
||||||
const showDetailDialog = ref(false)
|
|
||||||
const currentLog = ref<any>(null)
|
|
||||||
|
|
||||||
const formatTime = (time: string) => {
|
|
||||||
return dayjs(time).format('MM-DD HH:mm')
|
|
||||||
}
|
|
||||||
|
|
||||||
const getActionIcon = (action: string) => {
|
|
||||||
const iconMap: Record<string, any> = {
|
|
||||||
'登录': User,
|
|
||||||
'修改密码': Lock,
|
|
||||||
'更新个人信息': Edit,
|
|
||||||
'删除': Delete,
|
|
||||||
'导出': Download
|
|
||||||
}
|
|
||||||
return iconMap[action] || Document
|
|
||||||
}
|
|
||||||
|
|
||||||
const getActionDetail = (row: any) => {
|
|
||||||
const detailMap: Record<string, string> = {
|
|
||||||
'登录系统': `${row.status === '成功' ? '成功登录系统' : '登录失败'}`,
|
|
||||||
'修改密码': '修改账户密码',
|
|
||||||
'更新个人信息': '更新个人资料',
|
|
||||||
'导出数据': '导出系统数据',
|
|
||||||
'删除数据': '删除系统数据'
|
|
||||||
}
|
|
||||||
return detailMap[row.action] || row.action
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleSearch = () => {
|
|
||||||
emit('load-more', filterForm)
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleReset = () => {
|
|
||||||
filterForm.actionType = ''
|
|
||||||
filterForm.status = ''
|
|
||||||
filterForm.dateRange = []
|
|
||||||
handleSearch()
|
|
||||||
}
|
|
||||||
|
|
||||||
const handlePageChange = (page: number) => {
|
|
||||||
props.logs.page = page
|
|
||||||
emit('load-more')
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleSizeChange = (size: number) => {
|
|
||||||
props.logs.page = 1
|
|
||||||
// 这里需要修改父组件的pageSize,触发重新加载
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleViewDetail = (log: any) => {
|
|
||||||
currentLog.value = log
|
|
||||||
showDetailDialog.value = true
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
|
||||||
.sticky-element {
|
|
||||||
position: sticky;
|
|
||||||
top: 0;
|
|
||||||
z-index: 100;
|
|
||||||
background-color: white;
|
|
||||||
}
|
|
||||||
.sticky-element-bottom {
|
|
||||||
position: sticky;
|
|
||||||
bottom: 0;
|
|
||||||
z-index: 100;
|
|
||||||
background-color: white;
|
|
||||||
}
|
|
||||||
.operation-logs {
|
|
||||||
.log-filters {
|
|
||||||
margin-bottom: 20px;
|
|
||||||
padding: 16px;
|
|
||||||
background: white;
|
|
||||||
border-radius: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.action-cell {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 8px;
|
|
||||||
|
|
||||||
.el-icon {
|
|
||||||
color: var(--el-color-primary);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.log-detail {
|
|
||||||
.location {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 4px;
|
|
||||||
margin-top: 4px;
|
|
||||||
font-size: 12px;
|
|
||||||
color: var(--el-text-color-secondary);
|
|
||||||
|
|
||||||
.el-icon {
|
|
||||||
font-size: 12px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.log-pagination {
|
|
||||||
margin-top: 20px;
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.log-detail-content {
|
|
||||||
.detail-item {
|
|
||||||
display: flex;
|
|
||||||
margin-bottom: 12px;
|
|
||||||
line-height: 1.6;
|
|
||||||
|
|
||||||
.label {
|
|
||||||
width: 100px;
|
|
||||||
color: var(--el-text-color-secondary);
|
|
||||||
flex-shrink: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.value {
|
|
||||||
color: var(--el-text-color-primary);
|
|
||||||
flex: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.details-pre {
|
|
||||||
margin: 0;
|
|
||||||
padding: 8px;
|
|
||||||
background: var(--el-fill-color-light);
|
|
||||||
border-radius: 4px;
|
|
||||||
font-size: 13px;
|
|
||||||
white-space: pre-wrap;
|
|
||||||
word-break: break-all;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@ -2,81 +2,136 @@
|
|||||||
<el-card class="user-info-card">
|
<el-card class="user-info-card">
|
||||||
<template #header>
|
<template #header>
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<span>个人信息</span>
|
<span>账号信息</span>
|
||||||
<el-button
|
|
||||||
type="primary"
|
|
||||||
link
|
|
||||||
icon="Edit"
|
|
||||||
@click="$emit('edit-profile')"
|
|
||||||
>
|
|
||||||
编辑
|
|
||||||
</el-button>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<div class="avatar-section">
|
|
||||||
<el-avatar :size="80" :src="user.avatar" class="user-avatar">
|
|
||||||
{{ user.nickname ? user.nickname.charAt(0) : 'U' }}
|
|
||||||
</el-avatar>
|
|
||||||
<div class="avatar-overlay">
|
|
||||||
<el-icon><Camera /></el-icon>
|
|
||||||
<span>更换头像</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="user-details">
|
<div class="user-details">
|
||||||
<div class="detail-item">
|
<div class="detail-item">
|
||||||
<span class="label">用户名</span>
|
<span class="label">用户名</span>
|
||||||
<span class="value">{{ user.username }}</span>
|
<div v-if="!editing" class="value username-value">
|
||||||
|
<span>{{ user.username || '-' }}</span>
|
||||||
|
<el-button type="primary" link size="small" @click="startEditing">
|
||||||
|
更改
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
<div v-else class="username-editor">
|
||||||
|
<el-input
|
||||||
|
ref="usernameInputRef"
|
||||||
|
v-model="usernameDraft"
|
||||||
|
size="small"
|
||||||
|
placeholder="请输入新账号"
|
||||||
|
maxlength="30"
|
||||||
|
@keyup.enter="submitUsername"
|
||||||
|
@keyup.esc="cancelEditing"
|
||||||
|
/>
|
||||||
|
<el-button type="primary" link size="small" @click="submitUsername">
|
||||||
|
保存
|
||||||
|
</el-button>
|
||||||
|
<el-button link size="small" @click="cancelEditing">
|
||||||
|
取消
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="detail-item">
|
<div class="detail-item">
|
||||||
<span class="label">昵称</span>
|
<span class="label">姓名</span>
|
||||||
<span class="value">{{ user.nickname }}</span>
|
<span class="value">{{ user.real_name || '-' }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="detail-item">
|
<div class="detail-item">
|
||||||
<span class="label">邮箱</span>
|
<span class="label">邮箱</span>
|
||||||
<span class="value">{{ user.email }}</span>
|
<span class="value">{{ user.email || '-' }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="detail-item">
|
<div class="detail-item">
|
||||||
<span class="label">手机</span>
|
<span class="label">手机</span>
|
||||||
<span class="value">{{ user.phone }}</span>
|
<span class="value">{{ user.phone || '-' }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="detail-item">
|
<div class="detail-item">
|
||||||
<span class="label">公司</span>
|
<span class="label">账号状态</span>
|
||||||
<span class="value">{{ user.store_name }}</span>
|
<el-tag :type="user.status === 1 ? 'success' : 'danger'" size="small">
|
||||||
</div>
|
{{ user.status === 1 ? '正常' : '已禁用' }}
|
||||||
<div class="detail-item">
|
</el-tag>
|
||||||
<span class="label">角色</span>
|
|
||||||
<span class="value">{{ user.role_name }}</span>
|
|
||||||
</div>
|
|
||||||
<div class="detail-item">
|
|
||||||
<span class="label">工号</span>
|
|
||||||
<span class="value">{{ user.department }}</span>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="login-info">
|
<div class="login-info">
|
||||||
<el-divider>最近登录</el-divider>
|
<el-divider>时间信息</el-divider>
|
||||||
<div class="login-detail">
|
<div class="login-detail">
|
||||||
<el-icon><Clock /></el-icon>
|
<el-icon><Clock /></el-icon>
|
||||||
<span>{{ user.lastLogin }}</span>
|
<span>最近登录:{{ user.lastLogin || '-' }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="login-detail">
|
<div class="login-detail">
|
||||||
<el-icon><Location /></el-icon>
|
<el-icon><Calendar /></el-icon>
|
||||||
<span>IP: {{ user.loginIp }}</span>
|
<span>注册时间:{{ user.createdAt || '-' }}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</el-card>
|
</el-card>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { Camera, Clock, Location, Edit } from '@element-plus/icons-vue'
|
import { nextTick, ref, watch } from 'vue'
|
||||||
|
import type { InputInstance } from 'element-plus'
|
||||||
|
import { ElMessage } from 'element-plus'
|
||||||
|
import { Calendar, Clock } from '@element-plus/icons-vue'
|
||||||
|
|
||||||
defineProps<{
|
interface CardUser {
|
||||||
user: any
|
username?: string
|
||||||
|
real_name?: string
|
||||||
|
email?: string
|
||||||
|
phone?: string
|
||||||
|
status?: number
|
||||||
|
lastLogin?: string
|
||||||
|
createdAt?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
user: CardUser
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
defineEmits(['edit-profile'])
|
const emit = defineEmits<{
|
||||||
|
(e: 'change-username', username: string): void
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const USERNAME_PATTERN = /^[a-zA-Z0-9_-]{3,30}$/
|
||||||
|
|
||||||
|
const editing = ref(false)
|
||||||
|
const usernameDraft = ref('')
|
||||||
|
const usernameInputRef = ref<InputInstance>()
|
||||||
|
|
||||||
|
const startEditing = async () => {
|
||||||
|
usernameDraft.value = props.user.username || ''
|
||||||
|
editing.value = true
|
||||||
|
await nextTick()
|
||||||
|
usernameInputRef.value?.focus()
|
||||||
|
}
|
||||||
|
|
||||||
|
const cancelEditing = () => {
|
||||||
|
editing.value = false
|
||||||
|
usernameDraft.value = props.user.username || ''
|
||||||
|
}
|
||||||
|
|
||||||
|
const submitUsername = () => {
|
||||||
|
const username = usernameDraft.value.trim()
|
||||||
|
if (!username) {
|
||||||
|
ElMessage.warning('请输入账号')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!USERNAME_PATTERN.test(username)) {
|
||||||
|
ElMessage.warning('账号需为 3-30 位字母、数字、下划线或中划线')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (username === props.user.username) {
|
||||||
|
cancelEditing()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
editing.value = false
|
||||||
|
emit('change-username', username)
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(() => props.user.username, (value) => {
|
||||||
|
if (!editing.value) {
|
||||||
|
usernameDraft.value = value || ''
|
||||||
|
}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
@ -87,50 +142,6 @@ defineEmits(['edit-profile'])
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.avatar-section {
|
|
||||||
position: relative;
|
|
||||||
width: 80px;
|
|
||||||
height: 80px;
|
|
||||||
margin: 0 auto 20px;
|
|
||||||
cursor: pointer;
|
|
||||||
border-radius: 50%;
|
|
||||||
overflow: hidden;
|
|
||||||
|
|
||||||
.user-avatar {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.avatar-overlay {
|
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
background: rgba(0, 0, 0, 0.5);
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
color: white;
|
|
||||||
opacity: 0;
|
|
||||||
transition: opacity 0.3s;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.el-icon {
|
|
||||||
font-size: 20px;
|
|
||||||
margin-bottom: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
span {
|
|
||||||
font-size: 12px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.user-details {
|
.user-details {
|
||||||
.detail-item {
|
.detail-item {
|
||||||
display: flex;
|
display: flex;
|
||||||
@ -152,6 +163,22 @@ defineEmits(['edit-profile'])
|
|||||||
color: var(--el-text-color-primary);
|
color: var(--el-text-color-primary);
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.username-value {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.username-editor {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
|
||||||
|
:deep(.el-input) {
|
||||||
|
width: 140px;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,39 +1,25 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="profile-container">
|
<div class="profile-container">
|
||||||
<!-- 主要内容区 -->
|
<!-- 主要内容区 -->
|
||||||
<div class="profile-content">
|
<div v-loading="profileLoading" class="profile-content">
|
||||||
<!-- 左侧用户信息卡片 -->
|
<!-- 左侧账号信息卡片 -->
|
||||||
<div class="left-sidebar">
|
<div class="left-sidebar">
|
||||||
<UserInfoCard
|
<UserInfoCard
|
||||||
:user="userInfo"
|
:user="userInfo"
|
||||||
@edit-profile="handleEditProfile"
|
@change-username="handleChangeUsername"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<!-- 右侧内容区 -->
|
<!-- 右侧内容区 -->
|
||||||
<div class="right-content">
|
<div class="right-content">
|
||||||
<el-card class="tabs-card">
|
<el-card class="tabs-card">
|
||||||
<el-tabs v-model="activeTab" class="profile-tabs">
|
<el-tabs v-model="activeTab" class="profile-tabs">
|
||||||
<!-- 基本信息 -->
|
|
||||||
<el-tab-pane label="基本信息" name="basic">
|
|
||||||
<BasicInfoForm
|
|
||||||
:user="userInfo"
|
|
||||||
@submit="handleUpdateBasicInfo"
|
|
||||||
/>
|
|
||||||
</el-tab-pane>
|
|
||||||
|
|
||||||
<!-- 账户安全 -->
|
<!-- 账户安全 -->
|
||||||
<el-tab-pane label="账户安全" name="security">
|
<el-tab-pane label="账户安全" name="security">
|
||||||
<AccountSecurity
|
<AccountSecurity
|
||||||
:security-info="securityInfo"
|
:security-info="securityInfo"
|
||||||
|
:has-password="Boolean(userInfo.isCustomPassword)"
|
||||||
@refresh="handleRefreshSecurity"
|
@refresh="handleRefreshSecurity"
|
||||||
/>
|
@change-password="openPasswordDialog"
|
||||||
</el-tab-pane>
|
|
||||||
|
|
||||||
<!-- 操作日志 -->
|
|
||||||
<el-tab-pane label="操作日志" name="logs">
|
|
||||||
<OperationLogs
|
|
||||||
:logs="operationLogs"
|
|
||||||
@load-more="handleLoadMoreLogs"
|
|
||||||
/>
|
/>
|
||||||
</el-tab-pane>
|
</el-tab-pane>
|
||||||
|
|
||||||
@ -51,106 +37,125 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 修改密码对话框 -->
|
<!-- 修改/设置密码对话框 -->
|
||||||
<ChangePasswordDialog
|
<ChangePasswordDialog
|
||||||
v-model="showPasswordDialog"
|
v-model="showPasswordDialog"
|
||||||
|
:first-set="passwordFirstSet"
|
||||||
@success="handlePasswordChangeSuccess"
|
@success="handlePasswordChangeSuccess"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, reactive, onMounted, computed, watch } from 'vue'
|
import { ref, reactive, onMounted, computed } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
|
||||||
import { useUserStore } from '@/stores/modules/user'
|
import { useUserStore } from '@/stores/modules/user'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
|
import dayjs from 'dayjs'
|
||||||
|
import { getAccountInfo, updateUsername } from '@/api/user/user'
|
||||||
|
|
||||||
import UserInfoCard from './components/UserInfoCard.vue'
|
import UserInfoCard from './components/UserInfoCard.vue'
|
||||||
import BasicInfoForm from './components/BasicInfoForm.vue'
|
|
||||||
import AccountSecurity from './components/AccountSecurity.vue'
|
import AccountSecurity from './components/AccountSecurity.vue'
|
||||||
import OperationLogs from './components/OperationLogs.vue'
|
|
||||||
import ChangePasswordDialog from './components/ChangePasswordDialog.vue'
|
import ChangePasswordDialog from './components/ChangePasswordDialog.vue'
|
||||||
import WelcomCard from '../dashboard/components/WelcomCard.vue'
|
import WelcomCard from '../dashboard/components/WelcomCard.vue'
|
||||||
import Bind from './components/Bind.vue'
|
import Bind from './components/Bind.vue'
|
||||||
|
|
||||||
// 引入配置文件
|
// 引入配置文件
|
||||||
import { MOCK_SECURITY_INFO, MOCK_OPERATION_LOGS, PROFILE_TABS } from './profile-config'
|
import { MOCK_SECURITY_INFO, PROFILE_TABS } from './profile-config'
|
||||||
|
|
||||||
|
interface AccountInfo {
|
||||||
|
id?: number
|
||||||
|
username?: string
|
||||||
|
real_name?: string
|
||||||
|
phone?: string
|
||||||
|
email?: string
|
||||||
|
status?: number
|
||||||
|
/** 是否已设置过登录密码(is_custom_password === 1) */
|
||||||
|
isCustomPassword?: boolean
|
||||||
|
lastLogin?: string
|
||||||
|
createdAt?: string
|
||||||
|
}
|
||||||
|
|
||||||
const router = useRouter()
|
|
||||||
const userStore = useUserStore()
|
const userStore = useUserStore()
|
||||||
|
|
||||||
const activeTab = ref<string>(PROFILE_TABS?.[0]?.name ?? 'basic')
|
const activeTab = ref<string>(PROFILE_TABS?.[0]?.name ?? 'security')
|
||||||
const showPasswordDialog = ref(false)
|
const showPasswordDialog = ref(false)
|
||||||
|
|
||||||
// User Info
|
// User Info
|
||||||
const userInfo = ref<any>({})
|
const userInfo = ref<AccountInfo>({})
|
||||||
|
const profileLoading = ref(false)
|
||||||
watch(() => userStore.user, (newVal) => {
|
|
||||||
if (newVal) {
|
|
||||||
userInfo.value = {
|
|
||||||
id: newVal.id,
|
|
||||||
username: newVal.username,
|
|
||||||
nickname: newVal.employees_name || newVal.nickname,
|
|
||||||
avatar: newVal.avatar || 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png',
|
|
||||||
email: newVal.email,
|
|
||||||
phone: newVal.phone,
|
|
||||||
department: newVal.department || '',
|
|
||||||
position: newVal.position,
|
|
||||||
bio: newVal.bio,
|
|
||||||
lastLogin: newVal.last_login_at,
|
|
||||||
store_name: newVal.store_name,
|
|
||||||
role_name: newVal.role_name,
|
|
||||||
loginIp: newVal.loginIp || '127.0.0.1' // fallback
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, { immediate: true, deep: true })
|
|
||||||
|
|
||||||
// Security Info (From Config)
|
// Security Info (From Config)
|
||||||
const securityInfo = reactive({ ...MOCK_SECURITY_INFO })
|
const securityInfo = reactive({ ...MOCK_SECURITY_INFO })
|
||||||
|
|
||||||
// Operation Logs (From Config)
|
const passwordFirstSet = computed(() => !userInfo.value.isCustomPassword)
|
||||||
const operationLogs = reactive({ ...MOCK_OPERATION_LOGS })
|
|
||||||
|
const formatDateTime = (value?: string) => (value ? dayjs(value).format('YYYY-MM-DD HH:mm') : '-')
|
||||||
|
|
||||||
|
const applyAccountInfo = (data: Record<string, unknown>) => {
|
||||||
|
userInfo.value = {
|
||||||
|
id: data.id as number,
|
||||||
|
username: (data.username as string) ?? '',
|
||||||
|
real_name: (data.real_name as string) ?? '',
|
||||||
|
phone: (data.phone as string) ?? '',
|
||||||
|
email: (data.email as string) ?? '',
|
||||||
|
status: data.status === undefined || data.status === null ? undefined : Number(data.status),
|
||||||
|
isCustomPassword: Number(data.is_custom_password) === 1,
|
||||||
|
lastLogin: formatDateTime(data.last_login_at as string | undefined),
|
||||||
|
createdAt: formatDateTime(data.created_at as string | undefined)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const loadAccountInfo = async () => {
|
||||||
|
profileLoading.value = true
|
||||||
|
try {
|
||||||
|
const resp = await getAccountInfo()
|
||||||
|
const payload = resp?.data
|
||||||
|
if (payload && typeof payload === 'object') {
|
||||||
|
applyAccountInfo(payload as Record<string, unknown>)
|
||||||
|
if (userStore.user && payload.username) {
|
||||||
|
userStore.user.username = payload.username
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
} catch {
|
||||||
|
// 错误提示由 request 拦截器统一处理
|
||||||
|
return false
|
||||||
|
} finally {
|
||||||
|
profileLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleChangeUsername = async (username: string) => {
|
||||||
|
const previous = userInfo.value.username
|
||||||
|
userInfo.value = { ...userInfo.value, username }
|
||||||
|
try {
|
||||||
|
await updateUsername({ username })
|
||||||
|
if (userStore.user) {
|
||||||
|
userStore.user.username = username
|
||||||
|
}
|
||||||
|
ElMessage.success('账号修改成功')
|
||||||
|
await loadAccountInfo()
|
||||||
|
} catch {
|
||||||
|
userInfo.value = { ...userInfo.value, username: previous }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const openPasswordDialog = () => {
|
||||||
|
showPasswordDialog.value = true
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
loadOperationLogs()
|
loadAccountInfo()
|
||||||
})
|
})
|
||||||
|
|
||||||
const loadOperationLogs = async () => {
|
const handleRefreshSecurity = async () => {
|
||||||
operationLogs.loading = true
|
if (await loadAccountInfo()) {
|
||||||
setTimeout(() => {
|
ElMessage.success('安全信息已刷新')
|
||||||
operationLogs.loading = false
|
|
||||||
}, 500)
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleEditProfile = () => {
|
|
||||||
activeTab.value = 'basic'
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleUpdateBasicInfo = async (formData: any) => {
|
|
||||||
try {
|
|
||||||
// Simulate API call
|
|
||||||
// await api.updateProfile(formData)
|
|
||||||
ElMessage.success('个人信息更新成功')
|
|
||||||
// Update local store if needed, but usually we reload user info
|
|
||||||
// userStore.getInfo()
|
|
||||||
} catch (error: any) {
|
|
||||||
ElMessage.error('更新失败: ' + error.message)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleRefreshSecurity = () => {
|
const handlePasswordChangeSuccess = async () => {
|
||||||
ElMessage.success('安全信息已刷新')
|
await loadAccountInfo()
|
||||||
}
|
|
||||||
|
|
||||||
const handleLoadMoreLogs = () => {
|
|
||||||
if (operationLogs.page * 10 < operationLogs.total) {
|
|
||||||
// operationLogs.page++ // handled in pagination component
|
|
||||||
loadOperationLogs()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const handlePasswordChangeSuccess = () => {
|
|
||||||
// Logic after password change
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@ -5,26 +5,13 @@
|
|||||||
|
|
||||||
// 1. 标签页配置
|
// 1. 标签页配置
|
||||||
export const PROFILE_TABS = [
|
export const PROFILE_TABS = [
|
||||||
{ label: '基本信息', name: 'basic', component: 'BasicInfoForm' },
|
|
||||||
{ label: '账户安全', name: 'security', component: 'AccountSecurity' },
|
{ label: '账户安全', name: 'security', component: 'AccountSecurity' },
|
||||||
{ label: '操作日志', name: 'logs', component: 'OperationLogs' },
|
|
||||||
{ label: '加入公司', name: 'joinStore', component: 'WelcomCard' },
|
{ label: '加入公司', name: 'joinStore', component: 'WelcomCard' },
|
||||||
{ label: '微信绑定', name: 'bind', component: 'Bind' }
|
{ label: '微信绑定', name: 'bind', component: 'Bind' }
|
||||||
]
|
]
|
||||||
|
|
||||||
// 2. 部门选项配置 (BasicInfoForm 使用)
|
// 2. 账户安全 Mock 数据
|
||||||
export const DEPARTMENT_OPTIONS = [
|
|
||||||
{ label: '技术部', value: '技术部' },
|
|
||||||
{ label: '产品部', value: '产品部' },
|
|
||||||
{ label: '设计部', value: '设计部' },
|
|
||||||
{ label: '市场部', value: '市场部' },
|
|
||||||
{ label: '运营部', value: '运营部' }
|
|
||||||
]
|
|
||||||
|
|
||||||
// 3. 账户安全 Mock 数据
|
|
||||||
export const MOCK_SECURITY_INFO = {
|
export const MOCK_SECURITY_INFO = {
|
||||||
passwordStrength: 'strong',
|
|
||||||
lastPasswordChange: '2023-12-01',
|
|
||||||
twoFactorEnabled: true,
|
twoFactorEnabled: true,
|
||||||
emailVerified: true,
|
emailVerified: true,
|
||||||
phoneVerified: true,
|
phoneVerified: true,
|
||||||
@ -33,17 +20,3 @@ export const MOCK_SECURITY_INFO = {
|
|||||||
{ id: 2, device: 'Safari on iPhone', location: '上海', lastActive: '2024-01-19 09:15', current: false }
|
{ id: 2, device: 'Safari on iPhone', location: '上海', lastActive: '2024-01-19 09:15', current: false }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. 操作日志 Mock 数据
|
|
||||||
export const MOCK_OPERATION_LOGS = {
|
|
||||||
list: [
|
|
||||||
{ id: 1, action: '登录系统', ip: '192.168.1.100', time: '2024-01-20 14:30:22', status: '成功' },
|
|
||||||
{ id: 2, action: '修改密码', ip: '192.168.1.100', time: '2024-01-19 10:15:33', status: '成功' },
|
|
||||||
{ id: 3, action: '更新个人信息', ip: '192.168.1.100', time: '2024-01-18 16:20:45', status: '成功' },
|
|
||||||
{ id: 4, action: '导出数据', ip: '192.168.1.100', time: '2024-01-17 11:05:12', status: '成功' },
|
|
||||||
{ id: 5, action: '登录系统', ip: '192.168.1.101', time: '2024-01-16 09:30:55', status: '失败' }
|
|
||||||
],
|
|
||||||
total: 45,
|
|
||||||
page: 1,
|
|
||||||
loading: false
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user