From ddbd8c7ea87b66d5a9c4362ce284d12a4ae970d1 Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期五, 01 十一月 2024 14:24:50 +0800
Subject: [PATCH] 1绑定相关。2首页修改开关阀提示。3.问题反馈相关功能
---
pages/wxbind/wxbind.js | 125 +++++++++++++++++++++++++++++++++--------
1 files changed, 100 insertions(+), 25 deletions(-)
diff --git a/pages/wxbind/wxbind.js b/pages/wxbind/wxbind.js
index d0ee79f..cff139a 100644
--- a/pages/wxbind/wxbind.js
+++ b/pages/wxbind/wxbind.js
@@ -1,5 +1,10 @@
// pages/wxbind/wxbind.js
const app = getApp();
+const {
+ get,
+ post
+} = require('../../api/request.js');
+const storage = require('../../utils/storage.js');
Page({
/**
@@ -7,10 +12,19 @@
*/
data: {
mobile: '',
- code: '',
+ phoneCode: '',
codeSent: false,
countdown: 60,
- isButtonEnabled: false
+ isButtonEnabled: false,
+ showErrorDialog: false,
+ errorData: "",
+ errorDialogTitle: "閿欒鎻愮ず",
+ confirmBtn: {
+ content: '纭'
+ }
+ },
+ onLoad(options) {
+
},
bindMobileInput(e) {
this.setData({
@@ -20,17 +34,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,21 +58,17 @@
});
return;
}
-
+ if (this.data.mobile.length != 11) {
+ wx.showToast({
+ title: '璇疯緭鍏ュ畬鏁存墜鏈哄彿',
+ icon: 'none',
+ duration: 2000,
+ });
+ return;
+ }
// 鍦ㄨ繖閲屽鐞嗗彂閫侀獙璇佺爜鐨勯�昏緫锛屽彲浠ヨ皟鐢ㄥ悗鍙版帴鍙e疄鐜�
- // 浠ヤ笅鏄竴涓畝鍗曠殑绀轰緥锛屼粎浣滃弬鑰�
- wx.showToast({
- title: '楠岃瘉鐮佸凡鍙戦��',
- icon: 'success',
- duration: 2000,
- });
+ this.postCode();
- this.setData({
- codeSent: true,
- });
-
- // 鍚姩鍊掕鏃�
- this.startCountdown();
},
//鍊掕鏃�
startCountdown: function () {
@@ -77,26 +88,90 @@
}
}, 1000);
},
- bind: function () {
+ bindSuccess: function () {
if (!this.data.isButtonEnabled) return;
wx.showToast({
title: '缁戝畾鎴愬姛',
icon: 'success'
});
// 璺宠浆鍒� TabBar 椤甸潰
- wx.switchTab({
+ wx.navigateTo({
url: '/pages/home/home' // 杩欓噷濉啓浣犳兂瑕佽烦杞殑 TabBar 椤甸潰璺緞
});
},
+ //鑾峰彇楠岃瘉鐮�
postCode: function () {
- post('/items', { name: 'New Item' })
+ const params = {
+ url: '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,
});
+ this.setData({
+ codeSent: true,
+ });
+ // 鍚姩鍊掕鏃�
+ this.startCountdown();
})
.catch((error) => {
+ this.setData({
+ showErrorDialog: true,
+ errorData: error.msg
+ })
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: 'wx/client/verify',
+ data: {
+ phoneNumber: this.data.mobile,
+ securityCode: this.data.phoneCode,
+ code: wxCode
+ }
+ };
+ post(params)
+ .then((data) => {
+ getApp().globalData.sessionId = String(data.content.sessionId)
+ storage.setItem("sessionId", String(data.content.sessionId))
+ getApp().globalData.clientId = String(data.content.clientId)
+ storage.setItem("clientId", String(data.content.clientId))
+ this.bindSuccess();
+ })
+ .catch((error) => {
+ wx.showToast({
+ title: error.msg,
+ icon: 'error',
+ duration: 3000,
+ });
+ console.error('Failed to add item:', error);
+ });
+ },
+ closeDialog() {
+ this.setData({
+ showErrorDialog: false
+ })
}
})
\ No newline at end of file
--
Gitblit v1.8.0