小程序
小游戏
企业微信
微信支付
扫描小程序码分享
由于需要对用户进行消息推送,所以需要获取formId。
现在登录按钮上绑定着submit(form标签上bindsubmit)和getuserinfo(button上的bindgetuserinfo)的两个方法,一个提交一个授权,点击登录按钮两个方法都被触发,能否控制授权完毕才进行提交呢?
在getuserinfo方法里面调用submit无法获取formId及value,反之同理,怎么解决求教。
2 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
用 promise 实现
<
form
report-submit
report-submit-timeout
=
"2000"
bindsubmit
"formSubmit"
>
input
class
"form-control text-center mb-3"
required
placeholder
"请输入您获得的四位随机码"
value
"{{ code }}"
maxlength
"4"
bindinput
'bindinput'
data-name
'code'
name
/>
button
wx:else
'btn btn-primary'
loading
"{{btnLoading}}"
form-type
"submit"
open-type
"getPhoneNumber"
bindgetphonenumber
disabled
"{{code.length !== 4}}"
>进入排队</
</
Page({
phoneReady:
null
,
formReady:
data: {
btnLoading:
false
},
onLoad() {
this
.resetPostPromise();
formSubmit:
function
(e) {
console.log(
'formsubmit'
, e);
.setData({ btnLoading:
true
, })
.formReady.resolve({ form_id: e.detail.formId, code: e.detail.value.code });
getPhoneNumber(e) {
if
(e.detail.iv) {
'getPhoneNumber'
, e)
postPhoneNumber(e.detail).then(user => {
'Phone post success.'
);
.phoneReady.resolve({});
.phoneReady.reject);
}
else
{
// 用户拒绝授权
.phoneReady.reject();
showToast(
"手机授权失败"
resetPostPromise() {
const phoneReady =
new
Promise((resolve, reject) => {
.phoneReady = {resolve, reject};
});
const formReady =
.formReady = { resolve, reject };
Promise.all([phoneReady, formReady]).then(res => {
// todo something
}).finally(() => {
, });
'resetPostPromise'
})
bindinput(e) {
const name = e.currentTarget.dataset.name;
.setData({
[name]: e.detail.value
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
想得美
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
用 promise 实现
<
form
report-submit
report-submit-timeout
=
"2000"
bindsubmit
=
"formSubmit"
>
<
input
class
=
"form-control text-center mb-3"
required
placeholder
=
"请输入您获得的四位随机码"
value
=
"{{ code }}"
maxlength
=
"4"
bindinput
=
'bindinput'
data-name
=
'code'
name
=
'code'
/>
<
button
wx:else
class
=
'btn btn-primary'
loading
=
"{{btnLoading}}"
form-type
=
"submit"
open-type
=
"getPhoneNumber"
bindgetphonenumber
=
"getPhoneNumber"
disabled
=
"{{code.length !== 4}}"
>进入排队</
button
>
</
form
>
Page({
phoneReady:
null
,
formReady:
null
,
data: {
btnLoading:
false
,
},
onLoad() {
this
.resetPostPromise();
},
formSubmit:
function
(e) {
console.log(
'formsubmit'
, e);
this
.setData({ btnLoading:
true
, })
this
.formReady.resolve({ form_id: e.detail.formId, code: e.detail.value.code });
},
getPhoneNumber(e) {
if
(e.detail.iv) {
console.log(
'getPhoneNumber'
, e)
postPhoneNumber(e.detail).then(user => {
console.log(
'Phone post success.'
);
this
.phoneReady.resolve({});
},
this
.phoneReady.reject);
}
else
{
// 用户拒绝授权
this
.phoneReady.reject();
showToast(
"手机授权失败"
);
}
},
resetPostPromise() {
const phoneReady =
new
Promise((resolve, reject) => {
this
.phoneReady = {resolve, reject};
});
const formReady =
new
Promise((resolve, reject) => {
this
.formReady = { resolve, reject };
});
Promise.all([phoneReady, formReady]).then(res => {
// todo something
}).finally(() => {
this
.setData({ btnLoading:
false
, });
console.log(
'resetPostPromise'
);
this
.resetPostPromise();
})
},
bindinput(e) {
const name = e.currentTarget.dataset.name;
this
.setData({
[name]: e.detail.value
})
}
})
想得美