66 <span class =" text-sm text-describe" >从你的设备上选取一张 JPG 或 PNG 图片作为新的头像。</span >
77 <div class =" item-content d-flex flex-ai" >
88 <v-avatar size =" 150" color =" primary" >
9- <img :src =" imgUrl" v-if =" form.avatar || imgBgc " />
9+ <img :src =" imgUrl" v-if =" form.avatar" />
1010 <span class =" white--text text-h3" v-else >{{form.nickname|preNickname}}</span >
1111 </v-avatar >
1212 <v-btn color =" info" class =" upload-btn" >
1313 <a @change =" chooseFile" class =" upload-a" href =" javascript:;" >
1414 <input class =" upload-input" ref =" fileInput" type =" file" accept =" image/png,image/jpg,image/jpeg"
15- multiple =" multiple" />
16- 上传头像
15+ multiple =" multiple" />上传头像
1716 </a >
1817 </v-btn >
1918 </div >
5453import { mapState , mapMutations } from ' vuex'
5554import regexpList from ' @utils/regexp'
5655import Cropper from ' @components/cropper'
57- import { getImgMainColor } from ' @utils/tools'
5856import cookie from ' @utils/cookie'
5957import * as qiNiu from ' @utils/qiNiu'
6058import { qiNiuImgLink } from ' @utils/publicData'
@@ -63,7 +61,6 @@ export default {
6361 return {
6462 qiNiuImgLink,
6563 imgUrl: ' ' ,
66- imgBgc: ' ' ,
6764 form: {
6865 avatar: ' ' ,
6966 nickname: ' ' ,
@@ -162,10 +159,6 @@ export default {
162159 this .imgUrl = image
163160 this .cropConf .cropUrl = ' '
164161 this .cropDialogVisible = false
165- // 获取图片主色调
166- getImgMainColor (image).then ((res ) => {
167- this .imgBgc = res
168- })
169162 },
170163 closeCrop () {
171164 this .clearInputFiles ()
@@ -190,17 +183,23 @@ export default {
190183 contactEmail: email,
191184 name: nickname,
192185 userPicture: imgKey || avatar,
193- backgroundColor : this . imgBgc ,
186+ oldImg : imgKey ? avatar : ' ' ,
194187 }
195188 const res = await this .$http .updateUserInfo (userInfo)
196189 if (res .state ) {
197190 this .$message .success (' 个人设置保存成功!' )
198191 // 用户信息更新成功之后更新前端数据
199- this .setCurUserDetail ({ nickname, about, email, avatar: imgKey })
200- this .setLoginInfoItem ({ key: ' avatar' , val: imgKey })
201- this .form .avatar = imgKey
202- this .imgUrl = qiNiuImgLink + imgKey
203- this .imgBgc = ' '
192+ this .setCurUserDetail ({
193+ nickname,
194+ about,
195+ email,
196+ avatar: imgKey,
197+ })
198+ if (imgKey) {
199+ this .setLoginInfoItem ({ key: ' avatar' , val: imgKey })
200+ this .form .avatar = imgKey
201+ imgKey && (this .imgUrl = qiNiuImgLink + imgKey)
202+ }
204203 }
205204 } catch (err) {
206205 console .log (err)
@@ -209,8 +208,9 @@ export default {
209208 this .loading = false
210209 },
211210 async uploadAvatar () {
212- // 通过imgBgc判断用户有没有上传新头像,如果没有就没必要上传了
213- if (! this .imgBgc ) return void 0
211+ // 如果imgUrl既不是空也不是http开头,说明换了新头像
212+ const imgUrl = this .imgUrl
213+ if (imgUrl === ' ' || / ^ http/ .test (imgUrl)) return void 0
214214 let token = cookie .get (' QI_NIU_TOKEN' )
215215 // 如果没有token需要获取七牛云token
216216 if (! token) {
0 commit comments