| | |
| | | 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) { |
| | |
| | | [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({ |
| | |
| | | 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(){ |