全部
常见问题
产品动态
精选推荐

CRMEB开源打通版/标准版v4电商商城系统小程序头像和昵称授权获取不到问题(v4.6一下版本)

管理 管理 编辑 删除

小程序文档中提出的调整说明

attachmentId-21541

attachmentId-21548

对于此次调整现将小程序授权方式做以调整

  1. 添加判断当前基础库是否支持头像昵称填写能力

在根目录App.vue中加入判断基础库是否大于2.21.2版本(大于此版本支持头像/昵称填写能力)

···
// #ifdef MP
  const version = uni.getSystemInfoSync().SDKVersion
  if (Routine.compareVersion(version, '2.21.3') >= 0) {
    console.log(version)
    that.$Cache.set('MP_VERSION_ISNEW', true)
  } else {
    that.$Cache.set('MP_VERSION_ISNEW', false)
  }
// #endif

2.修改/pages/users/wechat_login.vue文件

(1) 在data中加入基础库判断,决定授权逻辑
mp_is_new: this.$Cache.get('MP_VERSION_ISNEW') || false

(2)dom中新增逻辑判断


  {{$t(`微信登录`)}}
  {{$t(`微信登录`)}}
  {{$t(`微信登录`)}}

(3)methods中加入方法userLogin

// 小程序 22.11.8日删除getUserProfile 接口获取用户昵称头像
userLogin() {
  Routine.getCode()
    .then(code => {
      uni.showLoading({
      title: this.$t(`正在登录中`)
    });
  authLogin({
    code,
    spread_spid: app.globalData.spid,
    spread_code: app.globalData.code
    }).then(res => {
      if (res.data.key !== undefined && res.data.key) {
        uni.hideLoading();
        this.authKey = res.data.key;
        this.isPhoneBox = true;
      } else {
        uni.hideLoading();
        let time = res.data.expires_time - this.$Cache.time();
        this.$store.commit('LOGIN', {
        token: res.data.token,
        time: time
        });
        this.getUserInfo()
      }
    })
  })
  .catch(err => {
    console.log(err)
  });
},

3.新增用户头像/昵称获取能力
(1)调整pages/users/user_info.vue文件
data中新增 mp_is_new: this.$Cache.get('MP_VERSION_ISNEW') || false

(2)调整dom中



  {{$t(`头像`)}}
  
    
  
  
    
  


  {{$t(`昵称`)}}
  
  

(3)methods中加入方法

onChooseAvatar(e) {
  const {
    avatarUrl
  } = e.detail
  this.$util.uploadImgs('upload/image', avatarUrl, (res) => {
    this.userInfo.avatar = res.data.url
  }, (err) => {
    console.log(err)
  })
},

这里有一个公共方法uploadImgs需要在/utils/util.js中添加



uploadImgs(uploadUrl, filePath, successCallback, errorCallback) {
  let that = this;
  uni.uploadFile({
    url: HTTP_REQUEST_URL + '/api/' + uploadUrl,
    filePath: filePath,
    fileType: 'image',
    name: 'pics',
    formData: {
      'filename': 'pics'
    },
    header: {
    // #ifdef MP
    "Content-Type": "multipart/form-data",
    // #endif
    [TOKENNAME]: 'Bearer ' + store.state.app.token
  },
  success: (res) => {
  uni.hideLoading();
  if (res.statusCode == 403) {
    that.Tips({
      title: res.data
    });
  } else {
    let data = res.data ? JSON.parse(res.data) : {};
    if (data.status == 200) {
      successCallback && successCallback(data)
    } else {
      errorCallback && errorCallback(data);
        that.Tips({
          title: data.msg
        });
      }
    }
  },
  fail: (err) => {
    uni.hideLoading();
    that.Tips({
      title: i18n.t(`上传图片失败`)
      });
    }
  })
},

以上就是本次调整的所有内容了!

具体源码可以查看 https://gitee.com/ZhongBangKeJi/CRMEB/tree/master/template/uni-app

同时希望大家给个免费的 star 喔~ 比心



刘松林 最后编辑于2022-12-15 15:15:00

快捷回复
回复({{post_count}}) {{!is_user ? '我的回复' :'全部回复'}}
回复从新到旧

{{item.user_info.nickname ? item.user_info.nickname : item.user_name}}

作者 管理员 企业

{{item.floor}}# 同步到gitee 已同步到gitee {{item.is_suggest==1? '取消推荐': '推荐'}}
{{item.floor}}#
{{item.user_info.title}}
附件

{{itemf.name}}

{{item.created_at}}  {{item.ip_address}}
{{item.like_count}}
{{item.showReply ? '取消回复' : '回复'}}
删除
回复
回复

{{itemc.user_info.nickname}}

{{itemc.user_name}}

作者 管理员 企业

回复 {{itemc.comment_user_info.nickname}}

附件

{{itemf.name}}

{{itemc.created_at}}   {{itemc.ip_address}}
{{itemc.like_count}}
{{itemc.showReply ? '取消回复' : '回复'}}
删除
回复
回复
查看更多
回复
回复
3328
{{like_count}}
{{collect_count}}
添加回复 ({{post_count}})

相关推荐

CRMEB-慕白寒窗雪 作者
社区运营专员---高冷のBoy | 呆萌のGirl

回答

1919

发布

1766

经验

43235

快速安全登录

使用微信扫码登录
{{item.label}} {{item.label}} {{item.label}} 板块推荐 常见问题 产品动态 精选推荐 首页头条 首页动态 首页推荐
加精
取 消 确 定
回复
回复
问题:
问题自动获取的帖子内容,不准确时需要手动修改. [获取答案]
答案:
提交
bug 需求 取 消 确 定

微信登录/注册

切换手机号登录

{{ bind_phone ? '绑定手机' : '手机登录'}}

{{codeText}}
切换微信登录/注册
暂不绑定
CRMEB客服

CRMEB咨询热线 咨询热线

400-8888-794

微信扫码咨询

CRMEB开源商城下载 开源下载 CRMEB官方论坛 帮助文档
返回顶部 返回顶部
CRMEB客服