mpflutter
mpflutter copied to clipboard
[feature request] 为 WechatMiniProgramButton 添加 chooseAvatar 支持
如题,在 小程序用户头像昵称获取规则调整公告 中提到,小程序基础库 2.21.2 后、2022 年 10 月 25 日后不再支持 wx.getUserInfo
,虽然不确定这是否影响 button
的 open-type
为 getUserInfo
的情形,但毕竟官方提供了新的 chooseAvatar
所以还是希望能够提供支持。
另外,我这边试图使用 MPMiniProgramView
手搓一个 'open-type': 'chooseAvatar'
的 button
,手动更新了 weapp/project.config.json
中的基础库版本后发现, button
能够正常触发头像选择,却不能触发回调,但降级基础库版本、将 open-type
改为 getUserInfo
、 event
改为 getuserinfo
后回调正常,以下是我的代码:
class WeChatAvatar extends MPMiniProgramView {
WeChatAvatar()
: super(
tag: 'button',
attributes: {
'open-type': 'chooseAvatar',
},
eventListeners: [
MPMiniProgramEvent(
event: 'chooseavatar',
callback: (value) {
MPWebDialogs.alert(message: 'bindchooseavatar: $value');
},
)
],
child: MPIcon(
MaterialIcons.account_circle,
size: 64,
),
);
}
估计需要更新一下 kbone 的事件列表才行
估计需要更新一下 kbone 的事件列表才行
原来还有这一层,受教了……难怪怎么改都改不出来🤣
说来还想请问一下,虽然不知道和这个 issue 相不相符,请问有没有一个判断目前运行环境的方案?这样就可以实现仅在微信小程序中调用微信组件、在 Web 端另外处理,做到最大程度的兼容之类的…🤔
MPEnv 是可以判断当前环境的
多谢提醒!之前只在列表里粗略找了找没细看,这么一说才发现,这就去试试看 MPEnv
@PonyCui 想问问看,mpflutter_template 具体对 kbone 做了哪些改动…?还是说,其实没有改动,只是单纯的新版本不兼容呢…?
我把 kbone 中 miniprogram-element 更换为了 2.2.12(及最新版),将 base.js
中的 require("miniprogram-render")
改为了 require("../miniprogram-render/index")
,但在触发事件的时候提示:
WAServiceMainContext.js?t=wechat&s=1658497367628&v=2.25.0:1 TypeError: Cannot read property 'now' of undefined
at Uo.callSingleEvent (base.js:187)
at Uo.onButtonChooseAvatar (component.js:769)
at Object.i.safeCallback (WASubContext.js?t=wechat&s=1658497367628&v=2.25.0:1)
at WASubContext.js?t=wechat&s=1658497367628&v=2.25.0:1
at J (WASubContext.js?t=wechat&s=1658497367628&v=2.25.0:1)
at WASubContext.js?t=wechat&s=1658497367628&v=2.25.0:1
at WAServiceMainContext.js?t=wechat&s=1658497367628&v=2.25.0:1
at a (VM8 asdebug.js:10)
at c (VM8 asdebug.js:10)
at VM8 asdebug.js:1(env: Windows,mp,1.06.2206090; lib: 2.25.0)
,其中 base.js:187
前后大概是这样:
event: new Event({
timeStamp: window.performance.now(),
touches: evt && evt.touches, // line 187
changedTouches: evt && evt.changedTouches,
name: eventName,
感觉有点…一头雾水了,如果将 miniprogram-render 也一起替换的话,就会导致渲染不出来,文字全部变成大黑块……
编辑:并且这个问题在 debug 和 build 都存在,感觉应该不是缓存没刷新之类的
我准备更新一下 kbone 的版本,你这个问题是因为某些库缺失导致的。 例如 performance 这个库没有了,需要用 new Date().getTime()。
多谢,麻烦了!
使用 0.1.0 版本的 universal_miniprogram_api 应该可以了
问一下,现在 universal_miniprogram_api 是不支持 chooseAvatar ,还是需要自己改源码是吗?
同问,现在对于微信的 2.21.2 小程序 头像昵称填写 这两个组件怎么写?mp也没有任何相关的文档