代碼片段:https://developers.weixin.qq.com/s/GCBSbsmH7jkw
問題一:有必要把條件渲染代碼寫在組件中嗎?
?問題二:自定義組件中怎么獲取實體App 的屬性
問題三:為什么console沒有執行,打斷點也沒有用??
lifetimes: {
attached: function() {
conlose.log("測驗")
},
},
wxml
<block wx:if="{{isrenzheng===0}}">
<!-- 是否有必要把條件渲染寫在組件里 -->
<view class="verify-container">
<mp-dialog mask-closable="{{flase}}" title="提示資訊" show="{{dialogShow}}" bindbuttontap="_tapDialogButton"
buttons="{{buttons}}">
<view>{{textContent}}</view>
</mp-dialog>
<view class="flex-center-center shibie-text-icon">
<image src="https://bbs.csdn.net/topics/{{iconString}}"></image>
<!-- <text class="icon icon-renlianshibie1"></text> -->
<text>請進行人臉識別登錄</text>
</view>
<form catchsubmit="formSubmit">
<view class="page-body">
<view class="page-section">
<view class="weui-cells__title">姓名</view>
<view class="weui-cells weui-cells_after-title">
<view class="weui-cell weui-cell_input">
<input class="weui-input" name="username" maxlength="10" placeholder-style="color:#F76260"
placeholder="請輸入姓名" />
</view>
</view>
</view>
<view class="page-section">
<view class="weui-cells__title">身份證</view>
<view class="weui-cells weui-cells_after-title">
<view class="weui-cell weui-cell_input">
<input class="weui-input" type="idcard" name="useridCard" maxlength="18" placeholder-style="color:#F76260"
placeholder="請輸入身份證" />
</view>
</view>
</view>
</view>
<view class="btn-area">
<button disabled="{{disabled}}" type="primary" formType="submit" style="background:#2792ff">下一步</button>
</view>
</form>
</view>
</block>
<block wx:elif="{{isrenzheng===1}}">
<slot name="detail"></slot>
</block>
js
// components/verify/verify.js
var serv = require('../../libs/call-service.js');
const app = getApp();
Component({
options: {
multipleSlots: true
},
/**
* 組件的屬性串列
*/
properties: {
// isrenzheng:{ type:String,value:""}
},
/**
* 組件的初始資料
*/
data: {
isrenzheng: app.globalData.isCert,
iconString: "",
dialogShow: true,
textContent: "本次操作需要您進行登錄驗證",
buttons: [{ text: '取消' }, { text: '確定' }],
disabled: false
},
/**
* 組件的方法串列
*/
methods: {
formSubmit(e) {
console.log(e)
console.log("用戶的人臉識別是否通過" + app.globalData.isCert)
var _this = this
var username = e.detail.value.username
var useridcard = e.detail.value.useridCard
if (username == '' || useridcard == '') {
wx.showToast({
title: '請輸入資訊',
icon: "none"
})
return
} else {
console.log("跳轉到人臉識頁面")
var param = {
IdCard: useridcard,
Name: username,
openId: app.globalData.openerId,
isCert: 1
}
var _this = this
serv.get('byWxIntf/getBizToken.do', param, function (res) {
//console.log("getBizToken");
console.log(res.data);
var result = res.data;
//console.log("result:"+result);
console.log("url:" + result.Url);
console.log("BizToken:" + result.BizToken);
if (true) {
let BizToken = result.BizToken;
// 呼叫實名核身功能
wx.startVerify({
data: {
token: BizToken // BizToken
},
success: (res) => { // 驗證成功后觸發
// res 包含驗證成功的token, 這里需要加500ms延時,防止iOS下不執行后面的邏輯
setTimeout(() => {
// 驗證成功后,拿到token后的邏輯處理,具體以客戶自身邏輯為準
console.info("----------yes-----------success!----")
wx.showModal({
title: "提示",
content: "恭喜你,驗證成功!",
showCancel: false,
success(res) {
if (res.confirm) {
console.log('用戶點擊確定')
// _this.triggerEvent("formSubmit", { isrenzheng: 1 })
_this.setData({
isrenzheng: 1
})
}
}
})
serv.get('byWxIntf/updateWxUserIdent.do', param, function (res) {
console.log("updateWxUserIdent:" + res.data);
})
app.globalData.isCert = 1;
}, 500);
},
fail: (err) => { // 驗證失敗時觸發
// err 包含錯誤碼,錯誤資訊,彈窗提示錯誤
setTimeout(() => {
wx.showModal({
title: "提示",
content: err.ErrorMsg,
showCancel: false
})
}, 500);
}
});
}
});
}
},
_tapDialogButton: function (e) {
// console.log(e)
var index = e.detail.index
if (index == 0) {
wx.navigateBack({//回傳
delta: 1
})
}
this.setData({
dialogShow: false
})
},
}
})
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/77913.html
標籤:JavaScript
上一篇:從js取值到url超鏈接里面,求助大佬幫忙,急呢~~~~謝謝謝謝
下一篇:點擊按鈕為什么不能觸發js代碼?
