【微信小程序】上传头像 微信小程序内接小程序客服

这里写目录标题

微信小程序上传头像

使用button按钮包裹img

原本思路是只使用image标签再加上chooseImg,但发现使用button标签上传头像这种方法更实用。微信小程序文档上,button的 open-type 功能有很多

xml 复制代码
  <button
      style="border-radius: 50%;"
      open-type="chooseAvatar"
      bindchooseavatar="getPropertyPortrait"
  >
   <image style="margin: 0rpx;" src="{{headimg?headimg:'https://ys.zye.com/upload/touxiang.png' }}"></image>
  </button>
javascript 复制代码
  // 上传头像
  
  getPropertyPortrait(e){
    var that = this;
    var image =  e.detail.avatarUrl;
    // 调用上传函数
    imageUpload.uploadImage('/api/upload/headimg', image, 'file', {}).then((response) => {
      console.log('上传成功', response);
      that.setData({
        headimg: 'https://ys.zye.com' + response.data.pic_path
      })
      //上传之后在调用修改头像函数
      that.updePropertyPortrait('https://ys.zye.com' + response.data.pic_path);
    })
        .catch((error) => {
          console.error('上传失败', error);
          toast.showError(error.errMsg);
        });

  },
  // 修改头像
  updePropertyPortrait(pic_path){
    var that = this;
    var data = {
      token:app.globalData.token,
      headimg:pic_path
    }
    api.post('/api/member/moheadimg', JSON.stringify(data))
        .then((response) => {
          console.log('修改头像==》',response);
          if(response.code == 0){
            that.getPropertyDetails();
          }else{
            toast.showError(response.message);
          }
        })
        .catch((error) => {
          toast.showError(error.errMsg);
        });

  },

微信小程序内接小程序客服

内接公司内部的小程序客服,先在微信公众平台设置小程序客服,然后使用button的open-type设置成contact,再进行事件对接。

使用button按钮跳转客服

xml 复制代码
  <button class="containedwhd"
          open-type="contact"
          send-message-title="客服"
          show-message-card="true"
          bindcontact="contactEvent"
  >
    <image class="left_ls" src="https://ys.ziye.com/upload/iocn/kefu.png"></image>
    <view class="keda">客服</view>
  </button>
javascript 复制代码
Page({
     // 客服
  contactEvent(e){
  
	console.log(e,'客服===>')
	console.log(e.detail.path)
    console.log(e.detail.query)
    
  }, 
})
相关推荐
源码_V_saaskw9 天前
宇鹿家政服务系统小程序ThinkPHP+UniApp
微信小程序·小程序·uni-app·微信公众平台
说私域9 天前
云零售新中枢:定制化“开源AI智能名片+S2B2C商城小程序”驱动的沉浸式触点进化论
人工智能·小程序·开源·零售
伍哥的传说9 天前
React 轻量级状态管理器Zustand
前端·javascript·react.js·小程序·前端框架·ecmascript
好好的哦10 天前
抖音小程序支付错误码141211
小程序·uni-app
橘子海全栈攻城狮10 天前
【源码+文档+调试讲解】基于web的运动健康小程序的设计与实现y196
java·开发语言·小程序·notepad++
即可皕10 天前
WebSocket长连接在小程序中的实践:消息推送与断线重连机制设计
websocket·网络协议·小程序
Haibakeji10 天前
海拔案例分享-门店业绩管理小程序
大数据·小程序
鱼雀AIGC10 天前
如何仅用AI开发完整的小程序<3>—创建小程序基础框架
小程序·aigc·ai编程
素界UI设计10 天前
北斗导航深度接入小程序打车:高精度定位如何解决定位漂移难题?
小程序
郭玉齐10 天前
uniapp+vue3做小程序,获取容器高度
小程序·uni-app