Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a3e95b56
authored
Feb 17, 2024
by
dhb52
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 用户头像、昵称修改
parent
2f37232f
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
36 additions
and
18 deletions
+36
-18
src/assets/imgs/avatar.jpg
+0
-0
src/components/Cropper/src/CropperAvatar.vue
+1
-1
src/layout/components/UserInfo/src/UserInfo.vue
+9
-15
src/store/modules/user.ts
+14
-0
src/views/Profile/components/BasicInfo.vue
+5
-1
src/views/Profile/components/UserAvatar.vue
+7
-1
No files found.
src/assets/imgs/avatar.jpg
deleted
100644 → 0
View file @
2f37232f
6.12 KB
src/components/Cropper/src/CropperAvatar.vue
View file @
a3e95b56
...
@@ -18,7 +18,7 @@ import { useDesign } from '@/hooks/web/useDesign'
...
@@ -18,7 +18,7 @@ import { useDesign } from '@/hooks/web/useDesign'
import
{
propTypes
}
from
'@/utils/propTypes'
import
{
propTypes
}
from
'@/utils/propTypes'
import
{
useI18n
}
from
'vue-i18n'
import
{
useI18n
}
from
'vue-i18n'
import
CopperModal
from
'./CopperModal.vue'
import
CopperModal
from
'./CopperModal.vue'
import
avatar
from
'@/assets/imgs/avatar.
jpg
'
import
avatar
from
'@/assets/imgs/avatar.
gif
'
defineOptions
({
name
:
'CropperAvatar'
})
defineOptions
({
name
:
'CropperAvatar'
})
...
...
src/layout/components/UserInfo/src/UserInfo.vue
View file @
a3e95b56
<
script
lang=
"ts"
setup
>
<
script
lang=
"ts"
setup
>
import
{
ElMessageBox
}
from
'element-plus'
import
{
ElMessageBox
}
from
'element-plus'
import
{
CACHE_KEY
,
useCache
}
from
'@/hooks/web/useCache'
import
{
useDesign
}
from
'@/hooks/web/useDesign'
import
avatarImg
from
'@/assets/imgs/avatar.gif'
import
avatarImg
from
'@/assets/imgs/avatar.gif'
import
{
use
UserStore
}
from
'@/store/modules/user
'
import
{
use
Design
}
from
'@/hooks/web/useDesign
'
import
{
useTagsViewStore
}
from
'@/store/modules/tagsView'
import
{
useTagsViewStore
}
from
'@/store/modules/tagsView'
import
{
useUserStore
}
from
'@/store/modules/user'
defineOptions
({
name
:
'UserInfo'
})
defineOptions
({
name
:
'UserInfo'
})
const
{
t
}
=
useI18n
()
const
{
t
}
=
useI18n
()
const
{
wsCache
}
=
useCache
()
const
{
push
,
replace
}
=
useRouter
()
const
{
push
,
replace
}
=
useRouter
()
const
userStore
=
useUserStore
()
const
userStore
=
useUserStore
()
...
@@ -23,24 +20,21 @@ const { getPrefixCls } = useDesign()
...
@@ -23,24 +20,21 @@ const { getPrefixCls } = useDesign()
const
prefixCls
=
getPrefixCls
(
'user-info'
)
const
prefixCls
=
getPrefixCls
(
'user-info'
)
const
user
=
wsCache
.
get
(
CACHE_KEY
.
USER
)
const
avatar
=
computed
(()
=>
userStore
.
user
.
avatar
??
avatarImg
)
const
userName
=
computed
(()
=>
userStore
.
user
.
nickname
??
'Admin'
)
const
avatar
=
user
.
user
.
avatar
?
user
.
user
.
avatar
:
avatarImg
const
userName
=
user
.
user
.
nickname
?
user
.
user
.
nickname
:
'Admin'
const
loginOut
=
async
()
=>
{
try
{
const
loginOut
=
()
=>
{
await
ElMessageBox
.
confirm
(
t
(
'common.loginOutMessage'
),
t
(
'common.reminder'
),
{
ElMessageBox
.
confirm
(
t
(
'common.loginOutMessage'
),
t
(
'common.reminder'
),
{
confirmButtonText
:
t
(
'common.ok'
),
confirmButtonText
:
t
(
'common.ok'
),
cancelButtonText
:
t
(
'common.cancel'
),
cancelButtonText
:
t
(
'common.cancel'
),
type
:
'warning'
type
:
'warning'
})
})
.
then
(
async
()
=>
{
await
userStore
.
loginOut
()
await
userStore
.
loginOut
()
tagsViewStore
.
delAllViews
()
tagsViewStore
.
delAllViews
()
replace
(
'/login?redirect=/index'
)
replace
(
'/login?redirect=/index'
)
})
}
.
catch
(()
=>
{})
catch
{
}
}
}
const
toProfile
=
async
()
=>
{
const
toProfile
=
async
()
=>
{
push
(
'/user/profile'
)
push
(
'/user/profile'
)
...
...
src/store/modules/user.ts
View file @
a3e95b56
...
@@ -63,6 +63,20 @@ export const useUserStore = defineStore('admin-user', {
...
@@ -63,6 +63,20 @@ export const useUserStore = defineStore('admin-user', {
wsCache
.
set
(
CACHE_KEY
.
USER
,
userInfo
)
wsCache
.
set
(
CACHE_KEY
.
USER
,
userInfo
)
wsCache
.
set
(
CACHE_KEY
.
ROLE_ROUTERS
,
userInfo
.
menus
)
wsCache
.
set
(
CACHE_KEY
.
ROLE_ROUTERS
,
userInfo
.
menus
)
},
},
async
setUserAvatarAction
(
avatar
:
string
)
{
const
userInfo
=
wsCache
.
get
(
CACHE_KEY
.
USER
)
// NOTE: 是否需要像`setUserInfoAction`一样判断`userInfo != null`
this
.
user
.
avatar
=
avatar
userInfo
.
user
.
avatar
=
avatar
wsCache
.
set
(
CACHE_KEY
.
USER
,
userInfo
)
},
async
setUserNicknameAction
(
nickname
:
string
)
{
const
userInfo
=
wsCache
.
get
(
CACHE_KEY
.
USER
)
// NOTE: 是否需要像`setUserInfoAction`一样判断`userInfo != null`
this
.
user
.
nickname
=
nickname
userInfo
.
user
.
nickname
=
nickname
wsCache
.
set
(
CACHE_KEY
.
USER
,
userInfo
)
},
async
loginOut
()
{
async
loginOut
()
{
await
loginOut
()
await
loginOut
()
removeToken
()
removeToken
()
...
...
src/views/Profile/components/BasicInfo.vue
View file @
a3e95b56
...
@@ -21,11 +21,13 @@ import {
...
@@ -21,11 +21,13 @@ import {
updateUserProfile
,
updateUserProfile
,
UserProfileUpdateReqVO
UserProfileUpdateReqVO
}
from
'@/api/system/user/profile'
}
from
'@/api/system/user/profile'
import
{
useUserStore
}
from
'@/store/modules/user'
defineOptions
({
name
:
'BasicInfo'
})
defineOptions
({
name
:
'BasicInfo'
})
const
{
t
}
=
useI18n
()
const
{
t
}
=
useI18n
()
const
message
=
useMessage
()
// 消息弹窗
const
message
=
useMessage
()
// 消息弹窗
const
userStore
=
useUserStore
()
// 表单校验
// 表单校验
const
rules
=
reactive
<
FormRules
>
({
const
rules
=
reactive
<
FormRules
>
({
nickname
:
[{
required
:
true
,
message
:
t
(
'profile.rules.nickname'
),
trigger
:
'blur'
}],
nickname
:
[{
required
:
true
,
message
:
t
(
'profile.rules.nickname'
),
trigger
:
'blur'
}],
...
@@ -78,13 +80,15 @@ const submit = () => {
...
@@ -78,13 +80,15 @@ const submit = () => {
const
data
=
unref
(
formRef
)?.
formModel
as
UserProfileUpdateReqVO
const
data
=
unref
(
formRef
)?.
formModel
as
UserProfileUpdateReqVO
await
updateUserProfile
(
data
)
await
updateUserProfile
(
data
)
message
.
success
(
t
(
'common.updateSuccess'
))
message
.
success
(
t
(
'common.updateSuccess'
))
await
init
()
const
profile
=
await
init
()
userStore
.
setUserNicknameAction
(
profile
.
nickname
)
}
}
})
})
}
}
const
init
=
async
()
=>
{
const
init
=
async
()
=>
{
const
res
=
await
getUserProfile
()
const
res
=
await
getUserProfile
()
unref
(
formRef
)?.
setValues
(
res
)
unref
(
formRef
)?.
setValues
(
res
)
return
res
}
}
onMounted
(
async
()
=>
{
onMounted
(
async
()
=>
{
await
init
()
await
init
()
...
...
src/views/Profile/components/UserAvatar.vue
View file @
a3e95b56
...
@@ -14,6 +14,8 @@
...
@@ -14,6 +14,8 @@
import
{
propTypes
}
from
'@/utils/propTypes'
import
{
propTypes
}
from
'@/utils/propTypes'
import
{
uploadAvatar
}
from
'@/api/system/user/profile'
import
{
uploadAvatar
}
from
'@/api/system/user/profile'
import
{
CropperAvatar
}
from
'@/components/Cropper'
import
{
CropperAvatar
}
from
'@/components/Cropper'
import
{
useUserStore
}
from
'@/store/modules/user'
defineOptions
({
name
:
'UserAvatar'
})
defineOptions
({
name
:
'UserAvatar'
})
...
@@ -21,10 +23,14 @@ defineProps({
...
@@ -21,10 +23,14 @@ defineProps({
img
:
propTypes
.
string
.
def
(
''
)
img
:
propTypes
.
string
.
def
(
''
)
})
})
const
userStore
=
useUserStore
()
const
cropperRef
=
ref
()
const
cropperRef
=
ref
()
const
handelUpload
=
async
({
data
})
=>
{
const
handelUpload
=
async
({
data
})
=>
{
await
uploadAvatar
({
avatarFile
:
data
})
const
res
=
await
uploadAvatar
({
avatarFile
:
data
})
cropperRef
.
value
.
close
()
cropperRef
.
value
.
close
()
userStore
.
setUserAvatarAction
(
res
.
data
)
}
}
</
script
>
</
script
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment