Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.3.0-alpha.7 在h5环境不能使用jssdk中的方法 #9489

Closed
NoahSun opened this issue Jun 9, 2021 · 3 comments
Closed

3.3.0-alpha.7 在h5环境不能使用jssdk中的方法 #9489

NoahSun opened this issue Jun 9, 2021 · 3 comments
Labels
F-vue2 Framework - Vue 2 question Further information is requested T-h5 Target - 编译到 H5 V-3 Version - 3.x

Comments

@NoahSun
Copy link

NoahSun commented Jun 9, 2021

相关平台

H5

浏览器版本: 微信浏览器
使用框架: Vue 2

复现步骤

使用3.3.0-alpha.7 编译为h5,在引入了jssdk后,并且签名成功,在微信浏览器中调用硬件的相关方法不会有任何反应,如:

Taro.scanCode()

Taro.getLocation()

......

(估计应该所有jssdk中的方法都会调用失败)

期望结果

在h5环境能够正常使用

实际结果

在普通浏览器中调用硬件的相关方法会提示”h5端仅在微信公众号中支持 API“

在微信浏览器中调用硬件的相关方法不会有任何反应

直接使用如:
wx.scanQRCode()

wx.getLocation()

就是正常的

环境信息

  Taro CLI 3.3.0-alpha.7 environment info:
    System:
      OS: Windows 10
    Binaries:
      Node: 14.13.1
      Yarn: 1.22.10
      npm: 6.14.8
@taro-bot2 taro-bot2 bot added F-vue2 Framework - Vue 2 T-h5 Target - 编译到 H5 V-3 Version - 3.x labels Jun 9, 2021
@Chen-jj
Copy link
Contributor

Chen-jj commented Jun 11, 2021

3.2 可以吗?

可以断点进去看看,有没有成功调用 sdk。

export const scanCode = processOpenapi('scanQRCode', { needResult: 1 }, res => ({
errMsg: res.errMsg === 'scanQRCode:ok' ? 'scanCode:ok' : res.errMsg,
result: res.resultStr
}))

function processOpenapi (apiName, defaultOptions, formatResult = res => res, formatParams = options => options) {
if (!window.wx) {
return weixinCorpSupport(apiName)
}
return options => {
options = options || {}
const obj = Object.assign({}, defaultOptions, options)
const p = new Promise((resolve, reject) => {
['fail', 'success', 'complete'].forEach(k => {
obj[k] = oriRes => {
const res = formatResult(oriRes)
options[k] && options[k](res)
if (k === 'success') {
resolve(res)
} else if (k === 'fail') {
reject(res)
}
}
})
wx[apiName](formatParams(obj))
})
return p
}
}

@NoahSun
Copy link
Author

NoahSun commented Jun 15, 2021

@Chen-jj

暂时没试3.2。但是,直接调用Taro.scanCode,在微信浏览器中会直接报下图内容,而我打印window.wx的内容是{miniprograme: {}}

image

@NoahSun NoahSun closed this as completed Jun 15, 2021
@NoahSun NoahSun reopened this Jun 15, 2021
@Chen-jj
Copy link
Contributor

Chen-jj commented Jun 15, 2021

sdk 的问题吧,自行断点看看了

@Chen-jj Chen-jj added the question Further information is requested label Jun 16, 2021
@Chen-jj Chen-jj closed this as completed Oct 28, 2021
@ZakaryCode ZakaryCode moved this to Done in H5 Apr 10, 2023
@ZakaryCode ZakaryCode added this to H5 Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-vue2 Framework - Vue 2 question Further information is requested T-h5 Target - 编译到 H5 V-3 Version - 3.x
Projects
Archived in project
Development

No branches or pull requests

2 participants