From 25ebc714977470b5ed02b0ec7f30ea0615ebd89f Mon Sep 17 00:00:00 2001
From: zuoxiao <zuoxiao>
Date: 星期五, 14 三月 2025 16:48:09 +0800
Subject: [PATCH] 更新应用配置,添加AppID并修改页面路由;优化取水口界面,增加定时开阀功能和相关参数设置;修复首页反馈图标及提示信息。
---
pages/login/login.js | 301 +++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 296 insertions(+), 5 deletions(-)
diff --git a/pages/login/login.js b/pages/login/login.js
index 24469ad..a4dd503 100644
--- a/pages/login/login.js
+++ b/pages/login/login.js
@@ -1,18 +1,226 @@
-// pages/login/login.js
+const app = getApp();
+const storage = require('../../utils/storage.js');
+const {
+ post
+} = require('../../api/request.js');
+
Page({
/**
* 椤甸潰鐨勫垵濮嬫暟鎹�
*/
data: {
+ phone: '',
+ verificationCode: '',
+ codeText: '鑾峰彇楠岃瘉鐮�',
+ counting: false,
+ countDown: 60,
+ projectName: '鍢夊唱鍏抽」鐩�', // 榛樿椤圭洰鍚嶇О
+ selectedProject: 'JYG', // 榛樿椤圭洰浠g爜
+ showErrorDialog: false
+ },
+ /**
+ * 缁戝畾鎵嬫満鍙疯緭鍏�
+ */
+ bindPhoneInput: function (e) {
+ this.setData({
+ phone: e.detail.value
+ });
+ },
+
+ /**
+ * 缁戝畾楠岃瘉鐮佽緭鍏�
+ */
+ bindCodeInput: function (e) {
+ this.setData({
+ verificationCode: e.detail.value
+ });
+ },
+
+ /**
+ * 鍙戦�侀獙璇佺爜
+ */
+ sendVerificationCode: function () {
+ const {
+ phone,
+ counting
+ } = this.data;
+
+ // 濡傛灉姝e湪鍊掕鏃讹紝鍒欎笉鍏佽鍐嶆鍙戦��
+ if (counting) {
+ return;
+ }
+
+ // 楠岃瘉鎵嬫満鍙锋牸寮�
+ if (!/^1\d{10}$/.test(phone)) {
+ wx.showToast({
+ title: '璇疯緭鍏ユ纭殑鎵嬫満鍙�',
+ icon: 'none'
+ });
+ return;
+ }
+
+ // 寮�濮嬪�掕鏃�
+ this.startCountDown();
+
+ // 鍙戦�侀獙璇佺爜璇锋眰
+ this.postCode();
+ },
+
+ /**
+ * 寮�濮嬪�掕鏃�
+ */
+ startCountDown: function () {
+ this.setData({
+ counting: true,
+ countDown: 60
+ });
+
+ const timer = setInterval(() => {
+ if (this.data.countDown <= 1) {
+ clearInterval(timer);
+ this.setData({
+ counting: false,
+ codeText: '鑾峰彇楠岃瘉鐮�'
+ });
+ } else {
+ this.setData({
+ countDown: this.data.countDown - 1,
+ codeText: `${this.data.countDown - 1}绉掑悗閲嶅彂`
+ });
+ }
+ }, 1000);
+
+ // 淇濆瓨timer寮曠敤锛屼互渚垮湪椤甸潰鍗歌浇鏃舵竻闄�
+ this.countDownTimer = timer;
+ },
+
+ /**
+ * 鍋滄鍊掕鏃�
+ */
+ stopCountDown: function () {
+ if (this.countDownTimer) {
+ clearInterval(this.countDownTimer);
+ }
+ this.setData({
+ counting: false,
+ codeText: '鑾峰彇楠岃瘉鐮�'
+ });
+ },
+
+ /**
+ * 鐧诲綍
+ */
+ login: function () {
+ const {
+ phone,
+ verificationCode
+ } = this.data;
+
+ // 楠岃瘉鎵嬫満鍙峰拰楠岃瘉鐮�
+ if (!/^1\d{10}$/.test(phone)) {
+ wx.showToast({
+ title: '璇疯緭鍏ユ纭殑鎵嬫満鍙�',
+ icon: 'none'
+ });
+ return;
+ }
+
+ if (!/^\d{6}$/.test(verificationCode)) {
+ wx.showToast({
+ title: '璇疯緭鍏�6浣嶉獙璇佺爜',
+ icon: 'none'
+ });
+ return;
+ }
+
+ // 鏄剧ず鍔犺浇涓�
+ wx.showLoading({
+ title: '鐧诲綍涓�...',
+ mask: true
+ });
+ this.wsLogin();
+
+
+ // 鍙戦�佺櫥褰曡姹�
+ post('/api/loginByCode', {
+ phone: phone,
+ code: verificationCode,
+ projectCode: this.data.selectedProject
+ }).then(res => {
+ wx.hideLoading();
+
+ if (res.code === 0 && res.data) {
+ // 淇濆瓨鐢ㄦ埛淇℃伅鍜宼oken
+ storage.setUserInfo(res.data);
+ storage.setToken(res.data.token);
+
+ // 璺宠浆鍒伴椤�
+ wx.switchTab({
+ url: '/pages/index/index'
+ });
+ } else {
+ wx.showToast({
+ title: res.msg || '鐧诲綍澶辫触锛岃閲嶈瘯',
+ icon: 'none'
+ });
+ }
+ }).catch(err => {
+ wx.hideLoading();
+ console.error('鐧诲綍澶辫触', err);
+ wx.showToast({
+ title: '缃戠粶寮傚父锛岃閲嶈瘯',
+ icon: 'none'
+ });
+ });
+ },
+
+ /**
+ * 璺宠浆鍒版敞鍐岄〉闈�
+ */
+ goToRegister: function () {
+ wx.showToast({
+ title: '娉ㄥ唽鍔熻兘鏆傛湭寮�鏀�',
+ icon: 'none',
+ duration: 2000
+ });
+ },
+
+ /**
+ * 璺宠浆鍒板繕璁板瘑鐮侀〉闈�
+ */
+ goToForgetPassword: function () {
+ wx.showToast({
+ title: '鎵惧洖瀵嗙爜鍔熻兘鏆傛湭寮�鏀�',
+ icon: 'none',
+ duration: 2000
+ });
},
/**
* 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
*/
- onLoad(options) {
-
+ onLoad: function (options) {
+ // 鑾峰彇閫夋嫨鐨勯」鐩�
+ if (options.project) {
+ this.setData({
+ selectedProject: options.project,
+ projectName: options.project === 'JYG' ? '鍢夊唱鍏抽」鐩�' : '姘戝嫟椤圭洰'
+ });
+ } else {
+ // 灏濊瘯浠庢湰鍦板瓨鍌ㄨ幏鍙栧凡閫夋嫨鐨勯」鐩�
+ storage.getItem('selectedProject').then(project => {
+ if (project) {
+ this.setData({
+ selectedProject: project,
+ projectName: project === 'JYG' ? '鍢夊唱鍏抽」鐩�' : '姘戝嫟椤圭洰'
+ });
+ }
+ }).catch(err => {
+ console.error('鑾峰彇宸查�夋嫨椤圭洰澶辫触:', err);
+ });
+ }
},
/**
@@ -40,7 +248,11 @@
* 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍗歌浇
*/
onUnload() {
-
+ // 娓呴櫎楠岃瘉鐮佸�掕鏃跺畾鏃跺櫒
+ if (this.countDownTimer) {
+ clearInterval(this.countDownTimer);
+ this.countDownTimer = null;
+ }
},
/**
@@ -62,5 +274,84 @@
*/
onShareAppMessage() {
- }
+ },
+ //鑾峰彇楠岃瘉鐮�
+ postCode: function () {
+ const params = {
+ url: 'wx/client/send_sms?phoneNumber=' + this.data.phone
+ };
+ post(params)
+ .then((data) => {
+ wx.showToast({
+ title: '楠岃瘉鐮佸凡鍙戦��',
+ icon: 'success',
+ duration: 2000,
+ });
+ this.setData({
+ codeSent: true,
+ });
+ // 鍚姩鍊掕鏃�
+ this.startCountdown();
+ })
+ .catch((error) => {
+ wx.showToast({
+ title: error.msg,
+ icon: 'none'
+ });
+ console.error('Failed to add item:', error);
+ });
+ },
+ 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.phone,
+ securityCode: this.data.verificationCode,
+ code: wxCode
+ }
+ };
+ post(params)
+ .then((data) => {
+ wx.hideLoading();
+ 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.hideLoading();
+ wx.showToast({
+ title: error.msg,
+ icon: 'error',
+ duration: 3000,
+ });
+ console.error('Failed to add item:', error);
+ });
+ },
+ bindSuccess: function () {
+ if (!this.data.isButtonEnabled) return;
+ wx.showToast({
+ title: '缁戝畾鎴愬姛',
+ icon: 'success'
+ });
+ // 璺宠浆鍒� TabBar 椤甸潰
+ wx.redirectTo({
+ url: '/pages/home/home' // 杩欓噷濉啓浣犳兂瑕佽烦杞殑 TabBar 椤甸潰璺緞
+ });
+ },
})
\ No newline at end of file
--
Gitblit v1.8.0