Coder Social home page Coder Social logo

Comments (2)

gaoletian avatar gaoletian commented on May 6, 2024 4

这个可以通过自定义代码模板解决

my-pont-template.ts

import { CodeGenerator, Interface, Mod, BaseClass } from 'pont-engine';
import * as pont from 'pont-engine';

export default class MyGenerator extends CodeGenerator {
  /** 获取接口实现内容的代码 */
  getInterfaceContent(inter: Interface) {
    const bodyParmas = inter.getBodyParamsCode();
    const requestParams = bodyParmas ? `params, bodyParams` : `params`;

    return `
    /**
     * @desc ${inter.description}
     */

    import * as defs from '../../baseClass';

    // 修改为自己的 fetch函数
    import pontFetch from 'src/utils/pontFetch';

    export ${inter.getParamsCode()}
    export const init = ${inter.response.initialValue};

    export async function request(${requestParams}) {
      return pontFetch({
        url: '${inter.path}',
        ${bodyParmas ? 'params: bodyParams' : 'params'},
        method: '${inter.method}',
      });
    }
   `;
  }
}

这是我的代码生成模板, 参考一下
https://github.com/gaoletian/nuxt-ts-pont-demo/blob/275876a93f1de63765b2470a12b69acc9c7337bc/app/config/pont-template-nuxt.ts#L80

from pont.

jasonHzq avatar jasonHzq commented on May 6, 2024

我理解每个项目的 fetch 都有自己的业务逻辑,所以 pont 的默认模板里,并没有声明 fetch 方法如何实现。比如接口结构中,如何算成功,错误信息如何取,这个是 pont 不应该关心的。

每个项目应该会有自己实现的公共的 fetch 方法,'import pontFetch from src/utils/pontFetch' 可以在 自定义代码生成(templatePath)被覆盖,指向你实现的 fetch 方法。

from pont.

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.