From 41193d186d157937ba052e73dd04c12018e9ecab Mon Sep 17 00:00:00 2001
From: 祖安之光 <11848914+light-of-zuan@user.noreply.gitee.com>
Date: 星期四, 07 八月 2025 10:38:42 +0800
Subject: [PATCH] 新增

---
 pages/index/index.js |  123 +++++++++++++++-------------------------
 1 files changed, 47 insertions(+), 76 deletions(-)

diff --git a/pages/index/index.js b/pages/index/index.js
index 43e57a6..8f55672 100644
--- a/pages/index/index.js
+++ b/pages/index/index.js
@@ -11,24 +11,37 @@
     userFocused: false,
     codeFocused: false,
     form: {
-      username: 'qyyh12345',
-      password: 'Gkhy@c413',
+      username: '',
+      password: '',
       code: '',
       uuid: ''
     },
     isPwd: true,
-    isLogining: false
+    isLogining: false,
+    saveAccount: false
   },
   
   onShow() {
-    if(wx.getStorageSync('name') && wx.getStorageSync('pwd')){
-    }else{
-      wx.clearStorageSync();
-    }
+    
   },
   
   onLoad() {
-    
+    wx.showShareMenu({
+      withShareTicket: true,
+      menus: ['shareAppMessage', 'shareTimeline']
+    })
+    console.log(wx.getStorageSync('isSave'),'get1')
+    if(wx.getStorageSync('isSave')){
+      this.setData({
+        saveAccount: true,
+        form: {
+          username: wx.getStorageSync('username') || '',
+          password: wx.getStorageSync('pwd') || '',
+          code: '',
+          uuid: ''
+        }
+      })
+    }
   },
   
   base64Encode(e) {
@@ -47,7 +60,10 @@
       [field]: e.detail.value  // 动态更新对应字段
     });
   },
-
+  switchChange(e){
+    this.setData({ saveAccount: e.detail.value })
+    wx.setStorageSync('isSave',e.detail.value)
+  },
   Login(){
     if(this.data.form.username == ''){
       wx.showToast({
@@ -71,82 +87,37 @@
     const data = {username, password, code, uuid};
     data.password = this.base64Encode(data.password);
     wx.removeStorageSync('tk');
-    
-    // 云开发请求
-    cloudApi.queryPost('userList',{username: data.username,password: data.password}).then(res=>{
-      if(res.data.length>0){
+
+    // api请求
+    api.login(data).then(res => {
+      console.log(res,'res')
+      if (res.code === 200) {
         this.setData({
           isLogining: false
         });
-        const info = cloudApi.changeKey(res.data)
         wx.setStorageSync("username", this.data.form.username);
         wx.setStorageSync("pwd", this.data.form.password);
-        wx.setStorageSync("uid", info[0].Id);
-        wx.setStorageSync('user', info[0]);
+        wx.setStorageSync("tk", res.data.token);
+        wx.setStorageSync("uid", res.data.id);
+        wx.setStorageSync('user', res.data);
         wx.switchTab({
           url: '/pages/tabBar/firstPage/firstPage'
         });
-      }else{
-        cloudApi.queryPost('userList',{name: data.username}).then(res=>{
-          if(res.data.length>0){
-            wx.showToast({
-              icon: "none",
-              title: '密码错误'
-            });
-            this.setData({
-              'form.password': '',
-              isLogining: false
-            });
-          }else{
-            wx.showToast({
-              icon: "none",
-              title: '用户不存在'
-            });
-            this.setData({
-              form: {
-                username: '',
-                password: '',
-                code: '',
-                uuid: ''
-              },
-              isLogining: false
-            });
-          }
-        })
+      } else {
+        wx.showToast({
+          icon: "none",
+          title: res.message
+        });
+        this.setData({
+          isLogining: false
+        });
       }
-    })
-
-    // api请求
-    // api.login(data).then(res => {
-    //   console.log(res,'res')
-    //   if (res.code === 200) {
-    //     this.setData({
-    //       isLogining: false
-    //     });
-    //     wx.setStorageSync("name", this.data.form.username);
-    //     wx.setStorageSync("pwd", this.data.form.password);
-    //     wx.setStorageSync("tk", res.data.token);
-    //     wx.setStorageSync("uid", res.data.id);
-    //     wx.setStorageSync('user', res.data);
-    //     wx.switchTab({
-    //       url: '/pages/tabBar/firstPage/firstPage'
-    //     });
-    //   } else {
-    //     wx.showToast({
-    //       icon: "none",
-    //       title: res.message
-    //     });
-    //     this.setData({
-    //       'form.password': '',
-    //       isLogining: false
-    //     });
-    //   }
-    // }).catch(err => {
-    //   this.setData({
-    //     'form.password': '',
-    //     isLogining: false
-    //   });
-    // });
+    }).catch(err => {
+      this.setData({
+        'form.password': '',
+        isLogining: false
+      });
+    });
   },
   
   focusUser(){

--
Gitblit v1.9.2