钉钉微应用

2019-01-24移动端调试,钉钉开发踩坑

2019-01-26  本文已影响0人  追风筝的Hassan

1.this的指向问题导致页面无法跳转

 onInsert () {
      let self = this
      dd.biz.navigation.setRight({
        show: true, // 控制按钮显示, true 显示, false 隐藏, 默认true
        control: true, // 是否控制点击事件,true 控制,false 不控制, 默认false
        text: '添加', // 控制显示文本,空字符串表示显示默认文本
        onSuccess () {
          self.$router.push({ path: '/work/addBusiness' })
        },
        onFail (error) {
          console.log(JSON.stringify(error))
        }
      })
    },

2.清除时间问题导致,组件不显示问题

// 把时间改为100后,跳转组件页面不显示
 created () {
    let clearTime = setTimeout(() => {
      clearTimeout(clearTime)
      this.matchedTag()
    }, 500)
  },

3.页面缓存问题

可以使用keepAlive进行控制页面是否缓存

<keep-alive>
<router-view v-if="$route.meta.keepAlive"></router-view>
</keep-alive>
<router-view v-if="!$route.meta.keepAlive"></router-view>

然后在路由中设置路由元keepAlive的true,false来控制页面缓存,这种情况下,实现浏览器返回不刷新页面
一篇参考文章https://www.cnblogs.com/leejay6567/p/9096187.html

4.钉钉调用地图接口使用

调用其内部的接口需要获取userId获取权限

 async getAuthInfo () {
      let params = {
        requestUrl: 'http://crm-dev.jiuyescm.com:18000/'
      }
      let config = await Base.getAuthInfo(params)
      dd.config = {
        agentId: config.agentId, // 必填,微应用ID
        corpId: config.corpId, // 必填,企业ID
        timeStamp: config.timeStamp, // 必填,生成签名的时间戳
        nonceStr: config.nonceStr, // 必填,生成签名的随机串
        signature: config.signature, // 必填,签名
        jsApiList: [
          'runtime.permission.requestAuthCode',
          'biz.navigation.setTitle',
          'biz.navigation.setRight',
          'biz.util.datepicker',
          'biz.navigation.close',
          'biz.util.chosen',
          'biz.util.scanCard',
          'device.geolocation.get'
        ] // 必填,需要使用的jsapi列表
      }
      let code = await this.getCode(config.corpId)
      let userid = await this.getUserId(code)
      if (userid) this.$router.push('/dashboard')
      else this.$toast.fail('获取个人信息失败!')
    },
    // 获取code
    async getCode (corpId) {
      let resData = await Base.getCode()
      if (resData.code * 1 === Code.SUCCESS) {
        dd.runtime.permission.requestAuthCode({
          corpId: corpId,
          onSuccess: result => {
            this.getUserId(result.code)
          },
          onFail (err) {
            this.$toast.fail(JSON.stringify(err))
          }
        })
      } else {
        this.$toast.fail(resData.message)
      }
    },
    // 获取userId
    async getUserId (code) {
      let resData = await Base.getUserId({}, code)
      if (resData.code * 1 === Code.SUCCESS) {
        this.$router.push('/dashboard')
      } else {
        this.$toast.fail(resData.message)
      }
    }
  },
  computed: {}
}

未获取权限时会出现的错误
{'errCode': '7', 'jsapi': 'jsapi should be invoked after dd.ready callbacks'}

上一篇 下一篇

猜你喜欢

热点阅读