| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- // pages/my/my.js
- var app=getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- buttonText:'发送验证码',
- phone:"",
- code:"",
- countDown:60,
- timer:null,
- sendCodeDisabled:false,
- },
- onPhoneInput(e){
- this.setData({
- phone:e.detail
- });
- },
- onCodeInput(e){
- this.setData({
- code:e.detail
- });
- },
- sendCode(){
- if(this.data.sendCodeDisabled){
- return;
- }
- if(this.data.phone.length<11){
- wx.showToast({
- title: '手机号长度错误',
- icon:"none",
- });
- return;
- };
- var reg=/^(1[3|4|5|6|7|8|9])\d{9}$/;
- if(!reg.test(this.data.phone)){
- wx.showToast({
- title: '手机号格式错误',
- icon:"none",
- });
- return;
- }
- wx.request({
- url: 'http://127.0.0.1:8000/api/message/',
- data: {
- phone:this.data.phone
- },
- method: 'GET',
- success: (res) => {
- console.log(res);
- if(res.data.status){
- this.setData({
- sendCodeDisabled:true,
- timer:setInterval(this.hcountDown,1000)
- });
- wx.showToast({
- title: res.data.message,
- icon:"none",
- });
- }else{
- wx.showToast({
- title: res.data.message,
- icon:"none",
- });
- }
- },
- })
- },
- hcountDown(){
- var countDown=this.data.countDown;
- if(countDown===0){
- clearInterval(this.data.timer);
- this.setData({
- buttonText:'发送验证码',
- sendCodeDisabled:false,
- countDown:60
- });
- return;
- }
- this.setData({
- buttonText:countDown+'s',
- countDown:countDown-1
- });
- },
- login2(e){
- wx.showLoading({
- title: '登录中...',
- mask: true // 防止触摸穿透
- });
- wx.request({
- url: 'http://127.0.0.1:8000/api/login/',
- data: {
- phone:this.data.phone,
- code:this.data.code
- },
- method: 'POST',
- dataType:'json',
- success: (res) => {
- console.log(res);
- if(res.data.status){
- console.log(res.data.data);
- console.log(e);
- app.initUserInfo(res.data.data,e.detail.userInfo)
- wx.navigateBack({});
- }else{
- wx.showToast({
- title:res.data.message,
- icon:"none",
- });
- }
- },
- });
- wx.hideLoading();
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- clearInterval(this.data.timer);
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- }
- })
|