2020-12-30 10:17:56 +08:00
2020-12-29 17:16:53 +08:00
2020-12-29 16:34:10 +08:00
2020-12-30 10:17:56 +08:00
2020-12-30 10:17:56 +08:00
2020-12-30 10:16:26 +08:00
2020-12-29 17:22:26 +08:00
2020-12-30 10:15:22 +08:00
2020-12-30 10:16:26 +08:00
2020-12-28 17:13:09 +08:00
2020-12-30 10:17:56 +08:00
2020-12-30 10:17:56 +08:00
2020-11-30 17:09:04 +08:00

企获客(SAAS)

Author: TMOCT5

1. 项目目录

apis : 统一的请求工厂处理

|--- interfaces         //接口工厂
|    |--- auth.js       //授权接口模块
|    |--- file.js       //上传接口
|--- index.js           //统一接口路由出口
|--- request.js         //请求方法
|--- updateToken.hs     //token更新
|--- err.js             //错误处理

static : 静态资源目录

|--- imgs   //图片
|--- icon   //图标

components : 项目组件目录

pages : 页面路由

2. 使用apis接口方法

统一用法 : 在app.js 中引入api方法使用wx.$方法挂载全局

//app.js
//全局引用apis
import apis from "./apis/index"

onLaunch(){
    //挂载api方法
    wx.$api = apis
}

//pages.js
function () {
    wx.$api...().then(res=>{
        //成功回调
    }).cathc(err=>{
        //失败回调
    })
}

按需引用 : 按需要引用

//pages.js
import apis from "./apis/index"

function () {
    apis...().then(res=>{
        //成功回调
    }).cathc(err=>{
        //失败回调
    })
}

多个接口同时回调 : 面需多个接口同时返回信息时可使用ES6 Promise All回调方法

let api1 = wx.$api.{moduleName}.{apiName}(obj)
    api2 = wx.$api.{moduleName}.{apiName}(obj)
    api3 = wx.$api.{moduleName}.{apiName}(obj)

Promise.all([api1, api2, api3]).then(res=>{
    //请求回调成功
}).cathc(err=>{
    //请求回调失败
})

3. 请求方法描述

api全局请求方法参数说明

请求参数 是否必填 数据类型 数据说明
method String 请求方式默认为GET
url String 接口url地址
data Obj 需要发送的请求数据

请求方法模块用法

import {req} from "../request"

const apiName = (obj) => req({
    //请求参数
})

export default({
    apiName
})

4. 上传方法描述

api全局请求方法参数说明

请求参数 是否必填 数据类型 数据说明
url String 上传接口url地址
key String 文件对应的 key
path String 上传文件的临时路径可通过wx.chooseImage获得图片临时路径
data Obj 需要发送的请求数据

方法模块用法

import {upload} from "../request"

const apiName = (fileUrl, keyName, data) => upload({
    url : "...",        //api上传接口
    key : keyName,      //上传key
    path: fileUrl,      //上传路径
    data: data          //fromData
})


export default({
    apiName
})

接口用法

wx.$api.file.uploadImg(fileUrl, keyName, {
    //data
}).then(res=>{
    //上传成功
}).cathc(err=>{
    //上传失败
})
Description
企获客Saas
Readme 1.4 MiB
Languages
JavaScript 100%