網(wǎng)站免備案空間北京搜索排名優(yōu)化
開發(fā)準備
上一節(jié)我們實現(xiàn)了回收金提現(xiàn)記錄的展示功能,我們回收金相關(guān)的內(nèi)容更加的豐富了,在之前的業(yè)務(wù)邏輯中我們添加了一個設(shè)置安全鎖的功能,雖然我們成功設(shè)置了安全鎖,也把對應(yīng)的表信息提交到云端,但是我們并沒有在提現(xiàn)的流程中去使用安全鎖相關(guān)的內(nèi)容,這一節(jié)我們就把安全鎖相關(guān)的內(nèi)容跟提現(xiàn)流程關(guān)聯(lián)起來,讓我們的功能安全性更高
功能分析
首先我們在進入提現(xiàn)頁面的時候要先查詢當前userid下的安全鎖表有沒有數(shù)據(jù),有數(shù)據(jù)我們就拿當前安全鎖開啟的狀態(tài),如果是開啟的,那我們就在用戶點擊提現(xiàn)按鈕的時候進行一個彈窗校驗,根據(jù)用戶在彈窗里繪制的值跟我們設(shè)置的安全鎖的值進行匹配,如果匹配成功,就執(zhí)行內(nèi)容的添加操作,如果不成功,提醒用戶,安全鎖驗證失敗
代碼實現(xiàn)
首先我們在提現(xiàn)頁面先查詢對應(yīng)的表內(nèi)容
let databaseZone = cloudDatabase.zone('default');
let condition3 = new cloudDatabase.DatabaseQuery(verify_info);condition.equalTo("user_id", this.user?.user_id)let listData3 = await databaseZone.query(condition3);let json3 = JSON.stringify(listData3)let data3: VerifyInfo[] = JSON.parse(json3)this.verifyInfo=data3
然后我們進行數(shù)據(jù)源的非空判斷,安全鎖開關(guān)判斷
if (this.verifyInfo.length>0) {if (this.verifyInfo[0].open_lock) {}}
都沒問題之后我們需要有一個校驗的彈窗
import showToast from '../utils/ToastUtils';@Preview
@CustomDialog
export struct WithdrawalLockDialog {@State passwords: Number[]=[];public callback:(passwords:string)=>void=():void=>{}private patternLockController: PatternLockController = new PatternLockController();controller: CustomDialogController;build() {Column({space:10}) {Text("請驗證您的安全密碼!").fontColor(Color.White).fontWeight(FontWeight.Bold).fontSize(16).width('100%').textAlign(TextAlign.Center).padding(10)PatternLock(this.patternLockController).sideLength(300).circleRadius(9).pathStrokeWidth(5).borderRadius(10).activeColor('#707070').selectedColor('#707070').pathColor('#707070').backgroundColor('#F5F5F5').autoReset(true).onDotConnect((index: number) => {console.log("onDotConnect index: " + index);}).onPatternComplete((input: Array<number>) => {if (input.length < 5) {showToast("圖案連接數(shù)不能小于5")return;}const str: string = JSON.stringify(input);this.callback(str)this.controller.close()})}.width('100%').height(400)}
}
這里我們把彈窗中輸入的值通過回調(diào)傳遞出去,在提現(xiàn)頁面引用彈窗
private dialogController: CustomDialogController = new CustomDialogController({builder: WithdrawalLockDialog({callback: async (str:string)=>{}}),alignment: DialogAlignment.Bottom,customStyle:false});
然后我們把輸入的值跟表中存儲的值進行校驗,驗證成功后提交對應(yīng)的記錄
if (str==this.verifyInfo[0].lock_str) {showToast("校驗成功")let record=new withdrawal_record()record.id=Math.floor(Math.random() * 1000000)record.user_id=this.user!.user_idrecord.bank_name=this.bankList[0].bank_namerecord.bank_num=this.bankList[0].bank_cardrecord.creat_time=this.year+"-"+this.month+"-"+this.day+" "+this.timerecord.type_str='0'record.money=this.moneyNumlet status = await databaseZone.upsert(record);let money=new money_info()money.id=Math.floor(Math.random() * 1000000)money.user_id=this.user!.user_idmoney.money=String(this.moneyNum)money.all_money=''money.money_type='1'money.address='銀行卡提現(xiàn)'money.year=this.yearmoney.month=this.monthmoney.day=this.daymoney.time=this.timemoney.create_time=this.year+"-"+this.month+"-"+this.day+" "+this.timelet nums = await databaseZone.upsert(money);let userData=new user_info()userData.id=this.userInfo!.iduserData.user_id=this.userInfo!.user_iduserData.sex=this.userInfo!.sexuserData.bind_phone=this.userInfo!.bind_phoneuserData.create_time=this.userInfo!.create_timeuserData.nickname=this.userInfo!.nicknameuserData.head_img=this.userInfo!.head_imgif (this.userInfo?.money!=null) {userData.money=this.userInfo!.money-this.moneyNum}else {userData.money=0}if (this.userInfo?.points!=null) {userData.points=this.userInfo!.points}else {userData.points=0}let s= await databaseZone.upsert(userData);if (s>0) {router.pushUrl({url:'pages/recycle/money/SuccessPage'})}this.dialogController.close()}else {showToast("安全鎖驗證失敗!")}
我們執(zhí)行代碼查看一下開啟安全鎖后提現(xiàn)的效果