修复上传头像问题

master
toesbieya 6 years ago
parent 790d3e76fb
commit e1a3d536c3
  1. 2
      vue/src/api/system/user.js
  2. 10
      vue/src/assets/styles/index.scss
  3. 2
      vue/src/utils/file.js
  4. 13
      vue/src/views/system/user/index.vue
  5. 10
      vue/src/views/userCenter/components/Avatar.vue

@ -39,7 +39,7 @@ export function updateUserPwd(data) {
}
export function updateAvatar(key) {
return request.get(baseUrl + '/updateAvatar?key=' + encodeURIComponent(key)).then(({data}) => data)
return request.get(baseUrl + '/updateAvatar?key=' + encodeURIComponent(key)).then(({data}) => ({...data, key}))
}
export function validate(pwd) {

@ -96,6 +96,16 @@ a:hover {
margin-top: 10px;
}
.table-image {
cursor: pointer;
display: inline-block;
height: 32px;
width: 32px;
border-radius: 50%;
vertical-align: middle;
overflow: hidden;
}
.card-container {
position: relative;

@ -41,7 +41,7 @@ export function upload(blob, filename = '快照.png') {
param.append('file', blob, filename)
return request.post(attachmentUploadUrl, param, {...formConfig, baseUrl: ''})
})
.then(data => data.key)
.then(({data}) => data.key)
}
//自动补全附件链接前缀

@ -44,9 +44,13 @@
>
<el-table-column align="center" label="#" type="index" width="80"/>
<el-table-column align="center" label="头像" width="100">
<template v-slot="{row}">
<el-avatar :size="40" :src="row.avatar" v-if="row.avatar"/>
</template>
<img
slot-scope="{row}"
v-if="row.avatar"
:src="row.avatar"
class="table-image"
@click.stop="previewAvatar(row.avatar)"
>
</el-table-column>
<el-table-column align="center" label="用户名" prop="name" show-overflow-tooltip/>
<el-table-column align="center" label="角 色" prop="role_name" show-overflow-tooltip/>
@ -206,6 +210,9 @@
elSuccess(msg)
this.editDialog = false
this.search()
},
previewAvatar(src) {
this.$image({index: 0, urlList: [src]})
}
}
}

@ -78,15 +78,11 @@
if (!this.img) return elError('请先上传图片')
if (this.loading) return
this.loading = true
let url
this.$refs.cropper.getCropBlob(data => {
upload(new Blob([data]), this.name)
.then(key => {
url = key
return updateAvatar(key)
})
.then(({msg}) => {
this.$store.commit('user/SET_AVATAR', autoCompleteUrl(url))
.then(key => updateAvatar(key))
.then(({key, msg}) => {
this.$store.commit('user/SET_AVATAR', autoCompleteUrl(key))
this.$store.dispatch('user/refresh')
elSuccess(msg)
})

Loading…
Cancel
Save