收藏
回答

errMsg : "chooseImage:fail, the permissi

点击上传图片 偶尔会弹出errMsg : "chooseImage:fail, the permissi  手机机型iphone6  和 iphone xs max   进入页面立即点击(要快)就会出现报错


代码:

store/modules/Wechat.js

const actions = {
  /**
   * 初始化微信配置
   * @param {*} param0
   * @param {*} payload payload.perms微信权限
   */
  initConfig ({commit, state}, payload) {
    return new Promise((resolve, reject) => {
      let data = {
        url: state.url,
        perms: payload.perms
      }
      Http.post('/v1/wechat/js', data).then(response => {
        let wechatJs = response.data.meta.wechat_js
        // wechatJs.debug = true
        /* eslint-disable no-undef */
        wx.config(wechatJs)
        resolve()
      }).catch(err => {
        reject(err)
      })
    })
  },
 
  /**
   * 从相册中选图片或者拍照
  */
  chooseImage ({dispatch, state}, payload) {
    return new Promise((resolve, reject) => {
      // 因为是用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中
      wx.chooseImage({
        count: payload, // 默认9张照片
        sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
        sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
        success: resolve,
        fail: reject
      })
    })
  },
 
  /**
   * 获取本地图片
  */
  getLocalImgData ({dispatch, state}, payload) {
    return new Promise((resolve, reject) => {
      // 因为是用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中
      wx.getLocalImgData({
        localId: payload, // 图片的localID
        success: resolve,
        fail: reject
      })
    })
  }
}

router/index.js

// 微信分享部署
let wechatSetup = (to) => {
  // 设置微信校验Url
  store.commit('Wechat/setUrl', to.path)
  // 当页面中有上传图片就要调用Wechat/initConfig方法
  if (to.name === 'TeacherTimeLinePublish' || to.name === 'TeacherPublishBulletin' || to.name === 'MasterPublishAnnounce' || to.name === 'ParentMenage') {
    store.dispatch('Wechat/initConfig', {perms: ['chooseImage', 'getLocalImgData']})
  }
  if (to.meta.specialShare !== undefined && to.meta.specialShare === true) {
    // 什么操作都不做
  } else if (to.meta.defaultShare === false || to.meta.defaultShare === undefined) {
    // 默认关闭分享
    store.dispatch('Wechat/unShare')
  }
}
 
// 登录准备
let loginReady = (to, from, next) => {
  return new Promise((resolve, reject) => {
    let accessToken = Token.readAccessToken()
    let loginParams = {
      type: 'wechat',
      state: to.query.state,
      code: to.query.code
    }
 
    if (!accessToken) {
      if (!loginParams.state || !loginParams.code) {
        // 没有state和code参数时说明没有进行第一次认证
        store.dispatch('Auth/info', {current_full_path: Utils.getUrlFullPath(to.path, to.query)}).then(data => {
          if (data.mock === 1) {
            // 处理mock登录
            store.dispatch('Auth/login', loginParams).then(() => {
              resolve()
              next()
            }).catch(err => {
              return Promise.reject(err)
            })
          } else {
            window.location.href = data.auth_url
          }
        }).catch(err => {
          Notice.error(err)
        })
      } else {
        store.dispatch('Auth/login', loginParams).then(() => {
          resolve()
          next()
        }).catch(err => {
          Notice.error(err)
        })
      }
    } else {
      resolve()
      next()
    }
  })
}
 
router.beforeEach((to, from, next) => {
  if (!to.query.hasOwnProperty('pt') && Utils.pickAccountId().toLowerCase() !== 'public') {
    loginReady(to, from, next).then(() => {
      // 跳转之前验证登录
      identityRedirect(to, from, next)
      wechatSetup(to)
    })
  } else {
    next()
    if (Utils.pickAccountId().toLowerCase() === 'public') {
      wechatSetup(to)
    }
  }
})

页面

methods: {
    uploadImg () { // 图片上传(微信的js-dk)
      var self = this
      this.$store.dispatch('Wechat/chooseImage', 9).then(res => {
        var localIds = res.localIds // 返回选定照片的本地ID列表,localId可以作为img标签的src属性显示图片
        if (localIds.length > 0) {
          for (let i = 0; i < localIds.length; i++) {
            // 获取本地图片
            self.$store.dispatch('Wechat/getLocalImgData', localIds[i]).then(res => {
              var localData = res.localData // localData是图片的base64数据,可以用img标签显示
              // self.imgSrc.push(localData)
              let obj = {
                // 读取成功的数据
                readData: localData,
                // 是否显示蒙层
                isShow: true,
                // 上传成功的状态 true代表成功,false代表还在上传,null代表错误
                isSuccess: false
              }
              self.arr.push(obj)
            }).catch(err => {
              this.$utils.showError('getLocalImgData' + JSON.stringify(err))
            })
          }
        }
      }).catch(err => {
        this.$utils.showError('chooseImage' + JSON.stringify(err))
      })
    }


最后一次编辑于  02-21  (未经腾讯允许,不得转载)
邀请回答
复制链接收藏投诉关注问题回答

1 个回答

  • 微信支付技术助手
    微信支付技术助手
    02-21

    您好,请问这是哪里的上传图片?

    02-21
    赞同
    回复 2
    • 小猪
      小猪
      02-21

      微信公众号

      02-21
      回复
    • 小猪
      小猪
      02-25回复小猪

      请问有没有解决

      02-25
      回复