Giter Site home page Giter Site logo

Comments (5)

RickCole21 avatar RickCole21 commented on April 25, 2024

每一个api请求都可以使用对象类型配置,像这样:

api: {
    method: 'get',
    url: '/api/xxx',
    data:{
        x: 'xxx'
    },
    // 这里可以配置请求接收适配器
    adaptor: (payload, response) => {
        let data = payload.data;
        // ...对data进行一些normalize操作
        
        return {
              ...payload,
              data
        }
    },
    // 这里配置发送适配器
    requestAdaptor:(api)=>{
        // 这里可以在请求前对api进行改写
        return {
              ...api,
              data:{
                  ...api.data,
                  other: 'somedata' // 加点其他数据
              }
        }
    }
}

但是请注意,处理后的数据结构要遵循amis的规范才可以正常工作
例如crud的结构是:

{
    status:0,
    msg:'xxx',
    data:{
        items:[], // 这里列表数据
        count: 10,
        page: 1,
        pageSize: 10
        ...其他
    }
}

from amis.

unsad avatar unsad commented on April 25, 2024

@RickCole21 谢谢解答,不过有个问题是,配置文件是JSON格式的,从JSON解析到对象的过程中,类似于adaptor这层函数类型的配置是怎么处理的呢?

from amis.

2betop avatar 2betop commented on April 25, 2024
  1. 配置如果使用 json 文件来配置的话,不支持 function,所以这种情况只能用 js 来配置 json
  2. 如果一定要用json,只能在统一的入口 fetcher 那一层,做适配了,根据 api 地址不同,写不同的适配逻辑。

from amis.

unsad avatar unsad commented on April 25, 2024
  1. 配置如果使用 json 文件来配置的话,不支持 function,所以这种情况只能用 js 来配置 json
  2. 如果一定要用json,只能在统一的入口 fetcher 那一层,做适配了,根据 api 地址不同,写不同的适配逻辑。

我的想法是这样,要进一步提高生产效率的话还是需要做一套可视化编辑器处理配置文件,那么配置文件选择json入库存储应该是比较合适的选择,但管理系统对接的api结构不统一,normailize这一层又比较频繁,这种场景下的解决方案只有在统一入口的fetcher做适配吗?

from amis.

2betop avatar 2betop commented on April 25, 2024

嗯,目前平台做了个适配器配置的东西,就是走统一的 fetcher 那的钩子

from amis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.