Browse Source

feat: config api

wangyuan 2 years ago
parent
commit
181916ffa9
2 changed files with 61 additions and 0 deletions
  1. 23 0
      api/login.js
  2. 38 0
      api/request.js

+ 23 - 0
api/login.js

@@ -0,0 +1,23 @@
+
+// login
+import { wxRequest } from './request'
+
+// 密码登录
+const pwdLoginURL = '/worker/pwd/login'
+
+// 微信登录
+const workerLoginURL =   "/worker/login"
+
+// 绑定微信
+const bindWecahtURL = '/bind/wecaht'
+
+
+export const pwdLogin =  (data) => wxRequest(pwdLoginURL, data)
+
+export const workerLogin =  (data) => wxRequest(workerLoginURL, data)
+
+export const bindWecaht =  (data) => wxRequest(bindWecahtURL, data)
+
+
+
+

+ 38 - 0
api/request.js

@@ -0,0 +1,38 @@
+/* wx.request */
+const BASE_API = 'https://itt-worker.chl6zk.store/api' 
+const BASE_VERSION = '/v1'
+import itt from '../utils/util'
+const app = getApp()
+export const wxRequest = (url,data) => {
+  return new Promise((resolve, reject) => {
+    wx.request({
+      url: BASE_API + url + BASE_VERSION,
+      data: data,
+      header: {
+        systemData:JSON.stringify({
+          requestId: itt.getUUID(),
+          loginToken: app.globalData.accessToken,
+          timestamp: new Date().getTime()
+        })
+      },
+      method: 'POST',
+      success (response) {
+        console.log('当前请求地址:', url);
+        console.log('当前请求参数:', data);
+        console.log('当前请求返回:', response.data);
+        if (response.statusCode !== 200) {
+          reject(response.data.msg || '请求错误')
+        } else {
+          if (response.data.code !== '000') {
+            reject(response.data)
+          } else {
+            resolve(response.data)
+          }
+        }
+      },
+      fail (e) {
+        reject('网络错误')
+      }
+    })
+  })
+}