From 81a60aa4fb7ee1689518918ceb9122f5d257e2fc Mon Sep 17 00:00:00 2001
From: gerson <1405270578@qq.com>
Date: 星期日, 11 八月 2024 11:56:47 +0800
Subject: [PATCH] 手机登录,去除无效按钮

---
 miniprogram/pages/my/my.wxml             |   14 +-
 miniprogram/app.js                       |    5 
 miniprogram/utils/toolsValidate.ts       |   14 ++
 miniprogram/api/account.ts               |    6 
 miniprogram/pages/login/login.ts         |  158 ++++++++++++++++++++++++++++---
 miniprogram/pages/login/login.wxml       |   12 +
 miniprogram/utils/common.ts              |    3 
 miniprogram/pages/scene/scene.wxml       |    2 
 miniprogram/pages/question/question.wxml |   14 +-
 miniprogram/pages/my/my.js               |    7 
 miniprogram/pages/question/question.ts   |   11 ++
 11 files changed, 204 insertions(+), 42 deletions(-)

diff --git a/miniprogram/api/account.ts b/miniprogram/api/account.ts
index 3089a2e..f232598 100644
--- a/miniprogram/api/account.ts
+++ b/miniprogram/api/account.ts
@@ -28,7 +28,7 @@
 };
 
 //鍙戦�佺煭淇¢獙璇佺爜
-export const loginVerifyMessage = async (params) => {
+export const loginVerifyMessage = async (params,extraData={}) => {
   return http.request({
     url: TEL_LOGIN_URL,
     method: 'POST',
@@ -36,11 +36,12 @@
     headers: {
       'Content-Type': 'application/x-www-form-urlencoded',
     },
+    ...extraData
   });
 };
 
 //鍙戦�佺煭淇¢獙璇佺爜鐧诲綍
-export const loginMessageUser = async (params) => {
+export const loginMessageUser = async (params,extraData={}) => {
   return http.request({
     url: Get_LOGIN_SMS,
     method: 'POST',
@@ -48,5 +49,6 @@
     headers: {
       'Content-Type': 'application/x-www-form-urlencoded',
     },
+    ...extraData
   });
 };
diff --git a/miniprogram/app.js b/miniprogram/app.js
index 396294a..4c30529 100644
--- a/miniprogram/app.js
+++ b/miniprogram/app.js
@@ -13,7 +13,10 @@
     address: {},
   // 褰撳墠鐐瑰嚮鐨� sectionAId
     sectionAId:'',
-    sectionB:null
+    sectionB:null,
+    user:{
+      phoneNum:'',
+    }
   },
 
   onShow() {
diff --git a/miniprogram/pages/login/login.ts b/miniprogram/pages/login/login.ts
index aab9550..0f032ac 100644
--- a/miniprogram/pages/login/login.ts
+++ b/miniprogram/pages/login/login.ts
@@ -5,14 +5,15 @@
 // 瀵煎叆鏈湴瀛樺偍 api
 import { setStorage } from '@/utils/storage'
 // 瀵煎叆鎺ュ彛 API 鍑芥暟
-import { PostLogin } from '@/api/account';
+import { loginMessageUser, loginVerifyMessage, PostLogin } from '@/api/account';
 // 瀵煎叆 ComponentWithStore 鏂规硶
 import { ComponentWithStore } from 'mobx-miniprogram-bindings'
 // 瀵煎叆 store 瀵硅薄
 import { accountStore } from '@/stores/accountStore'
 
-import {STATIC_FILE_BASE_URL} from '@/config/constants'
-
+import { STATIC_FILE_BASE_URL } from '@/config/constants'
+import { verifyPhone } from '@/utils/toolsValidate';
+const app = getApp();
 // 浣跨敤 ComponentWithStore 鏂规硶鏇挎崲 Component 鏂规硶鏋勯�犻〉闈�
 ComponentWithStore({
   // 璁╅〉闈㈠拰 Store 瀵硅薄寤虹珛鍏宠仈
@@ -23,23 +24,116 @@
   },
   data: {
     activeTab: 'account',
-    user: 'tc',
-    password: 'a',
-    STATIC_FILE_BASE_URL
+    user: '',
+    password: '',
+    STATIC_FILE_BASE_URL,
+    countNum: null,
+    countTimer: null,
+    phoneNumber: '',
+    verifyCode: '',
   },
   lifetimes: {
     attached() {
       wx.hideHomeButton();
+    },
+
+  },
+  pageLifetimes: {
+    hide() {
+      this.resetContent();
     }
   },
-
   methods: {
+
+    resetContent() {
+      switch (this.data.activeTab) {
+        case 'account':
+          this.setData({
+            user: '',
+            password: '',
+          })
+          break;
+        case 'cellPhoneNumber':
+          this.setData({
+            phoneNumber: '',
+            verifyCode: '',
+          })
+          this.stopCount();
+          this.setData({
+            countNum: null
+          })
+        default:
+          break;
+      }
+
+    },
     tabChange: function (event) {
       this.setData({
         activeTab: event.detail.name
       })
-
+      this.resetContent();
     },
+    async getSMSClick() {
+      if (this.data.countNum !== null) {
+        return;
+      }
+      if (!this.data.phoneNumber) {
+        toast({
+          title: '璇疯緭鍏ユ墜鏈哄彿鐮侊紒'
+        });
+        return;
+      }
+      console.log(this.data.phoneNumber);
+      const isValid = verifyPhone(this.data.phoneNumber)
+      console.log(isValid);
+      
+      if (!isValid) {
+        toast({
+          title: '璇疯緭鍏ユ纭殑鎵嬫満鍙风爜锛�'
+        });
+        return;
+      }
+      this.setData({
+        verifyCode: ''
+      })
+      const res = await loginVerifyMessage({
+        phone: this.data.phoneNumber
+      },{
+        noAuth: true
+      })
+      
+      if (!res?.json_ok) {
+        return;
+      }
+      this.startCount();
+    },
+    stopCount() {
+      clearInterval(this.data.countTimer)
+    },
+
+    startCount() {
+      this.stopCount();
+      this.setData({
+        countNum: 60
+      })
+      this.data.countTimer = setInterval(() => {
+        if (this.data.countNum === 0) {
+          this.setData({
+            countNum: null
+          })
+          clearInterval(this.data.countTimer);
+          return;
+        }
+        this.setData({
+          countNum: this.data.countNum - 1
+        })
+      }, 1000);
+    },
+
+    handlePhoneNumName(phoneStr){
+     return phoneStr.substr(0,3)+"****"+phoneStr.substr(7);
+    },
+
     // 鎺堟潈鐧诲綍
     login: wx.$_.debounce(async function () {
 
@@ -65,22 +159,54 @@
           }, {
             noAuth: true
           });
-          if (!res.json_ok || !res.hswatersession) {
-            toast({
-              title: res.json_msg
-            })
-            return;
-          }
+          setStorage('username', this.data.user);
+          this.setUsername(this.data.user);
+          app.globalData.user.phoneNum = '';
+
           break;
         case 'cellPhoneNumber':
+
+          if (!this.data.phoneNumber) {
+            toast({
+              title: '璇疯緭鍏ユ墜鏈哄彿鐮侊紒'
+            });
+            return;
+          }
+          if (!verifyPhone(this.data.phoneNumber)) {
+            toast({
+              title: '璇疯緭鍏ユ纭殑鎵嬫満鍙风爜锛�'
+            });
+            return;
+          }
+          if (!this.data.verifyCode) {
+            toast({
+              title: '璇疯緭鍏ラ獙璇佺爜锛�'
+            });
+            return;
+          }
+          res = await loginMessageUser({
+            phone: this.data.phoneNumber,
+            code: this.data.verifyCode,
+          }, {
+            noAuth: true
+          });
+          const phoneName = this.handlePhoneNumName(this.data.phoneNumber) 
+          setStorage('username',phoneName);
+          this.setUsername(phoneName);
+          app.globalData.user.phoneNum = this.data.phoneNumber;
           break;
         default:
           break;
       }
+      if (!res.json_ok || !res.hswatersession) {
+        toast({
+          title: res.json_msg
+        })
+        return;
+      }
       setStorage('session', res.hswatersession);
       this.setSession(res.hswatersession)
-      setStorage('username', this.data.user);
-      this.setUsername(this.data.user);
+
       wx.switchTab({
         url: '/pages/question/question'
       });
diff --git a/miniprogram/pages/login/login.wxml b/miniprogram/pages/login/login.wxml
index 8df7c07..499ee12 100644
--- a/miniprogram/pages/login/login.wxml
+++ b/miniprogram/pages/login/login.wxml
@@ -13,15 +13,19 @@
       <van-tab name="account" title="璐﹀彿鐧诲綍">
         <van-cell-group>
           <van-field model:value="{{ user }}" placeholder="璐﹀彿" />
-          <van-field model:value="{{ password }}" placeholder="瀵嗙爜" border="{{ false }}" />
+          <van-field model:value="{{ password }}" placeholder="瀵嗙爜" type="password" border="{{ false }}" />
         </van-cell-group>
       </van-tab>
       <van-tab name="cellPhoneNumber" title="楠岃瘉鐮佺櫥褰�">
         <van-cell-group>
-          <van-field value="{{ user }}" placeholder="鎵嬫満鍙风爜">
-            <text slot="button" class="sms-send-btn font-bold font23">鑾峰彇楠岃瘉鐮�</text>
+          <van-field model:value="{{ phoneNumber }}" placeholder="鎵嬫満鍙风爜">
+            <text wx:if="{{countNum===null}}" slot="button" class="sms-send-btn font-bold font23" bind:tap="getSMSClick">鑾峰彇楠岃瘉鐮�</text>
+
+            <text wx:else slot="button" class="sms-send-btn font-bold font23 text-gray-300" >{{countNum+'绉掑悗閲嶈瘯'}}</text>
+
+
           </van-field>
-          <van-field value="{{ sms }}" center clearable label="" placeholder="璇疯緭鍏ョ煭淇¢獙璇佺爜" use-button-slot>
+          <van-field model:value="{{ verifyCode }}" center clearable label="" placeholder="璇疯緭鍏ョ煭淇¢獙璇佺爜" use-button-slot>
 
           </van-field>
         </van-cell-group>
diff --git a/miniprogram/pages/my/my.js b/miniprogram/pages/my/my.js
index f8678ac..7f0cbc3 100644
--- a/miniprogram/pages/my/my.js
+++ b/miniprogram/pages/my/my.js
@@ -1,5 +1,5 @@
-import { clearStorage } from "@/utils/storage"
-
+import { clearStorage,getStorage } from "@/utils/storage"
+const app = getApp();
 // pages/my/my.ts
 Component({
 
@@ -7,7 +7,8 @@
    * 椤甸潰鐨勫垵濮嬫暟鎹�
    */
   data: {
-
+    userName:getStorage('username'),
+    phoneNumber: app.globalData.user.phoneNum
   },
   methods:{
     logout(){
diff --git a/miniprogram/pages/my/my.wxml b/miniprogram/pages/my/my.wxml
index a9a5712..33e88d5 100644
--- a/miniprogram/pages/my/my.wxml
+++ b/miniprogram/pages/my/my.wxml
@@ -4,24 +4,24 @@
   <view>
     <view class="flex-items-center">
       <text class="ywicon icon-morentouxiang bg-gray-300 rounded-full text-gray-500 mr-20" style="font-size: 73rpx;"></text>
-      <text class="font25 font-bold">183799|鍏嶈垂鐢ㄦ埛</text>
+      <text class="font25 font-bold">{{userName}}</text>
     </view>
     <fui-list marginTop="40">
       <fui-list-cell highlight="{{false}}">璐﹀彿鍚�
 
-        <text class="text-gray-400">u645782</text>
+        <text class="text-gray-400">{{userName}}</text>
 
       </fui-list-cell>
-      <fui-list-cell arrow>
+      <!-- <fui-list-cell arrow>
         <text>淇敼瀵嗙爜</text>
-      </fui-list-cell>
+      </fui-list-cell> -->
       <fui-list-cell>
         <text>鎵嬫満鍙�</text>
-        <text class="text-gray-400">鏈粦瀹�</text>
+        <text class="text-gray-400">{{phoneNumber || '鏈粦瀹�'}}</text>
       </fui-list-cell>
-      <fui-list-cell arrow>
+      <!-- <fui-list-cell arrow>
         <text>浣跨敤娴忚鍣ㄧ櫥褰�</text>
-      </fui-list-cell>
+      </fui-list-cell> -->
       <!-- <fui-list-cell arrow>
         <text>鍒囨崲璐﹀彿瀵嗙爜鐧诲綍</text>
       </fui-list-cell> -->
diff --git a/miniprogram/pages/question/question.ts b/miniprogram/pages/question/question.ts
index 68bfff6..652cd49 100644
--- a/miniprogram/pages/question/question.ts
+++ b/miniprogram/pages/question/question.ts
@@ -21,6 +21,7 @@
 import { ErrorCode } from "@/utils/http";
 import { ComponentWithComputed, } from "miniprogram-computed";
 import { uuid } from "@/utils/uuid";
+import { getStorage } from "@/utils/storage";
 
 const app = getApp();
 // pages/question/question.js
@@ -132,8 +133,16 @@
     displaySampleList: [],
     section_a_id: '',
     sample_id: '',
-  },
+    userName:getStorage('username'),
 
+  },
+  onClickClear(){
+    console.log('clear');
+    
+    this.setData({
+      sendText:''
+    })
+  },
   async getSampleList() {
     const res = await getSelectSample({
       section_b_id: '',
diff --git a/miniprogram/pages/question/question.wxml b/miniprogram/pages/question/question.wxml
index 5beda3b..15a8e97 100644
--- a/miniprogram/pages/question/question.wxml
+++ b/miniprogram/pages/question/question.wxml
@@ -20,10 +20,10 @@
                 {{item.sample_title}}
               </view>
             </view>
-            <view class="w-300  ml-auto mr-auto mt-30 text-white font28 py-18" style="text-align: center;background: linear-gradient(to right,#37d0e0,#5988e0);border-radius: 300rpx">
+            <!-- <view class="w-300  ml-auto mr-auto mt-30 text-white font28 py-18" style="text-align: center;background: linear-gradient(to right,#37d0e0,#5988e0);border-radius: 300rpx">
               <text class="ywicon icon-maikefeng"></text>
               寮�鍚闊冲璇濆惂~
-            </view>
+            </view> -->
           </view>
         </block>
         <block wx:else>
@@ -52,9 +52,11 @@
     </scroll-view>
   </view>
   <view class="flex-0 flex-items-center py-20" style="background-color: #f4f6f8;">
-    <text class="font46 ywicon icon-fenxiang flex-0 mx-15"></text>
-    <van-field left-icon="replay" custom-class="py-3 flex-items-center van-field" input-class="ml-10" type="textarea" autosize placeholder="鍦ㄨ繖閲岃緭鍏ヤ綘鐨勯棶棰�" class="flex-auto" model:value="{{sendText}}" bind:change="onSendTextChange" size="large"></van-field>
-    <text class="font45 ywicon {{!sendText? 'icon-dianhua1':'icon-fasongxiaoxi'}} flex-0 mx-15" bind:tap="inputRighBtnClick"></text>
+    <!-- <text class="font46 ywicon icon-fenxiang flex-0 mx-15"></text> -->
+    <text class="font46  flex-0 mx-15"></text>
+    <van-field icon="cross" bind:click-icon="onClickClear"  custom-class="py-3 flex-items-center van-field" input-class="ml-10" type="textarea" autosize placeholder="鍦ㄨ繖閲岃緭鍏ヤ綘鐨勯棶棰�" class="flex-auto" model:value="{{sendText}}" bind:change="onSendTextChange" size="large"></van-field>
+    <!-- <text class="font45 ywicon {{!sendText? 'icon-dianhua1':'icon-fasongxiaoxi'}} flex-0 mx-15" bind:tap="inputRighBtnClick"></text> -->
+    <text class="font45 ywicon {{!sendText? 'icon-fasongxiaoxi':'icon-fasongxiaoxi'}} flex-0 mx-15" bind:tap="inputRighBtnClick"></text>
   </view>
   <fui-drawer model:show="{{drawerIsShow}}" direction="left">
     <view class="w-450 flex flex-col relative h-full" >
@@ -62,7 +64,7 @@
       <view class="p-15 flex flex-col justify-between" style="background-color: #e8f0fd;">
         <view class="flex-items-center">
           <text class="ywicon icon-morentouxiang bg-gray-300 rounded-full font60 text-gray-500 mr-20"></text>
-          <text class="font25 font-bold">183799|鍏嶈垂鐢ㄦ埛</text>
+          <text class="font25 font-bold">{{userName}}</text>
         </view>
         <view class="flex-items-center justify-between mt-20">
           <van-button class="" color="#000000" custom-style="font-size:20rpx;height:50rpx" round size="small" icon="plus" bind:tap="newChatRoomClick">鏂板缓鑱婂ぉ瀹�</van-button>
diff --git a/miniprogram/pages/scene/scene.wxml b/miniprogram/pages/scene/scene.wxml
index b9027fe..8316635 100644
--- a/miniprogram/pages/scene/scene.wxml
+++ b/miniprogram/pages/scene/scene.wxml
@@ -9,7 +9,7 @@
             <text class="ywicon icon-{{iconList[index]}} text-blue-600 font55"></text>
             <!-- <image src="/assets/scene/scene_2.png"></image> -->
             <text class="font-bold font32 my-7">{{item.section_name}}</text>
-            <text class="font26 overflow-hidden multi-over-ellisis" style="-webkit-line-clamp: 3;">{{item.section_title}}</text>
+            <text class="font26 overflow-hidden over-ellisis-3" style="-webkit-line-clamp: 3;">{{item.section_title}}</text>
           </view>
         </view>
       </block>
diff --git a/miniprogram/utils/common.ts b/miniprogram/utils/common.ts
index 034f5c3..3d152db 100644
--- a/miniprogram/utils/common.ts
+++ b/miniprogram/utils/common.ts
@@ -22,4 +22,5 @@
 	}, {}) as Record<string, T | T[]>;
 
 	return result;
-};
\ No newline at end of file
+};
+
diff --git a/miniprogram/utils/toolsValidate.ts b/miniprogram/utils/toolsValidate.ts
new file mode 100644
index 0000000..453d851
--- /dev/null
+++ b/miniprogram/utils/toolsValidate.ts
@@ -0,0 +1,14 @@
+
+/**
+ * 鎵嬫満鍙风爜
+ * @param val 褰撳墠鍊煎瓧绗︿覆
+ * @returns 杩斿洖 true: 鎵嬫満鍙风爜姝g‘
+ */
+export function verifyPhone(val: string) {
+	// false: 鎵嬫満鍙风爜涓嶆纭�
+	// if (!/^((12[0-9])|(13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0|1,5-9]))\d{8}$/.test(val)) return false;
+	if (!/^1[3456789]\d{9}$/.test(val)) return false;
+	
+	// true: 鎵嬫満鍙风爜姝g‘
+	else return true;
+}

--
Gitblit v1.9.3