赞
踩
最新发布的微信小程序已经无法获取头像和昵称,那么如何解决这个问题呢?
其实很简单,新用户注册后,提示跳转到新页面,要求修改昵称和头像即可。
- <import src="../temp.wxml"></import>
- <template is="nav_top" data="{{nav}}"></template>
-
- <view class="main_top" style="padding-top: {{nav.top+nav.safe_top+15}}px;"></view>
-
- <view class="warn">{{info.warn}}</view>
-
- <view class="box">
- <view class="logo">
- <view><view class="image" style="background: url({{user.logo}}) no-repeat center;background-size: cover;" ></view><text class="icon icon-bianji"></text>
- <button open-type="chooseAvatar" bindchooseavatar="save_logo"></button>
- </view>
-
- </view>
-
- <view class="l">
- <input type="nickname" placeholder="我的昵称" value="{{user.nickname}}" data-val="{{user.nickname}}" bindblur="val_change" data-c="nickname"></input>
- </view>
-
-
- <view class="l">
- <text>联系电话</text>
- <input placeholder="联系电话" value="{{user.phone}}" data-val="{{user.phone}}" bindblur="val_change" data-c="phone" style="text-align: left;font-size: 17px;" disabled="true"></input>
- <text style="position: absolute;right: 0;left:auto;color: #00a47c;">获取电话
- </text>
- <button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber" style="position: absolute;height: 40px;width:60px;z-index: 100;opacity:0;right: 0;top: 0;" ></button>
- </view>
- <view class="l" style="padding-right: 0;"><text>所在城市</text>
- <picker mode="region" value="{{region?region:''}}" bindchange="region_change" class="region">
- <view>{{user.dist?(user.dist):'未选择默认城市'}}
- <text class="icon icon-chevron-right"></text>
- </view>
- </picker>
- </view>
-
- </view>
-
-
- var app = getApp()
- var fun = require('../fun.js');
- Page({
- data: {
- nav:{top:app.globalData.nav_top,title:'我的信息',home:'show',back:'show',safe_top:app.globalData.safe_top,page:'my',no_data:'您还没有购买记录'},page:1,can_load:1,
- },
-
- onLoad(op) {
-
- },
-
- onReady() {
- this.load();
- var pages=getCurrentPages();
- this.setData({page_num:Object.keys(pages).length})
- },
-
-
- onShow() {
- if(app.globalData.flash==1){this.load();app.globalData.flash=0;}
- },
-
- load() {
- fun.get({ac:'get_my_info'}).then(res=>{
- var region;
- if(res.user.pro){
- region=[res.user.pro,res.user.city,res.user.dist]
- }
- this.setData({user:res.user,info:res.info,set:res.set,region:region})
- })
- },
- save_logo(e){
- console.log(e)
- var user=this.data.user;
- var save_data=this.data.save_data;if(!save_data){save_data={}}
- var that=this;
- var url=e.detail.avatarUrl;
- user.logo=url;
- //that.setData({user:user});
- wx.showLoading({
- title: '头像上传中,请稍后...',
- })
- setTimeout(function(){wx.hideLoading()},1500)
- var data={tempFilePath:url,size:0,c:'logo',}
- fun.upload(data).then(res=>{
- user.logo=res.img_240;
- that.setData({user:user});
- save_data.logo=res.img_240;
- that.data.save_data=save_data;
- that.save()
-
- })
-
- },
-
- save() {
- var save_data=this.data.save_data;
- if(!save_data){return;}
- if(Object.keys(save_data).length==0){return}
- fun.get({ac:'user_change',data:JSON.stringify(save_data)}).then(res=>{
- wx.hideLoading();
- this.data.save_data={}
- app.msg('保存成功');
- this.load();
- app.globalData.flash=1;
- })
- },
- val_change(e){
- var val=e.detail.value;
- var c=e.currentTarget.dataset.c;
- var save_data=this.data.save_data;if(!save_data){save_data={}}
- save_data[[c]]=val;
- this.data.save_data=save_data;
- this.save()
- },
- region_change(e){
- var region=e.detail.value;
- if(!app.globalData.region){
- app.globalData.region=region;
- try {
- wx.setStorageSync('region',region);
- } catch (e) { }
- }
- if(!app.globalData.area){
- app.globalData.area=region[2];
- try {
- wx.setStorageSync('area',region[2]);
- } catch (e) { }
- }
-
- var save_data=this.data.save_data;
- if(!save_data){save_data={}}
- save_data['pro']=region[0];save_data['city']=region[1];save_data['dist']=region[2];
- this.data.save_data=save_data;
- this.save();
-
- },
-
-
- getPhoneNumber(e){
- console.log('获取手机号',e.detail.errMsg,e.detail);
- var user=this.data.user;
- if(e.detail.errMsg=='getPhoneNumber:fail user deny'){
- this.back();return;
- }else{
- fun.get({ac:'get_phone',code:e.detail.code}).then(res=>{
- //获取成功后 则缓存状态
- if(res.phone){
- user.phone=res.phone;
- this.setData({user:user});
- var save_data=this.data.save_data;if(!save_data){save_data={}}
- save_data.phone=res.phone;
- this.data.save_data=save_data;
- this.save();
- }
- })
- }
- //this.back();
- },
-
-
- onReachBottom() {
-
- },
-
-
- onShareAppMessage() {
-
- },go(e){ wx.navigateTo({url: e.currentTarget.dataset.url})},
- back(e){var page_num=this.data.page_num;
- if(page_num==1){this.home();}else{wx.navigateBack({delta:1})}},
- home(e){ wx.reLaunch({url: '/pages/index/index'})},
- rgo(e){wx.redirectTo({url: e.currentTarget.dataset.url})},
- login: function (e) {wx.navigateTo({url: '/pages/login/index',})},
- win_open(e){var c=e.currentTarget.dataset.c;this.setData({[c]:'show'})},//打开窗口
- win_close(e){var c=e.currentTarget.dataset.c;this.setData({[c]:''})},//关闭窗口
- })
- .main_top{float: left;width: 100%;background: #fff;}
- .warn{float: left;width: 100%;padding: 10px;color: crimson;background: rgb(250, 218, 225);}
- page{background: #fff;}
- .box{float: left;width: 100%;background: #fff;padding:15px;margin-top: 15px;}
-
- .logo{float: left;width: 100%;display: flex;justify-content: center;}
- .logo view{float: left;width:80px;height: 80px;}
- .logo .image{float: left;width: 100%;height: 100%;border-radius: 50%;border: 5px solid #ccc;}
- .logo text{position: absolute;top:0px;right: 0px;background: #fff;width:24px;height: 24px;border-radius: 50%;font-size: 12px;text-align: center;line-height:18px;border:3px solid #eee;}
- .logo button{position: absolute;width:100%;height: 100%;z-index: 100;opacity: 0;}
-
- .l{float: left;width: 100%;margin-top:20px;padding-left:80px;padding-right:80px;font-size: 18px;}
- .l input{float: left;width: 100%;height: 40px;line-height: 40px;font-size: 20px;text-align: center;}
- .l text{position: absolute;left:0;height: 40px;line-height: 40px;}
- .l .region{float: left;width: 100%;height: 40px;line-height: 40px;padding-right: 30px;text-align: right;}
- .l .icon{right: 0;left: auto;font-size: 30px;}
- .l .region view{float: left;width: 100%;padding-right: 30px;}
-
本代码为原生代码,提供思路与解决办法,后端请自行编写.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。