From 06b93604f8f9bfbcc740decfe5a5b922d75a0de3 Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期三, 03 七月 2024 10:05:51 +0800
Subject: [PATCH] 完成界面
---
pages/wxbind/wxbind.js | 90 +++++++++++++++++++++++++++++++++++++--------
1 files changed, 74 insertions(+), 16 deletions(-)
diff --git a/pages/wxbind/wxbind.js b/pages/wxbind/wxbind.js
index d0ee79f..a944de6 100644
--- a/pages/wxbind/wxbind.js
+++ b/pages/wxbind/wxbind.js
@@ -1,5 +1,9 @@
// pages/wxbind/wxbind.js
const app = getApp();
+const {
+ get,
+ post
+} = require('../../api/request.js');
Page({
/**
@@ -7,10 +11,14 @@
*/
data: {
mobile: '',
- code: '',
+ phoneCode: '',
+
codeSent: false,
countdown: 60,
isButtonEnabled: false
+ },
+ onLoad(options) {
+
},
bindMobileInput(e) {
this.setData({
@@ -20,17 +28,18 @@
bindCodeInput(e) {
this.setData({
- code: e.detail.value
- }, this.checkButtonState);
+ phoneCode: e.detail.value
+ });
+ this.checkButtonState();
},
checkButtonState() {
const {
mobile,
- code
+ phoneCode
} = this.data;
- const isButtonEnabled = mobile.length === 11 && code.length == 6;
+ const isButtonEnabled = mobile.length === 11 && phoneCode.length == 6;
this.setData({
- isButtonEnabled
+ isButtonEnabled: isButtonEnabled
});
console.log(isButtonEnabled);
},
@@ -43,19 +52,11 @@
});
return;
}
-
// 鍦ㄨ繖閲屽鐞嗗彂閫侀獙璇佺爜鐨勯�昏緫锛屽彲浠ヨ皟鐢ㄥ悗鍙版帴鍙e疄鐜�
- // 浠ヤ笅鏄竴涓畝鍗曠殑绀轰緥锛屼粎浣滃弬鑰�
- wx.showToast({
- title: '楠岃瘉鐮佸凡鍙戦��',
- icon: 'success',
- duration: 2000,
- });
-
+ this.postCode();
this.setData({
codeSent: true,
});
-
// 鍚姩鍊掕鏃�
this.startCountdown();
},
@@ -88,15 +89,72 @@
url: '/pages/home/home' // 杩欓噷濉啓浣犳兂瑕佽烦杞殑 TabBar 椤甸潰璺緞
});
},
+ //鑾峰彇楠岃瘉鐮�
postCode: function () {
- post('/items', { name: 'New Item' })
+ const params = {
+ url: 'https://44978f7456.imdo.co/wx/client/send_sms?phoneNumber=' + this.data.mobile
+ };
+ post(params)
.then((data) => {
this.setData({
items: [...this.data.items, data]
});
+ wx.showToast({
+ title: '楠岃瘉鐮佸凡鍙戦��',
+ icon: 'success',
+ duration: 2000,
+ });
})
.catch((error) => {
console.error('Failed to add item:', error);
});
+ },
+
+ bind() {
+ this.wsLogin();
+ },
+ wsLogin(){
+ wx.login({
+ success: res => {
+ if (res.code) {
+ console.log('鐧诲綍鎴愬姛锛岃幏鍙栧埌鐨刢ode:', res.code);
+ // 鍙戦�� res.code 鍒板悗鍙版湇鍔″櫒鎹㈠彇 openId, sessionKey, unionId
+ this.verify(res.code)
+ } else {
+ console.log('鐧诲綍澶辫触锛�' + res.errMsg);
+ }
+ }
+ });
+ },
+ //鐢ㄦ埛缁戝畾
+ verify(wxCode){
+ const params = {
+ url: 'https://44978f7456.imdo.co/wx/client/verify',
+ data: {
+ phoneNumber: this.data.mobile,
+ securityCode: this.data.phoneCode,
+ code: wxCode
+ }
+ };
+ post(params)
+ .then((data) => {
+ getApp().globalData.sessionId= data.content
+ this.setData({
+ items: [...this.data.items, data]
+ });
+ wx.showToast({
+ title: '缁戝畾鎴愬姛',
+ icon: 'success',
+ duration: 2000,
+ });
+ })
+ .catch((error) => {
+ wx.showToast({
+ title: error.msg,
+ icon: 'error',
+ duration: 3000,
+ });
+ console.error('Failed to add item:', error);
+ });
}
})
\ No newline at end of file
--
Gitblit v1.8.0