Kaynağa Gözat

feat: config weixin request funciton

wangyuan 2 yıl önce
ebeveyn
işleme
3fe432987c
4 değiştirilmiş dosya ile 86 ekleme ve 1 silme
  1. 7 0
      api/app.js
  2. 0 0
      api/my.js
  3. 49 0
      api/request.js
  4. 30 1
      pages/my/my.js

+ 7 - 0
api/app.js

@@ -0,0 +1,7 @@
+
+// 应用公共 api 接口
+import { wxRequest } from './request'
+
+const loginURL = '/user/login/v1' // 登录
+
+export const ittLogin =  (data) => wxRequest(loginURL, data)

+ 0 - 0
api/my.js


+ 49 - 0
api/request.js

@@ -0,0 +1,49 @@
+/* wx.request */
+const BASE_API = 'http://itt.chl6zk.store/api'
+
+export const wxRequest = (url,data) => {
+  return new Promise((resolve, reject) => {
+    wx.showLoading({
+      title: '加载中...',
+      mask: true
+    })
+    wx.request({
+      url: BASE_API + url,
+      data: data,
+      method: 'POST',
+      success (response) {
+        if (response.statusCode !== 200) {
+          wx.showToast({
+            title: response.errMsg || '网络错误!',
+            icon: 'error',
+            duration: 2500,
+            mask: true
+          })
+        } else {
+          if (response.data.code !== '200') {
+            wx.showToast({
+              title: response.data.msg || '请求错误!',
+              icon: 'error',
+              duration: 2500,
+              mask: true
+            })
+          } else {
+            resolve(response.data)
+          }
+        }
+      },
+      fail (e) {
+        wx.showToast({
+          title: '请求错误!',
+          icon: 'error',
+          duration: 2500,
+          mask: true
+        })
+        reject(e)
+      },
+      complete () {
+        wx.hideLoading()
+      }
+    })
+  })
+}

+ 30 - 1
pages/my/my.js

@@ -1,5 +1,6 @@
 // pages/my/my.js
 import itt from '../../utils/util'
+import { ittLogin } from '../../api/app'
 const app = getApp()
 Page({
 
@@ -15,7 +16,7 @@ Page({
       {
         id: 0,
         title: '我的地址',
-        url: '/pages/address/address?form=my',
+        url: '/pages/address/address?form=my&back=0',
         imgUrl: '../../imaes/dizhi@2x.png'
       },
       {
@@ -90,6 +91,34 @@ Page({
    * 生命周期函数--监听页面显示
    */
   onShow() {
+    wx.login({
+      success (res) {
+        if (res.code) {
+          let data = {
+            code: res.code
+          }
+          ittLogin(data).then(res => {
+            console.log(res,'then login');
+          })
+        }
+      }
+    })
+    return
+    wx.login({
+      success (res) {
+        if (res.code) {
+          //发起网络请求
+          let data = {
+            code: res.code
+          }
+          itt.postLogin('http://itt.chl6zk.store/api/user/login/v1', data, function (res) {
+            console.log(res, 'itt my');
+          })
+        } else {
+          console.log('登录失败!' + res.errMsg)
+        }
+      }
+    })
     this.setData({
       pageLogin: app.globalData.userInfo.login
     })