Commit 028f9f1b1253c2444457de007a9b7b4ca2f40f83
1 parent
898bc1d0
个人头像和昵称的修复
Showing
6 changed files
with
206 additions
and
31 deletions
app.json
packageE/pages/user/nick_avatar/nick_avatar.js
0 → 100644
1 | +// pages/user/userfw/userfw.js | |
2 | +var e = getApp(), os = e.globalData.setting; | |
3 | +var utils = require('../../../../utils/util.js'); | |
4 | +var regeneratorRuntime = require('../../../../utils/runtime.js'); | |
5 | + | |
6 | + | |
7 | +Page({ | |
8 | + /** | |
9 | + * 页面的初始数据 | |
10 | + */ | |
11 | + data: { | |
12 | + defaultAvatar: os.imghost + "/miniapp/images/no-head.jpg", | |
13 | + ob: {}, | |
14 | + load: 0 | |
15 | + }, | |
16 | + | |
17 | + /** | |
18 | + * 生命周期函数--监听页面加载 | |
19 | + */ | |
20 | + onLoad: function (options) { | |
21 | + if(getApp().globalData.up_nick_avatar){ | |
22 | + this.setData({ | |
23 | + ob: JSON.parse(JSON.stringify(getApp().globalData.up_nick_avatar)) | |
24 | + }) | |
25 | + getApp().globalData.up_nick_avatar=null; | |
26 | + } | |
27 | + | |
28 | + }, | |
29 | + /** | |
30 | + * 生命周期函数--监听页面显示 | |
31 | + */ | |
32 | + onShow: async function () { | |
33 | + | |
34 | + }, | |
35 | + | |
36 | + | |
37 | + onChooseAvatar: function (e) { | |
38 | + console.log(e, 1111); | |
39 | + var th = this; | |
40 | + getApp().request.uploadFile(os.url + "/api/weshop/comment/uploadCommentImg", { | |
41 | + filePath: e.detail.avatarUrl, | |
42 | + name: "file", | |
43 | + success: function (t) { | |
44 | + var u = t.data.data; | |
45 | + th.setData({'ob.head_pic': u}) | |
46 | + } | |
47 | + }); | |
48 | + | |
49 | + }, | |
50 | + | |
51 | + get_val: function (e) { | |
52 | + console.log(e, 2222); | |
53 | + this.setData({'ob.nickname': e.detail.value}) | |
54 | + }, | |
55 | + | |
56 | + save_data() { | |
57 | + | |
58 | + if (!this.data.ob.head_pic) { | |
59 | + wx.showToast({ | |
60 | + title: '请选择头像', | |
61 | + icon: 'none', | |
62 | + duration: 2000 | |
63 | + }); | |
64 | + return false; | |
65 | + } | |
66 | + | |
67 | + if (!this.data.ob.nickname) { | |
68 | + wx.showToast({ | |
69 | + title: '请输入昵称', | |
70 | + icon: 'none', | |
71 | + duration: 2000 | |
72 | + }); | |
73 | + return false; | |
74 | + } | |
75 | + | |
76 | + if (this.data.load) return false; | |
77 | + this.setData({load: 1}) | |
78 | + | |
79 | + | |
80 | + wx.showLoading(); | |
81 | + getApp().request.put("/api/weshop/users/update", { | |
82 | + data: { | |
83 | + storeId: os.stoid, | |
84 | + user_id: getApp().globalData.user_id, | |
85 | + nickname: this.data.ob.nickname, | |
86 | + head_pic: this.data.ob.head_pic | |
87 | + | |
88 | + }, | |
89 | + success: function (su) { | |
90 | + wx.hideLoading(); | |
91 | + if (su.data.code == 0) { | |
92 | + wx.navigateBack({delta: 1}) | |
93 | + }else{ | |
94 | + this.setData({load: 0}) | |
95 | + wx.showToast({ | |
96 | + title: su.data.msg, | |
97 | + icon: 'none', | |
98 | + duration: 2000 | |
99 | + }); | |
100 | + } | |
101 | + } | |
102 | + }); | |
103 | + } | |
104 | + | |
105 | + | |
106 | +}) | |
0 | 107 | \ No newline at end of file | ... | ... |
packageE/pages/user/nick_avatar/nick_avatar.json
0 → 100644
packageE/pages/user/nick_avatar/nick_avatar.wxml
0 → 100644
1 | +<view class='page_set'> | |
2 | + <view class="item flex jc_sb ai_c"> | |
3 | + <view>头像</view> | |
4 | + <button open-type='chooseAvatar' bind:chooseavatar="onChooseAvatar" class="avatar_btn"> | |
5 | + <image class="head_img" src="{{ob.head_pic || defaultAvatar}} "></image> | |
6 | + </button> | |
7 | + </view> | |
8 | + | |
9 | + <view class="item flex jc_sb ai_c"> | |
10 | + <view>昵称</view> | |
11 | + <view> | |
12 | + <input class="nick_inp" type="nickname" placeholder="用户昵称" value="{{ob.nickname || ''}}" bindinput="get_val" ></input> | |
13 | + </view> | |
14 | + </view> | |
15 | + | |
16 | + | |
17 | + | |
18 | + <!-- 确认修改按钮 --> | |
19 | + <view class="flex-center confirm"> | |
20 | + <view class="flex-center fs30 confirmtext {{load?'load':''}}" bindtap="save_data"> | |
21 | + <view>确认修改</view> | |
22 | + </view> | |
23 | + </view> | |
24 | + | |
25 | +</view> | |
0 | 26 | \ No newline at end of file | ... | ... |
packageE/pages/user/nick_avatar/nick_avatar.wxss
0 → 100644
1 | +.avatar_btn{ width: 60rpx !important; height: 60rpx !important; border-radius:50%; border: none !important; | |
2 | + margin-left:0 !important;margin-right: 0 !important; } | |
3 | +.head_img{ width: 60rpx; height: 60rpx; border-radius: 50%} | |
4 | + | |
5 | +.page_set{ border-top: 20rpx solid #eee; } | |
6 | +.item{ height: 80rpx; border-bottom: 1rpx solid #eee;padding:0 20rpx} | |
7 | +.nick_inp{ text-align: right; color: #999} | |
8 | + | |
9 | + | |
10 | +.confirm { | |
11 | + width: 100%; | |
12 | + left: 0rpx; | |
13 | + bottom: 0rpx; | |
14 | + height: 130rpx; | |
15 | + background-color: rgb(255, 255, 255); | |
16 | + z-index: 9; | |
17 | + | |
18 | +} | |
19 | + | |
20 | +.confirmtext { | |
21 | + width: 495rpx; | |
22 | + height: 65rpx; | |
23 | + color: rgb(255, 255, 255); | |
24 | + background-color: rgb(214, 1, 33); | |
25 | + border-radius: 35rpx; | |
26 | +} | |
27 | + | |
28 | +.load{ | |
29 | + background-color:#ea3993 !important; | |
30 | +} | |
0 | 31 | \ No newline at end of file | ... | ... |
pages/user/userinfo/userinfo.js
... | ... | @@ -658,37 +658,46 @@ Page({ |
658 | 658 | // 获取用户头像昵称 |
659 | 659 | getUserProfile(e) { |
660 | 660 | var th = this; |
661 | - new Promise((resolve, reject) => { | |
662 | - wx.getUserProfile({ | |
663 | - desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 | |
664 | - success: (res) => { | |
665 | - th.data.user.nickname = res.userInfo.nickName; | |
666 | - th.data.user.head_pic = res.userInfo.avatarUrl; | |
667 | - this.setData({ | |
668 | - userInfo: res.userInfo, | |
669 | - hasUserInfo: true, | |
670 | - user: th.data.user, | |
671 | - }); | |
672 | - resolve(res.userInfo); | |
673 | - }, | |
674 | 661 | |
675 | - }); | |
676 | - }).then((userInfo) => { | |
677 | - getApp().request.put("/api/weshop/users/update", { | |
678 | - data: { | |
679 | - storeId: r.stoid, | |
680 | - user_id: getApp().globalData.user_id, | |
681 | - nickname: userInfo.nickName, | |
682 | - head_pic: userInfo.avatarUrl | |
683 | - | |
684 | - }, | |
685 | - success: function(su) { | |
686 | - if (su.data.code == 0) { | |
687 | - console.log("update user info OK"); | |
688 | - } | |
689 | - } | |
690 | - }); | |
691 | - }); | |
662 | + var ob={ | |
663 | + nickname:this.data.user.nickname, | |
664 | + head_pic:this.data.user.head_pic, | |
665 | + } | |
666 | + getApp().globalData.up_nick_avatar=ob; | |
667 | + getApp().goto('/packageE/pages/user/nick_avatar/nick_avatar'); | |
668 | + | |
669 | + | |
670 | + // new Promise((resolve, reject) => { | |
671 | + // wx.getUserProfile({ | |
672 | + // desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 | |
673 | + // success: (res) => { | |
674 | + // th.data.user.nickname = res.userInfo.nickName; | |
675 | + // th.data.user.head_pic = res.userInfo.avatarUrl; | |
676 | + // this.setData({ | |
677 | + // userInfo: res.userInfo, | |
678 | + // hasUserInfo: true, | |
679 | + // user: th.data.user, | |
680 | + // }); | |
681 | + // resolve(res.userInfo); | |
682 | + // }, | |
683 | + // | |
684 | + // }); | |
685 | + // }).then((userInfo) => { | |
686 | + // getApp().request.put("/api/weshop/users/update", { | |
687 | + // data: { | |
688 | + // storeId: r.stoid, | |
689 | + // user_id: getApp().globalData.user_id, | |
690 | + // nickname: userInfo.nickName, | |
691 | + // head_pic: userInfo.avatarUrl | |
692 | + // | |
693 | + // }, | |
694 | + // success: function(su) { | |
695 | + // if (su.data.code == 0) { | |
696 | + // console.log("update user info OK"); | |
697 | + // } | |
698 | + // } | |
699 | + // }); | |
700 | + // }); | |
692 | 701 | |
693 | 702 | |
694 | 703 | }, | ... | ... |