

详细代码
<t-button size="large" theme="primary" variant="outline" data-type="hasCancelBtn" bind:tap="showDialog" block style="display: none;">
开放能力按钮
</t-button>
<t-dialog id="t-dialog" />
// 获取手机号
showDialog() {
let that = this
interface PhoneNumberDetail {
iv: string; // 解密向量
encryptedData: string; // 加密数据
errMsg: string; // 错误信息
}
const dialogConfig = {
context: this,
title: '小程序',
content: '申请获取并验证你的手机号。',
cancelBtn: '取消',
confirmBtn: {
openType: 'getPhoneNumber',
content: '获取手机号',
bindgetphonenumber({ detail }: { detail: PhoneNumberDetail }) {
console.log(detail,'555')
that.setData({
encryptedData: detail.encryptedData,
iv: detail.iv
})
if (detail.errMsg.includes('fail')) {
return false; // 不关闭弹窗
}
return true; // 关闭弹窗
},
},
};
Dialog.confirm(dialogConfig)
.then(() => {
console.log('点击确定');
})
.catch(() => {
console.log('点击取消');
});
},
// 页面初始加载
onLoad() {
let iv = this.data.iv
if (!iv) {
this.showDialog()
}
},
// 页面的初始数据
data: {
encryptedData: '',//手机号参数
iv: '',//手机号参数
},