zs 2 years ago
parent
commit
f6473838a8
2 changed files with 13 additions and 34 deletions
  1. 9 16
      pages/login/index.js
  2. 4 18
      pages/register/index.js

+ 9 - 16
pages/login/index.js

@@ -27,28 +27,21 @@ Page({
     this.WxValidate = new WxValidate(rules, messages)
   },
   // 提交登录
-  onSubmit: function (e) {
+  onSubmit: async function (e) {
     const params = e.detail.value;
     if (!this.WxValidate.checkForm(params)) {
       const error = this.WxValidate.errorList[0];
       wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
       return false
     } else {
-      wx.request({
-        url: `${app.globalData.publicUrl}/courtAdmin/api/user/login`, //接口地址
-        method: 'post',
-        data: params,
-        success(res) {
-          if (res.data.errcode == 0) {
-            app.globalData.userInfo = res.data.data;//存用户信息到app.js
-            wx.setStorage({ key: "token", data: res.data.data })// 存用户信息到storage,以便之后判断用户是否登录
-            wx.showToast({ title: `账号登录成功`, icon: 'success', duration: 2000 }) //登录成功提示
-            wx.navigateTo({ url: '/pages/home/index' })// 跳转页面
-          } else {
-            wx.showToast({ title: res.data.errmsg, icon: 'error', duration: 2000 })
-          }
-        }
-      })
+      const arr = await app.$post(`/courtAdmin/api/user/login`, params)
+      if (arr.errcode == '0') {
+        app.globalData.userInfo = arr.data;//存用户信息到app.js
+        wx.setStorage({ key: "token", data: arr.data })// 存用户信息到storage,以便之后判断用户是否登录
+        wx.showToast({ title: `账号登录成功`, icon: 'success', duration: 2000 }) //登录成功提示
+        wx.navigateTo({ url: '/pages/home/index' })// 跳转页面
+      }
+      else wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
     }
   },
   // 去注册

+ 4 - 18
pages/register/index.js

@@ -36,7 +36,7 @@ Page({
     that.setData({ 'form.type_name': data.value });
   },
   // 提交登录
-  onSubmit: function (e) {
+  onSubmit: async function (e) {
     const that = this;
     const params = e.detail.value;
     if (!this.WxValidate.checkForm(params)) {
@@ -47,23 +47,9 @@ Page({
       if (params.password !== params.is_password) {
         wx.showToast({ title: '密码输入不一致', duration: 2000, icon: 'error', })
       } else {
-        wx.request({
-          url: `${app.globalData.publicUrl}/courtAdmin/api/user`, //接口地址
-          method: 'post',
-          data: params,
-          success(res) {
-            if (res.data.errcode == 0) {
-              wx.showToast({
-                title: '注册账号成功',
-                duration: 2000,
-                icon: 'success',
-                success: (res) => { that.back() }
-              })
-            } else {
-              wx.showToast({ title: res.data.errmsg, icon: 'error', duration: 2000 })
-            }
-          }
-        })
+        const arr = await app.$post(`/courtAdmin/api/user`, params)
+        if (arr.errcode == '0') { wx.showToast({ title: `注册账号成功`, icon: 'success', duration: 2000 }); that.back(); }
+        else wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
       }
     }
   },