祖安之光
2025-08-07 ad5c4cc086a40708e66040574ff1d465b66304b6
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(){